1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 #define ROLBCK_HISTORY_ONLY // Der Kampf gegen die CLOOK's
27 #include <doc.hxx>
28 #include <dcontact.hxx>
29 #include <com/sun/star/document/PrinterIndependentLayout.hpp>
30 #include <com/sun/star/document/UpdateDocMode.hpp>
31 #include <com/sun/star/text/XTextDocument.hpp>
32 #include <com/sun/star/linguistic2/XProofreadingIterator.hpp>
33 #include <com/sun/star/text/XFlatParagraphIteratorProvider.hpp>
34
35 #include <unotools/processfactory.hxx>
36 #include <vcl/svapp.hxx>
37 #include <vcl/virdev.hxx>
38 #include <rtl/logfile.hxx>
39 #include <sfx2/printer.hxx>
40 #include <sfx2/docfile.hxx>
41 #include <sfx2/frame.hxx>
42 #include <sfx2/viewfrm.hxx>
43
44 #include <svl/macitem.hxx>
45 #include <svx/svxids.hrc>
46 #include <svx/svdogrp.hxx>
47 #include <sfx2/linkmgr.hxx>
48 #include <editeng/forbiddencharacterstable.hxx>
49 #include <svl/zforlist.hxx>
50 #include <unotools/compatibility.hxx>
51 #include <unotools/lingucfg.hxx>
52 #include <svx/svdpage.hxx>
53 #include <paratr.hxx>
54 #include <fchrfmt.hxx>
55 #include <fmtcntnt.hxx>
56 #include <fmtanchr.hxx>
57 #include <fmtfsize.hxx>
58 #include <fmtfordr.hxx>
59 #include <fmtpdsc.hxx>
60 #include <pvprtdat.hxx>
61 #include <rootfrm.hxx> //Damit der RootDtor gerufen wird.
62 #include <layouter.hxx>
63 #include <pagedesc.hxx> //Damit die PageDescs zerstoert werden koennen.
64 #include <ndtxt.hxx>
65 #include <printdata.hxx>
66 #include <docfld.hxx>
67 #include <ftninfo.hxx>
68 #include <ftnidx.hxx>
69 #include <docstat.hxx>
70 #include <charfmt.hxx>
71 #include <frmfmt.hxx>
72 #include <rolbck.hxx> // Undo-Attr, SwHistory
73 #include <poolfmt.hxx> // fuer die Pool-Vorlage
74 #include <dbmgr.hxx>
75 #include <docsh.hxx>
76 #include <acorrect.hxx> // fuer die autom. Aufnahme von Ausnahmen
77 #include <visiturl.hxx> // fuer die URL-Change Benachrichtigung
78 #include <docary.hxx>
79 #include <lineinfo.hxx>
80 #include <drawdoc.hxx>
81 #include <linkenum.hxx>
82 #include <fldupde.hxx>
83 #include <extinput.hxx>
84 #include <viewsh.hxx>
85 #include <doctxm.hxx>
86 #include <shellres.hxx>
87 #include <breakit.hxx>
88 #include <laycache.hxx>
89 #include <mvsave.hxx>
90 #include <istyleaccess.hxx>
91 #include <swstylemanager.hxx>
92 #include <IGrammarContact.hxx>
93 #include <tblsel.hxx>
94 #include <MarkManager.hxx>
95 #include <UndoManager.hxx>
96 #include <unochart.hxx>
97
98 #include <cmdid.h> // fuer den dflt - Printer in SetJob
99
100
101 // --> OD 2006-04-19 #b6375613#
102 #include <com/sun/star/document/XDocumentInfoSupplier.hpp>
103 #include <com/sun/star/beans/XPropertyContainer.hpp>
104 #include <com/sun/star/beans/PropertyAttribute.hpp>
105
106 // <--
107
108 // --> OD 2007-03-16 #i73788#
109 #include <pausethreadstarting.hxx>
110 // <--
111 #include <numrule.hxx>
112 // --> OD 2008-03-13 #refactorlists#
113 #include <list.hxx>
114 #include <listfunc.hxx>
115 // <--
116
117 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
118
119 #include <sfx2/Metadatable.hxx>
120 #include <fmtmeta.hxx> // MetaFieldManager
121 #include <unotools/securityoptions.hxx>
122
123
124 using namespace ::com::sun::star;
125 using namespace ::com::sun::star::document;
126
127 const sal_Char __FAR_DATA sFrmFmtStr[] = "Frameformat";
128 const sal_Char __FAR_DATA sEmptyPageStr[] = "Empty Page";
129 const sal_Char __FAR_DATA sColumnCntStr[] = "Columncontainer";
130 const sal_Char __FAR_DATA sCharFmtStr[] = "Zeichenformat";
131 const sal_Char __FAR_DATA sTxtCollStr[] = "Textformatvorlage";
132 const sal_Char __FAR_DATA sGrfCollStr[] = "Graphikformatvorlage";
133
SV_IMPL_PTRARR(SwNumRuleTbl,SwNumRulePtr)134 SV_IMPL_PTRARR( SwNumRuleTbl, SwNumRulePtr)
135 SV_IMPL_PTRARR( SwTxtFmtColls, SwTxtFmtCollPtr)
136 SV_IMPL_PTRARR( SwGrfFmtColls, SwGrfFmtCollPtr)
137
138 /*
139 * global functions...
140 */
141
142 uno::Reference< linguistic2::XProofreadingIterator > SwDoc::GetGCIterator() const
143 {
144 if (!m_xGCIterator.is() && SvtLinguConfig().HasGrammarChecker())
145 {
146 uno::Reference< lang::XMultiServiceFactory > xMgr( utl::getProcessServiceFactory() );
147 if (xMgr.is())
148 {
149 try
150 {
151 rtl::OUString aServiceName( rtl::OUString::createFromAscii("com.sun.star.linguistic2.ProofreadingIterator") );
152 m_xGCIterator = uno::Reference< linguistic2::XProofreadingIterator >
153 ( xMgr->createInstance( aServiceName ), uno::UNO_QUERY_THROW );
154 }
155 catch (uno::Exception &)
156 {
157 DBG_ERROR( "No GCIterator" );
158 }
159 }
160 }
161
162 return m_xGCIterator;
163 }
164
StartGrammarChecking(SwDoc & rDoc)165 void StartGrammarChecking( SwDoc &rDoc )
166 {
167 // check for a visible view
168 bool bVisible = false;
169 const SwDocShell *pDocShell = rDoc.GetDocShell();
170 SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pDocShell, sal_False );
171 while (pFrame && !bVisible)
172 {
173 if (pFrame->IsVisible())
174 bVisible = true;
175 pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell, sal_False );
176 }
177
178 //!! only documents with visible views need to be checked
179 //!! (E.g. don't check temporary documents created for printing, see printing of notes and selections.
180 //!! Those get created on the fly and get hard deleted a bit later as well, and no one should have
181 //!! a uno reference to them)
182 if (bVisible)
183 {
184 uno::Reference< linguistic2::XProofreadingIterator > xGCIterator( rDoc.GetGCIterator() );
185 if ( xGCIterator.is() )
186 {
187 uno::Reference< lang::XComponent > xDoc( rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY );
188 uno::Reference< text::XFlatParagraphIteratorProvider > xFPIP( xDoc, uno::UNO_QUERY );
189
190 // start automatic background checking if not active already
191 if ( xFPIP.is() && !xGCIterator->isProofreading( xDoc ) )
192 xGCIterator->startProofreading( xDoc, xFPIP );
193 }
194 }
195 }
196
197 /*
198 * interne Funktionen
199 */
200
201
202
lcl_DelFmtIndizes(const SwFrmFmtPtr & rpFmt,void *)203 sal_Bool lcl_DelFmtIndizes( const SwFrmFmtPtr& rpFmt, void* )
204 {
205 SwFmtCntnt &rFmtCntnt = (SwFmtCntnt&)rpFmt->GetCntnt();
206 if ( rFmtCntnt.GetCntntIdx() )
207 rFmtCntnt.SetNewCntntIdx( 0 );
208 SwFmtAnchor &rFmtAnchor = (SwFmtAnchor&)rpFmt->GetAnchor();
209 if ( rFmtAnchor.GetCntntAnchor() )
210 rFmtAnchor.SetAnchor( 0 );
211 return sal_True;
212 }
213
214 /*
215 * exportierte Methoden
216 */
217
SwDoc()218 SwDoc::SwDoc()
219 : m_pNodes( new SwNodes(this) )
220 ,
221 mpAttrPool(new SwAttrPool(this)),
222 pMarkManager(new ::sw::mark::MarkManager(*this)),
223 m_pMetaFieldManager(new ::sw::MetaFieldManager()),
224 m_pUndoManager(new ::sw::UndoManager(
225 ::std::auto_ptr<SwNodes>(new SwNodes(this)), *this, *this, *this)),
226 pDfltFrmFmt( new SwFrmFmt( GetAttrPool(), sFrmFmtStr, 0 ) ),
227 pEmptyPageFmt( new SwFrmFmt( GetAttrPool(), sEmptyPageStr, pDfltFrmFmt ) ),
228 pColumnContFmt( new SwFrmFmt( GetAttrPool(), sColumnCntStr, pDfltFrmFmt ) ),
229 pDfltCharFmt( new SwCharFmt( GetAttrPool(), sCharFmtStr, 0 ) ),
230 pDfltTxtFmtColl( new SwTxtFmtColl( GetAttrPool(), sTxtCollStr ) ),
231 pDfltGrfFmtColl( new SwGrfFmtColl( GetAttrPool(), sGrfCollStr ) ),
232 pFrmFmtTbl( new SwFrmFmts() ),
233 pCharFmtTbl( new SwCharFmts() ),
234 pSpzFrmFmtTbl( new SwSpzFrmFmts() ),
235 pSectionFmtTbl( new SwSectionFmts() ),
236 pTblFrmFmtTbl( new SwFrmFmts() ),
237 pTxtFmtCollTbl( new SwTxtFmtColls() ),
238 pGrfFmtCollTbl( new SwGrfFmtColls() ),
239 pTOXTypes( new SwTOXTypes() ),
240 pDefTOXBases( new SwDefTOXBase_Impl() ),
241 pCurrentView( 0 ), //swmod 071225
242 pDrawModel( 0 ),
243 pUpdtFlds( new SwDocUpdtFld() ),
244 pFldTypes( new SwFldTypes() ),
245 pVirDev( 0 ),
246 pPrt( 0 ),
247 pPrtData( 0 ),
248 pGlossaryDoc( 0 ),
249 pOutlineRule( 0 ),
250 pFtnInfo( new SwFtnInfo ),
251 pEndNoteInfo( new SwEndNoteInfo ),
252 pLineNumberInfo( new SwLineNumberInfo ),
253 pFtnIdxs( new SwFtnIdxs ),
254 pDocStat( new SwDocStat ),
255 pDocShell( 0 ),
256 pLinkMgr( new sfx2::LinkManager( 0 ) ),
257 pACEWord( 0 ),
258 pURLStateChgd( 0 ),
259 pNumberFormatter( 0 ),
260 pNumRuleTbl( new SwNumRuleTbl ),
261 // --> OD 2008-03-26 #refactorlists#
262 maLists(),
263 maListStyleLists(),
264 // <--
265 pRedlineTbl( new SwRedlineTbl ),
266 pAutoFmtRedlnComment( 0 ),
267 pUnoCrsrTbl( new SwUnoCrsrTbl( 0, 16 ) ),
268 pPgPViewPrtData( 0 ),
269 pExtInputRing( 0 ),
270 pLayouter( 0 ),
271 // --> OD 2008-03-07 #refactorlists#
272 pStyleAccess( 0 ),
273 // <--
274 pLayoutCache( 0 ),
275 pUnoCallBack(new SwModify(0)),
276 mpGrammarContact( 0 ),
277 aChartDataProviderImplRef(),
278 pChartControllerHelper( 0 ),
279 // --> OD 2007-10-31 #i83479#
280 mpListItemsList( new tImplSortedNodeNumList() ),
281 // <--
282 m_pXmlIdRegistry(),
283 nAutoFmtRedlnCommentNo( 0 ),
284 nLinkUpdMode( GLOBALSETTING ),
285 eFldUpdMode( AUTOUPD_GLOBALSETTING ),
286 eRedlineMode((RedlineMode_t)(nsRedlineMode_t::REDLINE_SHOW_INSERT | nsRedlineMode_t::REDLINE_SHOW_DELETE)),
287 eChrCmprType( CHARCOMPRESS_NONE ),
288 mReferenceCount(0),
289 mIdleBlockCount(0),
290 nLockExpFld( 0 ),
291 mbReadlineChecked(false),
292 // --> OD 2005-02-11 #i38810#
293 mbLinksUpdated( sal_False ),
294 mbClipBoard( false ),
295 mbColumnSelection( false ),
296 mbContainsAtPageObjWithContentAnchor( false ),
297 // i#78591#
298 mbProtectForm(false),
299 mbLastBrowseMode( false ),
300 n32DummyCompatabilityOptions1(0),
301 n32DummyCompatabilityOptions2(0),
302 mbStartIdleTimer(sal_False),
303 meDocType( DOCTYPE_NATIVE )
304 {
305 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDoc::SwDoc" );
306
307 mbGlossDoc =
308 mbModified =
309 mbDtor =
310 mbPageNums =
311 mbLoaded =
312 mbUpdateExpFld =
313 mbNewDoc =
314 mbCopyIsMove =
315 mbInReading =
316 mbInXMLImport =
317 mbUpdateTOX =
318 mbInLoadAsynchron =
319 mbHTMLMode =
320 mbInCallModified =
321 mbIsGlobalDoc =
322 mbGlblDocSaveLinks =
323 mbIsLabelDoc =
324 mbIsAutoFmtRedline =
325 mbOLEPrtNotifyPending =
326 mbAllOLENotify =
327 mbIsRedlineMove =
328 mbInsOnlyTxtGlssry =
329 mbContains_MSVBasic =
330 mbKernAsianPunctuation =
331 #ifdef DBG_UTIL
332 mbXMLExport =
333 #endif
334 // --> OD 2006-03-21 #b6375613#
335 mbApplyWorkaroundForB6375613 =
336 // <--
337 false;
338
339 mbNewFldLst =
340 mbVisibleLinks =
341 mbPurgeOLE =
342 true;
343
344 pLinkMgr->SetAutoAskUpdateAllLinks();
345 //
346 // COMPATIBILITY FLAGS START
347 //
348
349 // Note: Any non-hidden compatibility flag should obtain its default
350 // by asking SvtCompatibilityOptions, see below.
351 //
352 const SvtCompatibilityOptions aOptions;
353 mbParaSpaceMax = aOptions.IsAddSpacing();
354 mbParaSpaceMaxAtPages = aOptions.IsAddSpacingAtPages();
355 mbTabCompat = !aOptions.IsUseOurTabStops();
356 mbUseVirtualDevice = !aOptions.IsUsePrtDevice();
357 mbAddExternalLeading = !aOptions.IsNoExtLeading();
358 mbOldLineSpacing = aOptions.IsUseLineSpacing();
359 mbAddParaSpacingToTableCells = aOptions.IsAddTableSpacing();
360 mbUseFormerObjectPos = aOptions.IsUseObjectPositioning();
361 mbUseFormerTextWrapping = aOptions.IsUseOurTextWrapping();
362 mbConsiderWrapOnObjPos = aOptions.IsConsiderWrappingStyle();
363 mbMathBaselineAlignment = false; // default for *old* documents is 'off'
364 mbAddFlyOffsets = false; // hidden
365 mbOldNumbering = false; // hidden
366 mbUseHiResolutionVirtualDevice = true; // hidden
367 mbIgnoreFirstLineIndentInNumbering = false; // hidden
368 mbDoNotJustifyLinesWithManualBreak = !aOptions.IsExpandWordSpace();
369 mbDoNotResetParaAttrsForNumFont = false; // hidden
370 mbOutlineLevelYieldsOutlineRule = false; // hidden
371 mbTableRowKeep = false; // hidden
372 mbIgnoreTabsAndBlanksForLineCalculation = false; // hidden
373 mbDoNotCaptureDrawObjsOnPage = false; // hidden
374 mbClipAsCharacterAnchoredWriterFlyFrames= false; // hidden
375 mbUnixForceZeroExtLeading = false; // hidden
376 mbOldPrinterMetrics = false; // hidden
377 mbTabRelativeToIndent = true; // hidden
378 // --> OD 2008-06-05 #i89181#
379 mbTabAtLeftIndentForParagraphsInList = false; // hidden
380 // <--
381
382 //
383 // COMPATIBILITY FLAGS END
384 //
385
386 pMacroTable = new SvxMacroTableDtor;
387
388 mpGrammarContact = ::createGrammarContact();
389
390 /*
391 * Defaultformate und DefaultFormatsammlungen (FmtColl)
392 * werden an der Position 0 in das jeweilige Array eingetragen.
393 * Die Formate der FmtColls sind von den Defaultformaten
394 * abgeleitet und stehen auch in der Liste.
395 */
396 /* Formate */
397 pFrmFmtTbl->Insert(pDfltFrmFmt, 0 );
398 pCharFmtTbl->Insert(pDfltCharFmt, 0 );
399
400 /* FmtColls */
401 // TXT
402 pTxtFmtCollTbl->Insert(pDfltTxtFmtColl, 0 );
403 // GRF
404 pGrfFmtCollTbl->Insert(pDfltGrfFmtColl, 0 );
405
406 // PageDesc, EmptyPageFmt und ColumnFmt anlegen
407 if ( !aPageDescs.Count() )
408 GetPageDescFromPool( RES_POOLPAGE_STANDARD );
409
410 //Leere Seite Einstellen.
411 pEmptyPageFmt->SetFmtAttr( SwFmtFrmSize( ATT_FIX_SIZE ) );
412 //BodyFmt fuer Spalten Einstellen.
413 pColumnContFmt->SetFmtAttr( SwFmtFillOrder( ATT_LEFT_TO_RIGHT ) );
414
415 _InitFieldTypes();
416
417 // lege (fuer die Filter) eine Default-OutlineNumRule an
418 // --> OD 2008-02-11 #newlistlevelattrs#
419 pOutlineRule = new SwNumRule( String::CreateFromAscii( SwNumRule::GetOutlineRuleName() ),
420 // --> OD 2008-06-06 #i89178#
421 numfunc::GetDefaultPositionAndSpaceMode(),
422 // <--
423 OUTLINE_RULE );
424 // <--
425 // #115901#
426 AddNumRule(pOutlineRule);
427 // --> OD 2005-10-21 - counting of phantoms depends on <IsOldNumbering()>
428 pOutlineRule->SetCountPhantoms( !get(IDocumentSettingAccess::OLD_NUMBERING) );
429 // <--
430
431 new SwTxtNode(
432 SwNodeIndex(GetUndoManager().GetUndoNodes().GetEndOfContent()),
433 pDfltTxtFmtColl );
434 new SwTxtNode( SwNodeIndex( GetNodes().GetEndOfContent() ),
435 GetTxtCollFromPool( RES_POOLCOLL_STANDARD ));
436
437 // den eigenen IdleTimer setzen
438 aIdleTimer.SetTimeout( 600 );
439 aIdleTimer.SetTimeoutHdl( LINK(this, SwDoc, DoIdleJobs) );
440
441 aOLEModifiedTimer.SetTimeout( 1000 );
442 aOLEModifiedTimer.SetTimeoutHdl( LINK( this, SwDoc, DoUpdateModifiedOLE ));
443
444 // DBMgr anlegen
445 pNewDBMgr = new SwNewDBMgr;
446
447 // create TOXTypes
448 InitTOXTypes();
449
450 // --> OD 2008-03-07 #refactorlists#
451 // pass empty item set containing the paragraph's list attributes
452 // as ignorable items to the stype manager.
453 {
454 SfxItemSet aIgnorableParagraphItems( GetAttrPool(),
455 RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END-1,
456 0 );
457 pStyleAccess = createStyleManager( &aIgnorableParagraphItems );
458 }
459 // <--
460
461 ResetModified();
462 }
463
464 /*
465 * Besonderheiten: an der Position 0 des Arrays der Formate und
466 * der GDI-Objekte befindet sich ein Member der Klasse SwDoc.
467 * Dieser darf also keinesfalls durch delete geloescht
468 * werden!!!!!!!!!!
469 */
470
471
~SwDoc()472 SwDoc::~SwDoc()
473 {
474 // nothing here should create Undo actions!
475 GetIDocumentUndoRedo().DoUndo(false);
476
477 if (pDocShell)
478 {
479 pDocShell->SetUndoManager(0);
480 }
481
482 // --> OD 2007-03-16 #i73788#
483 SwPauseThreadStarting aPauseThreadStarting;
484 // <--
485
486 // --> OD 2007-11-01 #i83479#
487 delete mpListItemsList;
488 mpListItemsList = 0;
489 // <--
490
491 // clean up chart related structures...
492 // Note: the chart data provider gets already diposed in ~SwDocShell
493 // since all UNO API related functionality requires an existing SwDocShell
494 // this assures that dipose gets called if there is need for it.
495 aChartDataProviderImplRef.reset();
496 delete pChartControllerHelper;
497
498 delete mpGrammarContact;
499 mpGrammarContact = 0;
500
501 //!! needs to be done to destroy a possible SwFmtDrop format that may
502 //!! be connected to a char format which may not otherwise be removed
503 //!! and thus would leave a unremoved SwFmt object. (TL)
504 //!! (this is case is not possible via UI but via API...)
505 SwFmtDrop aDrop;
506 SetDefault(aDrop);
507 //!! same for SwFmtCharFmt
508 SwFmtCharFmt aCharFmt(NULL);
509 SetDefault(aCharFmt);
510
511 StopIdling(); // stop idle timer
512
513 delete pUnoCallBack, pUnoCallBack = 0;
514 delete pURLStateChgd;
515
516 delete pLayouter;
517 // --> OD 2005-09-05 #125370#
518 pLayouter = 0L;
519 // <--
520
521 // Undo-Benachrichtigung vom Draw abschalten
522 if( pDrawModel )
523 {
524 DrawNotifyUndoHdl();
525 ClrContourCache();
526 }
527
528 delete pPgPViewPrtData;
529
530 mbDtor = sal_True;
531 pLayoutPtr.reset();
532
533 delete pRedlineTbl;
534 delete pUnoCrsrTbl;
535 delete pAutoFmtRedlnComment;
536
537 if( pUpdtFlds )
538 delete pUpdtFlds;
539
540 if( pACEWord )
541 delete pACEWord;
542
543 // die BaseLinks freigeben.
544 {
545 for( sal_uInt16 n = pLinkMgr->GetServers().Count(); n; )
546 pLinkMgr->GetServers()[ --n ]->Closed();
547
548 if( pLinkMgr->GetLinks().Count() )
549 pLinkMgr->Remove( 0, pLinkMgr->GetLinks().Count() );
550 }
551
552 // die KapitelNummern / Nummern muessen vor den Vorlage geloescht werden
553 // ansonsten wird noch staendig geupdatet !!!
554 m_pNodes->pOutlineNds->Remove(sal_uInt16(0), m_pNodes->pOutlineNds->Count());
555 SwNodes & rUndoNodes( GetUndoManager().GetUndoNodes() );
556 rUndoNodes.pOutlineNds->Remove(sal_uInt16(0), rUndoNodes.pOutlineNds->Count());
557
558 pFtnIdxs->Remove( sal_uInt16(0), pFtnIdxs->Count() );
559
560 // indices could be registered in attributes
561 m_pUndoManager->DelAllUndoObj();
562
563 // in den BookMarks sind Indizies auf den Content. Diese muessen vorm
564 // loesche der Nodes geloescht werden.
565 pMarkManager->clearAllMarks();
566 DELETEZ( pMacroTable );
567
568 if( pExtInputRing )
569 {
570 Ring* pTmp = pExtInputRing;
571 pExtInputRing = 0;
572 while( pTmp->GetNext() != pTmp )
573 delete pTmp->GetNext();
574 delete pTmp;
575 }
576
577 //JP: alt - loeschen ohne Flag ist teuer; Modify wird verschickt!
578 // aTOXTypes.DeleteAndDestroy( 0, aTOXTypes.Count() );
579 {
580 for( sal_uInt16 n = pTOXTypes->Count(); n; )
581 {
582 (*pTOXTypes)[ --n ]->SetInDocDTOR();
583 delete (*pTOXTypes)[ n ];
584 }
585 pTOXTypes->Remove( 0, pTOXTypes->Count() );
586 }
587 delete pDefTOXBases;
588
589 //Im einen oder anderen FrmFormat koennen noch Indizes angemeldet sein,
590 //Diese muessen spaetestens jetzt zerstoert werden.
591 pFrmFmtTbl->ForEach( &lcl_DelFmtIndizes, this );
592 pSpzFrmFmtTbl->ForEach( &lcl_DelFmtIndizes, this );
593 ((SwFrmFmts&)*pSectionFmtTbl).ForEach( &lcl_DelFmtIndizes, this );
594
595 //Die Formate, die hier hinter stehen sind von den DefaultFormaten
596 //abhaengig. Erst nach dem Loeschen der FmtIndizes weil der Inhalt von
597 //Kopf-/Fussbereichen geloescht wird. Wenn dort noch Indizes von Flys
598 //angemeldet sind gibts was an die Ohren.
599 aPageDescs.DeleteAndDestroy( 0, aPageDescs.Count() );
600
601 // Inhaltssections loeschen
602 // nicht erst durch den SwNodes-DTOR, damit Formate
603 // keine Abhaengigen mehr haben.
604 m_pNodes->DelNodes( SwNodeIndex(*m_pNodes), m_pNodes->Count() );
605 rUndoNodes.DelNodes( SwNodeIndex( rUndoNodes ), rUndoNodes.Count() );
606
607 // Formate loeschen, spaeter mal permanent machen.
608
609 // Delete fuer Collections
610 // damit die Abhaengigen wech sind
611 pFtnInfo->ReleaseCollection();
612 pEndNoteInfo->ReleaseCollection();
613
614 ASSERT( pDfltTxtFmtColl == (*pTxtFmtCollTbl)[0],
615 "Default-Text-Collection muss immer am Anfang stehen" );
616
617 // JP 27.01.98: opt.: ausgehend davon, das Standard als 2. im Array
618 // steht, sollte das als letztes geloescht werden, damit
619 // die ganze Umhaengerei der Formate vermieden wird!
620 if( 2 < pTxtFmtCollTbl->Count() )
621 pTxtFmtCollTbl->DeleteAndDestroy( 2, pTxtFmtCollTbl->Count()-2 );
622 pTxtFmtCollTbl->DeleteAndDestroy( 1, pTxtFmtCollTbl->Count()-1 );
623 delete pTxtFmtCollTbl;
624
625 ASSERT( pDfltGrfFmtColl == (*pGrfFmtCollTbl)[0],
626 "Default-Grf-Collection muss immer am Anfang stehen" );
627
628 pGrfFmtCollTbl->DeleteAndDestroy( 1, pGrfFmtCollTbl->Count()-1 );
629 // ergibt sich automatisch - kein _DEL Array!
630 // pGrfFmtCollTbl->Remove( 0, n );
631 delete pGrfFmtCollTbl;
632
633 /*
634 * Defaultformate und DefaultFormatsammlungen (FmtColl)
635 * sind an der Position 0 der jeweiligen Arrays eingetragen.
636 * Damit sie nicht vom DTOR der Array's zum 2.mal geloescht werden,
637 * nehme sie aus dem Array.
638 */
639 pFrmFmtTbl->Remove( 0 );
640 pCharFmtTbl->Remove( 0 );
641
642 // Delete fuer pPrt
643 DELETEZ( pPrt );
644 DELETEZ( pNewDBMgr );
645
646 // Alle Flys muessen vor dem Drawing Model zerstoert werden,
647 // da Flys noch DrawContacts enthalten koennen, wenn wegen
648 // eines Lesefehlers kein Layout aufgebaut wurde.
649 pSpzFrmFmtTbl->DeleteAndDestroy( 0, pSpzFrmFmtTbl->Count() );
650
651 //Erst jetzt das Model zerstoeren, die Zeichenobjekte - die ja auch
652 //im Undo herumlungern - wollen noch ihre Attribute beim Model entfernen.
653 //Ausserdem koennen vorher noch DrawContacts existieren.
654 ReleaseDrawModel();
655 //JP 28.01.99: DrawModel vorm LinkManager zerstoeren, da am DrawModel
656 // dieser immer gesetzt ist.
657 DELETEZ( pLinkMgr );
658
659 //Tables vor dem loeschen der Defaults leeren, sonst GPF wegen Def-Abhaengigen.
660 //Die Arrays sollten (wegen includes) bei Gelegenheit auch zu Pointern werden.
661 delete pFrmFmtTbl;
662 delete pSpzFrmFmtTbl;
663
664 delete pStyleAccess;
665
666 delete pCharFmtTbl;
667 delete pSectionFmtTbl;
668 delete pTblFrmFmtTbl;
669 delete pDfltTxtFmtColl;
670 delete pDfltGrfFmtColl;
671 delete pNumRuleTbl;
672
673 // --> OD 2008-03-26 #refactorlists#
674 {
675 for ( std::hash_map< String, SwList*, StringHash >::iterator
676 aListIter = maLists.begin();
677 aListIter != maLists.end();
678 ++aListIter )
679 {
680 delete (*aListIter).second;
681 }
682 maLists.clear();
683 }
684 maListStyleLists.clear();
685 // <--
686
687 disposeXForms(); // #i113606#, dispose the XForms objects
688
689 delete pPrtData;
690 delete pNumberFormatter;
691 delete pFtnInfo;
692 delete pEndNoteInfo;
693 delete pLineNumberInfo;
694 delete pFtnIdxs;
695 delete pFldTypes;
696 delete pTOXTypes;
697 delete pDocStat;
698 delete pEmptyPageFmt;
699 delete pColumnContFmt;
700 delete pDfltCharFmt;
701 delete pDfltFrmFmt;
702 delete pLayoutCache;
703 delete pVirDev;
704
705 SfxItemPool::Free(mpAttrPool);
706 }
707
708 //---------------------------------------------------
709
CreateVirtualDevice_() const710 VirtualDevice& SwDoc::CreateVirtualDevice_() const
711 {
712 VirtualDevice* pNewVir = new VirtualDevice( 1 );
713
714 // <--
715 pNewVir->SetReferenceDevice( VirtualDevice::REFDEV_MODE_MSO1 );
716
717 // --> FME 2006-10-09 #i60945# External leading compatibility for unix systems.
718 if ( get(IDocumentSettingAccess::UNIX_FORCE_ZERO_EXT_LEADING ) )
719 pNewVir->Compat_ZeroExtleadBug();
720 // <--
721
722 MapMode aMapMode( pNewVir->GetMapMode() );
723 aMapMode.SetMapUnit( MAP_TWIP );
724 pNewVir->SetMapMode( aMapMode );
725
726 const_cast<SwDoc*>(this)->setVirtualDevice( pNewVir, true, true );
727 return *pVirDev;
728 }
729
730 //---------------------------------------------------
731
CreatePrinter_() const732 SfxPrinter& SwDoc::CreatePrinter_() const
733 {
734 ASSERT( ! pPrt, "Do not call CreatePrinter_(), call getPrinter() instead" )
735
736 #if OSL_DEBUG_LEVEL > 1
737 OSL_TRACE( "Printer will be created!" );
738 #endif
739
740 // wir erzeugen einen default SfxPrinter.
741 // Das ItemSet wird vom Sfx geloescht!
742 SfxItemSet *pSet = new SfxItemSet( ((SwDoc*)this)->GetAttrPool(),
743 FN_PARAM_ADDPRINTER, FN_PARAM_ADDPRINTER,
744 SID_HTML_MODE, SID_HTML_MODE,
745 SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
746 SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
747 0 );
748
749 SfxPrinter* pNewPrt = new SfxPrinter( pSet );
750 const_cast<SwDoc*>(this)->setPrinter( pNewPrt, true, true );
751 return *pPrt;
752 }
753 //---------------------------------------------------
754
SetDocShell(SwDocShell * pDSh)755 void SwDoc::SetDocShell( SwDocShell* pDSh )
756 {
757 if( pDocShell != pDSh )
758 {
759 if (pDocShell)
760 {
761 pDocShell->SetUndoManager(0);
762 }
763 pDocShell = pDSh;
764 if (pDocShell)
765 {
766 pDocShell->SetUndoManager(& GetUndoManager());
767 }
768
769 pLinkMgr->SetPersist( pDocShell );
770 //JP 27.08.98: Bug 55570 - DocShell Pointer auch am DrawModel setzen
771 if( pDrawModel )
772 {
773 ((SwDrawDocument*)pDrawModel)->SetObjectShell( pDocShell );
774 pDrawModel->SetPersist( pDocShell );
775 ASSERT( pDrawModel->GetPersist() == GetPersist(),
776 "draw model's persist is out of sync" );
777 }
778 }
779 }
780
781
782 // Convenience-Methode, um uebermaessige Includes von docsh.hxx
783 // zu vermeiden
784
785
786
GetDocStorage()787 uno::Reference < embed::XStorage > SwDoc::GetDocStorage()
788 {
789 if( pDocShell )
790 return pDocShell->GetStorage();
791 if( pLinkMgr->GetPersist() )
792 return pLinkMgr->GetPersist()->GetStorage();
793 return NULL;
794 }
795
796
797
GetPersist() const798 SfxObjectShell* SwDoc::GetPersist() const
799 {
800 return pDocShell ? pDocShell : pLinkMgr->GetPersist();
801 }
802
803
ClearDoc()804 void SwDoc::ClearDoc()
805 {
806 GetIDocumentUndoRedo().DelAllUndoObj();
807 ::sw::UndoGuard const undoGuard(GetIDocumentUndoRedo());
808
809 // Undo-Benachrichtigung vom Draw abschalten
810 if( pDrawModel )
811 {
812 DrawNotifyUndoHdl();
813 ClrContourCache();
814 }
815
816 // stehen noch FlyFrames rum, loesche auch diese
817 sal_uInt16 n;
818 while ( 0 != (n = GetSpzFrmFmts()->Count()) )
819 DelLayoutFmt((*pSpzFrmFmtTbl)[n-1]);
820 ASSERT( !pDrawModel || !pDrawModel->GetPage(0)->GetObjCount(),
821 "not all DrawObjects removed from the page" );
822
823 pRedlineTbl->DeleteAndDestroy( 0, pRedlineTbl->Count() );
824
825 if( pACEWord )
826 delete pACEWord;
827
828 // in den BookMarks sind Indizies auf den Content. Diese muessen vorm
829 // loesche der Nodes geloescht werden.
830 pMarkManager->clearAllMarks();
831 InitTOXTypes();
832
833 // create a dummy pagedesc for the layout
834 sal_uInt16 nDummyPgDsc = MakePageDesc( String::CreateFromAscii( "?DUMMY?" ));
835 SwPageDesc* pDummyPgDsc = aPageDescs[ nDummyPgDsc ];
836
837 SwNodeIndex aSttIdx( *GetNodes().GetEndOfContent().StartOfSectionNode(), 1 );
838 // den ersten immer wieder neu anlegen (ohne Attribute/Vorlagen/...)
839 SwTxtNode* pFirstNd = GetNodes().MakeTxtNode( aSttIdx, pDfltTxtFmtColl );
840
841 if( pCurrentView ) //swmod 071029//swmod 071225
842 {
843 // set the layout to the dummy pagedesc
844 pFirstNd->SetAttr( SwFmtPageDesc( pDummyPgDsc ));
845
846 SwPosition aPos( *pFirstNd, SwIndex( pFirstNd ));
847 SwPaM const tmpPaM(aSttIdx, SwNodeIndex(GetNodes().GetEndOfContent()));
848 ::PaMCorrAbs(tmpPaM, aPos);
849 }
850
851 GetNodes().Delete( aSttIdx,
852 GetNodes().GetEndOfContent().GetIndex() - aSttIdx.GetIndex() );
853
854 // --> OD 2006-02-28 #i62440#
855 // destruction of numbering rules and creation of new outline rule
856 // *after* the document nodes are deleted.
857 pOutlineRule = NULL;
858 pNumRuleTbl->DeleteAndDestroy( 0, pNumRuleTbl->Count() );
859 // --> OD #i114725#,#i115828#
860 {
861 for ( std::hash_map< String, SwList*, StringHash >::iterator
862 aListIter = maLists.begin();
863 aListIter != maLists.end();
864 ++aListIter )
865 {
866 delete (*aListIter).second;
867 }
868 maLists.clear();
869 }
870 maListStyleLists.clear();
871 // <--
872 // creation of new outline numbering rule
873 // --> OD 2008-02-11 #newlistlevelattrs#
874 pOutlineRule = new SwNumRule( String::CreateFromAscii( SwNumRule::GetOutlineRuleName() ),
875 // --> OD 2008-06-06 #i89178#
876 numfunc::GetDefaultPositionAndSpaceMode(),
877 // <--
878 OUTLINE_RULE );
879 // <--
880 AddNumRule(pOutlineRule);
881 // --> OD 2005-10-21 - counting of phantoms depends on <IsOldNumbering()>
882 pOutlineRule->SetCountPhantoms( !get(IDocumentSettingAccess::OLD_NUMBERING) );
883 // <--
884 // <--
885
886 //remove the dummy pagedec from the array and delete all the old ones
887 aPageDescs.Remove( nDummyPgDsc );
888 aPageDescs.DeleteAndDestroy( 0, aPageDescs.Count() );
889
890 // Delete fuer Collections
891 // damit die Abhaengigen wech sind
892 pFtnInfo->ReleaseCollection();
893 pEndNoteInfo->ReleaseCollection();
894
895 // JP 27.01.98: opt.: ausgehend davon, das Standard als 2. im Array
896 // steht, sollte das als letztes geloescht werden, damit
897 // die ganze Umhaengerei der Formate vermieden wird!
898 if( 2 < pTxtFmtCollTbl->Count() )
899 pTxtFmtCollTbl->DeleteAndDestroy( 2, pTxtFmtCollTbl->Count()-2 );
900 pTxtFmtCollTbl->DeleteAndDestroy( 1, pTxtFmtCollTbl->Count()-1 );
901 pGrfFmtCollTbl->DeleteAndDestroy( 1, pGrfFmtCollTbl->Count()-1 );
902 pCharFmtTbl->DeleteAndDestroy( 1, pCharFmtTbl->Count()-1 );
903
904 if( pCurrentView )
905 {
906 // search the FrameFormat of the root frm. This is not allowed to delete
907 pFrmFmtTbl->Remove( pFrmFmtTbl->GetPos( pCurrentView->GetLayout()->GetFmt() ) );
908 pFrmFmtTbl->DeleteAndDestroy( 1, pFrmFmtTbl->Count()-1 );
909 pFrmFmtTbl->Insert( pCurrentView->GetLayout()->GetFmt(), pFrmFmtTbl->Count() );
910 }
911 else //swmod 071029//swmod 071225
912 pFrmFmtTbl->DeleteAndDestroy( 1, pFrmFmtTbl->Count()-1 );
913
914 xForbiddenCharsTable.unbind();
915
916 pFldTypes->DeleteAndDestroy( INIT_FLDTYPES,
917 pFldTypes->Count() - INIT_FLDTYPES );
918
919 delete pNumberFormatter, pNumberFormatter = 0;
920
921 GetPageDescFromPool( RES_POOLPAGE_STANDARD );
922 pFirstNd->ChgFmtColl( GetTxtCollFromPool( RES_POOLCOLL_STANDARD ));
923 nDummyPgDsc = aPageDescs.Count();
924 aPageDescs.Insert( pDummyPgDsc, nDummyPgDsc );
925 // set the layout back to the new standard pagedesc
926 pFirstNd->ResetAllAttr();
927 // delete now the dummy pagedesc
928 DelPageDesc( nDummyPgDsc );
929 }
930
SetPreViewPrtData(const SwPagePreViewPrtData * pNew)931 void SwDoc::SetPreViewPrtData( const SwPagePreViewPrtData* pNew )
932 {
933 if( pNew )
934 {
935 if( pPgPViewPrtData )
936 *pPgPViewPrtData = *pNew;
937 else
938 pPgPViewPrtData = new SwPagePreViewPrtData( *pNew );
939 }
940 else if( pPgPViewPrtData )
941 DELETEZ( pPgPViewPrtData );
942 SetModified();
943 }
944 /* -----------------------------06.01.00 14:03--------------------------------
945
946 ---------------------------------------------------------------------------*/
GetUnoCallBack() const947 SwModify* SwDoc::GetUnoCallBack() const
948 {
949 return pUnoCallBack;
950 }
951
952 /*-----------------28.5.2001 10:06------------------
953 * SwDoc:
954 * Reading and writing of the layout cache.
955 *--------------------------------------------------*/
956
ReadLayoutCache(SvStream & rStream)957 void SwDoc::ReadLayoutCache( SvStream& rStream )
958 {
959 if( !pLayoutCache )
960 pLayoutCache = new SwLayoutCache();
961 if( !pLayoutCache->IsLocked() )
962 {
963 pLayoutCache->GetLockCount() |= 0x8000;
964 pLayoutCache->Read( rStream );
965 pLayoutCache->GetLockCount() &= 0x7fff;
966 }
967 }
968
WriteLayoutCache(SvStream & rStream)969 void SwDoc::WriteLayoutCache( SvStream& rStream )
970 {
971 pLayoutCache->Write( rStream, *this );
972 }
973
getGrammarContact(const SwTxtNode & rTxtNode)974 IGrammarContact* getGrammarContact( const SwTxtNode& rTxtNode )
975 {
976 const SwDoc* pDoc = rTxtNode.GetDoc();
977 if( !pDoc || pDoc->IsInDtor() )
978 return 0;
979 return pDoc->getGrammarContact();
980 }
981
982 // --> FME 2005-02-25 #i42634# Moved common code of SwReader::Read() and
983 // SwDocShell::UpdateLinks() to new SwDoc::UpdateLinks():
UpdateLinks(sal_Bool bUI)984 void SwDoc::UpdateLinks( sal_Bool bUI )
985 {
986 SfxObjectCreateMode eMode;
987 sal_uInt16 nLinkMode = getLinkUpdateMode( true );
988 sal_uInt16 nUpdateDocMode = GetDocShell()->GetUpdateDocMode();
989 if( GetDocShell() &&
990 (nLinkMode != NEVER || document::UpdateDocMode::FULL_UPDATE == nUpdateDocMode) &&
991 GetLinkManager().GetLinks().Count() &&
992 SFX_CREATE_MODE_INTERNAL !=
993 ( eMode = GetDocShell()->GetCreateMode()) &&
994 SFX_CREATE_MODE_ORGANIZER != eMode &&
995 SFX_CREATE_MODE_PREVIEW != eMode &&
996 !GetDocShell()->IsPreview() )
997 {
998 ViewShell* pVSh = 0;
999 sal_Bool bAskUpdate = nLinkMode == MANUAL;
1000 sal_Bool bUpdate = sal_True;
1001 switch(nUpdateDocMode)
1002 {
1003 case document::UpdateDocMode::NO_UPDATE: bUpdate = sal_False;break;
1004 case document::UpdateDocMode::QUIET_UPDATE:bAskUpdate = sal_False; break;
1005 case document::UpdateDocMode::FULL_UPDATE: bAskUpdate = sal_True; break;
1006 }
1007 if (nLinkMode == AUTOMATIC && !bAskUpdate)
1008 {
1009 if (!(SvtSecurityOptions().GetMacroSecurityLevel() == 0))
1010 {
1011 bAskUpdate = true;
1012 }
1013 }
1014 if( bUpdate && (bUI || !bAskUpdate) )
1015 {
1016 SfxMedium* pMedium = GetDocShell()->GetMedium();
1017 SfxFrame* pFrm = pMedium ? pMedium->GetLoadTargetFrame() : 0;
1018 Window* pDlgParent = pFrm ? &pFrm->GetWindow() : 0;
1019 if( GetCurrentViewShell() && !GetEditShell( &pVSh ) && !pVSh ) //swmod 071108//swmod 071225
1020 {
1021 ViewShell aVSh( *this, 0, 0 );
1022
1023 SET_CURR_SHELL( &aVSh );
1024 GetLinkManager().UpdateAllLinks( bAskUpdate , sal_True, sal_False, pDlgParent );
1025 }
1026 else
1027 GetLinkManager().UpdateAllLinks( bAskUpdate, sal_True, sal_False, pDlgParent );
1028 }
1029 }
1030
1031 }
1032 // <--
1033 // --> OD 2006-04-19 #b6375613#
SetApplyWorkaroundForB6375613(bool p_bApplyWorkaroundForB6375613)1034 void SwDoc::SetApplyWorkaroundForB6375613( bool p_bApplyWorkaroundForB6375613 )
1035 {
1036 if ( mbApplyWorkaroundForB6375613 != p_bApplyWorkaroundForB6375613 )
1037 {
1038 mbApplyWorkaroundForB6375613 = p_bApplyWorkaroundForB6375613;
1039
1040 uno::Reference< document::XDocumentInfoSupplier > xDoc(
1041 GetDocShell()->GetBaseModel(),
1042 uno::UNO_QUERY);
1043 if ( xDoc.is() )
1044 {
1045 uno::Reference< beans::XPropertyContainer > xDocInfo(
1046 xDoc->getDocumentInfo(),
1047 uno::UNO_QUERY );
1048 if ( xDocInfo.is() )
1049 {
1050 try
1051 {
1052 if ( mbApplyWorkaroundForB6375613 )
1053 {
1054 xDocInfo->addProperty(
1055 rtl::OUString::createFromAscii("WorkaroundForB6375613Applied"),
1056 beans::PropertyAttribute::TRANSIENT | beans::PropertyAttribute::REMOVABLE,
1057 uno::makeAny( false ) );
1058 }
1059 else
1060 {
1061 xDocInfo->removeProperty( rtl::OUString::createFromAscii("WorkaroundForB6375613Applied") );
1062 }
1063 }
1064 catch( uno::Exception& )
1065 {
1066 }
1067 }
1068 }
1069 }
1070 }
1071 // <--
1072
1073 ::sfx2::IXmlIdRegistry&
GetXmlIdRegistry()1074 SwDoc::GetXmlIdRegistry()
1075 {
1076 // UGLY: this relies on SetClipBoard being called before GetXmlIdRegistry!
1077 if (!m_pXmlIdRegistry.get())
1078 {
1079 m_pXmlIdRegistry.reset( ::sfx2::createXmlIdRegistry( IsClipBoard() ) );
1080 }
1081 return *m_pXmlIdRegistry;
1082 }
1083
1084 ::sw::MetaFieldManager &
GetMetaFieldManager()1085 SwDoc::GetMetaFieldManager()
1086 {
1087 return *m_pMetaFieldManager;
1088 }
1089
1090 ::sw::UndoManager &
GetUndoManager()1091 SwDoc::GetUndoManager()
1092 {
1093 return *m_pUndoManager;
1094 }
1095
1096 ::sw::UndoManager const&
GetUndoManager() const1097 SwDoc::GetUndoManager() const
1098 {
1099 return *m_pUndoManager;
1100 }
1101
1102 IDocumentUndoRedo &
GetIDocumentUndoRedo()1103 SwDoc::GetIDocumentUndoRedo()
1104 {
1105 return *m_pUndoManager;
1106 }
1107
1108 IDocumentUndoRedo const&
GetIDocumentUndoRedo() const1109 SwDoc::GetIDocumentUndoRedo() const
1110 {
1111 return *m_pUndoManager;
1112 }
1113
InitTOXTypes()1114 void SwDoc::InitTOXTypes()
1115 {
1116 ShellResource* pShellRes = ViewShell::GetShellRes();
1117 SwTOXType * pNew = new SwTOXType(TOX_CONTENT, pShellRes->aTOXContentName );
1118 pTOXTypes->Insert( pNew, pTOXTypes->Count() );
1119 pNew = new SwTOXType(TOX_INDEX, pShellRes->aTOXIndexName );
1120 pTOXTypes->Insert( pNew, pTOXTypes->Count() );
1121 pNew = new SwTOXType(TOX_USER, pShellRes->aTOXUserName );
1122 pTOXTypes->Insert( pNew, pTOXTypes->Count() );
1123 pNew = new SwTOXType(TOX_ILLUSTRATIONS, pShellRes->aTOXIllustrationsName );
1124 pTOXTypes->Insert( pNew, pTOXTypes->Count() );
1125 pNew = new SwTOXType(TOX_OBJECTS, pShellRes->aTOXObjectsName );
1126 pTOXTypes->Insert( pNew, pTOXTypes->Count() );
1127 pNew = new SwTOXType(TOX_TABLES, pShellRes->aTOXTablesName );
1128 pTOXTypes->Insert( pNew, pTOXTypes->Count() );
1129 pNew = new SwTOXType(TOX_AUTHORITIES, pShellRes->aTOXAuthoritiesName );
1130 pTOXTypes->Insert( pNew, pTOXTypes->Count() );
1131 }
1132
1133 /*-- 08.05.2009 10:07:57---------------------------------------------------
1134
1135 -----------------------------------------------------------------------*/
CreateCopy(bool bCallInitNew) const1136 SfxObjectShell* SwDoc::CreateCopy(bool bCallInitNew ) const
1137 {
1138 SwDoc* pRet = new SwDoc;
1139 //copy settings
1140 sal_uInt16 __FAR_DATA aRangeOfDefaults[] = {
1141 RES_FRMATR_BEGIN, RES_FRMATR_END-1,
1142 RES_CHRATR_BEGIN, RES_CHRATR_END-1,
1143 RES_PARATR_BEGIN, RES_PARATR_END-1,
1144 // --> OD 2008-02-25 #refactorlists##
1145 RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END-1,
1146 // <--
1147 RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1,
1148 0
1149 };
1150
1151 SfxItemSet aNewDefaults( pRet->GetAttrPool(), aRangeOfDefaults );
1152
1153 sal_uInt16 nWhich;
1154 sal_uInt16 nRange = 0;
1155 while( aRangeOfDefaults[nRange] != 0)
1156 {
1157 for( nWhich = aRangeOfDefaults[nRange]; nWhich < aRangeOfDefaults[nRange + 1]; ++nWhich )
1158 {
1159 const SfxPoolItem& rSourceAttr = mpAttrPool->GetDefaultItem( nWhich );
1160 if( rSourceAttr != pRet->mpAttrPool->GetDefaultItem( nWhich ) )
1161 aNewDefaults.Put( rSourceAttr );
1162 }
1163 nRange += 2;
1164 }
1165 if( aNewDefaults.Count() )
1166 pRet->SetDefault( aNewDefaults );
1167
1168 pRet->n32DummyCompatabilityOptions1 = n32DummyCompatabilityOptions1;
1169 pRet->n32DummyCompatabilityOptions2 = n32DummyCompatabilityOptions2;
1170 pRet->mbParaSpaceMax = mbParaSpaceMax ;
1171 pRet->mbParaSpaceMaxAtPages = mbParaSpaceMaxAtPages ;
1172 pRet->mbTabCompat = mbTabCompat ;
1173 pRet->mbUseVirtualDevice = mbUseVirtualDevice ;
1174 pRet->mbAddExternalLeading = mbAddExternalLeading ;
1175 pRet->mbOldLineSpacing = mbOldLineSpacing ;
1176 pRet->mbAddParaSpacingToTableCells = mbAddParaSpacingToTableCells ;
1177 pRet->mbUseFormerObjectPos = mbUseFormerObjectPos ;
1178 pRet->mbUseFormerTextWrapping = mbUseFormerTextWrapping ;
1179 pRet->mbConsiderWrapOnObjPos = mbConsiderWrapOnObjPos ;
1180 pRet->mbAddFlyOffsets = mbAddFlyOffsets ;
1181 pRet->mbOldNumbering = mbOldNumbering ;
1182 pRet->mbUseHiResolutionVirtualDevice = mbUseHiResolutionVirtualDevice ;
1183 pRet->mbIgnoreFirstLineIndentInNumbering = mbIgnoreFirstLineIndentInNumbering ;
1184 pRet->mbDoNotJustifyLinesWithManualBreak = mbDoNotJustifyLinesWithManualBreak ;
1185 pRet->mbDoNotResetParaAttrsForNumFont = mbDoNotResetParaAttrsForNumFont ;
1186 pRet->mbOutlineLevelYieldsOutlineRule = mbOutlineLevelYieldsOutlineRule ;
1187 pRet->mbTableRowKeep = mbTableRowKeep ;
1188 pRet->mbIgnoreTabsAndBlanksForLineCalculation = mbIgnoreTabsAndBlanksForLineCalculation ;
1189 pRet->mbDoNotCaptureDrawObjsOnPage = mbDoNotCaptureDrawObjsOnPage ;
1190 pRet->mbClipAsCharacterAnchoredWriterFlyFrames= mbClipAsCharacterAnchoredWriterFlyFrames;
1191 pRet->mbUnixForceZeroExtLeading = mbUnixForceZeroExtLeading ;
1192 pRet->mbOldPrinterMetrics = mbOldPrinterMetrics ;
1193 pRet->mbTabRelativeToIndent = mbTabRelativeToIndent ;
1194 pRet->mbTabAtLeftIndentForParagraphsInList = mbTabAtLeftIndentForParagraphsInList ;
1195
1196 //
1197 // COMPATIBILITY FLAGS END
1198 //
1199 pRet->ReplaceStyles( * const_cast< SwDoc*>( this ));
1200
1201 // we have to use pointer here, since the callee has to decide whether SfxObjectShellLock or SfxObjectShellRef should be used
1202 // sometimes the object will be returned with refcount set to 0 ( if no DoInitNew is done )
1203 SfxObjectShell* pRetShell = new SwDocShell( pRet, SFX_CREATE_MODE_STANDARD );
1204 if( bCallInitNew )
1205 {
1206 // it could happen that DoInitNew creates model, that increases the refcount of the object
1207 pRetShell->DoInitNew();
1208 }
1209
1210 //copy content
1211 pRet->Paste( *this );
1212
1213 // remove the temporary shell if it is there as it was done before
1214 if(pRet->GetTmpDocShell())
1215 {
1216 // #123914# If we get here, SwOLENode::MakeCopy had to create a temporary
1217 // SwDocShell to have a SvPersist as a target for the OLE data to be copied.
1218 // It is reset by a call to SetTmpDocShell(NULL), but in this case here
1219 // there is no other ref holder to the just cloned SwDoc. Thus - to prevent
1220 // it's immediate deletion - it is required to hold a fercunt to it during
1221 // the SetTmpDocShell call. This can be done with an instance of a class
1222 // holding a SwDoc, but most simple using acquire/release on the SwDoc
1223 // (as long as these are public, I was surprised. Also probably not
1224 // guaranteed for the future is that the release call does not delete the
1225 // SwDoc it gets called at, but currently works like this).
1226 pRet->acquire();
1227 pRet->SetTmpDocShell((SfxObjectShell*)NULL);
1228 pRet->release();
1229 }
1230
1231 // remove the temporary shell if it is there as it was done before
1232 // pRet->SetTmpDocShell( (SfxObjectShell*)NULL );
1233
1234 return pRetShell;
1235 }
1236 /*-- 08.05.2009 10:52:40---------------------------------------------------
1237 copy document content - code from SwFEShell::Paste( SwDoc* , sal_Bool )
1238 -----------------------------------------------------------------------*/
Paste(const SwDoc & rSource)1239 void SwDoc::Paste( const SwDoc& rSource )
1240 {
1241 // this has to be empty const sal_uInt16 nStartPageNumber = GetPhyPageNum();
1242 // until the end of the NodesArray
1243 SwNodeIndex aSourceIdx( rSource.GetNodes().GetEndOfExtras(), 2 );
1244 SwPaM aCpyPam( aSourceIdx ); //DocStart
1245 SwNodeIndex aTargetIdx( GetNodes().GetEndOfExtras(), 2 );
1246 SwPaM aInsertPam( aTargetIdx ); //replaces PCURCRSR from SwFEShell::Paste()
1247
1248
1249 aCpyPam.SetMark();
1250 aCpyPam.Move( fnMoveForward, fnGoDoc );
1251
1252 this->GetIDocumentUndoRedo().StartUndo( UNDO_INSGLOSSARY, NULL );
1253 this->LockExpFlds();
1254
1255 {
1256 SwPosition& rInsPos = *aInsertPam.GetPoint();
1257 //find out if the clipboard document starts with a table
1258 bool bStartWithTable = 0 != aCpyPam.Start()->nNode.GetNode().FindTableNode();
1259 SwPosition aInsertPosition( rInsPos );
1260
1261 {
1262 SwNodeIndex aIndexBefore(rInsPos.nNode);
1263
1264 aIndexBefore--;
1265
1266 rSource.CopyRange( aCpyPam, rInsPos, true );
1267
1268 {
1269 aIndexBefore++;
1270 SwPaM aPaM(SwPosition(aIndexBefore),
1271 SwPosition(rInsPos.nNode));
1272
1273 MakeUniqueNumRules(aPaM);
1274 }
1275 }
1276
1277 //TODO: Is this necessary here? SaveTblBoxCntnt( &rInsPos );
1278 if(/*bIncludingPageFrames && */bStartWithTable)
1279 {
1280 //remove the paragraph in front of the table
1281 SwPaM aPara(aInsertPosition);
1282 this->DelFullPara(aPara);
1283 }
1284 //additionally copy page bound frames
1285 if( /*bIncludingPageFrames && */rSource.GetSpzFrmFmts()->Count() )
1286 {
1287 for ( sal_uInt16 i = 0; i < rSource.GetSpzFrmFmts()->Count(); ++i )
1288 {
1289 sal_Bool bInsWithFmt = sal_True;
1290 const SwFrmFmt& rCpyFmt = *(*rSource.GetSpzFrmFmts())[i];
1291 if( bInsWithFmt )
1292 {
1293 SwFmtAnchor aAnchor( rCpyFmt.GetAnchor() );
1294 if (FLY_AT_PAGE == aAnchor.GetAnchorId())
1295 {
1296 aAnchor.SetPageNum( aAnchor.GetPageNum() /*+ nStartPageNumber - */);
1297 }
1298 else
1299 continue;
1300 this->CopyLayoutFmt( rCpyFmt, aAnchor, true, true );
1301 }
1302 }
1303 }
1304 }
1305
1306 this->GetIDocumentUndoRedo().EndUndo( UNDO_INSGLOSSARY, NULL );
1307
1308 UnlockExpFlds();
1309 UpdateFlds(NULL, false);
1310 }
1311