LCOV - code coverage report
Current view: top level - sw/source/core/inc - rolbck.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 16 33 48.5 %
Date: 2015-06-13 12:38:46 Functions: 25 41 61.0 %
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 SwFormatColl;
      35             : class SwHistoryHint;
      36             : class SwTextAttr;
      37             : class SfxPoolItem;
      38             : class SwUndoSaveSection;
      39             : class SwTextFootnote;
      40             : class SwUndoDelLayFormat;
      41             : class SwFlyFrameFormat;
      42             : class SwFormatField;
      43             : class SwTextField;
      44             : class SwFieldType;
      45             : class SwTextTOXMark;
      46             : class SwTextRefMark;
      47             : class SwFrameFormat;
      48             : class SwpHints;
      49             : class SwFormatChain;
      50             : class SwNode;
      51             : class SwCharFormat;
      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       11944 :     SwHistoryHint( HISTORY_HINT eWhich ) : m_eWhichId( eWhich ) {}
      86       11929 :     virtual ~SwHistoryHint() {}
      87             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) = 0;
      88           1 :     HISTORY_HINT Which() const                     { return m_eWhichId; }
      89             :     virtual OUString GetDescription() const;
      90             : };
      91             : 
      92             : class SwHistorySetFormat : public SwHistoryHint
      93             : {
      94             :     ::std::unique_ptr<SfxPoolItem> m_pAttr;
      95             :     const sal_uLong m_nNodeIndex;
      96             : 
      97             : public:
      98             :     SwHistorySetFormat( const SfxPoolItem* pFormatHt, sal_uLong nNode );
      99             :     virtual ~SwHistorySetFormat();
     100             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     101             :     virtual OUString GetDescription() const SAL_OVERRIDE;
     102             : 
     103             : };
     104             : 
     105        2076 : class SwHistoryResetFormat : public SwHistoryHint
     106             : {
     107             :     const sal_uLong m_nNodeIndex;
     108             :     const sal_uInt16 m_nWhich;
     109             : 
     110             : public:
     111             :     SwHistoryResetFormat( const SfxPoolItem* pFormatHt, sal_uLong nNodeIdx );
     112             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     113             : 
     114             : };
     115             : 
     116             : class SwHistorySetText : 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             :     SwHistorySetText( SwTextAttr* pTextHt, sal_uLong nNode );
     127             :     virtual ~SwHistorySetText();
     128             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     129             : 
     130             : };
     131             : 
     132             : class SwHistorySetTextField : 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_pFieldType;
     137             :     const ::std::unique_ptr<SwFormatField> m_pField;
     138             : 
     139             :     sal_uLong m_nNodeIndex;
     140             :     sal_Int32 m_nPos;
     141             :     sal_uInt16 m_nFieldWhich;
     142             : 
     143             : public:
     144             :     SwHistorySetTextField( SwTextField* pTextField, sal_uLong nNode );
     145             :     virtual ~SwHistorySetTextField();
     146             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     147             : 
     148             :     virtual OUString GetDescription() const SAL_OVERRIDE;
     149             : 
     150             : };
     151             : 
     152          24 : 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( SwTextRefMark* pTextHt, sal_uLong nNode );
     161             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     162             : 
     163             : };
     164             : 
     165          26 : 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( SwTextTOXMark* pTextHt, sal_uLong nNode );
     176             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     177             :     bool IsEqual( const SwTOXMark& rCmp ) const;
     178             : 
     179             : };
     180             : 
     181        3526 : class SwHistoryResetText : 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             :     SwHistoryResetText( 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 GetContent() 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( SwTextFootnote* pTextFootnote, sal_uLong nNode );
     209             :     SwHistorySetFootnote( const SwTextFootnote& );
     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        4064 : class SwHistoryChangeFormatColl : public SwHistoryHint
     218             : {
     219             :     SwFormatColl * const m_pColl;
     220             :     const sal_uLong m_nNodeIndex;
     221             :     const sal_uInt8 m_nNodeType;
     222             : 
     223             : public:
     224             :     SwHistoryChangeFormatColl( SwFormatColl* pColl, sal_uLong nNode, sal_uInt8 nNodeWhich );
     225             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     226             : 
     227             : };
     228             : 
     229             : class SwHistoryTextFlyCnt : public SwHistoryHint
     230             : {
     231             :     ::std::unique_ptr<SwUndoDelLayFormat> m_pUndo;
     232             : 
     233             : public:
     234             :     SwHistoryTextFlyCnt( SwFrameFormat* const pFlyFormat );
     235             :     virtual ~SwHistoryTextFlyCnt();
     236             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     237           0 :     SwUndoDelLayFormat* GetUDelLFormat() { return m_pUndo.get(); }
     238             : 
     239             : };
     240             : 
     241        2546 : 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        1043 :         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_nContent;
     258             :         const sal_Int32 m_nOtherContent;
     259             :         const bool m_bSavePos;
     260             :         const bool m_bSaveOtherPos;
     261             :         const bool m_bHadOtherPos;
     262             :         const IDocumentMarkAccess::MarkType m_eBkmkType;
     263             :         std::shared_ptr< ::sfx2::MetadatableUndo > m_pMetadataUndo;
     264             : };
     265             : 
     266        2956 : 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        4450 : 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 GetContent() const         { return m_nStart; }
     295             : 
     296             : };
     297             : 
     298           0 : class SwHistoryChangeFlyAnchor : public SwHistoryHint
     299             : {
     300             :     SwFrameFormat & m_rFormat;
     301             :     const sal_uLong m_nOldNodeIndex;
     302             :     const sal_Int32 m_nOldContentIndex;
     303             : 
     304             : public:
     305             :     SwHistoryChangeFlyAnchor( SwFrameFormat& rFormat );
     306             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     307             : };
     308             : 
     309           0 : class SwHistoryChangeFlyChain : public SwHistoryHint
     310             : {
     311             :     SwFlyFrameFormat * const m_pPrevFormat;
     312             :     SwFlyFrameFormat * const m_pNextFormat;
     313             :     SwFlyFrameFormat * const m_pFlyFormat;
     314             : 
     315             : public:
     316             :     SwHistoryChangeFlyChain( SwFlyFrameFormat& rFormat, const SwFormatChain& rAttr );
     317             :     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) SAL_OVERRIDE;
     318             : };
     319             : 
     320           0 : class SwHistoryChangeCharFormat : public SwHistoryHint
     321             : {
     322             :     const SfxItemSet m_OldSet;
     323             :     const OUString m_Format;
     324             : 
     325             : public:
     326             :     SwHistoryChangeCharFormat( const SfxItemSet& rSet, const OUString & sFormat);
     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( SwTextAttr* pTextHt, sal_uLong nNodeIdx, bool bNewAttr = true );
     354             :     void Add( SwFormatColl*, sal_uLong nNodeIdx, sal_uInt8 nWhichNd );
     355             :     void Add( const ::sw::mark::IMark&, bool bSavePos, bool bSaveOtherPos );
     356             :     void Add( SwFrameFormat& rFormat );
     357             :     void Add( SwFlyFrameFormat&, sal_uInt16& rSetPos );
     358             :     void Add( const SwTextFootnote& );
     359             :     void Add( const SfxItemSet & rSet, const SwCharFormat & rCharFormat);
     360             : 
     361       15111 :     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         418 :     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 CopyFormatAttr( const SfxItemSet& rSet, sal_uLong nNodeIdx );
     389             : };
     390             : 
     391      111592 : 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( SwTextAttr* pHt, const bool bNew = false );
     414             : 
     415             :     void RegisterInModify( SwModify* pRegIn, const SwNode& rNd );
     416          18 :     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.11