Line data Source code
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 : #ifndef INCLUDED_SW_INC_IDOCUMENTUNDOREDO_HXX
21 : #define INCLUDED_SW_INC_IDOCUMENTUNDOREDO_HXX
22 :
23 : #include <sal/types.h>
24 :
25 : #include <swundo.hxx>
26 :
27 : class SwRewriter;
28 : class SwNodes;
29 : class SwUndo;
30 :
31 : namespace sw {
32 : class RepeatContext;
33 : }
34 :
35 : /** IDocumentUndoRedo
36 : */
37 0 : class IDocumentUndoRedo
38 : {
39 : public:
40 :
41 : /** Enable/Disable Undo.
42 : */
43 : virtual void DoUndo(bool const bDoUndo) = 0;
44 :
45 : /** Is Undo enabled?
46 : */
47 : virtual bool DoesUndo() const = 0;
48 :
49 : /** Enable/Disable Group Undo.
50 : This determines whether successive Insert/Delete/Overwrite
51 : actions are combined.
52 : */
53 : virtual void DoGroupUndo(bool const bDoUndo) = 0;
54 :
55 : /** Is Group Undo enabled?
56 : */
57 : virtual bool DoesGroupUndo() const = 0;
58 :
59 : /** Enable/Disable Undo for Drawing objects.
60 : */
61 : virtual void DoDrawUndo(bool const bDoUndo) = 0;
62 :
63 : /** Is Undo for Drawing objects enabled?
64 : for Draw-Undo: writer wants to handle actions on Flys on its own.
65 : */
66 : virtual bool DoesDrawUndo() const = 0;
67 :
68 : /** Set the position at which the document is in the "unmodified" state
69 : to the current position in the Undo stack.
70 : */
71 : virtual void SetUndoNoModifiedPosition() = 0;
72 :
73 : /** Prevent updates to the "unmodified" state position
74 : via SetUndoNoResetModified().
75 : */
76 : virtual void LockUndoNoModifiedPosition() = 0;
77 :
78 : /** Allow updates to the "unmodified" state position
79 : via SetUndoNoResetModified().
80 : */
81 : virtual void UnLockUndoNoModifiedPosition() = 0;
82 :
83 : /** Disable (re)setting the document modified flag on Undo/Redo.
84 : */
85 : virtual void SetUndoNoResetModified() = 0;
86 :
87 : /** Is setting the document modified flag on Undo/Redo disabled?
88 : */
89 : virtual bool IsUndoNoResetModified() const = 0;
90 :
91 : /** Execute Undo.
92 :
93 : @return true if executing the last Undo action was successful.
94 : */
95 : virtual bool Undo() = 0;
96 :
97 : /** Opens undo block.
98 :
99 : @remark StartUndo() and EndUndo() do nothing if !DoesUndo().
100 :
101 : @param nUndoId undo ID for the list action
102 : @param pRewriter rewriter for comments @see SwUndo::GetComment
103 :
104 : If the given nUndoId is equal to zero an undo object with ID
105 : UNDO_START will be generated.
106 :
107 : @return the undo ID of the created object
108 : */
109 : virtual SwUndoId StartUndo(SwUndoId const eUndoId,
110 : SwRewriter const*const pRewriter) = 0;
111 :
112 : /**
113 : Closes undo block.
114 :
115 : @remark StartUndo() and EndUndo() do nothing if !DoesUndo().
116 :
117 : @param nUndoId undo ID for the list action
118 : @param pRewriter rewriter for comments @see SwUndo::GetComment
119 :
120 : If the given nUndoId is not UNDO_EMPTY or UNDO_END, the comment of
121 : the resulting list action will be set via the nUndoId, applying the
122 : given pRewriter (if not 0). Otherwise the comment of the resulting
123 : list action is unchanged if it has an UndoId that is not UNDO_START
124 : set by StartUndo, and in case the UndoId is UNDO_START the comment
125 : of the list action defaults to the comment of the last action
126 : contained in the list action.
127 : */
128 : virtual SwUndoId EndUndo(SwUndoId const eUndoId,
129 : SwRewriter const*const pRewriter) = 0;
130 :
131 : /**
132 : Delete all Undo actions.
133 : Of course Undo will be disabled during deletion.
134 : */
135 : virtual void DelAllUndoObj() = 0;
136 :
137 : /** Get Id and comment of last Undo action.
138 : @param o_pStr if not 0, receives comment of last Undo action.
139 : @param o_pId if not 0, receives Id of last Undo action.
140 : @return true if there is a Undo action, false if none
141 : */
142 : virtual bool GetLastUndoInfo(OUString *const o_pStr,
143 : SwUndoId *const o_pId) const = 0;
144 :
145 : /** Get comments of Undo actions.
146 : @return comments of all top-level Undo actions.
147 : */
148 : virtual SwUndoComments_t GetUndoComments() const = 0;
149 :
150 : /** Execute Redo.
151 :
152 : @return true if executing the first Redo action was successful.
153 : */
154 : virtual bool Redo() = 0;
155 :
156 : /** Get Id and comment of first Redo action.
157 : @param o_pStr if not 0, receives comment of first Redo action.
158 : @param o_pId if not 0, receives Id of first Redo action.
159 : @return true if there is a Redo action, false if none
160 : */
161 : virtual bool GetFirstRedoInfo(OUString *const o_pStr,
162 : SwUndoId *const o_pId = 0) const = 0;
163 :
164 : /** Get comments of Redo actions.
165 : @return comments of all top-level Redo actions.
166 : */
167 : virtual SwUndoComments_t GetRedoComments() const = 0;
168 :
169 : /** Repeat the last Undo action.
170 : @return true if repeating the last Undo Redo action was attempted.
171 : */
172 : virtual bool Repeat(::sw::RepeatContext & rContext,
173 : sal_uInt16 const nRepeatCnt) = 0;
174 :
175 : /** Get Id and comment of last Undo action, if it is Repeat capable.
176 : @param o_pStr if not 0, receives comment of last Undo action
177 : if it is Repeat capable.
178 : @return Id of last Undo action if it is Repeat capable,
179 : or UNDO_EMPTY if there is none or it is not Repeat capable.
180 : */
181 : virtual SwUndoId GetRepeatInfo(OUString *const o_pStr) const = 0;
182 :
183 : /** Add new Undo action.
184 : Takes over ownership of pUndo.
185 : @remark calls ClearRedo(), except for UNDO_START/UNDO_END.
186 : @remark does nothing if !DoesUndo().
187 : */
188 : virtual void AppendUndo(SwUndo *const pUndo) = 0;
189 :
190 : /** Delete all Redo actions.
191 : */
192 : virtual void ClearRedo() = 0;
193 :
194 : /* Is the given nodes array the Undo nodes array?
195 : */
196 : virtual bool IsUndoNodes(SwNodes const& rNodes) const = 0;
197 :
198 : protected:
199 0 : virtual ~IDocumentUndoRedo() {};
200 : };
201 :
202 : namespace sw {
203 :
204 : class UndoGuard
205 : {
206 : public:
207 :
208 0 : UndoGuard(IDocumentUndoRedo & rUndoRedo)
209 : : m_rUndoRedo(rUndoRedo)
210 0 : , m_bUndoWasEnabled(rUndoRedo.DoesUndo())
211 : {
212 0 : m_rUndoRedo.DoUndo(false);
213 0 : }
214 0 : ~UndoGuard()
215 : {
216 0 : m_rUndoRedo.DoUndo(m_bUndoWasEnabled);
217 0 : }
218 :
219 0 : bool UndoWasEnabled() const
220 : {
221 0 : return m_bUndoWasEnabled;
222 : }
223 :
224 : private:
225 : IDocumentUndoRedo & m_rUndoRedo;
226 : bool const m_bUndoWasEnabled;
227 : };
228 :
229 : class GroupUndoGuard
230 : {
231 : public:
232 :
233 0 : GroupUndoGuard(IDocumentUndoRedo & rUndoRedo)
234 : : m_rUndoRedo(rUndoRedo)
235 0 : , m_bGroupUndoWasEnabled(rUndoRedo.DoesGroupUndo())
236 : {
237 0 : m_rUndoRedo.DoGroupUndo(false);
238 0 : }
239 0 : ~GroupUndoGuard()
240 : {
241 0 : m_rUndoRedo.DoGroupUndo(m_bGroupUndoWasEnabled);
242 0 : }
243 :
244 : private:
245 : IDocumentUndoRedo & m_rUndoRedo;
246 : bool const m_bGroupUndoWasEnabled;
247 : };
248 :
249 : class DrawUndoGuard
250 : {
251 : public:
252 :
253 0 : DrawUndoGuard(IDocumentUndoRedo & rUndoRedo)
254 : : m_rUndoRedo(rUndoRedo)
255 0 : , m_bDrawUndoWasEnabled(rUndoRedo.DoesDrawUndo())
256 : {
257 0 : m_rUndoRedo.DoDrawUndo(false);
258 0 : }
259 0 : ~DrawUndoGuard()
260 : {
261 0 : m_rUndoRedo.DoDrawUndo(m_bDrawUndoWasEnabled);
262 0 : }
263 :
264 : private:
265 : IDocumentUndoRedo & m_rUndoRedo;
266 : bool const m_bDrawUndoWasEnabled;
267 : };
268 :
269 : } // namespace sw
270 :
271 : #endif
272 :
273 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|