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