xref: /aoo42x/main/sw/inc/IDocumentUndoRedo.hxx (revision 89358e0f)
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 Id and comment of first Redo action.
164         @param o_pStr       if not 0, receives comment of first Redo action.
165         @param o_pId        if not 0, receives Id of first Redo action.
166         @return     true if there is a Redo action, false if none
167     */
168     virtual bool GetFirstRedoInfo(::rtl::OUString *const o_pStr,
169                                   SwUndoId *const o_pId = 0) const = 0;
170 
171     /** Get comments of Redo actions.
172         @return     comments of all top-level Redo actions.
173     */
174     virtual SwUndoComments_t GetRedoComments() const = 0;
175 
176     /** Repeat the last Undo action.
177         @return     true if repeating the last Undo Redo action was attempted.
178     */
179     virtual bool Repeat(::sw::RepeatContext & rContext,
180                 sal_uInt16 const nRepeatCnt) = 0;
181 
182     /** Get Id and comment of last Undo action, if it is Repeat capable.
183         @param o_pStr       if not 0, receives comment of last Undo action
184                             if it is Repeat capable.
185         @return     Id of last Undo action if it is Repeat capable,
186                     or UNDO_EMPTY if there is none or it is not Repeat capable.
187     */
188     virtual SwUndoId GetRepeatInfo(::rtl::OUString *const o_pStr) const = 0;
189 
190     /** Add new Undo action.
191         Takes over ownership of pUndo.
192         @remark     calls ClearRedo(), except for UNDO_START/UNDO_END.
193         @remark     does nothing if !DoesUndo().
194     */
195     virtual void AppendUndo(SwUndo *const pUndo) = 0;
196 
197     /** Delete all Redo actions.
198     */
199     virtual void ClearRedo() = 0;
200 
201     /* Is the given nodes array the Undo nodes array?
202     */
203     virtual bool IsUndoNodes(SwNodes const& rNodes) const = 0;
204 
205 protected:
~IDocumentUndoRedo()206     virtual ~IDocumentUndoRedo() {};
207 };
208 
209 
210 namespace sw {
211 
212 class UndoGuard
213 {
214 public:
215 
UndoGuard(IDocumentUndoRedo & rUndoRedo)216     UndoGuard(IDocumentUndoRedo & rUndoRedo)
217         :   m_rUndoRedo(rUndoRedo)
218         ,   m_bUndoWasEnabled(rUndoRedo.DoesUndo())
219     {
220         m_rUndoRedo.DoUndo(false);
221     }
~UndoGuard()222     ~UndoGuard()
223     {
224         m_rUndoRedo.DoUndo(m_bUndoWasEnabled);
225     }
226 
UndoWasEnabled() const227     bool UndoWasEnabled() const
228     {
229         return m_bUndoWasEnabled;
230     }
231 
232 private:
233     IDocumentUndoRedo & m_rUndoRedo;
234     bool const m_bUndoWasEnabled;
235 };
236 
237 class GroupUndoGuard
238 {
239 public:
240 
GroupUndoGuard(IDocumentUndoRedo & rUndoRedo)241     GroupUndoGuard(IDocumentUndoRedo & rUndoRedo)
242         :   m_rUndoRedo(rUndoRedo)
243         ,   m_bGroupUndoWasEnabled(rUndoRedo.DoesGroupUndo())
244     {
245         m_rUndoRedo.DoGroupUndo(false);
246     }
~GroupUndoGuard()247     ~GroupUndoGuard()
248     {
249         m_rUndoRedo.DoGroupUndo(m_bGroupUndoWasEnabled);
250     }
251 
252 private:
253     IDocumentUndoRedo & m_rUndoRedo;
254     bool const m_bGroupUndoWasEnabled;
255 };
256 
257 class DrawUndoGuard
258 {
259 public:
260 
DrawUndoGuard(IDocumentUndoRedo & rUndoRedo)261     DrawUndoGuard(IDocumentUndoRedo & rUndoRedo)
262         :   m_rUndoRedo(rUndoRedo)
263         ,   m_bDrawUndoWasEnabled(rUndoRedo.DoesDrawUndo())
264     {
265         m_rUndoRedo.DoDrawUndo(false);
266     }
~DrawUndoGuard()267     ~DrawUndoGuard()
268     {
269         m_rUndoRedo.DoDrawUndo(m_bDrawUndoWasEnabled);
270     }
271 
272 private:
273     IDocumentUndoRedo & m_rUndoRedo;
274     bool const m_bDrawUndoWasEnabled;
275 };
276 
277 
278 } // namespace sw
279 
280 #endif
281 
282