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

Generated by: LCOV version 1.10