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 .
22 #include <sal/types.h>
36 class SAL_LOPLUGIN_ANNOTATE("crosscast") IDocumentUndoRedo
40 /** Enable/Disable Undo.
42 virtual void DoUndo(bool const bDoUndo
) = 0;
46 virtual bool DoesUndo() const = 0;
48 /** Enable/Disable Group Undo.
49 This determines whether successive Insert/Delete/Overwrite
52 virtual void DoGroupUndo(bool const bDoUndo
) = 0;
54 /** Is Group Undo enabled?
56 virtual bool DoesGroupUndo() const = 0;
58 /** Enable/Disable Undo for Drawing objects.
60 virtual void DoDrawUndo(bool const bDoUndo
) = 0;
62 /** Is Undo for Drawing objects enabled?
63 for Draw-Undo: writer wants to handle actions on Flys on its own.
65 virtual bool DoesDrawUndo() const = 0;
67 /// Enable repair mode.
68 virtual void DoRepair(bool bRepair
) = 0;
69 /// Is repair mode active?
70 virtual bool DoesRepair() const = 0;
72 /** Set the position at which the document is in the "unmodified" state
73 to the current position in the Undo stack.
75 virtual void SetUndoNoModifiedPosition() = 0;
77 /** Prevent updates to the "unmodified" state position
78 via SetUndoNoResetModified().
80 virtual void LockUndoNoModifiedPosition() = 0;
82 /** Allow updates to the "unmodified" state position
83 via SetUndoNoResetModified().
85 virtual void UnLockUndoNoModifiedPosition() = 0;
87 /** Disable (re)setting the document modified flag on Undo/Redo.
89 virtual void SetUndoNoResetModified() = 0;
91 /** Is setting the document modified flag on Undo/Redo disabled?
93 virtual bool IsUndoNoResetModified() const = 0;
97 @return true if executing the last Undo action was successful.
99 virtual bool Undo() = 0;
101 /** Opens undo block.
103 @remark StartUndo() and EndUndo() do nothing if !DoesUndo().
105 @param nUndoId undo ID for the list action
106 @param pRewriter rewriter for comments @see SwUndo::GetComment
108 If the given nUndoId is equal to zero an undo object with ID
109 SwUndoId::START will be generated.
111 @return the undo ID of the created object
113 virtual SwUndoId
StartUndo(SwUndoId
const eUndoId
,
114 SwRewriter
const*const pRewriter
) = 0;
119 @remark StartUndo() and EndUndo() do nothing if !DoesUndo().
121 @param nUndoId undo ID for the list action
122 @param pRewriter rewriter for comments @see SwUndo::GetComment
124 If the given nUndoId is not SwUndoId::EMPTY or SwUndoId::END, the comment of
125 the resulting list action will be set via the nUndoId, applying the
126 given pRewriter (if not 0). Otherwise the comment of the resulting
127 list action is unchanged if it has an UndoId that is not SwUndoId::START
128 set by StartUndo, and in case the UndoId is SwUndoId::START the comment
129 of the list action defaults to the comment of the last action
130 contained in the list action.
132 virtual SwUndoId
EndUndo(SwUndoId
const eUndoId
,
133 SwRewriter
const*const pRewriter
) = 0;
136 Delete all Undo actions.
137 Of course Undo will be disabled during deletion.
139 virtual void DelAllUndoObj() = 0;
141 /** Get Id and comment of last Undo action.
142 @param o_pStr if not 0, receives comment of last Undo action.
143 @param o_pId if not 0, receives Id of last Undo action.
144 @param pView if not nullptr, get the info for this view
145 @return true if there is a Undo action, false if none
147 virtual bool GetLastUndoInfo(OUString
*const o_pStr
,
148 SwUndoId
*const o_pId
,
149 const SwView
* pView
= nullptr) const = 0;
151 /** Get comments of Undo actions.
152 @return comments of all top-level Undo actions.
154 virtual SwUndoComments_t
GetUndoComments() const = 0;
158 @return true if executing the first Redo action was successful.
160 virtual bool Redo() = 0;
162 /** Get Id and comment of first Redo action.
163 @param o_pStr if not 0, receives comment of first Redo action.
164 @param o_pId if not 0, receives Id of first Redo action.
165 @param pView if not nullptr, get the info for this view
166 @return true if there is a Redo action, false if none
168 virtual bool GetFirstRedoInfo(OUString
*const o_pStr
,
169 SwUndoId
*const o_pId
,
170 const SwView
* pView
= nullptr) const = 0;
172 /** Get comments of Redo actions.
173 @return comments of all top-level Redo actions.
175 virtual SwUndoComments_t
GetRedoComments() const = 0;
177 /** Repeat the last Undo action.
178 @return true if repeating the last Undo Redo action was attempted.
180 virtual bool Repeat(::sw::RepeatContext
& rContext
,
181 sal_uInt16
const nRepeatCnt
) = 0;
183 /** Get Id and comment of last Undo action, if it is Repeat capable.
184 @param o_pStr if not 0, receives comment of last Undo action
185 if it is Repeat capable.
186 @return Id of last Undo action if it is Repeat capable,
187 or SwUndoId::EMPTY if there is none or it is not Repeat capable.
189 virtual SwUndoId
GetRepeatInfo(OUString
*const o_pStr
) const = 0;
191 /** Add new Undo action.
192 Takes over ownership of pUndo.
193 @remark calls ClearRedo(), except for SwUndoId::START/SwUndoId::END.
194 @remark does nothing if !DoesUndo().
196 virtual void AppendUndo(std::unique_ptr
<SwUndo
> pUndo
) = 0;
198 /** Delete all Redo actions.
200 virtual void ClearRedo() = 0;
202 /* Is the given nodes array the Undo nodes array?
204 virtual bool IsUndoNodes(SwNodes
const& rNodes
) const = 0;
206 /** Get the number of Undo actions.
208 virtual size_t GetUndoActionCount(const bool bCurrentLevel
= true) const = 0;
210 /** Return undo/redo info for this view.
212 virtual void SetView(SwView
* pView
) = 0;
214 /// Zero offset means undoing the top undo action.
215 virtual bool UndoWithOffset(size_t nUndoOffset
) = 0;
218 virtual ~IDocumentUndoRedo() {};
227 UndoGuard(IDocumentUndoRedo
& rUndoRedo
)
228 : m_rUndoRedo(rUndoRedo
)
229 , m_bUndoWasEnabled(rUndoRedo
.DoesUndo())
231 m_rUndoRedo
.DoUndo(false);
235 m_rUndoRedo
.DoUndo(m_bUndoWasEnabled
);
238 bool UndoWasEnabled() const
240 return m_bUndoWasEnabled
;
244 IDocumentUndoRedo
& m_rUndoRedo
;
245 bool const m_bUndoWasEnabled
;
248 /// Blocks grouping undo actions together into an SfxListUndoAction.
253 GroupUndoGuard(IDocumentUndoRedo
& rUndoRedo
)
254 : m_rUndoRedo(rUndoRedo
)
255 , m_bGroupUndoWasEnabled(rUndoRedo
.DoesGroupUndo())
257 m_rUndoRedo
.DoGroupUndo(false);
261 m_rUndoRedo
.DoGroupUndo(m_bGroupUndoWasEnabled
);
265 IDocumentUndoRedo
& m_rUndoRedo
;
266 bool const m_bGroupUndoWasEnabled
;
273 DrawUndoGuard(IDocumentUndoRedo
& rUndoRedo
)
274 : m_rUndoRedo(rUndoRedo
)
275 , m_bDrawUndoWasEnabled(rUndoRedo
.DoesDrawUndo())
277 m_rUndoRedo
.DoDrawUndo(false);
281 m_rUndoRedo
.DoDrawUndo(m_bDrawUndoWasEnabled
);
285 IDocumentUndoRedo
& m_rUndoRedo
;
286 bool const m_bDrawUndoWasEnabled
;
291 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */