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

Generated by: LCOV version 1.10