LibreOffice Module dbaccess (master) 1
dbaundomanager.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21
22#include <com/sun/star/lang/DisposedException.hpp>
23#include <com/sun/star/lang/NoSupportException.hpp>
24
25#include <svl/undo.hxx>
26#include <vcl/svapp.hxx>
28#include <framework/imutex.hxx>
29
30namespace dbaui
31{
32
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;
41
42 // UndoManager_Impl
44 {
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 ,aUndoHelper( *this )
51 {
52 }
53
55 {
56 }
57
60 ::osl::Mutex& rMutex;
64
65 // IUndoManagerImplementation
66 virtual SfxUndoManager& getImplUndoManager() override;
67 virtual Reference< XUndoManager > getThis() override;
68 };
69
71 {
72 return aUndoManager;
73 }
74
76 {
77 return static_cast< XUndoManager* >( &rAntiImpl );
78 }
79
80 namespace {
81
82 // OslMutexFacade
83 class OslMutexFacade : public ::framework::IMutex
84 {
85 public:
86 explicit OslMutexFacade( ::osl::Mutex& i_mutex )
87 :m_rMutex( i_mutex )
88 {
89 }
90
91 virtual ~OslMutexFacade() {}
92
93 virtual void acquire() override;
94 virtual void release() override;
95
96 private:
97 ::osl::Mutex& m_rMutex;
98 };
99
100 }
101
102 void OslMutexFacade::acquire()
103 {
104 m_rMutex.acquire();
105 }
106
107 void OslMutexFacade::release()
108 {
109 m_rMutex.release();
110 }
111
112 namespace {
113
114 // UndoManagerMethodGuard
117 class UndoManagerMethodGuard : public ::framework::IMutexGuard
118 {
119 public:
120 explicit UndoManagerMethodGuard( UndoManager_Impl& i_impl )
121 :m_aGuard( i_impl.rMutex )
122 ,m_aMutexFacade( i_impl.rMutex )
123 {
124 // throw if the instance is already disposed
125 if ( i_impl.bDisposed )
126 throw DisposedException( OUString(), i_impl.getThis() );
127 }
128 virtual ~UndoManagerMethodGuard()
129 {
130 }
131
132 // IMutexGuard
133 virtual void clear() override;
134 virtual ::framework::IMutex& getGuardedMutex() override;
135
136 private:
137 osl::ClearableMutexGuard m_aGuard;
138 OslMutexFacade m_aMutexFacade;
139 };
140
141 }
142
143 ::framework::IMutex& UndoManagerMethodGuard::getGuardedMutex()
144 {
145 return m_aMutexFacade;
146 }
147
148 void UndoManagerMethodGuard::clear()
149 {
150 m_aGuard.clear();
151 }
152
153 // UndoManager
154 UndoManager::UndoManager( ::cppu::OWeakObject& i_parent, ::osl::Mutex& i_mutex )
155 :m_xImpl( new UndoManager_Impl( *this, i_parent, i_mutex ) )
156 {
157 }
158
160 {
161 }
162
164 {
165 return m_xImpl->aUndoManager;
166 }
167
168 void SAL_CALL UndoManager::acquire( ) noexcept
169 {
170 m_xImpl->rParent.acquire();
171 }
172
173 void SAL_CALL UndoManager::release( ) noexcept
174 {
175 m_xImpl->rParent.release();
176 }
177
179 {
180 {
181 ::osl::MutexGuard aGuard( m_xImpl->rMutex );
182 m_xImpl->bDisposed = true;
183 }
184 m_xImpl->aUndoHelper.disposing();
185 }
186
187 void SAL_CALL UndoManager::enterUndoContext( const OUString& i_title )
188 {
189 UndoManagerMethodGuard aGuard( *m_xImpl );
190 m_xImpl->aUndoHelper.enterUndoContext( i_title, aGuard );
191 }
192
194 {
195 UndoManagerMethodGuard aGuard( *m_xImpl );
196 m_xImpl->aUndoHelper.enterHiddenUndoContext( aGuard );
197 }
198
200 {
201 UndoManagerMethodGuard aGuard( *m_xImpl );
202 m_xImpl->aUndoHelper.leaveUndoContext( aGuard );
203 }
204
205 void SAL_CALL UndoManager::addUndoAction( const Reference< XUndoAction >& i_action )
206 {
207 UndoManagerMethodGuard aGuard( *m_xImpl );
208 m_xImpl->aUndoHelper.addUndoAction( i_action, aGuard );
209 }
210
211 void SAL_CALL UndoManager::undo( )
212 {
213 SolarMutexGuard aSolarGuard;
214 // (all our UndoActions work directly on VCL code, usually, so ...)
215 UndoManagerMethodGuard aGuard( *m_xImpl );
216 m_xImpl->aUndoHelper.undo( aGuard );
217 }
218
219 void SAL_CALL UndoManager::redo( )
220 {
221 SolarMutexGuard aSolarGuard;
222 // (all our UndoActions work directly on VCL code, usually, so ...)
223 UndoManagerMethodGuard aGuard( *m_xImpl );
224 m_xImpl->aUndoHelper.redo( aGuard );
225 }
226
228 {
229 UndoManagerMethodGuard aGuard( *m_xImpl );
230 return m_xImpl->aUndoHelper.isUndoPossible();
231 }
232
234 {
235 UndoManagerMethodGuard aGuard( *m_xImpl );
236 return m_xImpl->aUndoHelper.isRedoPossible();
237 }
238
240 {
241 UndoManagerMethodGuard aGuard( *m_xImpl );
242 return m_xImpl->aUndoHelper.getCurrentUndoActionTitle();
243 }
244
246 {
247 UndoManagerMethodGuard aGuard( *m_xImpl );
248 return m_xImpl->aUndoHelper.getCurrentRedoActionTitle();
249 }
250
252 {
253 UndoManagerMethodGuard aGuard( *m_xImpl );
254 return m_xImpl->aUndoHelper.getAllUndoActionTitles();
255 }
256
258 {
259 UndoManagerMethodGuard aGuard( *m_xImpl );
260 return m_xImpl->aUndoHelper.getAllRedoActionTitles();
261 }
262
263 void SAL_CALL UndoManager::clear( )
264 {
265 UndoManagerMethodGuard aGuard( *m_xImpl );
266 m_xImpl->aUndoHelper.clear( aGuard );
267 }
268
269 void SAL_CALL UndoManager::clearRedo( )
270 {
271 UndoManagerMethodGuard aGuard( *m_xImpl );
272 m_xImpl->aUndoHelper.clearRedo( aGuard );
273 }
274
275 void SAL_CALL UndoManager::reset( )
276 {
277 UndoManagerMethodGuard aGuard( *m_xImpl );
278 m_xImpl->aUndoHelper.reset( aGuard );
279 }
280
282 {
283 UndoManagerMethodGuard aGuard( *m_xImpl );
284 m_xImpl->aUndoHelper.addUndoManagerListener( i_listener );
285 }
286
287 void SAL_CALL UndoManager::removeUndoManagerListener( const Reference< XUndoManagerListener >& i_listener )
288 {
289 UndoManagerMethodGuard aGuard( *m_xImpl );
290 m_xImpl->aUndoHelper.removeUndoManagerListener( i_listener );
291 }
292
293 void SAL_CALL UndoManager::lock( )
294 {
295 UndoManagerMethodGuard aGuard( *m_xImpl );
296 m_xImpl->aUndoHelper.lock();
297 }
298
299 void SAL_CALL UndoManager::unlock( )
300 {
301 UndoManagerMethodGuard aGuard( *m_xImpl );
302 m_xImpl->aUndoHelper.unlock();
303 }
304
306 {
307 UndoManagerMethodGuard aGuard( *m_xImpl );
308 return m_xImpl->aUndoHelper.isLocked();
309 }
310
312 {
313 UndoManagerMethodGuard aGuard( *m_xImpl );
314 return m_xImpl->rParent;
315 }
316
317 void SAL_CALL UndoManager::setParent( const Reference< XInterface >& )
318 {
319 throw NoSupportException( OUString(), m_xImpl->getThis() );
320 }
321
322} // namespace dbaui
323
324/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL addUndoManagerListener(const css::uno::Reference< css::document::XUndoManagerListener > &i_listener) override
virtual void SAL_CALL redo() override
virtual void SAL_CALL enterUndoContext(const OUString &i_title) override
virtual void SAL_CALL setParent(const css::uno::Reference< css::uno::XInterface > &Parent) override
virtual css::uno::Sequence< OUString > SAL_CALL getAllUndoActionTitles() override
SfxUndoManager & GetSfxUndoManager() const
virtual void SAL_CALL addUndoAction(const css::uno::Reference< css::document::XUndoAction > &i_action) override
virtual void SAL_CALL clear() override
virtual void SAL_CALL removeUndoManagerListener(const css::uno::Reference< css::document::XUndoManagerListener > &i_listener) override
virtual void SAL_CALL lock() override
virtual void SAL_CALL leaveUndoContext() override
virtual sal_Bool SAL_CALL isRedoPossible() override
virtual css::uno::Sequence< OUString > SAL_CALL getAllRedoActionTitles() override
virtual OUString SAL_CALL getCurrentUndoActionTitle() override
virtual void SAL_CALL reset() override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent() override
virtual void SAL_CALL enterHiddenUndoContext() override
UndoManager(::cppu::OWeakObject &i_parent, ::osl::Mutex &i_mutex)
virtual void SAL_CALL acquire() noexcept override
virtual void SAL_CALL undo() override
virtual sal_Bool SAL_CALL isLocked() override
virtual sal_Bool SAL_CALL isUndoPossible() override
virtual void SAL_CALL clearRedo() override
virtual void SAL_CALL release() noexcept override
virtual void SAL_CALL unlock() override
virtual OUString SAL_CALL getCurrentRedoActionTitle() override
std::unique_ptr< UndoManager_Impl > m_xImpl
::osl::Mutex & m_rMutex
OslMutexFacade m_aMutexFacade
osl::ClearableMutexGuard m_aGuard
::framework::UndoManagerHelper aUndoHelper
SfxUndoManager aUndoManager
::cppu::OWeakObject & rParent
virtual Reference< XUndoManager > getThis() override
UndoManager_Impl(UndoManager &i_antiImpl, ::cppu::OWeakObject &i_parent, ::osl::Mutex &i_mutex)
virtual SfxUndoManager & getImplUndoManager() override
unsigned char sal_Bool