update credits
[LibreOffice.git] / sw / source / core / doc / docnew.cxx
blob91aa23b2ad9ef0aefc207c2b5bf95751ed0592a6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <doc.hxx>
21 #include <dcontact.hxx>
22 #include <com/sun/star/document/PrinterIndependentLayout.hpp>
23 #include <com/sun/star/document/UpdateDocMode.hpp>
24 #include <com/sun/star/text/XTextDocument.hpp>
25 #include <com/sun/star/linguistic2/ProofreadingIterator.hpp>
26 #include <com/sun/star/text/XFlatParagraphIteratorProvider.hpp>
28 #include <comphelper/processfactory.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/virdev.hxx>
31 #include <rtl/logfile.hxx>
32 #include <rtl/random.h>
33 #include <sfx2/printer.hxx>
34 #include <sfx2/docfile.hxx>
35 #include <sfx2/frame.hxx>
36 #include <sfx2/viewfrm.hxx>
38 #include <svl/macitem.hxx>
39 #include <svx/svxids.hrc>
40 #include <svx/svdogrp.hxx>
41 #include <sfx2/linkmgr.hxx>
42 #include <editeng/forbiddencharacterstable.hxx>
43 #include <svl/zforlist.hxx>
44 #include <unotools/compatibility.hxx>
45 #include <unotools/lingucfg.hxx>
46 #include <svx/svdpage.hxx>
47 #include <paratr.hxx>
48 #include <fchrfmt.hxx>
49 #include <fmtcntnt.hxx>
50 #include <fmtanchr.hxx>
51 #include <fmtfsize.hxx>
52 #include <fmtfordr.hxx>
53 #include <fmtpdsc.hxx>
54 #include <pvprtdat.hxx>
55 #include <rootfrm.hxx> // So that the RootDtor is being called
56 #include <layouter.hxx>
57 #include <pagedesc.hxx> // So that the PageDescs can be destroyed
58 #include <ndtxt.hxx>
59 #include <printdata.hxx>
60 #include <docfld.hxx>
61 #include <ftninfo.hxx>
62 #include <ftnidx.hxx>
63 #include <docstat.hxx>
64 #include <charfmt.hxx>
65 #include <frmfmt.hxx>
66 #include <rolbck.hxx> // Undo attributes, SwHistory
67 #include <poolfmt.hxx> // for the Pool template
68 #include <dbmgr.hxx>
69 #include <docsh.hxx>
70 #include <acorrect.hxx> // for the automatic adding of exceptions
71 #include <visiturl.hxx> // for the URLChange message
72 #include <docary.hxx>
73 #include <lineinfo.hxx>
74 #include <drawdoc.hxx>
75 #include <linkenum.hxx>
76 #include <fldupde.hxx>
77 #include <extinput.hxx>
78 #include <viewsh.hxx>
79 #include <doctxm.hxx>
80 #include <shellres.hxx>
81 #include <breakit.hxx>
82 #include <laycache.hxx>
83 #include <mvsave.hxx>
84 #include <istyleaccess.hxx>
85 #include <swstylemanager.hxx>
86 #include <IGrammarContact.hxx>
87 #include <tblsel.hxx>
88 #include <MarkManager.hxx>
89 #include <UndoManager.hxx>
90 #include <unochart.hxx>
91 #include <fldbas.hxx>
93 #include <cmdid.h> // for the default printer in SetJob
95 #include <pausethreadstarting.hxx>
96 #include <numrule.hxx>
97 #include <list.hxx>
98 #include <listfunc.hxx>
100 #include <sfx2/Metadatable.hxx>
101 #include <fmtmeta.hxx> // MetaFieldManager
102 #include <boost/foreach.hpp>
104 using namespace ::com::sun::star;
105 using namespace ::com::sun::star::document;
107 const sal_Char sFrmFmtStr[] = "Frameformat";
108 const sal_Char sEmptyPageStr[] = "Empty Page";
109 const sal_Char sColumnCntStr[] = "Columncontainer";
110 const sal_Char sCharFmtStr[] = "Zeichenformat";
111 const sal_Char sTxtCollStr[] = "Textformatvorlage";
112 const sal_Char sGrfCollStr[] = "Graphikformatvorlage";
115 * global functions...
117 uno::Reference< linguistic2::XProofreadingIterator > SwDoc::GetGCIterator() const
119 if (!m_xGCIterator.is() && SvtLinguConfig().HasGrammarChecker())
121 uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
124 m_xGCIterator = linguistic2::ProofreadingIterator::create( xContext );
126 catch (const uno::Exception &)
128 OSL_FAIL( "No GCIterator" );
132 return m_xGCIterator;
135 void StartGrammarChecking( SwDoc &rDoc )
137 // check for a visible view
138 bool bVisible = false;
139 const SwDocShell *mpDocShell = rDoc.GetDocShell();
140 SfxViewFrame *pFrame = SfxViewFrame::GetFirst( mpDocShell, sal_False );
141 while (pFrame && !bVisible)
143 if (pFrame->IsVisible())
144 bVisible = true;
145 pFrame = SfxViewFrame::GetNext( *pFrame, mpDocShell, sal_False );
148 //!! only documents with visible views need to be checked
149 //!! (E.g. don't check temporary documents created for printing, see printing of notes and selections.
150 //!! Those get created on the fly and get hard deleted a bit later as well, and no one should have
151 //!! a uno reference to them)
152 if (bVisible)
154 uno::Reference< linguistic2::XProofreadingIterator > xGCIterator( rDoc.GetGCIterator() );
155 if ( xGCIterator.is() )
157 uno::Reference< lang::XComponent > xDoc( rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY );
158 uno::Reference< text::XFlatParagraphIteratorProvider > xFPIP( xDoc, uno::UNO_QUERY );
160 // start automatic background checking if not active already
161 if ( xFPIP.is() && !xGCIterator->isProofreading( xDoc ) )
162 xGCIterator->startProofreading( xDoc, xFPIP );
168 * internal functions
170 static void lcl_DelFmtIndizes( SwFmt* pFmt )
172 SwFmtCntnt &rFmtCntnt = (SwFmtCntnt&)pFmt->GetCntnt();
173 if ( rFmtCntnt.GetCntntIdx() )
174 rFmtCntnt.SetNewCntntIdx( 0 );
175 SwFmtAnchor &rFmtAnchor = (SwFmtAnchor&)pFmt->GetAnchor();
176 if ( rFmtAnchor.GetCntntAnchor() )
177 rFmtAnchor.SetAnchor( 0 );
181 * exported methods
183 SwDoc::SwDoc()
184 : m_pNodes( new SwNodes(this) )
186 mpAttrPool(new SwAttrPool(this)),
187 mpMarkManager(new ::sw::mark::MarkManager(*this)),
188 m_pMetaFieldManager(new ::sw::MetaFieldManager()),
189 m_pUndoManager(new ::sw::UndoManager(
190 ::std::auto_ptr<SwNodes>(new SwNodes(this)), *this, *this, *this)),
191 mpDfltFrmFmt( new SwFrmFmt( GetAttrPool(), sFrmFmtStr, 0 ) ),
192 mpEmptyPageFmt( new SwFrmFmt( GetAttrPool(), sEmptyPageStr, mpDfltFrmFmt ) ),
193 mpColumnContFmt( new SwFrmFmt( GetAttrPool(), sColumnCntStr, mpDfltFrmFmt ) ),
194 mpDfltCharFmt( new SwCharFmt( GetAttrPool(), sCharFmtStr, 0 ) ),
195 mpDfltTxtFmtColl( new SwTxtFmtColl( GetAttrPool(), sTxtCollStr ) ),
196 mpDfltGrfFmtColl( new SwGrfFmtColl( GetAttrPool(), sGrfCollStr ) ),
197 mpFrmFmtTbl( new SwFrmFmts() ),
198 mpCharFmtTbl( new SwCharFmts() ),
199 mpSpzFrmFmtTbl( new SwFrmFmts() ),
200 mpSectionFmtTbl( new SwSectionFmts() ),
201 mpTblFrmFmtTbl( new SwFrmFmts() ),
202 mpTxtFmtCollTbl( new SwTxtFmtColls() ),
203 mpGrfFmtCollTbl( new SwGrfFmtColls() ),
204 mpTOXTypes( new SwTOXTypes() ),
205 mpDefTOXBases( new SwDefTOXBase_Impl() ),
206 mpCurrentView( 0 ), //swmod 071225
207 mpDrawModel( 0 ),
208 mpUpdtFlds( new SwDocUpdtFld( this ) ),
209 mpFldTypes( new SwFldTypes() ),
210 mpVirDev( 0 ),
211 mpPrt( 0 ),
212 mpPrtData( 0 ),
213 mpGlossaryDoc( 0 ),
214 mpOutlineRule( 0 ),
215 mpFtnInfo( new SwFtnInfo ),
216 mpEndNoteInfo( new SwEndNoteInfo ),
217 mpLineNumberInfo( new SwLineNumberInfo ),
218 mpFtnIdxs( new SwFtnIdxs ),
219 mpDocStat( new SwDocStat ),
220 mpDocShell( 0 ),
221 mpLinkMgr( new sfx2::LinkManager( 0 ) ),
222 mpACEWord( 0 ),
223 mpURLStateChgd( 0 ),
224 mpNumberFormatter( 0 ),
225 mpNumRuleTbl( new SwNumRuleTbl ),
226 maLists(),
227 maListStyleLists(),
228 mpRedlineTbl( new SwRedlineTbl ),
229 mpAutoFmtRedlnComment( 0 ),
230 mpUnoCrsrTbl( new SwUnoCrsrTbl() ),
231 mpPgPViewPrtData( 0 ),
232 mpExtInputRing( 0 ),
233 mpLayouter( 0 ),
234 mpStyleAccess( 0 ),
235 mpLayoutCache( 0 ),
236 mpUnoCallBack(new SwModify(0)),
237 mpGrammarContact(createGrammarContact()),
238 maChartDataProviderImplRef(),
239 mpChartControllerHelper( 0 ),
240 mpListItemsList( new tImplSortedNodeNumList() ), // #i83479#
241 m_pXmlIdRegistry(),
242 mnAutoFmtRedlnCommentNo( 0 ),
243 mnLinkUpdMode( GLOBALSETTING ),
244 meFldUpdMode( AUTOUPD_GLOBALSETTING ),
245 meRedlineMode((RedlineMode_t)(nsRedlineMode_t::REDLINE_SHOW_INSERT | nsRedlineMode_t::REDLINE_SHOW_DELETE)),
246 meChrCmprType( CHARCOMPRESS_NONE ),
247 mReferenceCount(0),
248 mIdleBlockCount(0),
249 mnLockExpFld( 0 ),
250 mbGlossDoc(false),
251 mbModified(false),
252 mbDtor(false),
253 mbPageNums(false),
254 mbLoaded(false),
255 mbUpdateExpFld(false),
256 mbNewDoc(false),
257 mbNewFldLst(true),
258 mbCopyIsMove(false),
259 mbVisibleLinks(true),
260 mbInReading(false),
261 mbInXMLImport(false),
262 mbUpdateTOX(false),
263 mbInLoadAsynchron(false),
264 mbHTMLMode(false),
265 mbInCallModified(false),
266 mbIsGlobalDoc(false),
267 mbGlblDocSaveLinks(false),
268 mbIsLabelDoc(false),
269 mbIsAutoFmtRedline(false),
270 mbOLEPrtNotifyPending(false),
271 mbAllOLENotify(false),
272 mbIsRedlineMove(false),
273 mbInsOnlyTxtGlssry(false),
274 mbContains_MSVBasic(false),
275 mbPurgeOLE(true),
276 mbKernAsianPunctuation(false),
277 mbReadlineChecked(false),
278 mbLinksUpdated( false ), //#i38810#
279 mbClipBoard( false ),
280 mbColumnSelection( false ),
281 #ifdef DBG_UTIL
282 mbXMLExport(false),
283 #endif
284 mbContainsAtPageObjWithContentAnchor(false), //#i119292#, fdo#37024
286 // COMPATIBILITY FLAGS START
288 mbAddFlyOffsets(false),
289 mbUseHiResolutionVirtualDevice(true),
290 mbMathBaselineAlignment(false), // default for *old* documents is 'off'
291 mbStylesNoDefault(false),
292 mbFloattableNomargins(false),
293 mEmbedFonts(false),
294 mEmbedSystemFonts(false),
295 mbOldNumbering(false),
296 mbIgnoreFirstLineIndentInNumbering(false),
297 mbDoNotResetParaAttrsForNumFont(false),
298 mbTableRowKeep(false),
299 mbIgnoreTabsAndBlanksForLineCalculation(false),
300 mbDoNotCaptureDrawObjsOnPage(false),
301 mbOutlineLevelYieldsOutlineRule(false),
302 mbClipAsCharacterAnchoredWriterFlyFrames(false),
303 mbUnixForceZeroExtLeading(false),
304 mbOldPrinterMetrics(false),
305 mbTabRelativeToIndent(true),
306 mbProtectForm(false), // i#78591#
307 mbInvertBorderSpacing (false),
308 mbCollapseEmptyCellPara(true),
309 mbTabAtLeftIndentForParagraphsInList(false), //#i89181#
310 mbSmallCapsPercentage66(false),
311 mbTabOverflow(true),
312 mbUnbreakableNumberings(false),
313 mbClippedPictures(false),
314 mbBackgroundParaOverDrawings(false),
315 mbTabOverMargin(false),
316 mbLastBrowseMode( false ),
317 mn32DummyCompatabilityOptions1(0),
318 mn32DummyCompatabilityOptions2(0),
320 // COMPATIBILITY FLAGS END
322 mbStartIdleTimer(false),
323 mbSetDrawDefaults(false)
325 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDoc::SwDoc" );
327 // COMPATIBILITY FLAGS START
329 // Note: Any non-hidden compatibility flag should obtain its default
330 // by asking SvtCompatibilityOptions, see below.
332 const SvtCompatibilityOptions aOptions;
333 mbParaSpaceMax = aOptions.IsAddSpacing();
334 mbParaSpaceMaxAtPages = aOptions.IsAddSpacingAtPages();
335 mbTabCompat = !aOptions.IsUseOurTabStops();
336 mbUseVirtualDevice = !aOptions.IsUsePrtDevice();
337 mbAddExternalLeading = !aOptions.IsNoExtLeading();
338 mbOldLineSpacing = aOptions.IsUseLineSpacing();
339 mbAddParaSpacingToTableCells = aOptions.IsAddTableSpacing();
340 mbUseFormerObjectPos = aOptions.IsUseObjectPositioning();
341 mbUseFormerTextWrapping = aOptions.IsUseOurTextWrapping();
342 mbConsiderWrapOnObjPos = aOptions.IsConsiderWrappingStyle();
344 mbDoNotJustifyLinesWithManualBreak = !aOptions.IsExpandWordSpace();
346 // COMPATIBILITY FLAGS END
349 * DefaultFormats and DefaultFormatCollections (FmtColl)
350 * are inserted at position 0 at the respective array.
351 * The formats in the FmtColls are derived from the
352 * DefaultFormats and are also in the list.
354 /* Formats */
355 mpFrmFmtTbl->push_back(mpDfltFrmFmt);
356 mpCharFmtTbl->push_back(mpDfltCharFmt);
358 /* FmtColls */
359 // TXT
360 mpTxtFmtCollTbl->push_back(mpDfltTxtFmtColl);
361 // GRF
362 mpGrfFmtCollTbl->push_back(mpDfltGrfFmtColl);
364 // Create PageDesc, EmptyPageFmt and ColumnFmt
365 if ( maPageDescs.empty() )
366 GetPageDescFromPool( RES_POOLPAGE_STANDARD );
368 // Set to "Empty Page"
369 mpEmptyPageFmt->SetFmtAttr( SwFmtFrmSize( ATT_FIX_SIZE ) );
370 // Set BodyFmt for columns
371 mpColumnContFmt->SetFmtAttr( SwFmtFillOrder( ATT_LEFT_TO_RIGHT ) );
373 _InitFieldTypes();
375 // Create a default OutlineNumRule (for Filters)
376 mpOutlineRule = new SwNumRule( OUString::createFromAscii( SwNumRule::GetOutlineRuleName() ),
377 // #i89178#
378 numfunc::GetDefaultPositionAndSpaceMode(),
379 OUTLINE_RULE );
380 AddNumRule(mpOutlineRule);
381 // Counting of phantoms depends on <IsOldNumbering()>
382 mpOutlineRule->SetCountPhantoms( !get(IDocumentSettingAccess::OLD_NUMBERING) );
384 new SwTxtNode(
385 SwNodeIndex(GetUndoManager().GetUndoNodes().GetEndOfContent()),
386 mpDfltTxtFmtColl );
387 new SwTxtNode( SwNodeIndex( GetNodes().GetEndOfContent() ),
388 GetTxtCollFromPool( RES_POOLCOLL_STANDARD ));
390 // set the own IdleTimer
391 maIdleTimer.SetTimeout( 600 );
392 maIdleTimer.SetTimeoutHdl( LINK(this, SwDoc, DoIdleJobs) );
394 maOLEModifiedTimer.SetTimeout( 1000 );
395 maOLEModifiedTimer.SetTimeoutHdl( LINK( this, SwDoc, DoUpdateModifiedOLE ));
397 maStatsUpdateTimer.SetTimeout( 100 );
398 maStatsUpdateTimer.SetTimeoutHdl( LINK( this, SwDoc, DoIdleStatsUpdate ) );
400 // Create DBMgr
401 mpNewDBMgr = new SwNewDBMgr;
403 // create TOXTypes
404 InitTOXTypes();
406 // pass empty item set containing the paragraph's list attributes
407 // as ignorable items to the stype manager.
409 SfxItemSet aIgnorableParagraphItems( GetAttrPool(), RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END-1);
410 mpStyleAccess = createStyleManager( &aIgnorableParagraphItems );
413 // Initialize the session id of the current document to a random number
414 // smaller than 2^21.
415 static rtlRandomPool aPool = rtl_random_createPool();
416 rtl_random_getBytes( aPool, &mnRsid, sizeof ( mnRsid ) );
417 mnRsid &= ( 1<<21 ) - 1;
418 mnRsid++;
419 mnRsidRoot = mnRsid;
421 ResetModified();
424 static void DeleteAndDestroy(SwFrmFmts& rFmts, int aStartIdx, int aEndIdx)
426 if (aEndIdx < aStartIdx)
427 return;
428 for( SwFrmFmts::const_iterator it = rFmts.begin() + aStartIdx;
429 it != rFmts.begin() + aEndIdx; ++it )
430 delete *it;
431 rFmts.erase( rFmts.begin() + aStartIdx, rFmts.begin() + aEndIdx);
434 static void DeleteAndDestroy(SwTxtFmtColls& rFmts, int aStartIdx, int aEndIdx)
436 if (aEndIdx < aStartIdx)
437 return;
438 for( SwTxtFmtColls::const_iterator it = rFmts.begin() + aStartIdx;
439 it != rFmts.begin() + aEndIdx; ++it )
440 delete *it;
441 rFmts.erase( rFmts.begin() + aStartIdx, rFmts.begin() + aEndIdx);
444 static void DeleteAndDestroy(SwCharFmts& rFmts, int aStartIdx, int aEndIdx)
446 if (aEndIdx < aStartIdx)
447 return;
448 for( SwCharFmts::const_iterator it = rFmts.begin() + aStartIdx;
449 it != rFmts.begin() + aEndIdx; ++it )
450 delete *it;
451 rFmts.erase( rFmts.begin() + aStartIdx, rFmts.begin() + aEndIdx);
454 static void DeleteAndDestroy(SwGrfFmtColls& rFmts, int aStartIdx, int aEndIdx)
456 if (aEndIdx < aStartIdx)
457 return;
458 for( SwGrfFmtColls::const_iterator it = rFmts.begin() + aStartIdx;
459 it != rFmts.begin() + aEndIdx; ++it )
460 delete *it;
461 rFmts.erase( rFmts.begin() + aStartIdx, rFmts.begin() + aEndIdx);
465 * Speciality: a member of the class SwDoc is located at
466 * position 0 in the array of the Format and GDI objects.
467 * This MUST not be destroyed using 'delete' in any case!
469 SwDoc::~SwDoc()
471 // nothing here should create Undo actions!
472 GetIDocumentUndoRedo().DoUndo(false);
474 if (mpDocShell)
476 mpDocShell->SetUndoManager(0);
480 // #i83479#
481 delete mpListItemsList;
482 mpListItemsList = 0;
484 // clean up chart related structures...
485 // Note: the chart data provider gets already diposed in ~SwDocShell
486 // since all UNO API related functionality requires an existing SwDocShell
487 // this assures that dipose gets called if there is need for it.
488 maChartDataProviderImplRef.reset();
489 delete mpChartControllerHelper;
491 delete mpGrammarContact;
492 mpGrammarContact = 0;
494 //!! needs to be done to destroy a possible SwFmtDrop format that may
495 //!! be connected to a char format which may not otherwise be removed
496 //!! and thus would leave a unremoved SwFmt object. (TL)
497 //!! (this is case is not possible via UI but via API...)
498 SwFmtDrop aDrop;
499 SetDefault(aDrop);
500 //!! same for SwFmtCharFmt
501 SwFmtCharFmt aCharFmt(NULL);
502 SetDefault(aCharFmt);
504 StopIdling(); // stop idle timer
505 maStatsUpdateTimer.Stop();
507 delete mpUnoCallBack, mpUnoCallBack = 0;
508 delete mpURLStateChgd;
510 delete mpLayouter;
511 mpLayouter = 0L;
513 // Deactivate Undo notification from Draw
514 if( mpDrawModel )
516 DrawNotifyUndoHdl();
517 ClrContourCache();
520 delete mpPgPViewPrtData;
522 mbDtor = true;
524 delete mpRedlineTbl;
525 delete mpUnoCrsrTbl;
526 delete mpAutoFmtRedlnComment;
527 delete mpUpdtFlds;
528 delete mpACEWord;
530 // Release the BaseLinks
532 ::sfx2::SvLinkSources aTemp(mpLinkMgr->GetServers());
533 for( ::sfx2::SvLinkSources::const_iterator it = aTemp.begin();
534 it != aTemp.end(); ++it )
535 (*it)->Closed();
537 if( !mpLinkMgr->GetLinks().empty() )
538 mpLinkMgr->Remove( 0, mpLinkMgr->GetLinks().size() );
541 // The ChapterNumbers/Numbers need to be deleted before the styles
542 // or we update all the time!
543 m_pNodes->pOutlineNds->clear();
544 SwNodes & rUndoNodes( GetUndoManager().GetUndoNodes() );
545 rUndoNodes.pOutlineNds->clear();
547 mpFtnIdxs->clear();
549 // indices could be registered in attributes
550 m_pUndoManager->DelAllUndoObj();
552 // The BookMarks contain indices to the Content. These must be deleted
553 // before deleting the Nodes.
554 mpMarkManager->clearAllMarks();
556 if( mpExtInputRing )
558 Ring* pTmp = mpExtInputRing;
559 mpExtInputRing = 0;
560 while( pTmp->GetNext() != pTmp )
561 delete pTmp->GetNext();
562 delete pTmp;
565 // Old - deletion without a Flag is expensive, because we send a Modify
566 // aTOXTypes.DeleteAndDestroy( 0, aTOXTypes.Count() );
568 for( sal_uInt16 n = mpTOXTypes->size(); n; )
570 (*mpTOXTypes)[ --n ]->SetInDocDTOR();
571 delete (*mpTOXTypes)[ n ];
573 mpTOXTypes->clear();
575 delete mpDefTOXBases;
577 // Any of the FrmFormats can still have indices registered.
578 // These need to be destroyed now at the latest.
579 BOOST_FOREACH( SwFrmFmt* pFmt, *mpFrmFmtTbl )
580 lcl_DelFmtIndizes( pFmt );
581 BOOST_FOREACH( SwFrmFmt* pFmt, *mpSpzFrmFmtTbl )
582 lcl_DelFmtIndizes( pFmt );
583 BOOST_FOREACH( SwSectionFmt* pFmt, *mpSectionFmtTbl )
584 lcl_DelFmtIndizes( pFmt );
586 // The formats/styles that follow depend on the default formats.
587 // Destroy these only after destroying the FmtIndices, because the content
588 // of headers/footers has to be deleted as well. If in the headers/footers
589 // there are still Flys registered at that point, we have a problem.
590 BOOST_FOREACH(SwPageDesc *pPageDesc, maPageDescs)
591 delete pPageDesc;
592 maPageDescs.clear();
594 // Delete content selections.
595 // Don't wait for the SwNodes dtor to destroy them; so that Formats
596 // do not have any dependencies anymore.
597 m_pNodes->DelNodes( SwNodeIndex(*m_pNodes), m_pNodes->Count() );
598 rUndoNodes.DelNodes( SwNodeIndex( rUndoNodes ), rUndoNodes.Count() );
600 // Delete Formats, make it permanent some time in the future
602 // Delete for Collections
603 // So that we get rid of the dependencies
604 mpFtnInfo->ReleaseCollection();
605 mpEndNoteInfo->ReleaseCollection();
607 OSL_ENSURE( mpDfltTxtFmtColl == (*mpTxtFmtCollTbl)[0],
608 "Default-Text-Collection must always be at the start" );
610 // Optimization: Based on the fact that Standard is always 2nd in the
611 // array, we should delete it as the last. With this we avoid
612 // reparenting the Formats all the time!
613 if( 2 < mpTxtFmtCollTbl->size() )
614 DeleteAndDestroy(*mpTxtFmtCollTbl, 2, mpTxtFmtCollTbl->size());
615 DeleteAndDestroy(*mpTxtFmtCollTbl, 1, mpTxtFmtCollTbl->size());
616 delete mpTxtFmtCollTbl;
618 OSL_ENSURE( mpDfltGrfFmtColl == (*mpGrfFmtCollTbl)[0],
619 "DefaultGrfCollection must always be at the start" );
621 DeleteAndDestroy(*mpGrfFmtCollTbl, 1, mpGrfFmtCollTbl->size());
622 delete mpGrfFmtCollTbl;
625 * DefaultFormats and DefaultFormatCollections (FmtColl)
626 * are at position 0 of their respective arrays.
627 * In order to not be deleted by the array's dtor, we remove them
628 * now.
630 mpFrmFmtTbl->erase( mpFrmFmtTbl->begin() );
631 mpCharFmtTbl->erase( mpCharFmtTbl->begin() );
633 DELETEZ( mpPrt );
634 DELETEZ( mpNewDBMgr );
636 // All Flys need to be destroyed before the Drawing Model,
637 // because Flys can still contain DrawContacts, when no
638 // Layout could be constructed due to a read error.
639 DeleteAndDestroy( *mpSpzFrmFmtTbl, 0, mpSpzFrmFmtTbl->size() );
641 // Only now destroy the Model, the drawing objects - which are also
642 // contained in the Undo - need to remove their attributes from the
643 // Model. Also, DrawContacts could exist before this.
644 ReleaseDrawModel();
645 // Destroy DrawModel before the LinkManager, because it's always set
646 // in the DrawModel.
647 DELETEZ( mpLinkMgr );
649 // Clear the Tables before deleting the defaults, or we crash due to
650 // dependencies on defaults.
651 delete mpFrmFmtTbl;
652 delete mpSpzFrmFmtTbl;
654 delete mpStyleAccess;
656 delete mpCharFmtTbl;
657 delete mpSectionFmtTbl;
658 delete mpTblFrmFmtTbl;
659 delete mpDfltTxtFmtColl;
660 delete mpDfltGrfFmtColl;
661 delete mpNumRuleTbl;
664 for ( boost::unordered_map< String, SwList*, StringHash >::iterator
665 aListIter = maLists.begin();
666 aListIter != maLists.end();
667 ++aListIter )
669 delete (*aListIter).second;
671 maLists.clear();
673 maListStyleLists.clear();
675 delete mpPrtData;
676 delete mpNumberFormatter;
677 delete mpFtnInfo;
678 delete mpEndNoteInfo;
679 delete mpLineNumberInfo;
680 delete mpFtnIdxs;
681 delete mpFldTypes;
682 delete mpTOXTypes;
683 delete mpDocStat;
684 delete mpEmptyPageFmt;
685 delete mpColumnContFmt;
686 delete mpDfltCharFmt;
687 delete mpDfltFrmFmt;
688 delete mpLayoutCache;
689 delete mpVirDev;
691 SfxItemPool::Free(mpAttrPool);
694 VirtualDevice& SwDoc::CreateVirtualDevice_() const
696 #ifdef IOS
697 VirtualDevice* pNewVir = new VirtualDevice( 8 );
698 #else
699 VirtualDevice* pNewVir = new VirtualDevice( 1 );
700 #endif
702 pNewVir->SetReferenceDevice( VirtualDevice::REFDEV_MODE_MSO1 );
704 // #i60945# External leading compatibility for unix systems.
705 if ( get(IDocumentSettingAccess::UNIX_FORCE_ZERO_EXT_LEADING ) )
706 pNewVir->Compat_ZeroExtleadBug();
708 MapMode aMapMode( pNewVir->GetMapMode() );
709 aMapMode.SetMapUnit( MAP_TWIP );
710 pNewVir->SetMapMode( aMapMode );
712 const_cast<SwDoc*>(this)->setVirtualDevice( pNewVir, true, true );
713 return *mpVirDev;
716 SfxPrinter& SwDoc::CreatePrinter_() const
718 OSL_ENSURE( ! mpPrt, "Do not call CreatePrinter_(), call getPrinter() instead" );
720 #if OSL_DEBUG_LEVEL > 1
721 OSL_TRACE( "Printer will be created!" );
722 #endif
724 // We create a default SfxPrinter.
725 // The ItemSet is deleted by Sfx!
726 SfxItemSet *pSet = new SfxItemSet( ((SwDoc*)this)->GetAttrPool(),
727 FN_PARAM_ADDPRINTER, FN_PARAM_ADDPRINTER,
728 SID_HTML_MODE, SID_HTML_MODE,
729 SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
730 SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
731 0 );
733 SfxPrinter* pNewPrt = new SfxPrinter( pSet );
734 const_cast<SwDoc*>(this)->setPrinter( pNewPrt, true, true );
735 return *mpPrt;
738 void SwDoc::SetDocShell( SwDocShell* pDSh )
740 if( mpDocShell != pDSh )
742 if (mpDocShell)
744 mpDocShell->SetUndoManager(0);
746 mpDocShell = pDSh;
747 if (mpDocShell)
749 mpDocShell->SetUndoManager(& GetUndoManager());
752 mpLinkMgr->SetPersist( mpDocShell );
753 if( mpDrawModel )
755 ((SwDrawDocument*)mpDrawModel)->SetObjectShell( mpDocShell );
756 mpDrawModel->SetPersist( mpDocShell );
757 OSL_ENSURE( mpDrawModel->GetPersist() == GetPersist(),
758 "draw model's persist is out of sync" );
763 // Convenience method; to avoid excessive includes from docsh.hxx
764 uno::Reference < embed::XStorage > SwDoc::GetDocStorage()
766 if( mpDocShell )
767 return mpDocShell->GetStorage();
768 if( mpLinkMgr->GetPersist() )
769 return mpLinkMgr->GetPersist()->GetStorage();
770 return NULL;
773 SfxObjectShell* SwDoc::GetPersist() const
775 return mpDocShell ? mpDocShell : mpLinkMgr->GetPersist();
778 void SwDoc::ClearDoc()
780 GetIDocumentUndoRedo().DelAllUndoObj();
781 ::sw::UndoGuard const undoGuard(GetIDocumentUndoRedo());
783 // Deactivate Undo notification from Draw
784 if( mpDrawModel )
786 DrawNotifyUndoHdl();
787 ClrContourCache();
790 // if there are still FlyFrames dangling around, delete them too
791 sal_uInt16 n;
792 while ( 0 != (n = GetSpzFrmFmts()->size()) )
793 DelLayoutFmt((*mpSpzFrmFmtTbl)[n-1]);
794 OSL_ENSURE( !mpDrawModel || !mpDrawModel->GetPage(0)->GetObjCount(),
795 "not all DrawObjects removed from the page" );
797 mpRedlineTbl->DeleteAndDestroyAll();
799 delete mpACEWord;
801 // The BookMarks contain indices to the Content. These must be deleted
802 // before deleting the Nodes.
803 mpMarkManager->clearAllMarks();
804 InitTOXTypes();
806 // create a dummy pagedesc for the layout
807 sal_uInt16 nDummyPgDsc = MakePageDesc(OUString("?DUMMY?"));
808 SwPageDesc* pDummyPgDsc = maPageDescs[ nDummyPgDsc ];
810 SwNodeIndex aSttIdx( *GetNodes().GetEndOfContent().StartOfSectionNode(), 1 );
811 // create the first one over and over again (without attributes/style etc.
812 SwTxtNode* pFirstNd = GetNodes().MakeTxtNode( aSttIdx, mpDfltTxtFmtColl );
814 if( mpCurrentView ) //swmod 071029//swmod 071225
816 // set the layout to the dummy pagedesc
817 pFirstNd->SetAttr( SwFmtPageDesc( pDummyPgDsc ));
819 SwPosition aPos( *pFirstNd, SwIndex( pFirstNd ));
820 SwPaM const tmpPaM(aSttIdx, SwNodeIndex(GetNodes().GetEndOfContent()));
821 ::PaMCorrAbs(tmpPaM, aPos);
824 GetNodes().Delete( aSttIdx,
825 GetNodes().GetEndOfContent().GetIndex() - aSttIdx.GetIndex() );
827 // #i62440#
828 // destruction of numbering rules and creation of new outline rule
829 // *after* the document nodes are deleted.
830 mpOutlineRule = NULL;
831 BOOST_FOREACH( SwNumRule* pNumRule, *mpNumRuleTbl )
832 delete pNumRule;
833 mpNumRuleTbl->clear();
834 // #i114725#,#i115828#
836 for ( boost::unordered_map< String, SwList*, StringHash >::iterator
837 aListIter = maLists.begin();
838 aListIter != maLists.end();
839 ++aListIter )
841 delete (*aListIter).second;
843 maLists.clear();
845 maListStyleLists.clear();
847 // creation of new outline numbering rule
848 mpOutlineRule = new SwNumRule( OUString::createFromAscii( SwNumRule::GetOutlineRuleName() ),
849 // #i89178#
850 numfunc::GetDefaultPositionAndSpaceMode(),
851 OUTLINE_RULE );
852 AddNumRule(mpOutlineRule);
853 // Counting of phantoms depends on <IsOldNumbering()>
854 mpOutlineRule->SetCountPhantoms( !get(IDocumentSettingAccess::OLD_NUMBERING) );
856 // remove the dummy pagedec from the array and delete all the old ones
857 maPageDescs.erase( maPageDescs.begin() + nDummyPgDsc );
858 BOOST_FOREACH(SwPageDesc *pPageDesc, maPageDescs)
859 delete pPageDesc;
860 maPageDescs.clear();
862 // Delete for Collections
863 // So that we get rid of the dependencies
864 mpFtnInfo->ReleaseCollection();
865 mpEndNoteInfo->ReleaseCollection();
867 // Optimization: Based on the fact that Standard is always 2nd in the
868 // array, we should delete it as the last. With this we avoid
869 // reparenting the Formats all the time!
870 if( 2 < mpTxtFmtCollTbl->size() )
871 DeleteAndDestroy(*mpTxtFmtCollTbl, 2, mpTxtFmtCollTbl->size());
872 DeleteAndDestroy(*mpTxtFmtCollTbl, 1, mpTxtFmtCollTbl->size());
873 DeleteAndDestroy(*mpGrfFmtCollTbl, 1, mpGrfFmtCollTbl->size());
874 DeleteAndDestroy(*mpCharFmtTbl, 1, mpCharFmtTbl->size());
876 if( mpCurrentView )
878 // search the FrameFormat of the root frm. This is not allowed to delete
879 mpFrmFmtTbl->erase( std::find( mpFrmFmtTbl->begin(), mpFrmFmtTbl->end(), mpCurrentView->GetLayout()->GetFmt() ) );
880 DeleteAndDestroy(*mpFrmFmtTbl, 1, mpFrmFmtTbl->size());
881 mpFrmFmtTbl->push_back( mpCurrentView->GetLayout()->GetFmt() );
883 else //swmod 071029//swmod 071225
884 DeleteAndDestroy(*mpFrmFmtTbl, 1, mpFrmFmtTbl->size());
886 mxForbiddenCharsTable.clear();
888 for(SwFldTypes::const_iterator it = mpFldTypes->begin() + INIT_FLDTYPES;
889 it != mpFldTypes->end(); ++it)
890 delete *it;
891 mpFldTypes->erase( mpFldTypes->begin() + INIT_FLDTYPES, mpFldTypes->end() );
893 delete mpNumberFormatter, mpNumberFormatter = 0;
895 GetPageDescFromPool( RES_POOLPAGE_STANDARD );
896 pFirstNd->ChgFmtColl( GetTxtCollFromPool( RES_POOLCOLL_STANDARD ));
897 nDummyPgDsc = maPageDescs.size();
898 maPageDescs.push_back( pDummyPgDsc );
899 // set the layout back to the new standard pagedesc
900 pFirstNd->ResetAllAttr();
901 // delete now the dummy pagedesc
902 DelPageDesc( nDummyPgDsc );
905 void SwDoc::SetPreViewPrtData( const SwPagePreViewPrtData* pNew )
907 if( pNew )
909 if( mpPgPViewPrtData )
910 *mpPgPViewPrtData = *pNew;
911 else
912 mpPgPViewPrtData = new SwPagePreViewPrtData( *pNew );
914 else if( mpPgPViewPrtData )
915 DELETEZ( mpPgPViewPrtData );
916 SetModified();
919 SwModify* SwDoc::GetUnoCallBack() const
921 return mpUnoCallBack;
925 /** SwDoc: Reading and writing of the layout cache. */
926 void SwDoc::ReadLayoutCache( SvStream& rStream )
928 if( !mpLayoutCache )
929 mpLayoutCache = new SwLayoutCache();
930 if( !mpLayoutCache->IsLocked() )
932 mpLayoutCache->GetLockCount() |= 0x8000;
933 mpLayoutCache->Read( rStream );
934 mpLayoutCache->GetLockCount() &= 0x7fff;
938 void SwDoc::WriteLayoutCache( SvStream& rStream )
940 mpLayoutCache->Write( rStream, *this );
943 IGrammarContact* getGrammarContact( const SwTxtNode& rTxtNode )
945 const SwDoc* pDoc = rTxtNode.GetDoc();
946 if( !pDoc || pDoc->IsInDtor() )
947 return 0;
948 return pDoc->getGrammarContact();
951 // #i42634# Moved common code of SwReader::Read() and SwDocShell::UpdateLinks()
952 // to new SwDoc::UpdateLinks():
953 void SwDoc::UpdateLinks( bool bUI )
955 SfxObjectCreateMode eMode;
956 sal_uInt16 nLinkMode = getLinkUpdateMode( true );
957 if ( GetDocShell()) {
958 sal_uInt16 nUpdateDocMode = GetDocShell()->GetUpdateDocMode();
959 if( (nLinkMode != NEVER || document::UpdateDocMode::FULL_UPDATE == nUpdateDocMode) &&
960 !GetLinkManager().GetLinks().empty() &&
961 SFX_CREATE_MODE_INTERNAL !=
962 ( eMode = GetDocShell()->GetCreateMode()) &&
963 SFX_CREATE_MODE_ORGANIZER != eMode &&
964 SFX_CREATE_MODE_PREVIEW != eMode &&
965 !GetDocShell()->IsPreview() )
967 ViewShell* pVSh = 0;
968 bool bAskUpdate = nLinkMode == MANUAL;
969 bool bUpdate = true;
970 switch(nUpdateDocMode)
972 case document::UpdateDocMode::NO_UPDATE: bUpdate = false;break;
973 case document::UpdateDocMode::QUIET_UPDATE:bAskUpdate = false; break;
974 case document::UpdateDocMode::FULL_UPDATE: bAskUpdate = true; break;
976 if( bUpdate && (bUI || !bAskUpdate) )
978 SfxMedium* pMedium = GetDocShell()->GetMedium();
979 SfxFrame* pFrm = pMedium ? pMedium->GetLoadTargetFrame() : 0;
980 Window* pDlgParent = pFrm ? &pFrm->GetWindow() : 0;
981 if( GetCurrentViewShell() && !GetEditShell( &pVSh ) && !pVSh ) //swmod 071108//swmod 071225
983 ViewShell aVSh( *this, 0, 0 );
985 SET_CURR_SHELL( &aVSh );
986 GetLinkManager().UpdateAllLinks( bAskUpdate , true, false, pDlgParent );
988 else
989 GetLinkManager().UpdateAllLinks( bAskUpdate, true, false, pDlgParent );
996 ::sfx2::IXmlIdRegistry&
997 SwDoc::GetXmlIdRegistry()
999 // UGLY: this relies on SetClipBoard being called before GetXmlIdRegistry!
1000 if (!m_pXmlIdRegistry.get())
1002 m_pXmlIdRegistry.reset( ::sfx2::createXmlIdRegistry( IsClipBoard() ) );
1004 return *m_pXmlIdRegistry;
1007 ::sw::MetaFieldManager &
1008 SwDoc::GetMetaFieldManager()
1010 return *m_pMetaFieldManager;
1013 ::sw::UndoManager &
1014 SwDoc::GetUndoManager()
1016 return *m_pUndoManager;
1019 ::sw::UndoManager const&
1020 SwDoc::GetUndoManager() const
1022 return *m_pUndoManager;
1025 IDocumentUndoRedo &
1026 SwDoc::GetIDocumentUndoRedo()
1028 return *m_pUndoManager;
1031 IDocumentUndoRedo const&
1032 SwDoc::GetIDocumentUndoRedo() const
1034 return *m_pUndoManager;
1037 void SwDoc::InitTOXTypes()
1039 ShellResource* pShellRes = ViewShell::GetShellRes();
1040 SwTOXType * pNew = new SwTOXType(TOX_CONTENT, pShellRes->aTOXContentName );
1041 mpTOXTypes->push_back( pNew );
1042 pNew = new SwTOXType(TOX_INDEX, pShellRes->aTOXIndexName );
1043 mpTOXTypes->push_back( pNew );
1044 pNew = new SwTOXType(TOX_USER, pShellRes->aTOXUserName );
1045 mpTOXTypes->push_back( pNew );
1046 pNew = new SwTOXType(TOX_ILLUSTRATIONS, pShellRes->aTOXIllustrationsName );
1047 mpTOXTypes->push_back( pNew );
1048 pNew = new SwTOXType(TOX_OBJECTS, pShellRes->aTOXObjectsName );
1049 mpTOXTypes->push_back( pNew );
1050 pNew = new SwTOXType(TOX_TABLES, pShellRes->aTOXTablesName );
1051 mpTOXTypes->push_back( pNew );
1052 pNew = new SwTOXType(TOX_AUTHORITIES, pShellRes->aTOXAuthoritiesName );
1053 mpTOXTypes->push_back( pNew );
1056 void SwDoc::ReplaceDefaults(const SwDoc& rSource)
1058 // copy property defaults
1059 const sal_uInt16 aRangeOfDefaults[] =
1061 RES_FRMATR_BEGIN, RES_FRMATR_END-1,
1062 RES_CHRATR_BEGIN, RES_CHRATR_END-1,
1063 RES_PARATR_BEGIN, RES_PARATR_END-1,
1064 RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END-1,
1065 RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1,
1069 SfxItemSet aNewDefaults(GetAttrPool(), aRangeOfDefaults);
1071 sal_uInt16 nRange = 0;
1072 while (aRangeOfDefaults[nRange] != 0)
1074 for (sal_uInt16 nWhich = aRangeOfDefaults[nRange];
1075 nWhich < aRangeOfDefaults[nRange + 1]; ++nWhich)
1077 const SfxPoolItem& rSourceAttr =
1078 rSource.mpAttrPool->GetDefaultItem(nWhich);
1079 if (rSourceAttr != mpAttrPool->GetDefaultItem(nWhich))
1080 aNewDefaults.Put(rSourceAttr);
1082 nRange += 2;
1085 if (aNewDefaults.Count())
1086 SetDefault(aNewDefaults);
1089 void SwDoc::ReplaceCompatabilityOptions(const SwDoc& rSource)
1091 mn32DummyCompatabilityOptions1 = rSource.mn32DummyCompatabilityOptions1;
1092 mn32DummyCompatabilityOptions2 = rSource.mn32DummyCompatabilityOptions2;
1093 mbParaSpaceMax = rSource.mbParaSpaceMax;
1094 mbParaSpaceMaxAtPages = rSource.mbParaSpaceMaxAtPages;
1095 mbTabCompat = rSource.mbTabCompat;
1096 mbUseVirtualDevice = rSource.mbUseVirtualDevice;
1097 mbAddExternalLeading = rSource.mbAddExternalLeading;
1098 mbOldLineSpacing = rSource.mbOldLineSpacing;
1099 mbAddParaSpacingToTableCells = rSource.mbAddParaSpacingToTableCells;
1100 mbUseFormerObjectPos = rSource.mbUseFormerObjectPos;
1101 mbUseFormerTextWrapping = rSource.mbUseFormerTextWrapping;
1102 mbConsiderWrapOnObjPos = rSource.mbConsiderWrapOnObjPos;
1103 mbAddFlyOffsets = rSource.mbAddFlyOffsets;
1104 mbOldNumbering = rSource.mbOldNumbering;
1105 mbUseHiResolutionVirtualDevice = rSource.mbUseHiResolutionVirtualDevice;
1106 mbIgnoreFirstLineIndentInNumbering = rSource.mbIgnoreFirstLineIndentInNumbering;
1107 mbDoNotJustifyLinesWithManualBreak = rSource.mbDoNotJustifyLinesWithManualBreak;
1108 mbDoNotResetParaAttrsForNumFont = rSource.mbDoNotResetParaAttrsForNumFont;
1109 mbOutlineLevelYieldsOutlineRule = rSource.mbOutlineLevelYieldsOutlineRule;
1110 mbTableRowKeep = rSource.mbTableRowKeep;
1111 mbIgnoreTabsAndBlanksForLineCalculation = rSource.mbIgnoreTabsAndBlanksForLineCalculation;
1112 mbDoNotCaptureDrawObjsOnPage = rSource.mbDoNotCaptureDrawObjsOnPage;
1113 mbClipAsCharacterAnchoredWriterFlyFrames = rSource.mbClipAsCharacterAnchoredWriterFlyFrames;
1114 mbUnixForceZeroExtLeading = rSource.mbUnixForceZeroExtLeading;
1115 mbOldPrinterMetrics = rSource.mbOldPrinterMetrics;
1116 mbTabRelativeToIndent = rSource.mbTabRelativeToIndent;
1117 mbTabAtLeftIndentForParagraphsInList = rSource.mbTabAtLeftIndentForParagraphsInList;
1120 SfxObjectShell* SwDoc::CreateCopy(bool bCallInitNew ) const
1122 SwDoc* pRet = new SwDoc;
1124 // we have to use pointer here, since the callee has to decide whether
1125 // SfxObjectShellLock or SfxObjectShellRef should be used sometimes the
1126 // object will be returned with refcount set to 0 ( if no DoInitNew is done )
1127 SfxObjectShell* pRetShell = new SwDocShell( pRet, SFX_CREATE_MODE_STANDARD );
1128 if( bCallInitNew )
1130 // it could happen that DoInitNew creates model, that increases the refcount of the object
1131 pRetShell->DoInitNew();
1134 pRet->acquire();
1136 pRet->ReplaceDefaults(*this);
1138 pRet->ReplaceCompatabilityOptions(*this);
1140 pRet->ReplaceStyles(*this);
1142 // copy content
1143 pRet->Paste( *this );
1145 // remove the temporary shell if it is there as it was done before
1146 pRet->SetTmpDocShell( (SfxObjectShell*)NULL );
1148 pRet->release();
1150 return pRetShell;
1153 // copy document content - code from SwFEShell::Paste( SwDoc* )
1154 void SwDoc::Paste( const SwDoc& rSource )
1156 // this has to be empty const sal_uInt16 nStartPageNumber = GetPhyPageNum();
1157 // until the end of the NodesArray
1158 SwNodeIndex aSourceIdx( rSource.GetNodes().GetEndOfExtras(), 2 );
1159 SwPaM aCpyPam( aSourceIdx ); //DocStart
1160 SwNodeIndex aTargetIdx( GetNodes().GetEndOfExtras(), 2 );
1161 SwPaM aInsertPam( aTargetIdx ); //replaces PCURCRSR from SwFEShell::Paste()
1164 aCpyPam.SetMark();
1165 aCpyPam.Move( fnMoveForward, fnGoDoc );
1167 this->GetIDocumentUndoRedo().StartUndo( UNDO_INSGLOSSARY, NULL );
1168 this->LockExpFlds();
1171 SwPosition& rInsPos = *aInsertPam.GetPoint();
1172 //find out if the clipboard document starts with a table
1173 bool bStartWithTable = 0 != aCpyPam.Start()->nNode.GetNode().FindTableNode();
1174 SwPosition aInsertPosition( rInsPos );
1177 SwNodeIndex aIndexBefore(rInsPos.nNode);
1179 aIndexBefore--;
1181 rSource.CopyRange( aCpyPam, rInsPos, true );
1184 ++aIndexBefore;
1185 SwPaM aPaM(SwPosition(aIndexBefore),
1186 SwPosition(rInsPos.nNode));
1188 MakeUniqueNumRules(aPaM);
1192 //TODO: Is this necessary here? SaveTblBoxCntnt( &rInsPos );
1193 if(/*bIncludingPageFrames && */bStartWithTable)
1195 //remove the paragraph in front of the table
1196 SwPaM aPara(aInsertPosition);
1197 this->DelFullPara(aPara);
1199 //additionally copy page bound frames
1200 if( /*bIncludingPageFrames && */rSource.GetSpzFrmFmts()->size() )
1202 for ( sal_uInt16 i = 0; i < rSource.GetSpzFrmFmts()->size(); ++i )
1204 const SwFrmFmt& rCpyFmt = *(*rSource.GetSpzFrmFmts())[i];
1205 SwFmtAnchor aAnchor( rCpyFmt.GetAnchor() );
1206 if (FLY_AT_PAGE == aAnchor.GetAnchorId())
1208 aAnchor.SetPageNum( aAnchor.GetPageNum() /*+ nStartPageNumber - */);
1210 else
1211 continue;
1212 this->CopyLayoutFmt( rCpyFmt, aAnchor, true, true );
1217 this->GetIDocumentUndoRedo().EndUndo( UNDO_INSGLOSSARY, NULL );
1219 UnlockExpFlds();
1220 UpdateFlds(NULL, false);
1223 sal_uInt16 SwTxtFmtColls::GetPos(const SwTxtFmtColl* p) const
1225 const_iterator it = std::find(begin(), end(), p);
1226 return it == end() ? USHRT_MAX : it - begin();
1229 sal_uInt16 SwGrfFmtColls::GetPos(const SwGrfFmtColl* p) const
1231 const_iterator it = std::find(begin(), end(), p);
1232 return it == end() ? USHRT_MAX : it - begin();
1235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */