Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / dbaccess / source / ui / misc / dbaundomanager.cxx
blob58b83be221a5f47a020e4209c3de570d3461c490
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 #include "dbaundomanager.hxx"
31 /** === begin UNO includes === **/
32 #include <com/sun/star/lang/DisposedException.hpp>
33 /** === end UNO includes === **/
35 #include <svl/undo.hxx>
36 #include <vcl/svapp.hxx>
37 #include <framework/undomanagerhelper.hxx>
39 //......................................................................................................................
40 namespace dbaui
42 //......................................................................................................................
44 /** === begin UNO using === **/
45 using ::com::sun::star::uno::Reference;
46 using ::com::sun::star::uno::XInterface;
47 using ::com::sun::star::uno::UNO_QUERY;
48 using ::com::sun::star::uno::UNO_QUERY_THROW;
49 using ::com::sun::star::uno::UNO_SET_THROW;
50 using ::com::sun::star::uno::Exception;
51 using ::com::sun::star::uno::RuntimeException;
52 using ::com::sun::star::uno::Any;
53 using ::com::sun::star::uno::makeAny;
54 using ::com::sun::star::uno::Sequence;
55 using ::com::sun::star::uno::Type;
56 using ::com::sun::star::document::XUndoManager;
57 using ::com::sun::star::lang::DisposedException;
58 using ::com::sun::star::document::UndoContextNotClosedException;
59 using ::com::sun::star::document::UndoFailedException;
60 using ::com::sun::star::document::EmptyUndoStackException;
61 using ::com::sun::star::util::InvalidStateException;
62 using ::com::sun::star::document::XUndoAction;
63 using ::com::sun::star::lang::IllegalArgumentException;
64 using ::com::sun::star::document::XUndoManagerListener;
65 using ::com::sun::star::util::NotLockedException;
66 using ::com::sun::star::lang::NoSupportException;
67 /** === end UNO using === **/
69 //==================================================================================================================
70 //= UndoManager_Impl
71 //==================================================================================================================
72 struct UndoManager_Impl : public ::framework::IUndoManagerImplementation
74 UndoManager_Impl( UndoManager& i_antiImpl, ::cppu::OWeakObject& i_parent, ::osl::Mutex& i_mutex )
75 :rAntiImpl( i_antiImpl )
76 ,rParent( i_parent )
77 ,rMutex( i_mutex )
78 ,bDisposed( false )
79 ,aUndoManager()
80 ,aUndoHelper( *this )
84 virtual ~UndoManager_Impl()
88 UndoManager& rAntiImpl;
89 ::cppu::OWeakObject& rParent;
90 ::osl::Mutex& rMutex;
91 bool bDisposed;
92 SfxUndoManager aUndoManager;
93 ::framework::UndoManagerHelper aUndoHelper;
95 // IUndoManagerImplementation
96 virtual ::svl::IUndoManager& getImplUndoManager();
97 virtual Reference< XUndoManager > getThis();
100 //------------------------------------------------------------------------------------------------------------------
101 ::svl::IUndoManager& UndoManager_Impl::getImplUndoManager()
103 return aUndoManager;
106 //------------------------------------------------------------------------------------------------------------------
107 Reference< XUndoManager > UndoManager_Impl::getThis()
109 return static_cast< XUndoManager* >( &rAntiImpl );
112 //==============================================================================================================
113 //= OslMutexFacade
114 //==============================================================================================================
115 class OslMutexFacade : public ::framework::IMutex
117 public:
118 OslMutexFacade( ::osl::Mutex& i_mutex )
119 :m_rMutex( i_mutex )
123 virtual ~OslMutexFacade() {}
125 virtual void acquire();
126 virtual void release();
128 private:
129 ::osl::Mutex& m_rMutex;
132 //--------------------------------------------------------------------------------------------------------------
133 void OslMutexFacade::acquire()
135 m_rMutex.acquire();
138 //--------------------------------------------------------------------------------------------------------------
139 void OslMutexFacade::release()
141 m_rMutex.release();
144 //==============================================================================================================
145 //= UndoManagerMethodGuard
146 //==============================================================================================================
147 /** guard for public UNO methods of the UndoManager
149 class UndoManagerMethodGuard : public ::framework::IMutexGuard
151 public:
152 UndoManagerMethodGuard( UndoManager_Impl& i_impl )
153 :m_aGuard( i_impl.rMutex )
154 ,m_aMutexFacade( i_impl.rMutex )
156 // throw if the instance is already disposed
157 if ( i_impl.bDisposed )
158 throw DisposedException( ::rtl::OUString(), i_impl.getThis() );
160 virtual ~UndoManagerMethodGuard()
164 // IMutexGuard
165 virtual ::framework::IMutex& getGuardedMutex();
167 // IGuard
168 virtual void clear();
169 virtual void reset();
171 private:
172 ::osl::ResettableMutexGuard m_aGuard;
173 OslMutexFacade m_aMutexFacade;
176 //--------------------------------------------------------------------------------------------------------------
177 ::framework::IMutex& UndoManagerMethodGuard::getGuardedMutex()
179 return m_aMutexFacade;
182 //--------------------------------------------------------------------------------------------------------------
183 void UndoManagerMethodGuard::clear()
185 m_aGuard.clear();
188 //--------------------------------------------------------------------------------------------------------------
189 void UndoManagerMethodGuard::reset()
191 m_aGuard.reset();
194 //==================================================================================================================
195 //= UndoManager
196 //==================================================================================================================
197 //------------------------------------------------------------------------------------------------------------------
198 UndoManager::UndoManager( ::cppu::OWeakObject& i_parent, ::osl::Mutex& i_mutex )
199 :m_pImpl( new UndoManager_Impl( *this, i_parent, i_mutex ) )
203 //------------------------------------------------------------------------------------------------------------------
204 UndoManager::~UndoManager()
208 //------------------------------------------------------------------------------------------------------------------
209 SfxUndoManager& UndoManager::GetSfxUndoManager() const
211 return m_pImpl->aUndoManager;
214 //------------------------------------------------------------------------------------------------------------------
215 void SAL_CALL UndoManager::acquire( ) throw ()
217 m_pImpl->rParent.acquire();
220 //------------------------------------------------------------------------------------------------------------------
221 void SAL_CALL UndoManager::release( ) throw ()
223 m_pImpl->rParent.release();
226 //------------------------------------------------------------------------------------------------------------------
227 void UndoManager::disposing()
230 ::osl::MutexGuard aGuard( m_pImpl->rMutex );
231 m_pImpl->bDisposed = true;
233 m_pImpl->aUndoHelper.disposing();
236 //------------------------------------------------------------------------------------------------------------------
237 void SAL_CALL UndoManager::enterUndoContext( const ::rtl::OUString& i_title ) throw (RuntimeException)
239 UndoManagerMethodGuard aGuard( *m_pImpl );
240 m_pImpl->aUndoHelper.enterUndoContext( i_title, aGuard );
243 //------------------------------------------------------------------------------------------------------------------
244 void SAL_CALL UndoManager::enterHiddenUndoContext( ) throw (EmptyUndoStackException, RuntimeException)
246 UndoManagerMethodGuard aGuard( *m_pImpl );
247 m_pImpl->aUndoHelper.enterHiddenUndoContext( aGuard );
250 //------------------------------------------------------------------------------------------------------------------
251 void SAL_CALL UndoManager::leaveUndoContext( ) throw (InvalidStateException, RuntimeException)
253 UndoManagerMethodGuard aGuard( *m_pImpl );
254 m_pImpl->aUndoHelper.leaveUndoContext( aGuard );
257 //------------------------------------------------------------------------------------------------------------------
258 void SAL_CALL UndoManager::addUndoAction( const Reference< XUndoAction >& i_action ) throw (IllegalArgumentException, RuntimeException)
260 UndoManagerMethodGuard aGuard( *m_pImpl );
261 m_pImpl->aUndoHelper.addUndoAction( i_action, aGuard );
264 //------------------------------------------------------------------------------------------------------------------
265 void SAL_CALL UndoManager::undo( ) throw (EmptyUndoStackException, UndoContextNotClosedException, UndoFailedException, RuntimeException)
267 SolarMutexGuard aSolarGuard;
268 // (all our UndoActions work directly on VCL code, usually, so ...)
269 UndoManagerMethodGuard aGuard( *m_pImpl );
270 m_pImpl->aUndoHelper.undo( aGuard );
273 //------------------------------------------------------------------------------------------------------------------
274 void SAL_CALL UndoManager::redo( ) throw (EmptyUndoStackException, UndoContextNotClosedException, UndoFailedException, RuntimeException)
276 SolarMutexGuard aSolarGuard;
277 // (all our UndoActions work directly on VCL code, usually, so ...)
278 UndoManagerMethodGuard aGuard( *m_pImpl );
279 m_pImpl->aUndoHelper.redo( aGuard );
282 //------------------------------------------------------------------------------------------------------------------
283 ::sal_Bool SAL_CALL UndoManager::isUndoPossible( ) throw (RuntimeException)
285 UndoManagerMethodGuard aGuard( *m_pImpl );
286 return m_pImpl->aUndoHelper.isUndoPossible();
289 //------------------------------------------------------------------------------------------------------------------
290 ::sal_Bool SAL_CALL UndoManager::isRedoPossible( ) throw (RuntimeException)
292 UndoManagerMethodGuard aGuard( *m_pImpl );
293 return m_pImpl->aUndoHelper.isRedoPossible();
296 //------------------------------------------------------------------------------------------------------------------
297 ::rtl::OUString SAL_CALL UndoManager::getCurrentUndoActionTitle( ) throw (EmptyUndoStackException, RuntimeException)
299 UndoManagerMethodGuard aGuard( *m_pImpl );
300 return m_pImpl->aUndoHelper.getCurrentUndoActionTitle();
303 //------------------------------------------------------------------------------------------------------------------
304 ::rtl::OUString SAL_CALL UndoManager::getCurrentRedoActionTitle( ) throw (EmptyUndoStackException, RuntimeException)
306 UndoManagerMethodGuard aGuard( *m_pImpl );
307 return m_pImpl->aUndoHelper.getCurrentRedoActionTitle();
310 //------------------------------------------------------------------------------------------------------------------
311 Sequence< ::rtl::OUString > SAL_CALL UndoManager::getAllUndoActionTitles( ) throw (RuntimeException)
313 UndoManagerMethodGuard aGuard( *m_pImpl );
314 return m_pImpl->aUndoHelper.getAllUndoActionTitles();
317 //------------------------------------------------------------------------------------------------------------------
318 Sequence< ::rtl::OUString > SAL_CALL UndoManager::getAllRedoActionTitles( ) throw (RuntimeException)
320 UndoManagerMethodGuard aGuard( *m_pImpl );
321 return m_pImpl->aUndoHelper.getAllRedoActionTitles();
324 //------------------------------------------------------------------------------------------------------------------
325 void SAL_CALL UndoManager::clear( ) throw (UndoContextNotClosedException, RuntimeException)
327 UndoManagerMethodGuard aGuard( *m_pImpl );
328 m_pImpl->aUndoHelper.clear( aGuard );
331 //------------------------------------------------------------------------------------------------------------------
332 void SAL_CALL UndoManager::clearRedo( ) throw (UndoContextNotClosedException, RuntimeException)
334 UndoManagerMethodGuard aGuard( *m_pImpl );
335 m_pImpl->aUndoHelper.clearRedo( aGuard );
338 //------------------------------------------------------------------------------------------------------------------
339 void SAL_CALL UndoManager::reset( ) throw (RuntimeException)
341 UndoManagerMethodGuard aGuard( *m_pImpl );
342 m_pImpl->aUndoHelper.reset( aGuard );
345 //------------------------------------------------------------------------------------------------------------------
346 void SAL_CALL UndoManager::addUndoManagerListener( const Reference< XUndoManagerListener >& i_listener ) throw (RuntimeException)
348 UndoManagerMethodGuard aGuard( *m_pImpl );
349 m_pImpl->aUndoHelper.addUndoManagerListener( i_listener );
352 //------------------------------------------------------------------------------------------------------------------
353 void SAL_CALL UndoManager::removeUndoManagerListener( const Reference< XUndoManagerListener >& i_listener ) throw (RuntimeException)
355 UndoManagerMethodGuard aGuard( *m_pImpl );
356 m_pImpl->aUndoHelper.removeUndoManagerListener( i_listener );
359 //------------------------------------------------------------------------------------------------------------------
360 void SAL_CALL UndoManager::lock( ) throw (RuntimeException)
362 UndoManagerMethodGuard aGuard( *m_pImpl );
363 m_pImpl->aUndoHelper.lock();
366 //------------------------------------------------------------------------------------------------------------------
367 void SAL_CALL UndoManager::unlock( ) throw (NotLockedException, RuntimeException)
369 UndoManagerMethodGuard aGuard( *m_pImpl );
370 m_pImpl->aUndoHelper.unlock();
373 //------------------------------------------------------------------------------------------------------------------
374 ::sal_Bool SAL_CALL UndoManager::isLocked( ) throw (RuntimeException)
376 UndoManagerMethodGuard aGuard( *m_pImpl );
377 return m_pImpl->aUndoHelper.isLocked();
380 //------------------------------------------------------------------------------------------------------------------
381 Reference< XInterface > SAL_CALL UndoManager::getParent( ) throw (RuntimeException)
383 UndoManagerMethodGuard aGuard( *m_pImpl );
384 return *&m_pImpl->rParent;
387 //------------------------------------------------------------------------------------------------------------------
388 void SAL_CALL UndoManager::setParent( const Reference< XInterface >& i_parent ) throw (NoSupportException, RuntimeException)
390 (void)i_parent;
391 throw NoSupportException( ::rtl::OUString(), m_pImpl->getThis() );
394 //......................................................................................................................
395 } // namespace dbaui
396 //......................................................................................................................
398 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */