LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/inc - undobj.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 9 12 75.0 %
Date: 2013-07-09 Functions: 11 15 73.3 %
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 SW_UNDOBJ_HXX
      20             : #define SW_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 String * pComment;
      58             : 
      59             :     void RemoveIdxFromSection( SwDoc&, sal_uLong nSttIdx, sal_uLong* pEndIdx = 0 );
      60             :     void RemoveIdxFromRange( SwPaM& rPam, sal_Bool bMoveNext );
      61             :     void RemoveIdxRel( sal_uLong, const SwPosition& );
      62             : 
      63             :     static sal_Bool CanRedlineGroup( SwRedlineSaveDatas& rCurr,
      64             :                                 const SwRedlineSaveDatas& rCheck,
      65             :                                 sal_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        8589 :     virtual sal_uInt16 GetId() const { 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();
      88             :     virtual void Redo();
      89             :     virtual void UndoWithContext(SfxUndoContext &);
      90             :     virtual void RedoWithContext(SfxUndoContext &);
      91             :     virtual void Repeat(SfxRepeatTarget &);
      92             :     virtual bool CanRepeat(SfxRepeatTarget &) const;
      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;
     108             : 
     109             :     // UndoObject remembers which mode was turned on.
     110             :     // In Undo/Redo/Repeat this remembered mode is switched on.
     111       14802 :     sal_uInt16 GetRedlineMode() const { return nOrigRedlineMode; }
     112       14744 :     void SetRedlineMode( sal_uInt16 eMode ) { nOrigRedlineMode = eMode; }
     113             : 
     114             :     bool IsDelBox() const;
     115             : 
     116             :     // Save and set Redline data.
     117             :     static sal_Bool FillSaveData( const SwPaM& rRange, SwRedlineSaveDatas& rSData,
     118             :                             sal_Bool bDelRange = sal_True, sal_Bool bCopyNext = sal_True );
     119             :     static sal_Bool FillSaveDataForFmt( const SwPaM& , SwRedlineSaveDatas& );
     120             :     static void SetSaveData( SwDoc& rDoc, const SwRedlineSaveDatas& rSData );
     121             :     static sal_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             : 
     141             : // This class has to be inherited into an Undo-object if it saves content
     142             : // for Redo/Undo...
     143             : class SwUndoSaveCntnt
     144             : {
     145             : protected:
     146             : 
     147             :     SwHistory* pHistory;
     148             : 
     149             :     // Needed for deletion of content. For Redo content is moved into the
     150             :     // UndoNodesArray. These methods always create a new node to insert
     151             :     // content. So the attributes do not get expanded.
     152             :     // MoveTo:      moves from the NodesArray into the UndoNodesArray.
     153             :     // MoveFrom:    moves from the UndoNodesArray into the NodesArray.
     154             :     void MoveToUndoNds( SwPaM& rPam,
     155             :                         SwNodeIndex* pNodeIdx = 0,
     156             :                         sal_uLong* pEndNdIdx = 0, xub_StrLen * pEndCntIdx = 0 );
     157             :     void MoveFromUndoNds( SwDoc& rDoc, sal_uLong nNodeIdx,
     158             :                           SwPosition& rInsPos,
     159             :                           sal_uLong* pEndNdIdx = 0, xub_StrLen * pEndCntIdx = 0 );
     160             : 
     161             :     // These two methods move the SPoint back/forth from PaM. With it
     162             :     // a range can be spanned for Undo/Redo. (In this case the SPoint
     163             :     // is before the manipulated range!!)
     164             :     // The flag indicates if there is content before the SPoint.
     165             :     sal_Bool MovePtBackward( SwPaM& rPam );
     166             :     void MovePtForward( SwPaM& rPam, sal_Bool bMvBkwrd );
     167             : 
     168             :     // Before moving stuff into UndoNodes-Array care has to be taken that
     169             :     // the content-bearing attributes are removed from the nodes-array.
     170             :     void DelCntntIndex( const SwPosition& pMark, const SwPosition& pPoint,
     171             :                         DelCntntType nDelCntntType = nsDelCntntType::DELCNT_ALL );
     172             : 
     173             : public:
     174             :     SwUndoSaveCntnt();
     175             :     ~SwUndoSaveCntnt();
     176             : };
     177             : 
     178             : // Save a complete section in nodes-array.
     179             : class SwUndoSaveSection : private SwUndoSaveCntnt
     180             : {
     181             :     SwNodeIndex *pMvStt;
     182             :     SwRedlineSaveDatas* pRedlSaveData;
     183             :     sal_uLong nMvLen;           // Index into UndoNodes-Array.
     184             :     sal_uLong nStartPos;
     185             : 
     186             : protected:
     187           5 :     SwNodeIndex* GetMvSttIdx() const { return pMvStt; }
     188           5 :     sal_uLong GetMvNodeCnt() const { return nMvLen; }
     189             : 
     190             : public:
     191             :     SwUndoSaveSection();
     192             :     ~SwUndoSaveSection();
     193             : 
     194             :     void SaveSection( SwDoc* pDoc, const SwNodeIndex& rSttIdx );
     195             :     void SaveSection( SwDoc* pDoc, const SwNodeRange& rRange );
     196             :     void RestoreSection( SwDoc* pDoc, SwNodeIndex* pIdx, sal_uInt16 nSectType );
     197             :     void RestoreSection( SwDoc* pDoc, const SwNodeIndex& rInsPos );
     198             : 
     199             :     const SwHistory* GetHistory() const { return pHistory; }
     200           0 :           SwHistory* GetHistory()       { return pHistory; }
     201             : };
     202             : 
     203             : 
     204             : // This class saves the PaM as sal_uInt16's and is able to restore it
     205             : // into a PaM.
     206             : class SwUndRng
     207             : {
     208             : public:
     209             :     sal_uLong nSttNode, nEndNode;
     210             :     xub_StrLen nSttCntnt, nEndCntnt;
     211             : 
     212             :     SwUndRng();
     213             :     SwUndRng( const SwPaM& );
     214             : 
     215             :     void SetValues( const SwPaM& rPam );
     216             :     void SetPaM( SwPaM&, sal_Bool bCorrToCntnt = sal_False ) const;
     217             :     SwPaM & AddUndoRedoPaM(
     218             :         ::sw::UndoRedoContext &, bool const bCorrToCntnt = false) const;
     219             : };
     220             : 
     221             : 
     222             : class SwUndoInsLayFmt;
     223             : 
     224             : // base class for insertion of Document, Glossaries and Copy
     225             : class SwUndoInserts : public SwUndo, public SwUndRng, private SwUndoSaveCntnt
     226             : {
     227             :     SwTxtFmtColl *pTxtFmtColl, *pLastNdColl;
     228             :     std::vector<SwFrmFmt*>* pFrmFmts;
     229             :     ::std::vector< ::boost::shared_ptr<SwUndoInsLayFmt> > m_FlyUndos;
     230             :     SwRedlineData* pRedlData;
     231             :     sal_Bool bSttWasTxtNd;
     232             : protected:
     233             :     sal_uLong nNdDiff;
     234             :     /// start of Content in UndoNodes for Redo
     235             :     ::boost::scoped_ptr<SwNodeIndex> m_pUndoNodeIndex;
     236             :     sal_uInt16 nSetPos;                 // Start in the history list.
     237             : 
     238             :     SwUndoInserts( SwUndoId nUndoId, const SwPaM& );
     239             : public:
     240             :     virtual ~SwUndoInserts();
     241             : 
     242             :     virtual void UndoImpl( ::sw::UndoRedoContext & );
     243             :     virtual void RedoImpl( ::sw::UndoRedoContext & );
     244             :     virtual void RepeatImpl( ::sw::RepeatContext & );
     245             : 
     246             :     // Set destination range after reading.
     247             :     void SetInsertRange( const SwPaM&, sal_Bool bScanFlys = sal_True,
     248             :                         sal_Bool bSttWasTxtNd = sal_True );
     249             : };
     250             : 
     251           0 : class SwUndoInsDoc : public SwUndoInserts
     252             : {
     253             : public:
     254             :     SwUndoInsDoc( const SwPaM& );
     255             : };
     256             : 
     257           6 : class SwUndoCpyDoc : public SwUndoInserts
     258             : {
     259             : public:
     260             :     SwUndoCpyDoc( const SwPaM& );
     261             : };
     262             : 
     263             : //--------------------------------------------------------------------
     264             : 
     265             : class SwUndoFlyBase : public SwUndo, private SwUndoSaveSection
     266             : {
     267             : protected:
     268             :     SwFrmFmt* pFrmFmt;          // The saved FlyFormat.
     269             :     sal_uLong nNdPgPos;
     270             :     xub_StrLen nCntPos;         // Page at/in paragraph.
     271             :     sal_uInt16 nRndId;
     272             :     sal_Bool bDelFmt;           // Delete saved format.
     273             : 
     274             :     void InsFly(::sw::UndoRedoContext & rContext, bool bShowSel = true);
     275             :     void DelFly( SwDoc* );
     276             : 
     277             :     SwUndoFlyBase( SwFrmFmt* pFormat, SwUndoId nUndoId );
     278             : 
     279           5 :     SwNodeIndex* GetMvSttIdx() const { return SwUndoSaveSection::GetMvSttIdx(); }
     280           5 :     sal_uLong GetMvNodeCnt() const { return SwUndoSaveSection::GetMvNodeCnt(); }
     281             : 
     282             : public:
     283             :     virtual ~SwUndoFlyBase();
     284             : 
     285             : };
     286             : 
     287             : class SwUndoInsLayFmt : public SwUndoFlyBase
     288             : {
     289             :     sal_uLong mnCrsrSaveIndexPara;           // Cursor position
     290             :     xub_StrLen mnCrsrSaveIndexPos;            // for undo
     291             : public:
     292             :     SwUndoInsLayFmt( SwFrmFmt* pFormat, sal_uLong nNodeIdx, xub_StrLen nCntIdx );
     293             : 
     294             :     virtual ~SwUndoInsLayFmt();
     295             : 
     296             :     virtual void UndoImpl( ::sw::UndoRedoContext & );
     297             :     virtual void RedoImpl( ::sw::UndoRedoContext & );
     298             :     virtual void RepeatImpl( ::sw::RepeatContext & );
     299             : 
     300             :     virtual OUString GetComment() const;
     301             : 
     302             : };
     303             : 
     304          10 : class SwUndoDelLayFmt : public SwUndoFlyBase
     305             : {
     306             :     sal_Bool bShowSelFrm;
     307             : public:
     308             :     SwUndoDelLayFmt( SwFrmFmt* pFormat );
     309             : 
     310             :     virtual void UndoImpl( ::sw::UndoRedoContext & );
     311             :     virtual void RedoImpl( ::sw::UndoRedoContext & );
     312             : 
     313             :     void RedoForRollback();
     314             : 
     315           0 :     void ChgShowSel( sal_Bool bNew ) { bShowSelFrm = bNew; }
     316             : 
     317             :     virtual SwRewriter GetRewriter() const;
     318             : 
     319             : };
     320             : 
     321             : #endif
     322             : 
     323             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10