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