LCOV - code coverage report
Current view: top level - sw/source/core/doc - doc.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 303 769 39.4 %
Date: 2014-11-03 Functions: 67 98 68.4 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10