LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/doc - docnew.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 362 535 67.7 %
Date: 2012-12-17 Functions: 25 35 71.4 %
Legend: Lines: hit not hit

          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        8669 :  uno::Reference< linguistic2::XProofreadingIterator > SwDoc::GetGCIterator() const
     119             : {
     120        8669 :     if (!m_xGCIterator.is() && SvtLinguConfig().HasGrammarChecker())
     121             :     {
     122           1 :         uno::Reference< lang::XMultiServiceFactory >  xMgr( comphelper::getProcessServiceFactory() );
     123           1 :         if (xMgr.is())
     124             :         {
     125             :             try
     126             :             {
     127           1 :                 rtl::OUString aServiceName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.linguistic2.ProofreadingIterator"));
     128             :                 m_xGCIterator = uno::Reference< linguistic2::XProofreadingIterator >
     129           1 :                     ( xMgr->createInstance( aServiceName ), uno::UNO_QUERY_THROW );
     130             :             }
     131           0 :             catch (uno::Exception &)
     132             :             {
     133             :                 OSL_FAIL( "No GCIterator" );
     134             :             }
     135           1 :         }
     136             :     }
     137             : 
     138        8669 :     return m_xGCIterator;
     139             : }
     140             : 
     141        8669 : void StartGrammarChecking( SwDoc &rDoc )
     142             : {
     143             :     // check for a visible view
     144        8669 :     bool bVisible = false;
     145        8669 :     const SwDocShell *pDocShell = rDoc.GetDocShell();
     146        8669 :     SfxViewFrame    *pFrame = SfxViewFrame::GetFirst( pDocShell, sal_False );
     147       26007 :     while (pFrame && !bVisible)
     148             :     {
     149        8669 :         if (pFrame->IsVisible())
     150        8669 :             bVisible = true;
     151        8669 :         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        8669 :     if (bVisible)
     159             :     {
     160        8669 :         uno::Reference< linguistic2::XProofreadingIterator > xGCIterator( rDoc.GetGCIterator() );
     161        8669 :         if ( xGCIterator.is() )
     162             :         {
     163           5 :             uno::Reference< lang::XComponent >  xDoc( rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY );
     164           5 :             uno::Reference< text::XFlatParagraphIteratorProvider >  xFPIP( xDoc, uno::UNO_QUERY );
     165             : 
     166             :             // start automatic background checking if not active already
     167           5 :             if ( xFPIP.is() && !xGCIterator->isProofreading( xDoc ) )
     168           2 :                 xGCIterator->startProofreading( xDoc, xFPIP );
     169        8669 :         }
     170             :     }
     171        8669 : }
     172             : 
     173             : /*
     174             :  * internal functions
     175             :  */
     176         606 : static void lcl_DelFmtIndizes( SwFmt* pFmt )
     177             : {
     178         606 :     SwFmtCntnt &rFmtCntnt = (SwFmtCntnt&)pFmt->GetCntnt();
     179         606 :     if ( rFmtCntnt.GetCntntIdx() )
     180         142 :         rFmtCntnt.SetNewCntntIdx( 0 );
     181         606 :     SwFmtAnchor &rFmtAnchor = (SwFmtAnchor&)pFmt->GetAnchor();
     182         606 :     if ( rFmtAnchor.GetCntntAnchor() )
     183         218 :         rFmtAnchor.SetAnchor( 0 );
     184         606 : }
     185             : 
     186             : /*
     187             :  * exported methods
     188             :  */
     189         558 : SwDoc::SwDoc()
     190         558 :     : m_pNodes( new SwNodes(this) )
     191             :     ,
     192         558 :     mpAttrPool(new SwAttrPool(this)),
     193         558 :     pMarkManager(new ::sw::mark::MarkManager(*this)),
     194           0 :     m_pMetaFieldManager(new ::sw::MetaFieldManager()),
     195             :     m_pUndoManager(new ::sw::UndoManager(
     196        1116 :             ::std::auto_ptr<SwNodes>(new SwNodes(this)), *this, *this, *this)),
     197         558 :     pDfltFrmFmt( new SwFrmFmt( GetAttrPool(), sFrmFmtStr, 0 ) ),
     198         558 :     pEmptyPageFmt( new SwFrmFmt( GetAttrPool(), sEmptyPageStr, pDfltFrmFmt ) ),
     199         558 :     pColumnContFmt( new SwFrmFmt( GetAttrPool(), sColumnCntStr, pDfltFrmFmt ) ),
     200         558 :     pDfltCharFmt( new SwCharFmt( GetAttrPool(), sCharFmtStr, 0 ) ),
     201         558 :     pDfltTxtFmtColl( new SwTxtFmtColl( GetAttrPool(), sTxtCollStr ) ),
     202         558 :     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           0 :     pUpdtFlds( new SwDocUpdtFld() ),
     215           0 :     pFldTypes( new SwFldTypes() ),
     216             :     pVirDev( 0 ),
     217             :     pPrt( 0 ),
     218             :     pPrtData( 0 ),
     219             :     pGlossaryDoc( 0 ),
     220             :     pOutlineRule( 0 ),
     221         558 :     pFtnInfo( new SwFtnInfo ),
     222         558 :     pEndNoteInfo( new SwEndNoteInfo ),
     223         558 :     pLineNumberInfo( new SwLineNumberInfo ),
     224         558 :     pFtnIdxs( new SwFtnIdxs ),
     225         558 :     pDocStat( new SwDocStat ),
     226             :     pDocShell( 0 ),
     227         558 :     pLinkMgr( new sfx2::LinkManager( 0 ) ),
     228             :     pACEWord( 0 ),
     229             :     pURLStateChgd( 0 ),
     230             :     pNumberFormatter( 0 ),
     231         558 :     pNumRuleTbl( new SwNumRuleTbl ),
     232             :     maLists(),
     233             :     maListStyleLists(),
     234         558 :     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         558 :     pUnoCallBack(new SwModify(0)),
     243         558 :     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       12276 :     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         558 :     const SvtCompatibilityOptions aOptions;
     339         558 :     mbParaSpaceMax                      = aOptions.IsAddSpacing();
     340         558 :     mbParaSpaceMaxAtPages               = aOptions.IsAddSpacingAtPages();
     341         558 :     mbTabCompat                         = !aOptions.IsUseOurTabStops();
     342         558 :     mbUseVirtualDevice                  = !aOptions.IsUsePrtDevice();
     343         558 :     mbAddExternalLeading                = !aOptions.IsNoExtLeading();
     344         558 :     mbOldLineSpacing                    = aOptions.IsUseLineSpacing();
     345         558 :     mbAddParaSpacingToTableCells        = aOptions.IsAddTableSpacing();
     346         558 :     mbUseFormerObjectPos                = aOptions.IsUseObjectPositioning();
     347         558 :     mbUseFormerTextWrapping             = aOptions.IsUseOurTextWrapping();
     348         558 :     mbConsiderWrapOnObjPos              = aOptions.IsConsiderWrappingStyle();
     349             : 
     350         558 :     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         558 :     pFrmFmtTbl->push_back(pDfltFrmFmt);
     364         558 :     pCharFmtTbl->push_back(pDfltCharFmt);
     365             : 
     366             :     /* FmtColls */
     367             :     // TXT
     368         558 :     pTxtFmtCollTbl->push_back(pDfltTxtFmtColl);
     369             :     // GRF
     370         558 :     pGrfFmtCollTbl->push_back(pDfltGrfFmtColl);
     371             : 
     372             :     // Create PageDesc, EmptyPageFmt and ColumnFmt
     373         558 :     if ( aPageDescs.empty() )
     374         558 :         GetPageDescFromPool( RES_POOLPAGE_STANDARD );
     375             : 
     376             :     // Set to "Empty Page"
     377         558 :     pEmptyPageFmt->SetFmtAttr( SwFmtFrmSize( ATT_FIX_SIZE ) );
     378             :     // Set BodyFmt for columns
     379         558 :     pColumnContFmt->SetFmtAttr( SwFmtFillOrder( ATT_LEFT_TO_RIGHT ) );
     380             : 
     381         558 :     _InitFieldTypes();
     382             : 
     383             :     // Create a default OutlineNumRule (for Filters)
     384         558 :     pOutlineRule = new SwNumRule( rtl::OUString::createFromAscii( SwNumRule::GetOutlineRuleName() ),
     385             :                                   // #i89178#
     386             :                                   numfunc::GetDefaultPositionAndSpaceMode(),
     387         558 :                                   OUTLINE_RULE );
     388         558 :     AddNumRule(pOutlineRule);
     389             :     // Counting of phantoms depends on <IsOldNumbering()>
     390         558 :     pOutlineRule->SetCountPhantoms( !get(IDocumentSettingAccess::OLD_NUMBERING) );
     391             : 
     392             :     new SwTxtNode(
     393         558 :             SwNodeIndex(GetUndoManager().GetUndoNodes().GetEndOfContent()),
     394         558 :             pDfltTxtFmtColl );
     395         558 :     new SwTxtNode( SwNodeIndex( GetNodes().GetEndOfContent() ),
     396         558 :                     GetTxtCollFromPool( RES_POOLCOLL_STANDARD ));
     397             : 
     398             :     // set the own IdleTimer
     399         558 :     aIdleTimer.SetTimeout( 600 );
     400         558 :     aIdleTimer.SetTimeoutHdl( LINK(this, SwDoc, DoIdleJobs) );
     401             : 
     402         558 :     aOLEModifiedTimer.SetTimeout( 1000 );
     403         558 :     aOLEModifiedTimer.SetTimeoutHdl( LINK( this, SwDoc, DoUpdateModifiedOLE ));
     404             : 
     405             :     // Create DBMgr
     406         558 :     pNewDBMgr = new SwNewDBMgr;
     407             : 
     408             :     // create TOXTypes
     409         558 :     InitTOXTypes();
     410             : 
     411             :     // pass empty item set containing the paragraph's list attributes
     412             :     // as ignorable items to the stype manager.
     413             :     {
     414         558 :         SfxItemSet aIgnorableParagraphItems( GetAttrPool(), RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END-1);
     415         558 :         pStyleAccess = createStyleManager( &aIgnorableParagraphItems );
     416             :     }
     417             : 
     418             :     // Initialize the session id of the current document to a random number
     419             :     // smaller than 2^21.
     420         558 :     static rtlRandomPool aPool = rtl_random_createPool();
     421         558 :     rtl_random_getBytes( aPool, &nRsid, sizeof ( nRsid ) );
     422         558 :     nRsid &= ( 1<<21 ) - 1;
     423         558 :     nRsid++;
     424         558 :     nRsidRoot = nRsid;
     425             : 
     426         558 :     ResetModified();
     427         558 : }
     428             : 
     429         166 : static void DeleteAndDestroy(SwFrmFmts& rFmts, int aStartIdx, int aEndIdx)
     430             : {
     431         166 :     if (aEndIdx < aStartIdx)
     432         166 :         return;
     433         852 :     for( SwFrmFmts::const_iterator it = rFmts.begin() + aStartIdx;
     434         568 :          it != rFmts.begin() + aEndIdx; ++it )
     435         118 :              delete *it;
     436         166 :     rFmts.erase( rFmts.begin() + aStartIdx, rFmts.begin() + aEndIdx);
     437             : }
     438             : 
     439         314 : static void DeleteAndDestroy(SwTxtFmtColls& rFmts, int aStartIdx, int aEndIdx)
     440             : {
     441         314 :     if (aEndIdx < aStartIdx)
     442         314 :         return;
     443        4644 :     for( SwTxtFmtColls::const_iterator it = rFmts.begin() + aStartIdx;
     444        3096 :          it != rFmts.begin() + aEndIdx; ++it )
     445        1234 :              delete *it;
     446         314 :     rFmts.erase( rFmts.begin() + aStartIdx, rFmts.begin() + aEndIdx);
     447             : }
     448             : 
     449          16 : static void DeleteAndDestroy(SwCharFmts& rFmts, int aStartIdx, int aEndIdx)
     450             : {
     451          16 :     if (aEndIdx < aStartIdx)
     452          16 :         return;
     453          48 :     for( SwCharFmts::const_iterator it = rFmts.begin() + aStartIdx;
     454          32 :          it != rFmts.begin() + aEndIdx; ++it )
     455           0 :              delete *it;
     456          16 :     rFmts.erase( rFmts.begin() + aStartIdx, rFmts.begin() + aEndIdx);
     457             : }
     458             : 
     459         166 : static void DeleteAndDestroy(SwGrfFmtColls& rFmts, int aStartIdx, int aEndIdx)
     460             : {
     461         166 :     if (aEndIdx < aStartIdx)
     462         166 :         return;
     463         498 :     for( SwGrfFmtColls::const_iterator it = rFmts.begin() + aStartIdx;
     464         332 :          it != rFmts.begin() + aEndIdx; ++it )
     465           0 :              delete *it;
     466         166 :     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         450 : SwDoc::~SwDoc()
     475             : {
     476             :     // nothing here should create Undo actions!
     477         150 :     GetIDocumentUndoRedo().DoUndo(false);
     478             : 
     479         150 :     if (pDocShell)
     480             :     {
     481          16 :         pDocShell->SetUndoManager(0);
     482             :     }
     483             : 
     484             : 
     485             :     // #i83479#
     486         150 :     delete mpListItemsList;
     487         150 :     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         150 :     aChartDataProviderImplRef.reset();
     494         150 :     delete pChartControllerHelper;
     495             : 
     496         150 :     delete mpGrammarContact;
     497         150 :     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         150 :     SwFmtDrop aDrop;
     504         150 :     SetDefault(aDrop);
     505             :     //!! same for SwFmtCharFmt
     506         150 :     SwFmtCharFmt aCharFmt(NULL);
     507         150 :     SetDefault(aCharFmt);
     508             : 
     509         150 :     StopIdling();   // stop idle timer
     510             : 
     511         150 :     delete pUnoCallBack, pUnoCallBack = 0;
     512         150 :     delete pURLStateChgd;
     513             : 
     514         150 :     delete pLayouter;
     515         150 :     pLayouter = 0L;
     516             : 
     517             :     // Deactivate Undo notification from Draw
     518         150 :     if( pDrawModel )
     519             :     {
     520         122 :         DrawNotifyUndoHdl();
     521         122 :         ClrContourCache();
     522             :     }
     523             : 
     524         150 :     delete pPgPViewPrtData;
     525             : 
     526         150 :     mbDtor = true;
     527         150 :     pLayoutPtr.reset();
     528             : 
     529         150 :     delete pRedlineTbl;
     530         150 :     delete pUnoCrsrTbl;
     531         150 :     delete pAutoFmtRedlnComment;
     532         150 :     delete pUpdtFlds;
     533         150 :     delete pACEWord;
     534             : 
     535             :     // Release the BaseLinks
     536             :     {
     537         150 :        ::sfx2::SvLinkSources aTemp(pLinkMgr->GetServers());
     538         450 :        for( ::sfx2::SvLinkSources::const_iterator it = aTemp.begin();
     539         300 :             it != aTemp.end(); ++it )
     540           0 :             (*it)->Closed();
     541             : 
     542         150 :         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         150 :     m_pNodes->pOutlineNds->clear();
     549         150 :     SwNodes & rUndoNodes( GetUndoManager().GetUndoNodes() );
     550         150 :     rUndoNodes.pOutlineNds->clear();
     551             : 
     552         150 :     pFtnIdxs->clear();
     553             : 
     554             :     // indices could be registered in attributes
     555         150 :     m_pUndoManager->DelAllUndoObj();
     556             : 
     557             :     // The BookMarks contain indices to the Content. These must be deleted
     558             :     // before deleting the Nodes.
     559         150 :     pMarkManager->clearAllMarks();
     560             : 
     561         150 :     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        1462 :         for( sal_uInt16 n = pTOXTypes->size(); n; )
     574             :         {
     575        1162 :             (*pTOXTypes)[ --n ]->SetInDocDTOR();
     576        1162 :             delete (*pTOXTypes)[ n ];
     577             :         }
     578         150 :         pTOXTypes->clear();
     579             :     }
     580         150 :     delete pDefTOXBases;
     581             : 
     582             :     // Any of the FrmFormats can still have indices registered.
     583             :     // These need to be destroyed now at the latest.
     584         532 :     BOOST_FOREACH( SwFrmFmt* pFmt, *pFrmFmtTbl )
     585         382 :         lcl_DelFmtIndizes( pFmt );
     586         372 :     BOOST_FOREACH( SwFrmFmt* pFmt, *pSpzFrmFmtTbl )
     587         222 :         lcl_DelFmtIndizes( pFmt );
     588         152 :     BOOST_FOREACH( SwSectionFmt* pFmt, *pSectionFmtTbl )
     589           2 :         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         366 :     BOOST_FOREACH(SwPageDesc *pPageDesc, aPageDescs)
     596         216 :         delete pPageDesc;
     597         150 :     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         150 :     m_pNodes->DelNodes( SwNodeIndex(*m_pNodes), m_pNodes->Count() );
     603         150 :     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         150 :     pFtnInfo->ReleaseCollection();
     610         150 :     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         150 :     if( 2 < pTxtFmtCollTbl->size() )
     619         146 :         DeleteAndDestroy(*pTxtFmtCollTbl, 2, pTxtFmtCollTbl->size());
     620         150 :     DeleteAndDestroy(*pTxtFmtCollTbl, 1, pTxtFmtCollTbl->size());
     621         150 :     delete pTxtFmtCollTbl;
     622             : 
     623             :     OSL_ENSURE( pDfltGrfFmtColl == (*pGrfFmtCollTbl)[0],
     624             :             "DefaultGrfCollection must always be at the start" );
     625             : 
     626         150 :     DeleteAndDestroy(*pGrfFmtCollTbl, 1, pGrfFmtCollTbl->size());
     627         150 :     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         150 :     pFrmFmtTbl->erase( pFrmFmtTbl->begin() );
     636         150 :     pCharFmtTbl->erase( pCharFmtTbl->begin() );
     637             : 
     638         150 :     DELETEZ( pPrt );
     639         150 :     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         150 :     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         150 :     ReleaseDrawModel();
     650             :     // Destroy DrawModel before the LinkManager, because it's always set
     651             :     // in the DrawModel.
     652         150 :     DELETEZ( pLinkMgr );
     653             : 
     654             :     // Clear the Tables before deleting the defaults, or we crash due to
     655             :     // dependencies on defaults.
     656         150 :     delete pFrmFmtTbl;
     657         150 :     delete pSpzFrmFmtTbl;
     658             : 
     659         150 :     delete pStyleAccess;
     660             : 
     661         150 :     delete pCharFmtTbl;
     662         150 :     delete pSectionFmtTbl;
     663         150 :     delete pTblFrmFmtTbl;
     664         150 :     delete pDfltTxtFmtColl;
     665         150 :     delete pDfltGrfFmtColl;
     666         150 :     delete pNumRuleTbl;
     667             : 
     668             :     {
     669        2307 :         for ( boost::unordered_map< String, SwList*, StringHash >::iterator
     670         150 :                                                     aListIter = maLists.begin();
     671        1538 :               aListIter != maLists.end();
     672             :               ++aListIter )
     673             :         {
     674         619 :             delete (*aListIter).second;
     675             :         }
     676         150 :         maLists.clear();
     677             :     }
     678         150 :     maListStyleLists.clear();
     679             : 
     680         150 :     delete pPrtData;
     681         150 :     delete pNumberFormatter;
     682         150 :     delete pFtnInfo;
     683         150 :     delete pEndNoteInfo;
     684         150 :     delete pLineNumberInfo;
     685         150 :     delete pFtnIdxs;
     686         150 :     delete pFldTypes;
     687         150 :     delete pTOXTypes;
     688         150 :     delete pDocStat;
     689         150 :     delete pEmptyPageFmt;
     690         150 :     delete pColumnContFmt;
     691         150 :     delete pDfltCharFmt;
     692         150 :     delete pDfltFrmFmt;
     693         150 :     delete pLayoutCache;
     694         150 :     delete pVirDev;
     695             : 
     696         150 :     SfxItemPool::Free(mpAttrPool);
     697         300 : }
     698             : 
     699         556 : VirtualDevice& SwDoc::CreateVirtualDevice_() const
     700             : {
     701         556 :     VirtualDevice* pNewVir = new VirtualDevice( 1 );
     702             : 
     703         556 :     pNewVir->SetReferenceDevice( VirtualDevice::REFDEV_MODE_MSO1 );
     704             : 
     705             :     // #i60945# External leading compatibility for unix systems.
     706         556 :     if ( get(IDocumentSettingAccess::UNIX_FORCE_ZERO_EXT_LEADING ) )
     707           0 :         pNewVir->Compat_ZeroExtleadBug();
     708             : 
     709         556 :     MapMode aMapMode( pNewVir->GetMapMode() );
     710         556 :     aMapMode.SetMapUnit( MAP_TWIP );
     711         556 :     pNewVir->SetMapMode( aMapMode );
     712             : 
     713         556 :     const_cast<SwDoc*>(this)->setVirtualDevice( pNewVir, true, true );
     714         556 :     return *pVirDev;
     715             : }
     716             : 
     717           8 : 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           8 :     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           8 :                     0 );
     733             : 
     734           8 :     SfxPrinter* pNewPrt = new SfxPrinter( pSet );
     735           8 :     const_cast<SwDoc*>(this)->setPrinter( pNewPrt, true, true );
     736           8 :     return *pPrt;
     737             : }
     738             : 
     739         910 : void SwDoc::SetDocShell( SwDocShell* pDSh )
     740             : {
     741         910 :     if( pDocShell != pDSh )
     742             :     {
     743         910 :         if (pDocShell)
     744             :         {
     745         244 :             pDocShell->SetUndoManager(0);
     746             :         }
     747         910 :         pDocShell = pDSh;
     748         910 :         if (pDocShell)
     749             :         {
     750         666 :             pDocShell->SetUndoManager(& GetUndoManager());
     751             :         }
     752             : 
     753         910 :         pLinkMgr->SetPersist( pDocShell );
     754         910 :         if( pDrawModel )
     755             :         {
     756         342 :             ((SwDrawDocument*)pDrawModel)->SetObjectShell( pDocShell );
     757         342 :             pDrawModel->SetPersist( pDocShell );
     758             :             OSL_ENSURE( pDrawModel->GetPersist() == GetPersist(),
     759             :                     "draw model's persist is out of sync" );
     760             :         }
     761             :     }
     762         910 : }
     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         741 : SfxObjectShell* SwDoc::GetPersist() const
     775             : {
     776         741 :     return pDocShell ? pDocShell : pLinkMgr->GetPersist();
     777             : }
     778             : 
     779          16 : void SwDoc::ClearDoc()
     780             : {
     781          16 :     GetIDocumentUndoRedo().DelAllUndoObj();
     782          16 :     ::sw::UndoGuard const undoGuard(GetIDocumentUndoRedo());
     783             : 
     784             :     // Deactivate Undo notification from Draw
     785          16 :     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          32 :     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          16 :     pRedlineTbl->DeleteAndDestroyAll();
     799             : 
     800          16 :     delete pACEWord;
     801             : 
     802             :     // The BookMarks contain indices to the Content. These must be deleted
     803             :     // before deleting the Nodes.
     804          16 :     pMarkManager->clearAllMarks();
     805          16 :     InitTOXTypes();
     806             : 
     807             :     // create a dummy pagedesc for the layout
     808          16 :     sal_uInt16 nDummyPgDsc = MakePageDesc(rtl::OUString("?DUMMY?"));
     809          16 :     SwPageDesc* pDummyPgDsc = aPageDescs[ nDummyPgDsc ];
     810             : 
     811          16 :     SwNodeIndex aSttIdx( *GetNodes().GetEndOfContent().StartOfSectionNode(), 1 );
     812             :     // create the first one over and over again (without attributes/style etc.
     813          16 :     SwTxtNode* pFirstNd = GetNodes().MakeTxtNode( aSttIdx, pDfltTxtFmtColl );
     814             : 
     815          16 :     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          16 :     GetNodes().Delete( aSttIdx,
     826          32 :             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          16 :     pOutlineRule = NULL;
     832          32 :     BOOST_FOREACH( SwNumRule* pNumRule, *pNumRuleTbl )
     833          16 :         delete pNumRule;
     834          16 :     pNumRuleTbl->clear();
     835             :     // #i114725#,#i115828#
     836             :     {
     837          96 :         for ( boost::unordered_map< String, SwList*, StringHash >::iterator
     838          16 :                                                     aListIter = maLists.begin();
     839          64 :               aListIter != maLists.end();
     840             :               ++aListIter )
     841             :         {
     842          16 :             delete (*aListIter).second;
     843             :         }
     844          16 :         maLists.clear();
     845             :     }
     846          16 :     maListStyleLists.clear();
     847             : 
     848             :     // creation of new outline numbering rule
     849          16 :     pOutlineRule = new SwNumRule( rtl::OUString::createFromAscii( SwNumRule::GetOutlineRuleName() ),
     850             :                                   // #i89178#
     851             :                                   numfunc::GetDefaultPositionAndSpaceMode(),
     852          16 :                                   OUTLINE_RULE );
     853          16 :     AddNumRule(pOutlineRule);
     854             :     // Counting of phantoms depends on <IsOldNumbering()>
     855          16 :     pOutlineRule->SetCountPhantoms( !get(IDocumentSettingAccess::OLD_NUMBERING) );
     856             : 
     857             :     // remove the dummy pagedec from the array and delete all the old ones
     858          16 :     aPageDescs.erase( aPageDescs.begin() + nDummyPgDsc );
     859          32 :     BOOST_FOREACH(SwPageDesc *pPageDesc, aPageDescs)
     860          16 :         delete pPageDesc;
     861          16 :     aPageDescs.clear();
     862             : 
     863             :     // Delete for Collections
     864             :     // So that we get rid of the dependencies
     865          16 :     pFtnInfo->ReleaseCollection();
     866          16 :     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          16 :     if( 2 < pTxtFmtCollTbl->size() )
     872           2 :         DeleteAndDestroy(*pTxtFmtCollTbl, 2, pTxtFmtCollTbl->size());
     873          16 :     DeleteAndDestroy(*pTxtFmtCollTbl, 1, pTxtFmtCollTbl->size());
     874          16 :     DeleteAndDestroy(*pGrfFmtCollTbl, 1, pGrfFmtCollTbl->size());
     875          16 :     DeleteAndDestroy(*pCharFmtTbl, 1, pCharFmtTbl->size());
     876             : 
     877          16 :     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          16 :         DeleteAndDestroy(*pFrmFmtTbl, 1, pFrmFmtTbl->size());
     886             : 
     887          16 :     xForbiddenCharsTable.clear();
     888             : 
     889          48 :     for(SwFldTypes::const_iterator it = pFldTypes->begin() + INIT_FLDTYPES;
     890          32 :         it != pFldTypes->end(); ++it)
     891           0 :         delete *it;
     892          16 :     pFldTypes->erase( pFldTypes->begin() + INIT_FLDTYPES, pFldTypes->end() );
     893             : 
     894          16 :     delete pNumberFormatter, pNumberFormatter = 0;
     895             : 
     896          16 :     GetPageDescFromPool( RES_POOLPAGE_STANDARD );
     897          16 :     pFirstNd->ChgFmtColl( GetTxtCollFromPool( RES_POOLCOLL_STANDARD ));
     898          16 :     nDummyPgDsc = aPageDescs.size();
     899          16 :     aPageDescs.push_back( pDummyPgDsc );
     900             :     // set the layout back to the new standard pagedesc
     901          16 :     pFirstNd->ResetAllAttr();
     902             :     // delete now the dummy pagedesc
     903          16 :     DelPageDesc( nDummyPgDsc );
     904          16 : }
     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         175 : SwModify*   SwDoc::GetUnoCallBack() const
     921             : {
     922         175 :     return pUnoCallBack;
     923             : }
     924             : 
     925             : 
     926             : /** SwDoc:
     927             :  *  Reading and writing of the layout cache.
     928             :  *--------------------------------------------------*/
     929          10 : void SwDoc::ReadLayoutCache( SvStream& rStream )
     930             : {
     931          10 :     if( !pLayoutCache )
     932          10 :         pLayoutCache = new SwLayoutCache();
     933          10 :     if( !pLayoutCache->IsLocked() )
     934             :     {
     935          10 :         pLayoutCache->GetLockCount() |= 0x8000;
     936          10 :         pLayoutCache->Read( rStream );
     937          10 :         pLayoutCache->GetLockCount() &= 0x7fff;
     938             :     }
     939          10 : }
     940             : 
     941           2 : void SwDoc::WriteLayoutCache( SvStream& rStream )
     942             : {
     943           2 :     pLayoutCache->Write( rStream, *this );
     944           2 : }
     945             : 
     946         839 : IGrammarContact* getGrammarContact( const SwTxtNode& rTxtNode )
     947             : {
     948         839 :     const SwDoc* pDoc = rTxtNode.GetDoc();
     949         839 :     if( !pDoc || pDoc->IsInDtor() )
     950           0 :         return 0;
     951         839 :     return pDoc->getGrammarContact();
     952             : }
     953             : 
     954             : // #i42634# Moved common code of SwReader::Read() and SwDocShell::UpdateLinks()
     955             : // to new SwDoc::UpdateLinks():
     956         539 : void SwDoc::UpdateLinks( bool bUI )
     957             : {
     958             :     SfxObjectCreateMode eMode;
     959         539 :     sal_uInt16 nLinkMode = getLinkUpdateMode( true );
     960         539 :     if ( GetDocShell()) {
     961         539 :         sal_uInt16 nUpdateDocMode = GetDocShell()->GetUpdateDocMode();
     962        1078 :         if( (nLinkMode != NEVER ||  document::UpdateDocMode::FULL_UPDATE == nUpdateDocMode) &&
     963         539 :             !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         539 : }
     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         462 : SwDoc::GetMetaFieldManager()
    1012             : {
    1013         462 :     return *m_pMetaFieldManager;
    1014             : }
    1015             : 
    1016             : ::sw::UndoManager &
    1017        1374 : SwDoc::GetUndoManager()
    1018             : {
    1019        1374 :     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      246508 : SwDoc::GetIDocumentUndoRedo()
    1030             : {
    1031      246508 :     return *m_pUndoManager;
    1032             : }
    1033             : 
    1034             : IDocumentUndoRedo const&
    1035         684 : SwDoc::GetIDocumentUndoRedo() const
    1036             : {
    1037         684 :     return *m_pUndoManager;
    1038             : }
    1039             : 
    1040         574 : void SwDoc::InitTOXTypes()
    1041             : {
    1042         574 :    ShellResource* pShellRes = ViewShell::GetShellRes();
    1043         574 :    SwTOXType * pNew = new SwTOXType(TOX_CONTENT,   pShellRes->aTOXContentName        );
    1044         574 :    pTOXTypes->push_back( pNew );
    1045         574 :    pNew = new SwTOXType(TOX_INDEX,                 pShellRes->aTOXIndexName  );
    1046         574 :    pTOXTypes->push_back( pNew );
    1047         574 :    pNew = new SwTOXType(TOX_USER,                  pShellRes->aTOXUserName  );
    1048         574 :    pTOXTypes->push_back( pNew );
    1049         574 :    pNew = new SwTOXType(TOX_ILLUSTRATIONS,         pShellRes->aTOXIllustrationsName );
    1050         574 :    pTOXTypes->push_back( pNew );
    1051         574 :    pNew = new SwTOXType(TOX_OBJECTS,               pShellRes->aTOXObjectsName       );
    1052         574 :    pTOXTypes->push_back( pNew );
    1053         574 :    pNew = new SwTOXType(TOX_TABLES,                pShellRes->aTOXTablesName        );
    1054         574 :    pTOXTypes->push_back( pNew );
    1055         574 :    pNew = new SwTOXType(TOX_AUTHORITIES,           pShellRes->aTOXAuthoritiesName   );
    1056         574 :    pTOXTypes->push_back( pNew );
    1057         574 : }
    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: */

Generated by: LCOV version 1.10