xref: /aoo41x/main/sw/inc/IDocumentUndoRedo.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef IDOCUMENTUNDOREDO_HXX_INCLUDED
29 #define IDOCUMENTUNDOREDO_HXX_INCLUDED
30 
31 #include <sal/types.h>
32 
33 #include <swundo.hxx>
34 
35 
36 class SwRewriter;
37 class SwNodes;
38 class SwUndo;
39 
40 namespace sw {
41     class RepeatContext;
42 }
43 
44 
45 
46 /** IDocumentUndoRedo
47 */
48 class IDocumentUndoRedo
49 {
50 public:
51 
52     /** Enable/Disable Undo.
53     */
54     virtual void DoUndo(bool const bDoUndo) = 0;
55 
56     /** Is Undo enabled?
57     */
58     virtual bool DoesUndo() const = 0;
59 
60     /** Enable/Disable Group Undo.
61         This determines whether successive Insert/Delete/Overwrite
62         actions are combined.
63     */
64     virtual void DoGroupUndo(bool const bDoUndo) = 0;
65 
66     /** Is Group Undo enabled?
67     */
68     virtual bool DoesGroupUndo() const = 0;
69 
70     /** Enable/Disable Undo for Drawing objects.
71      */
72     virtual void DoDrawUndo(bool const bDoUndo) = 0;
73 
74     /** Is Undo for Drawing objects enabled?
75         for Draw-Undo: writer wants to handle actions on Flys on its own.
76      */
77     virtual bool DoesDrawUndo() const = 0;
78 
79     /** Set the position at which the document is in the "unmodified" state
80         to the current position in the Undo stack.
81     */
82     virtual void SetUndoNoModifiedPosition() = 0;
83 
84     /** Prevent updates to the "unmodified" state position
85         via SetUndoNoResetModified().
86     */
87     virtual void LockUndoNoModifiedPosition() = 0;
88 
89     /** Allow updates to the "unmodified" state position
90         via SetUndoNoResetModified().
91     */
92     virtual void UnLockUndoNoModifiedPosition() = 0;
93 
94     /** Disable (re)setting the document modified flag on Undo/Redo.
95     */
96     virtual void SetUndoNoResetModified() = 0;
97 
98     /** Is setting the document modified flag on Undo/Redo disabled?
99     */
100     virtual bool IsUndoNoResetModified() const = 0;
101 
102     /** Execute Undo.
103 
104         @return     true if executing the last Undo action was successful.
105     */
106     virtual sal_Bool Undo() = 0;
107 
108     /** Opens undo block.
109 
110         @remark     StartUndo() and EndUndo() do nothing if !DoesUndo().
111 
112         @param nUndoId        undo ID for the list action
113         @param pRewriter      rewriter for comments @see SwUndo::GetComment
114 
115         If the given nUndoId is equal to zero an undo object with ID
116         UNDO_START will be generated.
117 
118         @return the undo ID of the created object
119     */
120     virtual SwUndoId StartUndo(SwUndoId const eUndoId,
121                 SwRewriter const*const  pRewriter) = 0;
122 
123     /**
124        Closes undo block.
125 
126        @remark     StartUndo() and EndUndo() do nothing if !DoesUndo().
127 
128        @param nUndoId         undo ID for the list action
129        @param pRewriter       rewriter for comments @see SwUndo::GetComment
130 
131        If the given nUndoId is not UNDO_EMPTY or UNDO_END, the comment of
132        the resulting list action will be set via the nUndoId, applying the
133        given pRewriter (if not 0).  Otherwise the comment of the resulting
134        list action is unchanged if it has an UndoId that is not UNDO_START
135        set by StartUndo, and in case the UndoId is UNDO_START the comment
136        of the list action defaults to the comment of the last action
137        contained in the list action.
138     */
139     virtual SwUndoId EndUndo(SwUndoId const eUndoId,
140                 SwRewriter const*const  pRewriter) = 0;
141 
142     /** <- #111827#
143         Delete all Undo actions.
144         Of course Undo will be disabled during deletion.
145     */
146     virtual void DelAllUndoObj() = 0;
147 
148     /** Get Id and comment of last Undo action.
149         @param o_pStr       if not 0, receives comment of last Undo action.
150         @param o_pId        if not 0, receives Id of last Undo action.
151         @return     true if there is a Undo action, false if none
152     */
153     virtual bool GetLastUndoInfo(::rtl::OUString *const o_pStr,
154                 SwUndoId *const o_pId) const = 0;
155 
156     /** Get comments of Undo actions.
157         @return     comments of all top-level Undo actions.
158     */
159     virtual SwUndoComments_t GetUndoComments() const = 0;
160 
161     /** Execute Redo.
162 
163         @return     true if executing the first Redo action was successful.
164     */
165     virtual sal_Bool Redo() = 0;
166 
167     /** Get comment of first Redo action.
168         @param o_pStr       if not 0, receives comment of first Redo action.
169         @return     true if there is a Redo action, false if none
170     */
171     virtual bool GetFirstRedoInfo(::rtl::OUString *const o_pStr) const = 0;
172 
173     /** Get comments of Redo actions.
174         @return     comments of all top-level Redo actions.
175     */
176     virtual SwUndoComments_t GetRedoComments() const = 0;
177 
178     /** Repeat the last Undo action.
179         @return     true if repeating the last Undo Redo action was attempted.
180     */
181     virtual bool Repeat(::sw::RepeatContext & rContext,
182                 sal_uInt16 const nRepeatCnt) = 0;
183 
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 UNDO_EMPTY if there is none or it is not Repeat capable.
189     */
190     virtual SwUndoId GetRepeatInfo(::rtl::OUString *const o_pStr) const = 0;
191 
192     /** Add new Undo action.
193         Takes over ownership of pUndo.
194         @remark     calls ClearRedo(), except for UNDO_START/UNDO_END.
195         @remark     does nothing if !DoesUndo().
196     */
197     virtual void AppendUndo(SwUndo *const pUndo) = 0;
198 
199     /** Delete all Redo actions.
200     */
201     virtual void ClearRedo() = 0;
202 
203     /* Is the given nodes array the Undo nodes array?
204     */
205     virtual bool IsUndoNodes(SwNodes const& rNodes) const = 0;
206 
207 protected:
208     virtual ~IDocumentUndoRedo() {};
209 };
210 
211 
212 namespace sw {
213 
214 class UndoGuard
215 {
216 public:
217 
218     UndoGuard(IDocumentUndoRedo & rUndoRedo)
219         :   m_rUndoRedo(rUndoRedo)
220         ,   m_bUndoWasEnabled(rUndoRedo.DoesUndo())
221     {
222         m_rUndoRedo.DoUndo(false);
223     }
224     ~UndoGuard()
225     {
226         m_rUndoRedo.DoUndo(m_bUndoWasEnabled);
227     }
228 
229     bool UndoWasEnabled() const
230     {
231         return m_bUndoWasEnabled;
232     }
233 
234 private:
235     IDocumentUndoRedo & m_rUndoRedo;
236     bool const m_bUndoWasEnabled;
237 };
238 
239 class GroupUndoGuard
240 {
241 public:
242 
243     GroupUndoGuard(IDocumentUndoRedo & rUndoRedo)
244         :   m_rUndoRedo(rUndoRedo)
245         ,   m_bGroupUndoWasEnabled(rUndoRedo.DoesGroupUndo())
246     {
247         m_rUndoRedo.DoGroupUndo(false);
248     }
249     ~GroupUndoGuard()
250     {
251         m_rUndoRedo.DoGroupUndo(m_bGroupUndoWasEnabled);
252     }
253 
254 private:
255     IDocumentUndoRedo & m_rUndoRedo;
256     bool const m_bGroupUndoWasEnabled;
257 };
258 
259 class DrawUndoGuard
260 {
261 public:
262 
263     DrawUndoGuard(IDocumentUndoRedo & rUndoRedo)
264         :   m_rUndoRedo(rUndoRedo)
265         ,   m_bDrawUndoWasEnabled(rUndoRedo.DoesDrawUndo())
266     {
267         m_rUndoRedo.DoDrawUndo(false);
268     }
269     ~DrawUndoGuard()
270     {
271         m_rUndoRedo.DoDrawUndo(m_bDrawUndoWasEnabled);
272     }
273 
274 private:
275     IDocumentUndoRedo & m_rUndoRedo;
276     bool const m_bDrawUndoWasEnabled;
277 };
278 
279 
280 } // namespace sw
281 
282 #endif
283 
284