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