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