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