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