LCOV - code coverage report
Current view: top level - sw/source/core/doc - doc.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 687 1355 50.7 %
Date: 2014-04-11 Functions: 75 106 70.8 %
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 <UndoManager.hxx>
      22             : #include <hintids.hxx>
      23             : 
      24             : #include <tools/shl.hxx>
      25             : #include <tools/globname.hxx>
      26             : #include <svx/svxids.hrc>
      27             : #include <rtl/random.h>
      28             : 
      29             : #include <com/sun/star/i18n/WordType.hpp>
      30             : #include <com/sun/star/i18n/ForbiddenCharacters.hpp>
      31             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      32             : #include <com/sun/star/beans/NamedValue.hpp>
      33             : #include <com/sun/star/beans/XPropertySet.hpp>
      34             : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
      35             : #include <com/sun/star/document/XDocumentProperties.hpp>
      36             : #include <comphelper/processfactory.hxx>
      37             : #include <comphelper/string.hxx>
      38             : #include <tools/urlobj.hxx>
      39             : #include <tools/poly.hxx>
      40             : #include <tools/multisel.hxx>
      41             : #include <rtl/ustring.hxx>
      42             : #include <vcl/virdev.hxx>
      43             : #include <svl/itemiter.hxx>
      44             : #include <svl/poolitem.hxx>
      45             : #include <unotools/syslocale.hxx>
      46             : #include <sfx2/printer.hxx>
      47             : #include <editeng/keepitem.hxx>
      48             : #include <editeng/charsetcoloritem.hxx>
      49             : #include <editeng/formatbreakitem.hxx>
      50             : #include <sfx2/linkmgr.hxx>
      51             : #include <editeng/forbiddencharacterstable.hxx>
      52             : #include <svx/svdmodel.hxx>
      53             : #include <editeng/pbinitem.hxx>
      54             : #include <unotools/charclass.hxx>
      55             : #include <unotools/localedatawrapper.hxx>
      56             : #include <vcl/timer.hxx>
      57             : 
      58             : #include <swatrset.hxx>
      59             : #include <swmodule.hxx>
      60             : #include <fmtpdsc.hxx>
      61             : #include <fmtanchr.hxx>
      62             : #include <fmtrfmrk.hxx>
      63             : #include <fmtinfmt.hxx>
      64             : #include <fmtfld.hxx>
      65             : #include <txtfld.hxx>
      66             : #include <dbfld.hxx>
      67             : #include <txtinet.hxx>
      68             : #include <txtrfmrk.hxx>
      69             : #include <frmatr.hxx>
      70             : #include <linkenum.hxx>
      71             : #include <pagefrm.hxx>
      72             : #include <rootfrm.hxx>
      73             : #include <swtable.hxx>
      74             : #include <pam.hxx>
      75             : #include <ndtxt.hxx>
      76             : #include <swundo.hxx>
      77             : #include <UndoCore.hxx>
      78             : #include <UndoInsert.hxx>
      79             : #include <UndoSplitMove.hxx>
      80             : #include <UndoTable.hxx>
      81             : #include <pagedesc.hxx>
      82             : #include <breakit.hxx>
      83             : #include <ndole.hxx>
      84             : #include <ndgrf.hxx>
      85             : #include <rolbck.hxx>
      86             : #include <doctxm.hxx>
      87             : #include <grfatr.hxx>
      88             : #include <poolfmt.hxx>
      89             : #include <mvsave.hxx>
      90             : #include <SwGrammarMarkUp.hxx>
      91             : #include <scriptinfo.hxx>
      92             : #include <acorrect.hxx>
      93             : #include <mdiexp.hxx>
      94             : #include <docstat.hxx>
      95             : #include <docary.hxx>
      96             : #include <redline.hxx>
      97             : #include <fldupde.hxx>
      98             : #include <swbaslnk.hxx>
      99             : #include <printdata.hxx>
     100             : #include <cmdid.h>
     101             : #include <statstr.hrc>
     102             : #include <comcore.hrc>
     103             : #include <SwUndoTOXChange.hxx>
     104             : #include <SwUndoFmt.hxx>
     105             : #include <unocrsr.hxx>
     106             : #include <docsh.hxx>
     107             : #include <viewopt.hxx>
     108             : #include <docfld.hxx>
     109             : #include <docufld.hxx>
     110             : #include <viewsh.hxx>
     111             : #include <shellres.hxx>
     112             : #include <txtfrm.hxx>
     113             : #include <attrhint.hxx>
     114             : #include <view.hxx>
     115             : 
     116             : #include <wdocsh.hxx>
     117             : #include <prtopt.hxx>
     118             : 
     119             : #include <vector>
     120             : #include <map>
     121             : 
     122             : #include <osl/diagnose.h>
     123             : #include <osl/interlck.h>
     124             : #include <vbahelper/vbaaccesshelper.hxx>
     125             : 
     126             : #include "switerator.hxx"
     127             : 
     128             : /* @@@MAINTAINABILITY-HORROR@@@
     129             :    Probably unwanted dependency on SwDocShell
     130             : */
     131             : #include <layouter.hxx>
     132             : 
     133             : using namespace ::com::sun::star;
     134             : 
     135             : /* IInterface */
     136        5833 : sal_Int32 SwDoc::acquire()
     137             : {
     138             :     OSL_ENSURE(mReferenceCount >= 0, "Negative reference count detected! This is a sign for unbalanced acquire/release calls.");
     139        5833 :     return osl_atomic_increment(&mReferenceCount);
     140             : }
     141             : 
     142        5816 : sal_Int32 SwDoc::release()
     143             : {
     144             :     OSL_PRECOND(mReferenceCount >= 1, "Object is already released! Releasing it again leads to a negative reference count.");
     145        5816 :     return osl_atomic_decrement(&mReferenceCount);
     146             : }
     147             : 
     148        1594 : sal_Int32 SwDoc::getReferenceCount() const
     149             : {
     150             :     OSL_ENSURE(mReferenceCount >= 0, "Negative reference count detected! This is a sign for unbalanced acquire/release calls.");
     151        1594 :     return mReferenceCount;
     152             : }
     153             : 
     154             : /* IDocumentSettingAccess */
     155     4495749 : bool SwDoc::get(/*[in]*/ DocumentSettingId id) const
     156             : {
     157     4495749 :     switch (id)
     158             :     {
     159             :         // COMPATIBILITY FLAGS START
     160       32421 :         case PARA_SPACE_MAX: return mbParaSpaceMax; //(n8Dummy1 & DUMMY_PARASPACEMAX);
     161       35767 :         case PARA_SPACE_MAX_AT_PAGES: return mbParaSpaceMaxAtPages; //(n8Dummy1 & DUMMY_PARASPACEMAX_AT_PAGES);
     162      119234 :         case TAB_COMPAT: return mbTabCompat; //(n8Dummy1 & DUMMY_TAB_COMPAT);
     163       46933 :         case ADD_FLY_OFFSETS: return mbAddFlyOffsets; //(n8Dummy2 & DUMMY_ADD_FLY_OFFSETS);
     164      790904 :         case ADD_EXT_LEADING: return mbAddExternalLeading; //(n8Dummy2 & DUMMY_ADD_EXTERNAL_LEADING);
     165     1343197 :         case USE_VIRTUAL_DEVICE: return mbUseVirtualDevice; //(n8Dummy1 & DUMMY_USE_VIRTUAL_DEVICE);
     166         128 :         case USE_HIRES_VIRTUAL_DEVICE: return mbUseHiResolutionVirtualDevice; //(n8Dummy2 & DUMMY_USE_HIRES_VIR_DEV);
     167        1891 :         case OLD_NUMBERING: return mbOldNumbering;
     168      162683 :         case OLD_LINE_SPACING: return mbOldLineSpacing;
     169       19660 :         case ADD_PARA_SPACING_TO_TABLE_CELLS: return mbAddParaSpacingToTableCells;
     170       11026 :         case USE_FORMER_OBJECT_POS: return mbUseFormerObjectPos;
     171       56842 :         case USE_FORMER_TEXT_WRAPPING: return mbUseFormerTextWrapping;
     172      268061 :         case CONSIDER_WRAP_ON_OBJECT_POSITION: return mbConsiderWrapOnObjPos;
     173         153 :         case DO_NOT_JUSTIFY_LINES_WITH_MANUAL_BREAK: return mbDoNotJustifyLinesWithManualBreak;
     174      204655 :         case IGNORE_FIRST_LINE_INDENT_IN_NUMBERING: return mbIgnoreFirstLineIndentInNumbering;
     175          20 :         case OUTLINE_LEVEL_YIELDS_OUTLINE_RULE: return mbOutlineLevelYieldsOutlineRule;
     176        4016 :         case TABLE_ROW_KEEP: return mbTableRowKeep;
     177       56853 :         case IGNORE_TABS_AND_BLANKS_FOR_LINE_CALCULATION: return mbIgnoreTabsAndBlanksForLineCalculation;
     178        2838 :         case DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE: return mbDoNotCaptureDrawObjsOnPage;
     179             :         // #i68949#
     180        2199 :         case CLIP_AS_CHARACTER_ANCHORED_WRITER_FLY_FRAME: return mbClipAsCharacterAnchoredWriterFlyFrames;
     181        1864 :         case UNIX_FORCE_ZERO_EXT_LEADING: return mbUnixForceZeroExtLeading;
     182      143823 :         case TABS_RELATIVE_TO_INDENT : return mbTabRelativeToIndent;
     183       31463 :         case PROTECT_FORM: return mbProtectForm;
     184             :         // #i89181#
     185         351 :         case TAB_AT_LEFT_INDENT_FOR_PARA_IN_LIST: return mbTabAtLeftIndentForParagraphsInList;
     186      373321 :         case INVERT_BORDER_SPACING: return mbInvertBorderSpacing;
     187      111532 :         case COLLAPSE_EMPTY_CELL_PARA: return mbCollapseEmptyCellPara;
     188       36867 :         case SMALL_CAPS_PERCENTAGE_66: return mbSmallCapsPercentage66;
     189       11077 :         case TAB_OVERFLOW: return mbTabOverflow;
     190       64457 :         case UNBREAKABLE_NUMBERINGS: return mbUnbreakableNumberings;
     191         133 :         case CLIPPED_PICTURES: return mbClippedPictures;
     192        6776 :         case BACKGROUND_PARA_OVER_DRAWINGS: return mbBackgroundParaOverDrawings;
     193       95264 :         case TAB_OVER_MARGIN: return mbTabOverMargin;
     194         531 :         case SURROUND_TEXT_WRAP_SMALL: return mbSurroundTextWrapSmall;
     195             : 
     196        8576 :         case BROWSE_MODE: return mbLastBrowseMode; // Attention: normally the SwViewShell has to be asked!
     197      188815 :         case HTML_MODE: return mbHTMLMode;
     198        1854 :         case GLOBAL_DOCUMENT: return mbIsGlobalDoc;
     199          22 :         case GLOBAL_DOCUMENT_SAVE_LINKS: return mbGlblDocSaveLinks;
     200        3932 :         case LABEL_DOCUMENT: return mbIsLabelDoc;
     201        6897 :         case PURGE_OLE: return mbPurgeOLE;
     202       32476 :         case KERN_ASIAN_PUNCTUATION: return mbKernAsianPunctuation;
     203        3134 :         case DO_NOT_RESET_PARA_ATTRS_FOR_NUM_FONT: return mbDoNotResetParaAttrsForNumFont;
     204          20 :         case MATH_BASELINE_ALIGNMENT: return mbMathBaselineAlignment;
     205       14160 :         case STYLES_NODEFAULT: return mbStylesNoDefault;
     206      194539 :         case FLOATTABLE_NOMARGINS: return mbFloattableNomargins;
     207        4092 :         case EMBED_FONTS: return mEmbedFonts;
     208         292 :         case EMBED_SYSTEM_FONTS: return mEmbedSystemFonts;
     209             :         default:
     210             :             OSL_FAIL("Invalid setting id");
     211             :     }
     212           0 :     return false;
     213             : }
     214             : 
     215       51403 : void SwDoc::set(/*[in]*/ DocumentSettingId id, /*[in]*/ bool value)
     216             : {
     217       51403 :     switch (id)
     218             :     {
     219             :         // COMPATIBILITY FLAGS START
     220             :         case PARA_SPACE_MAX:
     221        1351 :             mbParaSpaceMax = value;
     222        1351 :             break;
     223             :         case PARA_SPACE_MAX_AT_PAGES:
     224         186 :             mbParaSpaceMaxAtPages = value;
     225         186 :             break;
     226             :         case TAB_COMPAT:
     227         186 :             mbTabCompat = value;
     228         186 :             break;
     229             :         case ADD_FLY_OFFSETS:
     230        1089 :             mbAddFlyOffsets = value;
     231        1089 :             break;
     232             :         case ADD_EXT_LEADING:
     233         188 :             mbAddExternalLeading = value;
     234         188 :             break;
     235             :         case USE_VIRTUAL_DEVICE:
     236          78 :             mbUseVirtualDevice = value;
     237          78 :             break;
     238             :         case USE_HIRES_VIRTUAL_DEVICE:
     239          78 :             mbUseHiResolutionVirtualDevice = value;
     240          78 :             break;
     241             :         case OLD_NUMBERING:
     242        1090 :             if (mbOldNumbering != value)
     243             :             {
     244           3 :                 mbOldNumbering = value;
     245             : 
     246           3 :                 const SwNumRuleTbl& rNmTbl = GetNumRuleTbl();
     247           6 :                 for( sal_uInt16 n = 0; n < rNmTbl.size(); ++n )
     248           3 :                     rNmTbl[n]->SetInvalidRule(sal_True);
     249             : 
     250           3 :                 UpdateNumRule();
     251             : 
     252           3 :                 if (mpOutlineRule)
     253             :                 {
     254           3 :                     mpOutlineRule->Validate();
     255             :                     // counting of phantoms depends on <IsOldNumbering()>
     256           3 :                     mpOutlineRule->SetCountPhantoms( !mbOldNumbering );
     257             :                 }
     258             :             }
     259        1090 :             break;
     260             :         case OLD_LINE_SPACING:
     261        1091 :             mbOldLineSpacing = value;
     262        1091 :             break;
     263             :         case ADD_PARA_SPACING_TO_TABLE_CELLS:
     264        1091 :             mbAddParaSpacingToTableCells = value;
     265        1091 :             break;
     266             :         case USE_FORMER_OBJECT_POS:
     267        1091 :             mbUseFormerObjectPos = value;
     268        1091 :             break;
     269             :         case USE_FORMER_TEXT_WRAPPING:
     270        1090 :             mbUseFormerTextWrapping = value;
     271        1090 :             break;
     272             :         case CONSIDER_WRAP_ON_OBJECT_POSITION:
     273        1090 :             mbConsiderWrapOnObjPos = value;
     274        1090 :             break;
     275             :         case DO_NOT_JUSTIFY_LINES_WITH_MANUAL_BREAK:
     276         186 :             mbDoNotJustifyLinesWithManualBreak = value;
     277         186 :             break;
     278             :         case IGNORE_FIRST_LINE_INDENT_IN_NUMBERING:
     279        1090 :             mbIgnoreFirstLineIndentInNumbering = value;
     280        1090 :             break;
     281             : 
     282             :         case OUTLINE_LEVEL_YIELDS_OUTLINE_RULE:
     283         113 :             mbOutlineLevelYieldsOutlineRule = value;
     284         113 :             break;
     285             : 
     286             :         case TABLE_ROW_KEEP:
     287        1090 :             mbTableRowKeep = value;
     288        1090 :             break;
     289             : 
     290             :         case IGNORE_TABS_AND_BLANKS_FOR_LINE_CALCULATION:
     291        1089 :             mbIgnoreTabsAndBlanksForLineCalculation = value;
     292        1089 :             break;
     293             : 
     294             :         case DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE:
     295         114 :             mbDoNotCaptureDrawObjsOnPage = value;
     296         114 :             break;
     297             : 
     298             :         // #i68949#
     299             :         case CLIP_AS_CHARACTER_ANCHORED_WRITER_FLY_FRAME:
     300         113 :             mbClipAsCharacterAnchoredWriterFlyFrames = value;
     301         113 :             break;
     302             : 
     303             :         case UNIX_FORCE_ZERO_EXT_LEADING:
     304         113 :             mbUnixForceZeroExtLeading = value;
     305         113 :             break;
     306             : 
     307             :         case PROTECT_FORM:
     308         184 :             mbProtectForm = value;
     309         184 :             break;
     310             : 
     311             :         case TABS_RELATIVE_TO_INDENT:
     312        1360 :             mbTabRelativeToIndent = value;
     313        1360 :             break;
     314             :         // #i89181#
     315             :         case TAB_AT_LEFT_INDENT_FOR_PARA_IN_LIST:
     316         112 :             mbTabAtLeftIndentForParagraphsInList = value;
     317         112 :             break;
     318             : 
     319             :         case INVERT_BORDER_SPACING:
     320        1079 :             mbInvertBorderSpacing = value;
     321        1079 :             break;
     322             : 
     323             :         case COLLAPSE_EMPTY_CELL_PARA:
     324        1079 :             mbCollapseEmptyCellPara = value;
     325        1079 :             break;
     326             : 
     327             :         case SMALL_CAPS_PERCENTAGE_66:
     328         113 :             mbSmallCapsPercentage66 = value;
     329         113 :             break;
     330             : 
     331             :         case TAB_OVERFLOW:
     332        1090 :             mbTabOverflow = value;
     333        1090 :             break;
     334             : 
     335             :         case UNBREAKABLE_NUMBERINGS:
     336        1090 :             mbUnbreakableNumberings = value;
     337        1090 :             break;
     338             : 
     339             :         case CLIPPED_PICTURES:
     340        1090 :             mbClippedPictures = value;
     341        1090 :             break;
     342             : 
     343             :         case BACKGROUND_PARA_OVER_DRAWINGS:
     344        1017 :             mbBackgroundParaOverDrawings = value;
     345        1017 :             break;
     346             : 
     347             :         case TAB_OVER_MARGIN:
     348        1090 :             mbTabOverMargin = value;
     349        1090 :             break;
     350             : 
     351             :         case SURROUND_TEXT_WRAP_SMALL:
     352        1305 :             mbSurroundTextWrapSmall = value;
     353        1305 :             break;
     354             : 
     355             :         // COMPATIBILITY FLAGS END
     356             : 
     357             :         case BROWSE_MODE: //can be used temporary (load/save) when no SwViewShell is avaiable
     358        1719 :             mbLastBrowseMode = value;
     359        1719 :             break;
     360             : 
     361             :         case HTML_MODE:
     362        4327 :             mbHTMLMode = value;
     363        4327 :             break;
     364             : 
     365             :         case GLOBAL_DOCUMENT:
     366           0 :             mbIsGlobalDoc = value;
     367           0 :             break;
     368             : 
     369             :         case GLOBAL_DOCUMENT_SAVE_LINKS:
     370         113 :             mbGlblDocSaveLinks = value;
     371         113 :             break;
     372             : 
     373             :         case LABEL_DOCUMENT:
     374         113 :             mbIsLabelDoc = value;
     375         113 :             break;
     376             : 
     377             :         case PURGE_OLE:
     378       13794 :             mbPurgeOLE = value;
     379       13794 :             break;
     380             : 
     381             :         case KERN_ASIAN_PUNCTUATION:
     382        1920 :             mbKernAsianPunctuation = value;
     383        1920 :             break;
     384             : 
     385             :         case DO_NOT_RESET_PARA_ATTRS_FOR_NUM_FONT:
     386        1090 :             mbDoNotResetParaAttrsForNumFont = value;
     387        1090 :             break;
     388             :         case MATH_BASELINE_ALIGNMENT:
     389        1835 :             mbMathBaselineAlignment  = value;
     390        1835 :             break;
     391             :         case STYLES_NODEFAULT:
     392         983 :             mbStylesNoDefault  = value;
     393         983 :             break;
     394             :         case FLOATTABLE_NOMARGINS:
     395         988 :             mbFloattableNomargins = value;
     396         988 :             break;
     397             :         case EMBED_FONTS:
     398          79 :             mEmbedFonts = value;
     399          79 :             break;
     400             :         case EMBED_SYSTEM_FONTS:
     401         226 :             mEmbedSystemFonts = value;
     402         226 :             break;
     403             :         default:
     404             :             OSL_FAIL("Invalid setting id");
     405             :     }
     406       51403 : }
     407             : 
     408             : const i18n::ForbiddenCharacters*
     409       24695 :     SwDoc::getForbiddenCharacters(/*[in]*/ sal_uInt16 nLang, /*[in]*/ bool bLocaleData ) const
     410             : {
     411       24695 :     const i18n::ForbiddenCharacters* pRet = 0;
     412       24695 :     if( mxForbiddenCharsTable.is() )
     413       24695 :         pRet = mxForbiddenCharsTable->GetForbiddenCharacters( nLang, false );
     414       24695 :     if( bLocaleData && !pRet && g_pBreakIt )
     415       23082 :         pRet = &g_pBreakIt->GetForbidden( (LanguageType)nLang );
     416       24695 :     return pRet;
     417             : }
     418             : 
     419          60 : void SwDoc::setForbiddenCharacters(/*[in]*/ sal_uInt16 nLang,
     420             :                                    /*[in]*/ const com::sun::star::i18n::ForbiddenCharacters& rFChars )
     421             : {
     422          60 :     if( !mxForbiddenCharsTable.is() )
     423             :     {
     424          60 :         mxForbiddenCharsTable = new SvxForbiddenCharactersTable( ::comphelper::getProcessComponentContext() );
     425             :     }
     426          60 :     mxForbiddenCharsTable->SetForbiddenCharacters( nLang, rFChars );
     427          60 :     if( mpDrawModel )
     428             :     {
     429           0 :         mpDrawModel->SetForbiddenCharsTable( mxForbiddenCharsTable );
     430           0 :         if( !mbInReading )
     431           0 :             mpDrawModel->ReformatAllTextObjects();
     432             :     }
     433             : 
     434          60 :     SwRootFrm* pTmpRoot = GetCurrentLayout();
     435          60 :     if( pTmpRoot && !mbInReading )
     436             :     {
     437           0 :         pTmpRoot->StartAllAction();
     438           0 :         std::set<SwRootFrm*> aAllLayouts = GetAllLayouts();
     439           0 :         std::for_each( aAllLayouts.begin(), aAllLayouts.end(), std::bind2nd(std::mem_fun(&SwRootFrm::InvalidateAllCntnt), INV_SIZE));
     440           0 :         pTmpRoot->EndAllAction();
     441             :     }
     442          60 :     SetModified();
     443          60 : }
     444             : 
     445        1931 : rtl::Reference<SvxForbiddenCharactersTable>& SwDoc::getForbiddenCharacterTable()
     446             : {
     447        1931 :     if( !mxForbiddenCharsTable.is() )
     448             :     {
     449        1714 :         mxForbiddenCharsTable = new SvxForbiddenCharactersTable( ::comphelper::getProcessComponentContext() );
     450             :     }
     451        1931 :     return mxForbiddenCharsTable;
     452             : }
     453             : 
     454           0 : const rtl::Reference<SvxForbiddenCharactersTable>& SwDoc::getForbiddenCharacterTable() const
     455             : {
     456           0 :     return mxForbiddenCharsTable;
     457             : }
     458             : 
     459        1395 : sal_uInt16 SwDoc::getLinkUpdateMode( /*[in]*/bool bGlobalSettings ) const
     460             : {
     461        1395 :     sal_uInt16 nRet = mnLinkUpdMode;
     462        1395 :     if( bGlobalSettings && GLOBALSETTING == nRet )
     463        1268 :         nRet = SW_MOD()->GetLinkUpdMode(get(IDocumentSettingAccess::HTML_MODE));
     464        1395 :     return nRet;
     465             : }
     466             : 
     467        1848 : void SwDoc::setLinkUpdateMode( /*[in]*/sal_uInt16 eMode )
     468             : {
     469        1848 :     mnLinkUpdMode = eMode;
     470        1848 : }
     471             : 
     472          40 : sal_uInt32 SwDoc::getRsid() const
     473             : {
     474          40 :     return mnRsid;
     475             : }
     476             : 
     477         113 : void SwDoc::setRsid( sal_uInt32 nVal )
     478             : {
     479         113 :     static bool bHack = (getenv("LIBO_ONEWAY_STABLE_ODF_EXPORT") != NULL);
     480             : 
     481         113 :     sal_uInt32 nIncrease = 0;
     482         113 :     if (!bHack)
     483             :     {
     484             :         // Increase the rsid with a random number smaller than 2^17. This way we
     485             :         // expect to be able to edit a document 2^12 times before rsid overflows.
     486         113 :         static rtlRandomPool aPool = rtl_random_createPool();
     487         113 :         rtl_random_getBytes( aPool, &nIncrease, sizeof ( nIncrease ) );
     488         113 :         nIncrease &= ( 1<<17 ) - 1;
     489         113 :         nIncrease++; // make sure the new rsid is not the same
     490             :     }
     491         113 :     mnRsid = nVal + nIncrease;
     492         113 : }
     493             : 
     494          20 : sal_uInt32 SwDoc::getRsidRoot() const
     495             : {
     496          20 :     return mnRsidRoot;
     497             : }
     498             : 
     499          93 : void SwDoc::setRsidRoot( sal_uInt32 nVal )
     500             : {
     501          93 :     mnRsidRoot = nVal;
     502          93 : }
     503             : 
     504         450 : SwFldUpdateFlags SwDoc::getFieldUpdateFlags( /*[in]*/bool bGlobalSettings ) const
     505             : {
     506         450 :     SwFldUpdateFlags eRet = meFldUpdMode;
     507         450 :     if( bGlobalSettings && AUTOUPD_GLOBALSETTING == eRet )
     508         301 :         eRet = SW_MOD()->GetFldUpdateFlags(get(IDocumentSettingAccess::HTML_MODE));
     509         450 :     return eRet;
     510             : }
     511             : 
     512        1961 : void SwDoc::setFieldUpdateFlags(/*[in]*/SwFldUpdateFlags eMode )
     513             : {
     514        1961 :     meFldUpdMode = eMode;
     515        1961 : }
     516             : 
     517       31216 : SwCharCompressType SwDoc::getCharacterCompressionType() const
     518             : {
     519       31216 :     return meChrCmprType;
     520             : }
     521             : 
     522        1920 : void SwDoc::setCharacterCompressionType( /*[in]*/SwCharCompressType n )
     523             : {
     524        1920 :     if( meChrCmprType != n )
     525             :     {
     526           5 :         meChrCmprType = n;
     527           5 :         if( mpDrawModel )
     528             :         {
     529           0 :             mpDrawModel->SetCharCompressType( static_cast<sal_uInt16>(n) );
     530           0 :             if( !mbInReading )
     531           0 :                 mpDrawModel->ReformatAllTextObjects();
     532             :         }
     533             : 
     534           5 :         SwRootFrm* pTmpRoot = GetCurrentLayout();
     535           5 :         if( pTmpRoot && !mbInReading )
     536             :         {
     537           0 :             pTmpRoot->StartAllAction();
     538           0 :             std::set<SwRootFrm*> aAllLayouts = GetAllLayouts();
     539           0 :             std::for_each( aAllLayouts.begin(), aAllLayouts.end(), std::bind2nd(std::mem_fun(&SwRootFrm::InvalidateAllCntnt), INV_SIZE));
     540           0 :             pTmpRoot->EndAllAction();
     541             :         }
     542           5 :         SetModified();
     543             :     }
     544        1920 : }
     545             : 
     546             : /* IDocumentDeviceAccess */
     547       16534 : SfxPrinter* SwDoc::getPrinter(/*[in]*/ bool bCreate ) const
     548             : {
     549       16534 :     SfxPrinter* pRet = 0;
     550       16534 :     if ( !bCreate || mpPrt )
     551       16527 :         pRet = mpPrt;
     552             :     else
     553           7 :         pRet = &CreatePrinter_();
     554             : 
     555       16534 :     return pRet;
     556             : }
     557             : 
     558          14 : void SwDoc::setPrinter(/*[in]*/ SfxPrinter *pP,/*[in]*/ bool bDeleteOld,/*[in]*/ bool bCallPrtDataChanged )
     559             : {
     560          14 :     if ( pP != mpPrt )
     561             :     {
     562          13 :         if ( bDeleteOld )
     563          13 :             delete mpPrt;
     564          13 :         mpPrt = pP;
     565             : 
     566             :         // our printer should always use TWIP. Don't rely on this being set in SwViewShell::InitPrt, there
     567             :         // are situations where this isn't called.
     568             :         // #i108712# / 2010-02-26 / frank.schoenheit@sun.com
     569          13 :         if ( mpPrt )
     570             :         {
     571          13 :             MapMode aMapMode( mpPrt->GetMapMode() );
     572          13 :             aMapMode.SetMapUnit( MAP_TWIP );
     573          13 :             mpPrt->SetMapMode( aMapMode );
     574             :         }
     575             : 
     576          13 :         if ( mpDrawModel && !get( IDocumentSettingAccess::USE_VIRTUAL_DEVICE ) )
     577           4 :             mpDrawModel->SetRefDevice( mpPrt );
     578             :     }
     579             : 
     580          28 :     if ( bCallPrtDataChanged &&
     581             :          // #i41075# Do not call PrtDataChanged() if we do not
     582             :          // use the printer for formatting:
     583          14 :          !get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE) )
     584           6 :         PrtDataChanged();
     585          14 : }
     586             : 
     587     1342524 : VirtualDevice* SwDoc::getVirtualDevice(/*[in]*/ bool bCreate ) const
     588             : {
     589     1342524 :     VirtualDevice* pRet = 0;
     590     1342524 :     if ( !bCreate || mpVirDev )
     591     1340680 :         pRet = mpVirDev;
     592             :     else
     593        1844 :         pRet = &CreateVirtualDevice_();
     594             : 
     595     1342524 :     return pRet;
     596             : }
     597             : 
     598        1844 : void SwDoc::setVirtualDevice(/*[in]*/ VirtualDevice* pVd,/*[in]*/ bool bDeleteOld, /*[in]*/ bool )
     599             : {
     600        1844 :     if ( mpVirDev != pVd )
     601             :     {
     602        1844 :         if ( bDeleteOld )
     603        1844 :             delete mpVirDev;
     604        1844 :         mpVirDev = pVd;
     605             : 
     606        1844 :         if ( mpDrawModel && get( IDocumentSettingAccess::USE_VIRTUAL_DEVICE ) )
     607         108 :             mpDrawModel->SetRefDevice( mpVirDev );
     608             :     }
     609        1844 : }
     610             : 
     611     1342925 : OutputDevice* SwDoc::getReferenceDevice(/*[in]*/ bool bCreate ) const
     612             : {
     613     1342925 :     OutputDevice* pRet = 0;
     614     1342925 :     if ( !get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE) )
     615             :     {
     616         401 :         pRet = getPrinter( bCreate );
     617             : 
     618         401 :         if ( bCreate && !mpPrt->IsValid() )
     619             :         {
     620           0 :             pRet = getVirtualDevice( true );
     621             :         }
     622             :     }
     623             :     else
     624             :     {
     625     1342524 :         pRet = getVirtualDevice( bCreate );
     626             :     }
     627             : 
     628     1342925 :     return pRet;
     629             : }
     630             : 
     631         113 : void SwDoc::setReferenceDeviceType(/*[in]*/ bool bNewVirtual,/*[in]*/ bool bNewHiRes )
     632             : {
     633         221 :     if ( get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE) != bNewVirtual ||
     634         108 :          get(IDocumentSettingAccess::USE_HIRES_VIRTUAL_DEVICE) != bNewHiRes )
     635             :     {
     636           5 :         if ( bNewVirtual )
     637             :         {
     638           0 :             VirtualDevice* pMyVirDev = getVirtualDevice( true );
     639           0 :             if ( !bNewHiRes )
     640           0 :                 pMyVirDev->SetReferenceDevice( VirtualDevice::REFDEV_MODE06 );
     641             :             else
     642           0 :                 pMyVirDev->SetReferenceDevice( VirtualDevice::REFDEV_MODE_MSO1 );
     643             : 
     644           0 :             if( mpDrawModel )
     645           0 :                 mpDrawModel->SetRefDevice( pMyVirDev );
     646             :         }
     647             :         else
     648             :         {
     649             :             // #i41075#
     650             :             // We have to take care that a printer exists before calling
     651             :             // PrtDataChanged() in order to prevent that PrtDataChanged()
     652             :             // triggers this funny situation:
     653             :             // getReferenceDevice()->getPrinter()->CreatePrinter_()
     654             :             // ->setPrinter()-> PrtDataChanged()
     655           5 :             SfxPrinter* pPrinter = getPrinter( true );
     656           5 :             if( mpDrawModel )
     657           0 :                 mpDrawModel->SetRefDevice( pPrinter );
     658             :         }
     659             : 
     660           5 :         set(IDocumentSettingAccess::USE_VIRTUAL_DEVICE, bNewVirtual );
     661           5 :         set(IDocumentSettingAccess::USE_HIRES_VIRTUAL_DEVICE, bNewHiRes );
     662           5 :         PrtDataChanged();
     663           5 :         SetModified();
     664             :     }
     665         113 : }
     666             : 
     667           0 : const JobSetup* SwDoc::getJobsetup() const
     668             : {
     669           0 :     return mpPrt ? &mpPrt->GetJobSetup() : 0;
     670             : }
     671             : 
     672           0 : void SwDoc::setJobsetup(/*[in]*/ const JobSetup &rJobSetup )
     673             : {
     674           0 :     bool bCheckPageDescs = 0 == mpPrt;
     675           0 :     bool bDataChanged = false;
     676             : 
     677           0 :     if ( mpPrt )
     678             :     {
     679           0 :         if ( mpPrt->GetName() == rJobSetup.GetPrinterName() )
     680             :         {
     681           0 :             if ( mpPrt->GetJobSetup() != rJobSetup )
     682             :             {
     683           0 :                 mpPrt->SetJobSetup( rJobSetup );
     684           0 :                 bDataChanged = true;
     685             :             }
     686             :         }
     687             :         else
     688           0 :             delete mpPrt, mpPrt = 0;
     689             :     }
     690             : 
     691           0 :     if( !mpPrt )
     692             :     {
     693             :         //The ItemSet is deleted by Sfx!
     694           0 :         SfxItemSet *pSet = new SfxItemSet( GetAttrPool(),
     695             :                         FN_PARAM_ADDPRINTER, FN_PARAM_ADDPRINTER,
     696             :                         SID_HTML_MODE,  SID_HTML_MODE,
     697             :                         SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
     698             :                         SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
     699           0 :                         0 );
     700           0 :         SfxPrinter *p = new SfxPrinter( pSet, rJobSetup );
     701           0 :         if ( bCheckPageDescs )
     702           0 :             setPrinter( p, true, true );
     703             :         else
     704             :         {
     705           0 :             mpPrt = p;
     706           0 :             bDataChanged = true;
     707             :         }
     708             :     }
     709           0 :     if ( bDataChanged && !get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE) )
     710           0 :         PrtDataChanged();
     711           0 : }
     712             : 
     713        2411 : const SwPrintData & SwDoc::getPrintData() const
     714             : {
     715        2411 :     if(!mpPrtData)
     716             :     {
     717         112 :         SwDoc * pThis = const_cast< SwDoc * >(this);
     718         112 :         pThis->mpPrtData = new SwPrintData;
     719             : 
     720             :         // SwPrintData should be initialized from the configuration,
     721             :         // the respective config item is implememted by SwPrintOptions which
     722             :         // is also derived from SwPrintData
     723         112 :         const SwDocShell *pDocSh = GetDocShell();
     724             :         OSL_ENSURE( pDocSh, "pDocSh is 0, can't determine if this is a WebDoc or not" );
     725         112 :         bool bWeb = 0 != dynamic_cast< const SwWebDocShell * >(pDocSh);
     726         112 :         SwPrintOptions aPrintOptions( bWeb );
     727         112 :         *pThis->mpPrtData = aPrintOptions;
     728             :     }
     729        2411 :     return *mpPrtData;
     730             : }
     731             : 
     732        1736 : void SwDoc::setPrintData(/*[in]*/ const SwPrintData& rPrtData )
     733             : {
     734        1736 :     if(!mpPrtData)
     735        1736 :         mpPrtData = new SwPrintData;
     736        1736 :     *mpPrtData = rPrtData;
     737        1736 : }
     738             : 
     739             : /* Implementations the next Interface here */
     740             : 
     741             : /*
     742             :  * Document editing (Doc-SS) to fill the document
     743             :  * by the RTF parser and for the EditShell.
     744             :  */
     745         336 : void SwDoc::ChgDBData(const SwDBData& rNewData)
     746             : {
     747         336 :     if( rNewData != maDBData )
     748             :     {
     749          12 :         maDBData = rNewData;
     750          12 :         SetModified();
     751             :     }
     752         336 :     GetSysFldType(RES_DBNAMEFLD)->UpdateFlds();
     753         336 : }
     754             : 
     755         581 : bool SwDoc::SplitNode( const SwPosition &rPos, bool bChkTableStart )
     756             : {
     757         581 :     SwCntntNode *pNode = rPos.nNode.GetNode().GetCntntNode();
     758         581 :     if(0 == pNode)
     759           0 :         return false;
     760             : 
     761             :     {
     762             :         // BUG 26675: Send DataChanged before deleting, so that we notice which objects are in scope.
     763             :         //            After that they can be before/after the position.
     764         581 :         SwDataChanged aTmp( this, rPos );
     765             :     }
     766             : 
     767         581 :     SwUndoSplitNode* pUndo = 0;
     768         581 :     if (GetIDocumentUndoRedo().DoesUndo())
     769             :     {
     770         297 :         GetIDocumentUndoRedo().ClearRedo();
     771             :         // insert the Undo object (currently only for TextNode)
     772         297 :         if( pNode->IsTxtNode() )
     773             :         {
     774         297 :             pUndo = new SwUndoSplitNode( this, rPos, bChkTableStart );
     775         297 :             GetIDocumentUndoRedo().AppendUndo(pUndo);
     776             :         }
     777             :     }
     778             : 
     779             :     // Update the rsid of the old and the new node unless
     780             :     // the old node is split at the beginning or at the end
     781         581 :     SwTxtNode *pTxtNode =  rPos.nNode.GetNode().GetTxtNode();
     782         581 :     const sal_Int32 nPos = rPos.nContent.GetIndex();
     783         581 :     if( pTxtNode && nPos && nPos != pTxtNode->Len() )
     784             :     {
     785          41 :         UpdateParRsid( pTxtNode );
     786             :     }
     787             : 
     788             :     //JP 28.01.97: Special case for SplitNode at table start:
     789             :     //             If it is at the beginning of a Doc/Fly/Footer/... or right at after a table
     790             :     //             then insert a paragraph before it.
     791         581 :     if( bChkTableStart && !rPos.nContent.GetIndex() && pNode->IsTxtNode() )
     792             :     {
     793           1 :         sal_uLong nPrevPos = rPos.nNode.GetIndex() - 1;
     794             :         const SwTableNode* pTblNd;
     795           1 :         const SwNode* pNd = GetNodes()[ nPrevPos ];
     796           3 :         if( pNd->IsStartNode() &&
     797           1 :             SwTableBoxStartNode == ((SwStartNode*)pNd)->GetStartNodeType() &&
     798           1 :             0 != ( pTblNd = GetNodes()[ --nPrevPos ]->GetTableNode() ) &&
     799           0 :             ((( pNd = GetNodes()[ --nPrevPos ])->IsStartNode() &&
     800           0 :                SwTableBoxStartNode != ((SwStartNode*)pNd)->GetStartNodeType() )
     801           0 :                || ( pNd->IsEndNode() && pNd->StartOfSectionNode()->IsTableNode() )
     802           0 :                || pNd->IsCntntNode() ))
     803             :         {
     804           0 :             if( pNd->IsCntntNode() )
     805             :             {
     806             :                 //JP 30.04.99 Bug 65660:
     807             :                 // There are no page breaks outside of the normal body area,
     808             :                 // so this is not a valid condition to insert a paragraph.
     809           0 :                 if( nPrevPos < GetNodes().GetEndOfExtras().GetIndex() )
     810           0 :                     pNd = 0;
     811             :                 else
     812             :                 {
     813             :                     // Only if the table has page breaks!
     814           0 :                     const SwFrmFmt* pFrmFmt = pTblNd->GetTable().GetFrmFmt();
     815           0 :                     if( SFX_ITEM_SET != pFrmFmt->GetItemState(RES_PAGEDESC, sal_False) &&
     816           0 :                         SFX_ITEM_SET != pFrmFmt->GetItemState( RES_BREAK, sal_False ) )
     817           0 :                         pNd = 0;
     818             :                 }
     819             :             }
     820             : 
     821           0 :             if( pNd )
     822             :             {
     823           0 :                 SwTxtNode* pTxtNd = GetNodes().MakeTxtNode(
     824             :                                         SwNodeIndex( *pTblNd ),
     825           0 :                                         GetTxtCollFromPool( RES_POOLCOLL_TEXT ));
     826           0 :                 if( pTxtNd )
     827             :                 {
     828           0 :                     ((SwPosition&)rPos).nNode = pTblNd->GetIndex()-1;
     829           0 :                     ((SwPosition&)rPos).nContent.Assign( pTxtNd, 0 );
     830             : 
     831             :                     // only add page breaks/styles to the body area
     832           0 :                     if( nPrevPos > GetNodes().GetEndOfExtras().GetIndex() )
     833             :                     {
     834           0 :                         SwFrmFmt* pFrmFmt = pTblNd->GetTable().GetFrmFmt();
     835             :                         const SfxPoolItem *pItem;
     836           0 :                         if( SFX_ITEM_SET == pFrmFmt->GetItemState( RES_PAGEDESC,
     837           0 :                             sal_False, &pItem ) )
     838             :                         {
     839           0 :                             pTxtNd->SetAttr( *pItem );
     840           0 :                             pFrmFmt->ResetFmtAttr( RES_PAGEDESC );
     841             :                         }
     842           0 :                         if( SFX_ITEM_SET == pFrmFmt->GetItemState( RES_BREAK,
     843           0 :                             sal_False, &pItem ) )
     844             :                         {
     845           0 :                             pTxtNd->SetAttr( *pItem );
     846           0 :                             pFrmFmt->ResetFmtAttr( RES_BREAK );
     847             :                         }
     848             :                     }
     849             : 
     850           0 :                     if( pUndo )
     851           0 :                         pUndo->SetTblFlag();
     852           0 :                     SetModified();
     853           0 :                     return true;
     854             :                 }
     855             :             }
     856             :         }
     857             :     }
     858             : 
     859         581 :     std::vector<sal_uLong> aBkmkArr;
     860             :     _SaveCntntIdx( this, rPos.nNode.GetIndex(), rPos.nContent.GetIndex(),
     861         581 :                     aBkmkArr, SAVEFLY_SPLIT );
     862             :     // FIXME: only SwTxtNode has a valid implementation of SplitCntntNode!
     863             :     OSL_ENSURE(pNode->IsTxtNode(), "splitting non-text node?");
     864         581 :     pNode = pNode->SplitCntntNode( rPos );
     865         581 :     if (pNode)
     866             :     {
     867             :         // move all bookmarks, TOXMarks, FlyAtCnt
     868         581 :         if( !aBkmkArr.empty() )
     869          32 :             _RestoreCntntIdx( this, aBkmkArr, rPos.nNode.GetIndex()-1, 0, true );
     870             : 
     871             :         // To-Do - add 'SwExtraRedlineTbl' also ?
     872         581 :         if( IsRedlineOn() || (!IsIgnoreRedline() && !mpRedlineTbl->empty() ))
     873             :         {
     874           0 :             SwPaM aPam( rPos );
     875           0 :             aPam.SetMark();
     876           0 :             aPam.Move( fnMoveBackward );
     877           0 :             if( IsRedlineOn() )
     878           0 :                 AppendRedline( new SwRangeRedline( nsRedlineType_t::REDLINE_INSERT, aPam ), true);
     879             :             else
     880           0 :                 SplitRedline( aPam );
     881             :         }
     882             :     }
     883             : 
     884         581 :     SetModified();
     885         581 :     return true;
     886             : }
     887             : 
     888       25604 : bool SwDoc::AppendTxtNode( SwPosition& rPos )
     889             : {
     890             :     // create new node before EndOfContent
     891       25604 :     SwTxtNode * pCurNode = rPos.nNode.GetNode().GetTxtNode();
     892       25604 :     if( !pCurNode )
     893             :     {
     894             :         // so then one can be created!
     895         108 :         SwNodeIndex aIdx( rPos.nNode, 1 );
     896         108 :         pCurNode = GetNodes().MakeTxtNode( aIdx,
     897         216 :                         GetTxtCollFromPool( RES_POOLCOLL_STANDARD ));
     898             :     }
     899             :     else
     900       25496 :         pCurNode = (SwTxtNode*)pCurNode->AppendNode( rPos );
     901             : 
     902       25604 :     rPos.nNode++;
     903       25604 :     rPos.nContent.Assign( pCurNode, 0 );
     904             : 
     905       25604 :     if (GetIDocumentUndoRedo().DoesUndo())
     906             :     {
     907        1678 :         GetIDocumentUndoRedo().AppendUndo( new SwUndoInsert( rPos.nNode ) );
     908             :     }
     909             : 
     910             :     // To-Do - add 'SwExtraRedlineTbl' also ?
     911       25604 :     if( IsRedlineOn() || (!IsIgnoreRedline() && !mpRedlineTbl->empty() ))
     912             :     {
     913         308 :         SwPaM aPam( rPos );
     914         308 :         aPam.SetMark();
     915         308 :         aPam.Move( fnMoveBackward );
     916         308 :         if( IsRedlineOn() )
     917          12 :             AppendRedline( new SwRangeRedline( nsRedlineType_t::REDLINE_INSERT, aPam ), true);
     918             :         else
     919         296 :             SplitRedline( aPam );
     920             :     }
     921             : 
     922       25604 :     SetModified();
     923       25604 :     return true;
     924             : }
     925             : 
     926       95157 : bool SwDoc::InsertString( const SwPaM &rRg, const OUString &rStr,
     927             :         const enum InsertFlags nInsertMode )
     928             : {
     929             :     // fetching DoesUndo is surprisingly expensive
     930       95157 :     bool bDoesUndo = GetIDocumentUndoRedo().DoesUndo();
     931       95157 :     if (bDoesUndo)
     932        8066 :         GetIDocumentUndoRedo().ClearRedo(); // AppendUndo not always called!
     933             : 
     934       95157 :     const SwPosition& rPos = *rRg.GetPoint();
     935             : 
     936       95157 :     if( mpACEWord )                  // add to auto correction
     937             :     {
     938           0 :         if( 1 == rStr.getLength() && mpACEWord->IsDeleted() )
     939             :         {
     940           0 :             mpACEWord->CheckChar( rPos, rStr[ 0 ] );
     941             :         }
     942           0 :         delete mpACEWord, mpACEWord = 0;
     943             :     }
     944             : 
     945       95157 :     SwTxtNode *const pNode = rPos.nNode.GetNode().GetTxtNode();
     946       95157 :     if(!pNode)
     947        1369 :         return false;
     948             : 
     949       93788 :     SwDataChanged aTmp( rRg );
     950             : 
     951       93788 :     if (!bDoesUndo || !GetIDocumentUndoRedo().DoesGroupUndo())
     952             :     {
     953       93698 :         OUString const ins(pNode->InsertText(rStr, rPos.nContent, nInsertMode));
     954       93698 :         if (bDoesUndo)
     955             :         {
     956             :             SwUndoInsert * const pUndo( new SwUndoInsert(rPos.nNode,
     957        7976 :                     rPos.nContent.GetIndex(), ins.getLength(), nInsertMode));
     958        7976 :             GetIDocumentUndoRedo().AppendUndo(pUndo);
     959       93698 :         }
     960             :     }
     961             :     else
     962             :     {   // if Undo and grouping is enabled, everything changes!
     963          90 :         SwUndoInsert * pUndo = NULL;
     964             : 
     965             :         // don't group the start if hints at the start should be expanded
     966          90 :         if (!(nInsertMode & IDocumentContentOperations::INS_FORCEHINTEXPAND))
     967             :         {
     968          89 :             SwUndo *const pLastUndo = GetUndoManager().GetLastUndo();
     969             :             SwUndoInsert *const pUndoInsert(
     970          89 :                 dynamic_cast<SwUndoInsert *>(pLastUndo) );
     971          89 :             if (pUndoInsert && pUndoInsert->CanGrouping(rPos))
     972             :             {
     973          47 :                 pUndo = pUndoInsert;
     974             :             }
     975             :         }
     976             : 
     977          90 :         CharClass const& rCC = GetAppCharClass();
     978          90 :         sal_Int32 nInsPos = rPos.nContent.GetIndex();
     979             : 
     980          90 :         if (!pUndo)
     981             :         {
     982             :             pUndo = new SwUndoInsert( rPos.nNode, nInsPos, 0, nInsertMode,
     983          43 :                             !rCC.isLetterNumeric( rStr, 0 ) );
     984          43 :             GetIDocumentUndoRedo().AppendUndo( pUndo );
     985             :         }
     986             : 
     987          90 :         OUString const ins(pNode->InsertText(rStr, rPos.nContent, nInsertMode));
     988             : 
     989         328 :         for (sal_Int32 i = 0; i < ins.getLength(); ++i)
     990             :         {
     991         238 :             nInsPos++;
     992             :             // if CanGrouping() returns true, everything has already been done
     993         238 :             if (!pUndo->CanGrouping(ins[i]))
     994             :             {
     995             :                 pUndo = new SwUndoInsert(rPos.nNode, nInsPos, 1, nInsertMode,
     996          27 :                             !rCC.isLetterNumeric(ins, i));
     997          27 :                 GetIDocumentUndoRedo().AppendUndo( pUndo );
     998             :             }
     999          90 :         }
    1000             :     }
    1001             : 
    1002             :     // To-Do - add 'SwExtraRedlineTbl' also ?
    1003       93788 :     if( IsRedlineOn() || (!IsIgnoreRedline() && !mpRedlineTbl->empty() ))
    1004             :     {
    1005             :         SwPaM aPam( rPos.nNode, aTmp.GetCntnt(),
    1006        1194 :                     rPos.nNode, rPos.nContent.GetIndex());
    1007        1194 :         if( IsRedlineOn() )
    1008             :         {
    1009             :             AppendRedline(
    1010         669 :                 new SwRangeRedline( nsRedlineType_t::REDLINE_INSERT, aPam ), true);
    1011             :         }
    1012             :         else
    1013             :         {
    1014         525 :             SplitRedline( aPam );
    1015        1194 :         }
    1016             :     }
    1017             : 
    1018       93788 :     SetModified();
    1019       93788 :     return true;
    1020             : }
    1021             : 
    1022         709 : SwFlyFrmFmt* SwDoc::_InsNoTxtNode( const SwPosition& rPos, SwNoTxtNode* pNode,
    1023             :                                     const SfxItemSet* pFlyAttrSet,
    1024             :                                     const SfxItemSet* pGrfAttrSet,
    1025             :                                     SwFrmFmt* pFrmFmt)
    1026             : {
    1027         709 :     SwFlyFrmFmt *pFmt = 0;
    1028         709 :     if( pNode )
    1029             :     {
    1030             :         pFmt = _MakeFlySection( rPos, *pNode, FLY_AT_PARA,
    1031         709 :                                 pFlyAttrSet, pFrmFmt );
    1032         709 :         if( pGrfAttrSet )
    1033         338 :             pNode->SetAttr( *pGrfAttrSet );
    1034             :     }
    1035         709 :     return pFmt;
    1036             : }
    1037             : 
    1038         191 : SwFlyFrmFmt* SwDoc::Insert( const SwPaM &rRg,
    1039             :                             const OUString& rGrfName,
    1040             :                             const OUString& rFltName,
    1041             :                             const Graphic* pGraphic,
    1042             :                             const SfxItemSet* pFlyAttrSet,
    1043             :                             const SfxItemSet* pGrfAttrSet,
    1044             :                             SwFrmFmt* pFrmFmt )
    1045             : {
    1046         191 :     if( !pFrmFmt )
    1047         191 :         pFrmFmt = GetFrmFmtFromPool( RES_POOLFRM_GRAPHIC );
    1048         191 :     SwGrfNode* pSwGrfNode = GetNodes().MakeGrfNode(
    1049         191 :                             SwNodeIndex( GetNodes().GetEndOfAutotext() ),
    1050             :                             rGrfName, rFltName, pGraphic,
    1051         573 :                             mpDfltGrfFmtColl );
    1052         191 :     SwFlyFrmFmt* pSwFlyFrmFmt = _InsNoTxtNode( *rRg.GetPoint(), pSwGrfNode,
    1053         191 :                             pFlyAttrSet, pGrfAttrSet, pFrmFmt );
    1054         191 :     pSwGrfNode->onGraphicChanged();
    1055         191 :     return pSwFlyFrmFmt;
    1056             : }
    1057             : 
    1058         135 : SwFlyFrmFmt* SwDoc::Insert( const SwPaM &rRg, const GraphicObject& rGrfObj,
    1059             :                             const SfxItemSet* pFlyAttrSet,
    1060             :                             const SfxItemSet* pGrfAttrSet,
    1061             :                             SwFrmFmt* pFrmFmt )
    1062             : {
    1063         135 :     if( !pFrmFmt )
    1064           0 :         pFrmFmt = GetFrmFmtFromPool( RES_POOLFRM_GRAPHIC );
    1065         135 :     SwGrfNode* pSwGrfNode = GetNodes().MakeGrfNode(
    1066         135 :                             SwNodeIndex( GetNodes().GetEndOfAutotext() ),
    1067         405 :                             rGrfObj, mpDfltGrfFmtColl );
    1068         135 :     SwFlyFrmFmt* pSwFlyFrmFmt = _InsNoTxtNode( *rRg.GetPoint(), pSwGrfNode,
    1069         135 :                             pFlyAttrSet, pGrfAttrSet, pFrmFmt );
    1070         135 :     pSwGrfNode->onGraphicChanged();
    1071         135 :     return pSwFlyFrmFmt;
    1072             : }
    1073             : 
    1074         339 : SwFlyFrmFmt* SwDoc::Insert(const SwPaM &rRg, const svt::EmbeddedObjectRef& xObj,
    1075             :                         const SfxItemSet* pFlyAttrSet,
    1076             :                         const SfxItemSet* pGrfAttrSet,
    1077             :                         SwFrmFmt* pFrmFmt )
    1078             : {
    1079         339 :     if( !pFrmFmt )
    1080             :     {
    1081         339 :         sal_uInt16 nId = RES_POOLFRM_OLE;
    1082         339 :         SvGlobalName aClassName( xObj->getClassID() );
    1083         339 :         if (SotExchange::IsMath(aClassName))
    1084         266 :             nId = RES_POOLFRM_FORMEL;
    1085             : 
    1086         339 :         pFrmFmt = GetFrmFmtFromPool( nId );
    1087             :     }
    1088         678 :     return _InsNoTxtNode( *rRg.GetPoint(), GetNodes().MakeOLENode(
    1089         339 :                             SwNodeIndex( GetNodes().GetEndOfAutotext() ),
    1090             :                             xObj,
    1091        1356 :                             mpDfltGrfFmtColl ),
    1092             :                             pFlyAttrSet, pGrfAttrSet,
    1093         678 :                             pFrmFmt );
    1094             : }
    1095             : 
    1096          44 : SwFlyFrmFmt* SwDoc::InsertOLE(const SwPaM &rRg, const OUString& rObjName,
    1097             :                         sal_Int64 nAspect,
    1098             :                         const SfxItemSet* pFlyAttrSet,
    1099             :                         const SfxItemSet* pGrfAttrSet,
    1100             :                         SwFrmFmt* pFrmFmt )
    1101             : {
    1102          44 :     if( !pFrmFmt )
    1103          44 :         pFrmFmt = GetFrmFmtFromPool( RES_POOLFRM_OLE );
    1104             : 
    1105          44 :     return _InsNoTxtNode( *rRg.GetPoint(),
    1106          44 :                             GetNodes().MakeOLENode(
    1107          44 :                                 SwNodeIndex( GetNodes().GetEndOfAutotext() ),
    1108             :                                 rObjName,
    1109             :                                 nAspect,
    1110             :                                 mpDfltGrfFmtColl,
    1111         176 :                                 0 ),
    1112             :                             pFlyAttrSet, pGrfAttrSet,
    1113          88 :                             pFrmFmt );
    1114             : }
    1115             : 
    1116             : /// @returns the field type of the Doc
    1117       16854 : SwFieldType *SwDoc::GetSysFldType( const sal_uInt16 eWhich ) const
    1118             : {
    1119      147652 :     for( sal_uInt16 i = 0; i < INIT_FLDTYPES; ++i )
    1120      147652 :         if( eWhich == (*mpFldTypes)[i]->Which() )
    1121       16854 :             return (*mpFldTypes)[i];
    1122           0 :     return 0;
    1123             : }
    1124             : 
    1125         112 : void SwDoc::SetDocStat( const SwDocStat& rStat )
    1126             : {
    1127         112 :     *mpDocStat = rStat;
    1128         112 : }
    1129             : 
    1130        6030 : const SwDocStat& SwDoc::GetDocStat() const
    1131             : {
    1132        6030 :     return *mpDocStat;
    1133             : }
    1134             : 
    1135         752 : const SwDocStat& SwDoc::GetUpdatedDocStat( bool bCompleteAsync, bool bFields )
    1136             : {
    1137         752 :     if( mpDocStat->bModified )
    1138             :     {
    1139         733 :         UpdateDocStat( bCompleteAsync, bFields );
    1140             :     }
    1141         752 :     return *mpDocStat;
    1142             : }
    1143             : 
    1144             : struct _PostItFld : public _SetGetExpFld
    1145             : {
    1146           0 :     _PostItFld( const SwNodeIndex& rNdIdx, const SwTxtFld* pFld,  const SwIndex* pIdx = 0 )
    1147           0 :         : _SetGetExpFld( rNdIdx, pFld, pIdx ) {}
    1148             : 
    1149             :     sal_uInt16 GetPageNo( const StringRangeEnumerator &rRangeEnum,
    1150             :             const std::set< sal_Int32 > &rPossiblePages,
    1151             :             sal_uInt16& rVirtPgNo, sal_uInt16& rLineNo );
    1152             : 
    1153           0 :     SwPostItField* GetPostIt() const
    1154             :     {
    1155           0 :         return (SwPostItField*) GetTxtFld()->GetFmtFld().GetField();
    1156             :     }
    1157             : };
    1158             : 
    1159           0 : sal_uInt16 _PostItFld::GetPageNo(
    1160             :     const StringRangeEnumerator &rRangeEnum,
    1161             :     const std::set< sal_Int32 > &rPossiblePages,
    1162             :     /* out */ sal_uInt16& rVirtPgNo, /* out */ sal_uInt16& rLineNo )
    1163             : {
    1164             :     //Problem: If a PostItFld is contained in a Node that is represented
    1165             :     //by more than one layout instance,
    1166             :     //we have to decide whether it should be printed once or n-times.
    1167             :     //Probably only once. For the page number we don't select a random one,
    1168             :     //but the PostIt's first occurrence in the selected area.
    1169           0 :     rVirtPgNo = 0;
    1170           0 :     sal_uInt16 nPos = GetCntnt();
    1171           0 :     SwIterator<SwTxtFrm,SwTxtNode> aIter( GetTxtFld()->GetTxtNode() );
    1172           0 :     for( SwTxtFrm* pFrm = aIter.First(); pFrm;  pFrm = aIter.Next() )
    1173             :     {
    1174           0 :         if( pFrm->GetOfst() > nPos ||
    1175           0 :             (pFrm->HasFollow() && pFrm->GetFollow()->GetOfst() <= nPos) )
    1176           0 :             continue;
    1177           0 :         sal_uInt16 nPgNo = pFrm->GetPhyPageNum();
    1178           0 :         if( rRangeEnum.hasValue( nPgNo, &rPossiblePages ))
    1179             :         {
    1180           0 :             rLineNo = (sal_uInt16)(pFrm->GetLineCount( nPos ) +
    1181           0 :                       pFrm->GetAllLines() - pFrm->GetThisLines());
    1182           0 :             rVirtPgNo = pFrm->GetVirtPageNum();
    1183           0 :             return nPgNo;
    1184             :         }
    1185             :     }
    1186           0 :     return 0;
    1187             : }
    1188             : 
    1189           0 : bool sw_GetPostIts(
    1190             :     IDocumentFieldsAccess* pIDFA,
    1191             :     _SetGetExpFlds * pSrtLst )
    1192             : {
    1193           0 :     bool bHasPostIts = false;
    1194             : 
    1195           0 :     SwFieldType* pFldType = pIDFA->GetSysFldType( RES_POSTITFLD );
    1196             :     OSL_ENSURE( pFldType, "no PostItType ? ");
    1197             : 
    1198           0 :     if( pFldType->GetDepends() )
    1199             :     {
    1200             :         // Found modify object; insert all fields into the array
    1201           0 :         SwIterator<SwFmtFld,SwFieldType> aIter( *pFldType );
    1202             :         const SwTxtFld* pTxtFld;
    1203           0 :         for( SwFmtFld* pFld = aIter.First(); pFld;  pFld = aIter.Next() )
    1204             :         {
    1205           0 :             if( 0 != ( pTxtFld = pFld->GetTxtFld() ) &&
    1206           0 :                 pTxtFld->GetTxtNode().GetNodes().IsDocNodes() )
    1207             :             {
    1208           0 :                 bHasPostIts = true;
    1209           0 :                 if (pSrtLst)
    1210             :                 {
    1211           0 :                     SwNodeIndex aIdx( pTxtFld->GetTxtNode() );
    1212           0 :                     _PostItFld* pNew = new _PostItFld( aIdx, pTxtFld );
    1213           0 :                     pSrtLst->insert( pNew );
    1214             :                 }
    1215             :                 else
    1216           0 :                     break;  // we just wanted to check for the existence of postits ...
    1217             :             }
    1218           0 :         }
    1219             :     }
    1220             : 
    1221           0 :     return bHasPostIts;
    1222             : }
    1223             : 
    1224           0 : static void lcl_FormatPostIt(
    1225             :     IDocumentContentOperations* pIDCO,
    1226             :     SwPaM& aPam,
    1227             :     SwPostItField* pField,
    1228             :     bool bNewPage, bool bIsFirstPostIt,
    1229             :     sal_uInt16 nPageNo, sal_uInt16 nLineNo )
    1230             : {
    1231             :     static char const sTmp[] = " : ";
    1232             : 
    1233             :     OSL_ENSURE( SwViewShell::GetShellRes(), "missing ShellRes" );
    1234             : 
    1235           0 :     if (bNewPage)
    1236             :     {
    1237           0 :         pIDCO->InsertPoolItem( aPam, SvxFmtBreakItem( SVX_BREAK_PAGE_AFTER, RES_BREAK ), 0 );
    1238           0 :         pIDCO->SplitNode( *aPam.GetPoint(), false );
    1239             :     }
    1240           0 :     else if (!bIsFirstPostIt)
    1241             :     {
    1242             :         // add an empty line between different notes
    1243           0 :         pIDCO->SplitNode( *aPam.GetPoint(), false );
    1244           0 :         pIDCO->SplitNode( *aPam.GetPoint(), false );
    1245             :     }
    1246             : 
    1247           0 :     OUString aStr( SwViewShell::GetShellRes()->aPostItPage );
    1248           0 :     aStr += sTmp;
    1249             : 
    1250           0 :     aStr += OUString::number( nPageNo );
    1251           0 :     aStr += " ";
    1252           0 :     if( nLineNo )
    1253             :     {
    1254           0 :         aStr += SwViewShell::GetShellRes()->aPostItLine;
    1255           0 :         aStr += sTmp;
    1256           0 :         aStr += OUString::number( nLineNo );
    1257           0 :         aStr += " ";
    1258             :     }
    1259           0 :     aStr += SwViewShell::GetShellRes()->aPostItAuthor;
    1260           0 :     aStr += sTmp;
    1261           0 :     aStr += pField->GetPar1();
    1262           0 :     aStr += " ";
    1263           0 :     SvtSysLocale aSysLocale;
    1264           0 :     aStr += /*(LocaleDataWrapper&)*/aSysLocale.GetLocaleData().getDate( pField->GetDate() );
    1265           0 :     pIDCO->InsertString( aPam, aStr );
    1266             : 
    1267           0 :     pIDCO->SplitNode( *aPam.GetPoint(), false );
    1268           0 :     aStr = pField->GetPar2();
    1269             : #if defined( WNT )
    1270             :     // Throw out all CR in Windows
    1271             :     aStr = comphelper::string::remove(aStr, '\r');
    1272             : #endif
    1273           0 :     pIDCO->InsertString( aPam, aStr );
    1274           0 : }
    1275             : 
    1276             : /// provide the paper tray to use according to the page style in use,
    1277             : /// but do that only if the respective item is NOT just the default item
    1278           0 : static sal_Int32 lcl_GetPaperBin( const SwPageFrm *pStartFrm )
    1279             : {
    1280           0 :     sal_Int32 nRes = -1;
    1281             : 
    1282           0 :     const SwFrmFmt &rFmt = pStartFrm->GetPageDesc()->GetMaster();
    1283           0 :     const SfxPoolItem *pItem = NULL;
    1284           0 :     SfxItemState eState = rFmt.GetItemState( RES_PAPER_BIN, sal_False, &pItem );
    1285           0 :     const SvxPaperBinItem *pPaperBinItem = dynamic_cast< const SvxPaperBinItem * >(pItem);
    1286           0 :     if (eState > SFX_ITEM_DEFAULT && pPaperBinItem)
    1287           0 :         nRes = pPaperBinItem->GetValue();
    1288             : 
    1289           0 :     return nRes;
    1290             : }
    1291             : 
    1292           0 : void SwDoc::CalculatePagesForPrinting(
    1293             :     const SwRootFrm& rLayout,
    1294             :     /* out */ SwRenderData &rData,
    1295             :     const SwPrintUIOptions &rOptions,
    1296             :     bool bIsPDFExport,
    1297             :     sal_Int32 nDocPageCount )
    1298             : {
    1299           0 :     const sal_Int64 nContent = rOptions.getIntValue( "PrintContent", 0 );
    1300           0 :     const bool bPrintSelection = nContent == 2;
    1301             : 
    1302             :     // properties to take into account when calcualting the set of pages
    1303             :     // (PDF export UI does not allow for selecting left or right pages only)
    1304           0 :     bool bPrintLeftPages    = bIsPDFExport ? true : rOptions.IsPrintLeftPages();
    1305           0 :     bool bPrintRightPages   = bIsPDFExport ? true : rOptions.IsPrintRightPages();
    1306             :     // #i103700# printing selections should not allow for automatic inserting empty pages
    1307           0 :     bool bPrintEmptyPages   = bPrintSelection ? false : rOptions.IsPrintEmptyPages( bIsPDFExport );
    1308             : 
    1309           0 :     std::map< sal_Int32, sal_Int32 > &rPrinterPaperTrays = rData.GetPrinterPaperTrays();
    1310           0 :     std::set< sal_Int32 > &rValidPages = rData.GetValidPagesSet();
    1311           0 :     rValidPages.clear();
    1312             : 
    1313           0 :     sal_Int32 nPageNum = 1;
    1314           0 :     const SwPageFrm *pStPage = dynamic_cast<const SwPageFrm*>( rLayout.Lower() );
    1315           0 :     while (pStPage && nPageNum <= nDocPageCount)
    1316             :     {
    1317             :         const bool bPrintThisPage =
    1318           0 :             ( (bPrintRightPages && pStPage->OnRightPage()) ||
    1319           0 :               (bPrintLeftPages && !pStPage->OnRightPage()) ) &&
    1320           0 :             ( bPrintEmptyPages || pStPage->Frm().Height() );
    1321             : 
    1322           0 :         if (bPrintThisPage)
    1323             :         {
    1324           0 :             rValidPages.insert( nPageNum );
    1325           0 :             rPrinterPaperTrays[ nPageNum ] = lcl_GetPaperBin( pStPage );
    1326             :         }
    1327             : 
    1328           0 :         ++nPageNum;
    1329           0 :         pStPage = (SwPageFrm*)pStPage->GetNext();
    1330             :     }
    1331             : 
    1332             :     // now that we have identified the valid pages for printing according
    1333             :     // to the print settings we need to get the PageRange to use and
    1334             :     // use both results to get the actual pages to be printed
    1335             :     // (post-it settings need to be taken into account later on!)
    1336             : 
    1337             :     // get PageRange value to use
    1338           0 :     OUString aPageRange;
    1339             :     // #i116085# - adjusting fix for i113919
    1340           0 :     if ( !bIsPDFExport )
    1341             :     {
    1342             :         // PageContent :
    1343             :         // 0 -> print all pages (default if aPageRange is empty)
    1344             :         // 1 -> print range according to PageRange
    1345             :         // 2 -> print selection
    1346           0 :         if (1 == nContent)
    1347           0 :             aPageRange = rOptions.getStringValue( "PageRange", OUString() );
    1348             :         if (2 == nContent)
    1349             :         {
    1350             :             // note that printing selections is actually implemented by copying
    1351             :             // the selection to a new temporary document and printing all of that one.
    1352             :             // Thus for Writer "PrintContent" must never be 2.
    1353             :             // See SwXTextDocument::GetRenderDoc for evaluating if a selection is to be
    1354             :             // printed and for creating the temporary document.
    1355             :         }
    1356             : 
    1357             :         // please note
    1358             :     }
    1359           0 :     if (aPageRange.isEmpty())    // empty string -> print all
    1360             :     {
    1361             :         // set page range to print to 'all pages'
    1362           0 :         aPageRange = OUString::number( 1 ) + "-" + OUString::number( nDocPageCount );
    1363             :     }
    1364           0 :     rData.SetPageRange( aPageRange );
    1365             : 
    1366             :     // get vector of pages to print according to PageRange and valid pages set from above
    1367             :     // (result may be an empty vector, for example if the range string is not correct)
    1368             :     StringRangeEnumerator::getRangesFromString(
    1369           0 :             aPageRange, rData.GetPagesToPrint(),
    1370           0 :             1, nDocPageCount, 0, &rData.GetValidPagesSet() );
    1371           0 : }
    1372             : 
    1373           0 : void SwDoc::UpdatePagesForPrintingWithPostItData(
    1374             :     /* out */ SwRenderData &rData,
    1375             :     const SwPrintUIOptions &rOptions,
    1376             :     bool /*bIsPDFExport*/,
    1377             :     sal_Int32 nDocPageCount )
    1378             : {
    1379             : 
    1380           0 :     sal_Int16 nPostItMode = (sal_Int16) rOptions.getIntValue( "PrintAnnotationMode", 0 );
    1381             :     OSL_ENSURE(nPostItMode == POSTITS_NONE || rData.HasPostItData(),
    1382             :             "print post-its without post-it data?" );
    1383           0 :     const sal_uInt16 nPostItCount = rData.HasPostItData() ? rData.m_pPostItFields->size() : 0;
    1384           0 :     if (nPostItMode != POSTITS_NONE && nPostItCount > 0)
    1385             :     {
    1386           0 :         SET_CURR_SHELL( rData.m_pPostItShell.get() );
    1387             : 
    1388             :         // clear document and move to end of it
    1389           0 :         SwDoc & rPostItDoc(*rData.m_pPostItShell->GetDoc());
    1390           0 :         SwPaM aPam(rPostItDoc.GetNodes().GetEndOfContent());
    1391           0 :         aPam.Move( fnMoveBackward, fnGoDoc );
    1392           0 :         aPam.SetMark();
    1393           0 :         aPam.Move( fnMoveForward, fnGoDoc );
    1394           0 :         rPostItDoc.DeleteRange( aPam );
    1395             : 
    1396           0 :         const StringRangeEnumerator aRangeEnum( rData.GetPageRange(), 1, nDocPageCount, 0 );
    1397             : 
    1398             :         // For mode POSTITS_ENDPAGE:
    1399             :         // maps a physical page number to the page number in post-it document that holds
    1400             :         // the first post-it for that physical page . Needed to relate the correct start frames
    1401             :         // from the post-it doc to the physical page of the document
    1402           0 :         std::map< sal_Int32, sal_Int32 >  aPostItLastStartPageNum;
    1403             : 
    1404             :         // add all post-its on valid pages within the page range to the
    1405             :         // temporary post-it document.
    1406             :         // Since the array of post-it fileds is sorted by page and line number we will
    1407             :         // already get them in the correct order
    1408           0 :         sal_uInt16 nVirtPg = 0, nLineNo = 0, nLastPageNum = 0, nPhyPageNum = 0;
    1409           0 :         bool bIsFirstPostIt = true;
    1410           0 :         for (sal_uInt16 i = 0; i < nPostItCount; ++i)
    1411             :         {
    1412           0 :             _PostItFld& rPostIt = (_PostItFld&)*(*rData.m_pPostItFields)[ i ];
    1413           0 :             nLastPageNum = nPhyPageNum;
    1414             :             nPhyPageNum = rPostIt.GetPageNo(
    1415           0 :                     aRangeEnum, rData.GetValidPagesSet(), nVirtPg, nLineNo );
    1416           0 :             if (nPhyPageNum)
    1417             :             {
    1418             :                 // need to insert a page break?
    1419             :                 // In POSTITS_ENDPAGE mode for each document page the following
    1420             :                 // post-it page needs to start on a new page
    1421           0 :                 const bool bNewPage = nPostItMode == POSTITS_ENDPAGE &&
    1422           0 :                         !bIsFirstPostIt && nPhyPageNum != nLastPageNum;
    1423             : 
    1424           0 :                 lcl_FormatPostIt( rData.m_pPostItShell->GetDoc(), aPam,
    1425           0 :                         rPostIt.GetPostIt(), bNewPage, bIsFirstPostIt, nVirtPg, nLineNo );
    1426           0 :                 bIsFirstPostIt = false;
    1427             : 
    1428           0 :                 if (nPostItMode == POSTITS_ENDPAGE)
    1429             :                 {
    1430             :                     // get the correct number of current pages for the post-it document
    1431           0 :                     rData.m_pPostItShell->CalcLayout();
    1432           0 :                     const sal_Int32 nPages = rData.m_pPostItShell->GetPageCount();
    1433           0 :                     aPostItLastStartPageNum[ nPhyPageNum ] = nPages;
    1434             :                 }
    1435             :             }
    1436             :         }
    1437             : 
    1438             :         // format post-it doc to get correct number of pages
    1439           0 :         rData.m_pPostItShell->CalcLayout();
    1440           0 :         const sal_Int32 nPostItDocPageCount = rData.m_pPostItShell->GetPageCount();
    1441             : 
    1442           0 :         if (nPostItMode == POSTITS_ONLY || nPostItMode == POSTITS_ENDDOC)
    1443             :         {
    1444             :             // now add those post-it pages to the vector of pages to print
    1445             :             // or replace them if only post-its should be printed
    1446             : 
    1447           0 :             if (nPostItMode == POSTITS_ONLY)
    1448             :             {
    1449             :                 // no document page to be printed
    1450           0 :                 rData.GetPagesToPrint().clear();
    1451             :             }
    1452             : 
    1453             :             // now we just need to add the post-it pages to be printed to the
    1454             :             // end of the vector of pages to print
    1455           0 :             sal_Int32 nPageNum = 0;
    1456           0 :             const SwPageFrm * pPageFrm = (SwPageFrm*)rData.m_pPostItShell->GetLayout()->Lower();
    1457           0 :             while( pPageFrm && nPageNum < nPostItDocPageCount )
    1458             :             {
    1459             :                 OSL_ENSURE( pPageFrm, "Empty page frame. How are we going to print this?" );
    1460           0 :                 ++nPageNum;
    1461             :                 // negative page number indicates page is from the post-it doc
    1462           0 :                 rData.GetPagesToPrint().push_back( -nPageNum );
    1463             :                 OSL_ENSURE( pPageFrm, "pPageFrm is NULL!" );
    1464           0 :                 pPageFrm = (SwPageFrm*)pPageFrm->GetNext();
    1465             :             }
    1466           0 :             OSL_ENSURE( nPageNum == nPostItDocPageCount, "unexpected number of pages" );
    1467             :         }
    1468           0 :         else if (nPostItMode == POSTITS_ENDPAGE)
    1469             :         {
    1470             :             // the next step is to find all the pages from the post-it
    1471             :             // document that should be printed for a given physical page
    1472             :             // of the document
    1473             : 
    1474           0 :             std::vector< sal_Int32 >            aTmpPagesToPrint;
    1475           0 :             sal_Int32 nLastPostItPage(0);
    1476           0 :             const size_t nNum = rData.GetPagesToPrint().size();
    1477           0 :             for (size_t i = 0 ;  i < nNum;  ++i)
    1478             :             {
    1479             :                 // add the physical page to print from the document
    1480           0 :                 const sal_Int32 nPhysPage = rData.GetPagesToPrint()[i];
    1481           0 :                 aTmpPagesToPrint.push_back( nPhysPage );
    1482             : 
    1483             :                 // add the post-it document pages to print, i.e those
    1484             :                 // post-it pages that have the data for the above physical page
    1485             :                 ::std::map<sal_Int32, sal_Int32>::const_iterator const iter(
    1486           0 :                         aPostItLastStartPageNum.find(nPhysPage));
    1487           0 :                 if (iter != aPostItLastStartPageNum.end())
    1488             :                 {
    1489           0 :                     for (sal_Int32 j = nLastPostItPage + 1;
    1490           0 :                             j <= iter->second; ++j)
    1491             :                     {
    1492             :                         // negative page number indicates page is from the
    1493           0 :                         aTmpPagesToPrint.push_back(-j); // post-it document
    1494             :                     }
    1495           0 :                     nLastPostItPage = iter->second;
    1496             :                 }
    1497             :             }
    1498             : 
    1499             :             // finally we need to assign those vectors to the resulting ones.
    1500             :             // swapping the data should be more efficient than assigning since
    1501             :             // we won't need the temporary vectors anymore
    1502           0 :             rData.GetPagesToPrint().swap( aTmpPagesToPrint );
    1503           0 :         }
    1504             :     }
    1505           0 : }
    1506             : 
    1507           0 : void SwDoc::CalculatePagePairsForProspectPrinting(
    1508             :     const SwRootFrm& rLayout,
    1509             :     /* out */ SwRenderData &rData,
    1510             :     const SwPrintUIOptions &rOptions,
    1511             :     sal_Int32 nDocPageCount )
    1512             : {
    1513           0 :     std::map< sal_Int32, sal_Int32 > &rPrinterPaperTrays = rData.GetPrinterPaperTrays();
    1514           0 :     std::set< sal_Int32 > &rValidPagesSet = rData.GetValidPagesSet();
    1515           0 :     std::vector< std::pair< sal_Int32, sal_Int32 > > &rPagePairs = rData.GetPagePairsForProspectPrinting();
    1516           0 :     std::map< sal_Int32, const SwPageFrm * > validStartFrms;
    1517             : 
    1518           0 :     rPagePairs.clear();
    1519           0 :     rValidPagesSet.clear();
    1520             : 
    1521           0 :     OUString aPageRange;
    1522             :     // PageContent :
    1523             :     // 0 -> print all pages (default if aPageRange is empty)
    1524             :     // 1 -> print range according to PageRange
    1525             :     // 2 -> print selection
    1526           0 :     const sal_Int64 nContent = rOptions.getIntValue( "PrintContent", 0 );
    1527           0 :     if (nContent == 1)
    1528           0 :         aPageRange = rOptions.getStringValue( "PageRange", OUString() );
    1529           0 :     if (aPageRange.isEmpty())    // empty string -> print all
    1530             :     {
    1531             :         // set page range to print to 'all pages'
    1532           0 :         aPageRange = OUString::number( 1 ) + "-" + OUString::number( nDocPageCount );
    1533             :     }
    1534           0 :     StringRangeEnumerator aRange( aPageRange, 1, nDocPageCount, 0 );
    1535             : 
    1536           0 :     if ( aRange.size() <= 0)
    1537           0 :         return;
    1538             : 
    1539           0 :     const SwPageFrm *pStPage  = dynamic_cast<const SwPageFrm*>( rLayout.Lower() );
    1540           0 :     sal_Int32 i = 0;
    1541           0 :     for ( i = 1; pStPage && i < nDocPageCount; ++i )
    1542           0 :         pStPage = (SwPageFrm*)pStPage->GetNext();
    1543           0 :     if ( !pStPage )          // Then it was that
    1544           0 :         return;
    1545             : 
    1546             :     // currently for prospect printing all pages are valid to be printed
    1547             :     // thus we add them all to the respective map and set for later use
    1548           0 :     sal_Int32 nPageNum = 0;
    1549           0 :     const SwPageFrm *pPageFrm  = dynamic_cast<const SwPageFrm*>( rLayout.Lower() );
    1550           0 :     while( pPageFrm && nPageNum < nDocPageCount )
    1551             :     {
    1552             :         OSL_ENSURE( pPageFrm, "Empty page frame. How are we going to print this?" );
    1553           0 :         ++nPageNum;
    1554           0 :         rValidPagesSet.insert( nPageNum );
    1555           0 :         validStartFrms[ nPageNum ] = pPageFrm;
    1556           0 :         pPageFrm = (SwPageFrm*)pPageFrm->GetNext();
    1557             : 
    1558           0 :         rPrinterPaperTrays[ nPageNum ] = lcl_GetPaperBin( pStPage );
    1559             :     }
    1560             :     OSL_ENSURE( nPageNum == nDocPageCount, "unexpected number of pages" );
    1561             : 
    1562             :     // properties to take into account when calcualting the set of pages
    1563             :     // Note: here bPrintLeftPages and bPrintRightPages refer to the (virtual) resulting pages
    1564             :     //      of the prospect!
    1565           0 :     bool bPrintLeftPages     = rOptions.IsPrintLeftPages();
    1566           0 :     bool bPrintRightPages    = rOptions.IsPrintRightPages();
    1567           0 :     bool bPrintProspectRTL = rOptions.getIntValue( "PrintProspectRTL",  0 ) ? true : false;
    1568             : 
    1569             :     // get pages for prospect printing according to the 'PageRange'
    1570             :     // (duplicates and any order allowed!)
    1571           0 :     std::vector< sal_Int32 > aPagesToPrint;
    1572             :     StringRangeEnumerator::getRangesFromString(
    1573           0 :             aPageRange, aPagesToPrint, 1, nDocPageCount, 0 );
    1574             : 
    1575           0 :     if (aPagesToPrint.empty())
    1576           0 :         return;
    1577             : 
    1578             :     // now fill the vector for calculating the page pairs with the start frames
    1579             :     // from the above obtained vector
    1580           0 :     std::vector< const SwPageFrm * > aVec;
    1581           0 :     for ( i = 0; i < sal_Int32(aPagesToPrint.size()); ++i)
    1582             :     {
    1583           0 :         const sal_Int32 nPage = aPagesToPrint[i];
    1584           0 :         const SwPageFrm *pFrm = validStartFrms[ nPage ];
    1585           0 :         aVec.push_back( pFrm );
    1586             :     }
    1587             : 
    1588             :     // just one page is special ...
    1589           0 :     if ( 1 == aVec.size() )
    1590           0 :         aVec.insert( aVec.begin() + 1, (SwPageFrm *)0 ); // insert a second empty page
    1591             :     else
    1592             :     {
    1593             :         // now extend the number of pages to fit a multiple of 4
    1594             :         // (4 'normal' pages are needed for a single prospect paper
    1595             :         //  with back and front)
    1596           0 :         while( aVec.size() & 3 )
    1597           0 :             aVec.push_back( 0 );
    1598             :     }
    1599             : 
    1600             :     // make sure that all pages are in correct order
    1601           0 :     sal_uInt16 nSPg = 0;
    1602           0 :     sal_uInt32 nEPg = aVec.size();
    1603           0 :     sal_uInt16 nStep = 1;
    1604           0 :     if ( 0 == (nEPg & 1 ))      // there are no uneven ones!
    1605           0 :         --nEPg;
    1606             : 
    1607           0 :     if ( !bPrintLeftPages )
    1608           0 :         ++nStep;
    1609           0 :     else if ( !bPrintRightPages )
    1610             :     {
    1611           0 :         ++nStep;
    1612           0 :         ++nSPg, --nEPg;
    1613             :     }
    1614             : 
    1615             :     // the number of 'virtual' pages to be printed
    1616           0 :     sal_Int32 nCntPage = (( nEPg - nSPg ) / ( 2 * nStep )) + 1;
    1617             : 
    1618           0 :     for ( sal_uInt16 nPrintCount = 0; nSPg < nEPg &&
    1619           0 :             nPrintCount < nCntPage; ++nPrintCount )
    1620             :     {
    1621           0 :         pStPage = aVec[ nSPg ];
    1622           0 :         const SwPageFrm* pNxtPage = nEPg < aVec.size() ? aVec[ nEPg ] : 0;
    1623             : 
    1624           0 :         short nRtlOfs = bPrintProspectRTL ? 1 : 0;
    1625           0 :         if ( 0 == (( nSPg + nRtlOfs) & 1 ) )     // switch for odd number in LTR, even number in RTL
    1626             :         {
    1627           0 :             const SwPageFrm* pTmp = pStPage;
    1628           0 :             pStPage = pNxtPage;
    1629           0 :             pNxtPage = pTmp;
    1630             :         }
    1631             : 
    1632           0 :         sal_Int32 nFirst = -1, nSecond = -1;
    1633           0 :         for ( int nC = 0; nC < 2; ++nC )
    1634             :         {
    1635           0 :             sal_Int32 nPage = -1;
    1636           0 :             if ( pStPage )
    1637           0 :                 nPage = pStPage->GetPhyPageNum();
    1638           0 :             if (nC == 0)
    1639           0 :                 nFirst  = nPage;
    1640             :             else
    1641           0 :                 nSecond = nPage;
    1642             : 
    1643           0 :             pStPage = pNxtPage;
    1644             :         }
    1645           0 :         rPagePairs.push_back( std::pair< sal_Int32, sal_Int32 >(nFirst, nSecond) );
    1646             : 
    1647           0 :         nSPg = nSPg + nStep;
    1648           0 :         nEPg = nEPg - nStep;
    1649             :     }
    1650           0 :     OSL_ENSURE( size_t(nCntPage) == rPagePairs.size(), "size mismatch for number of page pairs" );
    1651             : 
    1652             :     // luckily prospect printing does not make use of post-its so far,
    1653             :     // thus we are done here.
    1654             : }
    1655             : 
    1656             : // returns true while there is more to do
    1657         820 : bool SwDoc::IncrementalDocStatCalculate(long nChars, bool bFields)
    1658             : {
    1659         820 :     mpDocStat->Reset();
    1660         820 :     mpDocStat->nPara = 0; // default is 1!
    1661             :     SwNode* pNd;
    1662             : 
    1663             :     // This is the inner loop - at least while the paras are dirty.
    1664       15850 :     for( sal_uLong i = GetNodes().Count(); i > 0 && nChars > 0; )
    1665             :     {
    1666       14210 :         switch( ( pNd = GetNodes()[ --i ])->GetNodeType() )
    1667             :         {
    1668             :         case ND_TEXTNODE:
    1669             :         {
    1670        3850 :             long const nOldChars(mpDocStat->nChar);
    1671        3850 :             SwTxtNode *pTxt = static_cast< SwTxtNode * >( pNd );
    1672        3850 :             if (pTxt->CountWords(*mpDocStat, 0, pTxt->GetTxt().getLength()))
    1673             :             {
    1674         464 :                 nChars -= (mpDocStat->nChar - nOldChars);
    1675             :             }
    1676        3850 :             break;
    1677             :         }
    1678          35 :         case ND_TABLENODE:      ++mpDocStat->nTbl;   break;
    1679          22 :         case ND_GRFNODE:        ++mpDocStat->nGrf;   break;
    1680          11 :         case ND_OLENODE:        ++mpDocStat->nOLE;   break;
    1681          68 :         case ND_SECTIONNODE:    break;
    1682             :         }
    1683             :     }
    1684             : 
    1685             :     // #i93174#: notes contain paragraphs that are not nodes
    1686             :     {
    1687         820 :         SwFieldType * const pPostits( GetSysFldType(RES_POSTITFLD) );
    1688         820 :         SwIterator<SwFmtFld,SwFieldType> aIter( *pPostits );
    1689         827 :         for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld;  pFmtFld = aIter.Next() )
    1690             :         {
    1691           7 :             if (pFmtFld->IsFldInDoc())
    1692             :             {
    1693             :                 SwPostItField const * const pField(
    1694           7 :                     static_cast<SwPostItField const*>(pFmtFld->GetField()));
    1695           7 :                 mpDocStat->nAllPara += pField->GetNumberOfParagraphs();
    1696             :             }
    1697         820 :         }
    1698             :     }
    1699             : 
    1700         820 :     mpDocStat->nPage     = GetCurrentLayout() ? GetCurrentLayout()->GetPageNum() : 0;
    1701         820 :     mpDocStat->bModified = sal_False;
    1702             : 
    1703         820 :     com::sun::star::uno::Sequence < com::sun::star::beans::NamedValue > aStat( mpDocStat->nPage ? 8 : 7);
    1704         820 :     sal_Int32 n=0;
    1705         820 :     aStat[n].Name = "TableCount";
    1706         820 :     aStat[n++].Value <<= (sal_Int32)mpDocStat->nTbl;
    1707         820 :     aStat[n].Name = "ImageCount";
    1708         820 :     aStat[n++].Value <<= (sal_Int32)mpDocStat->nGrf;
    1709         820 :     aStat[n].Name = "ObjectCount";
    1710         820 :     aStat[n++].Value <<= (sal_Int32)mpDocStat->nOLE;
    1711         820 :     if ( mpDocStat->nPage )
    1712             :     {
    1713         817 :         aStat[n].Name = "PageCount";
    1714         817 :         aStat[n++].Value <<= (sal_Int32)mpDocStat->nPage;
    1715             :     }
    1716         820 :     aStat[n].Name = "ParagraphCount";
    1717         820 :     aStat[n++].Value <<= (sal_Int32)mpDocStat->nPara;
    1718         820 :     aStat[n].Name = "WordCount";
    1719         820 :     aStat[n++].Value <<= (sal_Int32)mpDocStat->nWord;
    1720         820 :     aStat[n].Name = "CharacterCount";
    1721         820 :     aStat[n++].Value <<= (sal_Int32)mpDocStat->nChar;
    1722         820 :     aStat[n].Name = "NonWhitespaceCharacterCount";
    1723         820 :     aStat[n++].Value <<= (sal_Int32)mpDocStat->nCharExcludingSpaces;
    1724             : 
    1725             :     // For e.g. autotext documents there is no pSwgInfo (#i79945)
    1726         820 :     SfxObjectShell * const pObjShell( GetDocShell() );
    1727         820 :     if (pObjShell)
    1728             :     {
    1729             :         const uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
    1730         820 :                 pObjShell->GetModel(), uno::UNO_QUERY_THROW);
    1731             :         const uno::Reference<document::XDocumentProperties> xDocProps(
    1732        1640 :                 xDPS->getDocumentProperties());
    1733             :         // #i96786#: do not set modified flag when updating statistics
    1734         820 :         const bool bDocWasModified( IsModified() );
    1735        1640 :         const ModifyBlocker_Impl b(pObjShell);
    1736         820 :         xDocProps->setDocumentStatistics(aStat);
    1737         820 :         if (!bDocWasModified)
    1738             :         {
    1739         429 :             ResetModified();
    1740         820 :         }
    1741             :     }
    1742             : 
    1743             :     // optionally update stat. fields
    1744         820 :     if (bFields)
    1745             :     {
    1746          96 :         SwFieldType *pType = GetSysFldType(RES_DOCSTATFLD);
    1747          96 :         pType->UpdateFlds();
    1748             :     }
    1749             : 
    1750         820 :     return nChars <= 0;
    1751             : }
    1752             : 
    1753          10 : IMPL_LINK( SwDoc, DoIdleStatsUpdate, Timer *, pTimer )
    1754             : {
    1755             :     (void)pTimer;
    1756           5 :     if (IncrementalDocStatCalculate(32000))
    1757           0 :         maStatsUpdateTimer.Start();
    1758             : 
    1759           5 :     SwView* pView = GetDocShell() ? GetDocShell()->GetView() : NULL;
    1760           5 :     if( pView )
    1761           5 :         pView->UpdateDocStats();
    1762           5 :     return 0;
    1763             : }
    1764             : 
    1765         815 : void SwDoc::UpdateDocStat( bool bCompleteAsync, bool bFields )
    1766             : {
    1767         815 :     if( mpDocStat->bModified )
    1768             :     {
    1769         815 :         if (!bCompleteAsync)
    1770             :         {
    1771         182 :             while (IncrementalDocStatCalculate(
    1772          91 :                         ::std::numeric_limits<long>::max(), bFields)) {}
    1773          91 :             maStatsUpdateTimer.Stop();
    1774             :         }
    1775         724 :         else if (IncrementalDocStatCalculate(5000, bFields))
    1776           5 :             maStatsUpdateTimer.Start();
    1777             :     }
    1778         815 : }
    1779             : 
    1780        2543 : void SwDoc::DocInfoChgd( )
    1781             : {
    1782        2543 :     GetSysFldType( RES_DOCINFOFLD )->UpdateFlds();
    1783        2543 :     GetSysFldType( RES_TEMPLNAMEFLD )->UpdateFlds();
    1784        2543 :     SetModified();
    1785        2543 : }
    1786             : 
    1787             : /// @return the reference in the doc for the name
    1788          62 : const SwFmtRefMark* SwDoc::GetRefMark( const OUString& rName ) const
    1789             : {
    1790             :     const SfxPoolItem* pItem;
    1791          62 :     sal_uInt32 nMaxItems = GetAttrPool().GetItemCount2( RES_TXTATR_REFMARK );
    1792         451 :     for( sal_uInt32 n = 0; n < nMaxItems; ++n )
    1793             :     {
    1794         447 :         if( 0 == (pItem = GetAttrPool().GetItem2( RES_TXTATR_REFMARK, n ) ))
    1795         117 :             continue;
    1796             : 
    1797         330 :         const SwFmtRefMark* pFmtRef = (SwFmtRefMark*)pItem;
    1798         330 :         const SwTxtRefMark* pTxtRef = pFmtRef->GetTxtRefMark();
    1799         449 :         if( pTxtRef && &pTxtRef->GetTxtNode().GetNodes() == &GetNodes() &&
    1800         119 :             rName == pFmtRef->GetRefName() )
    1801          58 :             return pFmtRef;
    1802             :     }
    1803           4 :     return 0;
    1804             : }
    1805             : 
    1806             : /// @return the RefMark per index - for Uno
    1807           4 : const SwFmtRefMark* SwDoc::GetRefMark( sal_uInt16 nIndex ) const
    1808             : {
    1809             :     const SfxPoolItem* pItem;
    1810             :     const SwTxtRefMark* pTxtRef;
    1811           4 :     const SwFmtRefMark* pRet = 0;
    1812             : 
    1813           4 :     sal_uInt32 nMaxItems = GetAttrPool().GetItemCount2( RES_TXTATR_REFMARK );
    1814           4 :     sal_uInt32 nCount = 0;
    1815          24 :     for( sal_uInt32 n = 0; n < nMaxItems; ++n )
    1816          61 :         if( 0 != (pItem = GetAttrPool().GetItem2( RES_TXTATR_REFMARK, n )) &&
    1817          30 :             0 != (pTxtRef = ((SwFmtRefMark*)pItem)->GetTxtRefMark()) &&
    1818           7 :             &pTxtRef->GetTxtNode().GetNodes() == &GetNodes() )
    1819             :         {
    1820           7 :             if(nCount == nIndex)
    1821             :             {
    1822           3 :                 pRet = (SwFmtRefMark*)pItem;
    1823           3 :                 break;
    1824             :             }
    1825           4 :             nCount++;
    1826             :         }
    1827           4 :    return pRet;
    1828             : }
    1829             : 
    1830             : /// @return the names of all set references in the Doc
    1831             : //JP 24.06.96: If the array pointer is 0, then just return whether a RefMark is set in the Doc
    1832             : // OS 25.06.96: From now on we always return the reference count
    1833           3 : sal_uInt16 SwDoc::GetRefMarks( std::vector<OUString>* pNames ) const
    1834             : {
    1835             :     const SfxPoolItem* pItem;
    1836             :     const SwTxtRefMark* pTxtRef;
    1837             : 
    1838           3 :     const sal_uInt32 nMaxItems = GetAttrPool().GetItemCount2( RES_TXTATR_REFMARK );
    1839           3 :     sal_uInt16 nCount = 0;
    1840          21 :     for( sal_uInt32 n = 0; n < nMaxItems; ++n )
    1841          48 :         if( 0 != (pItem = GetAttrPool().GetItem2( RES_TXTATR_REFMARK, n )) &&
    1842          24 :             0 != (pTxtRef = ((SwFmtRefMark*)pItem)->GetTxtRefMark()) &&
    1843           6 :             &pTxtRef->GetTxtNode().GetNodes() == &GetNodes() )
    1844             :         {
    1845           6 :             if( pNames )
    1846             :             {
    1847           2 :                 OUString pTmp(((SwFmtRefMark*)pItem)->GetRefName());
    1848           2 :                 pNames->insert(pNames->begin() + nCount, pTmp);
    1849             :             }
    1850           6 :             ++nCount;
    1851             :         }
    1852             : 
    1853           3 :     return nCount;
    1854             : }
    1855             : 
    1856           0 : bool SwDoc::IsLoaded() const
    1857             : {
    1858           0 :     return mbLoaded;
    1859             : }
    1860             : 
    1861        2416 : bool SwDoc::IsUpdateExpFld() const
    1862             : {
    1863        2416 :     return mbUpdateExpFld;
    1864             : }
    1865             : 
    1866           0 : bool SwDoc::IsNewDoc() const
    1867             : {
    1868           0 :     return mbNewDoc;
    1869             : }
    1870             : 
    1871           0 : bool SwDoc::IsPageNums() const
    1872             : {
    1873           0 :   return mbPageNums;
    1874             : }
    1875             : 
    1876           0 : void SwDoc::SetPageNums(bool b)
    1877             : {
    1878           0 :     mbPageNums = b;
    1879           0 : }
    1880             : 
    1881           0 : void SwDoc::SetNewDoc(bool b)
    1882             : {
    1883           0 :     mbNewDoc = b;
    1884           0 : }
    1885             : 
    1886         120 : void SwDoc::SetUpdateExpFldStat(bool b)
    1887             : {
    1888         120 :     mbUpdateExpFld = b;
    1889         120 : }
    1890             : 
    1891         202 : void SwDoc::SetLoaded(bool b)
    1892             : {
    1893         202 :     mbLoaded = b;
    1894         202 : }
    1895             : 
    1896       41420 : bool SwDoc::IsModified() const
    1897             : {
    1898       41420 :     return mbModified;
    1899             : }
    1900             : 
    1901             : //Load document from fdo#42534 under valgrind, drag the scrollbar down so full
    1902             : //document layout is triggered. Close document before layout has completed, and
    1903             : //SwAnchoredObject objects deleted by the deletion of layout remain referenced
    1904             : //by the SwLayouter
    1905      711856 : void SwDoc::ClearSwLayouterEntries()
    1906             : {
    1907      711856 :     SwLayouter::ClearMovedFwdFrms( *this );
    1908      711856 :     SwLayouter::ClearObjsTmpConsiderWrapInfluence( *this );
    1909             :     // #i65250#
    1910      711856 :     SwLayouter::ClearMoveBwdLayoutInfo( *this );
    1911      711856 : }
    1912             : 
    1913      710125 : void SwDoc::SetModified()
    1914             : {
    1915      710125 :     ClearSwLayouterEntries();
    1916             :     // give the old and new modified state to the link
    1917             :     //  Bit 0:  -> old state
    1918             :     //  Bit 1:  -> new state
    1919      710125 :     sal_IntPtr nCall = mbModified ? 3 : 2;
    1920      710125 :     mbModified = true;
    1921      710125 :     mpDocStat->bModified = sal_True;
    1922      710125 :     if( maOle2Link.IsSet() )
    1923             :     {
    1924      601854 :         mbInCallModified = true;
    1925      601854 :         maOle2Link.Call( (void*)nCall );
    1926      601854 :         mbInCallModified = false;
    1927             :     }
    1928             : 
    1929      710125 :     if( mpACEWord && !mpACEWord->IsDeleted() )
    1930           0 :         delete mpACEWord, mpACEWord = 0;
    1931      710125 : }
    1932             : 
    1933       29366 : void SwDoc::ResetModified()
    1934             : {
    1935             :     // give the old and new modified state to the link
    1936             :     //  Bit 0:  -> old state
    1937             :     //  Bit 1:  -> new state
    1938       29366 :     sal_IntPtr nCall = mbModified ? 1 : 0;
    1939       29366 :     mbModified = false;
    1940       29366 :     GetIDocumentUndoRedo().SetUndoNoModifiedPosition();
    1941       29366 :     if( nCall && maOle2Link.IsSet() )
    1942             :     {
    1943        8811 :         mbInCallModified = true;
    1944        8811 :         maOle2Link.Call( (void*)nCall );
    1945        8811 :         mbInCallModified = false;
    1946             :     }
    1947       29366 : }
    1948             : 
    1949           6 : void SwDoc::ReRead( SwPaM& rPam, const OUString& rGrfName,
    1950             :                     const OUString& rFltName, const Graphic* pGraphic,
    1951             :                     const GraphicObject* pGrafObj )
    1952             : {
    1953             :     SwGrfNode *pGrfNd;
    1954          12 :     if( ( !rPam.HasMark()
    1955           0 :          || rPam.GetPoint()->nNode.GetIndex() == rPam.GetMark()->nNode.GetIndex() )
    1956          12 :          && 0 != ( pGrfNd = rPam.GetPoint()->nNode.GetNode().GetGrfNode() ) )
    1957             :     {
    1958           6 :         if (GetIDocumentUndoRedo().DoesUndo())
    1959             :         {
    1960           6 :             GetIDocumentUndoRedo().AppendUndo(new SwUndoReRead(rPam, *pGrfNd));
    1961             :         }
    1962             : 
    1963             :         // Because we don't know if we can mirror the graphic, the mirror attribute is always reset
    1964          12 :         if( RES_MIRROR_GRAPH_DONT != pGrfNd->GetSwAttrSet().
    1965           6 :                                                 GetMirrorGrf().GetValue() )
    1966           1 :             pGrfNd->SetAttr( SwMirrorGrf() );
    1967             : 
    1968           6 :         pGrfNd->ReRead( rGrfName, rFltName, pGraphic, pGrafObj, true );
    1969           6 :         SetModified();
    1970             :     }
    1971           6 : }
    1972             : 
    1973          56 : static bool lcl_SpellAndGrammarAgain( const SwNodePtr& rpNd, void* pArgs )
    1974             : {
    1975          56 :     SwTxtNode *pTxtNode = (SwTxtNode*)rpNd->GetTxtNode();
    1976          56 :     sal_Bool bOnlyWrong = *(sal_Bool*)pArgs;
    1977          56 :     if( pTxtNode )
    1978             :     {
    1979           6 :         if( bOnlyWrong )
    1980             :         {
    1981           2 :             if( pTxtNode->GetWrong() &&
    1982           0 :                 pTxtNode->GetWrong()->InvalidateWrong() )
    1983           0 :                 pTxtNode->SetWrongDirty( true );
    1984           2 :             if( pTxtNode->GetGrammarCheck() &&
    1985           0 :                 pTxtNode->GetGrammarCheck()->InvalidateWrong() )
    1986           0 :                 pTxtNode->SetGrammarCheckDirty( true );
    1987             :         }
    1988             :         else
    1989             :         {
    1990           4 :             pTxtNode->SetWrongDirty( true );
    1991           4 :             if( pTxtNode->GetWrong() )
    1992           0 :                 pTxtNode->GetWrong()->SetInvalid( 0, COMPLETE_STRING );
    1993           4 :             pTxtNode->SetGrammarCheckDirty( true );
    1994           4 :             if( pTxtNode->GetGrammarCheck() )
    1995           0 :                 pTxtNode->GetGrammarCheck()->SetInvalid( 0, COMPLETE_STRING );
    1996             :         }
    1997             :     }
    1998          56 :     return true;
    1999             : }
    2000             : 
    2001          44 : static bool lcl_CheckSmartTagsAgain( const SwNodePtr& rpNd, void*  )
    2002             : {
    2003          44 :     SwTxtNode *pTxtNode = (SwTxtNode*)rpNd->GetTxtNode();
    2004          44 :     if( pTxtNode )
    2005             :     {
    2006           4 :         pTxtNode->SetSmartTagDirty( true );
    2007           4 :         if( pTxtNode->GetSmartTags() )
    2008             :         {
    2009           0 :             pTxtNode->SetSmartTags( NULL );
    2010             :         }
    2011             :     }
    2012          44 :     return true;
    2013             : }
    2014             : 
    2015             : /** Re-trigger spelling in the idle handler.
    2016             :  *
    2017             :  * @param bInvalid if <true>, the WrongLists in all nodes are invalidated
    2018             :  *                 and the SpellInvalid flag is set on all pages.
    2019             :  * @param bOnlyWrong controls whether only the areas with wrong words are
    2020             :  *                   checked or the whole area.
    2021             :  * @param bSmartTags ???
    2022             :  ************************************************************************/
    2023           5 : void SwDoc::SpellItAgainSam( bool bInvalid, bool bOnlyWrong, bool bSmartTags )
    2024             : {
    2025           5 :     std::set<SwRootFrm*> aAllLayouts = GetAllLayouts();
    2026             :     OSL_ENSURE( GetCurrentLayout(), "SpellAgain: Where's my RootFrm?" );
    2027           5 :     if( bInvalid )
    2028             :     {
    2029           5 :         std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::bind2nd(std::mem_fun(&SwRootFrm::AllInvalidateSmartTagsOrSpelling),bSmartTags));
    2030           5 :         std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::bind2nd(std::mem_fun(&SwRootFrm::SetNeedGrammarCheck), true) );
    2031           5 :         if ( bSmartTags )
    2032           4 :             GetNodes().ForEach( lcl_CheckSmartTagsAgain, &bOnlyWrong );
    2033           5 :         GetNodes().ForEach( lcl_SpellAndGrammarAgain, &bOnlyWrong );
    2034             :     }
    2035             : 
    2036           5 :     std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::mem_fun(&SwRootFrm::SetIdleFlags));
    2037           5 : }
    2038             : 
    2039           0 : void SwDoc::InvalidateAutoCompleteFlag()
    2040             : {
    2041           0 :     SwRootFrm* pTmpRoot = GetCurrentLayout();
    2042           0 :     if( pTmpRoot )
    2043             :     {
    2044           0 :         std::set<SwRootFrm*> aAllLayouts = GetAllLayouts();
    2045           0 :         std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::mem_fun(&SwRootFrm::AllInvalidateAutoCompleteWords));
    2046           0 :         for( sal_uLong nNd = 1, nCnt = GetNodes().Count(); nNd < nCnt; ++nNd )
    2047             :         {
    2048           0 :             SwTxtNode* pTxtNode = GetNodes()[ nNd ]->GetTxtNode();
    2049           0 :             if ( pTxtNode ) pTxtNode->SetAutoCompleteWordDirty( true );
    2050             :         }
    2051             : 
    2052           0 :         std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::mem_fun(&SwRootFrm::SetIdleFlags));
    2053             :     }
    2054           0 : }
    2055             : 
    2056           0 : const SwFmtINetFmt* SwDoc::FindINetAttr( const OUString& rName ) const
    2057             : {
    2058             :     const SwFmtINetFmt* pItem;
    2059             :     const SwTxtINetFmt* pTxtAttr;
    2060             :     const SwTxtNode* pTxtNd;
    2061           0 :     sal_uInt32 n, nMaxItems = GetAttrPool().GetItemCount2( RES_TXTATR_INETFMT );
    2062           0 :     for( n = 0; n < nMaxItems; ++n )
    2063           0 :         if( 0 != (pItem = (SwFmtINetFmt*)GetAttrPool().GetItem2(
    2064           0 :             RES_TXTATR_INETFMT, n ) ) &&
    2065           0 :             pItem->GetName() == rName &&
    2066           0 :             0 != ( pTxtAttr = pItem->GetTxtINetFmt()) &&
    2067           0 :             0 != ( pTxtNd = pTxtAttr->GetpTxtNode() ) &&
    2068           0 :             &pTxtNd->GetNodes() == &GetNodes() )
    2069             :         {
    2070           0 :             return pItem;
    2071             :         }
    2072             : 
    2073           0 :     return 0;
    2074             : }
    2075             : 
    2076           0 : void SwDoc::Summary( SwDoc* pExtDoc, sal_uInt8 nLevel, sal_uInt8 nPara, bool bImpress )
    2077             : {
    2078           0 :     const SwOutlineNodes& rOutNds = GetNodes().GetOutLineNds();
    2079           0 :     if( pExtDoc && !rOutNds.empty() )
    2080             :     {
    2081             :         sal_uInt16 i;
    2082           0 :         ::StartProgress( STR_STATSTR_SUMMARY, 0, rOutNds.size(), GetDocShell() );
    2083           0 :         SwNodeIndex aEndOfDoc( pExtDoc->GetNodes().GetEndOfContent(), -1 );
    2084           0 :         for( i = 0; i < rOutNds.size(); ++i )
    2085             :         {
    2086           0 :             ::SetProgressState( i, GetDocShell() );
    2087           0 :             const sal_uLong nIndex = rOutNds[ i ]->GetIndex();
    2088             : 
    2089           0 :             const int nLvl = ((SwTxtNode*)GetNodes()[ nIndex ])->GetAttrOutlineLevel()-1;
    2090           0 :             if( nLvl > nLevel )
    2091           0 :                 continue;
    2092           0 :             sal_uInt16 nEndOfs = 1;
    2093           0 :             sal_uInt8 nWish = nPara;
    2094           0 :             sal_uLong nNextOutNd = i + 1 < (sal_uInt16)rOutNds.size() ?
    2095           0 :                 rOutNds[ i + 1 ]->GetIndex() : GetNodes().Count();
    2096           0 :             sal_Bool bKeep = sal_False;
    2097           0 :             while( ( nWish || bKeep ) && nIndex + nEndOfs < nNextOutNd &&
    2098           0 :                    GetNodes()[ nIndex + nEndOfs ]->IsTxtNode() )
    2099             :             {
    2100           0 :                 SwTxtNode* pTxtNode = (SwTxtNode*)GetNodes()[ nIndex+nEndOfs ];
    2101           0 :                 if (pTxtNode->GetTxt().getLength() && nWish)
    2102           0 :                     --nWish;
    2103           0 :                 bKeep = pTxtNode->GetSwAttrSet().GetKeep().GetValue();
    2104           0 :                 ++nEndOfs;
    2105             :             }
    2106             : 
    2107           0 :             SwNodeRange aRange( *rOutNds[ i ], 0, *rOutNds[ i ], nEndOfs );
    2108           0 :             GetNodes()._Copy( aRange, aEndOfDoc );
    2109           0 :         }
    2110           0 :         const SwTxtFmtColls *pColl = pExtDoc->GetTxtFmtColls();
    2111           0 :         for( i = 0; i < pColl->size(); ++i )
    2112           0 :             (*pColl)[ i ]->ResetFmtAttr( RES_PAGEDESC, RES_BREAK );
    2113           0 :         SwNodeIndex aIndx( pExtDoc->GetNodes().GetEndOfExtras() );
    2114           0 :         ++aEndOfDoc;
    2115           0 :         while( aIndx < aEndOfDoc )
    2116             :         {
    2117             :             SwNode *pNode;
    2118           0 :             bool bDelete = false;
    2119           0 :             if( (pNode = &aIndx.GetNode())->IsTxtNode() )
    2120             :             {
    2121           0 :                 SwTxtNode *pNd = (SwTxtNode*)pNode;
    2122           0 :                 if( pNd->HasSwAttrSet() )
    2123           0 :                     pNd->ResetAttr( RES_PAGEDESC, RES_BREAK );
    2124           0 :                 if( bImpress )
    2125             :                 {
    2126           0 :                     SwTxtFmtColl* pMyColl = pNd->GetTxtColl();
    2127             : 
    2128             :                     const sal_uInt16 nHeadLine = static_cast<sal_uInt16>(
    2129           0 :                                 !pMyColl->IsAssignedToListLevelOfOutlineStyle()
    2130             :                                 ? RES_POOLCOLL_HEADLINE2
    2131           0 :                                 : RES_POOLCOLL_HEADLINE1 );
    2132           0 :                     pMyColl = pExtDoc->GetTxtCollFromPool( nHeadLine );
    2133           0 :                     pNd->ChgFmtColl( pMyColl );
    2134             :                 }
    2135           0 :                 if( !pNd->Len() &&
    2136           0 :                     pNd->StartOfSectionIndex()+2 < pNd->EndOfSectionIndex() )
    2137             :                 {
    2138           0 :                     bDelete = true;
    2139           0 :                     pExtDoc->GetNodes().Delete( aIndx );
    2140             :                 }
    2141             :             }
    2142           0 :             if( !bDelete )
    2143           0 :                 ++aIndx;
    2144             :         }
    2145           0 :         ::EndProgress( GetDocShell() );
    2146             :     }
    2147           0 : }
    2148             : 
    2149             : /// Remove the invisible content from the document e.g. hidden areas, hidden paragraphs
    2150           0 : bool SwDoc::RemoveInvisibleContent()
    2151             : {
    2152           0 :     bool bRet = false;
    2153           0 :     GetIDocumentUndoRedo().StartUndo( UNDO_UI_DELETE_INVISIBLECNTNT, NULL );
    2154             : 
    2155             :     {
    2156             :         SwTxtNode* pTxtNd;
    2157           0 :         SwIterator<SwFmtFld,SwFieldType> aIter( *GetSysFldType( RES_HIDDENPARAFLD )  );
    2158           0 :         for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld;  pFmtFld = aIter.Next() )
    2159             :         {
    2160           0 :             if( pFmtFld->GetTxtFld() &&
    2161           0 :                 0 != ( pTxtNd = (SwTxtNode*)pFmtFld->GetTxtFld()->GetpTxtNode() ) &&
    2162           0 :                 pTxtNd->GetpSwpHints() && pTxtNd->HasHiddenParaField() &&
    2163           0 :                 &pTxtNd->GetNodes() == &GetNodes() )
    2164             :             {
    2165           0 :                 bRet = true;
    2166           0 :                 SwPaM aPam(*pTxtNd, 0, *pTxtNd, pTxtNd->GetTxt().getLength());
    2167             : 
    2168             :                 // Remove hidden paragraph or delete contents:
    2169             :                 // Delete contents if
    2170             :                 // 1. removing the paragraph would result in an empty section or
    2171             :                 // 2. if the paragraph is the last paragraph in the section and
    2172             :                 //    there is no paragraph in front of the paragraph:
    2173           0 :                 if ( ( 2 == pTxtNd->EndOfSectionIndex() - pTxtNd->StartOfSectionIndex() ) ||
    2174           0 :                      ( 1 == pTxtNd->EndOfSectionIndex() - pTxtNd->GetIndex() &&
    2175           0 :                        !GetNodes()[ pTxtNd->GetIndex() - 1 ]->GetTxtNode() ) )
    2176             :                 {
    2177           0 :                     DeleteRange( aPam );
    2178             :                 }
    2179             :                 else
    2180             :                 {
    2181           0 :                     aPam.DeleteMark();
    2182           0 :                     DelFullPara( aPam );
    2183           0 :                 }
    2184             :             }
    2185           0 :         }
    2186             :     }
    2187             : 
    2188             :     // Remove any hidden paragraph (hidden text attribute)
    2189           0 :     for( sal_uLong n = GetNodes().Count(); n; )
    2190             :     {
    2191           0 :         SwTxtNode* pTxtNd = GetNodes()[ --n ]->GetTxtNode();
    2192           0 :         if ( pTxtNd )
    2193             :         {
    2194           0 :             bool bRemoved = false;
    2195           0 :             SwPaM aPam(*pTxtNd, 0, *pTxtNd, pTxtNd->GetTxt().getLength());
    2196           0 :             if ( pTxtNd->HasHiddenCharAttribute( true ) )
    2197             :             {
    2198           0 :                 bRemoved = true;
    2199           0 :                 bRet = true;
    2200             : 
    2201             :                 // Remove hidden paragraph or delete contents:
    2202             :                 // Delete contents if
    2203             :                 // 1. removing the paragraph would result in an empty section or
    2204             :                 // 2. if the paragraph is the last paragraph in the section and
    2205             :                 //    there is no paragraph in front of the paragraph:
    2206           0 :                 if ( ( 2 == pTxtNd->EndOfSectionIndex() - pTxtNd->StartOfSectionIndex() ) ||
    2207           0 :                      ( 1 == pTxtNd->EndOfSectionIndex() - pTxtNd->GetIndex() &&
    2208           0 :                        !GetNodes()[ pTxtNd->GetIndex() - 1 ]->GetTxtNode() ) )
    2209             :                 {
    2210           0 :                     DeleteRange( aPam );
    2211             :                 }
    2212             :                 else
    2213             :                 {
    2214           0 :                     aPam.DeleteMark();
    2215           0 :                     DelFullPara( aPam );
    2216             :                 }
    2217             :             }
    2218           0 :             else if ( pTxtNd->HasHiddenCharAttribute( false ) )
    2219             :             {
    2220           0 :                 bRemoved = true;
    2221           0 :                 bRet = true;
    2222           0 :                 SwScriptInfo::DeleteHiddenRanges( *pTxtNd );
    2223             :             }
    2224             : 
    2225             :             // Footnotes/Frames may have been removed, therefore we have
    2226             :             // to reset n:
    2227           0 :             if ( bRemoved )
    2228           0 :                 n = aPam.GetPoint()->nNode.GetIndex();
    2229             :         }
    2230             :     }
    2231             : 
    2232             :     {
    2233             :         // Delete/empty all hidden areas
    2234           0 :         SwSectionFmts aSectFmts;
    2235           0 :         SwSectionFmts& rSectFmts = GetSections();
    2236             :         sal_uInt16 n;
    2237             : 
    2238           0 :         for( n = rSectFmts.size(); n; )
    2239             :         {
    2240           0 :             SwSectionFmt* pSectFmt = rSectFmts[ --n ];
    2241             :             // don't add sections in Undo/Redo
    2242           0 :             if( !pSectFmt->IsInNodesArr())
    2243           0 :                 continue;
    2244           0 :             SwSection* pSect = pSectFmt->GetSection();
    2245           0 :             if( pSect->CalcHiddenFlag() )
    2246             :             {
    2247           0 :                 SwSection* pParent = pSect, *pTmp;
    2248           0 :                 while( 0 != (pTmp = pParent->GetParent() ))
    2249             :                 {
    2250           0 :                     if( pTmp->IsHiddenFlag() )
    2251           0 :                         pSect = pTmp;
    2252           0 :                     pParent = pTmp;
    2253             :                 }
    2254             : 
    2255             :                 SwSectionFmts::iterator it = std::find(
    2256           0 :                         aSectFmts.begin(), aSectFmts.end(), pSect->GetFmt() );
    2257           0 :                 if (it == aSectFmts.end())
    2258           0 :                     aSectFmts.insert( aSectFmts.begin(), pSect->GetFmt() );
    2259             :             }
    2260           0 :             if( !pSect->GetCondition().isEmpty() )
    2261             :             {
    2262           0 :                 SwSectionData aSectionData( *pSect );
    2263           0 :                 aSectionData.SetCondition( OUString() );
    2264           0 :                 aSectionData.SetHidden( false );
    2265           0 :                 UpdateSection( n, aSectionData );
    2266             :             }
    2267             :         }
    2268             : 
    2269           0 :         if( 0 != ( n = aSectFmts.size() ))
    2270             :         {
    2271           0 :             while( n )
    2272             :             {
    2273           0 :                 SwSectionFmt* pSectFmt = aSectFmts[ --n ];
    2274           0 :                 SwSectionNode* pSectNd = pSectFmt->GetSectionNode();
    2275           0 :                 if( pSectNd )
    2276             :                 {
    2277           0 :                     bRet = true;
    2278           0 :                     SwPaM aPam( *pSectNd );
    2279             : 
    2280           0 :                     if( pSectNd->StartOfSectionNode()->StartOfSectionIndex() ==
    2281           0 :                         pSectNd->GetIndex() - 1 &&
    2282           0 :                         pSectNd->StartOfSectionNode()->EndOfSectionIndex() ==
    2283           0 :                         pSectNd->EndOfSectionIndex() + 1 )
    2284             :                     {
    2285             :                         // only delete the content
    2286           0 :                         SwCntntNode* pCNd = GetNodes().GoNext(
    2287           0 :                                                 &aPam.GetPoint()->nNode );
    2288           0 :                         aPam.GetPoint()->nContent.Assign( pCNd, 0 );
    2289           0 :                         aPam.SetMark();
    2290           0 :                         aPam.GetPoint()->nNode = *pSectNd->EndOfSectionNode();
    2291           0 :                         pCNd = GetNodes().GoPrevious(
    2292           0 :                                                 &aPam.GetPoint()->nNode );
    2293           0 :                         aPam.GetPoint()->nContent.Assign( pCNd, pCNd->Len() );
    2294             : 
    2295           0 :                         DeleteRange( aPam );
    2296             :                     }
    2297             :                     else
    2298             :                     {
    2299             :                         // delete the whole section
    2300           0 :                         aPam.SetMark();
    2301           0 :                         aPam.GetPoint()->nNode = *pSectNd->EndOfSectionNode();
    2302           0 :                         DelFullPara( aPam );
    2303           0 :                     }
    2304             : 
    2305             :                 }
    2306             :             }
    2307           0 :             aSectFmts.clear();
    2308           0 :         }
    2309             :     }
    2310             : 
    2311           0 :     if( bRet )
    2312           0 :         SetModified();
    2313           0 :     GetIDocumentUndoRedo().EndUndo( UNDO_UI_DELETE_INVISIBLECNTNT, NULL );
    2314           0 :     return bRet;
    2315             : }
    2316             : 
    2317           0 : bool SwDoc::HasInvisibleContent() const
    2318             : {
    2319           0 :     bool bRet = false;
    2320             : 
    2321           0 :     SwClientIter aIter( *GetSysFldType( RES_HIDDENPARAFLD ) );
    2322           0 :     if( aIter.First( TYPE( SwFmtFld ) ) )
    2323           0 :         bRet = true;
    2324             : 
    2325             :     // Search for any hidden paragraph (hidden text attribute)
    2326           0 :     if( ! bRet )
    2327             :     {
    2328           0 :         for( sal_uLong n = GetNodes().Count(); !bRet && (n > 0); )
    2329             :         {
    2330           0 :             SwTxtNode* pTxtNd = GetNodes()[ --n ]->GetTxtNode();
    2331           0 :             if ( pTxtNd )
    2332             :             {
    2333           0 :                 SwPaM aPam(*pTxtNd, 0, *pTxtNd, pTxtNd->GetTxt().getLength());
    2334           0 :                 if( pTxtNd->HasHiddenCharAttribute( true ) ||  ( pTxtNd->HasHiddenCharAttribute( false ) ) )
    2335             :                 {
    2336           0 :                     bRet = true;
    2337           0 :                 }
    2338             :             }
    2339             :         }
    2340             :     }
    2341             : 
    2342           0 :     if( ! bRet )
    2343             :     {
    2344           0 :         const SwSectionFmts& rSectFmts = GetSections();
    2345             :         sal_uInt16 n;
    2346             : 
    2347           0 :         for( n = rSectFmts.size(); !bRet && (n > 0); )
    2348             :         {
    2349           0 :             SwSectionFmt* pSectFmt = rSectFmts[ --n ];
    2350             :             // don't add sections in Undo/Redo
    2351           0 :             if( !pSectFmt->IsInNodesArr())
    2352           0 :                 continue;
    2353           0 :             SwSection* pSect = pSectFmt->GetSection();
    2354           0 :             if( pSect->IsHidden() )
    2355           0 :                 bRet = true;
    2356             :         }
    2357             :     }
    2358           0 :     return bRet;
    2359             : }
    2360             : 
    2361           0 : bool SwDoc::RestoreInvisibleContent()
    2362             : {
    2363           0 :     SwUndoId nLastUndoId(UNDO_EMPTY);
    2364           0 :     if (GetIDocumentUndoRedo().GetLastUndoInfo(0, & nLastUndoId)
    2365           0 :         && (UNDO_UI_DELETE_INVISIBLECNTNT == nLastUndoId))
    2366             :     {
    2367           0 :         GetIDocumentUndoRedo().Undo();
    2368           0 :         GetIDocumentUndoRedo().ClearRedo();
    2369           0 :         return true;
    2370             :     }
    2371           0 :     return false;
    2372             : }
    2373             : 
    2374           0 : bool SwDoc::ConvertFieldsToText()
    2375             : {
    2376           0 :     bool bRet = false;
    2377           0 :     LockExpFlds();
    2378           0 :     GetIDocumentUndoRedo().StartUndo( UNDO_UI_REPLACE, NULL );
    2379             : 
    2380           0 :     const SwFldTypes* pMyFldTypes = GetFldTypes();
    2381           0 :     sal_uInt16 nCount = pMyFldTypes->size();
    2382             :     //go backward, field types are removed
    2383           0 :     for(sal_uInt16 nType = nCount;  nType > 0;  --nType)
    2384             :     {
    2385           0 :         const SwFieldType *pCurType = (*pMyFldTypes)[nType - 1];
    2386             : 
    2387           0 :         if ( RES_POSTITFLD == pCurType->Which() )
    2388           0 :             continue;
    2389             : 
    2390           0 :         SwIterator<SwFmtFld,SwFieldType> aIter( *pCurType );
    2391           0 :         ::std::vector<const SwFmtFld*> aFieldFmts;
    2392           0 :         for( SwFmtFld* pCurFldFmt = aIter.First(); pCurFldFmt; pCurFldFmt = aIter.Next() )
    2393           0 :             aFieldFmts.push_back(pCurFldFmt);
    2394             : 
    2395           0 :         ::std::vector<const SwFmtFld*>::iterator aBegin = aFieldFmts.begin();
    2396           0 :         ::std::vector<const SwFmtFld*>::iterator aEnd = aFieldFmts.end();
    2397           0 :         while(aBegin != aEnd)
    2398             :         {
    2399           0 :             const SwTxtFld *pTxtFld = (*aBegin)->GetTxtFld();
    2400             :             // skip fields that are currently not in the document
    2401             :             // e.g. fields in undo or redo array
    2402             : 
    2403           0 :             bool bSkip = !pTxtFld ||
    2404           0 :                          !pTxtFld->GetpTxtNode()->GetNodes().IsDocNodes();
    2405             : 
    2406           0 :             if (!bSkip)
    2407             :             {
    2408           0 :                 bool bInHeaderFooter = IsInHeaderFooter(SwNodeIndex(*pTxtFld->GetpTxtNode()));
    2409           0 :                 const SwFmtFld& rFmtFld = pTxtFld->GetFmtFld();
    2410           0 :                 const SwField*  pField = rFmtFld.GetField();
    2411             : 
    2412             :                 //#i55595# some fields have to be excluded in headers/footers
    2413           0 :                 sal_uInt16 nWhich = pField->GetTyp()->Which();
    2414           0 :                 if(!bInHeaderFooter ||
    2415           0 :                         (nWhich != RES_PAGENUMBERFLD &&
    2416           0 :                         nWhich != RES_CHAPTERFLD &&
    2417           0 :                         nWhich != RES_GETEXPFLD&&
    2418           0 :                         nWhich != RES_SETEXPFLD&&
    2419           0 :                         nWhich != RES_INPUTFLD&&
    2420           0 :                         nWhich != RES_REFPAGEGETFLD&&
    2421             :                         nWhich != RES_REFPAGESETFLD))
    2422             :                 {
    2423           0 :                     OUString sText = pField->ExpandField(true);
    2424             :                     //database fields should not convert their command into text
    2425           0 :                     if( RES_DBFLD == pCurType->Which() && !static_cast<const SwDBField*>(pField)->IsInitialized())
    2426           0 :                         sText = "";
    2427             : 
    2428             :                     //now remove the field and insert the string
    2429           0 :                     SwPaM aPam1(*pTxtFld->GetpTxtNode(), *pTxtFld->GetStart());
    2430           0 :                     aPam1.Move();
    2431             :                     //insert first to keep the field's attributes
    2432           0 :                     if (!sText.isEmpty())
    2433           0 :                         InsertString( aPam1, sText );
    2434           0 :                     SwPaM aPam2(*pTxtFld->GetpTxtNode(), *pTxtFld->GetStart());
    2435           0 :                     aPam2.SetMark();
    2436           0 :                     aPam2.Move();
    2437           0 :                     DeleteAndJoin(aPam2);//remove the field
    2438           0 :                     bRet=true;
    2439             :                 }
    2440             :             }
    2441           0 :             ++aBegin;
    2442             :         }
    2443           0 :     }
    2444             : 
    2445           0 :     if( bRet )
    2446           0 :         SetModified();
    2447           0 :     GetIDocumentUndoRedo().EndUndo( UNDO_UI_REPLACE, NULL );
    2448           0 :     UnlockExpFlds();
    2449           0 :     return bRet;
    2450             : 
    2451             : }
    2452             : 
    2453          23 : bool SwDoc::IsVisibleLinks() const
    2454             : {
    2455          23 :     return mbVisibleLinks;
    2456             : }
    2457             : 
    2458          16 : void SwDoc::SetVisibleLinks(bool bFlag)
    2459             : {
    2460          16 :     mbVisibleLinks = bFlag;
    2461          16 : }
    2462             : 
    2463       24115 : sfx2::LinkManager& SwDoc::GetLinkManager()
    2464             : {
    2465       24115 :     return *mpLinkMgr;
    2466             : }
    2467             : 
    2468          60 : const sfx2::LinkManager& SwDoc::GetLinkManager() const
    2469             : {
    2470          60 :     return *mpLinkMgr;
    2471             : }
    2472             : 
    2473          48 : void SwDoc::SetLinksUpdated(const bool bNewLinksUpdated)
    2474             : {
    2475          48 :     mbLinksUpdated = bNewLinksUpdated;
    2476          48 : }
    2477             : 
    2478         393 : bool SwDoc::LinksUpdated() const
    2479             : {
    2480         393 :     return mbLinksUpdated;
    2481             : }
    2482             : 
    2483           0 : static ::sfx2::SvBaseLink* lcl_FindNextRemovableLink( const ::sfx2::SvBaseLinks& rLinks, sfx2::LinkManager& rLnkMgr )
    2484             : {
    2485           0 :     for( sal_uInt16 n = 0; n < rLinks.size(); ++n )
    2486             :     {
    2487           0 :         ::sfx2::SvBaseLink* pLnk = &(*rLinks[ n ]);
    2488           0 :         if( pLnk &&
    2489           0 :             ( OBJECT_CLIENT_GRF == pLnk->GetObjType() ||
    2490           0 :               OBJECT_CLIENT_FILE == pLnk->GetObjType() ) &&
    2491           0 :             pLnk->ISA( SwBaseLink ) )
    2492             :         {
    2493           0 :                 ::sfx2::SvBaseLinkRef xLink = pLnk;
    2494             : 
    2495           0 :                 OUString sFName;
    2496           0 :                 rLnkMgr.GetDisplayNames( xLink, 0, &sFName, 0, 0 );
    2497             : 
    2498           0 :                 INetURLObject aURL( sFName );
    2499           0 :                 if( INET_PROT_FILE == aURL.GetProtocol() ||
    2500           0 :                     INET_PROT_CID == aURL.GetProtocol() )
    2501           0 :                     return pLnk;
    2502             :         }
    2503             :     }
    2504           0 :     return 0;
    2505             : }
    2506             : 
    2507             : /// embedded all local links (Areas/Graphics)
    2508           0 : bool SwDoc::EmbedAllLinks()
    2509             : {
    2510           0 :     bool bRet = false;
    2511           0 :     sfx2::LinkManager& rLnkMgr = GetLinkManager();
    2512           0 :     const ::sfx2::SvBaseLinks& rLinks = rLnkMgr.GetLinks();
    2513           0 :     if( !rLinks.empty() )
    2514             :     {
    2515           0 :         ::sw::UndoGuard const undoGuard(GetIDocumentUndoRedo());
    2516             : 
    2517           0 :         ::sfx2::SvBaseLink* pLnk = 0;
    2518           0 :         while( 0 != (pLnk = lcl_FindNextRemovableLink( rLinks, rLnkMgr ) ) )
    2519             :         {
    2520           0 :             ::sfx2::SvBaseLinkRef xLink = pLnk;
    2521             :             // Tell the link that it's being destroyed!
    2522           0 :             xLink->Closed();
    2523             : 
    2524             :             // if one forgot to remove itself
    2525           0 :             if( xLink.Is() )
    2526           0 :                 rLnkMgr.Remove( xLink );
    2527             : 
    2528           0 :             bRet = true;
    2529           0 :         }
    2530             : 
    2531           0 :         GetIDocumentUndoRedo().DelAllUndoObj();
    2532           0 :         SetModified();
    2533             :     }
    2534           0 :     return bRet;
    2535             : }
    2536             : 
    2537           0 : sal_Bool SwDoc::IsInsTblFormatNum() const
    2538             : {
    2539           0 :     return SW_MOD()->IsInsTblFormatNum(get(IDocumentSettingAccess::HTML_MODE));
    2540             : }
    2541             : 
    2542           0 : sal_Bool SwDoc::IsInsTblChangeNumFormat() const
    2543             : {
    2544           0 :     return SW_MOD()->IsInsTblChangeNumFormat(get(IDocumentSettingAccess::HTML_MODE));
    2545             : }
    2546             : 
    2547          77 : sal_Bool SwDoc::IsInsTblAlignNum() const
    2548             : {
    2549          77 :     return SW_MOD()->IsInsTblAlignNum(get(IDocumentSettingAccess::HTML_MODE));
    2550             : }
    2551             : 
    2552             : /// Set up the InsertDB as Undo table
    2553           0 : void SwDoc::AppendUndoForInsertFromDB( const SwPaM& rPam, sal_Bool bIsTable )
    2554             : {
    2555           0 :     if( bIsTable )
    2556             :     {
    2557           0 :         const SwTableNode* pTblNd = rPam.GetPoint()->nNode.GetNode().FindTableNode();
    2558           0 :         if( pTblNd )
    2559             :         {
    2560           0 :             SwUndoCpyTbl* pUndo = new SwUndoCpyTbl;
    2561           0 :             pUndo->SetTableSttIdx( pTblNd->GetIndex() );
    2562           0 :             GetIDocumentUndoRedo().AppendUndo( pUndo );
    2563             :         }
    2564             :     }
    2565           0 :     else if( rPam.HasMark() )
    2566             :     {
    2567           0 :         SwUndoCpyDoc* pUndo = new SwUndoCpyDoc( rPam );
    2568           0 :         pUndo->SetInsertRange( rPam, false );
    2569           0 :         GetIDocumentUndoRedo().AppendUndo( pUndo );
    2570             :     }
    2571           0 : }
    2572             : 
    2573           0 : void SwDoc::ChgTOX(SwTOXBase & rTOX, const SwTOXBase & rNew)
    2574             : {
    2575           0 :     if (GetIDocumentUndoRedo().DoesUndo())
    2576             :     {
    2577           0 :         GetIDocumentUndoRedo().DelAllUndoObj();
    2578             : 
    2579           0 :         SwUndo * pUndo = new SwUndoTOXChange(&rTOX, rNew);
    2580             : 
    2581           0 :         GetIDocumentUndoRedo().AppendUndo(pUndo);
    2582             :     }
    2583             : 
    2584           0 :     rTOX = rNew;
    2585             : 
    2586           0 :     if (rTOX.ISA(SwTOXBaseSection))
    2587             :     {
    2588           0 :         static_cast<SwTOXBaseSection &>(rTOX).Update();
    2589           0 :         static_cast<SwTOXBaseSection &>(rTOX).UpdatePageNum();
    2590             :     }
    2591           0 : }
    2592             : 
    2593           0 : OUString SwDoc::GetPaMDescr(const SwPaM & rPam) const
    2594             : {
    2595           0 :     if (rPam.GetNode(true) == rPam.GetNode(false))
    2596             :     {
    2597           0 :         SwTxtNode * pTxtNode = rPam.GetNode(true)->GetTxtNode();
    2598             : 
    2599           0 :         if (0 != pTxtNode)
    2600             :         {
    2601           0 :             const sal_Int32 nStart = rPam.Start()->nContent.GetIndex();
    2602           0 :             const sal_Int32 nEnd = rPam.End()->nContent.GetIndex();
    2603             : 
    2604             :             return SW_RESSTR(STR_START_QUOTE)
    2605           0 :                 + ShortenString(pTxtNode->GetTxt().copy(nStart, nEnd - nStart),
    2606             :                                 nUndoStringLength,
    2607           0 :                                 SW_RESSTR(STR_LDOTS))
    2608           0 :                 + SW_RESSTR(STR_END_QUOTE);
    2609             :         }
    2610             :     }
    2611           0 :     else if (0 != rPam.GetNode(true))
    2612             :     {
    2613           0 :         if (0 != rPam.GetNode(false))
    2614             :         {
    2615           0 :             return SW_RESSTR(STR_PARAGRAPHS);
    2616             :         }
    2617           0 :         return OUString();
    2618             :     }
    2619             : 
    2620           0 :     return OUString("??");
    2621             : }
    2622             : 
    2623          83 : SwField * SwDoc::GetFieldAtPos(const SwPosition & rPos)
    2624             : {
    2625          83 :     SwTxtFld * const pAttr = GetTxtFldAtPos(rPos);
    2626             : 
    2627          83 :     return (pAttr) ? const_cast<SwField *>( pAttr->GetFmtFld().GetField() ) : 0;
    2628             : }
    2629             : 
    2630          83 : SwTxtFld * SwDoc::GetTxtFldAtPos(const SwPosition & rPos)
    2631             : {
    2632          83 :     SwTxtNode * const pNode = rPos.nNode.GetNode().GetTxtNode();
    2633             : 
    2634             :     return (pNode != NULL)
    2635          83 :         ? pNode->GetFldTxtAttrAt( rPos.nContent.GetIndex(), true )
    2636         166 :         : 0;
    2637             : }
    2638             : 
    2639           2 : bool SwDoc::ContainsHiddenChars() const
    2640             : {
    2641          26 :     for( sal_uLong n = GetNodes().Count(); n; )
    2642             :     {
    2643          22 :         SwNode* pNd = GetNodes()[ --n ];
    2644          24 :         if ( pNd->IsTxtNode() &&
    2645           2 :              ((SwTxtNode*)pNd)->HasHiddenCharAttribute( false ) )
    2646           0 :             return true;
    2647             :     }
    2648             : 
    2649           2 :     return false;
    2650             : }
    2651             : 
    2652      130974 : SwUnoCrsr* SwDoc::CreateUnoCrsr( const SwPosition& rPos, bool bTblCrsr )
    2653             : {
    2654             :     SwUnoCrsr* pNew;
    2655      130974 :     if( bTblCrsr )
    2656          34 :         pNew = new SwUnoTableCrsr( rPos );
    2657             :     else
    2658      130940 :         pNew = new SwUnoCrsr( rPos );
    2659             : 
    2660      130974 :     mpUnoCrsrTbl->insert( pNew );
    2661      130974 :     return pNew;
    2662             : }
    2663             : 
    2664         202 : void SwDoc::ChkCondColls()
    2665             : {
    2666        2317 :      for (sal_uInt16 n = 0; n < mpTxtFmtCollTbl->size(); n++)
    2667             :      {
    2668        2115 :         SwTxtFmtColl *pColl = (*mpTxtFmtCollTbl)[n];
    2669        2115 :         if (RES_CONDTXTFMTCOLL == pColl->Which())
    2670         201 :             pColl->CallSwClientNotify( SwAttrHint(RES_CONDTXTFMTCOLL) );
    2671             :      }
    2672         202 : }
    2673             : 
    2674             : uno::Reference< script::vba::XVBAEventProcessor >
    2675       81865 : SwDoc::GetVbaEventProcessor()
    2676             : {
    2677             : #ifndef DISABLE_SCRIPTING
    2678       81865 :     if( !mxVbaEvents.is() && mpDocShell && ooo::vba::isAlienWordDoc( *mpDocShell ) )
    2679             :     {
    2680             :         try
    2681             :         {
    2682       21088 :             uno::Reference< frame::XModel > xModel( mpDocShell->GetModel(), uno::UNO_SET_THROW );
    2683       42176 :             uno::Sequence< uno::Any > aArgs(1);
    2684       21088 :             aArgs[0] <<= xModel;
    2685       42189 :             mxVbaEvents.set( ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "com.sun.star.script.vba.VBATextEventProcessor" , aArgs ), uno::UNO_QUERY_THROW );
    2686             :         }
    2687       21088 :         catch( uno::Exception& )
    2688             :         {
    2689             :         }
    2690             :     }
    2691             : #endif
    2692       81865 :     return mxVbaEvents;
    2693             : }
    2694             : 
    2695         146 : void SwDoc::setExternalData(::sw::tExternalDataType eType,
    2696             :                             ::sw::tExternalDataPointer pPayload)
    2697             : {
    2698         146 :     m_externalData[eType] = pPayload;
    2699         146 : }
    2700             : 
    2701          24 : ::sw::tExternalDataPointer SwDoc::getExternalData(::sw::tExternalDataType eType)
    2702             : {
    2703          24 :     return m_externalData[eType];
    2704             : }
    2705             : 
    2706         542 : sal_uInt16 SwNumRuleTbl::GetPos(const SwNumRule* pRule) const
    2707             : {
    2708         542 :     const_iterator it = std::find(begin(), end(), pRule);
    2709         542 :     return it == end() ? USHRT_MAX : it - begin();
    2710             : }
    2711             : 
    2712        3848 : SwNumRuleTbl::~SwNumRuleTbl()
    2713             : {
    2714       18914 :     for(const_iterator it = begin(); it != end(); ++it)
    2715       16990 :         delete *it;
    2716        1924 : }
    2717             : 
    2718             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10