Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #define ROLBCK_HISTORY_ONLY // The fight against the CLOOK's
21 : #include <doc.hxx>
22 : #include <dcontact.hxx>
23 : #include <com/sun/star/document/PrinterIndependentLayout.hpp>
24 : #include <com/sun/star/document/UpdateDocMode.hpp>
25 : #include <com/sun/star/text/XTextDocument.hpp>
26 : #include <com/sun/star/linguistic2/XProofreadingIterator.hpp>
27 : #include <com/sun/star/text/XFlatParagraphIteratorProvider.hpp>
28 :
29 : #include <comphelper/processfactory.hxx>
30 : #include <vcl/svapp.hxx>
31 : #include <vcl/virdev.hxx>
32 : #include <rtl/logfile.hxx>
33 : #include <rtl/random.h>
34 : #include <sfx2/printer.hxx>
35 : #include <sfx2/docfile.hxx>
36 : #include <sfx2/frame.hxx>
37 : #include <sfx2/viewfrm.hxx>
38 :
39 : #include <svl/macitem.hxx>
40 : #include <svx/svxids.hrc>
41 : #include <svx/svdogrp.hxx>
42 : #include <sfx2/linkmgr.hxx>
43 : #include <editeng/forbiddencharacterstable.hxx>
44 : #include <svl/zforlist.hxx>
45 : #include <unotools/compatibility.hxx>
46 : #include <unotools/lingucfg.hxx>
47 : #include <svx/svdpage.hxx>
48 : #include <paratr.hxx>
49 : #include <fchrfmt.hxx>
50 : #include <fmtcntnt.hxx>
51 : #include <fmtanchr.hxx>
52 : #include <fmtfsize.hxx>
53 : #include <fmtfordr.hxx>
54 : #include <fmtpdsc.hxx>
55 : #include <pvprtdat.hxx>
56 : #include <rootfrm.hxx> // So that the RootDtor is being called
57 : #include <layouter.hxx>
58 : #include <pagedesc.hxx> // So that the PageDescs can be destroyed
59 : #include <ndtxt.hxx>
60 : #include <printdata.hxx>
61 : #include <docfld.hxx>
62 : #include <ftninfo.hxx>
63 : #include <ftnidx.hxx>
64 : #include <docstat.hxx>
65 : #include <charfmt.hxx>
66 : #include <frmfmt.hxx>
67 : #include <rolbck.hxx> // Undo attributes, SwHistory
68 : #include <poolfmt.hxx> // for the Pool template
69 : #include <dbmgr.hxx>
70 : #include <docsh.hxx>
71 : #include <acorrect.hxx> // for the automatic adding of exceptions
72 : #include <visiturl.hxx> // for the URLChange message
73 : #include <docary.hxx>
74 : #include <lineinfo.hxx>
75 : #include <drawdoc.hxx>
76 : #include <linkenum.hxx>
77 : #include <fldupde.hxx>
78 : #include <extinput.hxx>
79 : #include <viewsh.hxx>
80 : #include <doctxm.hxx>
81 : #include <shellres.hxx>
82 : #include <breakit.hxx>
83 : #include <laycache.hxx>
84 : #include <mvsave.hxx>
85 : #include <istyleaccess.hxx>
86 : #include <swstylemanager.hxx>
87 : #include <IGrammarContact.hxx>
88 : #include <tblsel.hxx>
89 : #include <MarkManager.hxx>
90 : #include <UndoManager.hxx>
91 : #include <unochart.hxx>
92 : #include <fldbas.hxx>
93 :
94 : #include <cmdid.h> // for the default printer in SetJob
95 :
96 : #include <pausethreadstarting.hxx>
97 : #include <numrule.hxx>
98 : #include <list.hxx>
99 : #include <listfunc.hxx>
100 :
101 : #include <sfx2/Metadatable.hxx>
102 : #include <fmtmeta.hxx> // MetaFieldManager
103 : #include <boost/foreach.hpp>
104 :
105 : using namespace ::com::sun::star;
106 : using namespace ::com::sun::star::document;
107 :
108 : const sal_Char sFrmFmtStr[] = "Frameformat";
109 : const sal_Char sEmptyPageStr[] = "Empty Page";
110 : const sal_Char sColumnCntStr[] = "Columncontainer";
111 : const sal_Char sCharFmtStr[] = "Zeichenformat";
112 : const sal_Char sTxtCollStr[] = "Textformatvorlage";
113 : const sal_Char sGrfCollStr[] = "Graphikformatvorlage";
114 :
115 : /*
116 : * global functions...
117 : */
118 467 : uno::Reference< linguistic2::XProofreadingIterator > SwDoc::GetGCIterator() const
119 : {
120 467 : if (!m_xGCIterator.is() && SvtLinguConfig().HasGrammarChecker())
121 : {
122 0 : uno::Reference< lang::XMultiServiceFactory > xMgr( comphelper::getProcessServiceFactory() );
123 0 : if (xMgr.is())
124 : {
125 : try
126 : {
127 0 : rtl::OUString aServiceName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.linguistic2.ProofreadingIterator"));
128 : m_xGCIterator = uno::Reference< linguistic2::XProofreadingIterator >
129 0 : ( xMgr->createInstance( aServiceName ), uno::UNO_QUERY_THROW );
130 : }
131 0 : catch (uno::Exception &)
132 : {
133 : OSL_FAIL( "No GCIterator" );
134 : }
135 0 : }
136 : }
137 :
138 467 : return m_xGCIterator;
139 : }
140 :
141 467 : void StartGrammarChecking( SwDoc &rDoc )
142 : {
143 : // check for a visible view
144 467 : bool bVisible = false;
145 467 : const SwDocShell *pDocShell = rDoc.GetDocShell();
146 467 : SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pDocShell, sal_False );
147 1401 : while (pFrame && !bVisible)
148 : {
149 467 : if (pFrame->IsVisible())
150 467 : bVisible = true;
151 467 : pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell, sal_False );
152 : }
153 :
154 : //!! only documents with visible views need to be checked
155 : //!! (E.g. don't check temporary documents created for printing, see printing of notes and selections.
156 : //!! Those get created on the fly and get hard deleted a bit later as well, and no one should have
157 : //!! a uno reference to them)
158 467 : if (bVisible)
159 : {
160 467 : uno::Reference< linguistic2::XProofreadingIterator > xGCIterator( rDoc.GetGCIterator() );
161 467 : if ( xGCIterator.is() )
162 : {
163 0 : uno::Reference< lang::XComponent > xDoc( rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY );
164 0 : uno::Reference< text::XFlatParagraphIteratorProvider > xFPIP( xDoc, uno::UNO_QUERY );
165 :
166 : // start automatic background checking if not active already
167 0 : if ( xFPIP.is() && !xGCIterator->isProofreading( xDoc ) )
168 0 : xGCIterator->startProofreading( xDoc, xFPIP );
169 467 : }
170 : }
171 467 : }
172 :
173 : /*
174 : * internal functions
175 : */
176 388 : static void lcl_DelFmtIndizes( SwFmt* pFmt )
177 : {
178 388 : SwFmtCntnt &rFmtCntnt = (SwFmtCntnt&)pFmt->GetCntnt();
179 388 : if ( rFmtCntnt.GetCntntIdx() )
180 99 : rFmtCntnt.SetNewCntntIdx( 0 );
181 388 : SwFmtAnchor &rFmtAnchor = (SwFmtAnchor&)pFmt->GetAnchor();
182 388 : if ( rFmtAnchor.GetCntntAnchor() )
183 140 : rFmtAnchor.SetAnchor( 0 );
184 388 : }
185 :
186 : /*
187 : * exported methods
188 : */
189 276 : SwDoc::SwDoc()
190 276 : : m_pNodes( new SwNodes(this) )
191 : ,
192 276 : mpAttrPool(new SwAttrPool(this)),
193 276 : pMarkManager(new ::sw::mark::MarkManager(*this)),
194 0 : m_pMetaFieldManager(new ::sw::MetaFieldManager()),
195 : m_pUndoManager(new ::sw::UndoManager(
196 552 : ::std::auto_ptr<SwNodes>(new SwNodes(this)), *this, *this, *this)),
197 276 : pDfltFrmFmt( new SwFrmFmt( GetAttrPool(), sFrmFmtStr, 0 ) ),
198 276 : pEmptyPageFmt( new SwFrmFmt( GetAttrPool(), sEmptyPageStr, pDfltFrmFmt ) ),
199 276 : pColumnContFmt( new SwFrmFmt( GetAttrPool(), sColumnCntStr, pDfltFrmFmt ) ),
200 276 : pDfltCharFmt( new SwCharFmt( GetAttrPool(), sCharFmtStr, 0 ) ),
201 276 : pDfltTxtFmtColl( new SwTxtFmtColl( GetAttrPool(), sTxtCollStr ) ),
202 276 : pDfltGrfFmtColl( new SwGrfFmtColl( GetAttrPool(), sGrfCollStr ) ),
203 0 : pFrmFmtTbl( new SwFrmFmts() ),
204 0 : pCharFmtTbl( new SwCharFmts() ),
205 0 : pSpzFrmFmtTbl( new SwFrmFmts() ),
206 0 : pSectionFmtTbl( new SwSectionFmts() ),
207 0 : pTblFrmFmtTbl( new SwFrmFmts() ),
208 0 : pTxtFmtCollTbl( new SwTxtFmtColls() ),
209 0 : pGrfFmtCollTbl( new SwGrfFmtColls() ),
210 0 : pTOXTypes( new SwTOXTypes() ),
211 : pDefTOXBases( new SwDefTOXBase_Impl() ),
212 : pCurrentView( 0 ), //swmod 071225
213 : pDrawModel( 0 ),
214 276 : pUpdtFlds( new SwDocUpdtFld( this ) ),
215 0 : pFldTypes( new SwFldTypes() ),
216 : pVirDev( 0 ),
217 : pPrt( 0 ),
218 : pPrtData( 0 ),
219 : pGlossaryDoc( 0 ),
220 : pOutlineRule( 0 ),
221 276 : pFtnInfo( new SwFtnInfo ),
222 276 : pEndNoteInfo( new SwEndNoteInfo ),
223 276 : pLineNumberInfo( new SwLineNumberInfo ),
224 276 : pFtnIdxs( new SwFtnIdxs ),
225 276 : pDocStat( new SwDocStat ),
226 : pDocShell( 0 ),
227 276 : pLinkMgr( new sfx2::LinkManager( 0 ) ),
228 : pACEWord( 0 ),
229 : pURLStateChgd( 0 ),
230 : pNumberFormatter( 0 ),
231 276 : pNumRuleTbl( new SwNumRuleTbl ),
232 : maLists(),
233 : maListStyleLists(),
234 276 : pRedlineTbl( new SwRedlineTbl ),
235 : pAutoFmtRedlnComment( 0 ),
236 0 : pUnoCrsrTbl( new SwUnoCrsrTbl() ),
237 : pPgPViewPrtData( 0 ),
238 : pExtInputRing( 0 ),
239 : pLayouter( 0 ),
240 : pStyleAccess( 0 ),
241 : pLayoutCache( 0 ),
242 276 : pUnoCallBack(new SwModify(0)),
243 276 : mpGrammarContact(createGrammarContact()),
244 : aChartDataProviderImplRef(),
245 : pChartControllerHelper( 0 ),
246 0 : mpListItemsList( new tImplSortedNodeNumList() ), // #i83479#
247 : m_pXmlIdRegistry(),
248 : nAutoFmtRedlnCommentNo( 0 ),
249 : nLinkUpdMode( GLOBALSETTING ),
250 : eFldUpdMode( AUTOUPD_GLOBALSETTING ),
251 : eRedlineMode((RedlineMode_t)(nsRedlineMode_t::REDLINE_SHOW_INSERT | nsRedlineMode_t::REDLINE_SHOW_DELETE)),
252 : eChrCmprType( CHARCOMPRESS_NONE ),
253 : mReferenceCount(0),
254 : mIdleBlockCount(0),
255 : nLockExpFld( 0 ),
256 : mbGlossDoc(false),
257 : mbModified(false),
258 : mbDtor(false),
259 : mbPageNums(false),
260 : mbLoaded(false),
261 : mbUpdateExpFld(false),
262 : mbNewDoc(false),
263 : mbNewFldLst(true),
264 : mbCopyIsMove(false),
265 : mbVisibleLinks(true),
266 : mbInReading(false),
267 : mbInXMLImport(false),
268 : mbUpdateTOX(false),
269 : mbInLoadAsynchron(false),
270 : mbHTMLMode(false),
271 : mbInCallModified(false),
272 : mbIsGlobalDoc(false),
273 : mbGlblDocSaveLinks(false),
274 : mbIsLabelDoc(false),
275 : mbIsAutoFmtRedline(false),
276 : mbOLEPrtNotifyPending(false),
277 : mbAllOLENotify(false),
278 : mbIsRedlineMove(false),
279 : mbInsOnlyTxtGlssry(false),
280 : mbContains_MSVBasic(false),
281 : mbPurgeOLE(true),
282 : mbKernAsianPunctuation(false),
283 : mbReadlineChecked(false),
284 : mbLinksUpdated( false ), //#i38810#
285 : mbClipBoard( false ),
286 : mbColumnSelection( false ),
287 : #ifdef DBG_UTIL
288 : mbXMLExport(false),
289 : #endif
290 :
291 : // COMPATIBILITY FLAGS START
292 :
293 : mbAddFlyOffsets(false),
294 : mbUseHiResolutionVirtualDevice(true),
295 : mbMathBaselineAlignment(false), // default for *old* documents is 'off'
296 : mbStylesNoDefault(false),
297 : mbFloattableNomargins(false),
298 : mEmbedFonts(false),
299 : mEmbedSystemFonts(false),
300 : mbOldNumbering(false),
301 : mbIgnoreFirstLineIndentInNumbering(false),
302 : mbDoNotResetParaAttrsForNumFont(false),
303 : mbTableRowKeep(false),
304 : mbIgnoreTabsAndBlanksForLineCalculation(false),
305 : mbDoNotCaptureDrawObjsOnPage(false),
306 : mbOutlineLevelYieldsOutlineRule(false),
307 : mbClipAsCharacterAnchoredWriterFlyFrames(false),
308 : mbUnixForceZeroExtLeading(false),
309 : mbOldPrinterMetrics(false),
310 : mbTabRelativeToIndent(true),
311 : mbProtectForm(false), // i#78591#
312 : mbInvertBorderSpacing (false),
313 : mbCollapseEmptyCellPara(true),
314 : mbTabAtLeftIndentForParagraphsInList(false), //#i89181#
315 : mbSmallCapsPercentage66(false),
316 : mbTabOverflow(true),
317 : mbUnbreakableNumberings(false),
318 : mbClippedPictures(false),
319 : mbBackgroundParaOverDrawings(false),
320 : mbLastBrowseMode( false ),
321 : n32DummyCompatabilityOptions1(0),
322 : n32DummyCompatabilityOptions2(0),
323 :
324 : // COMPATIBILITY FLAGS END
325 :
326 : mbStartIdleTimer(false),
327 6348 : mbSetDrawDefaults(false)
328 : {
329 : RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDoc::SwDoc" );
330 :
331 : //
332 : // COMPATIBILITY FLAGS START
333 : //
334 :
335 : // Note: Any non-hidden compatibility flag should obtain its default
336 : // by asking SvtCompatibilityOptions, see below.
337 : //
338 276 : const SvtCompatibilityOptions aOptions;
339 276 : mbParaSpaceMax = aOptions.IsAddSpacing();
340 276 : mbParaSpaceMaxAtPages = aOptions.IsAddSpacingAtPages();
341 276 : mbTabCompat = !aOptions.IsUseOurTabStops();
342 276 : mbUseVirtualDevice = !aOptions.IsUsePrtDevice();
343 276 : mbAddExternalLeading = !aOptions.IsNoExtLeading();
344 276 : mbOldLineSpacing = aOptions.IsUseLineSpacing();
345 276 : mbAddParaSpacingToTableCells = aOptions.IsAddTableSpacing();
346 276 : mbUseFormerObjectPos = aOptions.IsUseObjectPositioning();
347 276 : mbUseFormerTextWrapping = aOptions.IsUseOurTextWrapping();
348 276 : mbConsiderWrapOnObjPos = aOptions.IsConsiderWrappingStyle();
349 :
350 276 : mbDoNotJustifyLinesWithManualBreak = !aOptions.IsExpandWordSpace();
351 :
352 : //
353 : // COMPATIBILITY FLAGS END
354 : //
355 :
356 : /*
357 : * DefaultFormats and DefaultFormatCollections (FmtColl)
358 : * are inserted at position 0 at the respective array.
359 : * The formats in the FmtColls are derived from the
360 : * DefaultFormats and are also in the list.
361 : */
362 : /* Formats */
363 276 : pFrmFmtTbl->push_back(pDfltFrmFmt);
364 276 : pCharFmtTbl->push_back(pDfltCharFmt);
365 :
366 : /* FmtColls */
367 : // TXT
368 276 : pTxtFmtCollTbl->push_back(pDfltTxtFmtColl);
369 : // GRF
370 276 : pGrfFmtCollTbl->push_back(pDfltGrfFmtColl);
371 :
372 : // Create PageDesc, EmptyPageFmt and ColumnFmt
373 276 : if ( aPageDescs.empty() )
374 276 : GetPageDescFromPool( RES_POOLPAGE_STANDARD );
375 :
376 : // Set to "Empty Page"
377 276 : pEmptyPageFmt->SetFmtAttr( SwFmtFrmSize( ATT_FIX_SIZE ) );
378 : // Set BodyFmt for columns
379 276 : pColumnContFmt->SetFmtAttr( SwFmtFillOrder( ATT_LEFT_TO_RIGHT ) );
380 :
381 276 : _InitFieldTypes();
382 :
383 : // Create a default OutlineNumRule (for Filters)
384 276 : pOutlineRule = new SwNumRule( rtl::OUString::createFromAscii( SwNumRule::GetOutlineRuleName() ),
385 : // #i89178#
386 : numfunc::GetDefaultPositionAndSpaceMode(),
387 276 : OUTLINE_RULE );
388 276 : AddNumRule(pOutlineRule);
389 : // Counting of phantoms depends on <IsOldNumbering()>
390 276 : pOutlineRule->SetCountPhantoms( !get(IDocumentSettingAccess::OLD_NUMBERING) );
391 :
392 : new SwTxtNode(
393 276 : SwNodeIndex(GetUndoManager().GetUndoNodes().GetEndOfContent()),
394 276 : pDfltTxtFmtColl );
395 276 : new SwTxtNode( SwNodeIndex( GetNodes().GetEndOfContent() ),
396 276 : GetTxtCollFromPool( RES_POOLCOLL_STANDARD ));
397 :
398 : // set the own IdleTimer
399 276 : aIdleTimer.SetTimeout( 600 );
400 276 : aIdleTimer.SetTimeoutHdl( LINK(this, SwDoc, DoIdleJobs) );
401 :
402 276 : aOLEModifiedTimer.SetTimeout( 1000 );
403 276 : aOLEModifiedTimer.SetTimeoutHdl( LINK( this, SwDoc, DoUpdateModifiedOLE ));
404 :
405 : // Create DBMgr
406 276 : pNewDBMgr = new SwNewDBMgr;
407 :
408 : // create TOXTypes
409 276 : InitTOXTypes();
410 :
411 : // pass empty item set containing the paragraph's list attributes
412 : // as ignorable items to the stype manager.
413 : {
414 276 : SfxItemSet aIgnorableParagraphItems( GetAttrPool(), RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END-1);
415 276 : pStyleAccess = createStyleManager( &aIgnorableParagraphItems );
416 : }
417 :
418 : // Initialize the session id of the current document to a random number
419 : // smaller than 2^21.
420 276 : static rtlRandomPool aPool = rtl_random_createPool();
421 276 : rtl_random_getBytes( aPool, &nRsid, sizeof ( nRsid ) );
422 276 : nRsid &= ( 1<<21 ) - 1;
423 276 : nRsid++;
424 276 : nRsidRoot = nRsid;
425 :
426 276 : ResetModified();
427 276 : }
428 :
429 110 : static void DeleteAndDestroy(SwFrmFmts& rFmts, int aStartIdx, int aEndIdx)
430 : {
431 110 : if (aEndIdx < aStartIdx)
432 110 : return;
433 504 : for( SwFrmFmts::const_iterator it = rFmts.begin() + aStartIdx;
434 336 : it != rFmts.begin() + aEndIdx; ++it )
435 58 : delete *it;
436 110 : rFmts.erase( rFmts.begin() + aStartIdx, rFmts.begin() + aEndIdx);
437 : }
438 :
439 211 : static void DeleteAndDestroy(SwTxtFmtColls& rFmts, int aStartIdx, int aEndIdx)
440 : {
441 211 : if (aEndIdx < aStartIdx)
442 211 : return;
443 2973 : for( SwTxtFmtColls::const_iterator it = rFmts.begin() + aStartIdx;
444 1982 : it != rFmts.begin() + aEndIdx; ++it )
445 780 : delete *it;
446 211 : rFmts.erase( rFmts.begin() + aStartIdx, rFmts.begin() + aEndIdx);
447 : }
448 :
449 8 : static void DeleteAndDestroy(SwCharFmts& rFmts, int aStartIdx, int aEndIdx)
450 : {
451 8 : if (aEndIdx < aStartIdx)
452 8 : return;
453 24 : for( SwCharFmts::const_iterator it = rFmts.begin() + aStartIdx;
454 16 : it != rFmts.begin() + aEndIdx; ++it )
455 0 : delete *it;
456 8 : rFmts.erase( rFmts.begin() + aStartIdx, rFmts.begin() + aEndIdx);
457 : }
458 :
459 110 : static void DeleteAndDestroy(SwGrfFmtColls& rFmts, int aStartIdx, int aEndIdx)
460 : {
461 110 : if (aEndIdx < aStartIdx)
462 110 : return;
463 330 : for( SwGrfFmtColls::const_iterator it = rFmts.begin() + aStartIdx;
464 220 : it != rFmts.begin() + aEndIdx; ++it )
465 0 : delete *it;
466 110 : rFmts.erase( rFmts.begin() + aStartIdx, rFmts.begin() + aEndIdx);
467 : }
468 :
469 : /*
470 : * Speciality: a member of the class SwDoc is located at
471 : * position 0 in the array of the Format and GDI objects.
472 : * This MUST not be destroyed using 'delete' in any case!
473 : */
474 306 : SwDoc::~SwDoc()
475 : {
476 : // nothing here should create Undo actions!
477 102 : GetIDocumentUndoRedo().DoUndo(false);
478 :
479 102 : if (pDocShell)
480 : {
481 8 : pDocShell->SetUndoManager(0);
482 : }
483 :
484 :
485 : // #i83479#
486 102 : delete mpListItemsList;
487 102 : mpListItemsList = 0;
488 :
489 : // clean up chart related structures...
490 : // Note: the chart data provider gets already diposed in ~SwDocShell
491 : // since all UNO API related functionality requires an existing SwDocShell
492 : // this assures that dipose gets called if there is need for it.
493 102 : aChartDataProviderImplRef.reset();
494 102 : delete pChartControllerHelper;
495 :
496 102 : delete mpGrammarContact;
497 102 : mpGrammarContact = 0;
498 :
499 : //!! needs to be done to destroy a possible SwFmtDrop format that may
500 : //!! be connected to a char format which may not otherwise be removed
501 : //!! and thus would leave a unremoved SwFmt object. (TL)
502 : //!! (this is case is not possible via UI but via API...)
503 102 : SwFmtDrop aDrop;
504 102 : SetDefault(aDrop);
505 : //!! same for SwFmtCharFmt
506 102 : SwFmtCharFmt aCharFmt(NULL);
507 102 : SetDefault(aCharFmt);
508 :
509 102 : StopIdling(); // stop idle timer
510 :
511 102 : delete pUnoCallBack, pUnoCallBack = 0;
512 102 : delete pURLStateChgd;
513 :
514 102 : delete pLayouter;
515 102 : pLayouter = 0L;
516 :
517 : // Deactivate Undo notification from Draw
518 102 : if( pDrawModel )
519 : {
520 88 : DrawNotifyUndoHdl();
521 88 : ClrContourCache();
522 : }
523 :
524 102 : delete pPgPViewPrtData;
525 :
526 102 : mbDtor = true;
527 102 : pLayoutPtr.reset();
528 :
529 102 : delete pRedlineTbl;
530 102 : delete pUnoCrsrTbl;
531 102 : delete pAutoFmtRedlnComment;
532 102 : delete pUpdtFlds;
533 102 : delete pACEWord;
534 :
535 : // Release the BaseLinks
536 : {
537 102 : ::sfx2::SvLinkSources aTemp(pLinkMgr->GetServers());
538 306 : for( ::sfx2::SvLinkSources::const_iterator it = aTemp.begin();
539 204 : it != aTemp.end(); ++it )
540 0 : (*it)->Closed();
541 :
542 102 : if( !pLinkMgr->GetLinks().empty() )
543 0 : pLinkMgr->Remove( 0, pLinkMgr->GetLinks().size() );
544 : }
545 :
546 : // The ChapterNumbers/Numbers need to be deleted before the styles
547 : // or we update all the time!
548 102 : m_pNodes->pOutlineNds->clear();
549 102 : SwNodes & rUndoNodes( GetUndoManager().GetUndoNodes() );
550 102 : rUndoNodes.pOutlineNds->clear();
551 :
552 102 : pFtnIdxs->clear();
553 :
554 : // indices could be registered in attributes
555 102 : m_pUndoManager->DelAllUndoObj();
556 :
557 : // The BookMarks contain indices to the Content. These must be deleted
558 : // before deleting the Nodes.
559 102 : pMarkManager->clearAllMarks();
560 :
561 102 : if( pExtInputRing )
562 : {
563 0 : Ring* pTmp = pExtInputRing;
564 0 : pExtInputRing = 0;
565 0 : while( pTmp->GetNext() != pTmp )
566 0 : delete pTmp->GetNext();
567 0 : delete pTmp;
568 : }
569 :
570 : // Old - deletion without a Flag is expensive, because we send a Modify
571 : // aTOXTypes.DeleteAndDestroy( 0, aTOXTypes.Count() );
572 : {
573 974 : for( sal_uInt16 n = pTOXTypes->size(); n; )
574 : {
575 770 : (*pTOXTypes)[ --n ]->SetInDocDTOR();
576 770 : delete (*pTOXTypes)[ n ];
577 : }
578 102 : pTOXTypes->clear();
579 : }
580 102 : delete pDefTOXBases;
581 :
582 : // Any of the FrmFormats can still have indices registered.
583 : // These need to be destroyed now at the latest.
584 350 : BOOST_FOREACH( SwFrmFmt* pFmt, *pFrmFmtTbl )
585 248 : lcl_DelFmtIndizes( pFmt );
586 242 : BOOST_FOREACH( SwFrmFmt* pFmt, *pSpzFrmFmtTbl )
587 140 : lcl_DelFmtIndizes( pFmt );
588 102 : BOOST_FOREACH( SwSectionFmt* pFmt, *pSectionFmtTbl )
589 0 : lcl_DelFmtIndizes( pFmt );
590 :
591 : // The formats/styles that follow depend on the default formats.
592 : // Destroy these only after destroying the FmtIndices, because the content
593 : // of headers/footers has to be deleted as well. If in the headers/footers
594 : // there are still Flys registered at that point, we have a problem.
595 238 : BOOST_FOREACH(SwPageDesc *pPageDesc, aPageDescs)
596 136 : delete pPageDesc;
597 102 : aPageDescs.clear();
598 :
599 : // Delete content selections.
600 : // Don't wait for the SwNodes dtor to destroy them; so that Formats
601 : // do not have any dependencies anymore.
602 102 : m_pNodes->DelNodes( SwNodeIndex(*m_pNodes), m_pNodes->Count() );
603 102 : rUndoNodes.DelNodes( SwNodeIndex( rUndoNodes ), rUndoNodes.Count() );
604 :
605 : // Delete Formats, make it permanent some time in the future
606 :
607 : // Delete for Collections
608 : // So that we get rid of the dependencies
609 102 : pFtnInfo->ReleaseCollection();
610 102 : pEndNoteInfo->ReleaseCollection();
611 :
612 : OSL_ENSURE( pDfltTxtFmtColl == (*pTxtFmtCollTbl)[0],
613 : "Default-Text-Collection must always be at the start" );
614 :
615 : // Optimization: Based on the fact that Standard is always 2nd in the
616 : // array, we should delete it as the last. With this we avoid
617 : // reparenting the Formats all the time!
618 102 : if( 2 < pTxtFmtCollTbl->size() )
619 100 : DeleteAndDestroy(*pTxtFmtCollTbl, 2, pTxtFmtCollTbl->size());
620 102 : DeleteAndDestroy(*pTxtFmtCollTbl, 1, pTxtFmtCollTbl->size());
621 102 : delete pTxtFmtCollTbl;
622 :
623 : OSL_ENSURE( pDfltGrfFmtColl == (*pGrfFmtCollTbl)[0],
624 : "DefaultGrfCollection must always be at the start" );
625 :
626 102 : DeleteAndDestroy(*pGrfFmtCollTbl, 1, pGrfFmtCollTbl->size());
627 102 : delete pGrfFmtCollTbl;
628 :
629 : /*
630 : * DefaultFormats and DefaultFormatCollections (FmtColl)
631 : * are at position 0 of their respective arrays.
632 : * In order to not be deleted by the array's dtor, we remove them
633 : * now.
634 : */
635 102 : pFrmFmtTbl->erase( pFrmFmtTbl->begin() );
636 102 : pCharFmtTbl->erase( pCharFmtTbl->begin() );
637 :
638 102 : DELETEZ( pPrt );
639 102 : DELETEZ( pNewDBMgr );
640 :
641 : // All Flys need to be destroyed before the Drawing Model,
642 : // because Flys can still contain DrawContacts, when no
643 : // Layout could be constructed due to a read error.
644 102 : DeleteAndDestroy( *pSpzFrmFmtTbl, 0, pSpzFrmFmtTbl->size() );
645 :
646 : // Only now destroy the Model, the drawing objects - which are also
647 : // contained in the Undo - need to remove their attributes from the
648 : // Model. Also, DrawContacts could exist before this.
649 102 : ReleaseDrawModel();
650 : // Destroy DrawModel before the LinkManager, because it's always set
651 : // in the DrawModel.
652 102 : DELETEZ( pLinkMgr );
653 :
654 : // Clear the Tables before deleting the defaults, or we crash due to
655 : // dependencies on defaults.
656 102 : delete pFrmFmtTbl;
657 102 : delete pSpzFrmFmtTbl;
658 :
659 102 : delete pStyleAccess;
660 :
661 102 : delete pCharFmtTbl;
662 102 : delete pSectionFmtTbl;
663 102 : delete pTblFrmFmtTbl;
664 102 : delete pDfltTxtFmtColl;
665 102 : delete pDfltGrfFmtColl;
666 102 : delete pNumRuleTbl;
667 :
668 : {
669 1311 : for ( boost::unordered_map< String, SwList*, StringHash >::iterator
670 102 : aListIter = maLists.begin();
671 874 : aListIter != maLists.end();
672 : ++aListIter )
673 : {
674 335 : delete (*aListIter).second;
675 : }
676 102 : maLists.clear();
677 : }
678 102 : maListStyleLists.clear();
679 :
680 102 : delete pPrtData;
681 102 : delete pNumberFormatter;
682 102 : delete pFtnInfo;
683 102 : delete pEndNoteInfo;
684 102 : delete pLineNumberInfo;
685 102 : delete pFtnIdxs;
686 102 : delete pFldTypes;
687 102 : delete pTOXTypes;
688 102 : delete pDocStat;
689 102 : delete pEmptyPageFmt;
690 102 : delete pColumnContFmt;
691 102 : delete pDfltCharFmt;
692 102 : delete pDfltFrmFmt;
693 102 : delete pLayoutCache;
694 102 : delete pVirDev;
695 :
696 102 : SfxItemPool::Free(mpAttrPool);
697 204 : }
698 :
699 275 : VirtualDevice& SwDoc::CreateVirtualDevice_() const
700 : {
701 275 : VirtualDevice* pNewVir = new VirtualDevice( 1 );
702 :
703 275 : pNewVir->SetReferenceDevice( VirtualDevice::REFDEV_MODE_MSO1 );
704 :
705 : // #i60945# External leading compatibility for unix systems.
706 275 : if ( get(IDocumentSettingAccess::UNIX_FORCE_ZERO_EXT_LEADING ) )
707 0 : pNewVir->Compat_ZeroExtleadBug();
708 :
709 275 : MapMode aMapMode( pNewVir->GetMapMode() );
710 275 : aMapMode.SetMapUnit( MAP_TWIP );
711 275 : pNewVir->SetMapMode( aMapMode );
712 :
713 275 : const_cast<SwDoc*>(this)->setVirtualDevice( pNewVir, true, true );
714 275 : return *pVirDev;
715 : }
716 :
717 4 : SfxPrinter& SwDoc::CreatePrinter_() const
718 : {
719 : OSL_ENSURE( ! pPrt, "Do not call CreatePrinter_(), call getPrinter() instead" );
720 :
721 : #if OSL_DEBUG_LEVEL > 1
722 : OSL_TRACE( "Printer will be created!" );
723 : #endif
724 :
725 : // We create a default SfxPrinter.
726 : // The ItemSet is deleted by Sfx!
727 4 : SfxItemSet *pSet = new SfxItemSet( ((SwDoc*)this)->GetAttrPool(),
728 : FN_PARAM_ADDPRINTER, FN_PARAM_ADDPRINTER,
729 : SID_HTML_MODE, SID_HTML_MODE,
730 : SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
731 : SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
732 4 : 0 );
733 :
734 4 : SfxPrinter* pNewPrt = new SfxPrinter( pSet );
735 4 : const_cast<SwDoc*>(this)->setPrinter( pNewPrt, true, true );
736 4 : return *pPrt;
737 : }
738 :
739 473 : void SwDoc::SetDocShell( SwDocShell* pDSh )
740 : {
741 473 : if( pDocShell != pDSh )
742 : {
743 473 : if (pDocShell)
744 : {
745 146 : pDocShell->SetUndoManager(0);
746 : }
747 473 : pDocShell = pDSh;
748 473 : if (pDocShell)
749 : {
750 327 : pDocShell->SetUndoManager(& GetUndoManager());
751 : }
752 :
753 473 : pLinkMgr->SetPersist( pDocShell );
754 473 : if( pDrawModel )
755 : {
756 192 : ((SwDrawDocument*)pDrawModel)->SetObjectShell( pDocShell );
757 192 : pDrawModel->SetPersist( pDocShell );
758 : OSL_ENSURE( pDrawModel->GetPersist() == GetPersist(),
759 : "draw model's persist is out of sync" );
760 : }
761 : }
762 473 : }
763 :
764 : // Convenience method; to avoid excessive includes from docsh.hxx
765 0 : uno::Reference < embed::XStorage > SwDoc::GetDocStorage()
766 : {
767 0 : if( pDocShell )
768 0 : return pDocShell->GetStorage();
769 0 : if( pLinkMgr->GetPersist() )
770 0 : return pLinkMgr->GetPersist()->GetStorage();
771 0 : return NULL;
772 : }
773 :
774 343 : SfxObjectShell* SwDoc::GetPersist() const
775 : {
776 343 : return pDocShell ? pDocShell : pLinkMgr->GetPersist();
777 : }
778 :
779 8 : void SwDoc::ClearDoc()
780 : {
781 8 : GetIDocumentUndoRedo().DelAllUndoObj();
782 8 : ::sw::UndoGuard const undoGuard(GetIDocumentUndoRedo());
783 :
784 : // Deactivate Undo notification from Draw
785 8 : if( pDrawModel )
786 : {
787 0 : DrawNotifyUndoHdl();
788 0 : ClrContourCache();
789 : }
790 :
791 : // if there are still FlyFrames dangling around, delete them too
792 : sal_uInt16 n;
793 16 : while ( 0 != (n = GetSpzFrmFmts()->size()) )
794 0 : DelLayoutFmt((*pSpzFrmFmtTbl)[n-1]);
795 : OSL_ENSURE( !pDrawModel || !pDrawModel->GetPage(0)->GetObjCount(),
796 : "not all DrawObjects removed from the page" );
797 :
798 8 : pRedlineTbl->DeleteAndDestroyAll();
799 :
800 8 : delete pACEWord;
801 :
802 : // The BookMarks contain indices to the Content. These must be deleted
803 : // before deleting the Nodes.
804 8 : pMarkManager->clearAllMarks();
805 8 : InitTOXTypes();
806 :
807 : // create a dummy pagedesc for the layout
808 8 : sal_uInt16 nDummyPgDsc = MakePageDesc(rtl::OUString("?DUMMY?"));
809 8 : SwPageDesc* pDummyPgDsc = aPageDescs[ nDummyPgDsc ];
810 :
811 8 : SwNodeIndex aSttIdx( *GetNodes().GetEndOfContent().StartOfSectionNode(), 1 );
812 : // create the first one over and over again (without attributes/style etc.
813 8 : SwTxtNode* pFirstNd = GetNodes().MakeTxtNode( aSttIdx, pDfltTxtFmtColl );
814 :
815 8 : if( pCurrentView ) //swmod 071029//swmod 071225
816 : {
817 : // set the layout to the dummy pagedesc
818 0 : pFirstNd->SetAttr( SwFmtPageDesc( pDummyPgDsc ));
819 :
820 0 : SwPosition aPos( *pFirstNd, SwIndex( pFirstNd ));
821 0 : SwPaM const tmpPaM(aSttIdx, SwNodeIndex(GetNodes().GetEndOfContent()));
822 0 : ::PaMCorrAbs(tmpPaM, aPos);
823 : }
824 :
825 8 : GetNodes().Delete( aSttIdx,
826 16 : GetNodes().GetEndOfContent().GetIndex() - aSttIdx.GetIndex() );
827 :
828 : // #i62440#
829 : // destruction of numbering rules and creation of new outline rule
830 : // *after* the document nodes are deleted.
831 8 : pOutlineRule = NULL;
832 16 : BOOST_FOREACH( SwNumRule* pNumRule, *pNumRuleTbl )
833 8 : delete pNumRule;
834 8 : pNumRuleTbl->clear();
835 : // #i114725#,#i115828#
836 : {
837 48 : for ( boost::unordered_map< String, SwList*, StringHash >::iterator
838 8 : aListIter = maLists.begin();
839 32 : aListIter != maLists.end();
840 : ++aListIter )
841 : {
842 8 : delete (*aListIter).second;
843 : }
844 8 : maLists.clear();
845 : }
846 8 : maListStyleLists.clear();
847 :
848 : // creation of new outline numbering rule
849 8 : pOutlineRule = new SwNumRule( rtl::OUString::createFromAscii( SwNumRule::GetOutlineRuleName() ),
850 : // #i89178#
851 : numfunc::GetDefaultPositionAndSpaceMode(),
852 8 : OUTLINE_RULE );
853 8 : AddNumRule(pOutlineRule);
854 : // Counting of phantoms depends on <IsOldNumbering()>
855 8 : pOutlineRule->SetCountPhantoms( !get(IDocumentSettingAccess::OLD_NUMBERING) );
856 :
857 : // remove the dummy pagedec from the array and delete all the old ones
858 8 : aPageDescs.erase( aPageDescs.begin() + nDummyPgDsc );
859 16 : BOOST_FOREACH(SwPageDesc *pPageDesc, aPageDescs)
860 8 : delete pPageDesc;
861 8 : aPageDescs.clear();
862 :
863 : // Delete for Collections
864 : // So that we get rid of the dependencies
865 8 : pFtnInfo->ReleaseCollection();
866 8 : pEndNoteInfo->ReleaseCollection();
867 :
868 : // Optimization: Based on the fact that Standard is always 2nd in the
869 : // array, we should delete it as the last. With this we avoid
870 : // reparenting the Formats all the time!
871 8 : if( 2 < pTxtFmtCollTbl->size() )
872 1 : DeleteAndDestroy(*pTxtFmtCollTbl, 2, pTxtFmtCollTbl->size());
873 8 : DeleteAndDestroy(*pTxtFmtCollTbl, 1, pTxtFmtCollTbl->size());
874 8 : DeleteAndDestroy(*pGrfFmtCollTbl, 1, pGrfFmtCollTbl->size());
875 8 : DeleteAndDestroy(*pCharFmtTbl, 1, pCharFmtTbl->size());
876 :
877 8 : if( pCurrentView )
878 : {
879 : // search the FrameFormat of the root frm. This is not allowed to delete
880 0 : pFrmFmtTbl->erase( std::find( pFrmFmtTbl->begin(), pFrmFmtTbl->end(), pCurrentView->GetLayout()->GetFmt() ) );
881 0 : DeleteAndDestroy(*pFrmFmtTbl, 1, pFrmFmtTbl->size());
882 0 : pFrmFmtTbl->push_back( pCurrentView->GetLayout()->GetFmt() );
883 : }
884 : else //swmod 071029//swmod 071225
885 8 : DeleteAndDestroy(*pFrmFmtTbl, 1, pFrmFmtTbl->size());
886 :
887 8 : xForbiddenCharsTable.clear();
888 :
889 24 : for(SwFldTypes::const_iterator it = pFldTypes->begin() + INIT_FLDTYPES;
890 16 : it != pFldTypes->end(); ++it)
891 0 : delete *it;
892 8 : pFldTypes->erase( pFldTypes->begin() + INIT_FLDTYPES, pFldTypes->end() );
893 :
894 8 : delete pNumberFormatter, pNumberFormatter = 0;
895 :
896 8 : GetPageDescFromPool( RES_POOLPAGE_STANDARD );
897 8 : pFirstNd->ChgFmtColl( GetTxtCollFromPool( RES_POOLCOLL_STANDARD ));
898 8 : nDummyPgDsc = aPageDescs.size();
899 8 : aPageDescs.push_back( pDummyPgDsc );
900 : // set the layout back to the new standard pagedesc
901 8 : pFirstNd->ResetAllAttr();
902 : // delete now the dummy pagedesc
903 8 : DelPageDesc( nDummyPgDsc );
904 8 : }
905 :
906 0 : void SwDoc::SetPreViewPrtData( const SwPagePreViewPrtData* pNew )
907 : {
908 0 : if( pNew )
909 : {
910 0 : if( pPgPViewPrtData )
911 0 : *pPgPViewPrtData = *pNew;
912 : else
913 0 : pPgPViewPrtData = new SwPagePreViewPrtData( *pNew );
914 : }
915 0 : else if( pPgPViewPrtData )
916 0 : DELETEZ( pPgPViewPrtData );
917 0 : SetModified();
918 0 : }
919 :
920 82 : SwModify* SwDoc::GetUnoCallBack() const
921 : {
922 82 : return pUnoCallBack;
923 : }
924 :
925 :
926 : /** SwDoc:
927 : * Reading and writing of the layout cache.
928 : *--------------------------------------------------*/
929 5 : void SwDoc::ReadLayoutCache( SvStream& rStream )
930 : {
931 5 : if( !pLayoutCache )
932 5 : pLayoutCache = new SwLayoutCache();
933 5 : if( !pLayoutCache->IsLocked() )
934 : {
935 5 : pLayoutCache->GetLockCount() |= 0x8000;
936 5 : pLayoutCache->Read( rStream );
937 5 : pLayoutCache->GetLockCount() &= 0x7fff;
938 : }
939 5 : }
940 :
941 1 : void SwDoc::WriteLayoutCache( SvStream& rStream )
942 : {
943 1 : pLayoutCache->Write( rStream, *this );
944 1 : }
945 :
946 273 : IGrammarContact* getGrammarContact( const SwTxtNode& rTxtNode )
947 : {
948 273 : const SwDoc* pDoc = rTxtNode.GetDoc();
949 273 : if( !pDoc || pDoc->IsInDtor() )
950 0 : return 0;
951 273 : return pDoc->getGrammarContact();
952 : }
953 :
954 : // #i42634# Moved common code of SwReader::Read() and SwDocShell::UpdateLinks()
955 : // to new SwDoc::UpdateLinks():
956 267 : void SwDoc::UpdateLinks( bool bUI )
957 : {
958 : SfxObjectCreateMode eMode;
959 267 : sal_uInt16 nLinkMode = getLinkUpdateMode( true );
960 267 : if ( GetDocShell()) {
961 267 : sal_uInt16 nUpdateDocMode = GetDocShell()->GetUpdateDocMode();
962 534 : if( (nLinkMode != NEVER || document::UpdateDocMode::FULL_UPDATE == nUpdateDocMode) &&
963 267 : !GetLinkManager().GetLinks().empty() &&
964 : SFX_CREATE_MODE_INTERNAL !=
965 0 : ( eMode = GetDocShell()->GetCreateMode()) &&
966 : SFX_CREATE_MODE_ORGANIZER != eMode &&
967 : SFX_CREATE_MODE_PREVIEW != eMode &&
968 0 : !GetDocShell()->IsPreview() )
969 : {
970 0 : ViewShell* pVSh = 0;
971 0 : bool bAskUpdate = nLinkMode == MANUAL;
972 0 : bool bUpdate = true;
973 0 : switch(nUpdateDocMode)
974 : {
975 0 : case document::UpdateDocMode::NO_UPDATE: bUpdate = false;break;
976 0 : case document::UpdateDocMode::QUIET_UPDATE:bAskUpdate = false; break;
977 0 : case document::UpdateDocMode::FULL_UPDATE: bAskUpdate = true; break;
978 : }
979 0 : if( bUpdate && (bUI || !bAskUpdate) )
980 : {
981 0 : SfxMedium* pMedium = GetDocShell()->GetMedium();
982 0 : SfxFrame* pFrm = pMedium ? pMedium->GetLoadTargetFrame() : 0;
983 0 : Window* pDlgParent = pFrm ? &pFrm->GetWindow() : 0;
984 0 : if( GetCurrentViewShell() && !GetEditShell( &pVSh ) && !pVSh ) //swmod 071108//swmod 071225
985 : {
986 0 : ViewShell aVSh( *this, 0, 0 );
987 :
988 0 : SET_CURR_SHELL( &aVSh );
989 0 : GetLinkManager().UpdateAllLinks( bAskUpdate , true, false, pDlgParent );
990 : }
991 : else
992 0 : GetLinkManager().UpdateAllLinks( bAskUpdate, true, false, pDlgParent );
993 : }
994 : }
995 : }
996 :
997 267 : }
998 :
999 : ::sfx2::IXmlIdRegistry&
1000 0 : SwDoc::GetXmlIdRegistry()
1001 : {
1002 : // UGLY: this relies on SetClipBoard being called before GetXmlIdRegistry!
1003 0 : if (!m_pXmlIdRegistry.get())
1004 : {
1005 0 : m_pXmlIdRegistry.reset( ::sfx2::createXmlIdRegistry( IsClipBoard() ) );
1006 : }
1007 0 : return *m_pXmlIdRegistry;
1008 : }
1009 :
1010 : ::sw::MetaFieldManager &
1011 235 : SwDoc::GetMetaFieldManager()
1012 : {
1013 235 : return *m_pMetaFieldManager;
1014 : }
1015 :
1016 : ::sw::UndoManager &
1017 705 : SwDoc::GetUndoManager()
1018 : {
1019 705 : return *m_pUndoManager;
1020 : }
1021 :
1022 : ::sw::UndoManager const&
1023 0 : SwDoc::GetUndoManager() const
1024 : {
1025 0 : return *m_pUndoManager;
1026 : }
1027 :
1028 : IDocumentUndoRedo &
1029 120808 : SwDoc::GetIDocumentUndoRedo()
1030 : {
1031 120808 : return *m_pUndoManager;
1032 : }
1033 :
1034 : IDocumentUndoRedo const&
1035 309 : SwDoc::GetIDocumentUndoRedo() const
1036 : {
1037 309 : return *m_pUndoManager;
1038 : }
1039 :
1040 284 : void SwDoc::InitTOXTypes()
1041 : {
1042 284 : ShellResource* pShellRes = ViewShell::GetShellRes();
1043 284 : SwTOXType * pNew = new SwTOXType(TOX_CONTENT, pShellRes->aTOXContentName );
1044 284 : pTOXTypes->push_back( pNew );
1045 284 : pNew = new SwTOXType(TOX_INDEX, pShellRes->aTOXIndexName );
1046 284 : pTOXTypes->push_back( pNew );
1047 284 : pNew = new SwTOXType(TOX_USER, pShellRes->aTOXUserName );
1048 284 : pTOXTypes->push_back( pNew );
1049 284 : pNew = new SwTOXType(TOX_ILLUSTRATIONS, pShellRes->aTOXIllustrationsName );
1050 284 : pTOXTypes->push_back( pNew );
1051 284 : pNew = new SwTOXType(TOX_OBJECTS, pShellRes->aTOXObjectsName );
1052 284 : pTOXTypes->push_back( pNew );
1053 284 : pNew = new SwTOXType(TOX_TABLES, pShellRes->aTOXTablesName );
1054 284 : pTOXTypes->push_back( pNew );
1055 284 : pNew = new SwTOXType(TOX_AUTHORITIES, pShellRes->aTOXAuthoritiesName );
1056 284 : pTOXTypes->push_back( pNew );
1057 284 : }
1058 :
1059 0 : void SwDoc::ReplaceDefaults(const SwDoc& rSource)
1060 : {
1061 : // copy property defaults
1062 : const sal_uInt16 aRangeOfDefaults[] =
1063 : {
1064 : RES_FRMATR_BEGIN, RES_FRMATR_END-1,
1065 : RES_CHRATR_BEGIN, RES_CHRATR_END-1,
1066 : RES_PARATR_BEGIN, RES_PARATR_END-1,
1067 : RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END-1,
1068 : RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1,
1069 : 0
1070 0 : };
1071 :
1072 0 : SfxItemSet aNewDefaults(GetAttrPool(), aRangeOfDefaults);
1073 :
1074 0 : sal_uInt16 nRange = 0;
1075 0 : while (aRangeOfDefaults[nRange] != 0)
1076 : {
1077 0 : for (sal_uInt16 nWhich = aRangeOfDefaults[nRange];
1078 0 : nWhich < aRangeOfDefaults[nRange + 1]; ++nWhich)
1079 : {
1080 : const SfxPoolItem& rSourceAttr =
1081 0 : rSource.mpAttrPool->GetDefaultItem(nWhich);
1082 0 : if (rSourceAttr != mpAttrPool->GetDefaultItem(nWhich))
1083 0 : aNewDefaults.Put(rSourceAttr);
1084 : }
1085 0 : nRange += 2;
1086 : }
1087 :
1088 0 : if (aNewDefaults.Count())
1089 0 : SetDefault(aNewDefaults);
1090 0 : }
1091 :
1092 0 : void SwDoc::ReplaceCompatabilityOptions(const SwDoc& rSource)
1093 : {
1094 0 : n32DummyCompatabilityOptions1 = rSource.n32DummyCompatabilityOptions1;
1095 0 : n32DummyCompatabilityOptions2 = rSource.n32DummyCompatabilityOptions2;
1096 0 : mbParaSpaceMax = rSource.mbParaSpaceMax;
1097 0 : mbParaSpaceMaxAtPages = rSource.mbParaSpaceMaxAtPages;
1098 0 : mbTabCompat = rSource.mbTabCompat;
1099 0 : mbUseVirtualDevice = rSource.mbUseVirtualDevice;
1100 0 : mbAddExternalLeading = rSource.mbAddExternalLeading;
1101 0 : mbOldLineSpacing = rSource.mbOldLineSpacing;
1102 0 : mbAddParaSpacingToTableCells = rSource.mbAddParaSpacingToTableCells;
1103 0 : mbUseFormerObjectPos = rSource.mbUseFormerObjectPos;
1104 0 : mbUseFormerTextWrapping = rSource.mbUseFormerTextWrapping;
1105 0 : mbConsiderWrapOnObjPos = rSource.mbConsiderWrapOnObjPos;
1106 0 : mbAddFlyOffsets = rSource.mbAddFlyOffsets;
1107 0 : mbOldNumbering = rSource.mbOldNumbering;
1108 0 : mbUseHiResolutionVirtualDevice = rSource.mbUseHiResolutionVirtualDevice;
1109 0 : mbIgnoreFirstLineIndentInNumbering = rSource.mbIgnoreFirstLineIndentInNumbering;
1110 0 : mbDoNotJustifyLinesWithManualBreak = rSource.mbDoNotJustifyLinesWithManualBreak;
1111 0 : mbDoNotResetParaAttrsForNumFont = rSource.mbDoNotResetParaAttrsForNumFont;
1112 0 : mbOutlineLevelYieldsOutlineRule = rSource.mbOutlineLevelYieldsOutlineRule;
1113 0 : mbTableRowKeep = rSource.mbTableRowKeep;
1114 0 : mbIgnoreTabsAndBlanksForLineCalculation = rSource.mbIgnoreTabsAndBlanksForLineCalculation;
1115 0 : mbDoNotCaptureDrawObjsOnPage = rSource.mbDoNotCaptureDrawObjsOnPage;
1116 0 : mbClipAsCharacterAnchoredWriterFlyFrames = rSource.mbClipAsCharacterAnchoredWriterFlyFrames;
1117 0 : mbUnixForceZeroExtLeading = rSource.mbUnixForceZeroExtLeading;
1118 0 : mbOldPrinterMetrics = rSource.mbOldPrinterMetrics;
1119 0 : mbTabRelativeToIndent = rSource.mbTabRelativeToIndent;
1120 0 : mbTabAtLeftIndentForParagraphsInList = rSource.mbTabAtLeftIndentForParagraphsInList;
1121 0 : }
1122 :
1123 0 : SfxObjectShell* SwDoc::CreateCopy(bool bCallInitNew ) const
1124 : {
1125 0 : SwDoc* pRet = new SwDoc;
1126 :
1127 : // we have to use pointer here, since the callee has to decide whether
1128 : // SfxObjectShellLock or SfxObjectShellRef should be used sometimes the
1129 : // object will be returned with refcount set to 0 ( if no DoInitNew is done )
1130 0 : SfxObjectShell* pRetShell = new SwDocShell( pRet, SFX_CREATE_MODE_STANDARD );
1131 0 : if( bCallInitNew )
1132 : {
1133 : // it could happen that DoInitNew creates model, that increases the refcount of the object
1134 0 : pRetShell->DoInitNew();
1135 : }
1136 :
1137 0 : pRet->acquire();
1138 :
1139 0 : pRet->ReplaceDefaults(*this);
1140 :
1141 0 : pRet->ReplaceCompatabilityOptions(*this);
1142 :
1143 0 : pRet->ReplaceStyles(*this);
1144 :
1145 : // copy content
1146 0 : pRet->Paste( *this );
1147 :
1148 : // remove the temporary shell if it is there as it was done before
1149 0 : pRet->SetTmpDocShell( (SfxObjectShell*)NULL );
1150 :
1151 0 : pRet->release();
1152 :
1153 0 : return pRetShell;
1154 : }
1155 :
1156 : /*-------------------------------------------------------------------------
1157 : copy document content - code from SwFEShell::Paste( SwDoc* )
1158 : -----------------------------------------------------------------------*/
1159 0 : void SwDoc::Paste( const SwDoc& rSource )
1160 : {
1161 : // this has to be empty const sal_uInt16 nStartPageNumber = GetPhyPageNum();
1162 : // until the end of the NodesArray
1163 0 : SwNodeIndex aSourceIdx( rSource.GetNodes().GetEndOfExtras(), 2 );
1164 0 : SwPaM aCpyPam( aSourceIdx ); //DocStart
1165 0 : SwNodeIndex aTargetIdx( GetNodes().GetEndOfExtras(), 2 );
1166 0 : SwPaM aInsertPam( aTargetIdx ); //replaces PCURCRSR from SwFEShell::Paste()
1167 :
1168 :
1169 0 : aCpyPam.SetMark();
1170 0 : aCpyPam.Move( fnMoveForward, fnGoDoc );
1171 :
1172 0 : this->GetIDocumentUndoRedo().StartUndo( UNDO_INSGLOSSARY, NULL );
1173 0 : this->LockExpFlds();
1174 :
1175 : {
1176 0 : SwPosition& rInsPos = *aInsertPam.GetPoint();
1177 : //find out if the clipboard document starts with a table
1178 0 : bool bStartWithTable = 0 != aCpyPam.Start()->nNode.GetNode().FindTableNode();
1179 0 : SwPosition aInsertPosition( rInsPos );
1180 :
1181 : {
1182 0 : SwNodeIndex aIndexBefore(rInsPos.nNode);
1183 :
1184 0 : aIndexBefore--;
1185 :
1186 0 : rSource.CopyRange( aCpyPam, rInsPos, true );
1187 :
1188 : {
1189 0 : ++aIndexBefore;
1190 : SwPaM aPaM(SwPosition(aIndexBefore),
1191 0 : SwPosition(rInsPos.nNode));
1192 :
1193 0 : MakeUniqueNumRules(aPaM);
1194 0 : }
1195 : }
1196 :
1197 : //TODO: Is this necessary here? SaveTblBoxCntnt( &rInsPos );
1198 0 : if(/*bIncludingPageFrames && */bStartWithTable)
1199 : {
1200 : //remove the paragraph in front of the table
1201 0 : SwPaM aPara(aInsertPosition);
1202 0 : this->DelFullPara(aPara);
1203 : }
1204 : //additionally copy page bound frames
1205 0 : if( /*bIncludingPageFrames && */rSource.GetSpzFrmFmts()->size() )
1206 : {
1207 0 : for ( sal_uInt16 i = 0; i < rSource.GetSpzFrmFmts()->size(); ++i )
1208 : {
1209 0 : const SwFrmFmt& rCpyFmt = *(*rSource.GetSpzFrmFmts())[i];
1210 0 : SwFmtAnchor aAnchor( rCpyFmt.GetAnchor() );
1211 0 : if (FLY_AT_PAGE == aAnchor.GetAnchorId())
1212 : {
1213 0 : aAnchor.SetPageNum( aAnchor.GetPageNum() /*+ nStartPageNumber - */);
1214 : }
1215 : else
1216 0 : continue;
1217 0 : this->CopyLayoutFmt( rCpyFmt, aAnchor, true, true );
1218 0 : }
1219 0 : }
1220 : }
1221 :
1222 0 : this->GetIDocumentUndoRedo().EndUndo( UNDO_INSGLOSSARY, NULL );
1223 :
1224 0 : UnlockExpFlds();
1225 0 : UpdateFlds(NULL, false);
1226 0 : }
1227 :
1228 0 : sal_uInt16 SwTxtFmtColls::GetPos(const SwTxtFmtColl* p) const
1229 : {
1230 0 : const_iterator it = std::find(begin(), end(), p);
1231 0 : return it == end() ? USHRT_MAX : it - begin();
1232 : }
1233 :
1234 0 : sal_uInt16 SwGrfFmtColls::GetPos(const SwGrfFmtColl* p) const
1235 : {
1236 0 : const_iterator it = std::find(begin(), end(), p);
1237 0 : return it == end() ? USHRT_MAX : it - begin();
1238 : }
1239 :
1240 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|