140df464eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
340df464eSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
440df464eSAndrew Rist * or more contributor license agreements. See the NOTICE file
540df464eSAndrew Rist * distributed with this work for additional information
640df464eSAndrew Rist * regarding copyright ownership. The ASF licenses this file
740df464eSAndrew Rist * to you under the Apache License, Version 2.0 (the
840df464eSAndrew Rist * "License"); you may not use this file except in compliance
940df464eSAndrew Rist * with the License. You may obtain a copy of the License at
1040df464eSAndrew Rist *
1140df464eSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
1240df464eSAndrew Rist *
1340df464eSAndrew Rist * Unless required by applicable law or agreed to in writing,
1440df464eSAndrew Rist * software distributed under the License is distributed on an
1540df464eSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1640df464eSAndrew Rist * KIND, either express or implied. See the License for the
1740df464eSAndrew Rist * specific language governing permissions and limitations
1840df464eSAndrew Rist * under the License.
1940df464eSAndrew Rist *
2040df464eSAndrew Rist *************************************************************/
2140df464eSAndrew Rist
2240df464eSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svl.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <com/sun/star/uno/Exception.hpp>
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <comphelper/flagguard.hxx>
30cdf0e10cSrcweir #include <tools/debug.hxx>
31cdf0e10cSrcweir #include <tools/diagnose_ex.h>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <svl/undo.hxx>
34cdf0e10cSrcweir
35cdf0e10cSrcweir #include <vector>
36cdf0e10cSrcweir #include <list>
37cdf0e10cSrcweir #include <limits>
38cdf0e10cSrcweir
39cdf0e10cSrcweir using ::com::sun::star::uno::Exception;
40cdf0e10cSrcweir
41cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
42cdf0e10cSrcweir
43cdf0e10cSrcweir DBG_NAME(SfxUndoAction)
44cdf0e10cSrcweir
45cdf0e10cSrcweir //========================================================================
46cdf0e10cSrcweir
47cdf0e10cSrcweir TYPEINIT0(SfxUndoAction);
48cdf0e10cSrcweir TYPEINIT0(SfxListUndoAction);
49cdf0e10cSrcweir TYPEINIT0(SfxLinkUndoAction);
50cdf0e10cSrcweir TYPEINIT0(SfxRepeatTarget);
51cdf0e10cSrcweir
52cdf0e10cSrcweir //------------------------------------------------------------------------
53cdf0e10cSrcweir
~SfxRepeatTarget()54cdf0e10cSrcweir SfxRepeatTarget::~SfxRepeatTarget()
55cdf0e10cSrcweir {
56cdf0e10cSrcweir }
57cdf0e10cSrcweir
58cdf0e10cSrcweir //------------------------------------------------------------------------
59cdf0e10cSrcweir
~SfxUndoContext()60cdf0e10cSrcweir SfxUndoContext::~SfxUndoContext()
61cdf0e10cSrcweir {
62cdf0e10cSrcweir }
63cdf0e10cSrcweir
64cdf0e10cSrcweir //------------------------------------------------------------------------
65cdf0e10cSrcweir
SetLinkToSfxLinkUndoAction(SfxLinkUndoAction * pSfxLinkUndoAction)6601300968SArmin Le Grand void SfxUndoAction::SetLinkToSfxLinkUndoAction(SfxLinkUndoAction* pSfxLinkUndoAction)
67cdf0e10cSrcweir {
6801300968SArmin Le Grand mpSfxLinkUndoAction = pSfxLinkUndoAction;
69cdf0e10cSrcweir }
70cdf0e10cSrcweir
71cdf0e10cSrcweir //------------------------------------------------------------------------
72cdf0e10cSrcweir
~SfxUndoAction()73cdf0e10cSrcweir SfxUndoAction::~SfxUndoAction()
74cdf0e10cSrcweir {
7501300968SArmin Le Grand DBG_DTOR(SfxUndoAction, 0);
7601300968SArmin Le Grand
7701300968SArmin Le Grand if(mpSfxLinkUndoAction)
7801300968SArmin Le Grand {
7901300968SArmin Le Grand mpSfxLinkUndoAction->LinkedSfxUndoActionDestructed(*this);
8001300968SArmin Le Grand mpSfxLinkUndoAction = 0;
8101300968SArmin Le Grand }
82cdf0e10cSrcweir }
83cdf0e10cSrcweir
84cdf0e10cSrcweir
SfxUndoAction()85cdf0e10cSrcweir SfxUndoAction::SfxUndoAction()
8601300968SArmin Le Grand : mpSfxLinkUndoAction(0)
87cdf0e10cSrcweir {
88cdf0e10cSrcweir DBG_CTOR(SfxUndoAction, 0);
89cdf0e10cSrcweir }
90cdf0e10cSrcweir
91cdf0e10cSrcweir //------------------------------------------------------------------------
92cdf0e10cSrcweir
Merge(SfxUndoAction *)93cdf0e10cSrcweir sal_Bool SfxUndoAction::Merge( SfxUndoAction * )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir DBG_CHKTHIS(SfxUndoAction, 0);
96cdf0e10cSrcweir return sal_False;
97cdf0e10cSrcweir }
98cdf0e10cSrcweir
99cdf0e10cSrcweir //------------------------------------------------------------------------
100cdf0e10cSrcweir
GetComment() const101cdf0e10cSrcweir XubString SfxUndoAction::GetComment() const
102cdf0e10cSrcweir {
103cdf0e10cSrcweir DBG_CHKTHIS(SfxUndoAction, 0);
104cdf0e10cSrcweir return XubString();
105cdf0e10cSrcweir }
106cdf0e10cSrcweir
107cdf0e10cSrcweir //------------------------------------------------------------------------
108cdf0e10cSrcweir
109cdf0e10cSrcweir
GetId() const110cdf0e10cSrcweir sal_uInt16 SfxUndoAction::GetId() const
111cdf0e10cSrcweir {
112cdf0e10cSrcweir DBG_CHKTHIS(SfxUndoAction, 0);
113cdf0e10cSrcweir return 0;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir
116cdf0e10cSrcweir //------------------------------------------------------------------------
117cdf0e10cSrcweir
GetRepeatComment(SfxRepeatTarget &) const118cdf0e10cSrcweir XubString SfxUndoAction::GetRepeatComment(SfxRepeatTarget&) const
119cdf0e10cSrcweir {
120cdf0e10cSrcweir DBG_CHKTHIS(SfxUndoAction, 0);
121cdf0e10cSrcweir return GetComment();
122cdf0e10cSrcweir }
123cdf0e10cSrcweir
124cdf0e10cSrcweir //------------------------------------------------------------------------
125cdf0e10cSrcweir
Undo()126cdf0e10cSrcweir void SfxUndoAction::Undo()
127cdf0e10cSrcweir {
128cdf0e10cSrcweir // die sind nur konzeptuell pure virtual
129cdf0e10cSrcweir DBG_ERROR( "pure virtual function called: SfxUndoAction::Undo()" );
130cdf0e10cSrcweir }
131cdf0e10cSrcweir
132cdf0e10cSrcweir //------------------------------------------------------------------------
133cdf0e10cSrcweir
UndoWithContext(SfxUndoContext & i_context)134cdf0e10cSrcweir void SfxUndoAction::UndoWithContext( SfxUndoContext& i_context )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir (void)i_context;
137cdf0e10cSrcweir Undo();
138cdf0e10cSrcweir }
139cdf0e10cSrcweir
140cdf0e10cSrcweir //------------------------------------------------------------------------
141cdf0e10cSrcweir
Redo()142cdf0e10cSrcweir void SfxUndoAction::Redo()
143cdf0e10cSrcweir {
144cdf0e10cSrcweir // die sind nur konzeptuell pure virtual
145cdf0e10cSrcweir DBG_ERROR( "pure virtual function called: SfxUndoAction::Redo()" );
146cdf0e10cSrcweir }
147cdf0e10cSrcweir
148cdf0e10cSrcweir //------------------------------------------------------------------------
149cdf0e10cSrcweir
RedoWithContext(SfxUndoContext & i_context)150cdf0e10cSrcweir void SfxUndoAction::RedoWithContext( SfxUndoContext& i_context )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir (void)i_context;
153cdf0e10cSrcweir Redo();
154cdf0e10cSrcweir }
155cdf0e10cSrcweir
156cdf0e10cSrcweir //------------------------------------------------------------------------
157cdf0e10cSrcweir
Repeat(SfxRepeatTarget &)158cdf0e10cSrcweir void SfxUndoAction::Repeat(SfxRepeatTarget&)
159cdf0e10cSrcweir {
160cdf0e10cSrcweir // die sind nur konzeptuell pure virtual
161cdf0e10cSrcweir DBG_ERROR( "pure virtual function called: SfxUndoAction::Repeat()" );
162cdf0e10cSrcweir }
163cdf0e10cSrcweir
164cdf0e10cSrcweir //------------------------------------------------------------------------
165cdf0e10cSrcweir
166cdf0e10cSrcweir
CanRepeat(SfxRepeatTarget &) const167cdf0e10cSrcweir sal_Bool SfxUndoAction::CanRepeat(SfxRepeatTarget&) const
168cdf0e10cSrcweir {
169cdf0e10cSrcweir return sal_True;
170cdf0e10cSrcweir }
171cdf0e10cSrcweir
172cdf0e10cSrcweir //========================================================================
173cdf0e10cSrcweir
174cdf0e10cSrcweir typedef ::std::vector< SfxUndoListener* > UndoListeners;
175cdf0e10cSrcweir
176cdf0e10cSrcweir struct SVL_DLLPRIVATE SfxUndoManager_Data
177cdf0e10cSrcweir {
178cdf0e10cSrcweir ::osl::Mutex aMutex;
179cdf0e10cSrcweir SfxUndoArray* pUndoArray;
180cdf0e10cSrcweir SfxUndoArray* pActUndoArray;
181cdf0e10cSrcweir SfxUndoArray* pFatherUndoArray;
182cdf0e10cSrcweir
183cdf0e10cSrcweir sal_Int32 mnMarks;
184cdf0e10cSrcweir sal_Int32 mnEmptyMark;
185cdf0e10cSrcweir bool mbUndoEnabled;
186cdf0e10cSrcweir bool mbDoing;
187cdf0e10cSrcweir bool mbClearUntilTopLevel;
188cdf0e10cSrcweir
189cdf0e10cSrcweir UndoListeners aListeners;
190cdf0e10cSrcweir
SfxUndoManager_DataSfxUndoManager_Data191cdf0e10cSrcweir SfxUndoManager_Data( size_t i_nMaxUndoActionCount )
192cdf0e10cSrcweir :pUndoArray( new SfxUndoArray( i_nMaxUndoActionCount ) )
193cdf0e10cSrcweir ,pActUndoArray( NULL )
194cdf0e10cSrcweir ,pFatherUndoArray( NULL )
195cdf0e10cSrcweir ,mnMarks( 0 )
196cdf0e10cSrcweir ,mnEmptyMark(MARK_INVALID)
197cdf0e10cSrcweir ,mbUndoEnabled( true )
198cdf0e10cSrcweir ,mbDoing( false )
199cdf0e10cSrcweir ,mbClearUntilTopLevel( false )
200cdf0e10cSrcweir {
201cdf0e10cSrcweir pActUndoArray = pUndoArray;
202cdf0e10cSrcweir }
203cdf0e10cSrcweir
~SfxUndoManager_DataSfxUndoManager_Data204cdf0e10cSrcweir ~SfxUndoManager_Data()
205cdf0e10cSrcweir {
206cdf0e10cSrcweir delete pUndoArray;
207cdf0e10cSrcweir }
208cdf0e10cSrcweir };
209cdf0e10cSrcweir
210cdf0e10cSrcweir //========================================================================
211cdf0e10cSrcweir
212cdf0e10cSrcweir namespace svl { namespace undo { namespace impl
213cdf0e10cSrcweir {
214cdf0e10cSrcweir //--------------------------------------------------------------------
215cdf0e10cSrcweir class SVL_DLLPRIVATE LockGuard
216cdf0e10cSrcweir {
217cdf0e10cSrcweir public:
LockGuard(SfxUndoManager & i_manager)218cdf0e10cSrcweir LockGuard( SfxUndoManager& i_manager )
219cdf0e10cSrcweir :m_manager( i_manager )
220cdf0e10cSrcweir {
221cdf0e10cSrcweir m_manager.ImplEnableUndo_Lock( false );
222cdf0e10cSrcweir }
223cdf0e10cSrcweir
~LockGuard()224cdf0e10cSrcweir ~LockGuard()
225cdf0e10cSrcweir {
226cdf0e10cSrcweir m_manager.ImplEnableUndo_Lock( true );
227cdf0e10cSrcweir }
228cdf0e10cSrcweir
229cdf0e10cSrcweir private:
230cdf0e10cSrcweir SfxUndoManager& m_manager;
231cdf0e10cSrcweir };
232cdf0e10cSrcweir
233cdf0e10cSrcweir //--------------------------------------------------------------------
234cdf0e10cSrcweir typedef void ( SfxUndoListener::*UndoListenerVoidMethod )();
235cdf0e10cSrcweir typedef void ( SfxUndoListener::*UndoListenerStringMethod )( const String& );
236cdf0e10cSrcweir
237cdf0e10cSrcweir //--------------------------------------------------------------------
238cdf0e10cSrcweir struct SVL_DLLPRIVATE NotifyUndoListener : public ::std::unary_function< SfxUndoListener*, void >
239cdf0e10cSrcweir {
NotifyUndoListenersvl::undo::impl::NotifyUndoListener240cdf0e10cSrcweir NotifyUndoListener()
241cdf0e10cSrcweir :m_notificationMethod( NULL )
242cdf0e10cSrcweir ,m_altNotificationMethod( NULL )
243cdf0e10cSrcweir ,m_sActionComment()
244cdf0e10cSrcweir {
245cdf0e10cSrcweir }
246cdf0e10cSrcweir
NotifyUndoListenersvl::undo::impl::NotifyUndoListener247cdf0e10cSrcweir NotifyUndoListener( UndoListenerVoidMethod i_notificationMethod )
248cdf0e10cSrcweir :m_notificationMethod( i_notificationMethod )
249cdf0e10cSrcweir ,m_altNotificationMethod( NULL )
250cdf0e10cSrcweir ,m_sActionComment()
251cdf0e10cSrcweir {
252cdf0e10cSrcweir }
253cdf0e10cSrcweir
NotifyUndoListenersvl::undo::impl::NotifyUndoListener254cdf0e10cSrcweir NotifyUndoListener( UndoListenerStringMethod i_notificationMethod, const String& i_actionComment )
255cdf0e10cSrcweir :m_notificationMethod( NULL )
256cdf0e10cSrcweir ,m_altNotificationMethod( i_notificationMethod )
257cdf0e10cSrcweir ,m_sActionComment( i_actionComment )
258cdf0e10cSrcweir {
259cdf0e10cSrcweir }
260cdf0e10cSrcweir
issvl::undo::impl::NotifyUndoListener261cdf0e10cSrcweir bool is() const
262cdf0e10cSrcweir {
263cdf0e10cSrcweir return ( m_notificationMethod != NULL ) || ( m_altNotificationMethod != NULL );
264cdf0e10cSrcweir }
265cdf0e10cSrcweir
operator ()svl::undo::impl::NotifyUndoListener266cdf0e10cSrcweir void operator()( SfxUndoListener* i_listener ) const
267cdf0e10cSrcweir {
268cdf0e10cSrcweir OSL_PRECOND( is(), "NotifyUndoListener: this will crash!" );
269cdf0e10cSrcweir if ( m_altNotificationMethod != NULL )
270cdf0e10cSrcweir {
271cdf0e10cSrcweir ( i_listener->*m_altNotificationMethod )( m_sActionComment );
272cdf0e10cSrcweir }
273cdf0e10cSrcweir else
274cdf0e10cSrcweir {
275cdf0e10cSrcweir ( i_listener->*m_notificationMethod )();
276cdf0e10cSrcweir }
277cdf0e10cSrcweir }
278cdf0e10cSrcweir
279cdf0e10cSrcweir private:
280cdf0e10cSrcweir UndoListenerVoidMethod m_notificationMethod;
281cdf0e10cSrcweir UndoListenerStringMethod m_altNotificationMethod;
282cdf0e10cSrcweir String m_sActionComment;
283cdf0e10cSrcweir };
284cdf0e10cSrcweir
285cdf0e10cSrcweir //--------------------------------------------------------------------
286cdf0e10cSrcweir class SVL_DLLPRIVATE UndoManagerGuard
287cdf0e10cSrcweir {
288cdf0e10cSrcweir public:
UndoManagerGuard(SfxUndoManager_Data & i_managerData)289cdf0e10cSrcweir UndoManagerGuard( SfxUndoManager_Data& i_managerData )
290cdf0e10cSrcweir :m_rManagerData( i_managerData )
291cdf0e10cSrcweir ,m_aGuard( i_managerData.aMutex )
292cdf0e10cSrcweir ,m_notifiers()
293cdf0e10cSrcweir {
294cdf0e10cSrcweir }
295cdf0e10cSrcweir
296cdf0e10cSrcweir ~UndoManagerGuard();
297cdf0e10cSrcweir
clear()298cdf0e10cSrcweir void clear()
299cdf0e10cSrcweir {
300cdf0e10cSrcweir m_aGuard.clear();
301cdf0e10cSrcweir }
302cdf0e10cSrcweir
reset()303cdf0e10cSrcweir void reset()
304cdf0e10cSrcweir {
305cdf0e10cSrcweir m_aGuard.reset();
306cdf0e10cSrcweir }
307cdf0e10cSrcweir
cancelNotifications()308cdf0e10cSrcweir void cancelNotifications()
309cdf0e10cSrcweir {
310cdf0e10cSrcweir m_notifiers.clear();
311cdf0e10cSrcweir }
312cdf0e10cSrcweir
313cdf0e10cSrcweir /** marks the given Undo action for deletion
314cdf0e10cSrcweir
315cdf0e10cSrcweir The Undo action will be put into a list, whose members will be deleted from within the destructor of the
316cdf0e10cSrcweir UndoManagerGuard. This deletion will happen without the UndoManager's mutex locked.
317cdf0e10cSrcweir */
markForDeletion(SfxUndoAction * i_action)318cdf0e10cSrcweir void markForDeletion( SfxUndoAction* i_action )
319cdf0e10cSrcweir {
320cdf0e10cSrcweir // remember
321cdf0e10cSrcweir if ( i_action )
322cdf0e10cSrcweir m_aUndoActionsCleanup.push_back( i_action );
323cdf0e10cSrcweir }
324cdf0e10cSrcweir
325cdf0e10cSrcweir /** schedules the given SfxUndoListener method to be called for all registered listeners.
326cdf0e10cSrcweir
327cdf0e10cSrcweir The notification will happen after the Undo manager's mutex has been released, and after all pending
328cdf0e10cSrcweir deletions of Undo actions are done.
329cdf0e10cSrcweir */
scheduleNotification(UndoListenerVoidMethod i_notificationMethod)330cdf0e10cSrcweir void scheduleNotification( UndoListenerVoidMethod i_notificationMethod )
331cdf0e10cSrcweir {
332cdf0e10cSrcweir m_notifiers.push_back( NotifyUndoListener( i_notificationMethod ) );
333cdf0e10cSrcweir }
334cdf0e10cSrcweir
scheduleNotification(UndoListenerStringMethod i_notificationMethod,const String & i_actionComment)335cdf0e10cSrcweir void scheduleNotification( UndoListenerStringMethod i_notificationMethod, const String& i_actionComment )
336cdf0e10cSrcweir {
337cdf0e10cSrcweir m_notifiers.push_back( NotifyUndoListener( i_notificationMethod, i_actionComment ) );
338cdf0e10cSrcweir }
339cdf0e10cSrcweir
340cdf0e10cSrcweir private:
341cdf0e10cSrcweir SfxUndoManager_Data& m_rManagerData;
342cdf0e10cSrcweir ::osl::ResettableMutexGuard m_aGuard;
343cdf0e10cSrcweir ::std::list< SfxUndoAction* > m_aUndoActionsCleanup;
344cdf0e10cSrcweir ::std::list< NotifyUndoListener > m_notifiers;
345cdf0e10cSrcweir };
346cdf0e10cSrcweir
~UndoManagerGuard()347cdf0e10cSrcweir UndoManagerGuard::~UndoManagerGuard()
348cdf0e10cSrcweir {
349cdf0e10cSrcweir // copy members
350cdf0e10cSrcweir UndoListeners aListenersCopy( m_rManagerData.aListeners );
351cdf0e10cSrcweir
352cdf0e10cSrcweir // release mutex
353cdf0e10cSrcweir m_aGuard.clear();
354cdf0e10cSrcweir
355cdf0e10cSrcweir // delete all actions
356cdf0e10cSrcweir while ( !m_aUndoActionsCleanup.empty() )
357cdf0e10cSrcweir {
358cdf0e10cSrcweir SfxUndoAction* pAction = m_aUndoActionsCleanup.front();
359cdf0e10cSrcweir m_aUndoActionsCleanup.pop_front();
360cdf0e10cSrcweir try
361cdf0e10cSrcweir {
362cdf0e10cSrcweir delete pAction;
363cdf0e10cSrcweir }
364cdf0e10cSrcweir catch( const Exception& )
365cdf0e10cSrcweir {
366cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
367cdf0e10cSrcweir }
368cdf0e10cSrcweir }
369cdf0e10cSrcweir
370cdf0e10cSrcweir // handle scheduled notification
371cdf0e10cSrcweir for ( ::std::list< NotifyUndoListener >::const_iterator notifier = m_notifiers.begin();
372cdf0e10cSrcweir notifier != m_notifiers.end();
373cdf0e10cSrcweir ++notifier
374cdf0e10cSrcweir )
375cdf0e10cSrcweir {
376cdf0e10cSrcweir if ( notifier->is() )
377cdf0e10cSrcweir ::std::for_each( aListenersCopy.begin(), aListenersCopy.end(), *notifier );
378cdf0e10cSrcweir }
379cdf0e10cSrcweir }
380cdf0e10cSrcweir } } }
381cdf0e10cSrcweir
382cdf0e10cSrcweir using namespace ::svl::undo::impl;
383cdf0e10cSrcweir
384cdf0e10cSrcweir //========================================================================
385cdf0e10cSrcweir
SfxUndoManager(size_t nMaxUndoActionCount)386cdf0e10cSrcweir SfxUndoManager::SfxUndoManager( size_t nMaxUndoActionCount )
387cdf0e10cSrcweir :m_pData( new SfxUndoManager_Data( nMaxUndoActionCount ) )
388cdf0e10cSrcweir {
389cdf0e10cSrcweir }
390cdf0e10cSrcweir
391cdf0e10cSrcweir //------------------------------------------------------------------------
392cdf0e10cSrcweir
~SfxUndoManager()393cdf0e10cSrcweir SfxUndoManager::~SfxUndoManager()
394cdf0e10cSrcweir {
395cdf0e10cSrcweir UndoListeners aListenersCopy;
396cdf0e10cSrcweir {
397cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
398cdf0e10cSrcweir aListenersCopy = m_pData->aListeners;
399cdf0e10cSrcweir }
400cdf0e10cSrcweir
401cdf0e10cSrcweir ::std::for_each( aListenersCopy.begin(), aListenersCopy.end(),
402cdf0e10cSrcweir NotifyUndoListener( &SfxUndoListener::undoManagerDying ) );
403cdf0e10cSrcweir }
404cdf0e10cSrcweir
405cdf0e10cSrcweir //------------------------------------------------------------------------
406cdf0e10cSrcweir
EnableUndo(bool i_enable)407cdf0e10cSrcweir void SfxUndoManager::EnableUndo( bool i_enable )
408cdf0e10cSrcweir {
409cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
410cdf0e10cSrcweir ImplEnableUndo_Lock( i_enable );
411cdf0e10cSrcweir
412cdf0e10cSrcweir }
413cdf0e10cSrcweir
414cdf0e10cSrcweir //------------------------------------------------------------------------
415cdf0e10cSrcweir
ImplEnableUndo_Lock(bool const i_enable)416cdf0e10cSrcweir void SfxUndoManager::ImplEnableUndo_Lock( bool const i_enable )
417cdf0e10cSrcweir {
418cdf0e10cSrcweir if ( m_pData->mbUndoEnabled == i_enable )
419cdf0e10cSrcweir return;
420cdf0e10cSrcweir m_pData->mbUndoEnabled = i_enable;
421cdf0e10cSrcweir }
422cdf0e10cSrcweir
423cdf0e10cSrcweir //------------------------------------------------------------------------
424cdf0e10cSrcweir
IsUndoEnabled() const425cdf0e10cSrcweir bool SfxUndoManager::IsUndoEnabled() const
426cdf0e10cSrcweir {
427cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
428cdf0e10cSrcweir return ImplIsUndoEnabled_Lock();
429cdf0e10cSrcweir }
430cdf0e10cSrcweir
431cdf0e10cSrcweir //------------------------------------------------------------------------
432cdf0e10cSrcweir
ImplIsUndoEnabled_Lock() const433cdf0e10cSrcweir bool SfxUndoManager::ImplIsUndoEnabled_Lock() const
434cdf0e10cSrcweir {
435cdf0e10cSrcweir return m_pData->mbUndoEnabled;
436cdf0e10cSrcweir }
437cdf0e10cSrcweir
438cdf0e10cSrcweir //------------------------------------------------------------------------
439cdf0e10cSrcweir
SetMaxUndoActionCount(size_t nMaxUndoActionCount)440cdf0e10cSrcweir void SfxUndoManager::SetMaxUndoActionCount( size_t nMaxUndoActionCount )
441cdf0e10cSrcweir {
442cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
443cdf0e10cSrcweir
444cdf0e10cSrcweir // Remove entries from the pActUndoArray when we have to reduce
445cdf0e10cSrcweir // the number of entries due to a lower nMaxUndoActionCount.
446cdf0e10cSrcweir // Both redo and undo action entries will be removed until we reached the
447cdf0e10cSrcweir // new nMaxUndoActionCount.
448cdf0e10cSrcweir
449cdf0e10cSrcweir long nNumToDelete = m_pData->pActUndoArray->aUndoActions.size() - nMaxUndoActionCount;
450cdf0e10cSrcweir while ( nNumToDelete > 0 )
451cdf0e10cSrcweir {
452cdf0e10cSrcweir size_t nPos = m_pData->pActUndoArray->aUndoActions.size();
453cdf0e10cSrcweir if ( nPos > m_pData->pActUndoArray->nCurUndoAction )
454cdf0e10cSrcweir {
455cdf0e10cSrcweir SfxUndoAction* pAction = m_pData->pActUndoArray->aUndoActions[nPos-1].pAction;
45601300968SArmin Le Grand aGuard.markForDeletion( pAction );
45701300968SArmin Le Grand m_pData->pActUndoArray->aUndoActions.Remove( nPos-1 );
45801300968SArmin Le Grand --nNumToDelete;
459cdf0e10cSrcweir }
460cdf0e10cSrcweir
461cdf0e10cSrcweir if ( nNumToDelete > 0 && m_pData->pActUndoArray->nCurUndoAction > 0 )
462cdf0e10cSrcweir {
463cdf0e10cSrcweir SfxUndoAction* pAction = m_pData->pActUndoArray->aUndoActions[0].pAction;
46401300968SArmin Le Grand aGuard.markForDeletion( pAction );
46501300968SArmin Le Grand m_pData->pActUndoArray->aUndoActions.Remove(0);
46601300968SArmin Le Grand --m_pData->pActUndoArray->nCurUndoAction;
46701300968SArmin Le Grand --nNumToDelete;
468cdf0e10cSrcweir }
469cdf0e10cSrcweir
470cdf0e10cSrcweir if ( nPos == m_pData->pActUndoArray->aUndoActions.size() )
471cdf0e10cSrcweir break; // Cannot delete more entries
472cdf0e10cSrcweir }
473cdf0e10cSrcweir
474cdf0e10cSrcweir m_pData->pActUndoArray->nMaxUndoActions = nMaxUndoActionCount;
475cdf0e10cSrcweir }
476cdf0e10cSrcweir
477cdf0e10cSrcweir //------------------------------------------------------------------------
478cdf0e10cSrcweir
GetMaxUndoActionCount() const479cdf0e10cSrcweir size_t SfxUndoManager::GetMaxUndoActionCount() const
480cdf0e10cSrcweir {
481cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
482cdf0e10cSrcweir return m_pData->pActUndoArray->nMaxUndoActions;
483cdf0e10cSrcweir }
484cdf0e10cSrcweir
485cdf0e10cSrcweir //------------------------------------------------------------------------
486cdf0e10cSrcweir
ImplClearCurrentLevel_NoNotify(UndoManagerGuard & i_guard)487cdf0e10cSrcweir void SfxUndoManager::ImplClearCurrentLevel_NoNotify( UndoManagerGuard& i_guard )
488cdf0e10cSrcweir {
489cdf0e10cSrcweir // clear array
490cdf0e10cSrcweir while ( !m_pData->pActUndoArray->aUndoActions.empty() )
491cdf0e10cSrcweir {
492cdf0e10cSrcweir size_t deletePos = m_pData->pActUndoArray->aUndoActions.size() - 1;
493cdf0e10cSrcweir SfxUndoAction* pAction = m_pData->pActUndoArray->aUndoActions[ deletePos ].pAction;
494cdf0e10cSrcweir i_guard.markForDeletion( pAction );
495cdf0e10cSrcweir m_pData->pActUndoArray->aUndoActions.Remove( deletePos );
496cdf0e10cSrcweir }
497cdf0e10cSrcweir
498cdf0e10cSrcweir m_pData->pActUndoArray->nCurUndoAction = 0;
499cdf0e10cSrcweir
500cdf0e10cSrcweir m_pData->mnMarks = 0;
501cdf0e10cSrcweir m_pData->mnEmptyMark = MARK_INVALID;
502cdf0e10cSrcweir }
503cdf0e10cSrcweir
504cdf0e10cSrcweir //------------------------------------------------------------------------
505cdf0e10cSrcweir
Clear()506cdf0e10cSrcweir void SfxUndoManager::Clear()
507cdf0e10cSrcweir {
508cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
509cdf0e10cSrcweir
510cdf0e10cSrcweir OSL_ENSURE( !ImplIsInListAction_Lock(), "SfxUndoManager::Clear: suspicious call - do you really wish to clear the current level?" );
511cdf0e10cSrcweir ImplClearCurrentLevel_NoNotify( aGuard );
512cdf0e10cSrcweir
513cdf0e10cSrcweir // notify listeners
514cdf0e10cSrcweir aGuard.scheduleNotification( &SfxUndoListener::cleared );
515cdf0e10cSrcweir }
516cdf0e10cSrcweir
517cdf0e10cSrcweir //------------------------------------------------------------------------
518cdf0e10cSrcweir
ClearAllLevels()519cdf0e10cSrcweir void SfxUndoManager::ClearAllLevels()
520cdf0e10cSrcweir {
521cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
522cdf0e10cSrcweir ImplClearCurrentLevel_NoNotify( aGuard );
523cdf0e10cSrcweir
524cdf0e10cSrcweir if ( ImplIsInListAction_Lock() )
525cdf0e10cSrcweir {
526cdf0e10cSrcweir m_pData->mbClearUntilTopLevel = true;
527cdf0e10cSrcweir }
528cdf0e10cSrcweir else
529cdf0e10cSrcweir {
530cdf0e10cSrcweir aGuard.scheduleNotification( &SfxUndoListener::cleared );
531cdf0e10cSrcweir }
532cdf0e10cSrcweir }
533cdf0e10cSrcweir
534cdf0e10cSrcweir //------------------------------------------------------------------------
535cdf0e10cSrcweir
ImplClearRedo_NoLock(bool const i_currentLevel)536cdf0e10cSrcweir void SfxUndoManager::ImplClearRedo_NoLock( bool const i_currentLevel )
537cdf0e10cSrcweir {
538cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
539cdf0e10cSrcweir ImplClearRedo( aGuard, i_currentLevel );
540cdf0e10cSrcweir }
541cdf0e10cSrcweir
542cdf0e10cSrcweir //------------------------------------------------------------------------
543cdf0e10cSrcweir
ClearRedo()544cdf0e10cSrcweir void SfxUndoManager::ClearRedo()
545cdf0e10cSrcweir {
546cdf0e10cSrcweir OSL_ENSURE( !IsInListAction(), "SfxUndoManager::ClearRedo: suspicious call - do you really wish to clear the current level?" );
547cdf0e10cSrcweir ImplClearRedo_NoLock( CurrentLevel );
548cdf0e10cSrcweir }
549cdf0e10cSrcweir
550cdf0e10cSrcweir //------------------------------------------------------------------------
551cdf0e10cSrcweir
Reset()552cdf0e10cSrcweir void SfxUndoManager::Reset()
553cdf0e10cSrcweir {
554cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
555cdf0e10cSrcweir
556cdf0e10cSrcweir // clear all locks
557cdf0e10cSrcweir while ( !ImplIsUndoEnabled_Lock() )
558cdf0e10cSrcweir ImplEnableUndo_Lock( true );
559cdf0e10cSrcweir
560cdf0e10cSrcweir // cancel all list actions
561cdf0e10cSrcweir while ( IsInListAction() )
562cdf0e10cSrcweir ImplLeaveListAction( false, aGuard );
563cdf0e10cSrcweir
564cdf0e10cSrcweir // clear both stacks
565cdf0e10cSrcweir ImplClearCurrentLevel_NoNotify( aGuard );
566cdf0e10cSrcweir
567cdf0e10cSrcweir // cancel the notifications scheduled by ImplLeaveListAction,
568cdf0e10cSrcweir // as we want to do an own, dedicated notification
569cdf0e10cSrcweir aGuard.cancelNotifications();
570cdf0e10cSrcweir
571cdf0e10cSrcweir // schedule notification
572cdf0e10cSrcweir aGuard.scheduleNotification( &SfxUndoListener::resetAll );
573cdf0e10cSrcweir }
574cdf0e10cSrcweir
575cdf0e10cSrcweir //------------------------------------------------------------------------
576cdf0e10cSrcweir
ImplClearUndo(UndoManagerGuard & i_guard)577cdf0e10cSrcweir void SfxUndoManager::ImplClearUndo( UndoManagerGuard& i_guard )
578cdf0e10cSrcweir {
579cdf0e10cSrcweir while ( m_pData->pActUndoArray->nCurUndoAction > 0 )
580cdf0e10cSrcweir {
581cdf0e10cSrcweir SfxUndoAction* pUndoAction = m_pData->pActUndoArray->aUndoActions[0].pAction;
582cdf0e10cSrcweir m_pData->pActUndoArray->aUndoActions.Remove( 0 );
583cdf0e10cSrcweir i_guard.markForDeletion( pUndoAction );
584cdf0e10cSrcweir --m_pData->pActUndoArray->nCurUndoAction;
585cdf0e10cSrcweir }
586cdf0e10cSrcweir // TODO: notifications? We don't have clearedUndo, only cleared and clearedRedo at the SfxUndoListener
587cdf0e10cSrcweir }
588cdf0e10cSrcweir
589cdf0e10cSrcweir //------------------------------------------------------------------------
590cdf0e10cSrcweir
ImplClearRedo(UndoManagerGuard & i_guard,bool const i_currentLevel)591cdf0e10cSrcweir void SfxUndoManager::ImplClearRedo( UndoManagerGuard& i_guard, bool const i_currentLevel )
592cdf0e10cSrcweir {
593cdf0e10cSrcweir SfxUndoArray* pUndoArray = ( i_currentLevel == IUndoManager::CurrentLevel ) ? m_pData->pActUndoArray : m_pData->pUndoArray;
594cdf0e10cSrcweir
595cdf0e10cSrcweir // clearance
596cdf0e10cSrcweir while ( pUndoArray->aUndoActions.size() > pUndoArray->nCurUndoAction )
597cdf0e10cSrcweir {
598cdf0e10cSrcweir size_t deletePos = pUndoArray->aUndoActions.size() - 1;
599cdf0e10cSrcweir SfxUndoAction* pAction = pUndoArray->aUndoActions[ deletePos ].pAction;
600cdf0e10cSrcweir pUndoArray->aUndoActions.Remove( deletePos );
601cdf0e10cSrcweir i_guard.markForDeletion( pAction );
602cdf0e10cSrcweir }
603cdf0e10cSrcweir
604cdf0e10cSrcweir // notification - only if the top level's stack was cleared
605cdf0e10cSrcweir if ( i_currentLevel == IUndoManager::TopLevel )
606cdf0e10cSrcweir i_guard.scheduleNotification( &SfxUndoListener::clearedRedo );
607cdf0e10cSrcweir }
608cdf0e10cSrcweir
609cdf0e10cSrcweir //------------------------------------------------------------------------
610cdf0e10cSrcweir
ImplAddUndoAction_NoNotify(SfxUndoAction * pAction,bool bTryMerge,bool bClearRedo,UndoManagerGuard & i_guard)611cdf0e10cSrcweir bool SfxUndoManager::ImplAddUndoAction_NoNotify( SfxUndoAction *pAction, bool bTryMerge, bool bClearRedo, UndoManagerGuard& i_guard )
612cdf0e10cSrcweir {
613cdf0e10cSrcweir if ( !ImplIsUndoEnabled_Lock() || ( m_pData->pActUndoArray->nMaxUndoActions == 0 ) )
614cdf0e10cSrcweir {
615cdf0e10cSrcweir i_guard.markForDeletion( pAction );
616cdf0e10cSrcweir return false;
617cdf0e10cSrcweir }
618cdf0e10cSrcweir
619cdf0e10cSrcweir // merge, if required
620cdf0e10cSrcweir SfxUndoAction* pMergeWithAction = m_pData->pActUndoArray->nCurUndoAction ?
621cdf0e10cSrcweir m_pData->pActUndoArray->aUndoActions[m_pData->pActUndoArray->nCurUndoAction-1].pAction : NULL;
622cfbf046dSOliver-Rainer Wittmann if ( bTryMerge && ( pMergeWithAction && pMergeWithAction->Merge( pAction ) ) )
623cdf0e10cSrcweir {
624cdf0e10cSrcweir i_guard.markForDeletion( pAction );
625cdf0e10cSrcweir return false;
626cdf0e10cSrcweir }
627cdf0e10cSrcweir
628cdf0e10cSrcweir // clear redo stack, if requested
629cdf0e10cSrcweir if ( bClearRedo && ( ImplGetRedoActionCount_Lock( CurrentLevel ) > 0 ) )
630cdf0e10cSrcweir ImplClearRedo( i_guard, IUndoManager::CurrentLevel );
631cdf0e10cSrcweir
632cdf0e10cSrcweir // respect max number
633cdf0e10cSrcweir if( m_pData->pActUndoArray == m_pData->pUndoArray )
634cdf0e10cSrcweir {
63501300968SArmin Le Grand while(m_pData->pActUndoArray->aUndoActions.size() >= m_pData->pActUndoArray->nMaxUndoActions)
636cdf0e10cSrcweir {
637cdf0e10cSrcweir i_guard.markForDeletion( m_pData->pActUndoArray->aUndoActions[0].pAction );
638cdf0e10cSrcweir m_pData->pActUndoArray->aUndoActions.Remove(0);
63964b14621SArmin Le Grand
64064b14621SArmin Le Grand if(m_pData->pActUndoArray->nCurUndoAction)
64164b14621SArmin Le Grand {
64264b14621SArmin Le Grand --m_pData->pActUndoArray->nCurUndoAction;
64364b14621SArmin Le Grand }
64464b14621SArmin Le Grand else
64564b14621SArmin Le Grand {
64664b14621SArmin Le Grand OSL_ENSURE(false, "CurrentUndoAction going negative (!)");
64764b14621SArmin Le Grand }
648cdf0e10cSrcweir }
649cdf0e10cSrcweir }
650cdf0e10cSrcweir
651cdf0e10cSrcweir // append new action
652cdf0e10cSrcweir m_pData->pActUndoArray->aUndoActions.Insert( pAction, m_pData->pActUndoArray->nCurUndoAction++ );
653cdf0e10cSrcweir return true;
654cdf0e10cSrcweir }
655cdf0e10cSrcweir
656cdf0e10cSrcweir //------------------------------------------------------------------------
657cdf0e10cSrcweir
AddUndoAction(SfxUndoAction * pAction,sal_Bool bTryMerge)658cdf0e10cSrcweir void SfxUndoManager::AddUndoAction( SfxUndoAction *pAction, sal_Bool bTryMerge )
659cdf0e10cSrcweir {
660cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
661cdf0e10cSrcweir
662cdf0e10cSrcweir // add
663cdf0e10cSrcweir if ( ImplAddUndoAction_NoNotify( pAction, bTryMerge, true, aGuard ) )
664cdf0e10cSrcweir {
665cdf0e10cSrcweir // notify listeners
666cdf0e10cSrcweir aGuard.scheduleNotification( &SfxUndoListener::undoActionAdded, pAction->GetComment() );
667cdf0e10cSrcweir }
668cdf0e10cSrcweir }
669cdf0e10cSrcweir
670cdf0e10cSrcweir //------------------------------------------------------------------------
671cdf0e10cSrcweir
GetUndoActionCount(bool const i_currentLevel) const672cdf0e10cSrcweir size_t SfxUndoManager::GetUndoActionCount( bool const i_currentLevel ) const
673cdf0e10cSrcweir {
674cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
675cdf0e10cSrcweir const SfxUndoArray* pUndoArray = i_currentLevel ? m_pData->pActUndoArray : m_pData->pUndoArray;
676cdf0e10cSrcweir return pUndoArray->nCurUndoAction;
677cdf0e10cSrcweir }
678cdf0e10cSrcweir
679cdf0e10cSrcweir //------------------------------------------------------------------------
680cdf0e10cSrcweir
GetUndoActionComment(size_t nNo,bool const i_currentLevel) const681cdf0e10cSrcweir XubString SfxUndoManager::GetUndoActionComment( size_t nNo, bool const i_currentLevel ) const
682cdf0e10cSrcweir {
683cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
684cdf0e10cSrcweir
685cdf0e10cSrcweir String sComment;
686cdf0e10cSrcweir const SfxUndoArray* pUndoArray = i_currentLevel ? m_pData->pActUndoArray : m_pData->pUndoArray;
687cdf0e10cSrcweir DBG_ASSERT( nNo < pUndoArray->nCurUndoAction, "svl::SfxUndoManager::GetUndoActionComment: illegal index!" );
688cdf0e10cSrcweir if( nNo < pUndoArray->nCurUndoAction )
689cdf0e10cSrcweir {
690cdf0e10cSrcweir sComment = pUndoArray->aUndoActions[ pUndoArray->nCurUndoAction - 1 - nNo ].pAction->GetComment();
691cdf0e10cSrcweir }
692cdf0e10cSrcweir return sComment;
693cdf0e10cSrcweir }
694cdf0e10cSrcweir
695cdf0e10cSrcweir //------------------------------------------------------------------------
696cdf0e10cSrcweir
GetUndoActionId() const697cdf0e10cSrcweir sal_uInt16 SfxUndoManager::GetUndoActionId() const
698cdf0e10cSrcweir {
699cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
700cdf0e10cSrcweir
701cdf0e10cSrcweir DBG_ASSERT( m_pData->pActUndoArray->nCurUndoAction > 0, "svl::SfxUndoManager::GetUndoActionId(), illegal id!" );
702cdf0e10cSrcweir if ( m_pData->pActUndoArray->nCurUndoAction == 0 )
703cdf0e10cSrcweir return 0;
704cdf0e10cSrcweir return m_pData->pActUndoArray->aUndoActions[m_pData->pActUndoArray->nCurUndoAction-1].pAction->GetId();
705cdf0e10cSrcweir }
706cdf0e10cSrcweir
707cdf0e10cSrcweir //------------------------------------------------------------------------
708cdf0e10cSrcweir
GetUndoAction(size_t nNo) const709cdf0e10cSrcweir SfxUndoAction* SfxUndoManager::GetUndoAction( size_t nNo ) const
710cdf0e10cSrcweir {
711cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
712cdf0e10cSrcweir
713cdf0e10cSrcweir DBG_ASSERT( nNo < m_pData->pActUndoArray->nCurUndoAction, "svl::SfxUndoManager::GetUndoAction(), illegal id!" );
714cdf0e10cSrcweir if( nNo >= m_pData->pActUndoArray->nCurUndoAction )
715cdf0e10cSrcweir return NULL;
716cdf0e10cSrcweir return m_pData->pActUndoArray->aUndoActions[m_pData->pActUndoArray->nCurUndoAction-1-nNo].pAction;
717cdf0e10cSrcweir }
718cdf0e10cSrcweir
719cdf0e10cSrcweir //------------------------------------------------------------------------
720cdf0e10cSrcweir
721cdf0e10cSrcweir /** clears the redo stack and removes the top undo action */
RemoveLastUndoAction()722cdf0e10cSrcweir void SfxUndoManager::RemoveLastUndoAction()
723cdf0e10cSrcweir {
724cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
725cdf0e10cSrcweir
726cdf0e10cSrcweir ENSURE_OR_RETURN_VOID( m_pData->pActUndoArray->nCurUndoAction, "svl::SfxUndoManager::RemoveLastUndoAction(), no action to remove?!" );
727cdf0e10cSrcweir
728cdf0e10cSrcweir m_pData->pActUndoArray->nCurUndoAction--;
729cdf0e10cSrcweir
730cdf0e10cSrcweir // delete redo-actions and top action
731cdf0e10cSrcweir for ( size_t nPos = m_pData->pActUndoArray->aUndoActions.size(); nPos > m_pData->pActUndoArray->nCurUndoAction; --nPos )
732cdf0e10cSrcweir {
733cdf0e10cSrcweir aGuard.markForDeletion( m_pData->pActUndoArray->aUndoActions[nPos-1].pAction );
734cdf0e10cSrcweir }
735cdf0e10cSrcweir
736cdf0e10cSrcweir m_pData->pActUndoArray->aUndoActions.Remove(
737cdf0e10cSrcweir m_pData->pActUndoArray->nCurUndoAction,
738cdf0e10cSrcweir m_pData->pActUndoArray->aUndoActions.size() - m_pData->pActUndoArray->nCurUndoAction );
739cdf0e10cSrcweir }
740cdf0e10cSrcweir
741cdf0e10cSrcweir //------------------------------------------------------------------------
742cdf0e10cSrcweir
IsDoing() const743cdf0e10cSrcweir bool SfxUndoManager::IsDoing() const
744cdf0e10cSrcweir {
745cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
746cdf0e10cSrcweir return m_pData->mbDoing;
747cdf0e10cSrcweir }
748cdf0e10cSrcweir
749cdf0e10cSrcweir //------------------------------------------------------------------------
750cdf0e10cSrcweir
Undo()751cdf0e10cSrcweir sal_Bool SfxUndoManager::Undo()
752cdf0e10cSrcweir {
753cdf0e10cSrcweir return ImplUndo( NULL );
754cdf0e10cSrcweir }
755cdf0e10cSrcweir
756cdf0e10cSrcweir //------------------------------------------------------------------------
757cdf0e10cSrcweir
UndoWithContext(SfxUndoContext & i_context)758cdf0e10cSrcweir sal_Bool SfxUndoManager::UndoWithContext( SfxUndoContext& i_context )
759cdf0e10cSrcweir {
760cdf0e10cSrcweir return ImplUndo( &i_context );
761cdf0e10cSrcweir }
762cdf0e10cSrcweir
763cdf0e10cSrcweir //------------------------------------------------------------------------
764cdf0e10cSrcweir
ImplUndo(SfxUndoContext * i_contextOrNull)765cdf0e10cSrcweir sal_Bool SfxUndoManager::ImplUndo( SfxUndoContext* i_contextOrNull )
766cdf0e10cSrcweir {
767cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
768cdf0e10cSrcweir OSL_ENSURE( !IsDoing(), "SfxUndoManager::Undo: *nested* Undo/Redo actions? How this?" );
769cdf0e10cSrcweir
770cdf0e10cSrcweir ::comphelper::FlagGuard aDoingGuard( m_pData->mbDoing );
771cdf0e10cSrcweir LockGuard aLockGuard( *this );
772cdf0e10cSrcweir
773cdf0e10cSrcweir if ( ImplIsInListAction_Lock() )
774cdf0e10cSrcweir {
775cdf0e10cSrcweir OSL_ENSURE( false, "SfxUndoManager::Undo: not possible when within a list action!" );
776cdf0e10cSrcweir return sal_False;
777cdf0e10cSrcweir }
778cdf0e10cSrcweir
779cdf0e10cSrcweir if ( m_pData->pActUndoArray->nCurUndoAction == 0 )
780cdf0e10cSrcweir {
781cdf0e10cSrcweir OSL_ENSURE( false, "SfxUndoManager::Undo: undo stack is empty!" );
782cdf0e10cSrcweir return sal_False;
783cdf0e10cSrcweir }
784cdf0e10cSrcweir
785cdf0e10cSrcweir SfxUndoAction* pAction = m_pData->pActUndoArray->aUndoActions[ --m_pData->pActUndoArray->nCurUndoAction ].pAction;
786cdf0e10cSrcweir const String sActionComment = pAction->GetComment();
787cdf0e10cSrcweir try
788cdf0e10cSrcweir {
789cdf0e10cSrcweir // clear the guard/mutex before calling into the SfxUndoAction - this can be an extension-implemented UNO component
790cdf0e10cSrcweir // nowadays ...
791cdf0e10cSrcweir aGuard.clear();
792cdf0e10cSrcweir if ( i_contextOrNull != NULL )
793cdf0e10cSrcweir pAction->UndoWithContext( *i_contextOrNull );
794cdf0e10cSrcweir else
795cdf0e10cSrcweir pAction->Undo();
796cdf0e10cSrcweir aGuard.reset();
797cdf0e10cSrcweir }
798cdf0e10cSrcweir catch( ... )
799cdf0e10cSrcweir {
800cdf0e10cSrcweir aGuard.reset();
801cdf0e10cSrcweir
802cdf0e10cSrcweir // in theory, somebody might have tampered with all of *m_pData while the mutex was unlocked. So, see if
803cdf0e10cSrcweir // we still find pAction in our current Undo array
804cdf0e10cSrcweir size_t nCurAction = 0;
805cdf0e10cSrcweir while ( nCurAction < m_pData->pActUndoArray->aUndoActions.size() )
806cdf0e10cSrcweir {
807cdf0e10cSrcweir if ( m_pData->pActUndoArray->aUndoActions[ nCurAction++ ].pAction == pAction )
808cdf0e10cSrcweir {
809cdf0e10cSrcweir // the Undo action is still there ...
810cdf0e10cSrcweir // assume the error is a permanent failure, and clear the Undo stack
811cdf0e10cSrcweir ImplClearUndo( aGuard );
812cdf0e10cSrcweir throw;
813cdf0e10cSrcweir }
814cdf0e10cSrcweir }
815cdf0e10cSrcweir OSL_ENSURE( false, "SfxUndoManager::Undo: can't clear the Undo stack after the failure - some other party was faster ..." );
816cdf0e10cSrcweir throw;
817cdf0e10cSrcweir }
818cdf0e10cSrcweir
819cdf0e10cSrcweir aGuard.scheduleNotification( &SfxUndoListener::actionUndone, sActionComment );
820cdf0e10cSrcweir
821cdf0e10cSrcweir return sal_True;
822cdf0e10cSrcweir }
823cdf0e10cSrcweir
824cdf0e10cSrcweir //------------------------------------------------------------------------
825cdf0e10cSrcweir
GetRedoActionCount(bool const i_currentLevel) const826cdf0e10cSrcweir size_t SfxUndoManager::GetRedoActionCount( bool const i_currentLevel ) const
827cdf0e10cSrcweir {
828cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
829cdf0e10cSrcweir return ImplGetRedoActionCount_Lock( i_currentLevel );
830cdf0e10cSrcweir }
831cdf0e10cSrcweir
832cdf0e10cSrcweir //------------------------------------------------------------------------
833cdf0e10cSrcweir
ImplGetRedoActionCount_Lock(bool const i_currentLevel) const834cdf0e10cSrcweir size_t SfxUndoManager::ImplGetRedoActionCount_Lock( bool const i_currentLevel ) const
835cdf0e10cSrcweir {
836cdf0e10cSrcweir const SfxUndoArray* pUndoArray = i_currentLevel ? m_pData->pActUndoArray : m_pData->pUndoArray;
837cdf0e10cSrcweir return pUndoArray->aUndoActions.size() - pUndoArray->nCurUndoAction;
838cdf0e10cSrcweir }
839cdf0e10cSrcweir
840cdf0e10cSrcweir //------------------------------------------------------------------------
841cdf0e10cSrcweir
GetRedoAction(size_t nNo,bool const i_currentLevel) const84289358e0fSOliver-Rainer Wittmann SfxUndoAction* SfxUndoManager::GetRedoAction( size_t nNo, bool const i_currentLevel ) const
84389358e0fSOliver-Rainer Wittmann {
84489358e0fSOliver-Rainer Wittmann UndoManagerGuard aGuard( *m_pData );
84589358e0fSOliver-Rainer Wittmann
84689358e0fSOliver-Rainer Wittmann const SfxUndoArray* pUndoArray = i_currentLevel ? m_pData->pActUndoArray : m_pData->pUndoArray;
84789358e0fSOliver-Rainer Wittmann if ( (pUndoArray->nCurUndoAction + nNo) > pUndoArray->aUndoActions.size() )
84889358e0fSOliver-Rainer Wittmann {
84989358e0fSOliver-Rainer Wittmann return NULL;
85089358e0fSOliver-Rainer Wittmann }
85189358e0fSOliver-Rainer Wittmann return pUndoArray->aUndoActions[ pUndoArray->nCurUndoAction + nNo ].pAction;
85289358e0fSOliver-Rainer Wittmann }
85389358e0fSOliver-Rainer Wittmann
85489358e0fSOliver-Rainer Wittmann //------------------------------------------------------------------------
85589358e0fSOliver-Rainer Wittmann
GetRedoActionComment(size_t nNo,bool const i_currentLevel) const856cdf0e10cSrcweir XubString SfxUndoManager::GetRedoActionComment( size_t nNo, bool const i_currentLevel ) const
857cdf0e10cSrcweir {
85889358e0fSOliver-Rainer Wittmann String sComment;
859cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
860cdf0e10cSrcweir const SfxUndoArray* pUndoArray = i_currentLevel ? m_pData->pActUndoArray : m_pData->pUndoArray;
86189358e0fSOliver-Rainer Wittmann if ( (pUndoArray->nCurUndoAction + nNo) < pUndoArray->aUndoActions.size() )
86289358e0fSOliver-Rainer Wittmann {
86389358e0fSOliver-Rainer Wittmann sComment = pUndoArray->aUndoActions[ pUndoArray->nCurUndoAction + nNo ].pAction->GetComment();
86489358e0fSOliver-Rainer Wittmann }
86589358e0fSOliver-Rainer Wittmann return sComment;
866cdf0e10cSrcweir }
867cdf0e10cSrcweir
868cdf0e10cSrcweir //------------------------------------------------------------------------
869cdf0e10cSrcweir
Redo()870cdf0e10cSrcweir sal_Bool SfxUndoManager::Redo()
871cdf0e10cSrcweir {
872cdf0e10cSrcweir return ImplRedo( NULL );
873cdf0e10cSrcweir }
874cdf0e10cSrcweir
875cdf0e10cSrcweir //------------------------------------------------------------------------
876cdf0e10cSrcweir
RedoWithContext(SfxUndoContext & i_context)877cdf0e10cSrcweir sal_Bool SfxUndoManager::RedoWithContext( SfxUndoContext& i_context )
878cdf0e10cSrcweir {
879cdf0e10cSrcweir return ImplRedo( &i_context );
880cdf0e10cSrcweir }
881cdf0e10cSrcweir
882cdf0e10cSrcweir //------------------------------------------------------------------------
883cdf0e10cSrcweir
ImplRedo(SfxUndoContext * i_contextOrNull)884cdf0e10cSrcweir sal_Bool SfxUndoManager::ImplRedo( SfxUndoContext* i_contextOrNull )
885cdf0e10cSrcweir {
886cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
887cdf0e10cSrcweir OSL_ENSURE( !IsDoing(), "SfxUndoManager::Redo: *nested* Undo/Redo actions? How this?" );
888cdf0e10cSrcweir
889cdf0e10cSrcweir ::comphelper::FlagGuard aDoingGuard( m_pData->mbDoing );
890cdf0e10cSrcweir LockGuard aLockGuard( *this );
891cdf0e10cSrcweir
892cdf0e10cSrcweir if ( ImplIsInListAction_Lock() )
893cdf0e10cSrcweir {
894cdf0e10cSrcweir OSL_ENSURE( false, "SfxUndoManager::Redo: not possible when within a list action!" );
895cdf0e10cSrcweir return sal_False;
896cdf0e10cSrcweir }
897cdf0e10cSrcweir
898cdf0e10cSrcweir if ( m_pData->pActUndoArray->nCurUndoAction >= m_pData->pActUndoArray->aUndoActions.size() )
899cdf0e10cSrcweir {
900cdf0e10cSrcweir OSL_ENSURE( false, "SfxUndoManager::Redo: redo stack is empty!" );
901cdf0e10cSrcweir return sal_False;
902cdf0e10cSrcweir }
903cdf0e10cSrcweir
904cdf0e10cSrcweir SfxUndoAction* pAction = m_pData->pActUndoArray->aUndoActions[ m_pData->pActUndoArray->nCurUndoAction++ ].pAction;
905cdf0e10cSrcweir const String sActionComment = pAction->GetComment();
906cdf0e10cSrcweir try
907cdf0e10cSrcweir {
908cdf0e10cSrcweir // clear the guard/mutex before calling into the SfxUndoAction - this can be a extension-implemented UNO component
909cdf0e10cSrcweir // nowadays ...
910cdf0e10cSrcweir aGuard.clear();
911cdf0e10cSrcweir if ( i_contextOrNull != NULL )
912cdf0e10cSrcweir pAction->RedoWithContext( *i_contextOrNull );
913cdf0e10cSrcweir else
914cdf0e10cSrcweir pAction->Redo();
915cdf0e10cSrcweir aGuard.reset();
916cdf0e10cSrcweir }
917cdf0e10cSrcweir catch( ... )
918cdf0e10cSrcweir {
919cdf0e10cSrcweir aGuard.reset();
920cdf0e10cSrcweir
921cdf0e10cSrcweir // in theory, somebody might have tampered with all of *m_pData while the mutex was unlocked. So, see if
922cdf0e10cSrcweir // we still find pAction in our current Undo array
923cdf0e10cSrcweir size_t nCurAction = 0;
924cdf0e10cSrcweir while ( nCurAction < m_pData->pActUndoArray->aUndoActions.size() )
925cdf0e10cSrcweir {
926cdf0e10cSrcweir if ( m_pData->pActUndoArray->aUndoActions[ nCurAction ].pAction == pAction )
927cdf0e10cSrcweir {
928cdf0e10cSrcweir // the Undo action is still there ...
929cdf0e10cSrcweir // assume the error is a permanent failure, and clear the Undo stack
930cdf0e10cSrcweir ImplClearRedo( aGuard, IUndoManager::CurrentLevel );
931cdf0e10cSrcweir throw;
932cdf0e10cSrcweir }
933cdf0e10cSrcweir ++nCurAction;
934cdf0e10cSrcweir }
935cdf0e10cSrcweir OSL_ENSURE( false, "SfxUndoManager::Redo: can't clear the Undo stack after the failure - some other party was faster ..." );
936cdf0e10cSrcweir throw;
937cdf0e10cSrcweir }
938cdf0e10cSrcweir
939cdf0e10cSrcweir aGuard.scheduleNotification( &SfxUndoListener::actionRedone, sActionComment );
940cdf0e10cSrcweir
941cdf0e10cSrcweir return sal_True;
942cdf0e10cSrcweir }
943cdf0e10cSrcweir
944cdf0e10cSrcweir //------------------------------------------------------------------------
945cdf0e10cSrcweir
GetRepeatActionCount() const946cdf0e10cSrcweir size_t SfxUndoManager::GetRepeatActionCount() const
947cdf0e10cSrcweir {
948cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
949cdf0e10cSrcweir return m_pData->pActUndoArray->aUndoActions.size();
950cdf0e10cSrcweir }
951cdf0e10cSrcweir
952cdf0e10cSrcweir //------------------------------------------------------------------------
953cdf0e10cSrcweir
GetRepeatActionComment(SfxRepeatTarget & rTarget) const954cdf0e10cSrcweir XubString SfxUndoManager::GetRepeatActionComment( SfxRepeatTarget &rTarget) const
955cdf0e10cSrcweir {
956cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
957cdf0e10cSrcweir return m_pData->pActUndoArray->aUndoActions[ m_pData->pActUndoArray->aUndoActions.size() - 1 ].pAction
958cdf0e10cSrcweir ->GetRepeatComment(rTarget);
959cdf0e10cSrcweir }
960cdf0e10cSrcweir
961cdf0e10cSrcweir //------------------------------------------------------------------------
962cdf0e10cSrcweir
Repeat(SfxRepeatTarget & rTarget)963cdf0e10cSrcweir sal_Bool SfxUndoManager::Repeat( SfxRepeatTarget &rTarget )
964cdf0e10cSrcweir {
965cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
966cdf0e10cSrcweir if ( !m_pData->pActUndoArray->aUndoActions.empty() )
967cdf0e10cSrcweir {
968cdf0e10cSrcweir SfxUndoAction* pAction = m_pData->pActUndoArray->aUndoActions[ m_pData->pActUndoArray->aUndoActions.size() - 1 ].pAction;
969cdf0e10cSrcweir aGuard.clear();
970cdf0e10cSrcweir if ( pAction->CanRepeat( rTarget ) )
971cdf0e10cSrcweir pAction->Repeat( rTarget );
972cdf0e10cSrcweir return sal_True;
973cdf0e10cSrcweir }
974cdf0e10cSrcweir
975cdf0e10cSrcweir return sal_False;
976cdf0e10cSrcweir }
977cdf0e10cSrcweir
978cdf0e10cSrcweir //------------------------------------------------------------------------
979cdf0e10cSrcweir
CanRepeat(SfxRepeatTarget & rTarget) const980cdf0e10cSrcweir sal_Bool SfxUndoManager::CanRepeat( SfxRepeatTarget &rTarget ) const
981cdf0e10cSrcweir {
982cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
983cdf0e10cSrcweir if ( !m_pData->pActUndoArray->aUndoActions.empty() )
984cdf0e10cSrcweir {
985cdf0e10cSrcweir size_t nActionNo = m_pData->pActUndoArray->aUndoActions.size() - 1;
986cdf0e10cSrcweir return m_pData->pActUndoArray->aUndoActions[nActionNo].pAction->CanRepeat(rTarget);
987cdf0e10cSrcweir }
988cdf0e10cSrcweir return sal_False;
989cdf0e10cSrcweir }
990cdf0e10cSrcweir
991cdf0e10cSrcweir //------------------------------------------------------------------------
992cdf0e10cSrcweir
AddUndoListener(SfxUndoListener & i_listener)993cdf0e10cSrcweir void SfxUndoManager::AddUndoListener( SfxUndoListener& i_listener )
994cdf0e10cSrcweir {
995cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
996cdf0e10cSrcweir m_pData->aListeners.push_back( &i_listener );
997cdf0e10cSrcweir }
998cdf0e10cSrcweir
999cdf0e10cSrcweir //------------------------------------------------------------------------
1000cdf0e10cSrcweir
RemoveUndoListener(SfxUndoListener & i_listener)1001cdf0e10cSrcweir void SfxUndoManager::RemoveUndoListener( SfxUndoListener& i_listener )
1002cdf0e10cSrcweir {
1003cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
1004cdf0e10cSrcweir for ( UndoListeners::iterator lookup = m_pData->aListeners.begin();
1005cdf0e10cSrcweir lookup != m_pData->aListeners.end();
1006cdf0e10cSrcweir ++lookup
1007cdf0e10cSrcweir )
1008cdf0e10cSrcweir {
1009cdf0e10cSrcweir if ( (*lookup) == &i_listener )
1010cdf0e10cSrcweir {
1011cdf0e10cSrcweir m_pData->aListeners.erase( lookup );
1012cdf0e10cSrcweir break;
1013cdf0e10cSrcweir }
1014cdf0e10cSrcweir }
1015cdf0e10cSrcweir }
1016cdf0e10cSrcweir
1017cdf0e10cSrcweir //------------------------------------------------------------------------
1018cdf0e10cSrcweir
EnterListAction(const XubString & rComment,const XubString & rRepeatComment,sal_uInt16 nId)1019cdf0e10cSrcweir void SfxUndoManager::EnterListAction(
1020cdf0e10cSrcweir const XubString& rComment, const XubString &rRepeatComment, sal_uInt16 nId )
1021cdf0e10cSrcweir
1022cdf0e10cSrcweir /* [Beschreibung]
1023cdf0e10cSrcweir
1024cdf0e10cSrcweir Fuegt eine ListUndoAction ein und setzt dessen UndoArray als aktuelles.
1025cdf0e10cSrcweir */
1026cdf0e10cSrcweir
1027cdf0e10cSrcweir {
1028cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
1029cdf0e10cSrcweir
1030cdf0e10cSrcweir if( !ImplIsUndoEnabled_Lock() )
1031cdf0e10cSrcweir return;
1032cdf0e10cSrcweir
1033cdf0e10cSrcweir if ( !m_pData->pUndoArray->nMaxUndoActions )
1034cdf0e10cSrcweir return;
1035cdf0e10cSrcweir
1036cdf0e10cSrcweir m_pData->pFatherUndoArray = m_pData->pActUndoArray;
1037cdf0e10cSrcweir SfxListUndoAction* pAction = new SfxListUndoAction( rComment, rRepeatComment, nId, m_pData->pActUndoArray );
1038cdf0e10cSrcweir OSL_VERIFY( ImplAddUndoAction_NoNotify( pAction, false, false, aGuard ) );
1039cdf0e10cSrcweir // expected to succeed: all conditions under which it could fail should have been checked already
1040cdf0e10cSrcweir m_pData->pActUndoArray = pAction;
1041cdf0e10cSrcweir
1042cdf0e10cSrcweir // notification
1043cdf0e10cSrcweir aGuard.scheduleNotification( &SfxUndoListener::listActionEntered, rComment );
1044cdf0e10cSrcweir }
1045cdf0e10cSrcweir
1046cdf0e10cSrcweir //------------------------------------------------------------------------
1047cdf0e10cSrcweir
IsInListAction() const1048cdf0e10cSrcweir bool SfxUndoManager::IsInListAction() const
1049cdf0e10cSrcweir {
1050cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
1051cdf0e10cSrcweir return ImplIsInListAction_Lock();
1052cdf0e10cSrcweir }
1053cdf0e10cSrcweir
1054cdf0e10cSrcweir //------------------------------------------------------------------------
1055cdf0e10cSrcweir
ImplIsInListAction_Lock() const1056cdf0e10cSrcweir bool SfxUndoManager::ImplIsInListAction_Lock() const
1057cdf0e10cSrcweir {
1058cdf0e10cSrcweir return ( m_pData->pActUndoArray != m_pData->pUndoArray );
1059cdf0e10cSrcweir }
1060cdf0e10cSrcweir
1061cdf0e10cSrcweir //------------------------------------------------------------------------
1062cdf0e10cSrcweir
GetListActionDepth() const1063cdf0e10cSrcweir size_t SfxUndoManager::GetListActionDepth() const
1064cdf0e10cSrcweir {
1065cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
1066cdf0e10cSrcweir size_t nDepth(0);
1067cdf0e10cSrcweir
1068cdf0e10cSrcweir SfxUndoArray* pLookup( m_pData->pActUndoArray );
1069cdf0e10cSrcweir while ( pLookup != m_pData->pUndoArray )
1070cdf0e10cSrcweir {
1071cdf0e10cSrcweir pLookup = pLookup->pFatherUndoArray;
1072cdf0e10cSrcweir ++nDepth;
1073cdf0e10cSrcweir }
1074cdf0e10cSrcweir
1075cdf0e10cSrcweir return nDepth;
1076cdf0e10cSrcweir }
1077cdf0e10cSrcweir
1078cdf0e10cSrcweir //------------------------------------------------------------------------
1079cdf0e10cSrcweir
LeaveListAction()1080cdf0e10cSrcweir size_t SfxUndoManager::LeaveListAction()
1081cdf0e10cSrcweir {
1082cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
1083cdf0e10cSrcweir size_t nCount = ImplLeaveListAction( false, aGuard );
1084cdf0e10cSrcweir
1085cdf0e10cSrcweir if ( m_pData->mbClearUntilTopLevel )
1086cdf0e10cSrcweir {
1087cdf0e10cSrcweir ImplClearCurrentLevel_NoNotify( aGuard );
1088cdf0e10cSrcweir if ( !ImplIsInListAction_Lock() )
1089cdf0e10cSrcweir {
1090cdf0e10cSrcweir m_pData->mbClearUntilTopLevel = false;
1091cdf0e10cSrcweir aGuard.scheduleNotification( &SfxUndoListener::cleared );
1092cdf0e10cSrcweir }
1093cdf0e10cSrcweir nCount = 0;
1094cdf0e10cSrcweir }
1095cdf0e10cSrcweir
1096cdf0e10cSrcweir return nCount;
1097cdf0e10cSrcweir }
1098cdf0e10cSrcweir
1099cdf0e10cSrcweir //------------------------------------------------------------------------
1100cdf0e10cSrcweir
LeaveAndMergeListAction()1101cdf0e10cSrcweir size_t SfxUndoManager::LeaveAndMergeListAction()
1102cdf0e10cSrcweir {
1103cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
1104cdf0e10cSrcweir return ImplLeaveListAction( true, aGuard );
1105cdf0e10cSrcweir }
1106cdf0e10cSrcweir
1107cdf0e10cSrcweir //------------------------------------------------------------------------
1108cdf0e10cSrcweir
ImplLeaveListAction(const bool i_merge,UndoManagerGuard & i_guard)1109cdf0e10cSrcweir size_t SfxUndoManager::ImplLeaveListAction( const bool i_merge, UndoManagerGuard& i_guard )
1110cdf0e10cSrcweir {
1111cdf0e10cSrcweir if ( !ImplIsUndoEnabled_Lock() )
1112cdf0e10cSrcweir return 0;
1113cdf0e10cSrcweir
1114cdf0e10cSrcweir if ( !m_pData->pUndoArray->nMaxUndoActions )
1115cdf0e10cSrcweir return 0;
1116cdf0e10cSrcweir
1117cdf0e10cSrcweir if( !ImplIsInListAction_Lock() )
1118cdf0e10cSrcweir {
1119cdf0e10cSrcweir DBG_ERROR( "svl::SfxUndoManager::ImplLeaveListAction, called without calling EnterListAction()!" );
1120cdf0e10cSrcweir return 0;
1121cdf0e10cSrcweir }
1122cdf0e10cSrcweir
1123cdf0e10cSrcweir DBG_ASSERT( m_pData->pActUndoArray->pFatherUndoArray, "SfxUndoManager::ImplLeaveListAction, no father undo array!?" );
1124cdf0e10cSrcweir
1125cdf0e10cSrcweir // the array/level which we're about to leave
1126cdf0e10cSrcweir SfxUndoArray* pArrayToLeave = m_pData->pActUndoArray;
1127cdf0e10cSrcweir // one step up
1128cdf0e10cSrcweir m_pData->pActUndoArray = m_pData->pActUndoArray->pFatherUndoArray;
1129cdf0e10cSrcweir
1130cdf0e10cSrcweir // If no undo actions were added to the list, delete the list action
1131cdf0e10cSrcweir const size_t nListActionElements = pArrayToLeave->nCurUndoAction;
1132cdf0e10cSrcweir if ( nListActionElements == 0 )
1133cdf0e10cSrcweir {
1134cdf0e10cSrcweir SfxUndoAction* pCurrentAction= m_pData->pActUndoArray->aUndoActions[ m_pData->pActUndoArray->nCurUndoAction-1 ].pAction;
1135cdf0e10cSrcweir m_pData->pActUndoArray->aUndoActions.Remove( --m_pData->pActUndoArray->nCurUndoAction );
1136cdf0e10cSrcweir i_guard.markForDeletion( pCurrentAction );
1137cdf0e10cSrcweir
1138cdf0e10cSrcweir i_guard.scheduleNotification( &SfxUndoListener::listActionCancelled );
1139cdf0e10cSrcweir return 0;
1140cdf0e10cSrcweir }
1141cdf0e10cSrcweir
1142cdf0e10cSrcweir // now that it is finally clear the list action is non-trivial, and does participate in the Undo stack, clear
1143cdf0e10cSrcweir // the redo stack
1144cdf0e10cSrcweir ImplClearRedo( i_guard, IUndoManager::CurrentLevel );
1145cdf0e10cSrcweir
1146cdf0e10cSrcweir SfxUndoAction* pCurrentAction= m_pData->pActUndoArray->aUndoActions[ m_pData->pActUndoArray->nCurUndoAction-1 ].pAction;
1147cdf0e10cSrcweir SfxListUndoAction* pListAction = dynamic_cast< SfxListUndoAction * >( pCurrentAction );
1148cdf0e10cSrcweir ENSURE_OR_RETURN( pListAction, "SfxUndoManager::ImplLeaveListAction: list action expected at this position!", nListActionElements );
1149cdf0e10cSrcweir
1150cdf0e10cSrcweir if ( i_merge )
1151cdf0e10cSrcweir {
1152cdf0e10cSrcweir // merge the list action with its predecessor on the same level
1153cdf0e10cSrcweir OSL_ENSURE( m_pData->pActUndoArray->nCurUndoAction > 1,
1154cdf0e10cSrcweir "SfxUndoManager::ImplLeaveListAction: cannot merge the list action if there's no other action on the same level - check this beforehand!" );
1155cdf0e10cSrcweir if ( m_pData->pActUndoArray->nCurUndoAction > 1 )
1156cdf0e10cSrcweir {
1157cdf0e10cSrcweir SfxUndoAction* pPreviousAction = m_pData->pActUndoArray->aUndoActions[ m_pData->pActUndoArray->nCurUndoAction - 2 ].pAction;
1158cdf0e10cSrcweir m_pData->pActUndoArray->aUndoActions.Remove( m_pData->pActUndoArray->nCurUndoAction - 2 );
1159cdf0e10cSrcweir --m_pData->pActUndoArray->nCurUndoAction;
1160cdf0e10cSrcweir pListAction->aUndoActions.Insert( pPreviousAction, 0 );
1161cdf0e10cSrcweir ++pListAction->nCurUndoAction;
1162cdf0e10cSrcweir
1163cdf0e10cSrcweir pListAction->SetComment( pPreviousAction->GetComment() );
1164cdf0e10cSrcweir }
1165cdf0e10cSrcweir }
1166cdf0e10cSrcweir
1167cdf0e10cSrcweir // if the undo array has no comment, try to get it from its children
1168cdf0e10cSrcweir if ( pListAction->GetComment().Len() == 0 )
1169cdf0e10cSrcweir {
1170cdf0e10cSrcweir for( size_t n = 0; n < pListAction->aUndoActions.size(); n++ )
1171cdf0e10cSrcweir {
1172cdf0e10cSrcweir if( pListAction->aUndoActions[n].pAction->GetComment().Len() )
1173cdf0e10cSrcweir {
1174cdf0e10cSrcweir pListAction->SetComment( pListAction->aUndoActions[n].pAction->GetComment() );
1175cdf0e10cSrcweir break;
1176cdf0e10cSrcweir }
1177cdf0e10cSrcweir }
1178cdf0e10cSrcweir }
1179cdf0e10cSrcweir
1180cdf0e10cSrcweir // notify listeners
1181cdf0e10cSrcweir i_guard.scheduleNotification( &SfxUndoListener::listActionLeft, pListAction->GetComment() );
1182cdf0e10cSrcweir
1183cdf0e10cSrcweir // outta here
1184cdf0e10cSrcweir return nListActionElements;
1185cdf0e10cSrcweir }
1186cdf0e10cSrcweir
1187cdf0e10cSrcweir //------------------------------------------------------------------------
MarkTopUndoAction()1188cdf0e10cSrcweir UndoStackMark SfxUndoManager::MarkTopUndoAction()
1189cdf0e10cSrcweir {
1190cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
1191cdf0e10cSrcweir
1192cdf0e10cSrcweir OSL_ENSURE( !IsInListAction(),
1193cdf0e10cSrcweir "SfxUndoManager::MarkTopUndoAction(): suspicious call!" );
1194cdf0e10cSrcweir OSL_ENSURE((m_pData->mnMarks + 1) < (m_pData->mnEmptyMark - 1),
1195cdf0e10cSrcweir "SfxUndoManager::MarkTopUndoAction(): mark overflow!");
1196cdf0e10cSrcweir
1197cdf0e10cSrcweir size_t const nActionPos = m_pData->pUndoArray->nCurUndoAction;
1198cdf0e10cSrcweir if (0 == nActionPos)
1199cdf0e10cSrcweir {
1200cdf0e10cSrcweir --m_pData->mnEmptyMark;
1201cdf0e10cSrcweir return m_pData->mnEmptyMark;
1202cdf0e10cSrcweir }
1203cdf0e10cSrcweir
1204cdf0e10cSrcweir m_pData->pUndoArray->aUndoActions[ nActionPos-1 ].aMarks.push_back(
1205cdf0e10cSrcweir ++m_pData->mnMarks );
1206cdf0e10cSrcweir return m_pData->mnMarks;
1207cdf0e10cSrcweir }
1208cdf0e10cSrcweir
1209cdf0e10cSrcweir //------------------------------------------------------------------------
RemoveMark(UndoStackMark const i_mark)1210cdf0e10cSrcweir void SfxUndoManager::RemoveMark( UndoStackMark const i_mark )
1211cdf0e10cSrcweir {
1212cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
1213cdf0e10cSrcweir
1214cdf0e10cSrcweir if ((m_pData->mnEmptyMark < i_mark) || (MARK_INVALID == i_mark))
1215cdf0e10cSrcweir {
1216cdf0e10cSrcweir return; // nothing to remove
1217cdf0e10cSrcweir }
1218cdf0e10cSrcweir else if (i_mark == m_pData->mnEmptyMark)
1219cdf0e10cSrcweir {
1220cdf0e10cSrcweir --m_pData->mnEmptyMark; // never returned from MarkTop => invalid
1221cdf0e10cSrcweir return;
1222cdf0e10cSrcweir }
1223cdf0e10cSrcweir
1224cdf0e10cSrcweir for ( size_t i=0; i<m_pData->pUndoArray->aUndoActions.size(); ++i )
1225cdf0e10cSrcweir {
1226cdf0e10cSrcweir MarkedUndoAction& rAction = m_pData->pUndoArray->aUndoActions[i];
1227cdf0e10cSrcweir for ( ::std::vector< UndoStackMark >::iterator markPos = rAction.aMarks.begin();
1228cdf0e10cSrcweir markPos != rAction.aMarks.end();
1229cdf0e10cSrcweir ++markPos
1230cdf0e10cSrcweir )
1231cdf0e10cSrcweir {
1232cdf0e10cSrcweir if ( *markPos == i_mark )
1233cdf0e10cSrcweir {
1234cdf0e10cSrcweir rAction.aMarks.erase( markPos );
1235cdf0e10cSrcweir return;
1236cdf0e10cSrcweir }
1237cdf0e10cSrcweir }
1238cdf0e10cSrcweir }
1239cdf0e10cSrcweir OSL_ENSURE( false, "SfxUndoManager::RemoveMark: mark not found!" );
1240cdf0e10cSrcweir // TODO: this might be too offensive. There are situations where we implicitly remove marks
1241cdf0e10cSrcweir // without our clients, in particular the client which created the mark, having a chance to know
1242cdf0e10cSrcweir // about this.
1243cdf0e10cSrcweir }
1244cdf0e10cSrcweir
1245cdf0e10cSrcweir //------------------------------------------------------------------------
HasTopUndoActionMark(UndoStackMark const i_mark)1246cdf0e10cSrcweir bool SfxUndoManager::HasTopUndoActionMark( UndoStackMark const i_mark )
1247cdf0e10cSrcweir {
1248cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
1249cdf0e10cSrcweir
1250cdf0e10cSrcweir size_t nActionPos = m_pData->pUndoArray->nCurUndoAction;
1251cdf0e10cSrcweir if ( nActionPos == 0 )
1252cdf0e10cSrcweir {
1253cdf0e10cSrcweir return (i_mark == m_pData->mnEmptyMark);
1254cdf0e10cSrcweir }
1255cdf0e10cSrcweir
1256cdf0e10cSrcweir const MarkedUndoAction& rAction =
1257cdf0e10cSrcweir m_pData->pUndoArray->aUndoActions[ nActionPos-1 ];
1258cdf0e10cSrcweir for ( ::std::vector< UndoStackMark >::const_iterator markPos = rAction.aMarks.begin();
1259cdf0e10cSrcweir markPos != rAction.aMarks.end();
1260cdf0e10cSrcweir ++markPos
1261cdf0e10cSrcweir )
1262cdf0e10cSrcweir {
1263cdf0e10cSrcweir if ( *markPos == i_mark )
1264cdf0e10cSrcweir return true;
1265cdf0e10cSrcweir }
1266cdf0e10cSrcweir
1267cdf0e10cSrcweir return false;
1268cdf0e10cSrcweir }
1269cdf0e10cSrcweir
1270cdf0e10cSrcweir //------------------------------------------------------------------------
1271cdf0e10cSrcweir
RemoveOldestUndoActions(size_t const i_count)1272cdf0e10cSrcweir void SfxUndoManager::RemoveOldestUndoActions( size_t const i_count )
1273cdf0e10cSrcweir {
1274cdf0e10cSrcweir UndoManagerGuard aGuard( *m_pData );
1275cdf0e10cSrcweir
1276cdf0e10cSrcweir size_t nActionsToRemove = i_count;
1277cdf0e10cSrcweir while ( nActionsToRemove )
1278cdf0e10cSrcweir {
1279cdf0e10cSrcweir SfxUndoAction* pActionToRemove = m_pData->pUndoArray->aUndoActions[0].pAction;
1280cdf0e10cSrcweir
1281cdf0e10cSrcweir if ( IsInListAction() && ( m_pData->pUndoArray->nCurUndoAction == 1 ) )
1282cdf0e10cSrcweir {
1283cdf0e10cSrcweir OSL_ENSURE( false, "SfxUndoManager::RemoveOldestUndoActions: cannot remove a not-yet-closed list action!" );
1284cdf0e10cSrcweir return;
1285cdf0e10cSrcweir }
1286cdf0e10cSrcweir
1287cdf0e10cSrcweir aGuard.markForDeletion( pActionToRemove );
1288cdf0e10cSrcweir m_pData->pUndoArray->aUndoActions.Remove( 0 );
1289cdf0e10cSrcweir --m_pData->pUndoArray->nCurUndoAction;
1290cdf0e10cSrcweir --nActionsToRemove;
1291cdf0e10cSrcweir }
1292cdf0e10cSrcweir }
1293cdf0e10cSrcweir
1294cdf0e10cSrcweir //------------------------------------------------------------------------
1295cdf0e10cSrcweir
GetId() const1296cdf0e10cSrcweir sal_uInt16 SfxListUndoAction::GetId() const
1297cdf0e10cSrcweir {
1298cdf0e10cSrcweir return nId;
1299cdf0e10cSrcweir }
1300cdf0e10cSrcweir
1301cdf0e10cSrcweir //------------------------------------------------------------------------
1302cdf0e10cSrcweir
GetComment() const1303cdf0e10cSrcweir XubString SfxListUndoAction::GetComment() const
1304cdf0e10cSrcweir {
1305cdf0e10cSrcweir return aComment;
1306cdf0e10cSrcweir }
1307cdf0e10cSrcweir
1308cdf0e10cSrcweir //------------------------------------------------------------------------
1309cdf0e10cSrcweir
SetComment(const UniString & rComment)1310cdf0e10cSrcweir void SfxListUndoAction::SetComment( const UniString& rComment )
1311cdf0e10cSrcweir {
1312cdf0e10cSrcweir aComment = rComment;
1313cdf0e10cSrcweir }
1314cdf0e10cSrcweir
1315cdf0e10cSrcweir //------------------------------------------------------------------------
1316cdf0e10cSrcweir
GetRepeatComment(SfxRepeatTarget &) const1317cdf0e10cSrcweir XubString SfxListUndoAction::GetRepeatComment(SfxRepeatTarget &) const
1318cdf0e10cSrcweir {
1319cdf0e10cSrcweir return aRepeatComment;
1320cdf0e10cSrcweir }
1321cdf0e10cSrcweir
1322cdf0e10cSrcweir
1323cdf0e10cSrcweir //------------------------------------------------------------------------
1324cdf0e10cSrcweir
SfxListUndoAction(const XubString & rComment,const XubString rRepeatComment,sal_uInt16 Id,SfxUndoArray * pFather)1325cdf0e10cSrcweir SfxListUndoAction::SfxListUndoAction
1326cdf0e10cSrcweir (
1327cdf0e10cSrcweir const XubString &rComment,
1328cdf0e10cSrcweir const XubString rRepeatComment,
1329cdf0e10cSrcweir sal_uInt16 Id,
1330cdf0e10cSrcweir SfxUndoArray *pFather
1331cdf0e10cSrcweir )
1332cdf0e10cSrcweir : nId(Id), aComment(rComment), aRepeatComment(rRepeatComment)
1333cdf0e10cSrcweir {
1334cdf0e10cSrcweir pFatherUndoArray = pFather;
1335cdf0e10cSrcweir nMaxUndoActions = USHRT_MAX;
1336cdf0e10cSrcweir }
1337cdf0e10cSrcweir
1338cdf0e10cSrcweir //------------------------------------------------------------------------
1339cdf0e10cSrcweir
Undo()1340cdf0e10cSrcweir void SfxListUndoAction::Undo()
1341cdf0e10cSrcweir {
1342cdf0e10cSrcweir for(size_t i=nCurUndoAction;i>0;)
1343cdf0e10cSrcweir aUndoActions[--i].pAction->Undo();
1344cdf0e10cSrcweir nCurUndoAction=0;
1345cdf0e10cSrcweir }
1346cdf0e10cSrcweir
1347cdf0e10cSrcweir //------------------------------------------------------------------------
1348cdf0e10cSrcweir
UndoWithContext(SfxUndoContext & i_context)1349cdf0e10cSrcweir void SfxListUndoAction::UndoWithContext( SfxUndoContext& i_context )
1350cdf0e10cSrcweir {
1351cdf0e10cSrcweir for(size_t i=nCurUndoAction;i>0;)
1352cdf0e10cSrcweir aUndoActions[--i].pAction->UndoWithContext( i_context );
1353cdf0e10cSrcweir nCurUndoAction=0;
1354cdf0e10cSrcweir }
1355cdf0e10cSrcweir
1356cdf0e10cSrcweir //------------------------------------------------------------------------
1357cdf0e10cSrcweir
Redo()1358cdf0e10cSrcweir void SfxListUndoAction::Redo()
1359cdf0e10cSrcweir {
1360cdf0e10cSrcweir for(size_t i=nCurUndoAction;i<aUndoActions.size();i++)
1361cdf0e10cSrcweir aUndoActions[i].pAction->Redo();
1362cdf0e10cSrcweir nCurUndoAction = aUndoActions.size();
1363cdf0e10cSrcweir }
1364cdf0e10cSrcweir
1365cdf0e10cSrcweir //------------------------------------------------------------------------
1366cdf0e10cSrcweir
RedoWithContext(SfxUndoContext & i_context)1367cdf0e10cSrcweir void SfxListUndoAction::RedoWithContext( SfxUndoContext& i_context )
1368cdf0e10cSrcweir {
1369cdf0e10cSrcweir for(size_t i=nCurUndoAction;i<aUndoActions.size();i++)
1370cdf0e10cSrcweir aUndoActions[i].pAction->RedoWithContext( i_context );
1371cdf0e10cSrcweir nCurUndoAction = aUndoActions.size();
1372cdf0e10cSrcweir }
1373cdf0e10cSrcweir
1374cdf0e10cSrcweir //------------------------------------------------------------------------
1375cdf0e10cSrcweir
Repeat(SfxRepeatTarget & rTarget)1376cdf0e10cSrcweir void SfxListUndoAction::Repeat(SfxRepeatTarget&rTarget)
1377cdf0e10cSrcweir {
1378cdf0e10cSrcweir for(size_t i=0;i<nCurUndoAction;i++)
1379cdf0e10cSrcweir aUndoActions[i].pAction->Repeat(rTarget);
1380cdf0e10cSrcweir }
1381cdf0e10cSrcweir
1382cdf0e10cSrcweir //------------------------------------------------------------------------
1383cdf0e10cSrcweir
CanRepeat(SfxRepeatTarget & r) const1384cdf0e10cSrcweir sal_Bool SfxListUndoAction::CanRepeat(SfxRepeatTarget&r) const
1385cdf0e10cSrcweir {
1386cdf0e10cSrcweir for(size_t i=0;i<nCurUndoAction;i++)
1387cdf0e10cSrcweir if(!aUndoActions[i].pAction->CanRepeat(r))
1388cdf0e10cSrcweir return sal_False;
1389cdf0e10cSrcweir return sal_True;
1390cdf0e10cSrcweir }
1391cdf0e10cSrcweir
1392cdf0e10cSrcweir //------------------------------------------------------------------------
1393cdf0e10cSrcweir
Merge(SfxUndoAction * pNextAction)1394cdf0e10cSrcweir sal_Bool SfxListUndoAction::Merge( SfxUndoAction *pNextAction )
1395cdf0e10cSrcweir {
1396cdf0e10cSrcweir return !aUndoActions.empty() && aUndoActions[aUndoActions.size()-1].pAction->Merge( pNextAction );
1397cdf0e10cSrcweir }
1398cdf0e10cSrcweir
1399cdf0e10cSrcweir //------------------------------------------------------------------------
1400cdf0e10cSrcweir
SfxLinkUndoAction(::svl::IUndoManager * pManager)1401cdf0e10cSrcweir SfxLinkUndoAction::SfxLinkUndoAction(::svl::IUndoManager *pManager)
1402cdf0e10cSrcweir /* [Beschreibung]
1403cdf0e10cSrcweir
1404cdf0e10cSrcweir Richtet eine LinkAction ein, die auf einen weiteren UndoManager zeigt.
1405cdf0e10cSrcweir Holt sich als zugehoerige Action des weiteren UndoManagers dessen
1406cdf0e10cSrcweir aktuelle Action.
1407cdf0e10cSrcweir */
1408cdf0e10cSrcweir
1409cdf0e10cSrcweir {
1410cdf0e10cSrcweir pUndoManager = pManager;
1411cdf0e10cSrcweir SfxUndoManager* pUndoManagerImplementation = dynamic_cast< SfxUndoManager* >( pManager );
1412cdf0e10cSrcweir ENSURE_OR_THROW( pUndoManagerImplementation != NULL, "unsupported undo manager implementation!" );
1413*fb0b81f5Smseidel // yes, this cast is dirty. But reaching into the SfxUndoManager's implementation,
1414cdf0e10cSrcweir // directly accessing its internal stack, and tampering with an action on that stack
1415cdf0e10cSrcweir // is dirty, too.
1416cdf0e10cSrcweir if ( pManager->GetMaxUndoActionCount() )
1417cdf0e10cSrcweir {
1418cdf0e10cSrcweir size_t nPos = pManager->GetUndoActionCount()-1;
1419cdf0e10cSrcweir pAction = pUndoManagerImplementation->m_pData->pActUndoArray->aUndoActions[nPos].pAction;
142001300968SArmin Le Grand pAction->SetLinkToSfxLinkUndoAction(this);
1421cdf0e10cSrcweir }
1422cdf0e10cSrcweir else
1423cdf0e10cSrcweir pAction = 0;
1424cdf0e10cSrcweir }
1425cdf0e10cSrcweir
1426cdf0e10cSrcweir //------------------------------------------------------------------------
1427cdf0e10cSrcweir
Undo()1428cdf0e10cSrcweir void SfxLinkUndoAction::Undo()
1429cdf0e10cSrcweir {
1430cdf0e10cSrcweir if ( pAction )
1431cdf0e10cSrcweir pUndoManager->Undo();
1432cdf0e10cSrcweir }
1433cdf0e10cSrcweir
1434cdf0e10cSrcweir //------------------------------------------------------------------------
1435cdf0e10cSrcweir
Redo()1436cdf0e10cSrcweir void SfxLinkUndoAction::Redo()
1437cdf0e10cSrcweir {
1438cdf0e10cSrcweir if ( pAction )
1439cdf0e10cSrcweir pUndoManager->Redo();
1440cdf0e10cSrcweir }
1441cdf0e10cSrcweir
1442cdf0e10cSrcweir //------------------------------------------------------------------------
1443cdf0e10cSrcweir
1444cdf0e10cSrcweir
CanRepeat(SfxRepeatTarget & r) const1445cdf0e10cSrcweir sal_Bool SfxLinkUndoAction::CanRepeat(SfxRepeatTarget& r) const
1446cdf0e10cSrcweir {
1447cdf0e10cSrcweir return pAction && pAction->CanRepeat(r);
1448cdf0e10cSrcweir }
1449cdf0e10cSrcweir
1450cdf0e10cSrcweir
1451cdf0e10cSrcweir //------------------------------------------------------------------------
1452cdf0e10cSrcweir
1453cdf0e10cSrcweir
Repeat(SfxRepeatTarget & r)1454cdf0e10cSrcweir void SfxLinkUndoAction::Repeat(SfxRepeatTarget&r)
1455cdf0e10cSrcweir {
1456cdf0e10cSrcweir if ( pAction && pAction->CanRepeat( r ) )
1457cdf0e10cSrcweir pAction->Repeat( r );
1458cdf0e10cSrcweir }
1459cdf0e10cSrcweir
1460cdf0e10cSrcweir
1461cdf0e10cSrcweir //------------------------------------------------------------------------
1462cdf0e10cSrcweir
GetComment() const1463cdf0e10cSrcweir XubString SfxLinkUndoAction::GetComment() const
1464cdf0e10cSrcweir {
1465cdf0e10cSrcweir if ( pAction )
1466cdf0e10cSrcweir return pAction->GetComment();
1467cdf0e10cSrcweir else
1468cdf0e10cSrcweir return XubString();
1469cdf0e10cSrcweir }
1470cdf0e10cSrcweir
1471cdf0e10cSrcweir
1472cdf0e10cSrcweir //------------------------------------------------------------------------
1473cdf0e10cSrcweir
GetRepeatComment(SfxRepeatTarget & r) const1474cdf0e10cSrcweir XubString SfxLinkUndoAction::GetRepeatComment(SfxRepeatTarget&r) const
1475cdf0e10cSrcweir {
1476cdf0e10cSrcweir if ( pAction )
1477cdf0e10cSrcweir return pAction->GetRepeatComment(r);
1478cdf0e10cSrcweir else
1479cdf0e10cSrcweir return XubString();
1480cdf0e10cSrcweir }
1481cdf0e10cSrcweir
1482cdf0e10cSrcweir //------------------------------------------------------------------------
1483cdf0e10cSrcweir
~SfxLinkUndoAction()1484cdf0e10cSrcweir SfxLinkUndoAction::~SfxLinkUndoAction()
1485cdf0e10cSrcweir {
1486cdf0e10cSrcweir if( pAction )
148701300968SArmin Le Grand pAction->SetLinkToSfxLinkUndoAction(0);
1488cdf0e10cSrcweir }
1489cdf0e10cSrcweir
149001300968SArmin Le Grand //------------------------------------------------------------------------
149101300968SArmin Le Grand
LinkedSfxUndoActionDestructed(const SfxUndoAction & rCandidate)149201300968SArmin Le Grand void SfxLinkUndoAction::LinkedSfxUndoActionDestructed(const SfxUndoAction& rCandidate)
149301300968SArmin Le Grand {
149401300968SArmin Le Grand OSL_ENSURE(0 != pAction, "OOps, we have no linked SfxUndoAction (!)");
149501300968SArmin Le Grand OSL_ENSURE(pAction == &rCandidate, "OOps, the destroyed and linked UndoActions differ (!)");
149601300968SArmin Le Grand (void)rCandidate;
149701300968SArmin Le Grand pAction = 0;
149801300968SArmin Le Grand }
1499cdf0e10cSrcweir
1500cdf0e10cSrcweir //------------------------------------------------------------------------
1501cdf0e10cSrcweir
~SfxUndoArray()1502cdf0e10cSrcweir SfxUndoArray::~SfxUndoArray()
1503cdf0e10cSrcweir {
1504cdf0e10cSrcweir while ( !aUndoActions.empty() )
1505cdf0e10cSrcweir {
1506cdf0e10cSrcweir SfxUndoAction *pAction = aUndoActions[ aUndoActions.size() - 1 ].pAction;
1507cdf0e10cSrcweir aUndoActions.Remove( aUndoActions.size() - 1 );
1508cdf0e10cSrcweir delete pAction;
1509cdf0e10cSrcweir }
1510cdf0e10cSrcweir }
1511cdf0e10cSrcweir
1512cdf0e10cSrcweir
GetId() const1513cdf0e10cSrcweir sal_uInt16 SfxLinkUndoAction::GetId() const
1514cdf0e10cSrcweir {
1515cdf0e10cSrcweir return pAction ? pAction->GetId() : 0;
1516cdf0e10cSrcweir }
1517