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>
37 class IDocumentUndoRedo
41 /** Enable/Disable Undo.
43 virtual void DoUndo(bool const bDoUndo
) = 0;
47 virtual bool DoesUndo() const = 0;
49 /** Enable/Disable Group Undo.
50 This determines whether successive Insert/Delete/Overwrite
53 virtual void DoGroupUndo(bool const bDoUndo
) = 0;
55 /** Is Group Undo enabled?
57 virtual bool DoesGroupUndo() const = 0;
59 /** Enable/Disable Undo for Drawing objects.
61 virtual void DoDrawUndo(bool const bDoUndo
) = 0;
63 /** Is Undo for Drawing objects enabled?
64 for Draw-Undo: writer wants to handle actions on Flys on its own.
66 virtual bool DoesDrawUndo() const = 0;
68 /// Enable repair mode.
69 virtual void DoRepair(bool bRepair
) = 0;
70 /// Is repair mode active?
71 virtual bool DoesRepair() const = 0;
73 /** Set the position at which the document is in the "unmodified" state
74 to the current position in the Undo stack.
76 virtual void SetUndoNoModifiedPosition() = 0;
78 /** Prevent updates to the "unmodified" state position
79 via SetUndoNoResetModified().
81 virtual void LockUndoNoModifiedPosition() = 0;
83 /** Allow updates to the "unmodified" state position
84 via SetUndoNoResetModified().
86 virtual void UnLockUndoNoModifiedPosition() = 0;
88 /** Disable (re)setting the document modified flag on Undo/Redo.
90 virtual void SetUndoNoResetModified() = 0;
92 /** Is setting the document modified flag on Undo/Redo disabled?
94 virtual bool IsUndoNoResetModified() const = 0;
98 @return true if executing the last Undo action was successful.
100 virtual bool Undo() = 0;
102 /** Opens undo block.
104 @remark StartUndo() and EndUndo() do nothing if !DoesUndo().
106 @param nUndoId undo ID for the list action
107 @param pRewriter rewriter for comments @see SwUndo::GetComment
109 If the given nUndoId is equal to zero an undo object with ID
110 SwUndoId::START will be generated.
112 @return the undo ID of the created object
114 virtual SwUndoId
StartUndo(SwUndoId
const eUndoId
,
115 SwRewriter
const*const pRewriter
) = 0;
120 @remark StartUndo() and EndUndo() do nothing if !DoesUndo().
122 @param nUndoId undo ID for the list action
123 @param pRewriter rewriter for comments @see SwUndo::GetComment
125 If the given nUndoId is not SwUndoId::EMPTY or SwUndoId::END, the comment of
126 the resulting list action will be set via the nUndoId, applying the
127 given pRewriter (if not 0). Otherwise the comment of the resulting
128 list action is unchanged if it has an UndoId that is not SwUndoId::START
129 set by StartUndo, and in case the UndoId is SwUndoId::START the comment
130 of the list action defaults to the comment of the last action
131 contained in the list action.
133 virtual SwUndoId
EndUndo(SwUndoId
const eUndoId
,
134 SwRewriter
const*const pRewriter
) = 0;
137 Delete all Undo actions.
138 Of course Undo will be disabled during deletion.
140 virtual void DelAllUndoObj() = 0;
142 /** Get Id and comment of last Undo action.
143 @param o_pStr if not 0, receives comment of last Undo action.
144 @param o_pId if not 0, receives Id of last Undo action.
145 @param pView if not nullptr, get the info for this view
146 @return true if there is a Undo action, false if none
148 virtual bool GetLastUndoInfo(OUString
*const o_pStr
,
149 SwUndoId
*const o_pId
,
150 const SwView
* pView
= nullptr) const = 0;
152 /** Get comments of Undo actions.
153 @return comments of all top-level Undo actions.
155 virtual SwUndoComments_t
GetUndoComments() const = 0;
159 @return true if executing the first Redo action was successful.
161 virtual bool Redo() = 0;
163 /** Get Id and comment of first Redo action.
164 @param o_pStr if not 0, receives comment of first Redo action.
165 @param o_pId if not 0, receives Id of first Redo action.
166 @param pView if not nullptr, get the info for this view
167 @return true if there is a Redo action, false if none
169 virtual bool GetFirstRedoInfo(OUString
*const o_pStr
,
170 SwUndoId
*const o_pId
,
171 const SwView
* pView
= nullptr) const = 0;
173 /** Get comments of Redo actions.
174 @return comments of all top-level Redo actions.
176 virtual SwUndoComments_t
GetRedoComments() const = 0;
178 /** Repeat the last Undo action.
179 @return true if repeating the last Undo Redo action was attempted.
181 virtual bool Repeat(::sw::RepeatContext
& rContext
,
182 sal_uInt16
const nRepeatCnt
) = 0;
184 /** Get Id and comment of last Undo action, if it is Repeat capable.
185 @param o_pStr if not 0, receives comment of last Undo action
186 if it is Repeat capable.
187 @return Id of last Undo action if it is Repeat capable,
188 or SwUndoId::EMPTY if there is none or it is not Repeat capable.
190 virtual SwUndoId
GetRepeatInfo(OUString
*const o_pStr
) const = 0;
192 /** Add new Undo action.
193 Takes over ownership of pUndo.
194 @remark calls ClearRedo(), except for SwUndoId::START/SwUndoId::END.
195 @remark does nothing if !DoesUndo().
197 virtual void AppendUndo(std::unique_ptr
<SwUndo
> pUndo
) = 0;
199 /** Delete all Redo actions.
201 virtual void ClearRedo() = 0;
203 /* Is the given nodes array the Undo nodes array?
205 virtual bool IsUndoNodes(SwNodes
const& rNodes
) const = 0;
207 /** Get the number of Undo actions.
209 virtual size_t GetUndoActionCount(const bool bCurrentLevel
= true) const = 0;
211 /** Return undo/redo info for this view.
213 virtual void SetView(SwView
* pView
) = 0;
216 virtual ~IDocumentUndoRedo() {};
225 UndoGuard(IDocumentUndoRedo
& rUndoRedo
)
226 : m_rUndoRedo(rUndoRedo
)
227 , m_bUndoWasEnabled(rUndoRedo
.DoesUndo())
229 m_rUndoRedo
.DoUndo(false);
233 m_rUndoRedo
.DoUndo(m_bUndoWasEnabled
);
236 bool UndoWasEnabled() const
238 return m_bUndoWasEnabled
;
242 IDocumentUndoRedo
& m_rUndoRedo
;
243 bool const m_bUndoWasEnabled
;
250 GroupUndoGuard(IDocumentUndoRedo
& rUndoRedo
)
251 : m_rUndoRedo(rUndoRedo
)
252 , m_bGroupUndoWasEnabled(rUndoRedo
.DoesGroupUndo())
254 m_rUndoRedo
.DoGroupUndo(false);
258 m_rUndoRedo
.DoGroupUndo(m_bGroupUndoWasEnabled
);
262 IDocumentUndoRedo
& m_rUndoRedo
;
263 bool const m_bGroupUndoWasEnabled
;
270 DrawUndoGuard(IDocumentUndoRedo
& rUndoRedo
)
271 : m_rUndoRedo(rUndoRedo
)
272 , m_bDrawUndoWasEnabled(rUndoRedo
.DoesDrawUndo())
274 m_rUndoRedo
.DoDrawUndo(false);
278 m_rUndoRedo
.DoDrawUndo(m_bDrawUndoWasEnabled
);
282 IDocumentUndoRedo
& m_rUndoRedo
;
283 bool const m_bDrawUndoWasEnabled
;
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */