1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 INCLUDED_SW_INC_IDOCUMENTUNDOREDO_HXX
21 #define INCLUDED_SW_INC_IDOCUMENTUNDOREDO_HXX
23 #include <sal/types.h>
35 class IDocumentUndoRedo
39 /** Enable/Disable Undo.
41 virtual void DoUndo(bool const bDoUndo
) = 0;
45 virtual bool DoesUndo() const = 0;
47 /** Enable/Disable Group Undo.
48 This determines whether successive Insert/Delete/Overwrite
51 virtual void DoGroupUndo(bool const bDoUndo
) = 0;
53 /** Is Group Undo enabled?
55 virtual bool DoesGroupUndo() const = 0;
57 /** Enable/Disable Undo for Drawing objects.
59 virtual void DoDrawUndo(bool const bDoUndo
) = 0;
61 /** Is Undo for Drawing objects enabled?
62 for Draw-Undo: writer wants to handle actions on Flys on its own.
64 virtual bool DoesDrawUndo() const = 0;
66 /** Set the position at which the document is in the "unmodified" state
67 to the current position in the Undo stack.
69 virtual void SetUndoNoModifiedPosition() = 0;
71 /** Prevent updates to the "unmodified" state position
72 via SetUndoNoResetModified().
74 virtual void LockUndoNoModifiedPosition() = 0;
76 /** Allow updates to the "unmodified" state position
77 via SetUndoNoResetModified().
79 virtual void UnLockUndoNoModifiedPosition() = 0;
81 /** Disable (re)setting the document modified flag on Undo/Redo.
83 virtual void SetUndoNoResetModified() = 0;
85 /** Is setting the document modified flag on Undo/Redo disabled?
87 virtual bool IsUndoNoResetModified() const = 0;
91 @return true if executing the last Undo action was successful.
93 virtual bool Undo() = 0;
97 @remark StartUndo() and EndUndo() do nothing if !DoesUndo().
99 @param nUndoId undo ID for the list action
100 @param pRewriter rewriter for comments @see SwUndo::GetComment
102 If the given nUndoId is equal to zero an undo object with ID
103 UNDO_START will be generated.
105 @return the undo ID of the created object
107 virtual SwUndoId
StartUndo(SwUndoId
const eUndoId
,
108 SwRewriter
const*const pRewriter
) = 0;
113 @remark StartUndo() and EndUndo() do nothing if !DoesUndo().
115 @param nUndoId undo ID for the list action
116 @param pRewriter rewriter for comments @see SwUndo::GetComment
118 If the given nUndoId is not UNDO_EMPTY or UNDO_END, the comment of
119 the resulting list action will be set via the nUndoId, applying the
120 given pRewriter (if not 0). Otherwise the comment of the resulting
121 list action is unchanged if it has an UndoId that is not UNDO_START
122 set by StartUndo, and in case the UndoId is UNDO_START the comment
123 of the list action defaults to the comment of the last action
124 contained in the list action.
126 virtual SwUndoId
EndUndo(SwUndoId
const eUndoId
,
127 SwRewriter
const*const pRewriter
) = 0;
130 Delete all Undo actions.
131 Of course Undo will be disabled during deletion.
133 virtual void DelAllUndoObj() = 0;
135 /** Get Id and comment of last Undo action.
136 @param o_pStr if not 0, receives comment of last Undo action.
137 @param o_pId if not 0, receives Id of last Undo action.
138 @return true if there is a Undo action, false if none
140 virtual bool GetLastUndoInfo(OUString
*const o_pStr
,
141 SwUndoId
*const o_pId
) const = 0;
143 /** Get comments of Undo actions.
144 @return comments of all top-level Undo actions.
146 virtual SwUndoComments_t
GetUndoComments() const = 0;
150 @return true if executing the first Redo action was successful.
152 virtual bool Redo() = 0;
154 /** Get Id and comment of first Redo action.
155 @param o_pStr if not 0, receives comment of first Redo action.
156 @param o_pId if not 0, receives Id of first Redo action.
157 @return true if there is a Redo action, false if none
159 virtual bool GetFirstRedoInfo(OUString
*const o_pStr
,
160 SwUndoId
*const o_pId
= 0) const = 0;
162 /** Get comments of Redo actions.
163 @return comments of all top-level Redo actions.
165 virtual SwUndoComments_t
GetRedoComments() const = 0;
167 /** Repeat the last Undo action.
168 @return true if repeating the last Undo Redo action was attempted.
170 virtual bool Repeat(::sw::RepeatContext
& rContext
,
171 sal_uInt16
const nRepeatCnt
) = 0;
173 /** Get Id and comment of last Undo action, if it is Repeat capable.
174 @param o_pStr if not 0, receives comment of last Undo action
175 if it is Repeat capable.
176 @return Id of last Undo action if it is Repeat capable,
177 or UNDO_EMPTY if there is none or it is not Repeat capable.
179 virtual SwUndoId
GetRepeatInfo(OUString
*const o_pStr
) const = 0;
181 /** Add new Undo action.
182 Takes over ownership of pUndo.
183 @remark calls ClearRedo(), except for UNDO_START/UNDO_END.
184 @remark does nothing if !DoesUndo().
186 virtual void AppendUndo(SwUndo
*const pUndo
) = 0;
188 /** Delete all Redo actions.
190 virtual void ClearRedo() = 0;
192 /* Is the given nodes array the Undo nodes array?
194 virtual bool IsUndoNodes(SwNodes
const& rNodes
) const = 0;
196 /** Get the number of Undo actions.
198 virtual size_t GetUndoActionCount(const bool bCurrentLevel
= true) const = 0;
201 virtual ~IDocumentUndoRedo() {};
210 UndoGuard(IDocumentUndoRedo
& rUndoRedo
)
211 : m_rUndoRedo(rUndoRedo
)
212 , m_bUndoWasEnabled(rUndoRedo
.DoesUndo())
214 m_rUndoRedo
.DoUndo(false);
218 m_rUndoRedo
.DoUndo(m_bUndoWasEnabled
);
221 bool UndoWasEnabled() const
223 return m_bUndoWasEnabled
;
227 IDocumentUndoRedo
& m_rUndoRedo
;
228 bool const m_bUndoWasEnabled
;
235 GroupUndoGuard(IDocumentUndoRedo
& rUndoRedo
)
236 : m_rUndoRedo(rUndoRedo
)
237 , m_bGroupUndoWasEnabled(rUndoRedo
.DoesGroupUndo())
239 m_rUndoRedo
.DoGroupUndo(false);
243 m_rUndoRedo
.DoGroupUndo(m_bGroupUndoWasEnabled
);
247 IDocumentUndoRedo
& m_rUndoRedo
;
248 bool const m_bGroupUndoWasEnabled
;
255 DrawUndoGuard(IDocumentUndoRedo
& rUndoRedo
)
256 : m_rUndoRedo(rUndoRedo
)
257 , m_bDrawUndoWasEnabled(rUndoRedo
.DoesDrawUndo())
259 m_rUndoRedo
.DoDrawUndo(false);
263 m_rUndoRedo
.DoDrawUndo(m_bDrawUndoWasEnabled
);
267 IDocumentUndoRedo
& m_rUndoRedo
;
268 bool const m_bDrawUndoWasEnabled
;
275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */