LCOV - code coverage report
Current view: top level - sw/source/core/inc - rolbck.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 15 33 45.5 %
Date: 2014-11-03 Functions: 23 41 56.1 %
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             : #ifndef INCLUDED_SW_SOURCE_CORE_INC_ROLBCK_HXX
      20             : #define INCLUDED_SW_SOURCE_CORE_INC_ROLBCK_HXX
      21             : 
      22             : #include <svl/itemset.hxx>
      23             : #include <tools/solar.h>
      24             : #include <vcl/keycod.hxx>
      25             : 
      26             : #include <vector>
      27             : #include <set>
      28             : 
      29             : namespace sfx2 {
      30             :     class MetadatableUndo;
      31             : }
      32             : 
      33             : class SwDoc;
      34             : class SwFmtColl;
      35             : class SwHistoryHint;
      36             : class SwTxtAttr;
      37             : class SfxPoolItem;
      38             : class SwUndoSaveSection;
      39             : class SwTxtFtn;
      40             : class SwUndoDelLayFmt;
      41             : class SwFlyFrmFmt;
      42             : class SwFmtFld;
      43             : class SwTxtFld;
      44             : class SwFieldType;
      45             : class SwTxtTOXMark;
      46             : class SwTxtRefMark;
      47             : class SwFrmFmt;
      48             : class SwpHints;
      49             : class SwFmtChain;
      50             : class SwNode;
      51             : class SwCharFmt;
      52             : 
      53             : #include <tox.hxx>
      54             : 
      55             : #include <SwNumberTreeTypes.hxx>
      56             : #include <IDocumentMarkAccess.hxx>
      57             : 
      58             : #include <memory>
      59             : 
      60             : enum HISTORY_HINT {
      61             :     HSTRY_SETFMTHNT,
      62             :     HSTRY_RESETFMTHNT,
      63             :     HSTRY_SETTXTHNT,
      64             :     HSTRY_SETTXTFLDHNT,
      65             :     HSTRY_SETREFMARKHNT,
      66             :     HSTRY_SETTOXMARKHNT,
      67             :     HSTRY_RESETTXTHNT,
      68             :     HSTRY_SETFTNHNT,
      69             :     HSTRY_CHGFMTCOLL,
      70             :     HSTRY_FLYCNT,
      71             :     HSTRY_BOOKMARK,
      72             :     HSTRY_SETATTRSET,
      73             :     HSTRY_RESETATTRSET,
      74             :     HSTRY_CHGFLYANCHOR,
      75             :     HSTRY_CHGFLYCHAIN,
      76             :     HSTRY_CHGCHARFMT,
      77             :     HSTRY_END
      78             : };
      79             : 
      80             : class SwHistoryHint
      81             : {
      82             :     const HISTORY_HINT m_eWhichId;
      83             : 
      84             : public:
      85       24428 :     SwHistoryHint( HISTORY_HINT eWhich ) : m_eWhichId( eWhich ) {}
      86       24421 :     virtual ~SwHistoryHint() {}
      87             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) = 0;
      88           0 :     HISTORY_HINT Which() const                     { return m_eWhichId; }
      89             :     virtual OUString GetDescription() const;
      90             : };
      91             : 
      92             : class SwHistorySetFmt : public SwHistoryHint
      93             : {
      94             :     ::std::unique_ptr<SfxPoolItem> m_pAttr;
      95             :     const sal_uLong m_nNodeIndex;
      96             : 
      97             : public:
      98             :     SwHistorySetFmt( const SfxPoolItem* pFmtHt, sal_uLong nNode );
      99             :     virtual ~SwHistorySetFmt();
     100             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     101             :     virtual OUString GetDescription() const SAL_OVERRIDE;
     102             : 
     103             : };
     104             : 
     105        4148 : class SwHistoryResetFmt : public SwHistoryHint
     106             : {
     107             :     const sal_uLong m_nNodeIndex;
     108             :     const sal_uInt16 m_nWhich;
     109             : 
     110             : public:
     111             :     SwHistoryResetFmt( const SfxPoolItem* pFmtHt, sal_uLong nNodeIdx );
     112             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     113             : 
     114             : };
     115             : 
     116             : class SwHistorySetTxt : public SwHistoryHint
     117             : {
     118             :     ::std::unique_ptr<SfxPoolItem> m_pAttr;
     119             :     const sal_uLong m_nNodeIndex;
     120             :     const sal_Int32 m_nStart;
     121             :     const sal_Int32 m_nEnd;
     122             :     bool m_bFormatIgnoreStart : 1;
     123             :     bool m_bFormatIgnoreEnd   : 1;
     124             : 
     125             : public:
     126             :     SwHistorySetTxt( SwTxtAttr* pTxtHt, sal_uLong nNode );
     127             :     virtual ~SwHistorySetTxt();
     128             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     129             : 
     130             : };
     131             : 
     132             : class SwHistorySetTxtFld : public SwHistoryHint
     133             : {
     134             :     //!! beware of the order for the declation of the auto_ptrs.
     135             :     //!! If they get destroyed in the wrong order sw may crash (namely mail-merge as well)
     136             :     ::std::unique_ptr<SwFieldType> m_pFldType;
     137             :     const ::std::unique_ptr<SwFmtFld> m_pFld;
     138             : 
     139             :     sal_uLong m_nNodeIndex;
     140             :     sal_Int32 m_nPos;
     141             :     sal_uInt16 m_nFldWhich;
     142             : 
     143             : public:
     144             :     SwHistorySetTxtFld( SwTxtFld* pTxtFld, sal_uLong nNode );
     145             :     virtual ~SwHistorySetTxtFld();
     146             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     147             : 
     148             :     virtual OUString GetDescription() const SAL_OVERRIDE;
     149             : 
     150             : };
     151             : 
     152          48 : class SwHistorySetRefMark : public SwHistoryHint
     153             : {
     154             :     const OUString m_RefName;
     155             :     const sal_uLong m_nNodeIndex;
     156             :     const sal_Int32 m_nStart;
     157             :     const sal_Int32 m_nEnd;
     158             : 
     159             : public:
     160             :     SwHistorySetRefMark( SwTxtRefMark* pTxtHt, sal_uLong nNode );
     161             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     162             : 
     163             : };
     164             : 
     165          52 : class SwHistorySetTOXMark : public SwHistoryHint
     166             : {
     167             :     SwTOXMark m_TOXMark;
     168             :     const OUString m_TOXName;
     169             :     const TOXTypes m_eTOXTypes;
     170             :     const sal_uLong m_nNodeIndex;
     171             :     const sal_Int32 m_nStart;
     172             :     const sal_Int32 m_nEnd;
     173             : 
     174             : public:
     175             :     SwHistorySetTOXMark( SwTxtTOXMark* pTxtHt, sal_uLong nNode );
     176             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     177             :     bool IsEqual( const SwTOXMark& rCmp ) const;
     178             : 
     179             : };
     180             : 
     181        7108 : class SwHistoryResetTxt : public SwHistoryHint
     182             : {
     183             :     const sal_uLong m_nNodeIndex;
     184             :     const sal_Int32 m_nStart;
     185             :     const sal_Int32 m_nEnd;
     186             :     const sal_uInt16 m_nAttr;
     187             : 
     188             : public:
     189             :     SwHistoryResetTxt( sal_uInt16 nWhich, sal_Int32 nStt, sal_Int32 nEnd,
     190             :                        sal_uLong nNode );
     191             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     192             : 
     193           0 :     sal_uInt16 GetWhich() const         { return m_nAttr; }
     194           0 :     sal_uLong GetNode() const           { return m_nNodeIndex; }
     195           0 :     sal_Int32 GetCntnt() const     { return m_nStart; }
     196             : 
     197             : };
     198             : 
     199             : class SwHistorySetFootnote : public SwHistoryHint
     200             : {
     201             :     const ::std::unique_ptr<SwUndoSaveSection> m_pUndo;
     202             :     const OUString m_FootnoteNumber;
     203             :     sal_uLong m_nNodeIndex;
     204             :     const sal_Int32 m_nStart;
     205             :     const bool m_bEndNote;
     206             : 
     207             : public:
     208             :     SwHistorySetFootnote( SwTxtFtn* pTxtFtn, sal_uLong nNode );
     209             :     SwHistorySetFootnote( const SwTxtFtn& );
     210             :     virtual ~SwHistorySetFootnote();
     211             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     212             : 
     213             :     virtual OUString GetDescription() const SAL_OVERRIDE;
     214             : 
     215             : };
     216             : 
     217        8112 : class SwHistoryChangeFmtColl : public SwHistoryHint
     218             : {
     219             :     SwFmtColl * const m_pColl;
     220             :     const sal_uLong m_nNodeIndex;
     221             :     const sal_uInt8 m_nNodeType;
     222             : 
     223             : public:
     224             :     SwHistoryChangeFmtColl( SwFmtColl* pColl, sal_uLong nNode, sal_uInt8 nNodeWhich );
     225             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     226             : 
     227             : };
     228             : 
     229             : class SwHistoryTxtFlyCnt : public SwHistoryHint
     230             : {
     231             :     ::std::unique_ptr<SwUndoDelLayFmt> m_pUndo;
     232             : 
     233             : public:
     234             :     SwHistoryTxtFlyCnt( SwFrmFmt* const pFlyFmt );
     235             :     virtual ~SwHistoryTxtFlyCnt();
     236             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     237           0 :     SwUndoDelLayFmt* GetUDelLFmt() { return m_pUndo.get(); }
     238             : 
     239             : };
     240             : 
     241        6216 : class SwHistoryBookmark : public SwHistoryHint
     242             : {
     243             :     public:
     244             :         SwHistoryBookmark(const ::sw::mark::IMark& rBkmk,
     245             :                         bool bSavePos, bool bSaveOtherPos);
     246             :         virtual void SetInDoc(SwDoc * pDoc, bool) SAL_OVERRIDE;
     247             : 
     248             :         bool IsEqualBookmark(const ::sw::mark::IMark& rBkmk);
     249        2080 :         const OUString& GetName() const { return m_aName;}
     250             : 
     251             :     private:
     252             :         const OUString m_aName;
     253             :         OUString m_aShortName;
     254             :         vcl::KeyCode m_aKeycode;
     255             :         const sal_uLong m_nNode;
     256             :         const sal_uLong m_nOtherNode;
     257             :         const sal_Int32 m_nCntnt;
     258             :         const sal_Int32 m_nOtherCntnt;
     259             :         const bool m_bSavePos;
     260             :         const bool m_bSaveOtherPos;
     261             :         const bool m_bHadOtherPos;
     262             :         const IDocumentMarkAccess::MarkType m_eBkmkType;
     263             :         ::boost::shared_ptr< ::sfx2::MetadatableUndo > m_pMetadataUndo;
     264             : };
     265             : 
     266        5912 : class SwHistorySetAttrSet : public SwHistoryHint
     267             : {
     268             :     SfxItemSet m_OldSet;
     269             :     std::vector<sal_uInt16> m_ResetArray;
     270             :     const sal_uLong m_nNodeIndex;
     271             : 
     272             : public:
     273             :     SwHistorySetAttrSet( const SfxItemSet& rSet, sal_uLong nNode,
     274             :                          const std::set<sal_uInt16> &rSetArr );
     275             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     276             : 
     277             : };
     278             : 
     279        8858 : class SwHistoryResetAttrSet : public SwHistoryHint
     280             : {
     281             :     const sal_uLong m_nNodeIndex;
     282             :     const sal_Int32 m_nStart;
     283             :     const sal_Int32 m_nEnd;
     284             :     std::vector<sal_uInt16> m_Array;
     285             : 
     286             : public:
     287             :     SwHistoryResetAttrSet( const SfxItemSet& rSet, sal_uLong nNode,
     288             :                         sal_Int32 nStt,
     289             :                         sal_Int32 nEnd);
     290             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     291             : 
     292           0 :     const std::vector<sal_uInt16>& GetArr() const { return m_Array; }
     293           0 :     sal_uLong GetNode() const               { return m_nNodeIndex; }
     294           0 :     sal_Int32 GetCntnt() const         { return m_nStart; }
     295             : 
     296             : };
     297             : 
     298           0 : class SwHistoryChangeFlyAnchor : public SwHistoryHint
     299             : {
     300             :     SwFrmFmt & m_rFmt;
     301             :     const sal_uLong m_nOldNodeIndex;
     302             :     const sal_Int32 m_nOldContentIndex;
     303             : 
     304             : public:
     305             :     SwHistoryChangeFlyAnchor( SwFrmFmt& rFmt );
     306             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     307             : };
     308             : 
     309           0 : class SwHistoryChangeFlyChain : public SwHistoryHint
     310             : {
     311             :     SwFlyFrmFmt * const m_pPrevFmt;
     312             :     SwFlyFrmFmt * const m_pNextFmt;
     313             :     SwFlyFrmFmt * const m_pFlyFmt;
     314             : 
     315             : public:
     316             :     SwHistoryChangeFlyChain( SwFlyFrmFmt& rFmt, const SwFmtChain& rAttr );
     317             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     318             : };
     319             : 
     320           0 : class SwHistoryChangeCharFmt : public SwHistoryHint
     321             : {
     322             :     const SfxItemSet m_OldSet;
     323             :     const OUString m_Fmt;
     324             : 
     325             : public:
     326             :     SwHistoryChangeCharFmt( const SfxItemSet& rSet, const OUString & sFmt);
     327             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     328             : 
     329             : };
     330             : 
     331             : class SwHistory
     332             : {
     333             :     friend class SwDoc;         // actually only SwDoc::DelUndoObj may access
     334             :     friend class SwRegHistory;  // for inserting History attributes
     335             : 
     336             :     std::vector<SwHistoryHint*> m_SwpHstry;
     337             :     sal_uInt16 m_nEndDiff;
     338             : 
     339             : public:
     340             :     typedef std::vector<SwHistoryHint*>::iterator SwpHstry_iterator;
     341             :     SwHistory( sal_uInt16 nInitSz = 0 );
     342             :     ~SwHistory();
     343             : 
     344             :     // delete History from nStart to array end
     345             :     void Delete( sal_uInt16 nStart = 0 );
     346             :     // call and delete all objects between nStart and array end
     347             :     bool Rollback( SwDoc* pDoc, sal_uInt16 nStart = 0 );
     348             :     // call all objects between nStart and TmpEnd; store nStart as TmpEnd
     349             :     bool TmpRollback( SwDoc* pDoc, sal_uInt16 nStart, bool ToFirst = true );
     350             : 
     351             :     void Add( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue,
     352             :               sal_uLong nNodeIdx );
     353             :     void Add( SwTxtAttr* pTxtHt, sal_uLong nNodeIdx, bool bNewAttr = true );
     354             :     void Add( SwFmtColl*, sal_uLong nNodeIdx, sal_uInt8 nWhichNd );
     355             :     void Add( const ::sw::mark::IMark&, bool bSavePos, bool bSaveOtherPos );
     356             :     void Add( SwFrmFmt& rFmt );
     357             :     void Add( SwFlyFrmFmt&, sal_uInt16& rSetPos );
     358             :     void Add( const SwTxtFtn& );
     359             :     void Add( const SfxItemSet & rSet, const SwCharFmt & rCharFmt);
     360             : 
     361       30737 :     sal_uInt16 Count() const { return m_SwpHstry.size(); }
     362           0 :     sal_uInt16 GetTmpEnd() const { return m_SwpHstry.size() - m_nEndDiff; }
     363             :     sal_uInt16 SetTmpEnd( sal_uInt16 nTmpEnd );        // return previous value
     364        1272 :     SwHistoryHint      * operator[]( sal_uInt16 nPos ) { return m_SwpHstry[nPos]; }
     365             :     SwHistoryHint const* operator[]( sal_uInt16 nPos ) const
     366             :         { return m_SwpHstry[nPos]; }
     367             : 
     368             :     // for SwUndoDelete::Undo/Redo
     369           0 :     void Move( sal_uInt16 nPos, SwHistory *pIns,
     370             :                sal_uInt16 const nStart = 0)
     371             :     {
     372           0 :         SwpHstry_iterator itSourceBegin = pIns->m_SwpHstry.begin() + nStart;
     373           0 :         SwpHstry_iterator itSourceEnd = pIns->m_SwpHstry.end();
     374           0 :         if (itSourceBegin == itSourceEnd) return;
     375           0 :         m_SwpHstry.insert(m_SwpHstry.begin() + nPos, itSourceBegin, itSourceEnd);
     376           0 :         pIns->m_SwpHstry.erase( itSourceBegin, itSourceEnd );
     377             :     }
     378             : 
     379             :     // helper methods for recording attribute in History
     380             :     // used by Undo classes (Delete/Overwrite/Inserts)
     381             :     void CopyAttr(
     382             :         SwpHints* pHts,
     383             :         const sal_uLong nNodeIdx,
     384             :         const sal_Int32 nStart,
     385             :         const sal_Int32 nEnd,
     386             :         const bool bCopyFields );
     387             : 
     388             :     void CopyFmtAttr( const SfxItemSet& rSet, sal_uLong nNodeIdx );
     389             : };
     390             : 
     391      205886 : class SwRegHistory : public SwClient
     392             : {
     393             : private:
     394             :     std::set<sal_uInt16> m_WhichIdSet;
     395             :     SwHistory * const m_pHistory;
     396             :     sal_uLong m_nNodeIndex;
     397             : 
     398             :     void _MakeSetWhichIds();
     399             : 
     400             : protected:
     401             :     virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew ) SAL_OVERRIDE;
     402             : 
     403             : public:
     404             :     SwRegHistory( SwHistory* pHst );
     405             :     SwRegHistory( const SwNode& rNd, SwHistory* pHst );
     406             :     SwRegHistory( SwModify* pRegIn, const SwNode& rNd, SwHistory* pHst );
     407             : 
     408             :     /// @return true if at least 1 item was inserted
     409             :     bool InsertItems( const SfxItemSet& rSet,
     410             :         sal_Int32 const nStart, sal_Int32 const nEnd,
     411             :         SetAttrMode const nFlags );
     412             : 
     413             :     void AddHint( SwTxtAttr* pHt, const bool bNew = false );
     414             : 
     415             :     void RegisterInModify( SwModify* pRegIn, const SwNode& rNd );
     416          40 :     void ChangeNodeIndex( sal_uLong nNew ) { m_nNodeIndex = nNew; }
     417             : };
     418             : 
     419             : #endif // INCLUDED_SW_SOURCE_CORE_INC_ROLBCK_HXX
     420             : 
     421             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10