Line data Source code
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 :
20 :
21 : #include <dbaccess/dbaundomanager.hxx>
22 :
23 : #include <com/sun/star/lang/DisposedException.hpp>
24 :
25 : #include <svl/undo.hxx>
26 : #include <vcl/svapp.hxx>
27 : #include <framework/undomanagerhelper.hxx>
28 :
29 : //......................................................................................................................
30 : namespace dbaui
31 : {
32 : //......................................................................................................................
33 :
34 : using ::com::sun::star::uno::Reference;
35 : using ::com::sun::star::uno::XInterface;
36 : using ::com::sun::star::uno::UNO_QUERY;
37 : using ::com::sun::star::uno::UNO_QUERY_THROW;
38 : using ::com::sun::star::uno::UNO_SET_THROW;
39 : using ::com::sun::star::uno::Exception;
40 : using ::com::sun::star::uno::RuntimeException;
41 : using ::com::sun::star::uno::Any;
42 : using ::com::sun::star::uno::makeAny;
43 : using ::com::sun::star::uno::Sequence;
44 : using ::com::sun::star::uno::Type;
45 : using ::com::sun::star::document::XUndoManager;
46 : using ::com::sun::star::lang::DisposedException;
47 : using ::com::sun::star::document::UndoContextNotClosedException;
48 : using ::com::sun::star::document::UndoFailedException;
49 : using ::com::sun::star::document::EmptyUndoStackException;
50 : using ::com::sun::star::util::InvalidStateException;
51 : using ::com::sun::star::document::XUndoAction;
52 : using ::com::sun::star::lang::IllegalArgumentException;
53 : using ::com::sun::star::document::XUndoManagerListener;
54 : using ::com::sun::star::util::NotLockedException;
55 : using ::com::sun::star::lang::NoSupportException;
56 :
57 : //==================================================================================================================
58 : //= UndoManager_Impl
59 : //==================================================================================================================
60 : struct UndoManager_Impl : public ::framework::IUndoManagerImplementation
61 : {
62 0 : UndoManager_Impl( UndoManager& i_antiImpl, ::cppu::OWeakObject& i_parent, ::osl::Mutex& i_mutex )
63 : :rAntiImpl( i_antiImpl )
64 : ,rParent( i_parent )
65 : ,rMutex( i_mutex )
66 : ,bDisposed( false )
67 : ,aUndoManager()
68 0 : ,aUndoHelper( *this )
69 : {
70 0 : }
71 :
72 0 : virtual ~UndoManager_Impl()
73 0 : {
74 0 : }
75 :
76 : UndoManager& rAntiImpl;
77 : ::cppu::OWeakObject& rParent;
78 : ::osl::Mutex& rMutex;
79 : bool bDisposed;
80 : SfxUndoManager aUndoManager;
81 : ::framework::UndoManagerHelper aUndoHelper;
82 :
83 : // IUndoManagerImplementation
84 : virtual ::svl::IUndoManager& getImplUndoManager();
85 : virtual Reference< XUndoManager > getThis();
86 : };
87 :
88 : //------------------------------------------------------------------------------------------------------------------
89 0 : ::svl::IUndoManager& UndoManager_Impl::getImplUndoManager()
90 : {
91 0 : return aUndoManager;
92 : }
93 :
94 : //------------------------------------------------------------------------------------------------------------------
95 0 : Reference< XUndoManager > UndoManager_Impl::getThis()
96 : {
97 0 : return static_cast< XUndoManager* >( &rAntiImpl );
98 : }
99 :
100 : //==============================================================================================================
101 : //= OslMutexFacade
102 : //==============================================================================================================
103 : class OslMutexFacade : public ::framework::IMutex
104 : {
105 : public:
106 0 : OslMutexFacade( ::osl::Mutex& i_mutex )
107 0 : :m_rMutex( i_mutex )
108 : {
109 0 : }
110 :
111 0 : virtual ~OslMutexFacade() {}
112 :
113 : virtual void acquire();
114 : virtual void release();
115 :
116 : private:
117 : ::osl::Mutex& m_rMutex;
118 : };
119 :
120 : //--------------------------------------------------------------------------------------------------------------
121 0 : void OslMutexFacade::acquire()
122 : {
123 0 : m_rMutex.acquire();
124 0 : }
125 :
126 : //--------------------------------------------------------------------------------------------------------------
127 0 : void OslMutexFacade::release()
128 : {
129 0 : m_rMutex.release();
130 0 : }
131 :
132 : //==============================================================================================================
133 : //= UndoManagerMethodGuard
134 : //==============================================================================================================
135 : /** guard for public UNO methods of the UndoManager
136 : */
137 : class UndoManagerMethodGuard : public ::framework::IMutexGuard
138 : {
139 : public:
140 0 : UndoManagerMethodGuard( UndoManager_Impl& i_impl )
141 : :m_aGuard( i_impl.rMutex )
142 0 : ,m_aMutexFacade( i_impl.rMutex )
143 : {
144 : // throw if the instance is already disposed
145 0 : if ( i_impl.bDisposed )
146 0 : throw DisposedException( OUString(), i_impl.getThis() );
147 0 : }
148 0 : virtual ~UndoManagerMethodGuard()
149 0 : {
150 0 : }
151 :
152 : // IMutexGuard
153 : virtual ::framework::IMutex& getGuardedMutex();
154 :
155 : // IGuard
156 : virtual void clear();
157 : virtual void reset();
158 :
159 : private:
160 : ::osl::ResettableMutexGuard m_aGuard;
161 : OslMutexFacade m_aMutexFacade;
162 : };
163 :
164 : //--------------------------------------------------------------------------------------------------------------
165 0 : ::framework::IMutex& UndoManagerMethodGuard::getGuardedMutex()
166 : {
167 0 : return m_aMutexFacade;
168 : }
169 :
170 : //--------------------------------------------------------------------------------------------------------------
171 0 : void UndoManagerMethodGuard::clear()
172 : {
173 0 : m_aGuard.clear();
174 0 : }
175 :
176 : //--------------------------------------------------------------------------------------------------------------
177 0 : void UndoManagerMethodGuard::reset()
178 : {
179 0 : m_aGuard.reset();
180 0 : }
181 :
182 : //==================================================================================================================
183 : //= UndoManager
184 : //==================================================================================================================
185 : //------------------------------------------------------------------------------------------------------------------
186 0 : UndoManager::UndoManager( ::cppu::OWeakObject& i_parent, ::osl::Mutex& i_mutex )
187 0 : :m_pImpl( new UndoManager_Impl( *this, i_parent, i_mutex ) )
188 : {
189 0 : }
190 :
191 : //------------------------------------------------------------------------------------------------------------------
192 0 : UndoManager::~UndoManager()
193 : {
194 0 : }
195 :
196 : //------------------------------------------------------------------------------------------------------------------
197 0 : SfxUndoManager& UndoManager::GetSfxUndoManager() const
198 : {
199 0 : return m_pImpl->aUndoManager;
200 : }
201 :
202 : //------------------------------------------------------------------------------------------------------------------
203 0 : void SAL_CALL UndoManager::acquire( ) throw ()
204 : {
205 0 : m_pImpl->rParent.acquire();
206 0 : }
207 :
208 : //------------------------------------------------------------------------------------------------------------------
209 0 : void SAL_CALL UndoManager::release( ) throw ()
210 : {
211 0 : m_pImpl->rParent.release();
212 0 : }
213 :
214 : //------------------------------------------------------------------------------------------------------------------
215 0 : void UndoManager::disposing()
216 : {
217 : {
218 0 : ::osl::MutexGuard aGuard( m_pImpl->rMutex );
219 0 : m_pImpl->bDisposed = true;
220 : }
221 0 : m_pImpl->aUndoHelper.disposing();
222 0 : }
223 :
224 : //------------------------------------------------------------------------------------------------------------------
225 0 : void SAL_CALL UndoManager::enterUndoContext( const OUString& i_title ) throw (RuntimeException)
226 : {
227 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
228 0 : m_pImpl->aUndoHelper.enterUndoContext( i_title, aGuard );
229 0 : }
230 :
231 : //------------------------------------------------------------------------------------------------------------------
232 0 : void SAL_CALL UndoManager::enterHiddenUndoContext( ) throw (EmptyUndoStackException, RuntimeException)
233 : {
234 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
235 0 : m_pImpl->aUndoHelper.enterHiddenUndoContext( aGuard );
236 0 : }
237 :
238 : //------------------------------------------------------------------------------------------------------------------
239 0 : void SAL_CALL UndoManager::leaveUndoContext( ) throw (InvalidStateException, RuntimeException)
240 : {
241 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
242 0 : m_pImpl->aUndoHelper.leaveUndoContext( aGuard );
243 0 : }
244 :
245 : //------------------------------------------------------------------------------------------------------------------
246 0 : void SAL_CALL UndoManager::addUndoAction( const Reference< XUndoAction >& i_action ) throw (IllegalArgumentException, RuntimeException)
247 : {
248 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
249 0 : m_pImpl->aUndoHelper.addUndoAction( i_action, aGuard );
250 0 : }
251 :
252 : //------------------------------------------------------------------------------------------------------------------
253 0 : void SAL_CALL UndoManager::undo( ) throw (EmptyUndoStackException, UndoContextNotClosedException, UndoFailedException, RuntimeException)
254 : {
255 0 : SolarMutexGuard aSolarGuard;
256 : // (all our UndoActions work directly on VCL code, usually, so ...)
257 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
258 0 : m_pImpl->aUndoHelper.undo( aGuard );
259 0 : }
260 :
261 : //------------------------------------------------------------------------------------------------------------------
262 0 : void SAL_CALL UndoManager::redo( ) throw (EmptyUndoStackException, UndoContextNotClosedException, UndoFailedException, RuntimeException)
263 : {
264 0 : SolarMutexGuard aSolarGuard;
265 : // (all our UndoActions work directly on VCL code, usually, so ...)
266 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
267 0 : m_pImpl->aUndoHelper.redo( aGuard );
268 0 : }
269 :
270 : //------------------------------------------------------------------------------------------------------------------
271 0 : ::sal_Bool SAL_CALL UndoManager::isUndoPossible( ) throw (RuntimeException)
272 : {
273 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
274 0 : return m_pImpl->aUndoHelper.isUndoPossible();
275 : }
276 :
277 : //------------------------------------------------------------------------------------------------------------------
278 0 : ::sal_Bool SAL_CALL UndoManager::isRedoPossible( ) throw (RuntimeException)
279 : {
280 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
281 0 : return m_pImpl->aUndoHelper.isRedoPossible();
282 : }
283 :
284 : //------------------------------------------------------------------------------------------------------------------
285 0 : OUString SAL_CALL UndoManager::getCurrentUndoActionTitle( ) throw (EmptyUndoStackException, RuntimeException)
286 : {
287 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
288 0 : return m_pImpl->aUndoHelper.getCurrentUndoActionTitle();
289 : }
290 :
291 : //------------------------------------------------------------------------------------------------------------------
292 0 : OUString SAL_CALL UndoManager::getCurrentRedoActionTitle( ) throw (EmptyUndoStackException, RuntimeException)
293 : {
294 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
295 0 : return m_pImpl->aUndoHelper.getCurrentRedoActionTitle();
296 : }
297 :
298 : //------------------------------------------------------------------------------------------------------------------
299 0 : Sequence< OUString > SAL_CALL UndoManager::getAllUndoActionTitles( ) throw (RuntimeException)
300 : {
301 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
302 0 : return m_pImpl->aUndoHelper.getAllUndoActionTitles();
303 : }
304 :
305 : //------------------------------------------------------------------------------------------------------------------
306 0 : Sequence< OUString > SAL_CALL UndoManager::getAllRedoActionTitles( ) throw (RuntimeException)
307 : {
308 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
309 0 : return m_pImpl->aUndoHelper.getAllRedoActionTitles();
310 : }
311 :
312 : //------------------------------------------------------------------------------------------------------------------
313 0 : void SAL_CALL UndoManager::clear( ) throw (UndoContextNotClosedException, RuntimeException)
314 : {
315 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
316 0 : m_pImpl->aUndoHelper.clear( aGuard );
317 0 : }
318 :
319 : //------------------------------------------------------------------------------------------------------------------
320 0 : void SAL_CALL UndoManager::clearRedo( ) throw (UndoContextNotClosedException, RuntimeException)
321 : {
322 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
323 0 : m_pImpl->aUndoHelper.clearRedo( aGuard );
324 0 : }
325 :
326 : //------------------------------------------------------------------------------------------------------------------
327 0 : void SAL_CALL UndoManager::reset( ) throw (RuntimeException)
328 : {
329 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
330 0 : m_pImpl->aUndoHelper.reset( aGuard );
331 0 : }
332 :
333 : //------------------------------------------------------------------------------------------------------------------
334 0 : void SAL_CALL UndoManager::addUndoManagerListener( const Reference< XUndoManagerListener >& i_listener ) throw (RuntimeException)
335 : {
336 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
337 0 : m_pImpl->aUndoHelper.addUndoManagerListener( i_listener );
338 0 : }
339 :
340 : //------------------------------------------------------------------------------------------------------------------
341 0 : void SAL_CALL UndoManager::removeUndoManagerListener( const Reference< XUndoManagerListener >& i_listener ) throw (RuntimeException)
342 : {
343 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
344 0 : m_pImpl->aUndoHelper.removeUndoManagerListener( i_listener );
345 0 : }
346 :
347 : //------------------------------------------------------------------------------------------------------------------
348 0 : void SAL_CALL UndoManager::lock( ) throw (RuntimeException)
349 : {
350 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
351 0 : m_pImpl->aUndoHelper.lock();
352 0 : }
353 :
354 : //------------------------------------------------------------------------------------------------------------------
355 0 : void SAL_CALL UndoManager::unlock( ) throw (NotLockedException, RuntimeException)
356 : {
357 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
358 0 : m_pImpl->aUndoHelper.unlock();
359 0 : }
360 :
361 : //------------------------------------------------------------------------------------------------------------------
362 0 : ::sal_Bool SAL_CALL UndoManager::isLocked( ) throw (RuntimeException)
363 : {
364 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
365 0 : return m_pImpl->aUndoHelper.isLocked();
366 : }
367 :
368 : //------------------------------------------------------------------------------------------------------------------
369 0 : Reference< XInterface > SAL_CALL UndoManager::getParent( ) throw (RuntimeException)
370 : {
371 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
372 0 : return *&m_pImpl->rParent;
373 : }
374 :
375 : //------------------------------------------------------------------------------------------------------------------
376 0 : void SAL_CALL UndoManager::setParent( const Reference< XInterface >& i_parent ) throw (NoSupportException, RuntimeException)
377 : {
378 : (void)i_parent;
379 0 : throw NoSupportException( OUString(), m_pImpl->getThis() );
380 : }
381 :
382 : //......................................................................................................................
383 12 : } // namespace dbaui
384 : //......................................................................................................................
385 :
386 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|