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