1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <hintids.hxx>
22 #include <tools/date.hxx>
23 #include <tools/time.hxx>
24 #include <svl/urihelper.hxx>
25 #include <svl/fstathelper.hxx>
26 #include <unotools/moduleoptions.hxx>
27 #include <sfx2/docfile.hxx>
28 #include <editeng/lrspitem.hxx>
29 #include <editeng/ulspitem.hxx>
30 #include <editeng/boxitem.hxx>
31 #include <editeng/paperinf.hxx>
34 #include <fmtanchr.hxx>
35 #include <fmtfsize.hxx>
36 #include <fmtpdsc.hxx>
37 #include <swtypes.hxx>
38 #include <shellio.hxx>
40 #include <IDocumentUndoRedo.hxx>
43 #include <undobj.hxx> // fuer Undo Insert-Dokument
44 #include <swundo.hxx> // fuer Undo Insert-Dokument
45 #include <swtable.hxx>
47 #include <pagedesc.hxx>
48 #include <poolfmt.hxx>
51 #include <redline.hxx>
56 #include <pausethreadstarting.hxx>
58 using namespace ::com::sun::star
;
60 //////////////////////////////////////////////////////////////////////////
62 sal_uLong
SwReader::Read( const Reader
& rOptions
)
64 // Variable uebertragen
65 Reader
* po
= (Reader
*) &rOptions
;
69 po
->bInsertMode
= 0 != pCrsr
;
71 // ist ein Medium angegeben, dann aus diesem die Streams besorgen
72 if( 0 != (po
->pMedium
= pMedium
) &&
73 !po
->SetStrmStgPtr() )
75 po
->SetReadUTF8( sal_False
);
76 po
->SetBlockMode( sal_False
);
77 po
->SetOrganizerMode( sal_False
);
78 po
->SetIgnoreHTMLComments( sal_False
);
79 return ERR_SWG_FILE_FORMAT_ERROR
;
82 sal_uLong nError
= 0L;
86 // waehrend des einlesens kein OLE-Modified rufen
87 Link
aOLELink( pDoc
->GetOle2Link() );
88 pDoc
->SetOle2Link( Link() );
90 pDoc
->SetInReading( true );
91 pDoc
->SetInXMLImport( 0 != dynamic_cast< XMLReader
* >(po
) );
98 // Wenn der Reader nicht mit einem Shell konstruiert wurde,
99 // selber einen Pam machen.
100 SwNodeIndex
nNode( pDoc
->GetNodes().GetEndOfContent(), -1 );
101 pPam
= new SwPaM( nNode
);
102 // Bei Web-Dokumenten wird die Default-Vorlage schon im InitNew
103 // gesetzt und braucht deshalb nicht nochmal gesetzt zu werden.
104 // Das gilt natuerlich nicht, wenn der Filter nicht der HTML-Filter
105 // ist oder im ConvertFrom zuvor ein SetTemplateName gerufen
107 if( !pDoc
->get(IDocumentSettingAccess::HTML_MODE
) || ReadHTML
!= po
|| !po
->pTemplate
)
108 po
->SetTemplate( *pDoc
);
111 // Pams sind ringfoermig verkettet. Aufhoeren, wenn man wieder beim
114 SwUndoInsDoc
* pUndo
= 0;
116 sal_Bool bReadPageDescs
= sal_False
;
117 bool const bDocUndo
= pDoc
->GetIDocumentUndoRedo().DoesUndo();
118 bool bSaveUndo
= bDocUndo
&& pCrsr
;
121 // das Einlesen von Seitenvorlagen ist nicht Undofaehig!
122 if( 0 != ( bReadPageDescs
= po
->aOpt
.IsPageDescs() ) )
125 pDoc
->GetIDocumentUndoRedo().DelAllUndoObj();
129 pDoc
->GetIDocumentUndoRedo().ClearRedo();
130 pDoc
->GetIDocumentUndoRedo().StartUndo( UNDO_INSDOKUMENT
, NULL
);
133 pDoc
->GetIDocumentUndoRedo().DoUndo(false);
135 SwNodeIndex
aSplitIdx( pDoc
->GetNodes() );
137 RedlineMode_t eOld
= pDoc
->GetRedlineMode();
138 RedlineMode_t
ePostReadRedlineMode( nsRedlineMode_t::REDLINE_IGNORE
);
140 // Array von FlyFormaten
141 SwFrmFmts aFlyFrmArr
;
142 // only read templates? then ignore multi selection!
143 sal_Bool bFmtsOnly
= po
->aOpt
.IsFmtsOnly();
148 pUndo
= new SwUndoInsDoc( *pPam
);
150 pDoc
->SetRedlineMode_intern( nsRedlineMode_t::REDLINE_IGNORE
);
153 if( bDocUndo
|| pCrsr
)
155 // Pam auf den Node davor setzen damit er nicht mit verschoben wird
156 const SwNodeIndex
& rTmp
= pPam
->GetPoint()->nNode
;
157 pUndoPam
= new SwPaM( rTmp
, rTmp
, 0, -1 );
160 // Speicher mal alle Fly's
163 std::copy(pDoc
->GetSpzFrmFmts()->begin(),
164 pDoc
->GetSpzFrmFmts()->end(), std::back_inserter(aFlyFrmArr
));
167 xub_StrLen nSttCntnt
= pPam
->GetPoint()->nContent
.GetIndex();
169 // damit fuer alle Reader die Ende-Position immer stimmt, hier
171 SwCntntNode
* pCNd
= pPam
->GetCntntNode();
172 xub_StrLen nEndCntnt
= pCNd
? pCNd
->Len() - nSttCntnt
: 0;
173 SwNodeIndex
aEndPos( pPam
->GetPoint()->nNode
, 1 );
175 pDoc
->SetRedlineMode_intern( eOld
);
177 nError
= po
->Read( *pDoc
, GetBaseURL(), *pPam
, aFileName
);
179 // an ODF document may contain redline mode in settings.xml; save it!
180 ePostReadRedlineMode
= pDoc
->GetRedlineMode();
182 pDoc
->SetRedlineMode_intern( nsRedlineMode_t::REDLINE_IGNORE
);
184 if( !IsError( nError
)) // dann setzen wir das Ende mal richtig
187 pCNd
= aEndPos
.GetNode().GetCntntNode();
188 if( !pCNd
&& 0 == ( pCNd
= pDoc
->GetNodes().GoPrevious( &aEndPos
) ))
189 pCNd
= pDoc
->GetNodes().GoNext( &aEndPos
);
191 pPam
->GetPoint()->nNode
= aEndPos
;
192 xub_StrLen nLen
= pCNd
->Len();
193 if( nLen
< nEndCntnt
)
196 nEndCntnt
= nLen
- nEndCntnt
;
197 pPam
->GetPoint()->nContent
.Assign( pCNd
, nEndCntnt
);
199 const SwStartNode
* pTblBoxStart
= pCNd
->FindTableBoxStartNode();
202 SwTableBox
* pBox
= pTblBoxStart
->GetTblBox();
205 pDoc
->ChkBoxNumFmt( *pBox
, sal_True
);
212 *pUndoPam
->GetMark() = *pPam
->GetPoint();
213 pUndoPam
->GetPoint()->nNode
++;
214 SwNode
* pNd
= pUndoPam
->GetNode();
215 if( pNd
->IsCntntNode() )
216 pUndoPam
->GetPoint()->nContent
.Assign(
217 (SwCntntNode
*)pNd
, nSttCntnt
);
219 pUndoPam
->GetPoint()->nContent
.Assign( 0, 0 );
221 int bChkHeaderFooter
= pNd
->FindHeaderStartNode() ||
222 pNd
->FindFooterStartNode();
224 // Suche alle neuen Fly's und speicher sie als einzelne Undo
226 for( sal_uInt16 n
= 0; n
< pDoc
->GetSpzFrmFmts()->size(); ++n
)
228 SwFrmFmt
* pFrmFmt
= (*pDoc
->GetSpzFrmFmts())[ n
];
229 const SwFmtAnchor
& rAnchor
= pFrmFmt
->GetAnchor();
230 if( USHRT_MAX
== aFlyFrmArr
.GetPos( pFrmFmt
) )
232 SwPosition
const*const pFrameAnchor(
233 rAnchor
.GetCntntAnchor());
234 if ( (FLY_AT_PAGE
== rAnchor
.GetAnchorId())
236 && ( ( (FLY_AT_PARA
== rAnchor
.GetAnchorId())
237 && ( (pUndoPam
->GetPoint()->nNode
==
239 || (pUndoPam
->GetMark()->nNode
==
243 // #i97570# also check frames anchored AT char
244 || ( (FLY_AT_CHAR
== rAnchor
.GetAnchorId())
245 && !IsDestroyFrameAnchoredAtChar(
247 *pUndoPam
->GetPoint(),
248 *pUndoPam
->GetMark())
254 if( bChkHeaderFooter
&&
255 (FLY_AT_PARA
== rAnchor
.GetAnchorId()) &&
256 RES_DRAWFRMFMT
== pFrmFmt
->Which() )
258 // DrawObjecte in Kopf-/Fusszeilen ist nicht
261 pDoc
->DelFrmFmt( pFrmFmt
);
268 pDoc
->SetRedlineMode_intern( eOld
);
269 // UGLY: temp. enable undo
270 pDoc
->GetIDocumentUndoRedo().DoUndo(true);
271 pDoc
->GetIDocumentUndoRedo().AppendUndo(
272 new SwUndoInsLayFmt( pFrmFmt
,0,0 ) );
273 pDoc
->GetIDocumentUndoRedo().DoUndo(false);
274 pDoc
->SetRedlineMode_intern( nsRedlineMode_t::REDLINE_IGNORE
);
276 if( pFrmFmt
->GetDepends() )
278 // beim Insert legen Draw-Objecte einen Frame an
283 if (FLY_AT_PAGE
== rAnchor
.GetAnchorId())
285 if( !rAnchor
.GetCntntAnchor() )
291 pDoc
->SetContainsAtPageObjWithContentAnchor( true );
300 if( !aFlyFrmArr
.empty() )
303 pDoc
->SetRedlineMode_intern( eOld
);
304 if( pDoc
->IsRedlineOn() )
305 pDoc
->AppendRedline( new SwRedline( nsRedlineType_t::REDLINE_INSERT
, *pUndoPam
), true);
307 pDoc
->SplitRedline( *pUndoPam
);
308 pDoc
->SetRedlineMode_intern( nsRedlineMode_t::REDLINE_IGNORE
);
312 pDoc
->SetRedlineMode_intern( eOld
);
313 pUndo
->SetInsertRange( *pUndoPam
, sal_False
);
314 // UGLY: temp. enable undo
315 pDoc
->GetIDocumentUndoRedo().DoUndo(true);
316 pDoc
->GetIDocumentUndoRedo().AppendUndo( pUndo
);
317 pDoc
->GetIDocumentUndoRedo().DoUndo(false);
318 pDoc
->SetRedlineMode_intern( nsRedlineMode_t::REDLINE_IGNORE
);
323 pPam
= (SwPaM
*) pPam
->GetNext();
327 // only read templates? then ignore multi selection! Bug 68593
332 * !!! man muss selbst den Status vom Stream zuruecksetzen. !!!
333 * Beim seekg wird der akt. Status, eof- und bad-Bit
334 * gesetzt, warum weiss keiner
343 pDoc
->SetInReading( false );
344 pDoc
->SetInXMLImport( false );
346 pDoc
->InvalidateNumRules();
347 pDoc
->UpdateNumRule();
348 pDoc
->ChkCondColls();
349 pDoc
->SetAllUniqueFlyNames();
350 pDoc
->SetLoaded( true );
352 pDoc
->GetIDocumentUndoRedo().DoUndo(bDocUndo
);
357 pDoc
->SetRedlineMode_intern( eOld
);
358 pDoc
->GetIDocumentUndoRedo().EndUndo( UNDO_INSDOKUMENT
, NULL
);
359 pDoc
->SetRedlineMode_intern( nsRedlineMode_t::REDLINE_IGNORE
);
363 // Wenn der Pam nur fuers Lesen konstruiert wurde, jetzt zerstoeren.
366 delete pPam
; // ein neues aufgemacht.
368 // #i42634# Moved common code of SwReader::Read() and
369 // SwDocShell::UpdateLinks() to new SwDoc::UpdateLinks():
370 // ATM still with Update
371 pDoc
->UpdateLinks( true );
373 // not insert: set the redline mode read from settings.xml
374 eOld
= static_cast<RedlineMode_t
>(
375 ePostReadRedlineMode
& ~nsRedlineMode_t::REDLINE_IGNORE
);
377 pDoc
->SetFieldsDirty(false, NULL
, 0);
380 pDoc
->SetRedlineMode_intern( eOld
);
381 pDoc
->SetOle2Link( aOLELink
);
383 if( pCrsr
) // das Doc ist jetzt modifiziert
385 // #i38810# - If links have been updated, the document
386 // have to be modified. During update of links the OLE link at the document
387 // isn't set. Thus, the document's modified state has to be set again after
388 // the OLE link is restored - see above <pDoc->SetOle2Link( aOLELink )>.
389 if ( pDoc
->LinksUpdated() )
394 po
->SetReadUTF8( sal_False
);
395 po
->SetBlockMode( sal_False
);
396 po
->SetOrganizerMode( sal_False
);
397 po
->SetIgnoreHTMLComments( sal_False
);
404 * Konstruktoren, Destruktor
407 SwReader::SwReader(SfxMedium
& rMedium
, const String
& rFileName
, SwDoc
*pDocument
)
408 : SwDocFac(pDocument
), pStrm(0), pMedium(&rMedium
), pCrsr(0),
411 SetBaseURL( rMedium
.GetBaseURL() );
414 // In ein existierendes Dokument einlesen
416 SwReader::SwReader(SvStream
& rStrm
, const String
& rFileName
, const String
& rBaseURL
, SwPaM
& rPam
)
417 : SwDocFac(rPam
.GetDoc()), pStrm(&rStrm
), pMedium(0), pCrsr(&rPam
),
420 SetBaseURL( rBaseURL
);
423 SwReader::SwReader(SfxMedium
& rMedium
, const String
& rFileName
, SwPaM
& rPam
)
424 : SwDocFac(rPam
.GetDoc()), pStrm(0), pMedium(&rMedium
),
425 pCrsr(&rPam
), aFileName(rFileName
)
427 SetBaseURL( rMedium
.GetBaseURL() );
430 SwReader::SwReader( const uno::Reference
< embed::XStorage
> &rStg
, const String
& rFilename
, SwPaM
&rPam
)
431 : SwDocFac(rPam
.GetDoc()), pStrm(0), xStg( rStg
), pMedium(0), pCrsr(&rPam
), aFileName(rFilename
)
437 aDStamp( Date::EMPTY
),
438 aTStamp( Time::EMPTY
),
439 aChkDateTime( DateTime::EMPTY
),
440 pStrm(0), pMedium(0), bInsertMode(0),
441 bTmplBrowseMode(0), bReadUTF8(0), bBlockMode(0), bOrganizerMode(0),
442 bHasAskTemplateName(0), bIgnoreHTMLComments(0)
451 String
Reader::GetTemplateName() const
456 // Die Filter-Vorlage laden, setzen und wieder freigeben
457 SwDoc
* Reader::GetTemplateDoc()
459 if( !bHasAskTemplateName
)
461 SetTemplateName( GetTemplateName() );
462 bHasAskTemplateName
= sal_True
;
465 if( !aTemplateNm
.Len() )
469 INetURLObject
aTDir( aTemplateNm
);
470 String aFileName
= aTDir
.GetMainURL( INetURLObject::NO_DECODE
);
471 OSL_ENSURE( !aTDir
.HasError(), "No absolute path for template name!" );
472 DateTime
aCurrDateTime( DateTime::SYSTEM
);
475 // Wenn das Template schon mal geladen wurde, nur einmal pro
476 // Minute nachschauen, ob es geaendert wurde.
477 if( !pTemplate
|| aCurrDateTime
>= aChkDateTime
)
479 Date
aTstDate( Date::EMPTY
);
480 Time
aTstTime( Time::EMPTY
);
481 if( FStatHelper::GetModifiedDateTimeOfFile(
482 aTDir
.GetMainURL( INetURLObject::NO_DECODE
),
483 &aTstDate
, &aTstTime
) &&
484 ( !pTemplate
|| aDStamp
!= aTstDate
|| aTStamp
!= aTstTime
))
491 // Erst in einer Minute wieder mal nachschauen, ob sich die
492 // Vorlage geaendert hat.
493 aChkDateTime
= aCurrDateTime
;
494 aChkDateTime
+= Time( 0L, 1L );
500 OSL_ENSURE( !pTemplate
, "Who holds the template doc?" );
502 // If the writer module is not installed,
503 // we cannot create a SwDocShell. We could create a
504 // SwWebDocShell however, because this exists always
506 SvtModuleOptions aModuleOptions
;
507 if( aModuleOptions
.IsWriter() )
510 new SwDocShell ( SFX_CREATE_MODE_INTERNAL
);
511 SfxObjectShellLock xDocSh
= pDocSh
;
512 if( pDocSh
->DoInitNew( 0 ) )
514 pTemplate
= pDocSh
->GetDoc();
515 pTemplate
->SetOle2Link( Link() );
517 pTemplate
->GetIDocumentUndoRedo().DoUndo( false );
518 pTemplate
->set(IDocumentSettingAccess::BROWSE_MODE
, bTmplBrowseMode
);
519 pTemplate
->RemoveAllFmtLanguageDependencies();
521 ReadXML
->SetOrganizerMode( sal_True
);
522 SfxMedium
aMedium( aFileName
, sal_False
);
523 SwReader
aRdr( aMedium
, aEmptyStr
, pTemplate
);
524 aRdr
.Read( *ReadXML
);
525 ReadXML
->SetOrganizerMode( sal_False
);
527 pTemplate
->acquire();
532 OSL_ENSURE( !pTemplate
|| FStatHelper::IsDocument( aFileName
) ||
533 aTemplateNm
.EqualsAscii( "$$Dummy$$" ),
534 "TemplatePtr but no template exist!" );
540 sal_Bool
Reader::SetTemplate( SwDoc
& rDoc
)
542 sal_Bool bRet
= sal_False
;
547 rDoc
.RemoveAllFmtLanguageDependencies();
548 rDoc
.ReplaceStyles( *pTemplate
);
549 rDoc
.SetFixFields(false, NULL
);
556 void Reader::ClearTemplate()
560 if( 0 == pTemplate
->release() )
566 void Reader::SetTemplateName( const String
& rDir
)
568 if( rDir
.Len() && aTemplateNm
!= rDir
)
575 void Reader::MakeHTMLDummyTemplateDoc()
578 pTemplate
= new SwDoc
;
579 pTemplate
->acquire();
580 pTemplate
->set(IDocumentSettingAccess::BROWSE_MODE
, bTmplBrowseMode
);
581 pTemplate
->getPrinter( true );
582 pTemplate
->RemoveAllFmtLanguageDependencies();
583 aChkDateTime
= Date( 1, 1, 2300 ); // 2300. Jahrtausend sollte reichen
584 aTemplateNm
.AssignAscii( "$$Dummy$$" );
587 // alle die die Streams / Storages nicht geoeffnet brauchen,
588 // muessen die Methode ueberladen
589 int Reader::SetStrmStgPtr()
591 OSL_ENSURE( pMedium
, "Wo ist das Medium??" );
593 if( pMedium
->IsStorage() )
595 if( SW_STORAGE_READER
& GetReaderType() )
597 xStg
= pMedium
->GetStorage();
603 pStrm
= pMedium
->GetInStream();
604 if ( pStrm
&& SotStorage::IsStorageFile(pStrm
) && (SW_STORAGE_READER
& GetReaderType()) )
606 pStg
= new SotStorage( *pStrm
);
609 else if ( !(SW_STREAM_READER
& GetReaderType()) )
621 int Reader::GetReaderType()
623 return SW_STREAM_READER
;
627 void Reader::SetFltName( const String
& )
632 void Reader::ResetFrmFmtAttrs( SfxItemSet
&rFrmSet
)
634 rFrmSet
.Put( SvxLRSpaceItem(RES_LR_SPACE
) );
635 rFrmSet
.Put( SvxULSpaceItem(RES_UL_SPACE
) );
636 rFrmSet
.Put( SvxBoxItem(RES_BOX
) );
640 void Reader::ResetFrmFmts( SwDoc
& rDoc
)
642 for (sal_uInt16 i
=0; i
<3; ++i
)
648 OSL_ENSURE(i
== 0, "Impossible");
651 nPoolId
= RES_POOLFRM_FRAME
;
654 nPoolId
= RES_POOLFRM_GRAPHIC
;
657 nPoolId
= RES_POOLFRM_OLE
;
661 SwFrmFmt
*pFrmFmt
= rDoc
.GetFrmFmtFromPool( nPoolId
);
663 pFrmFmt
->ResetFmtAttr( RES_LR_SPACE
);
664 pFrmFmt
->ResetFmtAttr( RES_UL_SPACE
);
665 pFrmFmt
->ResetFmtAttr( RES_BOX
);
669 // read the sections of the document, which is equal to the medium.
670 // returns the count of it
671 size_t Reader::GetSectionList( SfxMedium
&, std::vector
<String
*>& ) const
676 // ------------------------------------------------
677 sal_Bool
SwReader::HasGlossaries( const Reader
& rOptions
)
679 // Variable uebertragen
680 Reader
* po
= (Reader
*) &rOptions
;
683 po
->bInsertMode
= sal_False
;
685 // ist ein Medium angegeben, dann aus diesem die Streams besorgen
686 sal_Bool bRet
= sal_False
;
687 if( !( 0 != (po
->pMedium
= pMedium
) && !po
->SetStrmStgPtr() ))
688 bRet
= po
->HasGlossaries();
692 sal_Bool
SwReader::ReadGlossaries( const Reader
& rOptions
,
693 SwTextBlocks
& rBlocks
, sal_Bool bSaveRelFiles
)
695 // Variable uebertragen
696 Reader
* po
= (Reader
*) &rOptions
;
699 po
->bInsertMode
= sal_False
;
701 // ist ein Medium angegeben, dann aus diesem die Streams besorgen
702 sal_Bool bRet
= sal_False
;
703 if( !( 0 != (po
->pMedium
= pMedium
) && !po
->SetStrmStgPtr() ))
704 bRet
= po
->ReadGlossaries( rBlocks
, bSaveRelFiles
);
708 sal_Bool
Reader::HasGlossaries() const
713 sal_Bool
Reader::ReadGlossaries( SwTextBlocks
&, sal_Bool
) const
718 // ------------------------------------------------
720 int StgReader::GetReaderType()
722 return SW_STORAGE_READER
;
733 * Konstruktoren, Destruktoren sind inline (inc/shellio.hxx).
736 SwWriter::SwWriter(SvStream
& rStrm
, SwCrsrShell
&rShell
, sal_Bool bInWriteAll
)
737 : pStrm(&rStrm
), pMedium(0), pOutPam(0), pShell(&rShell
),
738 rDoc(*rShell
.GetDoc()), bWriteAll(bInWriteAll
)
742 SwWriter::SwWriter(SvStream
& rStrm
,SwDoc
&rDocument
)
743 : pStrm(&rStrm
), pMedium(0), pOutPam(0), pShell(0), rDoc(rDocument
),
748 SwWriter::SwWriter(SvStream
& rStrm
, SwPaM
& rPam
, sal_Bool bInWriteAll
)
749 : pStrm(&rStrm
), pMedium(0), pOutPam(&rPam
), pShell(0),
750 rDoc(*rPam
.GetDoc()), bWriteAll(bInWriteAll
)
754 SwWriter::SwWriter( const uno::Reference
< embed::XStorage
>& rStg
, SwDoc
&rDocument
)
755 : pStrm(0), xStg( rStg
), pMedium(0), pOutPam(0), pShell(0), rDoc(rDocument
), bWriteAll(true)
759 SwWriter::SwWriter(SfxMedium
& rMedium
, SwCrsrShell
&rShell
, sal_Bool bInWriteAll
)
760 : pStrm(0), pMedium(&rMedium
), pOutPam(0), pShell(&rShell
),
761 rDoc(*rShell
.GetDoc()), bWriteAll(bInWriteAll
)
765 SwWriter::SwWriter(SfxMedium
& rMedium
, SwDoc
&rDocument
)
766 : pStrm(0), pMedium(&rMedium
), pOutPam(0), pShell(0), rDoc(rDocument
),
771 sal_uLong
SwWriter::Write( WriterRef
& rxWriter
, const String
* pRealFileName
)
774 SwPauseThreadStarting aPauseThreadStarting
;
776 sal_Bool bHasMark
= sal_False
;
781 if ( pShell
&& !bWriteAll
&& pShell
->IsTableMode() )
783 bWriteAll
= sal_True
;
787 // kopiere Teile aus einer Tabelle: lege eine Tabelle mit der Breite
788 // von der Originalen an und kopiere die selectierten Boxen.
789 // Die Groessen werden prozentual korrigiert.
791 // lasse ueber das Layout die Boxen suchen
793 GetTblSel( *pShell
, aBoxes
);
794 SwTableNode
* pTblNd
= (SwTableNode
*)aBoxes
[0]->GetSttNd()->StartOfSectionNode();
795 SwNodeIndex
aIdx( pDoc
->GetNodes().GetEndOfExtras(), 2 );
796 SwCntntNode
*pNd
= aIdx
.GetNode().GetCntntNode();
797 OSL_ENSURE( pNd
, "Node not found" );
798 SwPosition
aPos( aIdx
, SwIndex( pNd
) );
799 pTblNd
->GetTable().MakeCopy( pDoc
, aPos
, aBoxes
);
802 if( !bWriteAll
&& ( pShell
|| pOutPam
))
805 pPam
= pShell
->GetCrsr();
811 // Erste Runde: Nachsehen, ob eine Selektion besteht.
814 bHasMark
= bHasMark
|| pPam
->HasMark();
815 pPam
= (SwPaM
*) pPam
->GetNext();
816 if(bHasMark
|| pPam
== pEnd
)
820 // Wenn keine Selektion besteht, eine ueber das ganze Dokument aufspannen.
826 pShell
->SttEndDoc(sal_True
);
828 pShell
->SttEndDoc(sal_False
);
832 pPam
= new SwPaM( *pPam
);
833 pPam
->Move( fnMoveBackward
, fnGoDoc
);
835 pPam
->Move( fnMoveForward
, fnGoDoc
);
838 // pPam ist immer noch der akt. Cursor !!
842 // keine Shell oder alles schreiben -> eigenen Pam erzeugen
843 SwDoc
* pOutDoc
= pDoc
? pDoc
: &rDoc
;
844 pPam
= new SwPaM( pOutDoc
->GetNodes().GetEndOfContent() );
845 if( pOutDoc
->IsClipBoard() )
847 pPam
->Move( fnMoveBackward
, fnGoDoc
);
849 pPam
->Move( fnMoveForward
, fnGoDoc
);
854 pPam
->Move( fnMoveBackward
, fnGoDoc
);
858 rxWriter
->bWriteAll
= bWriteAll
;
859 SwDoc
* pOutDoc
= pDoc
? pDoc
: &rDoc
;
861 // falls der Standart PageDesc. immer noch auf initalen Werten steht
862 // (wenn z.B. kein Drucker gesetzt wurde) dann setze jetzt auf DIN A4
863 // #i37248# - Modifications are only allowed at a new document.
864 // <pOutDoc> contains a new document, if <pDoc> is set - see above.
865 if ( pDoc
&& !pOutDoc
->getPrinter( false ) )
867 const SwPageDesc
& rPgDsc
= pOutDoc
->GetPageDesc( 0 );
868 //const SwPageDesc& rPgDsc = *pOutDoc->GetPageDescFromPool( RES_POOLPAGE_STANDARD );
869 const SwFmtFrmSize
& rSz
= rPgDsc
.GetMaster().GetFrmSize();
870 // Clipboard-Dokument wird immer ohne Drucker angelegt, so ist
871 // der Std.PageDesc immer aug LONG_MAX !! Mappe dann auf DIN A4
872 if( LONG_MAX
== rSz
.GetHeight() || LONG_MAX
== rSz
.GetWidth() )
874 SwPageDesc
aNew( rPgDsc
);
875 SwFmtFrmSize
aNewSz( rSz
);
876 Size
a4(SvxPaperInfo::GetPaperSize( PAPER_A4
));
877 aNewSz
.SetHeight( a4
.Width() );
878 aNewSz
.SetWidth( a4
.Height() );
879 aNew
.GetMaster().SetFmtAttr( aNewSz
);
880 pOutDoc
->ChgPageDesc( 0, aNew
);
884 sal_Bool
bLockedView(sal_False
);
885 SwEditShell
* pESh
= pOutDoc
->GetEditShell();
888 bLockedView
= pESh
->IsViewLocked();
889 pESh
->LockView( sal_True
); //lock visible section
890 pESh
->StartAllAction();
893 sal_Bool bWasPurgeOle
= pOutDoc
->get(IDocumentSettingAccess::PURGE_OLE
);
894 pOutDoc
->set(IDocumentSettingAccess::PURGE_OLE
, false);
896 sal_uLong nError
= 0;
898 nError
= rxWriter
->Write( *pPam
, *pMedium
, pRealFileName
);
900 nError
= rxWriter
->Write( *pPam
, *pStg
, pRealFileName
);
902 nError
= rxWriter
->Write( *pPam
, *pStrm
, pRealFileName
);
904 nError
= rxWriter
->Write( *pPam
, xStg
, pRealFileName
);
906 pOutDoc
->set(IDocumentSettingAccess::PURGE_OLE
, bWasPurgeOle
);
910 pESh
->EndAllAction();
911 pESh
->LockView( bLockedView
);
914 // Falls nur zum Schreiben eine Selektion aufgespannt wurde, vor der
915 // Rueckkehr den alten Crsr wieder herstellen.
916 if( !bWriteAll
&& ( pShell
|| pOutPam
))
921 pShell
->Pop( sal_False
);
928 delete pPam
; // loesche den hier erzeugten Pam
929 // Alles erfolgreich geschrieben? Sag' das dem Dokument!
930 if ( !IsError( nError
) && !pDoc
)
932 rDoc
.ResetModified();
933 // #i38810# - reset also flag, that indicates updated links
934 rDoc
.SetLinksUpdated( sal_False
);
940 if ( !pDoc
->release() )
942 bWriteAll
= sal_False
;
950 // ----------------------------------------------------------------------
953 sal_Bool
SetHTMLTemplate( SwDoc
& rDoc
)
955 // Vorlagennamen von den Sfx-HTML-Filter besorgen!!!
956 if( !ReadHTML
->GetTemplateDoc() )
957 ReadHTML
->MakeHTMLDummyTemplateDoc();
959 sal_Bool bRet
= ReadHTML
->SetTemplate( rDoc
);
961 SwNodes
& rNds
= rDoc
.GetNodes();
962 SwNodeIndex
aIdx( rNds
.GetEndOfExtras(), 1 );
963 SwCntntNode
* pCNd
= rNds
.GoNext( &aIdx
);
967 ( SwFmtPageDesc(rDoc
.GetPageDescFromPool(RES_POOLPAGE_HTML
, false) ) );
968 pCNd
->ChgFmtColl( rDoc
.GetTxtCollFromPool( RES_POOLCOLL_TEXT
, false ));
975 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */