1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <dbaccess/dbaundomanager.hxx>
22 #include <com/sun/star/lang/DisposedException.hpp>
24 #include <svl/undo.hxx>
25 #include <vcl/svapp.hxx>
26 #include <framework/undomanagerhelper.hxx>
31 using ::com::sun::star::uno::Reference
;
32 using ::com::sun::star::uno::XInterface
;
33 using ::com::sun::star::uno::UNO_QUERY
;
34 using ::com::sun::star::uno::UNO_QUERY_THROW
;
35 using ::com::sun::star::uno::UNO_SET_THROW
;
36 using ::com::sun::star::uno::Exception
;
37 using ::com::sun::star::uno::RuntimeException
;
38 using ::com::sun::star::uno::Any
;
39 using ::com::sun::star::uno::makeAny
;
40 using ::com::sun::star::uno::Sequence
;
41 using ::com::sun::star::uno::Type
;
42 using ::com::sun::star::document::XUndoManager
;
43 using ::com::sun::star::lang::DisposedException
;
44 using ::com::sun::star::document::UndoContextNotClosedException
;
45 using ::com::sun::star::document::UndoFailedException
;
46 using ::com::sun::star::document::EmptyUndoStackException
;
47 using ::com::sun::star::util::InvalidStateException
;
48 using ::com::sun::star::document::XUndoAction
;
49 using ::com::sun::star::lang::IllegalArgumentException
;
50 using ::com::sun::star::document::XUndoManagerListener
;
51 using ::com::sun::star::util::NotLockedException
;
52 using ::com::sun::star::lang::NoSupportException
;
55 struct UndoManager_Impl
: public ::framework::IUndoManagerImplementation
57 UndoManager_Impl( UndoManager
& i_antiImpl
, ::cppu::OWeakObject
& i_parent
, ::osl::Mutex
& i_mutex
)
58 :rAntiImpl( i_antiImpl
)
67 virtual ~UndoManager_Impl()
71 UndoManager
& rAntiImpl
;
72 ::cppu::OWeakObject
& rParent
;
75 SfxUndoManager aUndoManager
;
76 ::framework::UndoManagerHelper aUndoHelper
;
78 // IUndoManagerImplementation
79 virtual ::svl::IUndoManager
& getImplUndoManager() SAL_OVERRIDE
;
80 virtual Reference
< XUndoManager
> getThis() SAL_OVERRIDE
;
83 ::svl::IUndoManager
& UndoManager_Impl::getImplUndoManager()
88 Reference
< XUndoManager
> UndoManager_Impl::getThis()
90 return static_cast< XUndoManager
* >( &rAntiImpl
);
94 class OslMutexFacade
: public ::framework::IMutex
97 OslMutexFacade( ::osl::Mutex
& i_mutex
)
102 virtual ~OslMutexFacade() {}
104 virtual void acquire() SAL_OVERRIDE
;
105 virtual void release() SAL_OVERRIDE
;
108 ::osl::Mutex
& m_rMutex
;
111 void OslMutexFacade::acquire()
116 void OslMutexFacade::release()
121 // UndoManagerMethodGuard
122 /** guard for public UNO methods of the UndoManager
124 class UndoManagerMethodGuard
: public ::framework::IMutexGuard
127 UndoManagerMethodGuard( UndoManager_Impl
& i_impl
)
128 :m_aGuard( i_impl
.rMutex
)
129 ,m_aMutexFacade( i_impl
.rMutex
)
131 // throw if the instance is already disposed
132 if ( i_impl
.bDisposed
)
133 throw DisposedException( OUString(), i_impl
.getThis() );
135 virtual ~UndoManagerMethodGuard()
140 virtual void clear() SAL_OVERRIDE
;
141 virtual ::framework::IMutex
& getGuardedMutex() SAL_OVERRIDE
;
144 ::osl::ResettableMutexGuard m_aGuard
;
145 OslMutexFacade m_aMutexFacade
;
148 ::framework::IMutex
& UndoManagerMethodGuard::getGuardedMutex()
150 return m_aMutexFacade
;
153 void UndoManagerMethodGuard::clear()
159 UndoManager::UndoManager( ::cppu::OWeakObject
& i_parent
, ::osl::Mutex
& i_mutex
)
160 :m_xImpl( new UndoManager_Impl( *this, i_parent
, i_mutex
) )
164 UndoManager::~UndoManager()
168 SfxUndoManager
& UndoManager::GetSfxUndoManager() const
170 return m_xImpl
->aUndoManager
;
173 void SAL_CALL
UndoManager::acquire( ) throw ()
175 m_xImpl
->rParent
.acquire();
178 void SAL_CALL
UndoManager::release( ) throw ()
180 m_xImpl
->rParent
.release();
183 void UndoManager::disposing()
186 ::osl::MutexGuard
aGuard( m_xImpl
->rMutex
);
187 m_xImpl
->bDisposed
= true;
189 m_xImpl
->aUndoHelper
.disposing();
192 void SAL_CALL
UndoManager::enterUndoContext( const OUString
& i_title
) throw (RuntimeException
, std::exception
)
194 UndoManagerMethodGuard
aGuard( *m_xImpl
);
195 m_xImpl
->aUndoHelper
.enterUndoContext( i_title
, aGuard
);
198 void SAL_CALL
UndoManager::enterHiddenUndoContext( ) throw (EmptyUndoStackException
, RuntimeException
, std::exception
)
200 UndoManagerMethodGuard
aGuard( *m_xImpl
);
201 m_xImpl
->aUndoHelper
.enterHiddenUndoContext( aGuard
);
204 void SAL_CALL
UndoManager::leaveUndoContext( ) throw (InvalidStateException
, RuntimeException
, std::exception
)
206 UndoManagerMethodGuard
aGuard( *m_xImpl
);
207 m_xImpl
->aUndoHelper
.leaveUndoContext( aGuard
);
210 void SAL_CALL
UndoManager::addUndoAction( const Reference
< XUndoAction
>& i_action
) throw (IllegalArgumentException
, RuntimeException
, std::exception
)
212 UndoManagerMethodGuard
aGuard( *m_xImpl
);
213 m_xImpl
->aUndoHelper
.addUndoAction( i_action
, aGuard
);
216 void SAL_CALL
UndoManager::undo( ) throw (EmptyUndoStackException
, UndoContextNotClosedException
, UndoFailedException
, RuntimeException
, std::exception
)
218 SolarMutexGuard aSolarGuard
;
219 // (all our UndoActions work directly on VCL code, usually, so ...)
220 UndoManagerMethodGuard
aGuard( *m_xImpl
);
221 m_xImpl
->aUndoHelper
.undo( aGuard
);
224 void SAL_CALL
UndoManager::redo( ) throw (EmptyUndoStackException
, UndoContextNotClosedException
, UndoFailedException
, RuntimeException
, std::exception
)
226 SolarMutexGuard aSolarGuard
;
227 // (all our UndoActions work directly on VCL code, usually, so ...)
228 UndoManagerMethodGuard
aGuard( *m_xImpl
);
229 m_xImpl
->aUndoHelper
.redo( aGuard
);
232 sal_Bool SAL_CALL
UndoManager::isUndoPossible( ) throw (RuntimeException
, std::exception
)
234 UndoManagerMethodGuard
aGuard( *m_xImpl
);
235 return m_xImpl
->aUndoHelper
.isUndoPossible();
238 sal_Bool SAL_CALL
UndoManager::isRedoPossible( ) throw (RuntimeException
, std::exception
)
240 UndoManagerMethodGuard
aGuard( *m_xImpl
);
241 return m_xImpl
->aUndoHelper
.isRedoPossible();
244 OUString SAL_CALL
UndoManager::getCurrentUndoActionTitle( ) throw (EmptyUndoStackException
, RuntimeException
, std::exception
)
246 UndoManagerMethodGuard
aGuard( *m_xImpl
);
247 return m_xImpl
->aUndoHelper
.getCurrentUndoActionTitle();
250 OUString SAL_CALL
UndoManager::getCurrentRedoActionTitle( ) throw (EmptyUndoStackException
, RuntimeException
, std::exception
)
252 UndoManagerMethodGuard
aGuard( *m_xImpl
);
253 return m_xImpl
->aUndoHelper
.getCurrentRedoActionTitle();
256 Sequence
< OUString
> SAL_CALL
UndoManager::getAllUndoActionTitles( ) throw (RuntimeException
, std::exception
)
258 UndoManagerMethodGuard
aGuard( *m_xImpl
);
259 return m_xImpl
->aUndoHelper
.getAllUndoActionTitles();
262 Sequence
< OUString
> SAL_CALL
UndoManager::getAllRedoActionTitles( ) throw (RuntimeException
, std::exception
)
264 UndoManagerMethodGuard
aGuard( *m_xImpl
);
265 return m_xImpl
->aUndoHelper
.getAllRedoActionTitles();
268 void SAL_CALL
UndoManager::clear( ) throw (UndoContextNotClosedException
, RuntimeException
, std::exception
)
270 UndoManagerMethodGuard
aGuard( *m_xImpl
);
271 m_xImpl
->aUndoHelper
.clear( aGuard
);
274 void SAL_CALL
UndoManager::clearRedo( ) throw (UndoContextNotClosedException
, RuntimeException
, std::exception
)
276 UndoManagerMethodGuard
aGuard( *m_xImpl
);
277 m_xImpl
->aUndoHelper
.clearRedo( aGuard
);
280 void SAL_CALL
UndoManager::reset( ) throw (RuntimeException
, std::exception
)
282 UndoManagerMethodGuard
aGuard( *m_xImpl
);
283 m_xImpl
->aUndoHelper
.reset( aGuard
);
286 void SAL_CALL
UndoManager::addUndoManagerListener( const Reference
< XUndoManagerListener
>& i_listener
) throw (RuntimeException
, std::exception
)
288 UndoManagerMethodGuard
aGuard( *m_xImpl
);
289 m_xImpl
->aUndoHelper
.addUndoManagerListener( i_listener
);
292 void SAL_CALL
UndoManager::removeUndoManagerListener( const Reference
< XUndoManagerListener
>& i_listener
) throw (RuntimeException
, std::exception
)
294 UndoManagerMethodGuard
aGuard( *m_xImpl
);
295 m_xImpl
->aUndoHelper
.removeUndoManagerListener( i_listener
);
298 void SAL_CALL
UndoManager::lock( ) throw (RuntimeException
, std::exception
)
300 UndoManagerMethodGuard
aGuard( *m_xImpl
);
301 m_xImpl
->aUndoHelper
.lock();
304 void SAL_CALL
UndoManager::unlock( ) throw (NotLockedException
, RuntimeException
, std::exception
)
306 UndoManagerMethodGuard
aGuard( *m_xImpl
);
307 m_xImpl
->aUndoHelper
.unlock();
310 sal_Bool SAL_CALL
UndoManager::isLocked( ) throw (RuntimeException
, std::exception
)
312 UndoManagerMethodGuard
aGuard( *m_xImpl
);
313 return m_xImpl
->aUndoHelper
.isLocked();
316 Reference
< XInterface
> SAL_CALL
UndoManager::getParent( ) throw (RuntimeException
, std::exception
)
318 UndoManagerMethodGuard
aGuard( *m_xImpl
);
319 return *&m_xImpl
->rParent
;
322 void SAL_CALL
UndoManager::setParent( const Reference
< XInterface
>& i_parent
) throw (NoSupportException
, RuntimeException
, std::exception
)
325 throw NoSupportException( OUString(), m_xImpl
->getThis() );
330 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */