nss: upgrade to release 3.73
[LibreOffice.git] / dbaccess / source / ui / misc / dbaundomanager.cxx
blobd8659ce6157df12795fcb64865c9db8954cee54a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
23 #include <com/sun/star/lang/NoSupportException.hpp>
25 #include <svl/undo.hxx>
26 #include <vcl/svapp.hxx>
27 #include <framework/undomanagerhelper.hxx>
28 #include <framework/imutex.hxx>
30 namespace dbaui
33 using ::com::sun::star::uno::Reference;
34 using ::com::sun::star::uno::XInterface;
35 using ::com::sun::star::uno::Sequence;
36 using ::com::sun::star::document::XUndoManager;
37 using ::com::sun::star::lang::DisposedException;
38 using ::com::sun::star::document::XUndoAction;
39 using ::com::sun::star::document::XUndoManagerListener;
40 using ::com::sun::star::lang::NoSupportException;
42 // UndoManager_Impl
43 struct UndoManager_Impl : public ::framework::IUndoManagerImplementation
45 UndoManager_Impl( UndoManager& i_antiImpl, ::cppu::OWeakObject& i_parent, ::osl::Mutex& i_mutex )
46 :rAntiImpl( i_antiImpl )
47 ,rParent( i_parent )
48 ,rMutex( i_mutex )
49 ,bDisposed( false )
50 ,aUndoManager()
51 ,aUndoHelper( *this )
55 virtual ~UndoManager_Impl()
59 UndoManager& rAntiImpl;
60 ::cppu::OWeakObject& rParent;
61 ::osl::Mutex& rMutex;
62 bool bDisposed;
63 SfxUndoManager aUndoManager;
64 ::framework::UndoManagerHelper aUndoHelper;
66 // IUndoManagerImplementation
67 virtual SfxUndoManager& getImplUndoManager() override;
68 virtual Reference< XUndoManager > getThis() override;
71 SfxUndoManager& UndoManager_Impl::getImplUndoManager()
73 return aUndoManager;
76 Reference< XUndoManager > UndoManager_Impl::getThis()
78 return static_cast< XUndoManager* >( &rAntiImpl );
81 namespace {
83 // OslMutexFacade
84 class OslMutexFacade : public ::framework::IMutex
86 public:
87 explicit OslMutexFacade( ::osl::Mutex& i_mutex )
88 :m_rMutex( i_mutex )
92 virtual ~OslMutexFacade() {}
94 virtual void acquire() override;
95 virtual void release() override;
97 private:
98 ::osl::Mutex& m_rMutex;
103 void OslMutexFacade::acquire()
105 m_rMutex.acquire();
108 void OslMutexFacade::release()
110 m_rMutex.release();
113 namespace {
115 // UndoManagerMethodGuard
116 /** guard for public UNO methods of the UndoManager
118 class UndoManagerMethodGuard : public ::framework::IMutexGuard
120 public:
121 explicit UndoManagerMethodGuard( UndoManager_Impl& i_impl )
122 :m_aGuard( i_impl.rMutex )
123 ,m_aMutexFacade( i_impl.rMutex )
125 // throw if the instance is already disposed
126 if ( i_impl.bDisposed )
127 throw DisposedException( OUString(), i_impl.getThis() );
129 virtual ~UndoManagerMethodGuard()
133 // IMutexGuard
134 virtual void clear() override;
135 virtual ::framework::IMutex& getGuardedMutex() override;
137 private:
138 osl::ClearableMutexGuard m_aGuard;
139 OslMutexFacade m_aMutexFacade;
144 ::framework::IMutex& UndoManagerMethodGuard::getGuardedMutex()
146 return m_aMutexFacade;
149 void UndoManagerMethodGuard::clear()
151 m_aGuard.clear();
154 // UndoManager
155 UndoManager::UndoManager( ::cppu::OWeakObject& i_parent, ::osl::Mutex& i_mutex )
156 :m_xImpl( new UndoManager_Impl( *this, i_parent, i_mutex ) )
160 UndoManager::~UndoManager()
164 SfxUndoManager& UndoManager::GetSfxUndoManager() const
166 return m_xImpl->aUndoManager;
169 void SAL_CALL UndoManager::acquire( ) throw ()
171 m_xImpl->rParent.acquire();
174 void SAL_CALL UndoManager::release( ) throw ()
176 m_xImpl->rParent.release();
179 void UndoManager::disposing()
182 ::osl::MutexGuard aGuard( m_xImpl->rMutex );
183 m_xImpl->bDisposed = true;
185 m_xImpl->aUndoHelper.disposing();
188 void SAL_CALL UndoManager::enterUndoContext( const OUString& i_title )
190 UndoManagerMethodGuard aGuard( *m_xImpl );
191 m_xImpl->aUndoHelper.enterUndoContext( i_title, aGuard );
194 void SAL_CALL UndoManager::enterHiddenUndoContext( )
196 UndoManagerMethodGuard aGuard( *m_xImpl );
197 m_xImpl->aUndoHelper.enterHiddenUndoContext( aGuard );
200 void SAL_CALL UndoManager::leaveUndoContext( )
202 UndoManagerMethodGuard aGuard( *m_xImpl );
203 m_xImpl->aUndoHelper.leaveUndoContext( aGuard );
206 void SAL_CALL UndoManager::addUndoAction( const Reference< XUndoAction >& i_action )
208 UndoManagerMethodGuard aGuard( *m_xImpl );
209 m_xImpl->aUndoHelper.addUndoAction( i_action, aGuard );
212 void SAL_CALL UndoManager::undo( )
214 SolarMutexGuard aSolarGuard;
215 // (all our UndoActions work directly on VCL code, usually, so ...)
216 UndoManagerMethodGuard aGuard( *m_xImpl );
217 m_xImpl->aUndoHelper.undo( aGuard );
220 void SAL_CALL UndoManager::redo( )
222 SolarMutexGuard aSolarGuard;
223 // (all our UndoActions work directly on VCL code, usually, so ...)
224 UndoManagerMethodGuard aGuard( *m_xImpl );
225 m_xImpl->aUndoHelper.redo( aGuard );
228 sal_Bool SAL_CALL UndoManager::isUndoPossible( )
230 UndoManagerMethodGuard aGuard( *m_xImpl );
231 return m_xImpl->aUndoHelper.isUndoPossible();
234 sal_Bool SAL_CALL UndoManager::isRedoPossible( )
236 UndoManagerMethodGuard aGuard( *m_xImpl );
237 return m_xImpl->aUndoHelper.isRedoPossible();
240 OUString SAL_CALL UndoManager::getCurrentUndoActionTitle( )
242 UndoManagerMethodGuard aGuard( *m_xImpl );
243 return m_xImpl->aUndoHelper.getCurrentUndoActionTitle();
246 OUString SAL_CALL UndoManager::getCurrentRedoActionTitle( )
248 UndoManagerMethodGuard aGuard( *m_xImpl );
249 return m_xImpl->aUndoHelper.getCurrentRedoActionTitle();
252 Sequence< OUString > SAL_CALL UndoManager::getAllUndoActionTitles( )
254 UndoManagerMethodGuard aGuard( *m_xImpl );
255 return m_xImpl->aUndoHelper.getAllUndoActionTitles();
258 Sequence< OUString > SAL_CALL UndoManager::getAllRedoActionTitles( )
260 UndoManagerMethodGuard aGuard( *m_xImpl );
261 return m_xImpl->aUndoHelper.getAllRedoActionTitles();
264 void SAL_CALL UndoManager::clear( )
266 UndoManagerMethodGuard aGuard( *m_xImpl );
267 m_xImpl->aUndoHelper.clear( aGuard );
270 void SAL_CALL UndoManager::clearRedo( )
272 UndoManagerMethodGuard aGuard( *m_xImpl );
273 m_xImpl->aUndoHelper.clearRedo( aGuard );
276 void SAL_CALL UndoManager::reset( )
278 UndoManagerMethodGuard aGuard( *m_xImpl );
279 m_xImpl->aUndoHelper.reset( aGuard );
282 void SAL_CALL UndoManager::addUndoManagerListener( const Reference< XUndoManagerListener >& i_listener )
284 UndoManagerMethodGuard aGuard( *m_xImpl );
285 m_xImpl->aUndoHelper.addUndoManagerListener( i_listener );
288 void SAL_CALL UndoManager::removeUndoManagerListener( const Reference< XUndoManagerListener >& i_listener )
290 UndoManagerMethodGuard aGuard( *m_xImpl );
291 m_xImpl->aUndoHelper.removeUndoManagerListener( i_listener );
294 void SAL_CALL UndoManager::lock( )
296 UndoManagerMethodGuard aGuard( *m_xImpl );
297 m_xImpl->aUndoHelper.lock();
300 void SAL_CALL UndoManager::unlock( )
302 UndoManagerMethodGuard aGuard( *m_xImpl );
303 m_xImpl->aUndoHelper.unlock();
306 sal_Bool SAL_CALL UndoManager::isLocked( )
308 UndoManagerMethodGuard aGuard( *m_xImpl );
309 return m_xImpl->aUndoHelper.isLocked();
312 Reference< XInterface > SAL_CALL UndoManager::getParent( )
314 UndoManagerMethodGuard aGuard( *m_xImpl );
315 return m_xImpl->rParent;
318 void SAL_CALL UndoManager::setParent( const Reference< XInterface >& )
320 throw NoSupportException( OUString(), m_xImpl->getThis() );
323 } // namespace dbaui
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */