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