/src/libreoffice/sw/inc/IDocumentUndoRedo.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include <sal/types.h> |
23 | | |
24 | | #include "swundo.hxx" |
25 | | #include <memory> |
26 | | |
27 | | class SwRewriter; |
28 | | class SwNodes; |
29 | | class SwUndo; |
30 | | class SwView; |
31 | | |
32 | | namespace sw { |
33 | | class RepeatContext; |
34 | | } |
35 | | |
36 | | class SAL_LOPLUGIN_ANNOTATE("crosscast") IDocumentUndoRedo |
37 | | { |
38 | | public: |
39 | | |
40 | | /** Enable/Disable Undo. |
41 | | */ |
42 | | virtual void DoUndo(bool const bDoUndo) = 0; |
43 | | |
44 | | /** Is Undo enabled? |
45 | | */ |
46 | | virtual bool DoesUndo() const = 0; |
47 | | |
48 | | /** Enable/Disable Group Undo. |
49 | | This determines whether successive Insert/Delete/Overwrite |
50 | | actions are combined. |
51 | | */ |
52 | | virtual void DoGroupUndo(bool const bDoUndo) = 0; |
53 | | |
54 | | /** Is Group Undo enabled? |
55 | | */ |
56 | | virtual bool DoesGroupUndo() const = 0; |
57 | | |
58 | | /** Enable/Disable Undo for Drawing objects. |
59 | | */ |
60 | | virtual void DoDrawUndo(bool const bDoUndo) = 0; |
61 | | |
62 | | /** Is Undo for Drawing objects enabled? |
63 | | for Draw-Undo: writer wants to handle actions on Flys on its own. |
64 | | */ |
65 | | virtual bool DoesDrawUndo() const = 0; |
66 | | |
67 | | /// Enable repair mode. |
68 | | virtual void DoRepair(bool bRepair) = 0; |
69 | | /// Is repair mode active? |
70 | | virtual bool DoesRepair() const = 0; |
71 | | |
72 | | /** Set the position at which the document is in the "unmodified" state |
73 | | to the current position in the Undo stack. |
74 | | */ |
75 | | virtual void SetUndoNoModifiedPosition() = 0; |
76 | | |
77 | | /** Prevent updates to the "unmodified" state position |
78 | | via SetUndoNoResetModified(). |
79 | | */ |
80 | | virtual void LockUndoNoModifiedPosition() = 0; |
81 | | |
82 | | /** Allow updates to the "unmodified" state position |
83 | | via SetUndoNoResetModified(). |
84 | | */ |
85 | | virtual void UnLockUndoNoModifiedPosition() = 0; |
86 | | |
87 | | /** Disable (re)setting the document modified flag on Undo/Redo. |
88 | | */ |
89 | | virtual void SetUndoNoResetModified() = 0; |
90 | | |
91 | | /** Is setting the document modified flag on Undo/Redo disabled? |
92 | | */ |
93 | | virtual bool IsUndoNoResetModified() const = 0; |
94 | | |
95 | | /** Execute Undo. |
96 | | |
97 | | @return true if executing the last Undo action was successful. |
98 | | */ |
99 | | virtual bool Undo() = 0; |
100 | | |
101 | | /** Opens undo block. |
102 | | |
103 | | @remark StartUndo() and EndUndo() do nothing if !DoesUndo(). |
104 | | |
105 | | @param nUndoId undo ID for the list action |
106 | | @param pRewriter rewriter for comments @see SwUndo::GetComment |
107 | | |
108 | | If the given nUndoId is equal to zero an undo object with ID |
109 | | SwUndoId::START will be generated. |
110 | | |
111 | | @return the undo ID of the created object |
112 | | */ |
113 | | virtual SwUndoId StartUndo(SwUndoId const eUndoId, |
114 | | SwRewriter const*const pRewriter) = 0; |
115 | | |
116 | | /** |
117 | | Closes undo block. |
118 | | |
119 | | @remark StartUndo() and EndUndo() do nothing if !DoesUndo(). |
120 | | |
121 | | @param nUndoId undo ID for the list action |
122 | | @param pRewriter rewriter for comments @see SwUndo::GetComment |
123 | | |
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. |
131 | | */ |
132 | | virtual SwUndoId EndUndo(SwUndoId const eUndoId, |
133 | | SwRewriter const*const pRewriter) = 0; |
134 | | |
135 | | /** |
136 | | Delete all Undo actions. |
137 | | Of course Undo will be disabled during deletion. |
138 | | */ |
139 | | virtual void DelAllUndoObj() = 0; |
140 | | |
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 |
146 | | */ |
147 | | virtual bool GetLastUndoInfo(OUString *const o_pStr, |
148 | | SwUndoId *const o_pId, |
149 | | const SwView* pView = nullptr) const = 0; |
150 | | |
151 | | /** Get comments of Undo actions. |
152 | | @return comments of all top-level Undo actions. |
153 | | */ |
154 | | virtual SwUndoComments_t GetUndoComments() const = 0; |
155 | | |
156 | | /** Execute Redo. |
157 | | |
158 | | @return true if executing the first Redo action was successful. |
159 | | */ |
160 | | virtual bool Redo() = 0; |
161 | | |
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 |
167 | | */ |
168 | | virtual bool GetFirstRedoInfo(OUString *const o_pStr, |
169 | | SwUndoId *const o_pId, |
170 | | const SwView* pView = nullptr) const = 0; |
171 | | |
172 | | /** Get comments of Redo actions. |
173 | | @return comments of all top-level Redo actions. |
174 | | */ |
175 | | virtual SwUndoComments_t GetRedoComments() const = 0; |
176 | | |
177 | | /** Repeat the last Undo action. |
178 | | @return true if repeating the last Undo Redo action was attempted. |
179 | | */ |
180 | | virtual bool Repeat(::sw::RepeatContext & rContext, |
181 | | sal_uInt16 const nRepeatCnt) = 0; |
182 | | |
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. |
188 | | */ |
189 | | virtual SwUndoId GetRepeatInfo(OUString *const o_pStr) const = 0; |
190 | | |
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(). |
195 | | */ |
196 | | virtual void AppendUndo(std::unique_ptr<SwUndo> pUndo) = 0; |
197 | | |
198 | | /** Delete all Redo actions. |
199 | | */ |
200 | | virtual void ClearRedo() = 0; |
201 | | |
202 | | /* Is the given nodes array the Undo nodes array? |
203 | | */ |
204 | | virtual bool IsUndoNodes(SwNodes const& rNodes) const = 0; |
205 | | |
206 | | /** Get the number of Undo actions. |
207 | | */ |
208 | | virtual size_t GetUndoActionCount(const bool bCurrentLevel = true) const = 0; |
209 | | |
210 | | /** Return undo/redo info for this view. |
211 | | */ |
212 | | virtual void SetView(SwView* pView) = 0; |
213 | | |
214 | | /// Zero offset means undoing the top undo action. |
215 | | virtual bool UndoWithOffset(size_t nUndoOffset) = 0; |
216 | | |
217 | | protected: |
218 | 74.7k | virtual ~IDocumentUndoRedo() {}; |
219 | | }; |
220 | | |
221 | | namespace sw { |
222 | | |
223 | | class UndoGuard |
224 | | { |
225 | | public: |
226 | | |
227 | | UndoGuard(IDocumentUndoRedo & rUndoRedo) |
228 | 1.15M | : m_rUndoRedo(rUndoRedo) |
229 | 1.15M | , m_bUndoWasEnabled(rUndoRedo.DoesUndo()) |
230 | 1.15M | { |
231 | 1.15M | m_rUndoRedo.DoUndo(false); |
232 | 1.15M | } |
233 | | ~UndoGuard() |
234 | 1.15M | { |
235 | 1.15M | m_rUndoRedo.DoUndo(m_bUndoWasEnabled); |
236 | 1.15M | } |
237 | | |
238 | | bool UndoWasEnabled() const |
239 | 152k | { |
240 | 152k | return m_bUndoWasEnabled; |
241 | 152k | } |
242 | | |
243 | | private: |
244 | | IDocumentUndoRedo & m_rUndoRedo; |
245 | | bool const m_bUndoWasEnabled; |
246 | | }; |
247 | | |
248 | | /// Blocks grouping undo actions together into an SfxListUndoAction. |
249 | | class GroupUndoGuard |
250 | | { |
251 | | public: |
252 | | |
253 | | GroupUndoGuard(IDocumentUndoRedo & rUndoRedo) |
254 | 328k | : m_rUndoRedo(rUndoRedo) |
255 | 328k | , m_bGroupUndoWasEnabled(rUndoRedo.DoesGroupUndo()) |
256 | 328k | { |
257 | 328k | m_rUndoRedo.DoGroupUndo(false); |
258 | 328k | } |
259 | | ~GroupUndoGuard() |
260 | 328k | { |
261 | 328k | m_rUndoRedo.DoGroupUndo(m_bGroupUndoWasEnabled); |
262 | 328k | } |
263 | | |
264 | | private: |
265 | | IDocumentUndoRedo & m_rUndoRedo; |
266 | | bool const m_bGroupUndoWasEnabled; |
267 | | }; |
268 | | |
269 | | class DrawUndoGuard |
270 | | { |
271 | | public: |
272 | | |
273 | | DrawUndoGuard(IDocumentUndoRedo & rUndoRedo) |
274 | 24.1k | : m_rUndoRedo(rUndoRedo) |
275 | 24.1k | , m_bDrawUndoWasEnabled(rUndoRedo.DoesDrawUndo()) |
276 | 24.1k | { |
277 | 24.1k | m_rUndoRedo.DoDrawUndo(false); |
278 | 24.1k | } |
279 | | ~DrawUndoGuard() |
280 | 24.1k | { |
281 | 24.1k | m_rUndoRedo.DoDrawUndo(m_bDrawUndoWasEnabled); |
282 | 24.1k | } |
283 | | |
284 | | private: |
285 | | IDocumentUndoRedo & m_rUndoRedo; |
286 | | bool const m_bDrawUndoWasEnabled; |
287 | | }; |
288 | | |
289 | | } // namespace sw |
290 | | |
291 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |