LCOV - code coverage report
Current view: top level - sw/inc - undobj.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 9 12 75.0 %
Date: 2012-08-25 Functions: 11 15 73.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 6 33.3 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : #ifndef SW_UNDOBJ_HXX
      29                 :            : #define SW_UNDOBJ_HXX
      30                 :            : 
      31                 :            : #include <vector>
      32                 :            : 
      33                 :            : #include <boost/shared_ptr.hpp>
      34                 :            : 
      35                 :            : #include <svl/undo.hxx>
      36                 :            : 
      37                 :            : #include <SwRewriter.hxx>
      38                 :            : #include <swundo.hxx>
      39                 :            : 
      40                 :            : class SwHistory;
      41                 :            : class SwIndex;
      42                 :            : class SwPaM;
      43                 :            : struct SwPosition;
      44                 :            : class SwDoc;
      45                 :            : class SwTxtFmtColl;
      46                 :            : class SwFrmFmt;
      47                 :            : class SwNodeIndex;
      48                 :            : class SwNodeRange;
      49                 :            : class SwRedlineData;
      50                 :            : class SwRedlineSaveDatas;
      51                 :            : 
      52                 :            : namespace sw {
      53                 :            :     class UndoRedoContext;
      54                 :            :     class RepeatContext;
      55                 :            : }
      56                 :            : 
      57                 :            : class SwUndo
      58                 :            :     : public SfxUndoAction
      59                 :            : {
      60                 :            :     SwUndoId const m_nId;
      61                 :            :     sal_uInt16 nOrigRedlineMode;
      62                 :            : 
      63                 :            : protected:
      64                 :            :     bool bCacheComment;
      65                 :            :     mutable String * pComment;
      66                 :            : 
      67                 :            :     void RemoveIdxFromSection( SwDoc&, sal_uLong nSttIdx, sal_uLong* pEndIdx = 0 );
      68                 :            :     void RemoveIdxFromRange( SwPaM& rPam, sal_Bool bMoveNext );
      69                 :            :     void RemoveIdxRel( sal_uLong, const SwPosition& );
      70                 :            : 
      71                 :            :     static sal_Bool CanRedlineGroup( SwRedlineSaveDatas& rCurr,
      72                 :            :                                 const SwRedlineSaveDatas& rCheck,
      73                 :            :                                 sal_Bool bCurrIsEnd );
      74                 :            : 
      75                 :            :     /**
      76                 :            :        Returns the rewriter for this object.
      77                 :            : 
      78                 :            :        @return the rewriter for this object
      79                 :            :     */
      80                 :            :     virtual SwRewriter GetRewriter() const;
      81                 :            : 
      82                 :            :     // return type is sal_uInt16 because this overrides SfxUndoAction::GetId()
      83                 :      16654 :     virtual sal_uInt16 GetId() const { return static_cast<sal_uInt16>(m_nId); }
      84                 :            : 
      85                 :            :     // the 4 methods that derived classes have to override
      86                 :            :     // base implementation does nothing
      87                 :            :     virtual void RepeatImpl( ::sw::RepeatContext & );
      88                 :            :     virtual bool CanRepeatImpl( ::sw::RepeatContext & ) const;
      89                 :            : public: // should not be public, but ran into trouble in untbl.cxx
      90                 :            :     virtual void UndoImpl( ::sw::UndoRedoContext & ) = 0;
      91                 :            :     virtual void RedoImpl( ::sw::UndoRedoContext & ) = 0;
      92                 :            : 
      93                 :            : private:
      94                 :            :     // SfxUndoAction
      95                 :            :     virtual void Undo();
      96                 :            :     virtual void Redo();
      97                 :            :     virtual void UndoWithContext(SfxUndoContext &);
      98                 :            :     virtual void RedoWithContext(SfxUndoContext &);
      99                 :            :     virtual void Repeat(SfxRepeatTarget &);
     100                 :            :     virtual sal_Bool CanRepeat(SfxRepeatTarget &) const;
     101                 :            : 
     102                 :            : public:
     103                 :            :     SwUndo(SwUndoId const nId);
     104                 :            :     virtual ~SwUndo();
     105                 :            : 
     106                 :            :     /**
     107                 :            :        Returns textual comment for this undo object.
     108                 :            : 
     109                 :            :        The textual comment is created from the resource string
     110                 :            :        corresponding to this object's ID. The rewriter of this object
     111                 :            :        is applied to the resource string to get the final comment.
     112                 :            : 
     113                 :            :        @return textual comment for this undo object
     114                 :            :     */
     115                 :            :     virtual rtl::OUString GetComment() const;
     116                 :            : 
     117                 :            :     // UndoObject remembers which mode was turned on.
     118                 :            :     // In Undo/Redo/Repeat this remembered mode is switched on.
     119                 :      28525 :     sal_uInt16 GetRedlineMode() const { return nOrigRedlineMode; }
     120                 :      28409 :     void SetRedlineMode( sal_uInt16 eMode ) { nOrigRedlineMode = eMode; }
     121                 :            : 
     122                 :            :     bool IsDelBox() const;
     123                 :            : 
     124                 :            :     // Save and set Redline data.
     125                 :            :     static sal_Bool FillSaveData( const SwPaM& rRange, SwRedlineSaveDatas& rSData,
     126                 :            :                             sal_Bool bDelRange = sal_True, sal_Bool bCopyNext = sal_True );
     127                 :            :     static sal_Bool FillSaveDataForFmt( const SwPaM& , SwRedlineSaveDatas& );
     128                 :            :     static void SetSaveData( SwDoc& rDoc, const SwRedlineSaveDatas& rSData );
     129                 :            :     static sal_Bool HasHiddenRedlines( const SwRedlineSaveDatas& rSData );
     130                 :            : };
     131                 :            : 
     132                 :            : typedef sal_uInt16 DelCntntType;
     133                 :            : namespace nsDelCntntType
     134                 :            : {
     135                 :            :     const DelCntntType DELCNT_FTN = 0x01;
     136                 :            :     const DelCntntType DELCNT_FLY = 0x02;
     137                 :            :     const DelCntntType DELCNT_TOC = 0x04;
     138                 :            :     const DelCntntType DELCNT_BKM = 0x08;
     139                 :            :     const DelCntntType DELCNT_ALL = 0x0F;
     140                 :            :     const DelCntntType DELCNT_CHKNOCNTNT = 0x80;
     141                 :            : }
     142                 :            : 
     143                 :            : /// will DelCntntIndex destroy a frame anchored at character at rAnchorPos?
     144                 :            : bool IsDestroyFrameAnchoredAtChar(SwPosition const & rAnchorPos,
     145                 :            :         SwPosition const & rStart, SwPosition const & rEnd,
     146                 :            :         DelCntntType const nDelCntntType = nsDelCntntType::DELCNT_ALL);
     147                 :            : 
     148                 :            : 
     149                 :            : // This class has to be inherited into an Undo-object if it saves content
     150                 :            : // for Redo/Undo...
     151                 :            : class SwUndoSaveCntnt
     152                 :            : {
     153                 :            : protected:
     154                 :            : 
     155                 :            :     SwHistory* pHistory;
     156                 :            : 
     157                 :            :     // Needed for deletion of content. For Redo content is moved into the
     158                 :            :     // UndoNodesArray. These methods insert a separator for the attributes
     159                 :            :     // at the end of a TextNode. So the attributes do not get expanded.
     160                 :            :     // MoveTo:      moves from the NodesArray into the UndoNodesArray.
     161                 :            :     // MoveFrom:    moves from the UndoNodesArray into the NodesArray.
     162                 :            :     void MoveToUndoNds( SwPaM& rPam,
     163                 :            :                         SwNodeIndex* pNodeIdx = 0, SwIndex* pCntIdx = 0,
     164                 :            :                         sal_uLong* pEndNdIdx = 0, xub_StrLen * pEndCntIdx = 0 );
     165                 :            :     void MoveFromUndoNds( SwDoc& rDoc, sal_uLong nNodeIdx, xub_StrLen nCntntIdx,
     166                 :            :                           SwPosition& rInsPos,
     167                 :            :                           sal_uLong* pEndNdIdx = 0, xub_StrLen * pEndCntIdx = 0 );
     168                 :            : 
     169                 :            :     // These two methods move the SPoint back/forth from PaM. With it
     170                 :            :     // a range can be spanned for Undo/Redo. (In this case the SPoint
     171                 :            :     // is before the manipulated range!!)
     172                 :            :     // The flag indicates if there is content before the SPoint.
     173                 :            :     sal_Bool MovePtBackward( SwPaM& rPam );
     174                 :            :     void MovePtForward( SwPaM& rPam, sal_Bool bMvBkwrd );
     175                 :            : 
     176                 :            :     // Before moving stuff into UndoNodes-Array care has to be taken that
     177                 :            :     // the content-bearing attributes are removed from the nodes-array.
     178                 :            :     void DelCntntIndex( const SwPosition& pMark, const SwPosition& pPoint,
     179                 :            :                         DelCntntType nDelCntntType = nsDelCntntType::DELCNT_ALL );
     180                 :            : 
     181                 :            : public:
     182                 :            :     SwUndoSaveCntnt();
     183                 :            :     ~SwUndoSaveCntnt();
     184                 :            : };
     185                 :            : 
     186                 :            : // Save a complete section in nodes-array.
     187                 :            : class SwUndoSaveSection : private SwUndoSaveCntnt
     188                 :            : {
     189                 :            :     SwNodeIndex *pMvStt;
     190                 :            :     SwRedlineSaveDatas* pRedlSaveData;
     191                 :            :     sal_uLong nMvLen;           // Index into UndoNodes-Array.
     192                 :            :     sal_uLong nStartPos;
     193                 :            : 
     194                 :            : protected:
     195                 :         10 :     SwNodeIndex* GetMvSttIdx() const { return pMvStt; }
     196                 :         10 :     sal_uLong GetMvNodeCnt() const { return nMvLen; }
     197                 :            : 
     198                 :            : public:
     199                 :            :     SwUndoSaveSection();
     200                 :            :     ~SwUndoSaveSection();
     201                 :            : 
     202                 :            :     void SaveSection( SwDoc* pDoc, const SwNodeIndex& rSttIdx );
     203                 :            :     void SaveSection( SwDoc* pDoc, const SwNodeRange& rRange );
     204                 :            :     void RestoreSection( SwDoc* pDoc, SwNodeIndex* pIdx, sal_uInt16 nSectType );
     205                 :            :     void RestoreSection( SwDoc* pDoc, const SwNodeIndex& rInsPos );
     206                 :            : 
     207                 :            :     const SwHistory* GetHistory() const { return pHistory; }
     208                 :          0 :           SwHistory* GetHistory()       { return pHistory; }
     209                 :            : };
     210                 :            : 
     211                 :            : 
     212                 :            : // This class saves the PaM as sal_uInt16's and is able to restore it
     213                 :            : // into a PaM.
     214                 :            : class SwUndRng
     215                 :            : {
     216                 :            : public:
     217                 :            :     sal_uLong nSttNode, nEndNode;
     218                 :            :     xub_StrLen nSttCntnt, nEndCntnt;
     219                 :            : 
     220                 :            :     SwUndRng();
     221                 :            :     SwUndRng( const SwPaM& );
     222                 :            : 
     223                 :            :     void SetValues( const SwPaM& rPam );
     224                 :            :     void SetPaM( SwPaM&, sal_Bool bCorrToCntnt = sal_False ) const;
     225                 :            :     SwPaM & AddUndoRedoPaM(
     226                 :            :         ::sw::UndoRedoContext &, bool const bCorrToCntnt = false) const;
     227                 :            : };
     228                 :            : 
     229                 :            : 
     230                 :            : class SwUndoInsLayFmt;
     231                 :            : 
     232                 :            : // base class for insertion of Document, Glossaries and Copy
     233                 :            : class SwUndoInserts : public SwUndo, public SwUndRng, private SwUndoSaveCntnt
     234                 :            : {
     235                 :            :     SwTxtFmtColl *pTxtFmtColl, *pLastNdColl;
     236                 :            :     std::vector<SwFrmFmt*>* pFrmFmts;
     237                 :            :     ::std::vector< ::boost::shared_ptr<SwUndoInsLayFmt> > m_FlyUndos;
     238                 :            :     SwRedlineData* pRedlData;
     239                 :            :     sal_Bool bSttWasTxtNd;
     240                 :            : protected:
     241                 :            :     sal_uLong nNdDiff;
     242                 :            :     SwPosition *pPos;                   // Content for Redo.
     243                 :            :     sal_uInt16 nSetPos;                 // Start in the history list.
     244                 :            : 
     245                 :            :     SwUndoInserts( SwUndoId nUndoId, const SwPaM& );
     246                 :            : public:
     247                 :            :     virtual ~SwUndoInserts();
     248                 :            : 
     249                 :            :     virtual void UndoImpl( ::sw::UndoRedoContext & );
     250                 :            :     virtual void RedoImpl( ::sw::UndoRedoContext & );
     251                 :            :     virtual void RepeatImpl( ::sw::RepeatContext & );
     252                 :            : 
     253                 :            :     // Set destination range after reading.
     254                 :            :     void SetInsertRange( const SwPaM&, sal_Bool bScanFlys = sal_True,
     255                 :            :                         sal_Bool bSttWasTxtNd = sal_True );
     256                 :            : };
     257                 :            : 
     258         [ #  # ]:          0 : class SwUndoInsDoc : public SwUndoInserts
     259                 :            : {
     260                 :            : public:
     261                 :            :     SwUndoInsDoc( const SwPaM& );
     262                 :            : };
     263                 :            : 
     264         [ -  + ]:         12 : class SwUndoCpyDoc : public SwUndoInserts
     265                 :            : {
     266                 :            : public:
     267                 :            :     SwUndoCpyDoc( const SwPaM& );
     268                 :            : };
     269                 :            : 
     270                 :            : //--------------------------------------------------------------------
     271                 :            : 
     272                 :            : class SwUndoFlyBase : public SwUndo, private SwUndoSaveSection
     273                 :            : {
     274                 :            : protected:
     275                 :            :     SwFrmFmt* pFrmFmt;          // The saved FlyFormat.
     276                 :            :     sal_uLong nNdPgPos;
     277                 :            :     xub_StrLen nCntPos;         // Page at/in paragraph.
     278                 :            :     sal_uInt16 nRndId;
     279                 :            :     sal_Bool bDelFmt;           // Delete saved format.
     280                 :            : 
     281                 :            :     void InsFly(::sw::UndoRedoContext & rContext, bool bShowSel = true);
     282                 :            :     void DelFly( SwDoc* );
     283                 :            : 
     284                 :            :     SwUndoFlyBase( SwFrmFmt* pFormat, SwUndoId nUndoId );
     285                 :            : 
     286                 :         10 :     SwNodeIndex* GetMvSttIdx() const { return SwUndoSaveSection::GetMvSttIdx(); }
     287                 :         10 :     sal_uLong GetMvNodeCnt() const { return SwUndoSaveSection::GetMvNodeCnt(); }
     288                 :            : 
     289                 :            : public:
     290                 :            :     virtual ~SwUndoFlyBase();
     291                 :            : 
     292                 :            : };
     293                 :            : 
     294                 :            : class SwUndoInsLayFmt : public SwUndoFlyBase
     295                 :            : {
     296                 :            :     sal_uLong mnCrsrSaveIndexPara;           // Cursor position
     297                 :            :     xub_StrLen mnCrsrSaveIndexPos;            // for undo
     298                 :            : public:
     299                 :            :     SwUndoInsLayFmt( SwFrmFmt* pFormat, sal_uLong nNodeIdx, xub_StrLen nCntIdx );
     300                 :            : 
     301                 :            :     virtual ~SwUndoInsLayFmt();
     302                 :            : 
     303                 :            :     virtual void UndoImpl( ::sw::UndoRedoContext & );
     304                 :            :     virtual void RedoImpl( ::sw::UndoRedoContext & );
     305                 :            :     virtual void RepeatImpl( ::sw::RepeatContext & );
     306                 :            : 
     307                 :            :     virtual rtl::OUString GetComment() const;
     308                 :            : 
     309                 :            : };
     310                 :            : 
     311         [ -  + ]:         20 : class SwUndoDelLayFmt : public SwUndoFlyBase
     312                 :            : {
     313                 :            :     sal_Bool bShowSelFrm;
     314                 :            : public:
     315                 :            :     SwUndoDelLayFmt( SwFrmFmt* pFormat );
     316                 :            : 
     317                 :            :     virtual void UndoImpl( ::sw::UndoRedoContext & );
     318                 :            :     virtual void RedoImpl( ::sw::UndoRedoContext & );
     319                 :            : 
     320                 :            :     void RedoForRollback();
     321                 :            : 
     322                 :          0 :     void ChgShowSel( sal_Bool bNew ) { bShowSelFrm = bNew; }
     323                 :            : 
     324                 :            :     virtual SwRewriter GetRewriter() const;
     325                 :            : 
     326                 :            : };
     327                 :            : 
     328                 :            : #endif
     329                 :            : 
     330                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10