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