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