LCOV - code coverage report
Current view: top level - sw/inc - undobj.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 12 0.0 %
Date: 2014-04-14 Functions: 0 15 0.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_INC_UNDOBJ_HXX
      20             : #define INCLUDED_SW_INC_UNDOBJ_HXX
      21             : 
      22             : #include <vector>
      23             : 
      24             : #include <boost/scoped_ptr.hpp>
      25             : #include <boost/shared_ptr.hpp>
      26             : 
      27             : #include <svl/undo.hxx>
      28             : 
      29             : #include <SwRewriter.hxx>
      30             : #include <swundo.hxx>
      31             : 
      32             : class SwHistory;
      33             : class SwIndex;
      34             : class SwPaM;
      35             : struct SwPosition;
      36             : class SwDoc;
      37             : class SwTxtFmtColl;
      38             : class SwFrmFmt;
      39             : class SwNodeIndex;
      40             : class SwNodeRange;
      41             : class SwRedlineData;
      42             : class SwRedlineSaveDatas;
      43             : 
      44             : namespace sw {
      45             :     class UndoRedoContext;
      46             :     class RepeatContext;
      47             : }
      48             : 
      49             : class SwUndo
      50             :     : public SfxUndoAction
      51             : {
      52             :     SwUndoId const m_nId;
      53             :     sal_uInt16 nOrigRedlineMode;
      54             : 
      55             : protected:
      56             :     bool bCacheComment;
      57             :     mutable OUString * pComment;
      58             : 
      59             :     void RemoveIdxFromSection( SwDoc&, sal_uLong nSttIdx, sal_uLong* pEndIdx = 0 );
      60             :     void RemoveIdxFromRange( SwPaM& rPam, bool bMoveNext );
      61             :     void RemoveIdxRel( sal_uLong, const SwPosition& );
      62             : 
      63             :     static bool CanRedlineGroup( SwRedlineSaveDatas& rCurr,
      64             :                                 const SwRedlineSaveDatas& rCheck,
      65             :                                 bool bCurrIsEnd );
      66             : 
      67             :     /**
      68             :        Returns the rewriter for this object.
      69             : 
      70             :        @return the rewriter for this object
      71             :     */
      72             :     virtual SwRewriter GetRewriter() const;
      73             : 
      74             :     // return type is sal_uInt16 because this overrides SfxUndoAction::GetId()
      75           0 :     virtual sal_uInt16 GetId() const SAL_OVERRIDE { return static_cast<sal_uInt16>(m_nId); }
      76             : 
      77             :     // the 4 methods that derived classes have to override
      78             :     // base implementation does nothing
      79             :     virtual void RepeatImpl( ::sw::RepeatContext & );
      80             :     virtual bool CanRepeatImpl( ::sw::RepeatContext & ) const;
      81             : public: // should not be public, but ran into trouble in untbl.cxx
      82             :     virtual void UndoImpl( ::sw::UndoRedoContext & ) = 0;
      83             :     virtual void RedoImpl( ::sw::UndoRedoContext & ) = 0;
      84             : 
      85             : private:
      86             :     // SfxUndoAction
      87             :     virtual void Undo() SAL_OVERRIDE;
      88             :     virtual void Redo() SAL_OVERRIDE;
      89             :     virtual void UndoWithContext(SfxUndoContext &) SAL_OVERRIDE;
      90             :     virtual void RedoWithContext(SfxUndoContext &) SAL_OVERRIDE;
      91             :     virtual void Repeat(SfxRepeatTarget &) SAL_OVERRIDE;
      92             :     virtual bool CanRepeat(SfxRepeatTarget &) const SAL_OVERRIDE;
      93             : 
      94             : public:
      95             :     SwUndo(SwUndoId const nId);
      96             :     virtual ~SwUndo();
      97             : 
      98             :     /**
      99             :        Returns textual comment for this undo object.
     100             : 
     101             :        The textual comment is created from the resource string
     102             :        corresponding to this object's ID. The rewriter of this object
     103             :        is applied to the resource string to get the final comment.
     104             : 
     105             :        @return textual comment for this undo object
     106             :     */
     107             :     virtual OUString GetComment() const SAL_OVERRIDE;
     108             : 
     109             :     // UndoObject remembers which mode was turned on.
     110             :     // In Undo/Redo/Repeat this remembered mode is switched on.
     111           0 :     sal_uInt16 GetRedlineMode() const { return nOrigRedlineMode; }
     112           0 :     void SetRedlineMode( sal_uInt16 eMode ) { nOrigRedlineMode = eMode; }
     113             : 
     114             :     bool IsDelBox() const;
     115             : 
     116             :     // Save and set Redline data.
     117             :     static bool FillSaveData( const SwPaM& rRange, SwRedlineSaveDatas& rSData,
     118             :                               bool bDelRange = true, bool bCopyNext = true );
     119             :     static bool FillSaveDataForFmt( const SwPaM& , SwRedlineSaveDatas& );
     120             :     static void SetSaveData( SwDoc& rDoc, const SwRedlineSaveDatas& rSData );
     121             :     static bool HasHiddenRedlines( const SwRedlineSaveDatas& rSData );
     122             : };
     123             : 
     124             : typedef sal_uInt16 DelCntntType;
     125             : namespace nsDelCntntType
     126             : {
     127             :     const DelCntntType DELCNT_FTN = 0x01;
     128             :     const DelCntntType DELCNT_FLY = 0x02;
     129             :     const DelCntntType DELCNT_TOC = 0x04;
     130             :     const DelCntntType DELCNT_BKM = 0x08;
     131             :     const DelCntntType DELCNT_ALL = 0x0F;
     132             :     const DelCntntType DELCNT_CHKNOCNTNT = 0x80;
     133             : }
     134             : 
     135             : /// will DelCntntIndex destroy a frame anchored at character at rAnchorPos?
     136             : bool IsDestroyFrameAnchoredAtChar(SwPosition const & rAnchorPos,
     137             :         SwPosition const & rStart, SwPosition const & rEnd,
     138             :         DelCntntType const nDelCntntType = nsDelCntntType::DELCNT_ALL);
     139             : 
     140             : // This class has to be inherited into an Undo-object if it saves content
     141             : // for Redo/Undo...
     142             : class SwUndoSaveCntnt
     143             : {
     144             : protected:
     145             : 
     146             :     SwHistory* pHistory;
     147             : 
     148             :     // Needed for deletion of content. For Redo content is moved into the
     149             :     // UndoNodesArray. These methods always create a new node to insert
     150             :     // content. So the attributes do not get expanded.
     151             :     // MoveTo:      moves from the NodesArray into the UndoNodesArray.
     152             :     // MoveFrom:    moves from the UndoNodesArray into the NodesArray.
     153             :     void MoveToUndoNds( SwPaM& rPam,
     154             :                         SwNodeIndex* pNodeIdx = 0,
     155             :                         sal_uLong* pEndNdIdx = 0, sal_Int32 * pEndCntIdx = 0 );
     156             :     void MoveFromUndoNds( SwDoc& rDoc, sal_uLong nNodeIdx,
     157             :                           SwPosition& rInsPos,
     158             :                           sal_uLong* pEndNdIdx = 0, sal_Int32 * pEndCntIdx = 0 );
     159             : 
     160             :     // These two methods move the SPoint back/forth from PaM. With it
     161             :     // a range can be spanned for Undo/Redo. (In this case the SPoint
     162             :     // is before the manipulated range!!)
     163             :     // The flag indicates if there is content before the SPoint.
     164             :     bool MovePtBackward( SwPaM& rPam );
     165             :     void MovePtForward( SwPaM& rPam, bool bMvBkwrd );
     166             : 
     167             :     // Before moving stuff into UndoNodes-Array care has to be taken that
     168             :     // the content-bearing attributes are removed from the nodes-array.
     169             :     void DelCntntIndex( const SwPosition& pMark, const SwPosition& pPoint,
     170             :                         DelCntntType nDelCntntType = nsDelCntntType::DELCNT_ALL );
     171             : 
     172             : public:
     173             :     SwUndoSaveCntnt();
     174             :     ~SwUndoSaveCntnt();
     175             : };
     176             : 
     177             : // Save a complete section in nodes-array.
     178             : class SwUndoSaveSection : private SwUndoSaveCntnt
     179             : {
     180             :     SwNodeIndex *pMvStt;
     181             :     SwRedlineSaveDatas* pRedlSaveData;
     182             :     sal_uLong nMvLen;           // Index into UndoNodes-Array.
     183             :     sal_uLong nStartPos;
     184             : 
     185             : protected:
     186           0 :     SwNodeIndex* GetMvSttIdx() const { return pMvStt; }
     187           0 :     sal_uLong GetMvNodeCnt() const { return nMvLen; }
     188             : 
     189             : public:
     190             :     SwUndoSaveSection();
     191             :     ~SwUndoSaveSection();
     192             : 
     193             :     void SaveSection( SwDoc* pDoc, const SwNodeIndex& rSttIdx );
     194             :     void SaveSection( SwDoc* pDoc, const SwNodeRange& rRange );
     195             :     void RestoreSection( SwDoc* pDoc, SwNodeIndex* pIdx, sal_uInt16 nSectType );
     196             :     void RestoreSection( SwDoc* pDoc, const SwNodeIndex& rInsPos );
     197             : 
     198             :     const SwHistory* GetHistory() const { return pHistory; }
     199           0 :           SwHistory* GetHistory()       { return pHistory; }
     200             : };
     201             : 
     202             : // This class saves the PaM as sal_uInt16's and is able to restore it
     203             : // into a PaM.
     204             : class SwUndRng
     205             : {
     206             : public:
     207             :     sal_uLong nSttNode, nEndNode;
     208             :     sal_Int32 nSttCntnt, nEndCntnt;
     209             : 
     210             :     SwUndRng();
     211             :     SwUndRng( const SwPaM& );
     212             : 
     213             :     void SetValues( const SwPaM& rPam );
     214             :     void SetPaM( SwPaM&, bool bCorrToCntnt = false ) const;
     215             :     SwPaM & AddUndoRedoPaM(
     216             :         ::sw::UndoRedoContext &, bool const bCorrToCntnt = false) const;
     217             : };
     218             : 
     219             : class SwUndoInsLayFmt;
     220             : 
     221             : // base class for insertion of Document, Glossaries and Copy
     222             : class SwUndoInserts : public SwUndo, public SwUndRng, private SwUndoSaveCntnt
     223             : {
     224             :     SwTxtFmtColl *pTxtFmtColl, *pLastNdColl;
     225             :     std::vector<SwFrmFmt*>* pFrmFmts;
     226             :     ::std::vector< ::boost::shared_ptr<SwUndoInsLayFmt> > m_FlyUndos;
     227             :     SwRedlineData* pRedlData;
     228             :     bool bSttWasTxtNd;
     229             : protected:
     230             :     sal_uLong nNdDiff;
     231             :     /// start of Content in UndoNodes for Redo
     232             :     ::boost::scoped_ptr<SwNodeIndex> m_pUndoNodeIndex;
     233             :     sal_uInt16 nSetPos;                 // Start in the history list.
     234             : 
     235             :     SwUndoInserts( SwUndoId nUndoId, const SwPaM& );
     236             : public:
     237             :     virtual ~SwUndoInserts();
     238             : 
     239             :     virtual void UndoImpl( ::sw::UndoRedoContext & ) SAL_OVERRIDE;
     240             :     virtual void RedoImpl( ::sw::UndoRedoContext & ) SAL_OVERRIDE;
     241             :     virtual void RepeatImpl( ::sw::RepeatContext & ) SAL_OVERRIDE;
     242             : 
     243             :     // Set destination range after reading.
     244             :     void SetInsertRange( const SwPaM&, bool bScanFlys = true,
     245             :                          bool bSttWasTxtNd = true );
     246             : };
     247             : 
     248           0 : class SwUndoInsDoc : public SwUndoInserts
     249             : {
     250             : public:
     251             :     SwUndoInsDoc( const SwPaM& );
     252             : };
     253             : 
     254           0 : class SwUndoCpyDoc : public SwUndoInserts
     255             : {
     256             : public:
     257             :     SwUndoCpyDoc( const SwPaM& );
     258             : };
     259             : 
     260             : class SwUndoFlyBase : public SwUndo, private SwUndoSaveSection
     261             : {
     262             : protected:
     263             :     SwFrmFmt* pFrmFmt;          // The saved FlyFormat.
     264             :     sal_uLong nNdPgPos;
     265             :     sal_Int32 nCntPos;         // Page at/in paragraph.
     266             :     sal_uInt16 nRndId;
     267             :     bool bDelFmt;           // Delete saved format.
     268             : 
     269             :     void InsFly(::sw::UndoRedoContext & rContext, bool bShowSel = true);
     270             :     void DelFly( SwDoc* );
     271             : 
     272             :     SwUndoFlyBase( SwFrmFmt* pFormat, SwUndoId nUndoId );
     273             : 
     274           0 :     SwNodeIndex* GetMvSttIdx() const { return SwUndoSaveSection::GetMvSttIdx(); }
     275           0 :     sal_uLong GetMvNodeCnt() const { return SwUndoSaveSection::GetMvNodeCnt(); }
     276             : 
     277             : public:
     278             :     virtual ~SwUndoFlyBase();
     279             : 
     280             : };
     281             : 
     282             : class SwUndoInsLayFmt : public SwUndoFlyBase
     283             : {
     284             :     sal_uLong mnCrsrSaveIndexPara;           // Cursor position
     285             :     sal_Int32 mnCrsrSaveIndexPos;            // for undo
     286             : public:
     287             :     SwUndoInsLayFmt( SwFrmFmt* pFormat, sal_uLong nNodeIdx, sal_Int32 nCntIdx );
     288             : 
     289             :     virtual ~SwUndoInsLayFmt();
     290             : 
     291             :     virtual void UndoImpl( ::sw::UndoRedoContext & ) SAL_OVERRIDE;
     292             :     virtual void RedoImpl( ::sw::UndoRedoContext & ) SAL_OVERRIDE;
     293             :     virtual void RepeatImpl( ::sw::RepeatContext & ) SAL_OVERRIDE;
     294             : 
     295             :     virtual OUString GetComment() const SAL_OVERRIDE;
     296             : 
     297             : };
     298             : 
     299           0 : class SwUndoDelLayFmt : public SwUndoFlyBase
     300             : {
     301             :     bool bShowSelFrm;
     302             : public:
     303             :     SwUndoDelLayFmt( SwFrmFmt* pFormat );
     304             : 
     305             :     virtual void UndoImpl( ::sw::UndoRedoContext & ) SAL_OVERRIDE;
     306             :     virtual void RedoImpl( ::sw::UndoRedoContext & ) SAL_OVERRIDE;
     307             : 
     308             :     void RedoForRollback();
     309             : 
     310           0 :     void ChgShowSel( bool bNew ) { bShowSelFrm = bNew; }
     311             : 
     312             :     virtual SwRewriter GetRewriter() const SAL_OVERRIDE;
     313             : 
     314             : };
     315             : 
     316             : #endif
     317             : 
     318             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10