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