update credits
[LibreOffice.git] / sw / source / filter / basflt / shellio.cxx
bloba17f91d5409410d2be4b7b65d31221d8feb0689c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
32 #include <node.hxx>
33 #include <docary.hxx>
34 #include <fmtanchr.hxx>
35 #include <fmtfsize.hxx>
36 #include <fmtpdsc.hxx>
37 #include <swtypes.hxx>
38 #include <shellio.hxx>
39 #include <doc.hxx>
40 #include <IDocumentUndoRedo.hxx>
41 #include <pam.hxx>
42 #include <editsh.hxx>
43 #include <undobj.hxx> // fuer Undo Insert-Dokument
44 #include <swundo.hxx> // fuer Undo Insert-Dokument
45 #include <swtable.hxx>
46 #include <tblsel.hxx>
47 #include <pagedesc.hxx>
48 #include <poolfmt.hxx>
49 #include <fltini.hxx>
50 #include <docsh.hxx>
51 #include <redline.hxx>
52 #include <swerror.h>
53 #include <paratr.hxx>
55 // #i73788#
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;
66 po->pStrm = pStrm;
67 po->pStg = pStg;
68 po->xStg = xStg;
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;
84 GetDoc();
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) );
93 SwPaM *pPam;
94 if( pCrsr )
95 pPam = pCrsr;
96 else
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
106 // wurde.
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
112 // ersten ist.
113 SwPaM *pEnd = pPam;
114 SwUndoInsDoc* pUndo = 0;
116 sal_Bool bReadPageDescs = sal_False;
117 bool const bDocUndo = pDoc->GetIDocumentUndoRedo().DoesUndo();
118 bool bSaveUndo = bDocUndo && pCrsr;
119 if( bSaveUndo )
121 // das Einlesen von Seitenvorlagen ist nicht Undofaehig!
122 if( 0 != ( bReadPageDescs = po->aOpt.IsPageDescs() ) )
124 bSaveUndo = false;
125 pDoc->GetIDocumentUndoRedo().DelAllUndoObj();
127 else
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();
145 while( true )
147 if( bSaveUndo )
148 pUndo = new SwUndoInsDoc( *pPam );
150 pDoc->SetRedlineMode_intern( nsRedlineMode_t::REDLINE_IGNORE );
152 SwPaM* pUndoPam = 0;
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
161 if( pCrsr )
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
170 // pflegen.
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
186 aEndPos--;
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 )
194 nEndCntnt = 0;
195 else
196 nEndCntnt = nLen - nEndCntnt;
197 pPam->GetPoint()->nContent.Assign( pCNd, nEndCntnt );
199 const SwStartNode* pTblBoxStart = pCNd->FindTableBoxStartNode();
200 if ( pTblBoxStart )
202 SwTableBox* pBox = pTblBoxStart->GetTblBox();
203 if ( pBox )
205 pDoc->ChkBoxNumFmt( *pBox, sal_True );
210 if( pCrsr )
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 );
218 else
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
225 // Objecte
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())
235 || ( pFrameAnchor
236 && ( ( (FLY_AT_PARA == rAnchor.GetAnchorId())
237 && ( (pUndoPam->GetPoint()->nNode ==
238 pFrameAnchor->nNode)
239 || (pUndoPam->GetMark()->nNode ==
240 pFrameAnchor->nNode)
243 // #i97570# also check frames anchored AT char
244 || ( (FLY_AT_CHAR == rAnchor.GetAnchorId())
245 && !IsDestroyFrameAnchoredAtChar(
246 *pFrameAnchor,
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
259 // erlaubt!
260 pFrmFmt->DelFrms();
261 pDoc->DelFrmFmt( pFrmFmt );
262 --n;
264 else
266 if( bSaveUndo )
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
279 // also weg damit.
280 pFrmFmt->DelFrms();
283 if (FLY_AT_PAGE == rAnchor.GetAnchorId())
285 if( !rAnchor.GetCntntAnchor() )
287 pFrmFmt->MakeFrms();
289 else if( pCrsr )
291 pDoc->SetContainsAtPageObjWithContentAnchor( true );
294 else
295 pFrmFmt->MakeFrms();
300 if( !aFlyFrmArr.empty() )
301 aFlyFrmArr.clear();
303 pDoc->SetRedlineMode_intern( eOld );
304 if( pDoc->IsRedlineOn() )
305 pDoc->AppendRedline( new SwRedline( nsRedlineType_t::REDLINE_INSERT, *pUndoPam ), true);
306 else
307 pDoc->SplitRedline( *pUndoPam );
308 pDoc->SetRedlineMode_intern( nsRedlineMode_t::REDLINE_IGNORE );
310 if( bSaveUndo )
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 );
321 delete pUndoPam;
323 pPam = (SwPaM *) pPam->GetNext();
324 if( pPam == pEnd )
325 break;
327 // only read templates? then ignore multi selection! Bug 68593
328 if( bFmtsOnly )
329 break;
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
336 if( pStrm )
338 pStrm->Seek(0);
339 pStrm->ResetError();
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);
353 if (!bReadPageDescs)
355 if( bSaveUndo )
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.
364 if( !pCrsr )
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
384 pDoc->SetModified();
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() )
391 pDoc->SetModified();
394 po->SetReadUTF8( sal_False );
395 po->SetBlockMode( sal_False );
396 po->SetOrganizerMode( sal_False );
397 po->SetIgnoreHTMLComments( sal_False );
399 return nError;
404 * Konstruktoren, Destruktor
407 SwReader::SwReader(SfxMedium& rMedium, const String& rFileName, SwDoc *pDocument)
408 : SwDocFac(pDocument), pStrm(0), pMedium(&rMedium), pCrsr(0),
409 aFileName(rFileName)
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),
418 aFileName(rFileName)
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)
435 Reader::Reader()
436 : pTemplate(0),
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)
446 Reader::~Reader()
448 delete pTemplate;
451 String Reader::GetTemplateName() const
453 return aEmptyStr;
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() )
466 ClearTemplate();
467 else
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 );
473 bool bLoad = false;
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 ))
486 bLoad = true;
487 aDStamp = aTstDate;
488 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 );
497 if( bLoad )
499 ClearTemplate();
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
505 // for the help.
506 SvtModuleOptions aModuleOptions;
507 if( aModuleOptions.IsWriter() )
509 SwDocShell *pDocSh =
510 new SwDocShell ( SFX_CREATE_MODE_INTERNAL );
511 SfxObjectShellLock xDocSh = pDocSh;
512 if( pDocSh->DoInitNew( 0 ) )
514 pTemplate = pDocSh->GetDoc();
515 pTemplate->SetOle2Link( Link() );
516 // always FALSE
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!" );
537 return pTemplate;
540 sal_Bool Reader::SetTemplate( SwDoc& rDoc )
542 sal_Bool bRet = sal_False;
544 GetTemplateDoc();
545 if( pTemplate )
547 rDoc.RemoveAllFmtLanguageDependencies();
548 rDoc.ReplaceStyles( *pTemplate );
549 rDoc.SetFixFields(false, NULL);
550 bRet = sal_True;
553 return bRet;
556 void Reader::ClearTemplate()
558 if( pTemplate )
560 if( 0 == pTemplate->release() )
561 delete pTemplate,
562 pTemplate = 0;
566 void Reader::SetTemplateName( const String& rDir )
568 if( rDir.Len() && aTemplateNm != rDir )
570 ClearTemplate();
571 aTemplateNm = rDir;
575 void Reader::MakeHTMLDummyTemplateDoc()
577 ClearTemplate();
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();
598 return sal_True;
601 else
603 pStrm = pMedium->GetInStream();
604 if ( pStrm && SotStorage::IsStorageFile(pStrm) && (SW_STORAGE_READER & GetReaderType()) )
606 pStg = new SotStorage( *pStrm );
607 pStrm = NULL;
609 else if ( !(SW_STREAM_READER & GetReaderType()) )
611 pStrm = NULL;
612 return sal_False;
615 return sal_True;
617 return sal_False;
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)
644 sal_uInt16 nPoolId;
645 switch (i)
647 default:
648 OSL_ENSURE(i == 0, "Impossible");
649 //fallthrough
650 case 0:
651 nPoolId = RES_POOLFRM_FRAME;
652 break;
653 case 1:
654 nPoolId = RES_POOLFRM_GRAPHIC;
655 break;
656 case 2:
657 nPoolId = RES_POOLFRM_OLE;
658 break;
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
673 return 0;
676 // ------------------------------------------------
677 sal_Bool SwReader::HasGlossaries( const Reader& rOptions )
679 // Variable uebertragen
680 Reader* po = (Reader*) &rOptions;
681 po->pStrm = pStrm;
682 po->pStg = pStg;
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();
689 return bRet;
692 sal_Bool SwReader::ReadGlossaries( const Reader& rOptions,
693 SwTextBlocks& rBlocks, sal_Bool bSaveRelFiles )
695 // Variable uebertragen
696 Reader* po = (Reader*) &rOptions;
697 po->pStrm = pStrm;
698 po->pStg = pStg;
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 );
705 return bRet;
708 sal_Bool Reader::HasGlossaries() const
710 return sal_False;
713 sal_Bool Reader::ReadGlossaries( SwTextBlocks&, sal_Bool ) const
715 return sal_False;
718 // ------------------------------------------------
720 int StgReader::GetReaderType()
722 return SW_STORAGE_READER;
729 * Writer
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),
744 bWriteAll(true)
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),
767 bWriteAll(true)
771 sal_uLong SwWriter::Write( WriterRef& rxWriter, const String* pRealFileName )
773 // #i73788#
774 SwPauseThreadStarting aPauseThreadStarting;
776 sal_Bool bHasMark = sal_False;
777 SwPaM * pPam;
779 SwDoc *pDoc = 0;
781 if ( pShell && !bWriteAll && pShell->IsTableMode() )
783 bWriteAll = sal_True;
784 pDoc = new SwDoc;
785 pDoc->acquire();
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
792 SwSelBoxes aBoxes;
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 ))
804 if( pShell )
805 pPam = pShell->GetCrsr();
806 else
807 pPam = pOutPam;
809 SwPaM *pEnd = pPam;
811 // Erste Runde: Nachsehen, ob eine Selektion besteht.
812 while(true)
814 bHasMark = bHasMark || pPam->HasMark();
815 pPam = (SwPaM *) pPam->GetNext();
816 if(bHasMark || pPam == pEnd)
817 break;
820 // Wenn keine Selektion besteht, eine ueber das ganze Dokument aufspannen.
821 if(!bHasMark)
823 if( pShell )
825 pShell->Push();
826 pShell->SttEndDoc(sal_True);
827 pShell->SetMark();
828 pShell->SttEndDoc(sal_False);
830 else
832 pPam = new SwPaM( *pPam );
833 pPam->Move( fnMoveBackward, fnGoDoc );
834 pPam->SetMark();
835 pPam->Move( fnMoveForward, fnGoDoc );
838 // pPam ist immer noch der akt. Cursor !!
840 else
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 );
848 pPam->SetMark();
849 pPam->Move( fnMoveForward, fnGoDoc );
851 else
853 pPam->SetMark();
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();
886 if( pESh )
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;
897 if( pMedium )
898 nError = rxWriter->Write( *pPam, *pMedium, pRealFileName );
899 else if( pStg )
900 nError = rxWriter->Write( *pPam, *pStg, pRealFileName );
901 else if( pStrm )
902 nError = rxWriter->Write( *pPam, *pStrm, pRealFileName );
903 else if( xStg.is() )
904 nError = rxWriter->Write( *pPam, xStg, pRealFileName );
906 pOutDoc->set(IDocumentSettingAccess::PURGE_OLE, bWasPurgeOle );
908 if( pESh )
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 ))
918 if(!bHasMark)
920 if( pShell )
921 pShell->Pop( sal_False );
922 else
923 delete pPam;
926 else
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 );
938 if ( pDoc )
940 if ( !pDoc->release() )
941 delete pDoc;
942 bWriteAll = sal_False;
945 return nError;
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 );
964 if( pCNd )
966 pCNd->SetAttr
967 ( SwFmtPageDesc(rDoc.GetPageDescFromPool(RES_POOLPAGE_HTML, false) ) );
968 pCNd->ChgFmtColl( rDoc.GetTxtCollFromPool( RES_POOLCOLL_TEXT, false ));
971 return bRet;
975 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */