xref: /aoo41x/main/sw/source/core/doc/docnew.cxx (revision 8bfab1df)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 #define ROLBCK_HISTORY_ONLY 	// Der Kampf gegen die CLOOK's
31 #include <doc.hxx>
32 #include <dcontact.hxx>
33 #include <com/sun/star/document/PrinterIndependentLayout.hpp>
34 #include <com/sun/star/document/UpdateDocMode.hpp>
35 #include <com/sun/star/text/XTextDocument.hpp>
36 #include <com/sun/star/linguistic2/XProofreadingIterator.hpp>
37 #include <com/sun/star/text/XFlatParagraphIteratorProvider.hpp>
38 
39 #include <unotools/processfactory.hxx>
40 #include <vcl/svapp.hxx>
41 #include <vcl/virdev.hxx>
42 #include <rtl/logfile.hxx>
43 #include <sfx2/printer.hxx>
44 #include <sfx2/docfile.hxx>
45 #include <sfx2/frame.hxx>
46 #include <sfx2/viewfrm.hxx>
47 
48 #include <svl/macitem.hxx>
49 #include <svx/svxids.hrc>
50 #include <svx/svdogrp.hxx>
51 #include <sfx2/linkmgr.hxx>
52 #include <editeng/forbiddencharacterstable.hxx>
53 #include <svl/zforlist.hxx>
54 #include <unotools/compatibility.hxx>
55 #include <unotools/lingucfg.hxx>
56 #include <svx/svdpage.hxx>
57 #include <paratr.hxx>
58 #include <fchrfmt.hxx>
59 #include <fmtcntnt.hxx>
60 #include <fmtanchr.hxx>
61 #include <fmtfsize.hxx>
62 #include <fmtfordr.hxx>
63 #include <fmtpdsc.hxx>
64 #include <pvprtdat.hxx>
65 #include <rootfrm.hxx>  //Damit der RootDtor gerufen wird.
66 #include <layouter.hxx>
67 #include <pagedesc.hxx> //Damit die PageDescs zerstoert werden koennen.
68 #include <ndtxt.hxx>
69 #include <printdata.hxx>
70 #include <docfld.hxx>
71 #include <ftninfo.hxx>
72 #include <ftnidx.hxx>
73 #include <docstat.hxx>
74 #include <charfmt.hxx>
75 #include <frmfmt.hxx>
76 #include <rolbck.hxx>           // Undo-Attr, SwHistory
77 #include <poolfmt.hxx>          // fuer die Pool-Vorlage
78 #include <dbmgr.hxx>
79 #include <docsh.hxx>
80 #include <acorrect.hxx>			// fuer die autom. Aufnahme von Ausnahmen
81 #include <visiturl.hxx>			// fuer die URL-Change Benachrichtigung
82 #include <docary.hxx>
83 #include <lineinfo.hxx>
84 #include <drawdoc.hxx>
85 #include <linkenum.hxx>
86 #include <fldupde.hxx>
87 #include <extinput.hxx>
88 #include <viewsh.hxx>
89 #include <doctxm.hxx>
90 #include <shellres.hxx>
91 #include <breakit.hxx>
92 #include <laycache.hxx>
93 #include <mvsave.hxx>
94 #include <istyleaccess.hxx>
95 #include <swstylemanager.hxx>
96 #include <IGrammarContact.hxx>
97 #include <tblsel.hxx>
98 #include <MarkManager.hxx>
99 #include <UndoManager.hxx>
100 #include <unochart.hxx>
101 
102 #include <cmdid.h>              // fuer den dflt - Printer in SetJob
103 
104 
105 // --> OD 2006-04-19 #b6375613#
106 #include <com/sun/star/document/XDocumentInfoSupplier.hpp>
107 #include <com/sun/star/beans/XPropertyContainer.hpp>
108 #include <com/sun/star/beans/PropertyAttribute.hpp>
109 
110 // <--
111 
112 // --> OD 2007-03-16 #i73788#
113 #include <pausethreadstarting.hxx>
114 // <--
115 #include <numrule.hxx>
116 // --> OD 2008-03-13 #refactorlists#
117 #include <list.hxx>
118 #include <listfunc.hxx>
119 // <--
120 
121 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
122 
123 #include <sfx2/Metadatable.hxx>
124 #include <fmtmeta.hxx> // MetaFieldManager
125 
126 
127 using namespace ::com::sun::star;
128 using namespace ::com::sun::star::document;
129 
130 const sal_Char __FAR_DATA sFrmFmtStr[] = "Frameformat";
131 const sal_Char __FAR_DATA sEmptyPageStr[] = "Empty Page";
132 const sal_Char __FAR_DATA sColumnCntStr[] = "Columncontainer";
133 const sal_Char __FAR_DATA sCharFmtStr[] = "Zeichenformat";
134 const sal_Char __FAR_DATA sTxtCollStr[] = "Textformatvorlage";
135 const sal_Char __FAR_DATA sGrfCollStr[] = "Graphikformatvorlage";
136 
137 SV_IMPL_PTRARR( SwNumRuleTbl, SwNumRulePtr)
138 SV_IMPL_PTRARR( SwTxtFmtColls, SwTxtFmtCollPtr)
139 SV_IMPL_PTRARR( SwGrfFmtColls, SwGrfFmtCollPtr)
140 
141 /*
142  * global functions...
143  */
144 
145  uno::Reference< linguistic2::XProofreadingIterator > SwDoc::GetGCIterator() const
146 {
147     if (!m_xGCIterator.is() && SvtLinguConfig().HasGrammarChecker())
148     {
149         uno::Reference< lang::XMultiServiceFactory >  xMgr( utl::getProcessServiceFactory() );
150         if (xMgr.is())
151         {
152             try
153             {
154                 rtl::OUString aServiceName( rtl::OUString::createFromAscii("com.sun.star.linguistic2.ProofreadingIterator") );
155                 m_xGCIterator = uno::Reference< linguistic2::XProofreadingIterator >
156                     ( xMgr->createInstance( aServiceName ), uno::UNO_QUERY_THROW );
157             }
158             catch (uno::Exception &)
159             {
160                 DBG_ERROR( "No GCIterator" );
161             }
162         }
163     }
164 
165     return m_xGCIterator;
166 }
167 
168 void StartGrammarChecking( SwDoc &rDoc )
169 {
170     // check for a visible view
171     bool bVisible = false;
172     const SwDocShell *pDocShell = rDoc.GetDocShell();
173     SfxViewFrame    *pFrame = SfxViewFrame::GetFirst( pDocShell, sal_False );
174     while (pFrame && !bVisible)
175     {
176         if (pFrame->IsVisible())
177             bVisible = true;
178         pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell, sal_False );
179     }
180 
181     //!! only documents with visible views need to be checked
182     //!! (E.g. don't check temporary documents created for printing, see printing of notes and selections.
183     //!! Those get created on the fly and get hard deleted a bit later as well, and no one should have
184     //!! a uno reference to them)
185     if (bVisible)
186     {
187         uno::Reference< linguistic2::XProofreadingIterator > xGCIterator( rDoc.GetGCIterator() );
188         if ( xGCIterator.is() )
189         {
190             uno::Reference< lang::XComponent >  xDoc( rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY );
191             uno::Reference< text::XFlatParagraphIteratorProvider >  xFPIP( xDoc, uno::UNO_QUERY );
192 
193             // start automatic background checking if not active already
194             if ( xFPIP.is() && !xGCIterator->isProofreading( xDoc ) )
195                 xGCIterator->startProofreading( xDoc, xFPIP );
196         }
197     }
198 }
199 
200 /*
201  * interne Funktionen
202  */
203 
204 
205 
206 sal_Bool lcl_DelFmtIndizes( const SwFrmFmtPtr& rpFmt, void* )
207 {
208 	SwFmtCntnt &rFmtCntnt = (SwFmtCntnt&)rpFmt->GetCntnt();
209 	if ( rFmtCntnt.GetCntntIdx() )
210 		rFmtCntnt.SetNewCntntIdx( 0 );
211 	SwFmtAnchor &rFmtAnchor = (SwFmtAnchor&)rpFmt->GetAnchor();
212 	if ( rFmtAnchor.GetCntntAnchor() )
213 		rFmtAnchor.SetAnchor( 0 );
214 	return sal_True;
215 }
216 
217 /*
218  * exportierte Methoden
219  */
220 
221 SwDoc::SwDoc()
222     : m_pNodes( new SwNodes(this) )
223     ,
224 	mpAttrPool(new SwAttrPool(this)),
225     pMarkManager(new ::sw::mark::MarkManager(*this)),
226     m_pMetaFieldManager(new ::sw::MetaFieldManager()),
227     m_pUndoManager(new ::sw::UndoManager(
228             ::std::auto_ptr<SwNodes>(new SwNodes(this)), *this, *this, *this)),
229 	pDfltFrmFmt( new SwFrmFmt( GetAttrPool(), sFrmFmtStr, 0 ) ),
230 	pEmptyPageFmt( new SwFrmFmt( GetAttrPool(), sEmptyPageStr, pDfltFrmFmt ) ),
231 	pColumnContFmt( new SwFrmFmt( GetAttrPool(), sColumnCntStr, pDfltFrmFmt ) ),
232 	pDfltCharFmt( new SwCharFmt( GetAttrPool(), sCharFmtStr, 0 ) ),
233 	pDfltTxtFmtColl( new SwTxtFmtColl( GetAttrPool(), sTxtCollStr ) ),
234 	pDfltGrfFmtColl( new SwGrfFmtColl( GetAttrPool(), sGrfCollStr ) ),
235 	pFrmFmtTbl( new SwFrmFmts() ),
236 	pCharFmtTbl( new SwCharFmts() ),
237 	pSpzFrmFmtTbl( new SwSpzFrmFmts() ),
238 	pSectionFmtTbl( new SwSectionFmts() ),
239 	pTblFrmFmtTbl( new SwFrmFmts() ),
240 	pTxtFmtCollTbl( new SwTxtFmtColls() ),
241 	pGrfFmtCollTbl( new SwGrfFmtColls() ),
242 	pTOXTypes( new SwTOXTypes() ),
243 	pDefTOXBases( new SwDefTOXBase_Impl() ),
244 	pCurrentView( 0 ),	//swmod 071225
245 	pDrawModel( 0 ),
246 	pUpdtFlds( new SwDocUpdtFld() ),
247 	pFldTypes( new SwFldTypes() ),
248     pVirDev( 0 ),
249 	pPrt( 0 ),
250     pPrtData( 0 ),
251 	pGlossaryDoc( 0 ),
252 	pOutlineRule( 0 ),
253 	pFtnInfo( new SwFtnInfo ),
254 	pEndNoteInfo( new SwEndNoteInfo ),
255 	pLineNumberInfo( new SwLineNumberInfo ),
256 	pFtnIdxs( new SwFtnIdxs ),
257 	pDocStat( new SwDocStat ),
258 	pDocShell( 0 ),
259 	pLinkMgr( new sfx2::LinkManager( 0 ) ),
260 	pACEWord( 0 ),
261 	pURLStateChgd( 0 ),
262 	pNumberFormatter( 0 ),
263 	pNumRuleTbl( new SwNumRuleTbl ),
264     // --> OD 2008-03-26 #refactorlists#
265     maLists(),
266     maListStyleLists(),
267     // <--
268     pRedlineTbl( new SwRedlineTbl ),
269 	pAutoFmtRedlnComment( 0 ),
270 	pUnoCrsrTbl( new SwUnoCrsrTbl( 0, 16 ) ),
271 	pPgPViewPrtData( 0 ),
272 	pExtInputRing( 0 ),
273 	pLayouter( 0 ),
274     // --> OD 2008-03-07 #refactorlists#
275     pStyleAccess( 0 ),
276     // <--
277     pLayoutCache( 0 ),
278     pUnoCallBack(new SwModify(0)),
279     mpGrammarContact( 0 ),
280     aChartDataProviderImplRef(),
281     pChartControllerHelper( 0 ),
282     // --> OD 2007-10-31 #i83479#
283     mpListItemsList( new tImplSortedNodeNumList() ),
284     // <--
285     m_pXmlIdRegistry(),
286 	nAutoFmtRedlnCommentNo( 0 ),
287 	nLinkUpdMode( GLOBALSETTING ),
288  	eFldUpdMode( AUTOUPD_GLOBALSETTING ),
289 	eRedlineMode((RedlineMode_t)(nsRedlineMode_t::REDLINE_SHOW_INSERT | nsRedlineMode_t::REDLINE_SHOW_DELETE)),
290 	eChrCmprType( CHARCOMPRESS_NONE ),
291     mReferenceCount(0),
292     mIdleBlockCount(0),
293     nLockExpFld( 0 ),
294 	mbReadlineChecked(false),
295     // --> OD 2005-02-11 #i38810#
296     mbLinksUpdated( sal_False ),
297     mbClipBoard( false ),
298     mbColumnSelection( false ),
299     // i#78591#
300 	mbProtectForm(false),
301     mbLastBrowseMode( false ),
302     n32DummyCompatabilityOptions1(0),
303     n32DummyCompatabilityOptions2(0),
304     mbStartIdleTimer(sal_False),
305 	mbSetDrawDefaults(false)
306 {
307 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDoc::SwDoc" );
308 
309 	mbGlossDoc =
310 	mbModified =
311 	mbDtor =
312 	mbPageNums =
313 	mbLoaded =
314 	mbUpdateExpFld =
315 	mbNewDoc =
316 	mbCopyIsMove =
317 	mbInReading =
318     mbInXMLImport =
319 	mbUpdateTOX =
320 	mbInLoadAsynchron =
321 	mbHTMLMode =
322 	mbInCallModified =
323 	mbIsGlobalDoc =
324 	mbGlblDocSaveLinks =
325 	mbIsLabelDoc =
326 	mbIsAutoFmtRedline =
327 	mbOLEPrtNotifyPending =
328 	mbAllOLENotify =
329 	mbIsRedlineMove =
330 	mbInsOnlyTxtGlssry =
331 	mbContains_MSVBasic =
332 	mbKernAsianPunctuation =
333 #ifdef DBG_UTIL
334 	mbXMLExport =
335 #endif
336     // --> OD 2006-03-21 #b6375613#
337     mbApplyWorkaroundForB6375613 =
338     // <--
339                             false;
340 
341 	mbNewFldLst =
342 	mbVisibleLinks =
343     mbPurgeOLE =
344                             true;
345 
346     //
347     // COMPATIBILITY FLAGS START
348     //
349 
350     // Note: Any non-hidden compatibility flag should obtain its default
351     // by asking SvtCompatibilityOptions, see below.
352     //
353     const SvtCompatibilityOptions aOptions;
354     mbParaSpaceMax                      = aOptions.IsAddSpacing();
355     mbParaSpaceMaxAtPages               = aOptions.IsAddSpacingAtPages();
356     mbTabCompat                         = !aOptions.IsUseOurTabStops();
357     mbUseVirtualDevice                  = !aOptions.IsUsePrtDevice();
358     mbAddExternalLeading                = !aOptions.IsNoExtLeading();
359     mbOldLineSpacing                    = aOptions.IsUseLineSpacing();
360     mbAddParaSpacingToTableCells        = aOptions.IsAddTableSpacing();
361     mbUseFormerObjectPos                = aOptions.IsUseObjectPositioning();
362     mbUseFormerTextWrapping             = aOptions.IsUseOurTextWrapping();
363     mbConsiderWrapOnObjPos              = aOptions.IsConsiderWrappingStyle();
364     mbMathBaselineAlignment                 = false;        // default for *old* documents is 'off'
365     mbAddFlyOffsets                         = false;        // hidden
366     mbOldNumbering                          = false;        // hidden
367     mbUseHiResolutionVirtualDevice          = true;         // hidden
368     mbIgnoreFirstLineIndentInNumbering      = false;        // hidden
369     mbDoNotJustifyLinesWithManualBreak      = !aOptions.IsExpandWordSpace();
370     mbDoNotResetParaAttrsForNumFont         = false;        // hidden
371     mbOutlineLevelYieldsOutlineRule         = false;        // hidden
372     mbTableRowKeep                          = false;        // hidden
373     mbIgnoreTabsAndBlanksForLineCalculation = false;        // hidden
374     mbDoNotCaptureDrawObjsOnPage            = false;        // hidden
375     mbClipAsCharacterAnchoredWriterFlyFrames= false;        // hidden
376     mbUnixForceZeroExtLeading               = false;        // hidden
377     mbOldPrinterMetrics                     = false;        // hidden
378     mbTabRelativeToIndent                   = true;         // hidden
379     // --> OD 2008-06-05 #i89181#
380     mbTabAtLeftIndentForParagraphsInList    = false;        // hidden
381     // <--
382 
383     //
384     // COMPATIBILITY FLAGS END
385     //
386 
387 	pMacroTable = new SvxMacroTableDtor;
388 
389     mpGrammarContact = ::createGrammarContact();
390 
391 	/*
392 	 * Defaultformate und DefaultFormatsammlungen (FmtColl)
393 	 * werden an der Position 0 in das jeweilige Array eingetragen.
394 	 * Die Formate der FmtColls sind von den Defaultformaten
395 	 * abgeleitet und stehen auch in der Liste.
396 	 */
397 	/* Formate */
398 	pFrmFmtTbl->Insert(pDfltFrmFmt, 0 );
399 	pCharFmtTbl->Insert(pDfltCharFmt, 0 );
400 
401 	/* FmtColls */
402 	// TXT
403 	pTxtFmtCollTbl->Insert(pDfltTxtFmtColl, 0 );
404     // GRF
405 	pGrfFmtCollTbl->Insert(pDfltGrfFmtColl, 0 );
406 
407 	// PageDesc, EmptyPageFmt und ColumnFmt anlegen
408 	if ( !aPageDescs.Count() )
409 		GetPageDescFromPool( RES_POOLPAGE_STANDARD );
410 
411 		//Leere Seite Einstellen.
412     pEmptyPageFmt->SetFmtAttr( SwFmtFrmSize( ATT_FIX_SIZE ) );
413 		//BodyFmt fuer Spalten Einstellen.
414     pColumnContFmt->SetFmtAttr( SwFmtFillOrder( ATT_LEFT_TO_RIGHT ) );
415 
416 	_InitFieldTypes();
417 
418     // lege (fuer die Filter) eine Default-OutlineNumRule an
419     // --> OD 2008-02-11 #newlistlevelattrs#
420     pOutlineRule = new SwNumRule( String::CreateFromAscii( SwNumRule::GetOutlineRuleName() ),
421                                   // --> OD 2008-06-06 #i89178#
422                                   numfunc::GetDefaultPositionAndSpaceMode(),
423                                   // <--
424                                   OUTLINE_RULE );
425     // <--
426     // #115901#
427     AddNumRule(pOutlineRule);
428     // --> OD 2005-10-21 - counting of phantoms depends on <IsOldNumbering()>
429     pOutlineRule->SetCountPhantoms( !get(IDocumentSettingAccess::OLD_NUMBERING) );
430     // <--
431 
432     new SwTxtNode(
433             SwNodeIndex(GetUndoManager().GetUndoNodes().GetEndOfContent()),
434             pDfltTxtFmtColl );
435     new SwTxtNode( SwNodeIndex( GetNodes().GetEndOfContent() ),
436 					GetTxtCollFromPool( RES_POOLCOLL_STANDARD ));
437 
438 	// den eigenen IdleTimer setzen
439 	aIdleTimer.SetTimeout( 600 );
440 	aIdleTimer.SetTimeoutHdl( LINK(this, SwDoc, DoIdleJobs) );
441 
442 	aOLEModifiedTimer.SetTimeout( 1000 );
443 	aOLEModifiedTimer.SetTimeoutHdl( LINK( this, SwDoc, DoUpdateModifiedOLE ));
444 
445 	// DBMgr anlegen
446 	pNewDBMgr = new SwNewDBMgr;
447 
448 	// create TOXTypes
449     InitTOXTypes();
450 
451     // --> OD 2008-03-07 #refactorlists#
452     // pass empty item set containing the paragraph's list attributes
453     // as ignorable items to the stype manager.
454     {
455         SfxItemSet aIgnorableParagraphItems( GetAttrPool(),
456                                              RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END-1,
457                                              0 );
458         pStyleAccess = createStyleManager( &aIgnorableParagraphItems );
459     }
460     // <--
461 
462     ResetModified();
463 }
464 
465 /*
466  * Besonderheiten: an der Position 0 des Arrays der Formate und
467  * der GDI-Objekte befindet sich ein Member der Klasse SwDoc.
468  * Dieser darf also keinesfalls durch delete geloescht
469  * werden!!!!!!!!!!
470  */
471 
472 
473 SwDoc::~SwDoc()
474 {
475     // nothing here should create Undo actions!
476     GetIDocumentUndoRedo().DoUndo(false);
477 
478     if (pDocShell)
479     {
480         pDocShell->SetUndoManager(0);
481     }
482 
483     // --> OD 2007-03-16 #i73788#
484     SwPauseThreadStarting aPauseThreadStarting;
485     // <--
486 
487     // --> OD 2007-11-01 #i83479#
488     delete mpListItemsList;
489     mpListItemsList = 0;
490     // <--
491 
492     // clean up chart related structures...
493     // Note: the chart data provider gets already diposed in ~SwDocShell
494     // since all UNO API related functionality requires an existing SwDocShell
495     // this assures that dipose gets called if there is need for it.
496     aChartDataProviderImplRef.reset();
497     delete pChartControllerHelper;
498 
499     delete mpGrammarContact;
500     mpGrammarContact = 0;
501 
502     //!! needs to be done to destroy a possible SwFmtDrop format that may
503     //!! be connected to a char format which may not otherwise be removed
504     //!! and thus would leave a unremoved SwFmt object. (TL)
505     //!! (this is case is not possible via UI but via API...)
506     SwFmtDrop aDrop;
507     SetDefault(aDrop);
508     //!! same for SwFmtCharFmt
509     SwFmtCharFmt aCharFmt(NULL);
510     SetDefault(aCharFmt);
511 
512 	StopIdling();	// stop idle timer
513 
514 	delete pUnoCallBack, pUnoCallBack = 0;
515 	delete pURLStateChgd;
516 
517 	delete pLayouter;
518     // --> OD 2005-09-05 #125370#
519     pLayouter = 0L;
520     // <--
521 
522 	// Undo-Benachrichtigung vom Draw abschalten
523 	if( pDrawModel )
524 	{
525 		DrawNotifyUndoHdl();
526 		ClrContourCache();
527 	}
528 
529 	delete pPgPViewPrtData;
530 
531 	mbDtor = sal_True;
532 	pLayoutPtr.reset();
533 
534 	delete pRedlineTbl;
535 	delete pUnoCrsrTbl;
536 	delete pAutoFmtRedlnComment;
537 
538 	if( pUpdtFlds )
539 		delete pUpdtFlds;
540 
541 	if( pACEWord )
542 		delete pACEWord;
543 
544 	// die BaseLinks freigeben.
545 	{
546 		for( sal_uInt16 n = pLinkMgr->GetServers().Count(); n; )
547 			pLinkMgr->GetServers()[ --n ]->Closed();
548 
549 		if( pLinkMgr->GetLinks().Count() )
550 			pLinkMgr->Remove( 0, pLinkMgr->GetLinks().Count() );
551 	}
552 
553 	// die KapitelNummern / Nummern muessen vor den Vorlage geloescht werden
554 	// ansonsten wird noch staendig geupdatet !!!
555     m_pNodes->pOutlineNds->Remove(sal_uInt16(0), m_pNodes->pOutlineNds->Count());
556     SwNodes & rUndoNodes( GetUndoManager().GetUndoNodes() );
557     rUndoNodes.pOutlineNds->Remove(sal_uInt16(0), rUndoNodes.pOutlineNds->Count());
558 
559 	pFtnIdxs->Remove( sal_uInt16(0), pFtnIdxs->Count() );
560 
561     // indices could be registered in attributes
562     m_pUndoManager->DelAllUndoObj();
563 
564 	// in den BookMarks sind Indizies auf den Content. Diese muessen vorm
565 	// loesche der Nodes geloescht werden.
566     pMarkManager->clearAllMarks();
567 	DELETEZ( pMacroTable );
568 
569 	if( pExtInputRing )
570 	{
571 		Ring* pTmp = pExtInputRing;
572 		pExtInputRing = 0;
573 		while( pTmp->GetNext() != pTmp )
574 			delete pTmp->GetNext();
575 		delete pTmp;
576 	}
577 
578 //JP: alt - loeschen ohne Flag ist teuer; Modify wird verschickt!
579 //	aTOXTypes.DeleteAndDestroy( 0, aTOXTypes.Count() );
580 	{
581 		for( sal_uInt16 n = pTOXTypes->Count(); n; )
582 		{
583 			(*pTOXTypes)[ --n ]->SetInDocDTOR();
584 			delete (*pTOXTypes)[ n ];
585 		}
586 		pTOXTypes->Remove( 0, pTOXTypes->Count() );
587 	}
588 	delete pDefTOXBases;
589 
590 	//Im einen oder anderen FrmFormat koennen noch Indizes angemeldet sein,
591 	//Diese muessen spaetestens jetzt zerstoert werden.
592 	pFrmFmtTbl->ForEach( &lcl_DelFmtIndizes, this );
593 	pSpzFrmFmtTbl->ForEach( &lcl_DelFmtIndizes, this );
594 	((SwFrmFmts&)*pSectionFmtTbl).ForEach( &lcl_DelFmtIndizes, this );
595 
596 	//Die Formate, die hier hinter stehen sind von den DefaultFormaten
597 	//abhaengig. Erst nach dem Loeschen der FmtIndizes weil der Inhalt von
598 	//Kopf-/Fussbereichen geloescht wird. Wenn dort noch Indizes von Flys
599 	//angemeldet sind gibts was an die Ohren.
600 	aPageDescs.DeleteAndDestroy( 0, aPageDescs.Count() );
601 
602 	// Inhaltssections loeschen
603 	// nicht erst durch den SwNodes-DTOR, damit Formate
604 	// keine Abhaengigen mehr haben.
605     m_pNodes->DelNodes( SwNodeIndex(*m_pNodes), m_pNodes->Count() );
606     rUndoNodes.DelNodes( SwNodeIndex( rUndoNodes ), rUndoNodes.Count() );
607 
608 	// Formate loeschen, spaeter mal permanent machen.
609 
610 	// Delete fuer Collections
611 	// damit die Abhaengigen wech sind
612     pFtnInfo->ReleaseCollection();
613     pEndNoteInfo->ReleaseCollection();
614 
615 	ASSERT( pDfltTxtFmtColl == (*pTxtFmtCollTbl)[0],
616 			"Default-Text-Collection muss immer am Anfang stehen" );
617 
618 	// JP 27.01.98: opt.: ausgehend davon, das Standard als 2. im Array
619 	// 				steht, sollte das als letztes geloescht werden, damit
620 	//				die ganze Umhaengerei der Formate vermieden wird!
621 	if( 2 < pTxtFmtCollTbl->Count() )
622 		pTxtFmtCollTbl->DeleteAndDestroy( 2, pTxtFmtCollTbl->Count()-2 );
623 	pTxtFmtCollTbl->DeleteAndDestroy( 1, pTxtFmtCollTbl->Count()-1 );
624 	delete pTxtFmtCollTbl;
625 
626 	ASSERT( pDfltGrfFmtColl == (*pGrfFmtCollTbl)[0],
627 			"Default-Grf-Collection muss immer am Anfang stehen" );
628 
629 	pGrfFmtCollTbl->DeleteAndDestroy( 1, pGrfFmtCollTbl->Count()-1 );
630 // ergibt sich automatisch - kein _DEL Array!
631 //	pGrfFmtCollTbl->Remove( 0, n );
632 	delete pGrfFmtCollTbl;
633 
634 	/*
635 	 * Defaultformate und DefaultFormatsammlungen (FmtColl)
636 	 * sind an der Position 0 der jeweiligen Arrays eingetragen.
637 	 * Damit sie nicht vom DTOR der Array's zum 2.mal geloescht werden,
638 	 * nehme sie aus dem Array.
639 	 */
640 	pFrmFmtTbl->Remove( 0 );
641 	pCharFmtTbl->Remove( 0 );
642 
643 	// Delete fuer pPrt
644 	DELETEZ( pPrt );
645 	DELETEZ( pNewDBMgr );
646 
647 	// Alle Flys muessen vor dem Drawing Model zerstoert werden,
648 	// da Flys noch DrawContacts enthalten koennen, wenn wegen
649 	// eines Lesefehlers kein Layout aufgebaut wurde.
650 	pSpzFrmFmtTbl->DeleteAndDestroy( 0, pSpzFrmFmtTbl->Count() );
651 
652 	//Erst jetzt das Model zerstoeren, die Zeichenobjekte - die ja auch
653 	//im Undo herumlungern - wollen noch ihre Attribute beim Model entfernen.
654 	//Ausserdem koennen vorher noch DrawContacts existieren.
655 	ReleaseDrawModel();
656 	//JP 28.01.99: DrawModel vorm LinkManager zerstoeren, da am DrawModel
657 	// 			dieser immer gesetzt ist.
658 	DELETEZ( pLinkMgr );
659 
660 	//Tables vor dem loeschen der Defaults leeren, sonst GPF wegen Def-Abhaengigen.
661 	//Die Arrays sollten (wegen includes) bei Gelegenheit auch zu Pointern werden.
662 	delete pFrmFmtTbl;
663 	delete pSpzFrmFmtTbl;
664 
665     delete pStyleAccess;
666 
667 	delete pCharFmtTbl;
668 	delete pSectionFmtTbl;
669 	delete pTblFrmFmtTbl;
670 	delete pDfltTxtFmtColl;
671 	delete pDfltGrfFmtColl;
672 	delete pNumRuleTbl;
673 
674     // --> OD 2008-03-26 #refactorlists#
675     {
676         for ( std::hash_map< String, SwList*, StringHash >::iterator
677                                                     aListIter = maLists.begin();
678               aListIter != maLists.end();
679               ++aListIter )
680         {
681             delete (*aListIter).second;
682         }
683         maLists.clear();
684     }
685     maListStyleLists.clear();
686     // <--
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