xref: /trunk/main/sw/source/core/doc/docnew.cxx (revision ca2e0b9568643ae230e0ef9afccb3d0c5a206de2)
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     meDocType( DOCTYPE_NATIVE ),
292     // --> OD 2005-02-11 #i38810#
293     mbLinksUpdated( sal_False ),
294     mbClipBoard( false ),
295     mbColumnSelection( false ),
296     mbContainsAtPageObjWithContentAnchor( false ),
297     // i#78591#
298     mbProtectForm(false),
299     mbLastBrowseMode( false ),
300     n32DummyCompatabilityOptions1(0),
301     n32DummyCompatabilityOptions2(0),
302     mbStartIdleTimer(sal_False),
303     mbSetDrawDefaults(false)
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     delete pPrtData;
687     delete pNumberFormatter;
688     delete pFtnInfo;
689     delete pEndNoteInfo;
690     delete pLineNumberInfo;
691     delete pFtnIdxs;
692     delete pFldTypes;
693     delete pTOXTypes;
694     delete pDocStat;
695     delete pEmptyPageFmt;
696     delete pColumnContFmt;
697     delete pDfltCharFmt;
698     delete pDfltFrmFmt;
699     delete pLayoutCache;
700     delete pVirDev;
701 
702     SfxItemPool::Free(mpAttrPool);
703 }
704 
705 //---------------------------------------------------
706 
707 VirtualDevice& SwDoc::CreateVirtualDevice_() const
708 {
709     VirtualDevice* pNewVir = new VirtualDevice( 1 );
710 
711     // <--
712     pNewVir->SetReferenceDevice( VirtualDevice::REFDEV_MODE_MSO1 );
713 
714     // --> FME 2006-10-09 #i60945# External leading compatibility for unix systems.
715     if ( get(IDocumentSettingAccess::UNIX_FORCE_ZERO_EXT_LEADING ) )
716         pNewVir->Compat_ZeroExtleadBug();
717     // <--
718 
719     MapMode aMapMode( pNewVir->GetMapMode() );
720     aMapMode.SetMapUnit( MAP_TWIP );
721     pNewVir->SetMapMode( aMapMode );
722 
723     const_cast<SwDoc*>(this)->setVirtualDevice( pNewVir, true, true );
724     return *pVirDev;
725 }
726 
727 //---------------------------------------------------
728 
729 SfxPrinter& SwDoc::CreatePrinter_() const
730 {
731     ASSERT( ! pPrt, "Do not call CreatePrinter_(), call getPrinter() instead" )
732 
733 #if OSL_DEBUG_LEVEL > 1
734     OSL_TRACE( "Printer will be created!" );
735 #endif
736 
737     // wir erzeugen einen default SfxPrinter.
738     // Das ItemSet wird vom Sfx geloescht!
739     SfxItemSet *pSet = new SfxItemSet( ((SwDoc*)this)->GetAttrPool(),
740                     FN_PARAM_ADDPRINTER, FN_PARAM_ADDPRINTER,
741                     SID_HTML_MODE,  SID_HTML_MODE,
742                     SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
743                     SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
744                     0 );
745 
746     SfxPrinter* pNewPrt = new SfxPrinter( pSet );
747     const_cast<SwDoc*>(this)->setPrinter( pNewPrt, true, true );
748     return *pPrt;
749 }
750 //---------------------------------------------------
751 
752 void SwDoc::SetDocShell( SwDocShell* pDSh )
753 {
754     if( pDocShell != pDSh )
755     {
756         if (pDocShell)
757         {
758             pDocShell->SetUndoManager(0);
759         }
760         pDocShell = pDSh;
761         if (pDocShell)
762         {
763             pDocShell->SetUndoManager(& GetUndoManager());
764         }
765 
766         pLinkMgr->SetPersist( pDocShell );
767         //JP 27.08.98: Bug 55570 - DocShell Pointer auch am DrawModel setzen
768         if( pDrawModel )
769         {
770             ((SwDrawDocument*)pDrawModel)->SetObjectShell( pDocShell );
771             pDrawModel->SetPersist( pDocShell );
772             ASSERT( pDrawModel->GetPersist() == GetPersist(),
773                     "draw model's persist is out of sync" );
774         }
775     }
776 }
777 
778 
779 // Convenience-Methode, um uebermaessige Includes von docsh.hxx
780 // zu vermeiden
781 
782 
783 
784 uno::Reference < embed::XStorage > SwDoc::GetDocStorage()
785 {
786     if( pDocShell )
787         return pDocShell->GetStorage();
788     if( pLinkMgr->GetPersist() )
789         return pLinkMgr->GetPersist()->GetStorage();
790     return NULL;
791 }
792 
793 
794 
795 SfxObjectShell* SwDoc::GetPersist() const
796 {
797     return pDocShell ? pDocShell : pLinkMgr->GetPersist();
798 }
799 
800 
801 void SwDoc::ClearDoc()
802 {
803     GetIDocumentUndoRedo().DelAllUndoObj();
804     ::sw::UndoGuard const undoGuard(GetIDocumentUndoRedo());
805 
806     // Undo-Benachrichtigung vom Draw abschalten
807     if( pDrawModel )
808     {
809         DrawNotifyUndoHdl();
810         ClrContourCache();
811     }
812 
813     // stehen noch FlyFrames rum, loesche auch diese
814     sal_uInt16 n;
815     while ( 0 != (n = GetSpzFrmFmts()->Count()) )
816         DelLayoutFmt((*pSpzFrmFmtTbl)[n-1]);
817     ASSERT( !pDrawModel || !pDrawModel->GetPage(0)->GetObjCount(),
818                 "not all DrawObjects removed from the page" );
819 
820     pRedlineTbl->DeleteAndDestroy( 0, pRedlineTbl->Count() );
821 
822     if( pACEWord )
823         delete pACEWord;
824 
825     // in den BookMarks sind Indizies auf den Content. Diese muessen vorm
826     // loesche der Nodes geloescht werden.
827     pMarkManager->clearAllMarks();
828     InitTOXTypes();
829 
830     // create a dummy pagedesc for the layout
831     sal_uInt16 nDummyPgDsc = MakePageDesc( String::CreateFromAscii( "?DUMMY?" ));
832     SwPageDesc* pDummyPgDsc = aPageDescs[ nDummyPgDsc ];
833 
834     SwNodeIndex aSttIdx( *GetNodes().GetEndOfContent().StartOfSectionNode(), 1 );
835     // den ersten immer wieder neu anlegen (ohne Attribute/Vorlagen/...)
836     SwTxtNode* pFirstNd = GetNodes().MakeTxtNode( aSttIdx, pDfltTxtFmtColl );
837 
838     if( pCurrentView )  //swmod 071029//swmod 071225
839     {
840         // set the layout to the dummy pagedesc
841         pFirstNd->SetAttr( SwFmtPageDesc( pDummyPgDsc ));
842 
843         SwPosition aPos( *pFirstNd, SwIndex( pFirstNd ));
844         SwPaM const tmpPaM(aSttIdx, SwNodeIndex(GetNodes().GetEndOfContent()));
845         ::PaMCorrAbs(tmpPaM, aPos);
846     }
847 
848     GetNodes().Delete( aSttIdx,
849             GetNodes().GetEndOfContent().GetIndex() - aSttIdx.GetIndex() );
850 
851     // --> OD 2006-02-28 #i62440#
852     // destruction of numbering rules and creation of new outline rule
853     // *after* the document nodes are deleted.
854     pOutlineRule = NULL;
855     pNumRuleTbl->DeleteAndDestroy( 0, pNumRuleTbl->Count() );
856     // --> OD #i114725#,#i115828#
857     {
858         for ( std::hash_map< String, SwList*, StringHash >::iterator
859                                                     aListIter = maLists.begin();
860               aListIter != maLists.end();
861               ++aListIter )
862         {
863             delete (*aListIter).second;
864         }
865         maLists.clear();
866     }
867     maListStyleLists.clear();
868     // <--
869     // creation of new outline numbering rule
870     // --> OD 2008-02-11 #newlistlevelattrs#
871     pOutlineRule = new SwNumRule( String::CreateFromAscii( SwNumRule::GetOutlineRuleName() ),
872                                   // --> OD 2008-06-06 #i89178#
873                                   numfunc::GetDefaultPositionAndSpaceMode(),
874                                   // <--
875                                   OUTLINE_RULE );
876     // <--
877     AddNumRule(pOutlineRule);
878     // --> OD 2005-10-21 - counting of phantoms depends on <IsOldNumbering()>
879     pOutlineRule->SetCountPhantoms( !get(IDocumentSettingAccess::OLD_NUMBERING) );
880     // <--
881     // <--
882 
883     //remove the dummy pagedec from the array and delete all the old ones
884     aPageDescs.Remove( nDummyPgDsc );
885     aPageDescs.DeleteAndDestroy( 0, aPageDescs.Count() );
886 
887     // Delete fuer Collections
888     // damit die Abhaengigen wech sind
889     pFtnInfo->ReleaseCollection();
890     pEndNoteInfo->ReleaseCollection();
891 
892     // JP 27.01.98: opt.: ausgehend davon, das Standard als 2. im Array
893     //              steht, sollte das als letztes geloescht werden, damit
894     //              die ganze Umhaengerei der Formate vermieden wird!
895     if( 2 < pTxtFmtCollTbl->Count() )
896         pTxtFmtCollTbl->DeleteAndDestroy( 2, pTxtFmtCollTbl->Count()-2 );
897     pTxtFmtCollTbl->DeleteAndDestroy( 1, pTxtFmtCollTbl->Count()-1 );
898     pGrfFmtCollTbl->DeleteAndDestroy( 1, pGrfFmtCollTbl->Count()-1 );
899     pCharFmtTbl->DeleteAndDestroy( 1, pCharFmtTbl->Count()-1 );
900 
901     if( pCurrentView )
902     {
903         // search the FrameFormat of the root frm. This is not allowed to delete
904         pFrmFmtTbl->Remove( pFrmFmtTbl->GetPos( pCurrentView->GetLayout()->GetFmt() ) );
905         pFrmFmtTbl->DeleteAndDestroy( 1, pFrmFmtTbl->Count()-1 );
906         pFrmFmtTbl->Insert( pCurrentView->GetLayout()->GetFmt(), pFrmFmtTbl->Count() );
907     }
908     else    //swmod 071029//swmod 071225
909         pFrmFmtTbl->DeleteAndDestroy( 1, pFrmFmtTbl->Count()-1 );
910 
911     xForbiddenCharsTable.unbind();
912 
913     pFldTypes->DeleteAndDestroy( INIT_FLDTYPES,
914                                 pFldTypes->Count() - INIT_FLDTYPES );
915 
916     delete pNumberFormatter, pNumberFormatter = 0;
917 
918     GetPageDescFromPool( RES_POOLPAGE_STANDARD );
919     pFirstNd->ChgFmtColl( GetTxtCollFromPool( RES_POOLCOLL_STANDARD ));
920     nDummyPgDsc = aPageDescs.Count();
921     aPageDescs.Insert( pDummyPgDsc, nDummyPgDsc );
922     // set the layout back to the new standard pagedesc
923     pFirstNd->ResetAllAttr();
924     // delete now the dummy pagedesc
925     DelPageDesc( nDummyPgDsc );
926 }
927 
928 void SwDoc::SetPreViewPrtData( const SwPagePreViewPrtData* pNew )
929 {
930     if( pNew )
931     {
932         if( pPgPViewPrtData )
933             *pPgPViewPrtData = *pNew;
934         else
935             pPgPViewPrtData = new SwPagePreViewPrtData( *pNew );
936     }
937     else if( pPgPViewPrtData )
938         DELETEZ( pPgPViewPrtData );
939     SetModified();
940 }
941 /* -----------------------------06.01.00 14:03--------------------------------
942 
943  ---------------------------------------------------------------------------*/
944 SwModify*   SwDoc::GetUnoCallBack() const
945 {
946     return pUnoCallBack;
947 }
948 
949 /*-----------------28.5.2001 10:06------------------
950  * SwDoc:
951  *  Reading and writing of the layout cache.
952  *--------------------------------------------------*/
953 
954 void SwDoc::ReadLayoutCache( SvStream& rStream )
955 {
956     if( !pLayoutCache )
957         pLayoutCache = new SwLayoutCache();
958     if( !pLayoutCache->IsLocked() )
959     {
960         pLayoutCache->GetLockCount() |= 0x8000;
961         pLayoutCache->Read( rStream );
962         pLayoutCache->GetLockCount() &= 0x7fff;
963     }
964 }
965 
966 void SwDoc::WriteLayoutCache( SvStream& rStream )
967 {
968     pLayoutCache->Write( rStream, *this );
969 }
970 
971 IGrammarContact* getGrammarContact( const SwTxtNode& rTxtNode )
972 {
973     const SwDoc* pDoc = rTxtNode.GetDoc();
974     if( !pDoc || pDoc->IsInDtor() )
975         return 0;
976     return pDoc->getGrammarContact();
977 }
978 
979 // --> FME 2005-02-25 #i42634# Moved common code of SwReader::Read() and
980 // SwDocShell::UpdateLinks() to new SwDoc::UpdateLinks():
981 void SwDoc::UpdateLinks( sal_Bool bUI )
982 {
983     SfxObjectCreateMode eMode;
984     sal_uInt16 nLinkMode = getLinkUpdateMode( true );
985     sal_uInt16 nUpdateDocMode = GetDocShell()->GetUpdateDocMode();
986     if( GetDocShell() &&
987             (nLinkMode != NEVER ||  document::UpdateDocMode::FULL_UPDATE == nUpdateDocMode) &&
988         GetLinkManager().GetLinks().Count() &&
989         SFX_CREATE_MODE_INTERNAL !=
990                     ( eMode = GetDocShell()->GetCreateMode()) &&
991         SFX_CREATE_MODE_ORGANIZER != eMode &&
992         SFX_CREATE_MODE_PREVIEW != eMode &&
993         !GetDocShell()->IsPreview() )
994     {
995         ViewShell* pVSh = 0;
996         sal_Bool bAskUpdate = nLinkMode == MANUAL;
997         sal_Bool bUpdate = sal_True;
998         switch(nUpdateDocMode)
999         {
1000             case document::UpdateDocMode::NO_UPDATE:   bUpdate = sal_False;break;
1001             case document::UpdateDocMode::QUIET_UPDATE:bAskUpdate = sal_False; break;
1002             case document::UpdateDocMode::FULL_UPDATE: bAskUpdate = sal_True; break;
1003         }
1004         if( bUpdate && (bUI || !bAskUpdate) )
1005         {
1006             SfxMedium* pMedium = GetDocShell()->GetMedium();
1007             SfxFrame* pFrm = pMedium ? pMedium->GetLoadTargetFrame() : 0;
1008             Window* pDlgParent = pFrm ? &pFrm->GetWindow() : 0;
1009             if( GetCurrentViewShell() && !GetEditShell( &pVSh ) && !pVSh )  //swmod 071108//swmod 071225
1010             {
1011                 ViewShell aVSh( *this, 0, 0 );
1012 
1013                 SET_CURR_SHELL( &aVSh );
1014                 GetLinkManager().UpdateAllLinks( bAskUpdate , sal_True, sal_False, pDlgParent );
1015             }
1016             else
1017                 GetLinkManager().UpdateAllLinks( bAskUpdate, sal_True, sal_False, pDlgParent );
1018         }
1019     }
1020 
1021 }
1022 // <--
1023 // --> OD 2006-04-19 #b6375613#
1024 void SwDoc::SetApplyWorkaroundForB6375613( bool p_bApplyWorkaroundForB6375613 )
1025 {
1026     if ( mbApplyWorkaroundForB6375613 != p_bApplyWorkaroundForB6375613 )
1027     {
1028         mbApplyWorkaroundForB6375613 = p_bApplyWorkaroundForB6375613;
1029 
1030         uno::Reference< document::XDocumentInfoSupplier > xDoc(
1031                                                 GetDocShell()->GetBaseModel(),
1032                                                 uno::UNO_QUERY);
1033         if ( xDoc.is() )
1034         {
1035             uno::Reference< beans::XPropertyContainer > xDocInfo(
1036                                                         xDoc->getDocumentInfo(),
1037                                                         uno::UNO_QUERY );
1038             if ( xDocInfo.is() )
1039             {
1040                 try
1041                 {
1042                     if ( mbApplyWorkaroundForB6375613 )
1043                     {
1044                         xDocInfo->addProperty(
1045                             rtl::OUString::createFromAscii("WorkaroundForB6375613Applied"),
1046                             beans::PropertyAttribute::TRANSIENT | beans::PropertyAttribute::REMOVABLE,
1047                             uno::makeAny( false ) );
1048                     }
1049                     else
1050                     {
1051                         xDocInfo->removeProperty( rtl::OUString::createFromAscii("WorkaroundForB6375613Applied") );
1052                     }
1053                 }
1054                 catch( uno::Exception& )
1055                 {
1056                 }
1057             }
1058         }
1059     }
1060 }
1061 // <--
1062 
1063 ::sfx2::IXmlIdRegistry&
1064 SwDoc::GetXmlIdRegistry()
1065 {
1066     // UGLY: this relies on SetClipBoard being called before GetXmlIdRegistry!
1067     if (!m_pXmlIdRegistry.get())
1068     {
1069         m_pXmlIdRegistry.reset( ::sfx2::createXmlIdRegistry( IsClipBoard() ) );
1070     }
1071     return *m_pXmlIdRegistry;
1072 }
1073 
1074 ::sw::MetaFieldManager &
1075 SwDoc::GetMetaFieldManager()
1076 {
1077     return *m_pMetaFieldManager;
1078 }
1079 
1080 ::sw::UndoManager &
1081 SwDoc::GetUndoManager()
1082 {
1083     return *m_pUndoManager;
1084 }
1085 
1086 ::sw::UndoManager const&
1087 SwDoc::GetUndoManager() const
1088 {
1089     return *m_pUndoManager;
1090 }
1091 
1092 IDocumentUndoRedo &
1093 SwDoc::GetIDocumentUndoRedo()
1094 {
1095     return *m_pUndoManager;
1096 }
1097 
1098 IDocumentUndoRedo const&
1099 SwDoc::GetIDocumentUndoRedo() const
1100 {
1101     return *m_pUndoManager;
1102 }
1103 
1104 void SwDoc::InitTOXTypes()
1105 {
1106    ShellResource* pShellRes = ViewShell::GetShellRes();
1107    SwTOXType * pNew = new SwTOXType(TOX_CONTENT,   pShellRes->aTOXContentName        );
1108    pTOXTypes->Insert( pNew, pTOXTypes->Count() );
1109    pNew = new SwTOXType(TOX_INDEX,                 pShellRes->aTOXIndexName  );
1110    pTOXTypes->Insert( pNew, pTOXTypes->Count() );
1111    pNew = new SwTOXType(TOX_USER,                  pShellRes->aTOXUserName  );
1112    pTOXTypes->Insert( pNew, pTOXTypes->Count() );
1113    pNew = new SwTOXType(TOX_ILLUSTRATIONS,         pShellRes->aTOXIllustrationsName );
1114    pTOXTypes->Insert( pNew, pTOXTypes->Count() );
1115    pNew = new SwTOXType(TOX_OBJECTS,               pShellRes->aTOXObjectsName       );
1116    pTOXTypes->Insert( pNew, pTOXTypes->Count() );
1117    pNew = new SwTOXType(TOX_TABLES,                pShellRes->aTOXTablesName        );
1118    pTOXTypes->Insert( pNew, pTOXTypes->Count() );
1119    pNew = new SwTOXType(TOX_AUTHORITIES,           pShellRes->aTOXAuthoritiesName   );
1120    pTOXTypes->Insert( pNew, pTOXTypes->Count() );
1121 }
1122 
1123 /*-- 08.05.2009 10:07:57---------------------------------------------------
1124 
1125   -----------------------------------------------------------------------*/
1126 SfxObjectShell* SwDoc::CreateCopy(bool bCallInitNew ) const
1127 {
1128     SwDoc* pRet = new SwDoc;
1129     //copy settings
1130     sal_uInt16 __FAR_DATA aRangeOfDefaults[] = {
1131         RES_FRMATR_BEGIN, RES_FRMATR_END-1,
1132         RES_CHRATR_BEGIN, RES_CHRATR_END-1,
1133         RES_PARATR_BEGIN, RES_PARATR_END-1,
1134         // --> OD 2008-02-25 #refactorlists##
1135         RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END-1,
1136         // <--
1137         RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1,
1138         0
1139     };
1140 
1141     SfxItemSet aNewDefaults( pRet->GetAttrPool(), aRangeOfDefaults );
1142 
1143     sal_uInt16 nWhich;
1144     sal_uInt16 nRange = 0;
1145     while( aRangeOfDefaults[nRange] != 0)
1146     {
1147         for( nWhich = aRangeOfDefaults[nRange]; nWhich < aRangeOfDefaults[nRange + 1]; ++nWhich )
1148         {
1149             const SfxPoolItem& rSourceAttr = mpAttrPool->GetDefaultItem( nWhich );
1150             if( rSourceAttr != pRet->mpAttrPool->GetDefaultItem( nWhich ) )
1151                 aNewDefaults.Put( rSourceAttr );
1152         }
1153         nRange += 2;
1154     }
1155     if( aNewDefaults.Count() )
1156         pRet->SetDefault( aNewDefaults );
1157 
1158     pRet->n32DummyCompatabilityOptions1 = n32DummyCompatabilityOptions1;
1159     pRet->n32DummyCompatabilityOptions2 = n32DummyCompatabilityOptions2;
1160     pRet->mbParaSpaceMax                          = mbParaSpaceMax                          ;
1161     pRet->mbParaSpaceMaxAtPages                   = mbParaSpaceMaxAtPages                   ;
1162     pRet->mbTabCompat                             = mbTabCompat                             ;
1163     pRet->mbUseVirtualDevice                      = mbUseVirtualDevice                      ;
1164     pRet->mbAddExternalLeading                    = mbAddExternalLeading                    ;
1165     pRet->mbOldLineSpacing                        = mbOldLineSpacing                        ;
1166     pRet->mbAddParaSpacingToTableCells            = mbAddParaSpacingToTableCells            ;
1167     pRet->mbUseFormerObjectPos                    = mbUseFormerObjectPos                    ;
1168     pRet->mbUseFormerTextWrapping                 = mbUseFormerTextWrapping                 ;
1169     pRet->mbConsiderWrapOnObjPos                  = mbConsiderWrapOnObjPos                  ;
1170     pRet->mbAddFlyOffsets                         = mbAddFlyOffsets                         ;
1171     pRet->mbOldNumbering                          = mbOldNumbering                          ;
1172     pRet->mbUseHiResolutionVirtualDevice          = mbUseHiResolutionVirtualDevice          ;
1173     pRet->mbIgnoreFirstLineIndentInNumbering      = mbIgnoreFirstLineIndentInNumbering      ;
1174     pRet->mbDoNotJustifyLinesWithManualBreak      = mbDoNotJustifyLinesWithManualBreak      ;
1175     pRet->mbDoNotResetParaAttrsForNumFont         = mbDoNotResetParaAttrsForNumFont         ;
1176     pRet->mbOutlineLevelYieldsOutlineRule         = mbOutlineLevelYieldsOutlineRule         ;
1177     pRet->mbTableRowKeep                          = mbTableRowKeep                          ;
1178     pRet->mbIgnoreTabsAndBlanksForLineCalculation = mbIgnoreTabsAndBlanksForLineCalculation ;
1179     pRet->mbDoNotCaptureDrawObjsOnPage            = mbDoNotCaptureDrawObjsOnPage            ;
1180     pRet->mbClipAsCharacterAnchoredWriterFlyFrames= mbClipAsCharacterAnchoredWriterFlyFrames;
1181     pRet->mbUnixForceZeroExtLeading               = mbUnixForceZeroExtLeading               ;
1182     pRet->mbOldPrinterMetrics                     = mbOldPrinterMetrics                     ;
1183     pRet->mbTabRelativeToIndent                   = mbTabRelativeToIndent                   ;
1184     pRet->mbTabAtLeftIndentForParagraphsInList    = mbTabAtLeftIndentForParagraphsInList    ;
1185 
1186     //
1187     // COMPATIBILITY FLAGS END
1188     //
1189     pRet->ReplaceStyles( * const_cast< SwDoc*>( this ));
1190 
1191     // we have to use pointer here, since the callee has to decide whether SfxObjectShellLock or SfxObjectShellRef should be used
1192     // sometimes the object will be returned with refcount set to 0 ( if no DoInitNew is done )
1193     SfxObjectShell* pRetShell = new SwDocShell( pRet, SFX_CREATE_MODE_STANDARD );
1194     if( bCallInitNew )
1195     {
1196         // it could happen that DoInitNew creates model, that increases the refcount of the object
1197         pRetShell->DoInitNew();
1198     }
1199 
1200     //copy content
1201     pRet->Paste( *this );
1202 
1203     // remove the temporary shell if it is there as it was done before
1204     pRet->SetTmpDocShell( (SfxObjectShell*)NULL );
1205 
1206     return pRetShell;
1207 }
1208 /*-- 08.05.2009 10:52:40---------------------------------------------------
1209     copy document content - code from SwFEShell::Paste( SwDoc* , sal_Bool  )
1210   -----------------------------------------------------------------------*/
1211 void SwDoc::Paste( const SwDoc& rSource )
1212 {
1213 //  this has to be empty const sal_uInt16 nStartPageNumber = GetPhyPageNum();
1214     // until the end of the NodesArray
1215     SwNodeIndex aSourceIdx( rSource.GetNodes().GetEndOfExtras(), 2 );
1216     SwPaM aCpyPam( aSourceIdx ); //DocStart
1217     SwNodeIndex aTargetIdx( GetNodes().GetEndOfExtras(), 2 );
1218     SwPaM aInsertPam( aTargetIdx ); //replaces PCURCRSR from SwFEShell::Paste()
1219 
1220 
1221     aCpyPam.SetMark();
1222     aCpyPam.Move( fnMoveForward, fnGoDoc );
1223 
1224     this->GetIDocumentUndoRedo().StartUndo( UNDO_INSGLOSSARY, NULL );
1225     this->LockExpFlds();
1226 
1227     {
1228         SwPosition& rInsPos = *aInsertPam.GetPoint();
1229         //find out if the clipboard document starts with a table
1230         bool bStartWithTable = 0 != aCpyPam.Start()->nNode.GetNode().FindTableNode();
1231         SwPosition aInsertPosition( rInsPos );
1232 
1233         {
1234             SwNodeIndex aIndexBefore(rInsPos.nNode);
1235 
1236             aIndexBefore--;
1237 
1238             rSource.CopyRange( aCpyPam, rInsPos, true );
1239 
1240             {
1241                 aIndexBefore++;
1242                 SwPaM aPaM(SwPosition(aIndexBefore),
1243                            SwPosition(rInsPos.nNode));
1244 
1245                 MakeUniqueNumRules(aPaM);
1246             }
1247         }
1248 
1249         //TODO: Is this necessary here? SaveTblBoxCntnt( &rInsPos );
1250         if(/*bIncludingPageFrames && */bStartWithTable)
1251         {
1252             //remove the paragraph in front of the table
1253             SwPaM aPara(aInsertPosition);
1254             this->DelFullPara(aPara);
1255         }
1256         //additionally copy page bound frames
1257         if( /*bIncludingPageFrames && */rSource.GetSpzFrmFmts()->Count() )
1258         {
1259             for ( sal_uInt16 i = 0; i < rSource.GetSpzFrmFmts()->Count(); ++i )
1260             {
1261                 sal_Bool bInsWithFmt = sal_True;
1262                 const SwFrmFmt& rCpyFmt = *(*rSource.GetSpzFrmFmts())[i];
1263                 if( bInsWithFmt  )
1264                 {
1265                     SwFmtAnchor aAnchor( rCpyFmt.GetAnchor() );
1266                     if (FLY_AT_PAGE == aAnchor.GetAnchorId())
1267                     {
1268                         aAnchor.SetPageNum( aAnchor.GetPageNum() /*+ nStartPageNumber - */);
1269                     }
1270                     else
1271                         continue;
1272                     this->CopyLayoutFmt( rCpyFmt, aAnchor, true, true );
1273                 }
1274             }
1275         }
1276     }
1277 
1278     this->GetIDocumentUndoRedo().EndUndo( UNDO_INSGLOSSARY, NULL );
1279 
1280     UnlockExpFlds();
1281     UpdateFlds(NULL, false);
1282 }
1283