1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir #ifndef SW_UNDOBJ_HXX 28*cdf0e10cSrcweir #define SW_UNDOBJ_HXX 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include <vector> 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include <boost/shared_ptr.hpp> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include <svl/undo.hxx> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <SwRewriter.hxx> 37*cdf0e10cSrcweir #include <swundo.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir class SwHistory; 41*cdf0e10cSrcweir class SwIndex; 42*cdf0e10cSrcweir class SwPaM; 43*cdf0e10cSrcweir struct SwPosition; 44*cdf0e10cSrcweir class SwDoc; 45*cdf0e10cSrcweir class SwTxtFmtColl; 46*cdf0e10cSrcweir class SwFrmFmt; 47*cdf0e10cSrcweir class SwNodeIndex; 48*cdf0e10cSrcweir class SwNodeRange; 49*cdf0e10cSrcweir class SwRedlineData; 50*cdf0e10cSrcweir class SwRedlineSaveDatas; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir namespace sw { 53*cdf0e10cSrcweir class UndoRedoContext; 54*cdf0e10cSrcweir class RepeatContext; 55*cdf0e10cSrcweir } 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir class SwUndo 59*cdf0e10cSrcweir : public SfxUndoAction 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir SwUndoId const m_nId; 62*cdf0e10cSrcweir sal_uInt16 nOrigRedlineMode; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir protected: 65*cdf0e10cSrcweir bool bCacheComment; 66*cdf0e10cSrcweir mutable String * pComment; 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir void RemoveIdxFromSection( SwDoc&, sal_uLong nSttIdx, sal_uLong* pEndIdx = 0 ); 69*cdf0e10cSrcweir void RemoveIdxFromRange( SwPaM& rPam, sal_Bool bMoveNext ); 70*cdf0e10cSrcweir void RemoveIdxRel( sal_uLong, const SwPosition& ); 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir static sal_Bool CanRedlineGroup( SwRedlineSaveDatas& rCurr, 73*cdf0e10cSrcweir const SwRedlineSaveDatas& rCheck, 74*cdf0e10cSrcweir sal_Bool bCurrIsEnd ); 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir // #111827# 77*cdf0e10cSrcweir /** 78*cdf0e10cSrcweir Returns the rewriter for this object. 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir @return the rewriter for this object 81*cdf0e10cSrcweir */ 82*cdf0e10cSrcweir virtual SwRewriter GetRewriter() const; 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir // return type is sal_uInt16 because this overrides SfxUndoAction::GetId() 85*cdf0e10cSrcweir virtual sal_uInt16 GetId() const { return static_cast<sal_uInt16>(m_nId); } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir // the 4 methods that derived classes have to override 88*cdf0e10cSrcweir // base implementation does nothing 89*cdf0e10cSrcweir virtual void RepeatImpl( ::sw::RepeatContext & ); 90*cdf0e10cSrcweir virtual bool CanRepeatImpl( ::sw::RepeatContext & ) const; 91*cdf0e10cSrcweir public: // should not be public, but ran into trouble in untbl.cxx 92*cdf0e10cSrcweir virtual void UndoImpl( ::sw::UndoRedoContext & ) = 0; 93*cdf0e10cSrcweir virtual void RedoImpl( ::sw::UndoRedoContext & ) = 0; 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir private: 96*cdf0e10cSrcweir // SfxUndoAction 97*cdf0e10cSrcweir virtual void Undo(); 98*cdf0e10cSrcweir virtual void Redo(); 99*cdf0e10cSrcweir virtual void UndoWithContext(SfxUndoContext &); 100*cdf0e10cSrcweir virtual void RedoWithContext(SfxUndoContext &); 101*cdf0e10cSrcweir virtual void Repeat(SfxRepeatTarget &); 102*cdf0e10cSrcweir virtual sal_Bool CanRepeat(SfxRepeatTarget &) const; 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir public: 105*cdf0e10cSrcweir SwUndo(SwUndoId const nId); 106*cdf0e10cSrcweir virtual ~SwUndo(); 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir // #111827# 109*cdf0e10cSrcweir /** 110*cdf0e10cSrcweir Returns textual comment for this undo object. 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir The textual comment is created from the resource string 113*cdf0e10cSrcweir corresponding to this object's ID. The rewriter of this object 114*cdf0e10cSrcweir is applied to the resource string to get the final comment. 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir @return textual comment for this undo object 117*cdf0e10cSrcweir */ 118*cdf0e10cSrcweir virtual String GetComment() const; 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir // das UndoObject merkt sich, welcher Mode eingeschaltet war. 121*cdf0e10cSrcweir // In Undo/Redo/Repeat wird dann immer auf diesen zurueck geschaltet 122*cdf0e10cSrcweir sal_uInt16 GetRedlineMode() const { return nOrigRedlineMode; } 123*cdf0e10cSrcweir void SetRedlineMode( sal_uInt16 eMode ) { nOrigRedlineMode = eMode; } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir bool IsDelBox() const; 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir // sicher und setze die RedlineDaten 128*cdf0e10cSrcweir static sal_Bool FillSaveData( const SwPaM& rRange, SwRedlineSaveDatas& rSData, 129*cdf0e10cSrcweir sal_Bool bDelRange = sal_True, sal_Bool bCopyNext = sal_True ); 130*cdf0e10cSrcweir static sal_Bool FillSaveDataForFmt( const SwPaM& , SwRedlineSaveDatas& ); 131*cdf0e10cSrcweir static void SetSaveData( SwDoc& rDoc, const SwRedlineSaveDatas& rSData ); 132*cdf0e10cSrcweir static sal_Bool HasHiddenRedlines( const SwRedlineSaveDatas& rSData ); 133*cdf0e10cSrcweir }; 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir typedef sal_uInt16 DelCntntType; 136*cdf0e10cSrcweir namespace nsDelCntntType 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir const DelCntntType DELCNT_FTN = 0x01; 139*cdf0e10cSrcweir const DelCntntType DELCNT_FLY = 0x02; 140*cdf0e10cSrcweir const DelCntntType DELCNT_TOC = 0x04; 141*cdf0e10cSrcweir const DelCntntType DELCNT_BKM = 0x08; 142*cdf0e10cSrcweir const DelCntntType DELCNT_ALL = 0x0F; 143*cdf0e10cSrcweir const DelCntntType DELCNT_CHKNOCNTNT = 0x80; 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir /// will DelCntntIndex destroy a frame anchored at character at rAnchorPos? 147*cdf0e10cSrcweir bool IsDestroyFrameAnchoredAtChar(SwPosition const & rAnchorPos, 148*cdf0e10cSrcweir SwPosition const & rStart, SwPosition const & rEnd, 149*cdf0e10cSrcweir DelCntntType const nDelCntntType = nsDelCntntType::DELCNT_ALL); 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir // diese Klasse muss in ein Undo-Object vererbt werden, wenn dieses Inhalt 152*cdf0e10cSrcweir // fuers Redo/Undo ... speichert 153*cdf0e10cSrcweir class SwUndoSaveCntnt 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir protected: 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir SwHistory* pHistory; 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir // wird fuer das loeschen von Inhalt benoetigt. Fuer das ReDo werden 160*cdf0e10cSrcweir // Inhalte in das UndoNodesArray verschoben. Diese Methoden fuegen 161*cdf0e10cSrcweir // am Ende eines TextNodes ein Trenner fuer die Attribute. Damit werden 162*cdf0e10cSrcweir // Attribute nicht expandiert. 163*cdf0e10cSrcweir // MoveTo.. verschiebt aus dem NodesArray in das UndoNodesArray 164*cdf0e10cSrcweir // MoveFrom.. verschiebt aus dem UndoNodesArray in das NodesArray 165*cdf0e10cSrcweir void MoveToUndoNds( SwPaM& rPam, 166*cdf0e10cSrcweir SwNodeIndex* pNodeIdx = 0, SwIndex* pCntIdx = 0, 167*cdf0e10cSrcweir sal_uLong* pEndNdIdx = 0, xub_StrLen * pEndCntIdx = 0 ); 168*cdf0e10cSrcweir void MoveFromUndoNds( SwDoc& rDoc, sal_uLong nNodeIdx, xub_StrLen nCntntIdx, 169*cdf0e10cSrcweir SwPosition& rInsPos, 170*cdf0e10cSrcweir sal_uLong* pEndNdIdx = 0, xub_StrLen * pEndCntIdx = 0 ); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir // diese beiden Methoden bewegen den SPoint vom Pam zurueck/vor. Damit 173*cdf0e10cSrcweir // kann fuer ein Undo/Redo ein Bereich aufgespannt werden. (Der 174*cdf0e10cSrcweir // SPoint liegt dann vor dem manipuliertem Bereich !!) 175*cdf0e10cSrcweir // Das Flag gibt an, ob noch vorm SPoint Inhalt steht. 176*cdf0e10cSrcweir sal_Bool MovePtBackward( SwPaM& rPam ); 177*cdf0e10cSrcweir void MovePtForward( SwPaM& rPam, sal_Bool bMvBkwrd ); 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir // vor dem Move ins UndoNodes-Array muss dafuer gesorgt werden, das 180*cdf0e10cSrcweir // die Inhaltstragenden Attribute aus dem Nodes-Array entfernt werden. 181*cdf0e10cSrcweir void DelCntntIndex( const SwPosition& pMark, const SwPosition& pPoint, 182*cdf0e10cSrcweir DelCntntType nDelCntntType = nsDelCntntType::DELCNT_ALL ); 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir public: 185*cdf0e10cSrcweir SwUndoSaveCntnt(); 186*cdf0e10cSrcweir ~SwUndoSaveCntnt(); 187*cdf0e10cSrcweir }; 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir // sicher eine vollstaendige Section im Nodes-Array 191*cdf0e10cSrcweir class SwUndoSaveSection : private SwUndoSaveCntnt 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir SwNodeIndex *pMvStt; 194*cdf0e10cSrcweir SwRedlineSaveDatas* pRedlSaveData; 195*cdf0e10cSrcweir sal_uLong nMvLen; // Index ins UndoNodes-Array 196*cdf0e10cSrcweir sal_uLong nStartPos; 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir protected: 199*cdf0e10cSrcweir SwNodeIndex* GetMvSttIdx() const { return pMvStt; } 200*cdf0e10cSrcweir sal_uLong GetMvNodeCnt() const { return nMvLen; } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir public: 203*cdf0e10cSrcweir SwUndoSaveSection(); 204*cdf0e10cSrcweir ~SwUndoSaveSection(); 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir void SaveSection( SwDoc* pDoc, const SwNodeIndex& rSttIdx ); 207*cdf0e10cSrcweir void SaveSection( SwDoc* pDoc, const SwNodeRange& rRange ); 208*cdf0e10cSrcweir void RestoreSection( SwDoc* pDoc, SwNodeIndex* pIdx, sal_uInt16 nSectType ); 209*cdf0e10cSrcweir void RestoreSection( SwDoc* pDoc, const SwNodeIndex& rInsPos ); 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir const SwHistory* GetHistory() const { return pHistory; } 212*cdf0e10cSrcweir SwHistory* GetHistory() { return pHistory; } 213*cdf0e10cSrcweir }; 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir // Diese Klasse speichert den Pam als sal_uInt16's und kann diese wieder zu 217*cdf0e10cSrcweir // einem PaM zusammensetzen 218*cdf0e10cSrcweir class SwUndRng 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir public: 221*cdf0e10cSrcweir sal_uLong nSttNode, nEndNode; 222*cdf0e10cSrcweir xub_StrLen nSttCntnt, nEndCntnt; 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir SwUndRng(); 225*cdf0e10cSrcweir SwUndRng( const SwPaM& ); 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir void SetValues( const SwPaM& rPam ); 228*cdf0e10cSrcweir void SetPaM( SwPaM&, sal_Bool bCorrToCntnt = sal_False ) const; 229*cdf0e10cSrcweir SwPaM & AddUndoRedoPaM( 230*cdf0e10cSrcweir ::sw::UndoRedoContext &, bool const bCorrToCntnt = false) const; 231*cdf0e10cSrcweir }; 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir class SwUndoInsLayFmt; 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir // base class for insertion of Document, Glossaries and Copy 238*cdf0e10cSrcweir class SwUndoInserts : public SwUndo, public SwUndRng, private SwUndoSaveCntnt 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir SwTxtFmtColl *pTxtFmtColl, *pLastNdColl; 241*cdf0e10cSrcweir SvPtrarr* pFrmFmts; 242*cdf0e10cSrcweir ::std::vector< ::boost::shared_ptr<SwUndoInsLayFmt> > m_FlyUndos; 243*cdf0e10cSrcweir SwRedlineData* pRedlData; 244*cdf0e10cSrcweir sal_Bool bSttWasTxtNd; 245*cdf0e10cSrcweir protected: 246*cdf0e10cSrcweir sal_uLong nNdDiff; 247*cdf0e10cSrcweir SwPosition *pPos; // Inhalt fuers Redo 248*cdf0e10cSrcweir sal_uInt16 nSetPos; // Start in der History-Liste 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir SwUndoInserts( SwUndoId nUndoId, const SwPaM& ); 251*cdf0e10cSrcweir public: 252*cdf0e10cSrcweir virtual ~SwUndoInserts(); 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir virtual void UndoImpl( ::sw::UndoRedoContext & ); 255*cdf0e10cSrcweir virtual void RedoImpl( ::sw::UndoRedoContext & ); 256*cdf0e10cSrcweir virtual void RepeatImpl( ::sw::RepeatContext & ); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir // setze den Destination-Bereich nach dem Einlesen. 259*cdf0e10cSrcweir void SetInsertRange( const SwPaM&, sal_Bool bScanFlys = sal_True, 260*cdf0e10cSrcweir sal_Bool bSttWasTxtNd = sal_True ); 261*cdf0e10cSrcweir }; 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir class SwUndoInsDoc : public SwUndoInserts 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir public: 266*cdf0e10cSrcweir SwUndoInsDoc( const SwPaM& ); 267*cdf0e10cSrcweir }; 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir class SwUndoCpyDoc : public SwUndoInserts 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir public: 272*cdf0e10cSrcweir SwUndoCpyDoc( const SwPaM& ); 273*cdf0e10cSrcweir }; 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir //-------------------------------------------------------------------- 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir class SwUndoFlyBase : public SwUndo, private SwUndoSaveSection 280*cdf0e10cSrcweir { 281*cdf0e10cSrcweir protected: 282*cdf0e10cSrcweir SwFrmFmt* pFrmFmt; // das gespeicherte FlyFormat 283*cdf0e10cSrcweir sal_uLong nNdPgPos; 284*cdf0e10cSrcweir xub_StrLen nCntPos; // Seite/am Absatz/im Absatz 285*cdf0e10cSrcweir sal_uInt16 nRndId; 286*cdf0e10cSrcweir sal_Bool bDelFmt; // loesche das gespeicherte Format 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir void InsFly(::sw::UndoRedoContext & rContext, bool bShowSel = true); 289*cdf0e10cSrcweir void DelFly( SwDoc* ); 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir SwUndoFlyBase( SwFrmFmt* pFormat, SwUndoId nUndoId ); 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir SwNodeIndex* GetMvSttIdx() const { return SwUndoSaveSection::GetMvSttIdx(); } 294*cdf0e10cSrcweir sal_uLong GetMvNodeCnt() const { return SwUndoSaveSection::GetMvNodeCnt(); } 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir public: 297*cdf0e10cSrcweir virtual ~SwUndoFlyBase(); 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir }; 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir class SwUndoInsLayFmt : public SwUndoFlyBase 302*cdf0e10cSrcweir { 303*cdf0e10cSrcweir sal_uLong mnCrsrSaveIndexPara; // Cursor position 304*cdf0e10cSrcweir xub_StrLen mnCrsrSaveIndexPos; // for undo 305*cdf0e10cSrcweir public: 306*cdf0e10cSrcweir SwUndoInsLayFmt( SwFrmFmt* pFormat, sal_uLong nNodeIdx, xub_StrLen nCntIdx ); 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir virtual ~SwUndoInsLayFmt(); 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir virtual void UndoImpl( ::sw::UndoRedoContext & ); 311*cdf0e10cSrcweir virtual void RedoImpl( ::sw::UndoRedoContext & ); 312*cdf0e10cSrcweir virtual void RepeatImpl( ::sw::RepeatContext & ); 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir String GetComment() const; 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir }; 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir class SwUndoDelLayFmt : public SwUndoFlyBase 319*cdf0e10cSrcweir { 320*cdf0e10cSrcweir sal_Bool bShowSelFrm; 321*cdf0e10cSrcweir public: 322*cdf0e10cSrcweir SwUndoDelLayFmt( SwFrmFmt* pFormat ); 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir virtual void UndoImpl( ::sw::UndoRedoContext & ); 325*cdf0e10cSrcweir virtual void RedoImpl( ::sw::UndoRedoContext & ); 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir void RedoForRollback(); 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir void ChgShowSel( sal_Bool bNew ) { bShowSelFrm = bNew; } 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir virtual SwRewriter GetRewriter() const; 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir }; 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir #endif 336