xref: /aoo41x/main/svl/inc/svl/undo.hxx (revision 89358e0f)
139a19a47SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
339a19a47SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
439a19a47SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
539a19a47SAndrew Rist  * distributed with this work for additional information
639a19a47SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
739a19a47SAndrew Rist  * to you under the Apache License, Version 2.0 (the
839a19a47SAndrew Rist  * "License"); you may not use this file except in compliance
939a19a47SAndrew Rist  * with the License.  You may obtain a copy of the License at
1039a19a47SAndrew Rist  *
1139a19a47SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1239a19a47SAndrew Rist  *
1339a19a47SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1439a19a47SAndrew Rist  * software distributed under the License is distributed on an
1539a19a47SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1639a19a47SAndrew Rist  * KIND, either express or implied.  See the License for the
1739a19a47SAndrew Rist  * specific language governing permissions and limitations
1839a19a47SAndrew Rist  * under the License.
1939a19a47SAndrew Rist  *
2039a19a47SAndrew Rist  *************************************************************/
2139a19a47SAndrew Rist 
2239a19a47SAndrew Rist 
23cdf0e10cSrcweir #ifndef _UNDO_HXX
24cdf0e10cSrcweir #define _UNDO_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "svl/svldllapi.h"
27cdf0e10cSrcweir #include <tools/rtti.hxx>
28cdf0e10cSrcweir #include <tools/string.hxx>
29cdf0e10cSrcweir #include <svl/svarray.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <boost/scoped_ptr.hpp>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <vector>
34cdf0e10cSrcweir #include <limits>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir //====================================================================
37cdf0e10cSrcweir 
38cdf0e10cSrcweir class SVL_DLLPUBLIC SfxRepeatTarget
39cdf0e10cSrcweir {
40cdf0e10cSrcweir public:
41cdf0e10cSrcweir 						TYPEINFO();
42cdf0e10cSrcweir 	virtual 			~SfxRepeatTarget() = 0;
43cdf0e10cSrcweir };
44cdf0e10cSrcweir 
45cdf0e10cSrcweir //====================================================================
46cdf0e10cSrcweir 
47cdf0e10cSrcweir class SVL_DLLPUBLIC SfxUndoContext
48cdf0e10cSrcweir {
49cdf0e10cSrcweir public:
50cdf0e10cSrcweir     virtual             ~SfxUndoContext() = 0;
51cdf0e10cSrcweir };
52cdf0e10cSrcweir 
53cdf0e10cSrcweir //====================================================================
5401300968SArmin Le Grand class SfxLinkUndoAction;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir class SVL_DLLPUBLIC SfxUndoAction
57cdf0e10cSrcweir {
5801300968SArmin Le Grand private:
5901300968SArmin Le Grand     SfxLinkUndoAction*      mpSfxLinkUndoAction;
6001300968SArmin Le Grand 
61cdf0e10cSrcweir public:
62cdf0e10cSrcweir 							TYPEINFO();
63cdf0e10cSrcweir 							SfxUndoAction();
64cdf0e10cSrcweir 	virtual 				~SfxUndoAction();
65cdf0e10cSrcweir 
6601300968SArmin Le Grand     virtual void SetLinkToSfxLinkUndoAction(SfxLinkUndoAction* pSfxLinkUndoAction);
6701300968SArmin Le Grand 
6801300968SArmin Le Grand     virtual void			Undo();
69cdf0e10cSrcweir     virtual void            UndoWithContext( SfxUndoContext& i_context );
70cdf0e10cSrcweir 	virtual void			Redo();
71cdf0e10cSrcweir     virtual void            RedoWithContext( SfxUndoContext& i_context );
72cdf0e10cSrcweir 	virtual void			Repeat(SfxRepeatTarget&);
73cdf0e10cSrcweir 	virtual sal_Bool			CanRepeat(SfxRepeatTarget&) const;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	virtual sal_Bool			Merge( SfxUndoAction *pNextAction );
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 	virtual UniString       GetComment() const;
78cdf0e10cSrcweir 	virtual UniString       GetRepeatComment(SfxRepeatTarget&) const;
79cdf0e10cSrcweir 	virtual sal_uInt16	GetId() const;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir private:
82cdf0e10cSrcweir 	SfxUndoAction&			operator=( const SfxUndoAction& );	  // n.i.!!
83cdf0e10cSrcweir };
84cdf0e10cSrcweir 
85cdf0e10cSrcweir //========================================================================
86cdf0e10cSrcweir 
87cdf0e10cSrcweir /// is a mark on the Undo stack
88cdf0e10cSrcweir typedef sal_Int32 UndoStackMark;
89cdf0e10cSrcweir #define MARK_INVALID    ::std::numeric_limits< UndoStackMark >::max()
90cdf0e10cSrcweir 
91cdf0e10cSrcweir //========================================================================
92cdf0e10cSrcweir 
93cdf0e10cSrcweir struct MarkedUndoAction
94cdf0e10cSrcweir {
95cdf0e10cSrcweir     SfxUndoAction*                  pAction;
96cdf0e10cSrcweir     ::std::vector< UndoStackMark >  aMarks;
97cdf0e10cSrcweir 
MarkedUndoActionMarkedUndoAction98cdf0e10cSrcweir     MarkedUndoAction( SfxUndoAction* i_action )
99cdf0e10cSrcweir         :pAction( i_action )
100cdf0e10cSrcweir         ,aMarks()
101cdf0e10cSrcweir     {
102cdf0e10cSrcweir     }
103cdf0e10cSrcweir };
104cdf0e10cSrcweir 
105cdf0e10cSrcweir class SfxUndoActions
106cdf0e10cSrcweir {
107cdf0e10cSrcweir private:
108cdf0e10cSrcweir     ::std::vector< MarkedUndoAction > m_aActions;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir public:
SfxUndoActions()111cdf0e10cSrcweir     SfxUndoActions()
112cdf0e10cSrcweir     {
113cdf0e10cSrcweir     }
114cdf0e10cSrcweir 
empty() const115cdf0e10cSrcweir     bool    empty() const { return m_aActions.empty(); }
size() const116cdf0e10cSrcweir     size_t  size() const { return m_aActions.size(); }
117cdf0e10cSrcweir 
operator [](size_t i) const118cdf0e10cSrcweir     const MarkedUndoAction& operator[]( size_t i ) const { return m_aActions[i]; }
operator [](size_t i)119cdf0e10cSrcweir           MarkedUndoAction& operator[]( size_t i )       { return m_aActions[i]; }
120cdf0e10cSrcweir 
Remove(size_t i_pos)121cdf0e10cSrcweir     void    Remove( size_t i_pos )
122cdf0e10cSrcweir     {
123cdf0e10cSrcweir         m_aActions.erase( m_aActions.begin() + i_pos );
124cdf0e10cSrcweir     }
125cdf0e10cSrcweir 
Remove(size_t i_pos,size_t i_count)126cdf0e10cSrcweir     void    Remove( size_t i_pos, size_t i_count )
127cdf0e10cSrcweir     {
128cdf0e10cSrcweir         m_aActions.erase( m_aActions.begin() + i_pos, m_aActions.begin() + i_pos + i_count );
129cdf0e10cSrcweir     }
130cdf0e10cSrcweir 
Insert(SfxUndoAction * i_action,size_t i_pos)131cdf0e10cSrcweir     void    Insert( SfxUndoAction* i_action, size_t i_pos )
132cdf0e10cSrcweir     {
133cdf0e10cSrcweir         m_aActions.insert( m_aActions.begin() + i_pos, MarkedUndoAction( i_action ) );
134cdf0e10cSrcweir     }
135cdf0e10cSrcweir };
136cdf0e10cSrcweir 
137cdf0e10cSrcweir //====================================================================
138cdf0e10cSrcweir 
139cdf0e10cSrcweir /** do not make use of these implementation details, unless you
140cdf0e10cSrcweir 	really really have to! */
141cdf0e10cSrcweir struct SVL_DLLPUBLIC SfxUndoArray
142cdf0e10cSrcweir {
143cdf0e10cSrcweir 	SfxUndoActions          aUndoActions;
144cdf0e10cSrcweir 	size_t					nMaxUndoActions;
145cdf0e10cSrcweir 	size_t					nCurUndoAction;
146cdf0e10cSrcweir 	SfxUndoArray 			*pFatherUndoArray;
SfxUndoArraySfxUndoArray147cdf0e10cSrcweir 							SfxUndoArray(size_t nMax=0):
148cdf0e10cSrcweir                                 nMaxUndoActions(nMax), nCurUndoAction(0),
149cdf0e10cSrcweir                                 pFatherUndoArray(0) {}
150cdf0e10cSrcweir 						   ~SfxUndoArray();
151cdf0e10cSrcweir };
152cdf0e10cSrcweir 
153cdf0e10cSrcweir //=========================================================================
154cdf0e10cSrcweir 
155cdf0e10cSrcweir /** do not make use of these implementation details, unless you
156cdf0e10cSrcweir 	really really have to! */
157cdf0e10cSrcweir class SVL_DLLPUBLIC SfxListUndoAction : public SfxUndoAction, public SfxUndoArray
158cdf0e10cSrcweir 
159cdf0e10cSrcweir /*	[Beschreibung]
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 	UndoAction zur Klammerung mehrerer Undos in einer UndoAction.
162cdf0e10cSrcweir 	Diese Actions werden vom SfxUndoManager verwendet. Dort
163cdf0e10cSrcweir 	wird mit < SfxUndoManager::EnterListAction > eine Klammerebene
164cdf0e10cSrcweir 	geoeffnet und mit <SfxUndoManager::LeaveListAction > wieder
165cdf0e10cSrcweir 	geschlossen. Redo und Undo auf SfxListUndoActions wirken
166cdf0e10cSrcweir 	Elementweise.
167cdf0e10cSrcweir 
168cdf0e10cSrcweir */
169cdf0e10cSrcweir {
170cdf0e10cSrcweir 	public:
171cdf0e10cSrcweir 							TYPEINFO();
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 							SfxListUndoAction( const UniString &rComment,
174cdf0e10cSrcweir 								const UniString rRepeatComment, sal_uInt16 Id, SfxUndoArray *pFather);
175cdf0e10cSrcweir 	virtual void			Undo();
176cdf0e10cSrcweir     virtual void            UndoWithContext( SfxUndoContext& i_context );
177cdf0e10cSrcweir 	virtual void			Redo();
178cdf0e10cSrcweir     virtual void            RedoWithContext( SfxUndoContext& i_context );
179cdf0e10cSrcweir 	virtual void			Repeat(SfxRepeatTarget&);
180cdf0e10cSrcweir 	virtual sal_Bool			CanRepeat(SfxRepeatTarget&) const;
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 	virtual sal_Bool			Merge( SfxUndoAction *pNextAction );
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     virtual UniString       GetComment() const;
185cdf0e10cSrcweir     virtual UniString       GetRepeatComment(SfxRepeatTarget&) const;
186cdf0e10cSrcweir 	virtual sal_uInt16  GetId() const;
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 	void SetComment( const UniString& rComment );
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 	private:
191cdf0e10cSrcweir 
192cdf0e10cSrcweir     sal_uInt16		    nId;
193cdf0e10cSrcweir     UniString               aComment;
194cdf0e10cSrcweir     UniString               aRepeatComment;
195cdf0e10cSrcweir 
196cdf0e10cSrcweir };
197cdf0e10cSrcweir 
198cdf0e10cSrcweir //=========================================================================
199cdf0e10cSrcweir 
200cdf0e10cSrcweir /**  is a callback interface for notifications about state changes of an SfxUndoManager
201cdf0e10cSrcweir */
202cdf0e10cSrcweir class SAL_NO_VTABLE SfxUndoListener
203cdf0e10cSrcweir {
204cdf0e10cSrcweir public:
205cdf0e10cSrcweir     virtual void actionUndone( const String& i_actionComment ) = 0;
206cdf0e10cSrcweir     virtual void actionRedone( const String& i_actionComment ) = 0;
207cdf0e10cSrcweir     virtual void undoActionAdded( const String& i_actionComment ) = 0;
208cdf0e10cSrcweir     virtual void cleared() = 0;
209cdf0e10cSrcweir     virtual void clearedRedo() = 0;
210cdf0e10cSrcweir     virtual void resetAll() = 0;
211cdf0e10cSrcweir     virtual void listActionEntered( const String& i_comment ) = 0;
212cdf0e10cSrcweir     virtual void listActionLeft( const String& i_comment ) = 0;
213cdf0e10cSrcweir     virtual void listActionLeftAndMerged() = 0;
214cdf0e10cSrcweir     virtual void listActionCancelled() = 0;
215cdf0e10cSrcweir     virtual void undoManagerDying() = 0;
216cdf0e10cSrcweir };
217cdf0e10cSrcweir 
218cdf0e10cSrcweir //=========================================================================
219cdf0e10cSrcweir 
220cdf0e10cSrcweir namespace svl
221cdf0e10cSrcweir {
222cdf0e10cSrcweir     class SAL_NO_VTABLE IUndoManager
223cdf0e10cSrcweir     {
224cdf0e10cSrcweir     public:
225cdf0e10cSrcweir         enum
226cdf0e10cSrcweir         {
227cdf0e10cSrcweir             CurrentLevel = true,
228cdf0e10cSrcweir             TopLevel = false
229cdf0e10cSrcweir         };
230cdf0e10cSrcweir 
~IUndoManager()231cdf0e10cSrcweir         virtual                 ~IUndoManager() { };
232cdf0e10cSrcweir 
233cdf0e10cSrcweir         virtual void            SetMaxUndoActionCount( size_t nMaxUndoActionCount ) = 0;
234cdf0e10cSrcweir         virtual size_t          GetMaxUndoActionCount() const = 0;
235cdf0e10cSrcweir 
236cdf0e10cSrcweir         virtual void            AddUndoAction( SfxUndoAction *pAction, sal_Bool bTryMerg=sal_False ) = 0;
237cdf0e10cSrcweir 
238cdf0e10cSrcweir         virtual size_t          GetUndoActionCount( bool const i_currentLevel = CurrentLevel ) const = 0;
239cdf0e10cSrcweir         virtual sal_uInt16      GetUndoActionId() const = 0;
240cdf0e10cSrcweir         virtual UniString       GetUndoActionComment( size_t nNo=0, bool const i_currentLevel = CurrentLevel ) const = 0;
241cdf0e10cSrcweir         virtual SfxUndoAction*  GetUndoAction( size_t nNo=0 ) const = 0;
242cdf0e10cSrcweir 
243cdf0e10cSrcweir         virtual size_t          GetRedoActionCount( bool const i_currentLevel = CurrentLevel ) const = 0;
244cdf0e10cSrcweir         virtual UniString       GetRedoActionComment( size_t nNo=0, bool const i_currentLevel = CurrentLevel ) const = 0;
245*89358e0fSOliver-Rainer Wittmann         virtual SfxUndoAction*  GetRedoAction( size_t nNo=0, bool const i_currentLevel = CurrentLevel ) const = 0;
246cdf0e10cSrcweir 
247cdf0e10cSrcweir         virtual sal_Bool        Undo() = 0;
248cdf0e10cSrcweir         virtual sal_Bool        Redo() = 0;
249cdf0e10cSrcweir 
250cdf0e10cSrcweir         /** clears both the Redo and the Undo stack.
251cdf0e10cSrcweir 
252cdf0e10cSrcweir             Will assert and bail out when called while within a list action (<member>IsInListAction</member>).
253cdf0e10cSrcweir         */
254cdf0e10cSrcweir         virtual void            Clear() = 0;
255cdf0e10cSrcweir 
256cdf0e10cSrcweir         /** clears the Redo stack.
257cdf0e10cSrcweir 
258cdf0e10cSrcweir             Will assert and bail out when called while within a list action (<member>IsInListAction</member>).
259cdf0e10cSrcweir         */
260cdf0e10cSrcweir         virtual void            ClearRedo() = 0;
261cdf0e10cSrcweir 
262cdf0e10cSrcweir         /** leaves any possible open list action (<member>IsInListAction</member>), and clears both the Undo and the
263cdf0e10cSrcweir             Redo stack.
264cdf0e10cSrcweir 
265cdf0e10cSrcweir             Effectively, calling this method is equivalent to <code>while ( IsInListAction() ) LeaveListAction();</code>,
266cdf0e10cSrcweir             followed by <code>Clear()</code>. The only difference to this calling sequence is that Reset is an
267cdf0e10cSrcweir             atomar operation, also resulting in only one notification.
268cdf0e10cSrcweir         */
269cdf0e10cSrcweir         virtual void            Reset() = 0;
270cdf0e10cSrcweir 
271cdf0e10cSrcweir         /** determines whether an Undo or Redo is currently running
272cdf0e10cSrcweir         */
273cdf0e10cSrcweir         virtual bool            IsDoing() const = 0;
274cdf0e10cSrcweir 
275cdf0e10cSrcweir         virtual size_t          GetRepeatActionCount() const = 0;
276cdf0e10cSrcweir         virtual UniString       GetRepeatActionComment( SfxRepeatTarget &rTarget) const = 0;
277cdf0e10cSrcweir         virtual sal_Bool        Repeat( SfxRepeatTarget &rTarget ) = 0;
278cdf0e10cSrcweir         virtual sal_Bool        CanRepeat( SfxRepeatTarget &rTarget ) const = 0;
279cdf0e10cSrcweir 
280cdf0e10cSrcweir         virtual void            EnterListAction(const UniString &rComment, const UniString& rRepeatComment, sal_uInt16 nId=0) = 0;
281cdf0e10cSrcweir 
282cdf0e10cSrcweir         /** leaves the list action entered with EnterListAction
283cdf0e10cSrcweir             @return the number of the sub actions in the list which has just been left. Note that in case no such
284cdf0e10cSrcweir                 actions exist, the list action does not contribute to the Undo stack, but is silently removed.
285cdf0e10cSrcweir         */
286cdf0e10cSrcweir         virtual size_t          LeaveListAction() = 0;
287cdf0e10cSrcweir 
288cdf0e10cSrcweir         /** leaves the list action entered with EnterListAction, and forcefully merges the previous
289cdf0e10cSrcweir             action on the stack into the newly created list action.
290cdf0e10cSrcweir 
291cdf0e10cSrcweir             Say you have an Undo action A on the stack, then call EnterListAction, followed by one or more calls to
292cdf0e10cSrcweir             AddUndoAction, followed by a call to LeaveAndMergeListAction. In opposite to LeaveListAction, your Undo
293cdf0e10cSrcweir             stack will now still contain one undo action: the newly created list action, whose first child is the
294cdf0e10cSrcweir             original A, whose other children are those you added via AddUndoAction, and whose comment is the same as
295cdf0e10cSrcweir             the comment of A.
296cdf0e10cSrcweir 
297cdf0e10cSrcweir             Effectively, this means that all actions added between EnterListAction and LeaveAndMergeListAction are
298cdf0e10cSrcweir             hidden from the user.
299cdf0e10cSrcweir 
300cdf0e10cSrcweir             @return the number of the sub actions in the list which has just been left. Note that in case no such
301cdf0e10cSrcweir                 actions exist, the list action does not contribute to the Undo stack, but is silently removed.
302cdf0e10cSrcweir         */
303cdf0e10cSrcweir         virtual size_t          LeaveAndMergeListAction() = 0;
304cdf0e10cSrcweir 
305cdf0e10cSrcweir         /// determines whether we're within a ListAction context, i.e. a LeaveListAction/LeaveAndMergeListAction call is pending
306cdf0e10cSrcweir         virtual bool            IsInListAction() const = 0;
307cdf0e10cSrcweir 
308cdf0e10cSrcweir         /// determines how many nested list actions are currently open
309cdf0e10cSrcweir         virtual size_t          GetListActionDepth() const = 0;
310cdf0e10cSrcweir 
311cdf0e10cSrcweir         /** clears the redo stack and removes the top undo action */
312cdf0e10cSrcweir         virtual void            RemoveLastUndoAction() = 0;
313cdf0e10cSrcweir 
314cdf0e10cSrcweir         /** enables (true) or disables (false) recording of undo actions
315cdf0e10cSrcweir 
316cdf0e10cSrcweir             If undo actions are added while undo is disabled, they are deleted.
317cdf0e10cSrcweir             Disabling undo does not clear the current undo buffer!
318cdf0e10cSrcweir 
319cdf0e10cSrcweir             Multiple calls to <code>EnableUndo</code> are not cumulative. That is, calling <code>EnableUndo( false )</code>
320cdf0e10cSrcweir             twice, and then calling <code>EnableUndo( true )</code> means that Undo is enable afterwards.
321cdf0e10cSrcweir         */
322cdf0e10cSrcweir         virtual void            EnableUndo( bool bEnable ) = 0;
323cdf0e10cSrcweir 
324cdf0e10cSrcweir         // returns true if undo is currently enabled
325cdf0e10cSrcweir         // This returns false if undo was disabled using EnableUndo( false ) and
326cdf0e10cSrcweir         // also during the runtime of the Undo() and Redo() methods.
327cdf0e10cSrcweir         virtual bool            IsUndoEnabled() const = 0;
328cdf0e10cSrcweir 
329cdf0e10cSrcweir         /// adds a new listener to be notified about changes in the UndoManager's state
330cdf0e10cSrcweir         virtual void            AddUndoListener( SfxUndoListener& i_listener ) = 0;
331cdf0e10cSrcweir         virtual void            RemoveUndoListener( SfxUndoListener& i_listener ) = 0;
332cdf0e10cSrcweir    };
333cdf0e10cSrcweir }
334cdf0e10cSrcweir 
335cdf0e10cSrcweir //=========================================================================
336cdf0e10cSrcweir 
337cdf0e10cSrcweir namespace svl { namespace undo { namespace impl
338cdf0e10cSrcweir {
339cdf0e10cSrcweir     class UndoManagerGuard;
340cdf0e10cSrcweir     class LockGuard;
341cdf0e10cSrcweir } } }
342cdf0e10cSrcweir 
343cdf0e10cSrcweir struct SfxUndoManager_Data;
344cdf0e10cSrcweir class SVL_DLLPUBLIC SfxUndoManager : public ::svl::IUndoManager
345cdf0e10cSrcweir {
346cdf0e10cSrcweir 	friend class SfxLinkUndoAction;
347cdf0e10cSrcweir 
348cdf0e10cSrcweir     ::boost::scoped_ptr< SfxUndoManager_Data >
349cdf0e10cSrcweir                             m_pData;
350cdf0e10cSrcweir public:
351cdf0e10cSrcweir 							SfxUndoManager( size_t nMaxUndoActionCount = 20 );
352cdf0e10cSrcweir 	virtual 				~SfxUndoManager();
353cdf0e10cSrcweir 
354cdf0e10cSrcweir     // IUndoManager overridables
355cdf0e10cSrcweir     virtual void            SetMaxUndoActionCount( size_t nMaxUndoActionCount );
356cdf0e10cSrcweir     virtual size_t          GetMaxUndoActionCount() const;
357cdf0e10cSrcweir     virtual void            AddUndoAction( SfxUndoAction *pAction, sal_Bool bTryMerg=sal_False );
358cdf0e10cSrcweir     virtual size_t          GetUndoActionCount( bool const i_currentLevel = CurrentLevel ) const;
359cdf0e10cSrcweir     virtual sal_uInt16      GetUndoActionId() const;
360cdf0e10cSrcweir     virtual UniString       GetUndoActionComment( size_t nNo=0, bool const i_currentLevel = CurrentLevel ) const;
361cdf0e10cSrcweir     virtual SfxUndoAction*  GetUndoAction( size_t nNo=0 ) const;
362cdf0e10cSrcweir     virtual size_t          GetRedoActionCount( bool const i_currentLevel = CurrentLevel ) const;
363cdf0e10cSrcweir     virtual UniString       GetRedoActionComment( size_t nNo=0, bool const i_currentLevel = CurrentLevel ) const;
364*89358e0fSOliver-Rainer Wittmann     virtual SfxUndoAction*  GetRedoAction( size_t nNo=0, bool const i_currentLevel = CurrentLevel ) const;
365cdf0e10cSrcweir     virtual sal_Bool        Undo();
366cdf0e10cSrcweir     virtual sal_Bool        Redo();
367cdf0e10cSrcweir     virtual void            Clear();
368cdf0e10cSrcweir     virtual void            ClearRedo();
369cdf0e10cSrcweir     virtual void            Reset();
370cdf0e10cSrcweir     virtual bool            IsDoing() const;
371cdf0e10cSrcweir     virtual size_t          GetRepeatActionCount() const;
372cdf0e10cSrcweir     virtual UniString       GetRepeatActionComment( SfxRepeatTarget &rTarget) const;
373cdf0e10cSrcweir     virtual sal_Bool        Repeat( SfxRepeatTarget &rTarget );
374cdf0e10cSrcweir     virtual sal_Bool        CanRepeat( SfxRepeatTarget &rTarget ) const;
375cdf0e10cSrcweir     virtual void            EnterListAction(const UniString &rComment, const UniString& rRepeatComment, sal_uInt16 nId=0);
376cdf0e10cSrcweir     virtual size_t          LeaveListAction();
377cdf0e10cSrcweir     virtual size_t          LeaveAndMergeListAction();
378cdf0e10cSrcweir     virtual bool            IsInListAction() const;
379cdf0e10cSrcweir     virtual size_t          GetListActionDepth() const;
380cdf0e10cSrcweir     virtual void            RemoveLastUndoAction();
381cdf0e10cSrcweir     virtual void            EnableUndo( bool bEnable );
382cdf0e10cSrcweir     virtual bool            IsUndoEnabled() const;
383cdf0e10cSrcweir     virtual void            AddUndoListener( SfxUndoListener& i_listener );
384cdf0e10cSrcweir     virtual void            RemoveUndoListener( SfxUndoListener& i_listener );
385cdf0e10cSrcweir 
386cdf0e10cSrcweir     /** marks the current top-level element of the Undo stack, and returns a unique ID for it
387cdf0e10cSrcweir     */
388cdf0e10cSrcweir     UndoStackMark   MarkTopUndoAction();
389cdf0e10cSrcweir 
390cdf0e10cSrcweir     /** removes a mark given by its ID.
391cdf0e10cSrcweir         After the call, the mark ID is invalid.
392cdf0e10cSrcweir     */
393cdf0e10cSrcweir     void            RemoveMark( UndoStackMark const i_mark );
394cdf0e10cSrcweir 
395cdf0e10cSrcweir     /** determines whether the top action on the Undo stack has a given mark
396cdf0e10cSrcweir     */
397cdf0e10cSrcweir     bool            HasTopUndoActionMark( UndoStackMark const i_mark );
398cdf0e10cSrcweir 
399cdf0e10cSrcweir     /** removes the oldest Undo actions from the stack
400cdf0e10cSrcweir     */
401cdf0e10cSrcweir     void            RemoveOldestUndoActions( size_t const i_count );
402cdf0e10cSrcweir 
403cdf0e10cSrcweir protected:
404cdf0e10cSrcweir     sal_Bool UndoWithContext( SfxUndoContext& i_context );
405cdf0e10cSrcweir     sal_Bool RedoWithContext( SfxUndoContext& i_context );
406cdf0e10cSrcweir 
407cdf0e10cSrcweir     void    ImplClearRedo_NoLock( bool const i_currentLevel );
408cdf0e10cSrcweir 
409cdf0e10cSrcweir     /** clears all undo actions on the current level, plus all undo actions on superordinate levels,
410cdf0e10cSrcweir         as soon as those levels are reached.
411cdf0e10cSrcweir 
412cdf0e10cSrcweir         If no list action is active currently, i.e. we're on the top level already, this method is equivalent to
413cdf0e10cSrcweir         ->Clear.
414cdf0e10cSrcweir 
415cdf0e10cSrcweir         Otherwise, the Undo actions on the current level are removed. Upon leaving the current list action, all
416cdf0e10cSrcweir         undo actions on the then-current level are removed, too. This is continued until the top level is reached.
417cdf0e10cSrcweir     */
418cdf0e10cSrcweir     void    ClearAllLevels();
419cdf0e10cSrcweir 
420cdf0e10cSrcweir private:
421cdf0e10cSrcweir     size_t  ImplLeaveListAction( const bool i_merge, ::svl::undo::impl::UndoManagerGuard& i_guard );
422cdf0e10cSrcweir     bool    ImplAddUndoAction_NoNotify( SfxUndoAction* pAction, bool bTryMerge, bool bClearRedo, ::svl::undo::impl::UndoManagerGuard& i_guard );
423cdf0e10cSrcweir     void    ImplClearRedo( ::svl::undo::impl::UndoManagerGuard& i_guard, bool const i_currentLevel );
424cdf0e10cSrcweir     void    ImplClearUndo( ::svl::undo::impl::UndoManagerGuard& i_guard );
425cdf0e10cSrcweir     void    ImplClearCurrentLevel_NoNotify( ::svl::undo::impl::UndoManagerGuard& i_guard );
426cdf0e10cSrcweir     size_t  ImplGetRedoActionCount_Lock( bool const i_currentLevel = CurrentLevel ) const;
427cdf0e10cSrcweir     bool    ImplIsUndoEnabled_Lock() const;
428cdf0e10cSrcweir     bool    ImplIsInListAction_Lock() const;
429cdf0e10cSrcweir     void    ImplEnableUndo_Lock( bool const i_enable );
430cdf0e10cSrcweir 
431cdf0e10cSrcweir     sal_Bool ImplUndo( SfxUndoContext* i_contextOrNull );
432cdf0e10cSrcweir     sal_Bool ImplRedo( SfxUndoContext* i_contextOrNull );
433cdf0e10cSrcweir 
434cdf0e10cSrcweir     friend class ::svl::undo::impl::LockGuard;
435cdf0e10cSrcweir };
436cdf0e10cSrcweir 
437cdf0e10cSrcweir //=========================================================================
438cdf0e10cSrcweir 
439cdf0e10cSrcweir class SVL_DLLPUBLIC SfxLinkUndoAction : public SfxUndoAction
440cdf0e10cSrcweir 
441cdf0e10cSrcweir /*	[Beschreibung]
442cdf0e10cSrcweir 
443cdf0e10cSrcweir 	Die SfxLinkUndoAction dient zur Verbindung zweier SfxUndoManager. Die
444cdf0e10cSrcweir 	im ersten SfxUndoManager eingefuegten SfxUndoAction leiten ihr Undo und Redo
445cdf0e10cSrcweir 	an den zweiten weiter, so dass ein Undo und Redo am ersten
446cdf0e10cSrcweir 	SfxUndoManager wie eine am zweiten wirkt.
447cdf0e10cSrcweir 
448cdf0e10cSrcweir 	Die SfxLinkUndoAction ist nach dem Einfuegen der SfxUndoAction am
449cdf0e10cSrcweir 	zweiten SfxUndoManager einzufuegen. Waehrend der zweite SfxUndoManager
450cdf0e10cSrcweir 	vom ersten ferngesteuert wird, duerfen an ihm weder Actions eingefuegt werden,
451cdf0e10cSrcweir 	noch darf Undo/Redo aufgerufen werden.
452cdf0e10cSrcweir 
453cdf0e10cSrcweir */
454cdf0e10cSrcweir 
455cdf0e10cSrcweir {
45601300968SArmin Le Grand private:
45701300968SArmin Le Grand     friend class SfxUndoAction;
45801300968SArmin Le Grand     void LinkedSfxUndoActionDestructed(const SfxUndoAction& rCandidate);
45901300968SArmin Le Grand 
460cdf0e10cSrcweir public:
461cdf0e10cSrcweir 							TYPEINFO();
462cdf0e10cSrcweir                             SfxLinkUndoAction(::svl::IUndoManager *pManager);
463cdf0e10cSrcweir 							~SfxLinkUndoAction();
464cdf0e10cSrcweir 
465cdf0e10cSrcweir 	virtual void			Undo();
466cdf0e10cSrcweir 	virtual void			Redo();
467cdf0e10cSrcweir 	virtual sal_Bool			CanRepeat(SfxRepeatTarget& r) const;
468cdf0e10cSrcweir 
469cdf0e10cSrcweir 	virtual void			Repeat(SfxRepeatTarget&r);
470cdf0e10cSrcweir 
471cdf0e10cSrcweir 	virtual UniString       GetComment() const;
472cdf0e10cSrcweir 	virtual UniString       GetRepeatComment(SfxRepeatTarget&r) const;
473cdf0e10cSrcweir 	virtual sal_uInt16	GetId() const;
474cdf0e10cSrcweir 
GetAction() const475cdf0e10cSrcweir 	SfxUndoAction*			GetAction() const { return pAction; }
476cdf0e10cSrcweir 
477cdf0e10cSrcweir protected:
478cdf0e10cSrcweir 	::svl::IUndoManager     *pUndoManager;
479cdf0e10cSrcweir 	SfxUndoAction			*pAction;
480cdf0e10cSrcweir 
481cdf0e10cSrcweir };
482cdf0e10cSrcweir 
483cdf0e10cSrcweir #endif
484