11d2dbeb0SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 31d2dbeb0SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 41d2dbeb0SAndrew Rist * or more contributor license agreements. See the NOTICE file 51d2dbeb0SAndrew Rist * distributed with this work for additional information 61d2dbeb0SAndrew Rist * regarding copyright ownership. The ASF licenses this file 71d2dbeb0SAndrew Rist * to you under the Apache License, Version 2.0 (the 81d2dbeb0SAndrew Rist * "License"); you may not use this file except in compliance 91d2dbeb0SAndrew Rist * with the License. You may obtain a copy of the License at 101d2dbeb0SAndrew Rist * 111d2dbeb0SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 121d2dbeb0SAndrew Rist * 131d2dbeb0SAndrew Rist * Unless required by applicable law or agreed to in writing, 141d2dbeb0SAndrew Rist * software distributed under the License is distributed on an 151d2dbeb0SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 161d2dbeb0SAndrew Rist * KIND, either express or implied. See the License for the 171d2dbeb0SAndrew Rist * specific language governing permissions and limitations 181d2dbeb0SAndrew Rist * under the License. 191d2dbeb0SAndrew Rist * 201d2dbeb0SAndrew Rist *************************************************************/ 211d2dbeb0SAndrew Rist 221d2dbeb0SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef IDOCUMENTUNDOREDO_HXX_INCLUDED 25cdf0e10cSrcweir #define IDOCUMENTUNDOREDO_HXX_INCLUDED 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <sal/types.h> 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <swundo.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir 32cdf0e10cSrcweir class SwRewriter; 33cdf0e10cSrcweir class SwNodes; 34cdf0e10cSrcweir class SwUndo; 35cdf0e10cSrcweir 36cdf0e10cSrcweir namespace sw { 37cdf0e10cSrcweir class RepeatContext; 38cdf0e10cSrcweir } 39cdf0e10cSrcweir 40cdf0e10cSrcweir 41cdf0e10cSrcweir 42cdf0e10cSrcweir /** IDocumentUndoRedo 43cdf0e10cSrcweir */ 44cdf0e10cSrcweir class IDocumentUndoRedo 45cdf0e10cSrcweir { 46cdf0e10cSrcweir public: 47cdf0e10cSrcweir 48cdf0e10cSrcweir /** Enable/Disable Undo. 49cdf0e10cSrcweir */ 50cdf0e10cSrcweir virtual void DoUndo(bool const bDoUndo) = 0; 51cdf0e10cSrcweir 52cdf0e10cSrcweir /** Is Undo enabled? 53cdf0e10cSrcweir */ 54cdf0e10cSrcweir virtual bool DoesUndo() const = 0; 55cdf0e10cSrcweir 56cdf0e10cSrcweir /** Enable/Disable Group Undo. 57cdf0e10cSrcweir This determines whether successive Insert/Delete/Overwrite 58cdf0e10cSrcweir actions are combined. 59cdf0e10cSrcweir */ 60cdf0e10cSrcweir virtual void DoGroupUndo(bool const bDoUndo) = 0; 61cdf0e10cSrcweir 62cdf0e10cSrcweir /** Is Group Undo enabled? 63cdf0e10cSrcweir */ 64cdf0e10cSrcweir virtual bool DoesGroupUndo() const = 0; 65cdf0e10cSrcweir 66cdf0e10cSrcweir /** Enable/Disable Undo for Drawing objects. 67cdf0e10cSrcweir */ 68cdf0e10cSrcweir virtual void DoDrawUndo(bool const bDoUndo) = 0; 69cdf0e10cSrcweir 70cdf0e10cSrcweir /** Is Undo for Drawing objects enabled? 71cdf0e10cSrcweir for Draw-Undo: writer wants to handle actions on Flys on its own. 72cdf0e10cSrcweir */ 73cdf0e10cSrcweir virtual bool DoesDrawUndo() const = 0; 74cdf0e10cSrcweir 75cdf0e10cSrcweir /** Set the position at which the document is in the "unmodified" state 76cdf0e10cSrcweir to the current position in the Undo stack. 77cdf0e10cSrcweir */ 78cdf0e10cSrcweir virtual void SetUndoNoModifiedPosition() = 0; 79cdf0e10cSrcweir 80cdf0e10cSrcweir /** Prevent updates to the "unmodified" state position 81cdf0e10cSrcweir via SetUndoNoResetModified(). 82cdf0e10cSrcweir */ 83cdf0e10cSrcweir virtual void LockUndoNoModifiedPosition() = 0; 84cdf0e10cSrcweir 85cdf0e10cSrcweir /** Allow updates to the "unmodified" state position 86cdf0e10cSrcweir via SetUndoNoResetModified(). 87cdf0e10cSrcweir */ 88cdf0e10cSrcweir virtual void UnLockUndoNoModifiedPosition() = 0; 89cdf0e10cSrcweir 90cdf0e10cSrcweir /** Disable (re)setting the document modified flag on Undo/Redo. 91cdf0e10cSrcweir */ 92cdf0e10cSrcweir virtual void SetUndoNoResetModified() = 0; 93cdf0e10cSrcweir 94cdf0e10cSrcweir /** Is setting the document modified flag on Undo/Redo disabled? 95cdf0e10cSrcweir */ 96cdf0e10cSrcweir virtual bool IsUndoNoResetModified() const = 0; 97cdf0e10cSrcweir 98cdf0e10cSrcweir /** Execute Undo. 99cdf0e10cSrcweir 100cdf0e10cSrcweir @return true if executing the last Undo action was successful. 101cdf0e10cSrcweir */ 102cdf0e10cSrcweir virtual sal_Bool Undo() = 0; 103cdf0e10cSrcweir 104cdf0e10cSrcweir /** Opens undo block. 105cdf0e10cSrcweir 106cdf0e10cSrcweir @remark StartUndo() and EndUndo() do nothing if !DoesUndo(). 107cdf0e10cSrcweir 108cdf0e10cSrcweir @param nUndoId undo ID for the list action 109cdf0e10cSrcweir @param pRewriter rewriter for comments @see SwUndo::GetComment 110cdf0e10cSrcweir 111cdf0e10cSrcweir If the given nUndoId is equal to zero an undo object with ID 112cdf0e10cSrcweir UNDO_START will be generated. 113cdf0e10cSrcweir 114cdf0e10cSrcweir @return the undo ID of the created object 115cdf0e10cSrcweir */ 116cdf0e10cSrcweir virtual SwUndoId StartUndo(SwUndoId const eUndoId, 117cdf0e10cSrcweir SwRewriter const*const pRewriter) = 0; 118cdf0e10cSrcweir 119cdf0e10cSrcweir /** 120cdf0e10cSrcweir Closes undo block. 121cdf0e10cSrcweir 122cdf0e10cSrcweir @remark StartUndo() and EndUndo() do nothing if !DoesUndo(). 123cdf0e10cSrcweir 124cdf0e10cSrcweir @param nUndoId undo ID for the list action 125cdf0e10cSrcweir @param pRewriter rewriter for comments @see SwUndo::GetComment 126cdf0e10cSrcweir 127cdf0e10cSrcweir If the given nUndoId is not UNDO_EMPTY or UNDO_END, the comment of 128cdf0e10cSrcweir the resulting list action will be set via the nUndoId, applying the 129cdf0e10cSrcweir given pRewriter (if not 0). Otherwise the comment of the resulting 130cdf0e10cSrcweir list action is unchanged if it has an UndoId that is not UNDO_START 131cdf0e10cSrcweir set by StartUndo, and in case the UndoId is UNDO_START the comment 132cdf0e10cSrcweir of the list action defaults to the comment of the last action 133cdf0e10cSrcweir contained in the list action. 134cdf0e10cSrcweir */ 135cdf0e10cSrcweir virtual SwUndoId EndUndo(SwUndoId const eUndoId, 136cdf0e10cSrcweir SwRewriter const*const pRewriter) = 0; 137cdf0e10cSrcweir 138cdf0e10cSrcweir /** <- #111827# 139cdf0e10cSrcweir Delete all Undo actions. 140cdf0e10cSrcweir Of course Undo will be disabled during deletion. 141cdf0e10cSrcweir */ 142cdf0e10cSrcweir virtual void DelAllUndoObj() = 0; 143cdf0e10cSrcweir 144cdf0e10cSrcweir /** Get Id and comment of last Undo action. 145cdf0e10cSrcweir @param o_pStr if not 0, receives comment of last Undo action. 146cdf0e10cSrcweir @param o_pId if not 0, receives Id of last Undo action. 147cdf0e10cSrcweir @return true if there is a Undo action, false if none 148cdf0e10cSrcweir */ 149cdf0e10cSrcweir virtual bool GetLastUndoInfo(::rtl::OUString *const o_pStr, 150cdf0e10cSrcweir SwUndoId *const o_pId) const = 0; 151cdf0e10cSrcweir 152cdf0e10cSrcweir /** Get comments of Undo actions. 153cdf0e10cSrcweir @return comments of all top-level Undo actions. 154cdf0e10cSrcweir */ 155cdf0e10cSrcweir virtual SwUndoComments_t GetUndoComments() const = 0; 156cdf0e10cSrcweir 157cdf0e10cSrcweir /** Execute Redo. 158cdf0e10cSrcweir 159cdf0e10cSrcweir @return true if executing the first Redo action was successful. 160cdf0e10cSrcweir */ 161cdf0e10cSrcweir virtual sal_Bool Redo() = 0; 162cdf0e10cSrcweir 163*89358e0fSOliver-Rainer Wittmann /** Get Id and comment of first Redo action. 164cdf0e10cSrcweir @param o_pStr if not 0, receives comment of first Redo action. 165*89358e0fSOliver-Rainer Wittmann @param o_pId if not 0, receives Id of first Redo action. 166cdf0e10cSrcweir @return true if there is a Redo action, false if none 167cdf0e10cSrcweir */ 168*89358e0fSOliver-Rainer Wittmann virtual bool GetFirstRedoInfo(::rtl::OUString *const o_pStr, 169*89358e0fSOliver-Rainer Wittmann SwUndoId *const o_pId = 0) const = 0; 170cdf0e10cSrcweir 171cdf0e10cSrcweir /** Get comments of Redo actions. 172cdf0e10cSrcweir @return comments of all top-level Redo actions. 173cdf0e10cSrcweir */ 174cdf0e10cSrcweir virtual SwUndoComments_t GetRedoComments() const = 0; 175cdf0e10cSrcweir 176cdf0e10cSrcweir /** Repeat the last Undo action. 177cdf0e10cSrcweir @return true if repeating the last Undo Redo action was attempted. 178cdf0e10cSrcweir */ 179cdf0e10cSrcweir virtual bool Repeat(::sw::RepeatContext & rContext, 180cdf0e10cSrcweir sal_uInt16 const nRepeatCnt) = 0; 181cdf0e10cSrcweir 182cdf0e10cSrcweir /** Get Id and comment of last Undo action, if it is Repeat capable. 183cdf0e10cSrcweir @param o_pStr if not 0, receives comment of last Undo action 184cdf0e10cSrcweir if it is Repeat capable. 185cdf0e10cSrcweir @return Id of last Undo action if it is Repeat capable, 186cdf0e10cSrcweir or UNDO_EMPTY if there is none or it is not Repeat capable. 187cdf0e10cSrcweir */ 188cdf0e10cSrcweir virtual SwUndoId GetRepeatInfo(::rtl::OUString *const o_pStr) const = 0; 189cdf0e10cSrcweir 190cdf0e10cSrcweir /** Add new Undo action. 191cdf0e10cSrcweir Takes over ownership of pUndo. 192cdf0e10cSrcweir @remark calls ClearRedo(), except for UNDO_START/UNDO_END. 193cdf0e10cSrcweir @remark does nothing if !DoesUndo(). 194cdf0e10cSrcweir */ 195cdf0e10cSrcweir virtual void AppendUndo(SwUndo *const pUndo) = 0; 196cdf0e10cSrcweir 197cdf0e10cSrcweir /** Delete all Redo actions. 198cdf0e10cSrcweir */ 199cdf0e10cSrcweir virtual void ClearRedo() = 0; 200cdf0e10cSrcweir 201cdf0e10cSrcweir /* Is the given nodes array the Undo nodes array? 202cdf0e10cSrcweir */ 203cdf0e10cSrcweir virtual bool IsUndoNodes(SwNodes const& rNodes) const = 0; 204cdf0e10cSrcweir 205cdf0e10cSrcweir protected: ~IDocumentUndoRedo()206cdf0e10cSrcweir virtual ~IDocumentUndoRedo() {}; 207cdf0e10cSrcweir }; 208cdf0e10cSrcweir 209cdf0e10cSrcweir 210cdf0e10cSrcweir namespace sw { 211cdf0e10cSrcweir 212cdf0e10cSrcweir class UndoGuard 213cdf0e10cSrcweir { 214cdf0e10cSrcweir public: 215cdf0e10cSrcweir UndoGuard(IDocumentUndoRedo & rUndoRedo)216cdf0e10cSrcweir UndoGuard(IDocumentUndoRedo & rUndoRedo) 217cdf0e10cSrcweir : m_rUndoRedo(rUndoRedo) 218cdf0e10cSrcweir , m_bUndoWasEnabled(rUndoRedo.DoesUndo()) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir m_rUndoRedo.DoUndo(false); 221cdf0e10cSrcweir } ~UndoGuard()222cdf0e10cSrcweir ~UndoGuard() 223cdf0e10cSrcweir { 224cdf0e10cSrcweir m_rUndoRedo.DoUndo(m_bUndoWasEnabled); 225cdf0e10cSrcweir } 226cdf0e10cSrcweir UndoWasEnabled() const227cdf0e10cSrcweir bool UndoWasEnabled() const 228cdf0e10cSrcweir { 229cdf0e10cSrcweir return m_bUndoWasEnabled; 230cdf0e10cSrcweir } 231cdf0e10cSrcweir 232cdf0e10cSrcweir private: 233cdf0e10cSrcweir IDocumentUndoRedo & m_rUndoRedo; 234cdf0e10cSrcweir bool const m_bUndoWasEnabled; 235cdf0e10cSrcweir }; 236cdf0e10cSrcweir 237cdf0e10cSrcweir class GroupUndoGuard 238cdf0e10cSrcweir { 239cdf0e10cSrcweir public: 240cdf0e10cSrcweir GroupUndoGuard(IDocumentUndoRedo & rUndoRedo)241cdf0e10cSrcweir GroupUndoGuard(IDocumentUndoRedo & rUndoRedo) 242cdf0e10cSrcweir : m_rUndoRedo(rUndoRedo) 243cdf0e10cSrcweir , m_bGroupUndoWasEnabled(rUndoRedo.DoesGroupUndo()) 244cdf0e10cSrcweir { 245cdf0e10cSrcweir m_rUndoRedo.DoGroupUndo(false); 246cdf0e10cSrcweir } ~GroupUndoGuard()247cdf0e10cSrcweir ~GroupUndoGuard() 248cdf0e10cSrcweir { 249cdf0e10cSrcweir m_rUndoRedo.DoGroupUndo(m_bGroupUndoWasEnabled); 250cdf0e10cSrcweir } 251cdf0e10cSrcweir 252cdf0e10cSrcweir private: 253cdf0e10cSrcweir IDocumentUndoRedo & m_rUndoRedo; 254cdf0e10cSrcweir bool const m_bGroupUndoWasEnabled; 255cdf0e10cSrcweir }; 256cdf0e10cSrcweir 257cdf0e10cSrcweir class DrawUndoGuard 258cdf0e10cSrcweir { 259cdf0e10cSrcweir public: 260cdf0e10cSrcweir DrawUndoGuard(IDocumentUndoRedo & rUndoRedo)261cdf0e10cSrcweir DrawUndoGuard(IDocumentUndoRedo & rUndoRedo) 262cdf0e10cSrcweir : m_rUndoRedo(rUndoRedo) 263cdf0e10cSrcweir , m_bDrawUndoWasEnabled(rUndoRedo.DoesDrawUndo()) 264cdf0e10cSrcweir { 265cdf0e10cSrcweir m_rUndoRedo.DoDrawUndo(false); 266cdf0e10cSrcweir } ~DrawUndoGuard()267cdf0e10cSrcweir ~DrawUndoGuard() 268cdf0e10cSrcweir { 269cdf0e10cSrcweir m_rUndoRedo.DoDrawUndo(m_bDrawUndoWasEnabled); 270cdf0e10cSrcweir } 271cdf0e10cSrcweir 272cdf0e10cSrcweir private: 273cdf0e10cSrcweir IDocumentUndoRedo & m_rUndoRedo; 274cdf0e10cSrcweir bool const m_bDrawUndoWasEnabled; 275cdf0e10cSrcweir }; 276cdf0e10cSrcweir 277cdf0e10cSrcweir 278cdf0e10cSrcweir } // namespace sw 279cdf0e10cSrcweir 280cdf0e10cSrcweir #endif 281cdf0e10cSrcweir 282