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