LCOV - code coverage report
Current view: top level - sw/source/core/doc - doc.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 317 756 41.9 %
Date: 2015-06-13 12:38:46 Functions: 67 96 69.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <config_features.h>
      21             : 
      22             : #include <doc.hxx>
      23             : #include <DocumentFieldsManager.hxx>
      24             : #include <DocumentSettingManager.hxx>
      25             : #include <DocumentDrawModelManager.hxx>
      26             : #include <DocumentTimerManager.hxx>
      27             : #include <DocumentDeviceManager.hxx>
      28             : #include <DocumentChartDataProviderManager.hxx>
      29             : #include <DocumentLinksAdministrationManager.hxx>
      30             : #include <DocumentListItemsManager.hxx>
      31             : #include <DocumentListsManager.hxx>
      32             : #include <DocumentOutlineNodesManager.hxx>
      33             : #include <DocumentContentOperationsManager.hxx>
      34             : #include <DocumentRedlineManager.hxx>
      35             : #include <DocumentStatisticsManager.hxx>
      36             : #include <DocumentStateManager.hxx>
      37             : #include <DocumentStylePoolManager.hxx>
      38             : #include <DocumentLayoutManager.hxx>
      39             : #include <DocumentExternalDataManager.hxx>
      40             : #include <UndoManager.hxx>
      41             : #include <dbmgr.hxx>
      42             : #include <hintids.hxx>
      43             : #include <tools/globname.hxx>
      44             : #include <svx/svxids.hrc>
      45             : #include <rtl/random.h>
      46             : 
      47             : #include <com/sun/star/i18n/WordType.hpp>
      48             : #include <com/sun/star/i18n/ForbiddenCharacters.hpp>
      49             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      50             : #include <com/sun/star/beans/NamedValue.hpp>
      51             : #include <com/sun/star/beans/XPropertySet.hpp>
      52             : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
      53             : #include <com/sun/star/document/XDocumentProperties.hpp>
      54             : #include <comphelper/string.hxx>
      55             : #include <tools/urlobj.hxx>
      56             : #include <tools/poly.hxx>
      57             : #include <tools/multisel.hxx>
      58             : #include <rtl/ustring.hxx>
      59             : #include <vcl/virdev.hxx>
      60             : #include <svl/itemiter.hxx>
      61             : #include <svl/poolitem.hxx>
      62             : #include <unotools/syslocale.hxx>
      63             : #include <sfx2/printer.hxx>
      64             : #include <editeng/keepitem.hxx>
      65             : #include <editeng/charsetcoloritem.hxx>
      66             : #include <editeng/formatbreakitem.hxx>
      67             : #include <sfx2/linkmgr.hxx>
      68             : #include <svx/svdmodel.hxx>
      69             : #include <editeng/pbinitem.hxx>
      70             : #include <unotools/charclass.hxx>
      71             : #include <unotools/localedatawrapper.hxx>
      72             : #include <vcl/timer.hxx>
      73             : 
      74             : #include <swatrset.hxx>
      75             : #include <swmodule.hxx>
      76             : #include <fmtpdsc.hxx>
      77             : #include <fmtanchr.hxx>
      78             : #include <fmtrfmrk.hxx>
      79             : #include <fmtinfmt.hxx>
      80             : #include <fmtfld.hxx>
      81             : #include <txtfld.hxx>
      82             : #include <dbfld.hxx>
      83             : #include <txtinet.hxx>
      84             : #include <txtrfmrk.hxx>
      85             : #include <frmatr.hxx>
      86             : #include <pagefrm.hxx>
      87             : #include <rootfrm.hxx>
      88             : #include <swtable.hxx>
      89             : #include <pam.hxx>
      90             : #include <ndtxt.hxx>
      91             : #include <swundo.hxx>
      92             : #include <UndoCore.hxx>
      93             : #include <UndoInsert.hxx>
      94             : #include <UndoSplitMove.hxx>
      95             : #include <UndoTable.hxx>
      96             : #include <pagedesc.hxx>
      97             : #include <ndole.hxx>
      98             : #include <ndgrf.hxx>
      99             : #include <rolbck.hxx>
     100             : #include <doctxm.hxx>
     101             : #include <grfatr.hxx>
     102             : #include <poolfmt.hxx>
     103             : #include <mvsave.hxx>
     104             : #include <SwGrammarMarkUp.hxx>
     105             : #include <scriptinfo.hxx>
     106             : #include <acorrect.hxx>
     107             : #include <mdiexp.hxx>
     108             : #include <docstat.hxx>
     109             : #include <docary.hxx>
     110             : #include <redline.hxx>
     111             : #include <fldupde.hxx>
     112             : #include <swbaslnk.hxx>
     113             : #include <printdata.hxx>
     114             : #include <cmdid.h>
     115             : #include <statstr.hrc>
     116             : #include <comcore.hrc>
     117             : #include <SwUndoTOXChange.hxx>
     118             : #include <unocrsr.hxx>
     119             : #include <docsh.hxx>
     120             : #include <viewopt.hxx>
     121             : #include <docfld.hxx>
     122             : #include <docufld.hxx>
     123             : #include <viewsh.hxx>
     124             : #include <shellres.hxx>
     125             : #include <txtfrm.hxx>
     126             : #include <attrhint.hxx>
     127             : #include <view.hxx>
     128             : 
     129             : #include <wdocsh.hxx>
     130             : #include <prtopt.hxx>
     131             : #include <wrtsh.hxx>
     132             : 
     133             : #include <vector>
     134             : #include <map>
     135             : #include <osl/diagnose.h>
     136             : #include <osl/interlck.h>
     137             : #include <vbahelper/vbaaccesshelper.hxx>
     138             : #include <calbck.hxx>
     139             : 
     140             : /* @@@MAINTAINABILITY-HORROR@@@
     141             :    Probably unwanted dependency on SwDocShell
     142             : */
     143             : #include <layouter.hxx>
     144             : 
     145             : using namespace ::com::sun::star;
     146             : 
     147             : /* IInterface */
     148        9813 : sal_Int32 SwDoc::acquire()
     149             : {
     150             :     OSL_ENSURE(mReferenceCount >= 0, "Negative reference count detected! This is a sign for unbalanced acquire/release calls.");
     151        9813 :     return osl_atomic_increment(&mReferenceCount);
     152             : }
     153             : 
     154        9799 : sal_Int32 SwDoc::release()
     155             : {
     156             :     OSL_PRECOND(mReferenceCount >= 1, "Object is already released! Releasing it again leads to a negative reference count.");
     157        9799 :     return osl_atomic_decrement(&mReferenceCount);
     158             : }
     159             : 
     160        2083 : sal_Int32 SwDoc::getReferenceCount() const
     161             : {
     162             :     OSL_ENSURE(mReferenceCount >= 0, "Negative reference count detected! This is a sign for unbalanced acquire/release calls.");
     163        2083 :     return mReferenceCount;
     164             : }
     165             : 
     166        2483 : ::sw::MetaFieldManager & SwDoc::GetMetaFieldManager()
     167             : {
     168        2483 :     return *m_pMetaFieldManager;
     169             : }
     170             : 
     171        9899 : ::sw::UndoManager & SwDoc::GetUndoManager()
     172             : {
     173        9899 :     return *m_pUndoManager;
     174             : }
     175             : 
     176           0 : ::sw::UndoManager const & SwDoc::GetUndoManager() const
     177             : {
     178           0 :     return *m_pUndoManager;
     179             : }
     180             : 
     181             : 
     182     2538632 : IDocumentUndoRedo & SwDoc::GetIDocumentUndoRedo()
     183             : {
     184     2538632 :     return *m_pUndoManager;
     185             : }
     186             : 
     187        3833 : IDocumentUndoRedo const & SwDoc::GetIDocumentUndoRedo() const
     188             : {
     189        3833 :     return *m_pUndoManager;
     190             : }
     191             : 
     192             : /* IDocumentDrawModelAccess */
     193       88713 : IDocumentDrawModelAccess const & SwDoc::getIDocumentDrawModelAccess() const
     194             : {
     195       88713 :     return GetDocumentDrawModelManager();
     196             : }
     197             : 
     198     1019047 : IDocumentDrawModelAccess & SwDoc::getIDocumentDrawModelAccess()
     199             : {
     200     1019047 :     return GetDocumentDrawModelManager();
     201             : }
     202             : 
     203       88713 : ::sw::DocumentDrawModelManager const & SwDoc::GetDocumentDrawModelManager() const
     204             : {
     205       88713 :     return *m_pDocumentDrawModelManager;
     206             : }
     207             : 
     208     1034053 : ::sw::DocumentDrawModelManager & SwDoc::GetDocumentDrawModelManager()
     209             : {
     210     1034053 :     return *m_pDocumentDrawModelManager;
     211             : }
     212             : 
     213             : /* IDocumentSettingAccess */
     214         110 : IDocumentSettingAccess const & SwDoc::getIDocumentSettingAccess() const
     215             : {
     216         110 :     return GetDocumentSettingManager();
     217             : }
     218             : 
     219      642092 : IDocumentSettingAccess & SwDoc::getIDocumentSettingAccess()
     220             : {
     221      642092 :     return GetDocumentSettingManager();
     222             : }
     223             : 
     224     4027526 : ::sw::DocumentSettingManager & SwDoc::GetDocumentSettingManager()
     225             : {
     226     4027526 :     return *m_pDocumentSettingManager;
     227             : }
     228             : 
     229    52061960 : ::sw::DocumentSettingManager const & SwDoc::GetDocumentSettingManager() const
     230             : {
     231    52061960 :     return *m_pDocumentSettingManager;
     232             : }
     233             : 
     234         142 : sal_uInt32 SwDoc::getRsid() const
     235             : {
     236         142 :     return mnRsid;
     237             : }
     238             : 
     239         329 : void SwDoc::setRsid( sal_uInt32 nVal )
     240             : {
     241         329 :     static bool bHack = (getenv("LIBO_ONEWAY_STABLE_ODF_EXPORT") != NULL);
     242             : 
     243         329 :     sal_uInt32 nIncrease = 0;
     244         329 :     if (!bHack)
     245             :     {
     246             :         // Increase the rsid with a random number smaller than 2^17. This way we
     247             :         // expect to be able to edit a document 2^12 times before rsid overflows.
     248         329 :         static rtlRandomPool aPool = rtl_random_createPool();
     249         329 :         rtl_random_getBytes( aPool, &nIncrease, sizeof ( nIncrease ) );
     250         329 :         nIncrease &= ( 1<<17 ) - 1;
     251         329 :         nIncrease++; // make sure the new rsid is not the same
     252             :     }
     253         329 :     mnRsid = nVal + nIncrease;
     254         329 : }
     255             : 
     256          72 : sal_uInt32 SwDoc::getRsidRoot() const
     257             : {
     258          72 :     return mnRsidRoot;
     259             : }
     260             : 
     261         259 : void SwDoc::setRsidRoot( sal_uInt32 nVal )
     262             : {
     263         259 :     mnRsidRoot = nVal;
     264         259 : }
     265             : 
     266             : /* IDocumentChartDataProviderAccess */
     267           0 : IDocumentChartDataProviderAccess const & SwDoc::getIDocumentChartDataProviderAccess() const
     268             : {
     269           0 :     return *m_pDocumentChartDataProviderManager;
     270             : }
     271             : 
     272        5906 : IDocumentChartDataProviderAccess & SwDoc::getIDocumentChartDataProviderAccess()
     273             : {
     274        5906 :     return *m_pDocumentChartDataProviderManager;
     275             : }
     276             : 
     277             : // IDocumentDeviceAccess
     278      148362 : IDocumentDeviceAccess const & SwDoc::getIDocumentDeviceAccess() const
     279             : {
     280      148362 :     return *m_pDeviceAccess;
     281             : }
     282             : 
     283     1944046 : IDocumentDeviceAccess & SwDoc::getIDocumentDeviceAccess()
     284             : {
     285     1944046 :     return *m_pDeviceAccess;
     286             : }
     287             : 
     288             : //IDocumentTimerAccess
     289           0 : IDocumentTimerAccess const & SwDoc::getIDocumentTimerAccess() const
     290             : {
     291           0 :     return *m_pDocumentTimerManager;
     292             : }
     293             : 
     294      478924 : IDocumentTimerAccess & SwDoc::getIDocumentTimerAccess()
     295             : {
     296      478924 :     return *m_pDocumentTimerManager;
     297             : }
     298             : 
     299             : // IDocumentLinksAdministration
     300           0 : IDocumentLinksAdministration const & SwDoc::getIDocumentLinksAdministration() const
     301             : {
     302           0 :     return *m_pDocumentLinksAdministrationManager;
     303             : }
     304             : 
     305       41542 : IDocumentLinksAdministration & SwDoc::getIDocumentLinksAdministration()
     306             : {
     307       41542 :     return *m_pDocumentLinksAdministrationManager;
     308             : }
     309             : 
     310           0 : ::sw::DocumentLinksAdministrationManager const & SwDoc::GetDocumentLinksAdministrationManager() const
     311             : {
     312           0 :     return *m_pDocumentLinksAdministrationManager;
     313             : }
     314             : 
     315           0 : ::sw::DocumentLinksAdministrationManager & SwDoc::GetDocumentLinksAdministrationManager()
     316             : {
     317           0 :     return *m_pDocumentLinksAdministrationManager;
     318             : }
     319             : 
     320             : //IDocumentListItems
     321           0 : IDocumentListItems const & SwDoc::getIDocumentListItems() const
     322             : {
     323           0 :     return *m_pDocumentListItemsManager;
     324             : }
     325             : 
     326             : //IDocumentListItems
     327       12374 : IDocumentListItems & SwDoc::getIDocumentListItems()
     328             : {
     329       12374 :     return *m_pDocumentListItemsManager;
     330             : }
     331             : 
     332             : //IDocumentListsAccess
     333        6451 : IDocumentListsAccess const & SwDoc::getIDocumentListsAccess() const
     334             : {
     335        6451 :     return *m_pDocumentListsManager;
     336             : }
     337             : 
     338       35168 : IDocumentListsAccess & SwDoc::getIDocumentListsAccess()
     339             : {
     340       35168 :     return *m_pDocumentListsManager;
     341             : }
     342             : 
     343             : //IDocumentOutlinesNodes
     344           0 : IDocumentOutlineNodes const & SwDoc::getIDocumentOutlineNodes() const
     345             : {
     346           0 :     return *m_pDocumentOutlineNodesManager;
     347             : }
     348             : 
     349          40 : IDocumentOutlineNodes & SwDoc::getIDocumentOutlineNodes()
     350             : {
     351          40 :     return *m_pDocumentOutlineNodesManager;
     352             : }
     353             : 
     354             : //IDocumentContentOperations
     355          91 : IDocumentContentOperations const & SwDoc::getIDocumentContentOperations() const
     356             : {
     357          91 :     return *m_pDocumentContentOperationsManager;
     358             : }
     359             : 
     360      338608 : IDocumentContentOperations & SwDoc::getIDocumentContentOperations()
     361             : {
     362      338608 :     return *m_pDocumentContentOperationsManager;
     363             : }
     364             : 
     365        4328 : ::sw::DocumentContentOperationsManager const & SwDoc::GetDocumentContentOperationsManager() const
     366             : {
     367        4328 :     return *m_pDocumentContentOperationsManager;
     368             : }
     369         564 : ::sw::DocumentContentOperationsManager & SwDoc::GetDocumentContentOperationsManager()
     370             : {
     371         564 :     return *m_pDocumentContentOperationsManager;
     372             : }
     373             : 
     374             : //IDocumentRedlineAccess
     375   184262926 : IDocumentRedlineAccess const & SwDoc::getIDocumentRedlineAccess() const
     376             : {
     377   184262926 :     return *m_pDocumentRedlineManager;
     378             : }
     379             : 
     380     1153287 : IDocumentRedlineAccess& SwDoc::getIDocumentRedlineAccess()
     381             : {
     382     1153287 :     return *m_pDocumentRedlineManager;
     383             : }
     384             : 
     385           0 : ::sw::DocumentRedlineManager const & SwDoc::GetDocumentRedlineManager() const
     386             : {
     387           0 :     return *m_pDocumentRedlineManager;
     388             : }
     389             : 
     390         241 : ::sw::DocumentRedlineManager& SwDoc::GetDocumentRedlineManager()
     391             : {
     392         241 :     return *m_pDocumentRedlineManager;
     393             : }
     394             : 
     395             : //IDocumentFieldsAccess
     396             : 
     397         173 : IDocumentFieldsAccess const & SwDoc::getIDocumentFieldsAccess() const
     398             : {
     399         173 :     return *m_pDocumentFieldsManager;
     400             : }
     401             : 
     402      104752 : IDocumentFieldsAccess & SwDoc::getIDocumentFieldsAccess()
     403             : {
     404      104752 :     return *m_pDocumentFieldsManager;
     405             : }
     406             : 
     407        3080 : ::sw::DocumentFieldsManager & SwDoc::GetDocumentFieldsManager()
     408             : {
     409        3080 :     return *m_pDocumentFieldsManager;
     410             : }
     411             : 
     412             : //IDocumentStatistics
     413           0 : IDocumentStatistics const & SwDoc::getIDocumentStatistics() const
     414             : {
     415           0 :     return *m_pDocumentStatisticsManager;
     416             : }
     417             : 
     418    53561927 : IDocumentStatistics & SwDoc::getIDocumentStatistics()
     419             : {
     420    53561927 :     return *m_pDocumentStatisticsManager;
     421             : }
     422             : 
     423           0 : ::sw::DocumentStatisticsManager const & SwDoc::GetDocumentStatisticsManager() const
     424             : {
     425           0 :     return *m_pDocumentStatisticsManager;
     426             : }
     427             : 
     428     1001754 : ::sw::DocumentStatisticsManager & SwDoc::GetDocumentStatisticsManager()
     429             : {
     430     1001754 :     return *m_pDocumentStatisticsManager;
     431             : }
     432             : 
     433             : //IDocumentState
     434         157 : IDocumentState const & SwDoc::getIDocumentState() const
     435             : {
     436         157 :     return *m_pDocumentStateManager;
     437             : }
     438             : 
     439     1220620 : IDocumentState & SwDoc::getIDocumentState()
     440             : {
     441     1220620 :     return *m_pDocumentStateManager;
     442             : }
     443             : 
     444             : //IDocumentLayoutAccess
     445     3526942 : IDocumentLayoutAccess const & SwDoc::getIDocumentLayoutAccess() const
     446             : {
     447     3526942 :     return *m_pDocumentLayoutManager;
     448             : }
     449             : 
     450   108669621 : IDocumentLayoutAccess & SwDoc::getIDocumentLayoutAccess()
     451             : {
     452   108669621 :     return *m_pDocumentLayoutManager;
     453             : }
     454             : 
     455           0 : ::sw::DocumentLayoutManager const & SwDoc::GetDocumentLayoutManager() const
     456             : {
     457           0 :     return *m_pDocumentLayoutManager;
     458             : }
     459             : 
     460     1004792 : ::sw::DocumentLayoutManager & SwDoc::GetDocumentLayoutManager()
     461             : {
     462     1004792 :     return *m_pDocumentLayoutManager;
     463             : }
     464             : 
     465             : //IDocumentStylePoolAccess
     466         237 : IDocumentStylePoolAccess const & SwDoc::getIDocumentStylePoolAccess() const
     467             : {
     468         237 :     return *m_pDocumentStylePoolManager;
     469             : }
     470             : 
     471     4540411 : IDocumentStylePoolAccess & SwDoc::getIDocumentStylePoolAccess()
     472             : {
     473     4540411 :     return *m_pDocumentStylePoolManager;
     474             : }
     475             : 
     476             : //IDocumentExternalData
     477           0 : IDocumentExternalData const & SwDoc::getIDocumentExternalData() const
     478             : {
     479           0 :     return *m_pDocumentExternalDataManager;
     480             : }
     481             : 
     482         314 : IDocumentExternalData & SwDoc::getIDocumentExternalData()
     483             : {
     484         314 :     return *m_pDocumentExternalDataManager;
     485             : }
     486             : 
     487             : /* Implementations the next Interface here */
     488             : 
     489             : /*
     490             :  * Document editing (Doc-SS) to fill the document
     491             :  * by the RTF parser and for the EditShell.
     492             :  */
     493         860 : void SwDoc::ChgDBData(const SwDBData& rNewData)
     494             : {
     495         860 :     if( rNewData != maDBData )
     496             :     {
     497         132 :         maDBData = rNewData;
     498         132 :         getIDocumentState().SetModified();
     499             :     }
     500         860 :     getIDocumentFieldsAccess().GetSysFieldType(RES_DBNAMEFLD)->UpdateFields();
     501         860 : }
     502             : 
     503             : struct _PostItField : public _SetGetExpField
     504             : {
     505           0 :     _PostItField( const SwNodeIndex& rNdIdx, const SwTextField* pField,  const SwIndex* pIdx = 0 )
     506           0 :         : _SetGetExpField( rNdIdx, pField, pIdx ) {}
     507             : 
     508             :     sal_uInt16 GetPageNo( const StringRangeEnumerator &rRangeEnum,
     509             :             const std::set< sal_Int32 > &rPossiblePages,
     510             :             sal_uInt16& rVirtPgNo, sal_uInt16& rLineNo );
     511             : 
     512           0 :     const SwPostItField* GetPostIt() const
     513             :     {
     514           0 :         return static_cast<const SwPostItField*>( GetTextField()->GetFormatField().GetField() );
     515             :     }
     516             : };
     517             : 
     518           0 : sal_uInt16 _PostItField::GetPageNo(
     519             :     const StringRangeEnumerator &rRangeEnum,
     520             :     const std::set< sal_Int32 > &rPossiblePages,
     521             :     /* out */ sal_uInt16& rVirtPgNo, /* out */ sal_uInt16& rLineNo )
     522             : {
     523             :     //Problem: If a PostItField is contained in a Node that is represented
     524             :     //by more than one layout instance,
     525             :     //we have to decide whether it should be printed once or n-times.
     526             :     //Probably only once. For the page number we don't select a random one,
     527             :     //but the PostIt's first occurrence in the selected area.
     528           0 :     rVirtPgNo = 0;
     529           0 :     const sal_Int32 nPos = GetContent();
     530           0 :     SwIterator<SwTextFrm,SwTextNode> aIter( GetTextField()->GetTextNode() );
     531           0 :     for( SwTextFrm* pFrm = aIter.First(); pFrm;  pFrm = aIter.Next() )
     532             :     {
     533           0 :         if( pFrm->GetOfst() > nPos ||
     534           0 :             (pFrm->HasFollow() && pFrm->GetFollow()->GetOfst() <= nPos) )
     535           0 :             continue;
     536           0 :         sal_uInt16 nPgNo = pFrm->GetPhyPageNum();
     537           0 :         if( rRangeEnum.hasValue( nPgNo, &rPossiblePages ))
     538             :         {
     539           0 :             rLineNo = (sal_uInt16)(pFrm->GetLineCount( nPos ) +
     540           0 :                       pFrm->GetAllLines() - pFrm->GetThisLines());
     541           0 :             rVirtPgNo = pFrm->GetVirtPageNum();
     542           0 :             return nPgNo;
     543             :         }
     544             :     }
     545           0 :     return 0;
     546             : }
     547             : 
     548           1 : bool sw_GetPostIts(
     549             :     IDocumentFieldsAccess* pIDFA,
     550             :     _SetGetExpFields * pSrtLst )
     551             : {
     552           1 :     bool bHasPostIts = false;
     553             : 
     554           1 :     SwFieldType* pFieldType = pIDFA->GetSysFieldType( RES_POSTITFLD );
     555             :     OSL_ENSURE( pFieldType, "no PostItType ? ");
     556             : 
     557           1 :     if( pFieldType->HasWriterListeners() )
     558             :     {
     559             :         // Found modify object; insert all fields into the array
     560           0 :         SwIterator<SwFormatField,SwFieldType> aIter( *pFieldType );
     561           0 :         for( SwFormatField* pField = aIter.First(); pField;  pField = aIter.Next() )
     562             :         {
     563             :             const SwTextField* pTextField;
     564           0 :             if( 0 != ( pTextField = pField->GetTextField() ) &&
     565           0 :                 pTextField->GetTextNode().GetNodes().IsDocNodes() )
     566             :             {
     567           0 :                 bHasPostIts = true;
     568           0 :                 if (pSrtLst)
     569             :                 {
     570           0 :                     SwNodeIndex aIdx( pTextField->GetTextNode() );
     571           0 :                     _PostItField* pNew = new _PostItField( aIdx, pTextField );
     572           0 :                     pSrtLst->insert( pNew );
     573             :                 }
     574             :                 else
     575           0 :                     break;  // we just wanted to check for the existence of postits ...
     576             :             }
     577           0 :         }
     578             :     }
     579             : 
     580           1 :     return bHasPostIts;
     581             : }
     582             : 
     583           0 : static void lcl_FormatPostIt(
     584             :     IDocumentContentOperations* pIDCO,
     585             :     SwPaM& aPam,
     586             :     const SwPostItField* pField,
     587             :     bool bNewPage, bool bIsFirstPostIt,
     588             :     sal_uInt16 nPageNo, sal_uInt16 nLineNo )
     589             : {
     590             :     static char const sTmp[] = " : ";
     591             : 
     592             :     OSL_ENSURE( SwViewShell::GetShellRes(), "missing ShellRes" );
     593             : 
     594           0 :     if (bNewPage)
     595             :     {
     596           0 :         pIDCO->InsertPoolItem( aPam, SvxFormatBreakItem( SVX_BREAK_PAGE_AFTER, RES_BREAK ) );
     597           0 :         pIDCO->SplitNode( *aPam.GetPoint(), false );
     598             :     }
     599           0 :     else if (!bIsFirstPostIt)
     600             :     {
     601             :         // add an empty line between different notes
     602           0 :         pIDCO->SplitNode( *aPam.GetPoint(), false );
     603           0 :         pIDCO->SplitNode( *aPam.GetPoint(), false );
     604             :     }
     605             : 
     606           0 :     OUString aStr( SwViewShell::GetShellRes()->aPostItPage );
     607           0 :     aStr += sTmp;
     608             : 
     609           0 :     aStr += OUString::number( nPageNo );
     610           0 :     aStr += " ";
     611           0 :     if( nLineNo )
     612             :     {
     613           0 :         aStr += SwViewShell::GetShellRes()->aPostItLine;
     614           0 :         aStr += sTmp;
     615           0 :         aStr += OUString::number( nLineNo );
     616           0 :         aStr += " ";
     617             :     }
     618           0 :     aStr += SwViewShell::GetShellRes()->aPostItAuthor;
     619           0 :     aStr += sTmp;
     620           0 :     aStr += pField->GetPar1();
     621           0 :     aStr += " ";
     622           0 :     SvtSysLocale aSysLocale;
     623           0 :     aStr += /*(LocaleDataWrapper&)*/aSysLocale.GetLocaleData().getDate( pField->GetDate() );
     624           0 :     pIDCO->InsertString( aPam, aStr );
     625             : 
     626           0 :     pIDCO->SplitNode( *aPam.GetPoint(), false );
     627           0 :     aStr = pField->GetPar2();
     628             : #if defined( WNT )
     629             :     // Throw out all CR in Windows
     630             :     aStr = comphelper::string::remove(aStr, '\r');
     631             : #endif
     632           0 :     pIDCO->InsertString( aPam, aStr );
     633           0 : }
     634             : 
     635             : /// provide the paper tray to use according to the page style in use,
     636             : /// but do that only if the respective item is NOT just the default item
     637           1 : static sal_Int32 lcl_GetPaperBin( const SwPageFrm *pStartFrm )
     638             : {
     639           1 :     sal_Int32 nRes = -1;
     640             : 
     641           1 :     const SwFrameFormat &rFormat = pStartFrm->GetPageDesc()->GetMaster();
     642           1 :     const SfxPoolItem *pItem = NULL;
     643           1 :     SfxItemState eState = rFormat.GetItemState( RES_PAPER_BIN, false, &pItem );
     644           1 :     const SvxPaperBinItem *pPaperBinItem = dynamic_cast< const SvxPaperBinItem * >(pItem);
     645           1 :     if (eState > SfxItemState::DEFAULT && pPaperBinItem)
     646           0 :         nRes = pPaperBinItem->GetValue();
     647             : 
     648           1 :     return nRes;
     649             : }
     650             : 
     651           1 : void SwDoc::CalculatePagesForPrinting(
     652             :     const SwRootFrm& rLayout,
     653             :     /* out */ SwRenderData &rData,
     654             :     const SwPrintUIOptions &rOptions,
     655             :     bool bIsPDFExport,
     656             :     sal_Int32 nDocPageCount )
     657             : {
     658           1 :     const sal_Int64 nContent = rOptions.getIntValue( "PrintContent", 0 );
     659           1 :     const bool bPrintSelection = nContent == 2;
     660             : 
     661             :     // properties to take into account when calculating the set of pages
     662             :     // (PDF export UI does not allow for selecting left or right pages only)
     663           1 :     bool bPrintLeftPages    = bIsPDFExport || rOptions.IsPrintLeftPages();
     664           1 :     bool bPrintRightPages   = bIsPDFExport || rOptions.IsPrintRightPages();
     665             :     // #i103700# printing selections should not allow for automatic inserting empty pages
     666           1 :     bool bPrintEmptyPages   = !bPrintSelection && rOptions.IsPrintEmptyPages( bIsPDFExport );
     667             : 
     668           1 :     std::map< sal_Int32, sal_Int32 > &rPrinterPaperTrays = rData.GetPrinterPaperTrays();
     669           1 :     std::set< sal_Int32 > &rValidPages = rData.GetValidPagesSet();
     670           1 :     rValidPages.clear();
     671             : 
     672           1 :     sal_Int32 nPageNum = 1;
     673           1 :     const SwPageFrm *pStPage = dynamic_cast<const SwPageFrm*>( rLayout.Lower() );
     674           3 :     while (pStPage && nPageNum <= nDocPageCount)
     675             :     {
     676             :         const bool bPrintThisPage =
     677           1 :             ( (bPrintRightPages && pStPage->OnRightPage()) ||
     678           2 :               (bPrintLeftPages && !pStPage->OnRightPage()) ) &&
     679           1 :             ( bPrintEmptyPages || pStPage->Frm().Height() );
     680             : 
     681           1 :         if (bPrintThisPage)
     682             :         {
     683           1 :             rValidPages.insert( nPageNum );
     684           1 :             rPrinterPaperTrays[ nPageNum ] = lcl_GetPaperBin( pStPage );
     685             :         }
     686             : 
     687           1 :         ++nPageNum;
     688           1 :         pStPage = static_cast<const SwPageFrm*>(pStPage->GetNext());
     689             :     }
     690             : 
     691             :     // now that we have identified the valid pages for printing according
     692             :     // to the print settings we need to get the PageRange to use and
     693             :     // use both results to get the actual pages to be printed
     694             :     // (post-it settings need to be taken into account later on!)
     695             : 
     696             :     // get PageRange value to use
     697           1 :     OUString aPageRange;
     698             :     // #i116085# - adjusting fix for i113919
     699           1 :     if ( !bIsPDFExport )
     700             :     {
     701             :         // PageContent :
     702             :         // 0 -> print all pages (default if aPageRange is empty)
     703             :         // 1 -> print range according to PageRange
     704             :         // 2 -> print selection
     705           1 :         if (1 == nContent)
     706           0 :             aPageRange = rOptions.getStringValue( "PageRange", OUString() );
     707             :         if (2 == nContent)
     708             :         {
     709             :             // note that printing selections is actually implemented by copying
     710             :             // the selection to a new temporary document and printing all of that one.
     711             :             // Thus for Writer "PrintContent" must never be 2.
     712             :             // See SwXTextDocument::GetRenderDoc for evaluating if a selection is to be
     713             :             // printed and for creating the temporary document.
     714             :         }
     715             : 
     716             :         // please note
     717             :     }
     718           1 :     if (aPageRange.isEmpty())    // empty string -> print all
     719             :     {
     720             :         // set page range to print to 'all pages'
     721           1 :         aPageRange = OUString::number( 1 ) + "-" + OUString::number( nDocPageCount );
     722             :     }
     723           1 :     rData.SetPageRange( aPageRange );
     724             : 
     725             :     // get vector of pages to print according to PageRange and valid pages set from above
     726             :     // (result may be an empty vector, for example if the range string is not correct)
     727             :     StringRangeEnumerator::getRangesFromString(
     728           1 :             aPageRange, rData.GetPagesToPrint(),
     729           2 :             1, nDocPageCount, 0, &rData.GetValidPagesSet() );
     730           1 : }
     731             : 
     732           0 : void SwDoc::UpdatePagesForPrintingWithPostItData(
     733             :     /* out */ SwRenderData &rData,
     734             :     const SwPrintUIOptions &rOptions,
     735             :     bool /*bIsPDFExport*/,
     736             :     sal_Int32 nDocPageCount )
     737             : {
     738             : 
     739           0 :     sal_Int16 nPostItMode = (sal_Int16) rOptions.getIntValue( "PrintAnnotationMode", 0 );
     740             :     OSL_ENSURE(nPostItMode == POSTITS_NONE || rData.HasPostItData(),
     741             :             "print post-its without post-it data?" );
     742             :     const _SetGetExpFields::size_type nPostItCount =
     743           0 :         rData.HasPostItData() ? rData.m_pPostItFields->size() : 0;
     744           0 :     if (nPostItMode != POSTITS_NONE && nPostItCount > 0)
     745             :     {
     746           0 :         SET_CURR_SHELL( rData.m_pPostItShell.get() );
     747             : 
     748             :         // clear document and move to end of it
     749           0 :         SwDoc & rPostItDoc(*rData.m_pPostItShell->GetDoc());
     750           0 :         SwPaM aPam(rPostItDoc.GetNodes().GetEndOfContent());
     751           0 :         aPam.Move( fnMoveBackward, fnGoDoc );
     752           0 :         aPam.SetMark();
     753           0 :         aPam.Move( fnMoveForward, fnGoDoc );
     754           0 :         rPostItDoc.getIDocumentContentOperations().DeleteRange( aPam );
     755             : 
     756           0 :         const StringRangeEnumerator aRangeEnum( rData.GetPageRange(), 1, nDocPageCount, 0 );
     757             : 
     758             :         // For mode POSTITS_ENDPAGE:
     759             :         // maps a physical page number to the page number in post-it document that holds
     760             :         // the first post-it for that physical page . Needed to relate the correct start frames
     761             :         // from the post-it doc to the physical page of the document
     762           0 :         std::map< sal_Int32, sal_Int32 >  aPostItLastStartPageNum;
     763             : 
     764             :         // add all post-its on valid pages within the page range to the
     765             :         // temporary post-it document.
     766             :         // Since the array of post-it fields is sorted by page and line number we will
     767             :         // already get them in the correct order
     768           0 :         sal_uInt16 nVirtPg = 0, nLineNo = 0, nLastPageNum = 0, nPhyPageNum = 0;
     769           0 :         bool bIsFirstPostIt = true;
     770           0 :         for (_SetGetExpFields::size_type i = 0; i < nPostItCount; ++i)
     771             :         {
     772           0 :             _PostItField& rPostIt = static_cast<_PostItField&>(*(*rData.m_pPostItFields)[ i ]);
     773           0 :             nLastPageNum = nPhyPageNum;
     774             :             nPhyPageNum = rPostIt.GetPageNo(
     775           0 :                     aRangeEnum, rData.GetValidPagesSet(), nVirtPg, nLineNo );
     776           0 :             if (nPhyPageNum)
     777             :             {
     778             :                 // need to insert a page break?
     779             :                 // In POSTITS_ENDPAGE mode for each document page the following
     780             :                 // post-it page needs to start on a new page
     781           0 :                 const bool bNewPage = nPostItMode == POSTITS_ENDPAGE &&
     782           0 :                         !bIsFirstPostIt && nPhyPageNum != nLastPageNum;
     783             : 
     784           0 :                 lcl_FormatPostIt( &rData.m_pPostItShell->GetDoc()->getIDocumentContentOperations(), aPam,
     785           0 :                         rPostIt.GetPostIt(), bNewPage, bIsFirstPostIt, nVirtPg, nLineNo );
     786           0 :                 bIsFirstPostIt = false;
     787             : 
     788           0 :                 if (nPostItMode == POSTITS_ENDPAGE)
     789             :                 {
     790             :                     // get the correct number of current pages for the post-it document
     791           0 :                     rData.m_pPostItShell->CalcLayout();
     792           0 :                     const sal_Int32 nPages = rData.m_pPostItShell->GetPageCount();
     793           0 :                     aPostItLastStartPageNum[ nPhyPageNum ] = nPages;
     794             :                 }
     795             :             }
     796             :         }
     797             : 
     798             :         // format post-it doc to get correct number of pages
     799           0 :         rData.m_pPostItShell->CalcLayout();
     800           0 :         const sal_Int32 nPostItDocPageCount = rData.m_pPostItShell->GetPageCount();
     801             : 
     802           0 :         if (nPostItMode == POSTITS_ONLY || nPostItMode == POSTITS_ENDDOC)
     803             :         {
     804             :             // now add those post-it pages to the vector of pages to print
     805             :             // or replace them if only post-its should be printed
     806             : 
     807           0 :             if (nPostItMode == POSTITS_ONLY)
     808             :             {
     809             :                 // no document page to be printed
     810           0 :                 rData.GetPagesToPrint().clear();
     811             :             }
     812             : 
     813             :             // now we just need to add the post-it pages to be printed to the
     814             :             // end of the vector of pages to print
     815           0 :             sal_Int32 nPageNum = 0;
     816           0 :             const SwPageFrm * pPageFrm = static_cast<SwPageFrm*>(rData.m_pPostItShell->GetLayout()->Lower());
     817           0 :             while( pPageFrm && nPageNum < nPostItDocPageCount )
     818             :             {
     819             :                 OSL_ENSURE( pPageFrm, "Empty page frame. How are we going to print this?" );
     820           0 :                 ++nPageNum;
     821             :                 // negative page number indicates page is from the post-it doc
     822           0 :                 rData.GetPagesToPrint().push_back( -nPageNum );
     823             :                 OSL_ENSURE( pPageFrm, "pPageFrm is NULL!" );
     824           0 :                 pPageFrm = static_cast<const SwPageFrm*>(pPageFrm->GetNext());
     825             :             }
     826           0 :             OSL_ENSURE( nPageNum == nPostItDocPageCount, "unexpected number of pages" );
     827             :         }
     828           0 :         else if (nPostItMode == POSTITS_ENDPAGE)
     829             :         {
     830             :             // the next step is to find all the pages from the post-it
     831             :             // document that should be printed for a given physical page
     832             :             // of the document
     833             : 
     834           0 :             std::vector< sal_Int32 >            aTmpPagesToPrint;
     835           0 :             sal_Int32 nLastPostItPage(0);
     836           0 :             const size_t nNum = rData.GetPagesToPrint().size();
     837           0 :             for (size_t i = 0 ;  i < nNum;  ++i)
     838             :             {
     839             :                 // add the physical page to print from the document
     840           0 :                 const sal_Int32 nPhysPage = rData.GetPagesToPrint()[i];
     841           0 :                 aTmpPagesToPrint.push_back( nPhysPage );
     842             : 
     843             :                 // add the post-it document pages to print, i.e those
     844             :                 // post-it pages that have the data for the above physical page
     845             :                 ::std::map<sal_Int32, sal_Int32>::const_iterator const iter(
     846           0 :                         aPostItLastStartPageNum.find(nPhysPage));
     847           0 :                 if (iter != aPostItLastStartPageNum.end())
     848             :                 {
     849           0 :                     for (sal_Int32 j = nLastPostItPage + 1;
     850           0 :                             j <= iter->second; ++j)
     851             :                     {
     852             :                         // negative page number indicates page is from the
     853           0 :                         aTmpPagesToPrint.push_back(-j); // post-it document
     854             :                     }
     855           0 :                     nLastPostItPage = iter->second;
     856             :                 }
     857             :             }
     858             : 
     859             :             // finally we need to assign those vectors to the resulting ones.
     860             :             // swapping the data should be more efficient than assigning since
     861             :             // we won't need the temporary vectors anymore
     862           0 :             rData.GetPagesToPrint().swap( aTmpPagesToPrint );
     863           0 :         }
     864             :     }
     865           0 : }
     866             : 
     867           0 : void SwDoc::CalculatePagePairsForProspectPrinting(
     868             :     const SwRootFrm& rLayout,
     869             :     /* out */ SwRenderData &rData,
     870             :     const SwPrintUIOptions &rOptions,
     871             :     sal_Int32 nDocPageCount )
     872             : {
     873           0 :     std::map< sal_Int32, sal_Int32 > &rPrinterPaperTrays = rData.GetPrinterPaperTrays();
     874           0 :     std::set< sal_Int32 > &rValidPagesSet = rData.GetValidPagesSet();
     875           0 :     std::vector< std::pair< sal_Int32, sal_Int32 > > &rPagePairs = rData.GetPagePairsForProspectPrinting();
     876           0 :     std::map< sal_Int32, const SwPageFrm * > validStartFrms;
     877             : 
     878           0 :     rPagePairs.clear();
     879           0 :     rValidPagesSet.clear();
     880             : 
     881           0 :     OUString aPageRange;
     882             :     // PageContent :
     883             :     // 0 -> print all pages (default if aPageRange is empty)
     884             :     // 1 -> print range according to PageRange
     885             :     // 2 -> print selection
     886           0 :     const sal_Int64 nContent = rOptions.getIntValue( "PrintContent", 0 );
     887           0 :     if (nContent == 1)
     888           0 :         aPageRange = rOptions.getStringValue( "PageRange", OUString() );
     889           0 :     if (aPageRange.isEmpty())    // empty string -> print all
     890             :     {
     891             :         // set page range to print to 'all pages'
     892           0 :         aPageRange = OUString::number( 1 ) + "-" + OUString::number( nDocPageCount );
     893             :     }
     894           0 :     StringRangeEnumerator aRange( aPageRange, 1, nDocPageCount, 0 );
     895             : 
     896           0 :     if ( aRange.size() <= 0)
     897           0 :         return;
     898             : 
     899           0 :     const SwPageFrm *pStPage  = dynamic_cast<const SwPageFrm*>( rLayout.Lower() );
     900           0 :     for ( sal_Int32 i = 1; pStPage && i < nDocPageCount; ++i )
     901           0 :         pStPage = static_cast<const SwPageFrm*>(pStPage->GetNext());
     902           0 :     if ( !pStPage )          // Then it was that
     903           0 :         return;
     904             : 
     905             :     // currently for prospect printing all pages are valid to be printed
     906             :     // thus we add them all to the respective map and set for later use
     907           0 :     sal_Int32 nPageNum = 0;
     908           0 :     const SwPageFrm *pPageFrm  = dynamic_cast<const SwPageFrm*>( rLayout.Lower() );
     909           0 :     while( pPageFrm && nPageNum < nDocPageCount )
     910             :     {
     911             :         OSL_ENSURE( pPageFrm, "Empty page frame. How are we going to print this?" );
     912           0 :         ++nPageNum;
     913           0 :         rValidPagesSet.insert( nPageNum );
     914           0 :         validStartFrms[ nPageNum ] = pPageFrm;
     915           0 :         pPageFrm = static_cast<const SwPageFrm*>(pPageFrm->GetNext());
     916             : 
     917           0 :         rPrinterPaperTrays[ nPageNum ] = lcl_GetPaperBin( pStPage );
     918             :     }
     919             :     OSL_ENSURE( nPageNum == nDocPageCount, "unexpected number of pages" );
     920             : 
     921             :     // properties to take into account when calculating the set of pages
     922             :     // Note: here bPrintLeftPages and bPrintRightPages refer to the (virtual) resulting pages
     923             :     //      of the prospect!
     924           0 :     bool bPrintLeftPages     = rOptions.IsPrintLeftPages();
     925           0 :     bool bPrintRightPages    = rOptions.IsPrintRightPages();
     926           0 :     bool bPrintProspectRTL = rOptions.getIntValue( "PrintProspectRTL",  0 ) != 0;
     927             : 
     928             :     // get pages for prospect printing according to the 'PageRange'
     929             :     // (duplicates and any order allowed!)
     930           0 :     std::vector< sal_Int32 > aPagesToPrint;
     931             :     StringRangeEnumerator::getRangesFromString(
     932           0 :             aPageRange, aPagesToPrint, 1, nDocPageCount, 0 );
     933             : 
     934           0 :     if (aPagesToPrint.empty())
     935           0 :         return;
     936             : 
     937             :     // now fill the vector for calculating the page pairs with the start frames
     938             :     // from the above obtained vector
     939           0 :     std::vector< const SwPageFrm * > aVec;
     940           0 :     for ( std::vector< sal_Int32 >::size_type i = 0; i < aPagesToPrint.size(); ++i)
     941             :     {
     942           0 :         const sal_Int32 nPage = aPagesToPrint[i];
     943           0 :         const SwPageFrm *pFrm = validStartFrms[ nPage ];
     944           0 :         aVec.push_back( pFrm );
     945             :     }
     946             : 
     947             :     // just one page is special ...
     948           0 :     if ( 1 == aVec.size() )
     949           0 :         aVec.insert( aVec.begin() + 1, nullptr ); // insert a second empty page
     950             :     else
     951             :     {
     952             :         // now extend the number of pages to fit a multiple of 4
     953             :         // (4 'normal' pages are needed for a single prospect paper
     954             :         //  with back and front)
     955           0 :         while( aVec.size() & 3 )
     956           0 :             aVec.push_back( 0 );
     957             :     }
     958             : 
     959             :     // make sure that all pages are in correct order
     960           0 :     std::vector< const SwPageFrm * >::size_type nSPg = 0;
     961           0 :     std::vector< const SwPageFrm * >::size_type nEPg = aVec.size();
     962           0 :     sal_Int32 nStep = 1;
     963           0 :     if ( 0 == (nEPg & 1 ))      // there are no uneven ones!
     964           0 :         --nEPg;
     965             : 
     966           0 :     if ( !bPrintLeftPages )
     967           0 :         ++nStep;
     968           0 :     else if ( !bPrintRightPages )
     969             :     {
     970           0 :         ++nStep;
     971           0 :         ++nSPg, --nEPg;
     972             :     }
     973             : 
     974             :     // the number of 'virtual' pages to be printed
     975           0 :     sal_Int32 nCntPage = (( nEPg - nSPg ) / ( 2 * nStep )) + 1;
     976             : 
     977           0 :     for ( sal_Int32 nPrintCount = 0; nSPg < nEPg &&
     978             :             nPrintCount < nCntPage; ++nPrintCount )
     979             :     {
     980           0 :         pStPage = aVec[ nSPg ];
     981           0 :         const SwPageFrm* pNxtPage = nEPg < aVec.size() ? aVec[ nEPg ] : 0;
     982             : 
     983           0 :         short nRtlOfs = bPrintProspectRTL ? 1 : 0;
     984           0 :         if ( 0 == (( nSPg + nRtlOfs) & 1 ) )     // switch for odd number in LTR, even number in RTL
     985             :         {
     986           0 :             const SwPageFrm* pTmp = pStPage;
     987           0 :             pStPage = pNxtPage;
     988           0 :             pNxtPage = pTmp;
     989             :         }
     990             : 
     991           0 :         sal_Int32 nFirst = -1, nSecond = -1;
     992           0 :         for ( int nC = 0; nC < 2; ++nC )
     993             :         {
     994           0 :             sal_Int32 nPage = -1;
     995           0 :             if ( pStPage )
     996           0 :                 nPage = pStPage->GetPhyPageNum();
     997           0 :             if (nC == 0)
     998           0 :                 nFirst  = nPage;
     999             :             else
    1000           0 :                 nSecond = nPage;
    1001             : 
    1002           0 :             pStPage = pNxtPage;
    1003             :         }
    1004           0 :         rPagePairs.push_back( std::pair< sal_Int32, sal_Int32 >(nFirst, nSecond) );
    1005             : 
    1006           0 :         nSPg = nSPg + nStep;
    1007           0 :         nEPg = nEPg - nStep;
    1008             :     }
    1009           0 :     OSL_ENSURE( size_t(nCntPage) == rPagePairs.size(), "size mismatch for number of page pairs" );
    1010             : 
    1011             :     // luckily prospect printing does not make use of post-its so far,
    1012             :     // thus we are done here.
    1013             : }
    1014             : 
    1015             : /// @return the reference in the doc for the name
    1016          61 : const SwFormatRefMark* SwDoc::GetRefMark( const OUString& rName ) const
    1017             : {
    1018          61 :     sal_uInt32 nMaxItems = GetAttrPool().GetItemCount2( RES_TXTATR_REFMARK );
    1019         443 :     for( sal_uInt32 n = 0; n < nMaxItems; ++n )
    1020             :     {
    1021             :         const SfxPoolItem* pItem;
    1022         439 :         if( 0 == (pItem = GetAttrPool().GetItem2( RES_TXTATR_REFMARK, n ) ))
    1023         115 :             continue;
    1024             : 
    1025         324 :         const SwFormatRefMark* pFormatRef = static_cast<const SwFormatRefMark*>(pItem);
    1026         324 :         const SwTextRefMark* pTextRef = pFormatRef->GetTextRefMark();
    1027         442 :         if( pTextRef && &pTextRef->GetTextNode().GetNodes() == &GetNodes() &&
    1028         118 :             rName == pFormatRef->GetRefName() )
    1029          57 :             return pFormatRef;
    1030             :     }
    1031           4 :     return 0;
    1032             : }
    1033             : 
    1034             : /// @return the RefMark per index - for Uno
    1035           4 : const SwFormatRefMark* SwDoc::GetRefMark( sal_uInt16 nIndex ) const
    1036             : {
    1037             :     const SwTextRefMark* pTextRef;
    1038           4 :     const SwFormatRefMark* pRet = 0;
    1039             : 
    1040           4 :     sal_uInt32 nMaxItems = GetAttrPool().GetItemCount2( RES_TXTATR_REFMARK );
    1041           4 :     sal_uInt32 nCount = 0;
    1042          24 :     for( sal_uInt32 n = 0; n < nMaxItems; ++n )
    1043             :     {
    1044             :         const SfxPoolItem* pItem;
    1045             : 
    1046          61 :         if( 0 != (pItem = GetAttrPool().GetItem2( RES_TXTATR_REFMARK, n )) &&
    1047          30 :             0 != (pTextRef = static_cast<const SwFormatRefMark*>(pItem)->GetTextRefMark()) &&
    1048           7 :             &pTextRef->GetTextNode().GetNodes() == &GetNodes() )
    1049             :         {
    1050           7 :             if(nCount == nIndex)
    1051             :             {
    1052           3 :                 pRet = static_cast<const SwFormatRefMark*>(pItem);
    1053           3 :                 break;
    1054             :             }
    1055           4 :             nCount++;
    1056             :         }
    1057             :     }
    1058           4 :     return pRet;
    1059             : }
    1060             : 
    1061             : /// @return the names of all set references in the Doc
    1062             : //JP 24.06.96: If the array pointer is 0, then just return whether a RefMark is set in the Doc
    1063             : // OS 25.06.96: From now on we always return the reference count
    1064          43 : sal_uInt16 SwDoc::GetRefMarks( std::vector<OUString>* pNames ) const
    1065             : {
    1066             :     const SwTextRefMark* pTextRef;
    1067             : 
    1068          43 :     const sal_uInt32 nMaxItems = GetAttrPool().GetItemCount2( RES_TXTATR_REFMARK );
    1069          43 :     sal_uInt16 nCount = 0;
    1070          61 :     for( sal_uInt32 n = 0; n < nMaxItems; ++n )
    1071             :     {
    1072             :         const SfxPoolItem* pItem;
    1073             : 
    1074          48 :         if( 0 != (pItem = GetAttrPool().GetItem2( RES_TXTATR_REFMARK, n )) &&
    1075          24 :             0 != (pTextRef = static_cast<const SwFormatRefMark*>(pItem)->GetTextRefMark()) &&
    1076           6 :             &pTextRef->GetTextNode().GetNodes() == &GetNodes() )
    1077             :         {
    1078           6 :             if( pNames )
    1079             :             {
    1080           2 :                 OUString pTmp(static_cast<const SwFormatRefMark*>(pItem)->GetRefName());
    1081           2 :                 pNames->insert(pNames->begin() + nCount, pTmp);
    1082             :             }
    1083           6 :             ++nCount;
    1084             :         }
    1085             :     }
    1086             : 
    1087          43 :     return nCount;
    1088             : }
    1089             : 
    1090          56 : static bool lcl_SpellAndGrammarAgain( const SwNodePtr& rpNd, void* pArgs )
    1091             : {
    1092          56 :     SwTextNode *pTextNode = rpNd->GetTextNode();
    1093          56 :     bool bOnlyWrong = *static_cast<sal_Bool*>(pArgs);
    1094          56 :     if( pTextNode )
    1095             :     {
    1096           6 :         if( bOnlyWrong )
    1097             :         {
    1098           2 :             if( pTextNode->GetWrong() &&
    1099           0 :                 pTextNode->GetWrong()->InvalidateWrong() )
    1100           0 :                 pTextNode->SetWrongDirty( true );
    1101           2 :             if( pTextNode->GetGrammarCheck() &&
    1102           0 :                 pTextNode->GetGrammarCheck()->InvalidateWrong() )
    1103           0 :                 pTextNode->SetGrammarCheckDirty( true );
    1104             :         }
    1105             :         else
    1106             :         {
    1107           4 :             pTextNode->SetWrongDirty( true );
    1108           4 :             if( pTextNode->GetWrong() )
    1109           0 :                 pTextNode->GetWrong()->SetInvalid( 0, COMPLETE_STRING );
    1110           4 :             pTextNode->SetGrammarCheckDirty( true );
    1111           4 :             if( pTextNode->GetGrammarCheck() )
    1112           0 :                 pTextNode->GetGrammarCheck()->SetInvalid( 0, COMPLETE_STRING );
    1113             :         }
    1114             :     }
    1115          56 :     return true;
    1116             : }
    1117             : 
    1118          44 : static bool lcl_CheckSmartTagsAgain( const SwNodePtr& rpNd, void*  )
    1119             : {
    1120          44 :     SwTextNode *pTextNode = rpNd->GetTextNode();
    1121          44 :     if( pTextNode )
    1122             :     {
    1123           4 :         pTextNode->SetSmartTagDirty( true );
    1124           4 :         if( pTextNode->GetSmartTags() )
    1125             :         {
    1126           0 :             pTextNode->SetSmartTags( NULL );
    1127             :         }
    1128             :     }
    1129          44 :     return true;
    1130             : }
    1131             : 
    1132             : /**
    1133             :  * Re-trigger spelling in the idle handler.
    1134             :  *
    1135             :  * @param bInvalid if <true>, the WrongLists in all nodes are invalidated
    1136             :  *                 and the SpellInvalid flag is set on all pages.
    1137             :  * @param bOnlyWrong controls whether only the areas with wrong words are
    1138             :  *                   checked or the whole area.
    1139             :  * @param bSmartTags ???
    1140             :  */
    1141           5 : void SwDoc::SpellItAgainSam( bool bInvalid, bool bOnlyWrong, bool bSmartTags )
    1142             : {
    1143           5 :     std::set<SwRootFrm*> aAllLayouts = GetAllLayouts();
    1144             :     OSL_ENSURE( getIDocumentLayoutAccess().GetCurrentLayout(), "SpellAgain: Where's my RootFrm?" );
    1145           5 :     if( bInvalid )
    1146             :     {
    1147           5 :         std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::bind2nd(std::mem_fun(&SwRootFrm::AllInvalidateSmartTagsOrSpelling),bSmartTags));
    1148           5 :         std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::bind2nd(std::mem_fun(&SwRootFrm::SetNeedGrammarCheck), true) );
    1149           5 :         if ( bSmartTags )
    1150           4 :             GetNodes().ForEach( lcl_CheckSmartTagsAgain, &bOnlyWrong );
    1151           5 :         GetNodes().ForEach( lcl_SpellAndGrammarAgain, &bOnlyWrong );
    1152             :     }
    1153             : 
    1154           5 :     std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::mem_fun(&SwRootFrm::SetIdleFlags));
    1155           5 : }
    1156             : 
    1157           0 : void SwDoc::InvalidateAutoCompleteFlag()
    1158             : {
    1159           0 :     SwRootFrm* pTmpRoot = getIDocumentLayoutAccess().GetCurrentLayout();
    1160           0 :     if( pTmpRoot )
    1161             :     {
    1162           0 :         std::set<SwRootFrm*> aAllLayouts = GetAllLayouts();
    1163           0 :         std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::mem_fun(&SwRootFrm::AllInvalidateAutoCompleteWords));
    1164           0 :         for( sal_uLong nNd = 1, nCnt = GetNodes().Count(); nNd < nCnt; ++nNd )
    1165             :         {
    1166           0 :             SwTextNode* pTextNode = GetNodes()[ nNd ]->GetTextNode();
    1167           0 :             if ( pTextNode ) pTextNode->SetAutoCompleteWordDirty( true );
    1168             :         }
    1169             : 
    1170           0 :         std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::mem_fun(&SwRootFrm::SetIdleFlags));
    1171             :     }
    1172           0 : }
    1173             : 
    1174           0 : const SwFormatINetFormat* SwDoc::FindINetAttr( const OUString& rName ) const
    1175             : {
    1176             :     const SwFormatINetFormat* pItem;
    1177             :     const SwTextINetFormat* pTextAttr;
    1178             :     const SwTextNode* pTextNd;
    1179           0 :     sal_uInt32 n, nMaxItems = GetAttrPool().GetItemCount2( RES_TXTATR_INETFMT );
    1180           0 :     for( n = 0; n < nMaxItems; ++n )
    1181             :     {
    1182           0 :         pItem = static_cast<const SwFormatINetFormat*>( GetAttrPool().GetItem2( RES_TXTATR_INETFMT, n ) );
    1183           0 :         if( 0 != pItem &&
    1184           0 :             pItem->GetName() == rName &&
    1185           0 :             0 != ( pTextAttr = pItem->GetTextINetFormat()) &&
    1186           0 :             0 != ( pTextNd = pTextAttr->GetpTextNode() ) &&
    1187           0 :             &pTextNd->GetNodes() == &GetNodes() )
    1188             :         {
    1189           0 :             return pItem;
    1190             :         }
    1191             :     }
    1192           0 :     return 0;
    1193             : }
    1194             : 
    1195           0 : void SwDoc::Summary( SwDoc* pExtDoc, sal_uInt8 nLevel, sal_uInt8 nPara, bool bImpress )
    1196             : {
    1197           0 :     const SwOutlineNodes& rOutNds = GetNodes().GetOutLineNds();
    1198           0 :     if( pExtDoc && !rOutNds.empty() )
    1199             :     {
    1200           0 :         ::StartProgress( STR_STATSTR_SUMMARY, 0, rOutNds.size(), GetDocShell() );
    1201           0 :         SwNodeIndex aEndOfDoc( pExtDoc->GetNodes().GetEndOfContent(), -1 );
    1202           0 :         for( SwOutlineNodes::size_type i = 0; i < rOutNds.size(); ++i )
    1203             :         {
    1204           0 :             ::SetProgressState( static_cast<long>(i), GetDocShell() );
    1205           0 :             const sal_uLong nIndex = rOutNds[ i ]->GetIndex();
    1206             : 
    1207           0 :             const int nLvl = GetNodes()[ nIndex ]->GetTextNode()->GetAttrOutlineLevel()-1;
    1208           0 :             if( nLvl > nLevel )
    1209           0 :                 continue;
    1210           0 :             long nEndOfs = 1;
    1211           0 :             sal_uInt8 nWish = nPara;
    1212           0 :             sal_uLong nNextOutNd = i + 1 < rOutNds.size() ?
    1213           0 :                 rOutNds[ i + 1 ]->GetIndex() : GetNodes().Count();
    1214           0 :             bool bKeep = false;
    1215           0 :             while( ( nWish || bKeep ) && nIndex + nEndOfs < nNextOutNd &&
    1216           0 :                    GetNodes()[ nIndex + nEndOfs ]->IsTextNode() )
    1217             :             {
    1218           0 :                 SwTextNode* pTextNode = GetNodes()[ nIndex+nEndOfs ]->GetTextNode();
    1219           0 :                 if (pTextNode->GetText().getLength() && nWish)
    1220           0 :                     --nWish;
    1221           0 :                 bKeep = pTextNode->GetSwAttrSet().GetKeep().GetValue();
    1222           0 :                 ++nEndOfs;
    1223             :             }
    1224             : 
    1225           0 :             SwNodeRange aRange( *rOutNds[ i ], 0, *rOutNds[ i ], nEndOfs );
    1226           0 :             GetNodes()._Copy( aRange, aEndOfDoc );
    1227           0 :         }
    1228           0 :         const SwTextFormatColls *pColl = pExtDoc->GetTextFormatColls();
    1229           0 :         for( SwTextFormatColls::size_type i = 0; i < pColl->size(); ++i )
    1230           0 :             (*pColl)[ i ]->ResetFormatAttr( RES_PAGEDESC, RES_BREAK );
    1231           0 :         SwNodeIndex aIndx( pExtDoc->GetNodes().GetEndOfExtras() );
    1232           0 :         ++aEndOfDoc;
    1233           0 :         while( aIndx < aEndOfDoc )
    1234             :         {
    1235             :             SwNode *pNode;
    1236           0 :             bool bDelete = false;
    1237           0 :             if( (pNode = &aIndx.GetNode())->IsTextNode() )
    1238             :             {
    1239           0 :                 SwTextNode *pNd = pNode->GetTextNode();
    1240           0 :                 if( pNd->HasSwAttrSet() )
    1241           0 :                     pNd->ResetAttr( RES_PAGEDESC, RES_BREAK );
    1242           0 :                 if( bImpress )
    1243             :                 {
    1244           0 :                     SwTextFormatColl* pMyColl = pNd->GetTextColl();
    1245             : 
    1246             :                     const sal_uInt16 nHeadLine = static_cast<sal_uInt16>(
    1247           0 :                                 !pMyColl->IsAssignedToListLevelOfOutlineStyle()
    1248             :                                 ? RES_POOLCOLL_HEADLINE2
    1249           0 :                                 : RES_POOLCOLL_HEADLINE1 );
    1250           0 :                     pMyColl = pExtDoc->getIDocumentStylePoolAccess().GetTextCollFromPool( nHeadLine );
    1251           0 :                     pNd->ChgFormatColl( pMyColl );
    1252             :                 }
    1253           0 :                 if( !pNd->Len() &&
    1254           0 :                     pNd->StartOfSectionIndex()+2 < pNd->EndOfSectionIndex() )
    1255             :                 {
    1256           0 :                     bDelete = true;
    1257           0 :                     pExtDoc->GetNodes().Delete( aIndx );
    1258             :                 }
    1259             :             }
    1260           0 :             if( !bDelete )
    1261           0 :                 ++aIndx;
    1262             :         }
    1263           0 :         ::EndProgress( GetDocShell() );
    1264             :     }
    1265           0 : }
    1266             : 
    1267             : /// Remove the invisible content from the document e.g. hidden areas, hidden paragraphs
    1268          44 : bool SwDoc::RemoveInvisibleContent()
    1269             : {
    1270          44 :     bool bRet = false;
    1271          44 :     GetIDocumentUndoRedo().StartUndo( UNDO_UI_DELETE_INVISIBLECNTNT, NULL );
    1272             : 
    1273             :     {
    1274             :         SwTextNode* pTextNd;
    1275          44 :         SwIterator<SwFormatField,SwFieldType> aIter( *getIDocumentFieldsAccess().GetSysFieldType( RES_HIDDENPARAFLD )  );
    1276          44 :         for( SwFormatField* pFormatField = aIter.First(); pFormatField;  pFormatField = aIter.Next() )
    1277             :         {
    1278           0 :             if( pFormatField->GetTextField() &&
    1279           0 :                 0 != ( pTextNd = pFormatField->GetTextField()->GetpTextNode() ) &&
    1280           0 :                 pTextNd->GetpSwpHints() && pTextNd->HasHiddenParaField() &&
    1281           0 :                 &pTextNd->GetNodes() == &GetNodes() )
    1282             :             {
    1283           0 :                 bRet = true;
    1284           0 :                 SwPaM aPam(*pTextNd, 0, *pTextNd, pTextNd->GetText().getLength());
    1285             : 
    1286             :                 // Remove hidden paragraph or delete contents:
    1287             :                 // Delete contents if
    1288             :                 // 1. removing the paragraph would result in an empty section or
    1289             :                 // 2. if the paragraph is the last paragraph in the section and
    1290             :                 //    there is no paragraph in front of the paragraph:
    1291           0 :                 if ( ( 2 == pTextNd->EndOfSectionIndex() - pTextNd->StartOfSectionIndex() ) ||
    1292           0 :                      ( 1 == pTextNd->EndOfSectionIndex() - pTextNd->GetIndex() &&
    1293           0 :                        !GetNodes()[ pTextNd->GetIndex() - 1 ]->GetTextNode() ) )
    1294             :                 {
    1295           0 :                     getIDocumentContentOperations().DeleteRange( aPam );
    1296             :                 }
    1297             :                 else
    1298             :                 {
    1299           0 :                     aPam.DeleteMark();
    1300           0 :                     getIDocumentContentOperations().DelFullPara( aPam );
    1301           0 :                 }
    1302             :             }
    1303          44 :         }
    1304             :     }
    1305             : 
    1306             :     // Remove any hidden paragraph (hidden text attribute)
    1307         696 :     for( sal_uLong n = GetNodes().Count(); n; )
    1308             :     {
    1309         608 :         SwTextNode* pTextNd = GetNodes()[ --n ]->GetTextNode();
    1310         608 :         if ( pTextNd )
    1311             :         {
    1312         168 :             bool bRemoved = false;
    1313         168 :             SwPaM aPam(*pTextNd, 0, *pTextNd, pTextNd->GetText().getLength());
    1314         168 :             if ( pTextNd->HasHiddenCharAttribute( true ) )
    1315             :             {
    1316           0 :                 bRemoved = true;
    1317           0 :                 bRet = true;
    1318             : 
    1319             :                 // Remove hidden paragraph or delete contents:
    1320             :                 // Delete contents if
    1321             :                 // 1. removing the paragraph would result in an empty section or
    1322             :                 // 2. if the paragraph is the last paragraph in the section and
    1323             :                 //    there is no paragraph in front of the paragraph:
    1324           0 :                 if ( ( 2 == pTextNd->EndOfSectionIndex() - pTextNd->StartOfSectionIndex() ) ||
    1325           0 :                      ( 1 == pTextNd->EndOfSectionIndex() - pTextNd->GetIndex() &&
    1326           0 :                        !GetNodes()[ pTextNd->GetIndex() - 1 ]->GetTextNode() ) )
    1327             :                 {
    1328           0 :                     getIDocumentContentOperations().DeleteRange( aPam );
    1329             :                 }
    1330             :                 else
    1331             :                 {
    1332           0 :                     aPam.DeleteMark();
    1333           0 :                     getIDocumentContentOperations().DelFullPara( aPam );
    1334             :                 }
    1335             :             }
    1336         168 :             else if ( pTextNd->HasHiddenCharAttribute( false ) )
    1337             :             {
    1338           0 :                 bRemoved = true;
    1339           0 :                 bRet = true;
    1340           0 :                 SwScriptInfo::DeleteHiddenRanges( *pTextNd );
    1341             :             }
    1342             : 
    1343             :             // Footnotes/Frames may have been removed, therefore we have
    1344             :             // to reset n:
    1345         168 :             if ( bRemoved )
    1346           0 :                 n = aPam.GetPoint()->nNode.GetIndex();
    1347             :         }
    1348             :     }
    1349             : 
    1350             :     {
    1351             :         // Delete/empty all hidden areas
    1352          44 :         SwSectionFormats aSectFormats;
    1353          44 :         SwSectionFormats& rSectFormats = GetSections();
    1354             : 
    1355          88 :         for( SwSectionFormats::size_type n = rSectFormats.size(); n; )
    1356             :         {
    1357           0 :             SwSectionFormat* pSectFormat = rSectFormats[ --n ];
    1358             :             // don't add sections in Undo/Redo
    1359           0 :             if( !pSectFormat->IsInNodesArr())
    1360           0 :                 continue;
    1361           0 :             SwSection* pSect = pSectFormat->GetSection();
    1362           0 :             if( pSect->CalcHiddenFlag() )
    1363             :             {
    1364           0 :                 SwSection* pParent = pSect, *pTmp;
    1365           0 :                 while( 0 != (pTmp = pParent->GetParent() ))
    1366             :                 {
    1367           0 :                     if( pTmp->IsHiddenFlag() )
    1368           0 :                         pSect = pTmp;
    1369           0 :                     pParent = pTmp;
    1370             :                 }
    1371             : 
    1372             :                 SwSectionFormats::iterator it = std::find(
    1373           0 :                         aSectFormats.begin(), aSectFormats.end(), pSect->GetFormat() );
    1374           0 :                 if (it == aSectFormats.end())
    1375           0 :                     aSectFormats.insert( aSectFormats.begin(), pSect->GetFormat() );
    1376             :             }
    1377           0 :             if( !pSect->GetCondition().isEmpty() )
    1378             :             {
    1379           0 :                 SwSectionData aSectionData( *pSect );
    1380           0 :                 aSectionData.SetCondition( OUString() );
    1381           0 :                 aSectionData.SetHidden( false );
    1382           0 :                 UpdateSection( n, aSectionData );
    1383             :             }
    1384             :         }
    1385             : 
    1386          44 :         SwSectionFormats::size_type n = aSectFormats.size();
    1387             : 
    1388          44 :         if( 0 != n )
    1389             :         {
    1390           0 :             while( n )
    1391             :             {
    1392           0 :                 SwSectionFormat* pSectFormat = aSectFormats[ --n ];
    1393           0 :                 SwSectionNode* pSectNd = pSectFormat->GetSectionNode();
    1394           0 :                 if( pSectNd )
    1395             :                 {
    1396           0 :                     bRet = true;
    1397           0 :                     SwPaM aPam( *pSectNd );
    1398             : 
    1399           0 :                     if( pSectNd->StartOfSectionNode()->StartOfSectionIndex() ==
    1400           0 :                         pSectNd->GetIndex() - 1 &&
    1401           0 :                         pSectNd->StartOfSectionNode()->EndOfSectionIndex() ==
    1402           0 :                         pSectNd->EndOfSectionIndex() + 1 )
    1403             :                     {
    1404             :                         // only delete the content
    1405           0 :                         SwContentNode* pCNd = GetNodes().GoNext(
    1406           0 :                                                 &aPam.GetPoint()->nNode );
    1407           0 :                         aPam.GetPoint()->nContent.Assign( pCNd, 0 );
    1408           0 :                         aPam.SetMark();
    1409           0 :                         aPam.GetPoint()->nNode = *pSectNd->EndOfSectionNode();
    1410             :                         pCNd = SwNodes::GoPrevious(
    1411           0 :                                                 &aPam.GetPoint()->nNode );
    1412           0 :                         aPam.GetPoint()->nContent.Assign( pCNd, pCNd->Len() );
    1413             : 
    1414           0 :                         getIDocumentContentOperations().DeleteRange( aPam );
    1415             :                     }
    1416             :                     else
    1417             :                     {
    1418             :                         // delete the whole section
    1419           0 :                         aPam.SetMark();
    1420           0 :                         aPam.GetPoint()->nNode = *pSectNd->EndOfSectionNode();
    1421           0 :                         getIDocumentContentOperations().DelFullPara( aPam );
    1422           0 :                     }
    1423             : 
    1424             :                 }
    1425             :             }
    1426           0 :             aSectFormats.clear();
    1427          44 :         }
    1428             :     }
    1429             : 
    1430          44 :     if( bRet )
    1431           0 :         getIDocumentState().SetModified();
    1432          44 :     GetIDocumentUndoRedo().EndUndo( UNDO_UI_DELETE_INVISIBLECNTNT, NULL );
    1433          44 :     return bRet;
    1434             : }
    1435             : 
    1436           0 : bool SwDoc::HasInvisibleContent() const
    1437             : {
    1438           0 :     if(SwIterator<SwFormatField,SwFieldType>(*getIDocumentFieldsAccess().GetSysFieldType( RES_HIDDENPARAFLD)).First())
    1439           0 :         return true;
    1440             : 
    1441             :     // Search for any hidden paragraph (hidden text attribute)
    1442           0 :     for( sal_uLong n = GetNodes().Count()-1; n; --n)
    1443             :     {
    1444           0 :         SwTextNode* pTextNd = GetNodes()[ n ]->GetTextNode();
    1445           0 :         if ( pTextNd )
    1446             :         {
    1447           0 :             SwPaM aPam(*pTextNd, 0, *pTextNd, pTextNd->GetText().getLength());
    1448           0 :             if( pTextNd->HasHiddenCharAttribute( true ) ||  ( pTextNd->HasHiddenCharAttribute( false ) ) )
    1449           0 :                 return true;
    1450             :         }
    1451             :     }
    1452             : 
    1453           0 :     const SwSectionFormats& rSectFormats = GetSections();
    1454           0 :     for( SwSectionFormats::size_type n = rSectFormats.size()-1; n; --n )
    1455             :     {
    1456           0 :         SwSectionFormat* pSectFormat = rSectFormats[ n ];
    1457             :         // don't add sections in Undo/Redo
    1458           0 :         if( !pSectFormat->IsInNodesArr())
    1459           0 :             continue;
    1460           0 :         SwSection* pSect = pSectFormat->GetSection();
    1461           0 :         if( pSect->IsHidden() )
    1462           0 :             return true;
    1463             :     }
    1464           0 :     return false;
    1465             : }
    1466             : 
    1467           0 : bool SwDoc::RestoreInvisibleContent()
    1468             : {
    1469           0 :     SwUndoId nLastUndoId(UNDO_EMPTY);
    1470           0 :     if (GetIDocumentUndoRedo().GetLastUndoInfo(0, & nLastUndoId)
    1471           0 :         && (UNDO_UI_DELETE_INVISIBLECNTNT == nLastUndoId))
    1472             :     {
    1473           0 :         GetIDocumentUndoRedo().Undo();
    1474           0 :         GetIDocumentUndoRedo().ClearRedo();
    1475           0 :         return true;
    1476             :     }
    1477           0 :     return false;
    1478             : }
    1479             : 
    1480          44 : bool SwDoc::ConvertFieldsToText()
    1481             : {
    1482          44 :     bool bRet = false;
    1483          44 :     getIDocumentFieldsAccess().LockExpFields();
    1484          44 :     GetIDocumentUndoRedo().StartUndo( UNDO_UI_REPLACE, NULL );
    1485             : 
    1486          44 :     const SwFieldTypes* pMyFieldTypes = getIDocumentFieldsAccess().GetFieldTypes();
    1487          44 :     const SwFieldTypes::size_type nCount = pMyFieldTypes->size();
    1488             :     //go backward, field types are removed
    1489        1482 :     for(SwFieldTypes::size_type nType = nCount; nType > 0; --nType)
    1490             :     {
    1491        1438 :         const SwFieldType *pCurType = (*pMyFieldTypes)[nType - 1];
    1492             : 
    1493        1438 :         if ( RES_POSTITFLD == pCurType->Which() )
    1494          44 :             continue;
    1495             : 
    1496        1394 :         SwIterator<SwFormatField,SwFieldType> aIter( *pCurType );
    1497        2788 :         ::std::vector<const SwFormatField*> aFieldFormats;
    1498        1424 :         for( SwFormatField* pCurFieldFormat = aIter.First(); pCurFieldFormat; pCurFieldFormat = aIter.Next() )
    1499          30 :             aFieldFormats.push_back(pCurFieldFormat);
    1500             : 
    1501        1394 :         ::std::vector<const SwFormatField*>::iterator aBegin = aFieldFormats.begin();
    1502        1394 :         ::std::vector<const SwFormatField*>::iterator aEnd = aFieldFormats.end();
    1503        2818 :         while(aBegin != aEnd)
    1504             :         {
    1505          30 :             const SwTextField *pTextField = (*aBegin)->GetTextField();
    1506             :             // skip fields that are currently not in the document
    1507             :             // e.g. fields in undo or redo array
    1508             : 
    1509          60 :             bool bSkip = !pTextField ||
    1510          60 :                          !pTextField->GetpTextNode()->GetNodes().IsDocNodes();
    1511             : 
    1512          30 :             if (!bSkip)
    1513             :             {
    1514          30 :                 bool bInHeaderFooter = IsInHeaderFooter(SwNodeIndex(*pTextField->GetpTextNode()));
    1515          30 :                 const SwFormatField& rFormatField = pTextField->GetFormatField();
    1516          30 :                 const SwField*  pField = rFormatField.GetField();
    1517             : 
    1518             :                 //#i55595# some fields have to be excluded in headers/footers
    1519          30 :                 sal_uInt16 nWhich = pField->GetTyp()->Which();
    1520          30 :                 if(!bInHeaderFooter ||
    1521           0 :                         (nWhich != RES_PAGENUMBERFLD &&
    1522           0 :                         nWhich != RES_CHAPTERFLD &&
    1523           0 :                         nWhich != RES_GETEXPFLD&&
    1524           0 :                         nWhich != RES_SETEXPFLD&&
    1525           0 :                         nWhich != RES_INPUTFLD&&
    1526           0 :                         nWhich != RES_REFPAGEGETFLD&&
    1527             :                         nWhich != RES_REFPAGESETFLD))
    1528             :                 {
    1529          30 :                     OUString sText = pField->ExpandField(true);
    1530             : 
    1531             :                     // database fields should not convert their command into text
    1532          30 :                     if( RES_DBFLD == pCurType->Which() && !static_cast<const SwDBField*>(pField)->IsInitialized())
    1533           0 :                         sText.clear();
    1534             : 
    1535          60 :                     SwPaM aInsertPam(*pTextField->GetpTextNode(), pTextField->GetStart());
    1536          30 :                     aInsertPam.SetMark();
    1537             : 
    1538             :                     // go to the end of the field
    1539          30 :                     const SwTextField *pFieldAtEnd = sw::DocumentFieldsManager::GetTextFieldAtPos(*aInsertPam.End());
    1540          30 :                     if (pFieldAtEnd && pFieldAtEnd->Which() == RES_TXTATR_INPUTFIELD)
    1541             :                     {
    1542           0 :                         SwPosition &rEndPos = *aInsertPam.GetPoint();
    1543           0 :                         rEndPos.nContent = SwCrsrShell::EndOfInputFieldAtPos( *aInsertPam.End() );
    1544             :                     }
    1545             :                     else
    1546             :                     {
    1547          30 :                         aInsertPam.Move();
    1548             :                     }
    1549             : 
    1550             :                     // first insert the text after field to keep the field's attributes,
    1551             :                     // then delete the field
    1552          30 :                     if (!sText.isEmpty())
    1553             :                     {
    1554             :                         // to keep the position after insert
    1555          30 :                         SwPaM aDelPam( *aInsertPam.GetMark(), *aInsertPam.GetPoint() );
    1556          30 :                         aDelPam.Move( fnMoveBackward );
    1557          30 :                         aInsertPam.DeleteMark();
    1558             : 
    1559          30 :                         getIDocumentContentOperations().InsertString( aInsertPam, sText );
    1560             : 
    1561          30 :                         aDelPam.Move();
    1562             :                         // finally remove the field
    1563          30 :                         getIDocumentContentOperations().DeleteAndJoin( aDelPam );
    1564             :                     }
    1565             :                     else
    1566             :                     {
    1567           0 :                         getIDocumentContentOperations().DeleteAndJoin( aInsertPam );
    1568             :                     }
    1569             : 
    1570          60 :                     bRet = true;
    1571             :                 }
    1572             :             }
    1573          30 :             ++aBegin;
    1574             :         }
    1575        1394 :     }
    1576             : 
    1577          44 :     if( bRet )
    1578          20 :         getIDocumentState().SetModified();
    1579          44 :     GetIDocumentUndoRedo().EndUndo( UNDO_UI_REPLACE, NULL );
    1580          44 :     getIDocumentFieldsAccess().UnlockExpFields();
    1581          44 :     return bRet;
    1582             : 
    1583             : }
    1584             : 
    1585           0 : bool SwDoc::IsInsTableFormatNum() const
    1586             : {
    1587           0 :     return SW_MOD()->IsInsTableFormatNum(GetDocumentSettingManager().get(DocumentSettingId::HTML_MODE));
    1588             : }
    1589             : 
    1590           0 : bool SwDoc::IsInsTableChangeNumFormat() const
    1591             : {
    1592           0 :     return SW_MOD()->IsInsTableChangeNumFormat(GetDocumentSettingManager().get(DocumentSettingId::HTML_MODE));
    1593             : }
    1594             : 
    1595          95 : bool SwDoc::IsInsTableAlignNum() const
    1596             : {
    1597          95 :     return SW_MOD()->IsInsTableAlignNum(GetDocumentSettingManager().get(DocumentSettingId::HTML_MODE));
    1598             : }
    1599             : 
    1600             : /// Set up the InsertDB as Undo table
    1601           0 : void SwDoc::AppendUndoForInsertFromDB( const SwPaM& rPam, bool bIsTable )
    1602             : {
    1603           0 :     if( bIsTable )
    1604             :     {
    1605           0 :         const SwTableNode* pTableNd = rPam.GetPoint()->nNode.GetNode().FindTableNode();
    1606           0 :         if( pTableNd )
    1607             :         {
    1608           0 :             SwUndoCpyTable* pUndo = new SwUndoCpyTable;
    1609           0 :             pUndo->SetTableSttIdx( pTableNd->GetIndex() );
    1610           0 :             GetIDocumentUndoRedo().AppendUndo( pUndo );
    1611             :         }
    1612             :     }
    1613           0 :     else if( rPam.HasMark() )
    1614             :     {
    1615           0 :         SwUndoCpyDoc* pUndo = new SwUndoCpyDoc( rPam );
    1616           0 :         pUndo->SetInsertRange( rPam, false );
    1617           0 :         GetIDocumentUndoRedo().AppendUndo( pUndo );
    1618             :     }
    1619           0 : }
    1620             : 
    1621           0 : void SwDoc::ChgTOX(SwTOXBase & rTOX, const SwTOXBase & rNew)
    1622             : {
    1623           0 :     if (GetIDocumentUndoRedo().DoesUndo())
    1624             :     {
    1625           0 :         GetIDocumentUndoRedo().DelAllUndoObj();
    1626             : 
    1627           0 :         SwUndo * pUndo = new SwUndoTOXChange(&rTOX, rNew);
    1628             : 
    1629           0 :         GetIDocumentUndoRedo().AppendUndo(pUndo);
    1630             :     }
    1631             : 
    1632           0 :     rTOX = rNew;
    1633             : 
    1634           0 :     if (rTOX.ISA(SwTOXBaseSection))
    1635             :     {
    1636           0 :         static_cast<SwTOXBaseSection &>(rTOX).Update();
    1637           0 :         static_cast<SwTOXBaseSection &>(rTOX).UpdatePageNum();
    1638             :     }
    1639           0 : }
    1640             : 
    1641           0 : OUString SwDoc::GetPaMDescr(const SwPaM & rPam)
    1642             : {
    1643           0 :     if (&rPam.GetNode(true) == &rPam.GetNode(false))
    1644             :     {
    1645           0 :         SwTextNode * pTextNode = rPam.GetNode(true).GetTextNode();
    1646             : 
    1647           0 :         if (0 != pTextNode)
    1648             :         {
    1649           0 :             const sal_Int32 nStart = rPam.Start()->nContent.GetIndex();
    1650           0 :             const sal_Int32 nEnd = rPam.End()->nContent.GetIndex();
    1651             : 
    1652             :             return SW_RESSTR(STR_START_QUOTE)
    1653           0 :                 + ShortenString(pTextNode->GetText().copy(nStart, nEnd - nStart),
    1654             :                                 nUndoStringLength,
    1655           0 :                                 SW_RESSTR(STR_LDOTS))
    1656           0 :                 + SW_RESSTR(STR_END_QUOTE);
    1657             :         }
    1658             :     }
    1659             :     else
    1660             :     {
    1661           0 :         return SW_RESSTR(STR_PARAGRAPHS);
    1662             :     }
    1663             : 
    1664           0 :     return OUString("??");
    1665             : }
    1666             : 
    1667           3 : bool SwDoc::ContainsHiddenChars() const
    1668             : {
    1669          39 :     for( sal_uLong n = GetNodes().Count(); n; )
    1670             :     {
    1671          33 :         SwNode* pNd = GetNodes()[ --n ];
    1672          33 :         if ( pNd->IsTextNode() && pNd->GetTextNode()->HasHiddenCharAttribute( false ) )
    1673           0 :             return true;
    1674             :     }
    1675             : 
    1676           3 :     return false;
    1677             : }
    1678             : 
    1679      213291 : std::shared_ptr<SwUnoCrsr> SwDoc::CreateUnoCrsr( const SwPosition& rPos, bool bTblCrsr )
    1680             : {
    1681      213291 :     std::shared_ptr<SwUnoCrsr> pNew;
    1682      213291 :     if( bTblCrsr )
    1683         103 :         pNew.reset(new SwUnoTableCrsr( rPos ));
    1684             :     else
    1685      213188 :         pNew.reset(new SwUnoCrsr( rPos ));
    1686             : 
    1687      213291 :     mvUnoCrsrTbl.push_back( pNew );
    1688      213291 :     return pNew;
    1689             : }
    1690             : 
    1691         440 : void SwDoc::ChkCondColls()
    1692             : {
    1693        5902 :      for (SwTextFormatColls::size_type n = 0; n < mpTextFormatCollTable->size(); ++n)
    1694             :      {
    1695        5462 :         SwTextFormatColl *pColl = (*mpTextFormatCollTable)[n];
    1696        5462 :         if (RES_CONDTXTFMTCOLL == pColl->Which())
    1697         435 :             pColl->CallSwClientNotify( SwAttrHint(RES_CONDTXTFMTCOLL) );
    1698             :      }
    1699         440 : }
    1700             : 
    1701             : uno::Reference< script::vba::XVBAEventProcessor >
    1702      178891 : SwDoc::GetVbaEventProcessor()
    1703             : {
    1704             : #if HAVE_FEATURE_SCRIPTING
    1705      178891 :     if( !mxVbaEvents.is() && mpDocShell && ooo::vba::isAlienWordDoc( *mpDocShell ) )
    1706             :     {
    1707             :         try
    1708             :         {
    1709       34079 :             uno::Reference< frame::XModel > xModel( mpDocShell->GetModel(), uno::UNO_SET_THROW );
    1710       68158 :             uno::Sequence< uno::Any > aArgs(1);
    1711       34079 :             aArgs[0] <<= xModel;
    1712       68171 :             mxVbaEvents.set( ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "com.sun.star.script.vba.VBATextEventProcessor" , aArgs ), uno::UNO_QUERY_THROW );
    1713             :         }
    1714       34079 :         catch( uno::Exception& )
    1715             :         {
    1716             :         }
    1717             :     }
    1718             : #endif
    1719      178891 :     return mxVbaEvents;
    1720         177 : }
    1721             : 
    1722             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11