bump product version to 4.1.6.2
[LibreOffice.git] / sw / inc / IDocumentUndoRedo.hxx
blob26e76f0b838f88a20db631468a70b8066bc23274
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef IDOCUMENTUNDOREDO_HXX_INCLUDED
21 #define IDOCUMENTUNDOREDO_HXX_INCLUDED
23 #include <sal/types.h>
25 #include <swundo.hxx>
28 class SwRewriter;
29 class SwNodes;
30 class SwUndo;
32 namespace sw {
33 class RepeatContext;
38 /** IDocumentUndoRedo
40 class IDocumentUndoRedo
42 public:
44 /** Enable/Disable Undo.
46 virtual void DoUndo(bool const bDoUndo) = 0;
48 /** Is Undo enabled?
50 virtual bool DoesUndo() const = 0;
52 /** Enable/Disable Group Undo.
53 This determines whether successive Insert/Delete/Overwrite
54 actions are combined.
56 virtual void DoGroupUndo(bool const bDoUndo) = 0;
58 /** Is Group Undo enabled?
60 virtual bool DoesGroupUndo() const = 0;
62 /** Enable/Disable Undo for Drawing objects.
64 virtual void DoDrawUndo(bool const bDoUndo) = 0;
66 /** Is Undo for Drawing objects enabled?
67 for Draw-Undo: writer wants to handle actions on Flys on its own.
69 virtual bool DoesDrawUndo() const = 0;
71 /** Set the position at which the document is in the "unmodified" state
72 to the current position in the Undo stack.
74 virtual void SetUndoNoModifiedPosition() = 0;
76 /** Prevent updates to the "unmodified" state position
77 via SetUndoNoResetModified().
79 virtual void LockUndoNoModifiedPosition() = 0;
81 /** Allow updates to the "unmodified" state position
82 via SetUndoNoResetModified().
84 virtual void UnLockUndoNoModifiedPosition() = 0;
86 /** Disable (re)setting the document modified flag on Undo/Redo.
88 virtual void SetUndoNoResetModified() = 0;
90 /** Is setting the document modified flag on Undo/Redo disabled?
92 virtual bool IsUndoNoResetModified() const = 0;
94 /** Execute Undo.
96 @return true if executing the last Undo action was successful.
98 virtual sal_Bool Undo() = 0;
100 /** Opens undo block.
102 @remark StartUndo() and EndUndo() do nothing if !DoesUndo().
104 @param nUndoId undo ID for the list action
105 @param pRewriter rewriter for comments @see SwUndo::GetComment
107 If the given nUndoId is equal to zero an undo object with ID
108 UNDO_START will be generated.
110 @return the undo ID of the created object
112 virtual SwUndoId StartUndo(SwUndoId const eUndoId,
113 SwRewriter const*const pRewriter) = 0;
116 Closes undo block.
118 @remark StartUndo() and EndUndo() do nothing if !DoesUndo().
120 @param nUndoId undo ID for the list action
121 @param pRewriter rewriter for comments @see SwUndo::GetComment
123 If the given nUndoId is not UNDO_EMPTY or UNDO_END, the comment of
124 the resulting list action will be set via the nUndoId, applying the
125 given pRewriter (if not 0). Otherwise the comment of the resulting
126 list action is unchanged if it has an UndoId that is not UNDO_START
127 set by StartUndo, and in case the UndoId is UNDO_START the comment
128 of the list action defaults to the comment of the last action
129 contained in the list action.
131 virtual SwUndoId EndUndo(SwUndoId const eUndoId,
132 SwRewriter const*const pRewriter) = 0;
135 Delete all Undo actions.
136 Of course Undo will be disabled during deletion.
138 virtual void DelAllUndoObj() = 0;
140 /** Get Id and comment of last Undo action.
141 @param o_pStr if not 0, receives comment of last Undo action.
142 @param o_pId if not 0, receives Id of last Undo action.
143 @return true if there is a Undo action, false if none
145 virtual bool GetLastUndoInfo(OUString *const o_pStr,
146 SwUndoId *const o_pId) const = 0;
148 /** Get comments of Undo actions.
149 @return comments of all top-level Undo actions.
151 virtual SwUndoComments_t GetUndoComments() const = 0;
153 /** Execute Redo.
155 @return true if executing the first Redo action was successful.
157 virtual sal_Bool Redo() = 0;
159 /** Get comment of first Redo action.
160 @param o_pStr if not 0, receives comment of first Redo action.
161 @return true if there is a Redo action, false if none
163 virtual bool GetFirstRedoInfo(OUString *const o_pStr) const = 0;
165 /** Get comments of Redo actions.
166 @return comments of all top-level Redo actions.
168 virtual SwUndoComments_t GetRedoComments() const = 0;
170 /** Repeat the last Undo action.
171 @return true if repeating the last Undo Redo action was attempted.
173 virtual bool Repeat(::sw::RepeatContext & rContext,
174 sal_uInt16 const nRepeatCnt) = 0;
176 /** Get Id and comment of last Undo action, if it is Repeat capable.
177 @param o_pStr if not 0, receives comment of last Undo action
178 if it is Repeat capable.
179 @return Id of last Undo action if it is Repeat capable,
180 or UNDO_EMPTY if there is none or it is not Repeat capable.
182 virtual SwUndoId GetRepeatInfo(OUString *const o_pStr) const = 0;
184 /** Add new Undo action.
185 Takes over ownership of pUndo.
186 @remark calls ClearRedo(), except for UNDO_START/UNDO_END.
187 @remark does nothing if !DoesUndo().
189 virtual void AppendUndo(SwUndo *const pUndo) = 0;
191 /** Delete all Redo actions.
193 virtual void ClearRedo() = 0;
195 /* Is the given nodes array the Undo nodes array?
197 virtual bool IsUndoNodes(SwNodes const& rNodes) const = 0;
199 protected:
200 virtual ~IDocumentUndoRedo() {};
204 namespace sw {
206 class UndoGuard
208 public:
210 UndoGuard(IDocumentUndoRedo & rUndoRedo)
211 : m_rUndoRedo(rUndoRedo)
212 , m_bUndoWasEnabled(rUndoRedo.DoesUndo())
214 m_rUndoRedo.DoUndo(false);
216 ~UndoGuard()
218 m_rUndoRedo.DoUndo(m_bUndoWasEnabled);
221 bool UndoWasEnabled() const
223 return m_bUndoWasEnabled;
226 private:
227 IDocumentUndoRedo & m_rUndoRedo;
228 bool const m_bUndoWasEnabled;
231 class GroupUndoGuard
233 public:
235 GroupUndoGuard(IDocumentUndoRedo & rUndoRedo)
236 : m_rUndoRedo(rUndoRedo)
237 , m_bGroupUndoWasEnabled(rUndoRedo.DoesGroupUndo())
239 m_rUndoRedo.DoGroupUndo(false);
241 ~GroupUndoGuard()
243 m_rUndoRedo.DoGroupUndo(m_bGroupUndoWasEnabled);
246 private:
247 IDocumentUndoRedo & m_rUndoRedo;
248 bool const m_bGroupUndoWasEnabled;
251 class DrawUndoGuard
253 public:
255 DrawUndoGuard(IDocumentUndoRedo & rUndoRedo)
256 : m_rUndoRedo(rUndoRedo)
257 , m_bDrawUndoWasEnabled(rUndoRedo.DoesDrawUndo())
259 m_rUndoRedo.DoDrawUndo(false);
261 ~DrawUndoGuard()
263 m_rUndoRedo.DoDrawUndo(m_bDrawUndoWasEnabled);
266 private:
267 IDocumentUndoRedo & m_rUndoRedo;
268 bool const m_bDrawUndoWasEnabled;
272 } // namespace sw
274 #endif
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */