Branch data 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 "UndoManager.hxx"
22 : : #include "ChartViewHelper.hxx"
23 : :
24 : : #include <com/sun/star/lang/DisposedException.hpp>
25 : :
26 : : #include <framework/undomanagerhelper.hxx>
27 : : #include <officecfg/Office/Common.hxx>
28 : : #include <svl/undo.hxx>
29 : :
30 : : //......................................................................................................................
31 : : namespace chart
32 : : {
33 : : //......................................................................................................................
34 : :
35 : : /** === begin UNO using === **/
36 : : using ::com::sun::star::uno::Reference;
37 : : using ::com::sun::star::uno::XInterface;
38 : : using ::com::sun::star::uno::UNO_QUERY;
39 : : using ::com::sun::star::uno::UNO_QUERY_THROW;
40 : : using ::com::sun::star::uno::UNO_SET_THROW;
41 : : using ::com::sun::star::uno::Exception;
42 : : using ::com::sun::star::uno::RuntimeException;
43 : : using ::com::sun::star::uno::Any;
44 : : using ::com::sun::star::uno::makeAny;
45 : : using ::com::sun::star::uno::Sequence;
46 : : using ::com::sun::star::uno::Type;
47 : : using ::com::sun::star::lang::DisposedException;
48 : : using ::com::sun::star::document::XUndoManager;
49 : : using ::com::sun::star::document::EmptyUndoStackException;
50 : : using ::com::sun::star::document::UndoContextNotClosedException;
51 : : using ::com::sun::star::document::UndoFailedException;
52 : : using ::com::sun::star::util::InvalidStateException;
53 : : using ::com::sun::star::document::XUndoAction;
54 : : using ::com::sun::star::lang::IllegalArgumentException;
55 : : using ::com::sun::star::document::XUndoManagerListener;
56 : : using ::com::sun::star::util::NotLockedException;
57 : : using ::com::sun::star::lang::NoSupportException;
58 : : using ::com::sun::star::util::XModifyListener;
59 : : using ::com::sun::star::frame::XModel;
60 : : /** === end UNO using === **/
61 : :
62 : : namespace impl
63 : : {
64 : : //==============================================================================================================
65 : : //= UndoManager_Impl
66 : : //==============================================================================================================
67 : : class UndoManager_Impl : public ::framework::IUndoManagerImplementation
68 : : {
69 : : public:
70 : 34 : UndoManager_Impl( UndoManager& i_antiImpl, ::cppu::OWeakObject& i_parent, ::osl::Mutex& i_mutex )
71 : : :m_rAntiImpl( i_antiImpl )
72 : : ,m_rParent( i_parent )
73 : : ,m_rMutex( i_mutex )
74 : : ,m_bDisposed( false )
75 : : ,m_aUndoManager()
76 [ + - ][ + - ]: 34 : ,m_aUndoHelper( *this )
77 : : {
78 : : m_aUndoManager.SetMaxUndoActionCount(
79 [ + - ]: 34 : officecfg::Office::Common::Undo::Steps::get());
80 : 34 : }
81 : :
82 : 0 : virtual ~UndoManager_Impl()
83 [ # # ][ # # ]: 0 : {
84 [ # # ]: 0 : }
85 : :
86 : : // .........................................................................................................
87 : : // IUndoManagerImplementation
88 : : virtual ::osl::Mutex& getMutex();
89 : : virtual ::svl::IUndoManager& getImplUndoManager();
90 : : virtual Reference< XUndoManager > getThis();
91 : :
92 : : // .........................................................................................................
93 : : // attribute access
94 : 3266 : ::cppu::OWeakObject& getParent() { return m_rParent; }
95 : 1816 : ::framework::UndoManagerHelper& getUndoHelper() { return m_aUndoHelper; }
96 : :
97 : : // .........................................................................................................
98 : : // public interface
99 : :
100 : : /// is called when the owner of the UndoManager is being disposed
101 : : void disposing();
102 : :
103 : : /// checks whether we're already disposed, throws a DisposedException if so
104 : : void checkDisposed_lck();
105 : :
106 : : private:
107 : : UndoManager& m_rAntiImpl;
108 : : ::cppu::OWeakObject& m_rParent;
109 : : ::osl::Mutex& m_rMutex;
110 : : bool m_bDisposed;
111 : :
112 : : SfxUndoManager m_aUndoManager;
113 : : ::framework::UndoManagerHelper m_aUndoHelper;
114 : : };
115 : :
116 : : //--------------------------------------------------------------------------------------------------------------
117 : 1862 : ::osl::Mutex& UndoManager_Impl::getMutex()
118 : : {
119 : 1862 : return m_rMutex;
120 : : }
121 : :
122 : : //--------------------------------------------------------------------------------------------------------------
123 : 1960 : ::svl::IUndoManager& UndoManager_Impl::getImplUndoManager()
124 : : {
125 : 1960 : return m_aUndoManager;
126 : : }
127 : :
128 : : //--------------------------------------------------------------------------------------------------------------
129 : 652 : Reference< XUndoManager > UndoManager_Impl::getThis()
130 : : {
131 : 652 : return &m_rAntiImpl;
132 : : }
133 : :
134 : : //--------------------------------------------------------------------------------------------------------------
135 : 34 : void UndoManager_Impl::disposing()
136 : : {
137 : : {
138 [ + - ]: 34 : ::osl::MutexGuard aGuard( m_rMutex );
139 [ + - ]: 34 : m_bDisposed = true;
140 : : }
141 : 34 : m_aUndoHelper.disposing();
142 : 34 : }
143 : :
144 : : //--------------------------------------------------------------------------------------------------------------
145 : 1862 : void UndoManager_Impl::checkDisposed_lck()
146 : : {
147 [ - + ]: 1862 : if ( m_bDisposed )
148 [ # # ][ # # ]: 0 : throw DisposedException( ::rtl::OUString(), getThis() );
149 : 1862 : }
150 : :
151 : : //==============================================================================================================
152 : : //= UndoManagerMethodGuard
153 : : //==============================================================================================================
154 : : /** guard for public UNO methods of the UndoManager
155 : :
156 : : The only purpose of this guard is to check for the instance being disposed already. Everything else,
157 : : in particular the IMutexGuard functionality required by the UndoManagerHelper class, is a dummy only,
158 : : as all involved classes (means we ourselves, the UndoManagerHelper, the SfxUndoManager, and the Undo actions
159 : : we create) are inherently thread-safe, thus need no external lock (in particular no SolarMutex!).
160 : : */
161 : : class UndoManagerMethodGuard : public ::framework::IMutexGuard
162 : : {
163 : : public:
164 : 1862 : UndoManagerMethodGuard( UndoManager_Impl& i_impl )
165 : 1862 : {
166 [ + - ][ + - ]: 1862 : ::osl::MutexGuard aGuard( i_impl.getMutex() );
167 : : // throw if the instance is already disposed
168 [ + - ][ + - ]: 1862 : i_impl.checkDisposed_lck();
169 : 1862 : }
170 : 1862 : virtual ~UndoManagerMethodGuard()
171 : 1862 : {
172 [ - + ]: 1862 : }
173 : :
174 : : // IMutexGuard
175 : : virtual ::framework::IMutex& getGuardedMutex();
176 : :
177 : : // IGuard
178 : : virtual void clear();
179 : : virtual void reset();
180 : : };
181 : :
182 : : class DummyMutex : public ::framework::IMutex
183 : : {
184 : : public:
185 [ - + ]: 2 : virtual ~DummyMutex() {}
186 : 60 : virtual void acquire() { }
187 : 60 : virtual void release() { }
188 : : };
189 : :
190 : : //--------------------------------------------------------------------------------------------------------------
191 : 60 : ::framework::IMutex& UndoManagerMethodGuard::getGuardedMutex()
192 : : {
193 [ + + ][ + - ]: 60 : static DummyMutex s_aDummyMutex;
194 : 60 : return s_aDummyMutex;
195 : : }
196 : :
197 : : //--------------------------------------------------------------------------------------------------------------
198 : 276 : void UndoManagerMethodGuard::clear()
199 : : {
200 : : // nothing to do. This interface implementation is a dummy.
201 : 276 : }
202 : :
203 : : //--------------------------------------------------------------------------------------------------------------
204 : 0 : void UndoManagerMethodGuard::reset()
205 : : {
206 : : // nothing to do. This interface implementation is a dummy.
207 : 0 : }
208 : : }
209 : :
210 : : //==================================================================================================================
211 : : //= UndoManager
212 : : //==================================================================================================================
213 : : using impl::UndoManagerMethodGuard;
214 : :
215 : : //------------------------------------------------------------------------------------------------------------------
216 : 34 : UndoManager::UndoManager( ::cppu::OWeakObject& i_parent, ::osl::Mutex& i_mutex )
217 [ + - ][ + - ]: 34 : :m_pImpl( new impl::UndoManager_Impl( *this, i_parent, i_mutex ) )
218 : : {
219 : 34 : }
220 : :
221 : : //------------------------------------------------------------------------------------------------------------------
222 [ # # ]: 0 : UndoManager::~UndoManager()
223 : : {
224 [ # # ]: 0 : }
225 : :
226 : : //------------------------------------------------------------------------------------------------------------------
227 : 1610 : void SAL_CALL UndoManager::acquire() throw ()
228 : : {
229 : 1610 : m_pImpl->getParent().acquire();
230 : 1610 : }
231 : :
232 : : //------------------------------------------------------------------------------------------------------------------
233 : 1610 : void SAL_CALL UndoManager::release() throw ()
234 : : {
235 : 1610 : m_pImpl->getParent().release();
236 : 1610 : }
237 : :
238 : : //------------------------------------------------------------------------------------------------------------------
239 : 34 : void UndoManager::disposing()
240 : : {
241 : 34 : m_pImpl->disposing();
242 : 34 : }
243 : :
244 : : //------------------------------------------------------------------------------------------------------------------
245 : 26 : void SAL_CALL UndoManager::enterUndoContext( const ::rtl::OUString& i_title ) throw (RuntimeException)
246 : : {
247 [ + - ]: 26 : UndoManagerMethodGuard aGuard( *m_pImpl );
248 [ + - ]: 26 : m_pImpl->getUndoHelper().enterUndoContext( i_title, aGuard );
249 : 26 : }
250 : :
251 : : //------------------------------------------------------------------------------------------------------------------
252 : 16 : void SAL_CALL UndoManager::enterHiddenUndoContext( ) throw (EmptyUndoStackException, RuntimeException)
253 : : {
254 [ + - ]: 16 : UndoManagerMethodGuard aGuard( *m_pImpl );
255 [ + + ]: 16 : m_pImpl->getUndoHelper().enterHiddenUndoContext( aGuard );
256 : 12 : }
257 : :
258 : : //------------------------------------------------------------------------------------------------------------------
259 : 34 : void SAL_CALL UndoManager::leaveUndoContext( ) throw (InvalidStateException, RuntimeException)
260 : : {
261 [ + - ]: 34 : UndoManagerMethodGuard aGuard( *m_pImpl );
262 [ + + ]: 34 : m_pImpl->getUndoHelper().leaveUndoContext( aGuard );
263 : 32 : }
264 : :
265 : : //------------------------------------------------------------------------------------------------------------------
266 : 94 : void SAL_CALL UndoManager::addUndoAction( const Reference< XUndoAction >& i_action ) throw (IllegalArgumentException, RuntimeException)
267 : : {
268 [ + - ]: 94 : UndoManagerMethodGuard aGuard( *m_pImpl );
269 [ + + ]: 94 : m_pImpl->getUndoHelper().addUndoAction( i_action, aGuard );
270 : 92 : }
271 : :
272 : : //------------------------------------------------------------------------------------------------------------------
273 : 50 : void SAL_CALL UndoManager::undo( ) throw (EmptyUndoStackException, UndoContextNotClosedException, UndoFailedException, RuntimeException)
274 : : {
275 [ + - ]: 50 : UndoManagerMethodGuard aGuard( *m_pImpl );
276 [ + + ]: 50 : m_pImpl->getUndoHelper().undo( aGuard );
277 : :
278 [ + - ][ + - ]: 50 : ChartViewHelper::setViewToDirtyState( Reference< XModel >( getParent(), UNO_QUERY ) );
[ + - ]
279 : 42 : }
280 : :
281 : : //------------------------------------------------------------------------------------------------------------------
282 : 10 : void SAL_CALL UndoManager::redo( ) throw (EmptyUndoStackException, UndoContextNotClosedException, UndoFailedException, RuntimeException)
283 : : {
284 [ + - ]: 10 : UndoManagerMethodGuard aGuard( *m_pImpl );
285 [ + + ]: 10 : m_pImpl->getUndoHelper().redo( aGuard );
286 : :
287 [ + - ][ + - ]: 10 : ChartViewHelper::setViewToDirtyState( Reference< XModel >( getParent(), UNO_QUERY ) );
[ + - ]
288 : 2 : }
289 : :
290 : : //------------------------------------------------------------------------------------------------------------------
291 : 626 : ::sal_Bool SAL_CALL UndoManager::isUndoPossible( ) throw (RuntimeException)
292 : : {
293 [ + - ]: 626 : UndoManagerMethodGuard aGuard( *m_pImpl );
294 [ + - ]: 626 : return m_pImpl->getUndoHelper().isUndoPossible();
295 : : }
296 : :
297 : : //------------------------------------------------------------------------------------------------------------------
298 : 622 : ::sal_Bool SAL_CALL UndoManager::isRedoPossible( ) throw (RuntimeException)
299 : : {
300 [ + - ]: 622 : UndoManagerMethodGuard aGuard( *m_pImpl );
301 [ + - ]: 622 : return m_pImpl->getUndoHelper().isRedoPossible();
302 : : }
303 : :
304 : : //------------------------------------------------------------------------------------------------------------------
305 : 116 : ::rtl::OUString SAL_CALL UndoManager::getCurrentUndoActionTitle( ) throw (EmptyUndoStackException, RuntimeException)
306 : : {
307 [ + - ]: 116 : UndoManagerMethodGuard aGuard( *m_pImpl );
308 [ + + ]: 116 : return m_pImpl->getUndoHelper().getCurrentUndoActionTitle();
309 : : }
310 : :
311 : : //------------------------------------------------------------------------------------------------------------------
312 : 48 : ::rtl::OUString SAL_CALL UndoManager::getCurrentRedoActionTitle( ) throw (EmptyUndoStackException, RuntimeException)
313 : : {
314 [ + - ]: 48 : UndoManagerMethodGuard aGuard( *m_pImpl );
315 [ + + ]: 48 : return m_pImpl->getUndoHelper().getCurrentRedoActionTitle();
316 : : }
317 : :
318 : : //------------------------------------------------------------------------------------------------------------------
319 : 14 : Sequence< ::rtl::OUString > SAL_CALL UndoManager::getAllUndoActionTitles( ) throw (RuntimeException)
320 : : {
321 [ + - ]: 14 : UndoManagerMethodGuard aGuard( *m_pImpl );
322 [ + - ]: 14 : return m_pImpl->getUndoHelper().getAllUndoActionTitles();
323 : : }
324 : :
325 : : //------------------------------------------------------------------------------------------------------------------
326 : 18 : Sequence< ::rtl::OUString > SAL_CALL UndoManager::getAllRedoActionTitles( ) throw (RuntimeException)
327 : : {
328 [ + - ]: 18 : UndoManagerMethodGuard aGuard( *m_pImpl );
329 [ + - ]: 18 : return m_pImpl->getUndoHelper().getAllRedoActionTitles();
330 : : }
331 : :
332 : : //------------------------------------------------------------------------------------------------------------------
333 : 12 : void SAL_CALL UndoManager::clear( ) throw (UndoContextNotClosedException, RuntimeException)
334 : : {
335 [ + - ]: 12 : UndoManagerMethodGuard aGuard( *m_pImpl );
336 [ + + ]: 12 : m_pImpl->getUndoHelper().clear( aGuard );
337 : 10 : }
338 : :
339 : : //------------------------------------------------------------------------------------------------------------------
340 : 4 : void SAL_CALL UndoManager::clearRedo( ) throw (UndoContextNotClosedException, RuntimeException)
341 : : {
342 [ + - ]: 4 : UndoManagerMethodGuard aGuard( *m_pImpl );
343 [ + + ]: 4 : m_pImpl->getUndoHelper().clearRedo( aGuard );
344 : 2 : }
345 : :
346 : : //------------------------------------------------------------------------------------------------------------------
347 : 32 : void SAL_CALL UndoManager::reset( ) throw (RuntimeException)
348 : : {
349 [ + - ]: 32 : UndoManagerMethodGuard aGuard( *m_pImpl );
350 [ + - ]: 32 : m_pImpl->getUndoHelper().reset( aGuard );
351 : 32 : }
352 : :
353 : : //------------------------------------------------------------------------------------------------------------------
354 : 2 : void SAL_CALL UndoManager::addUndoManagerListener( const Reference< XUndoManagerListener >& i_listener ) throw (RuntimeException)
355 : : {
356 [ + - ]: 2 : UndoManagerMethodGuard aGuard( *m_pImpl );
357 [ + - ]: 2 : m_pImpl->getUndoHelper().addUndoManagerListener( i_listener );
358 : 2 : }
359 : :
360 : : //------------------------------------------------------------------------------------------------------------------
361 : 0 : void SAL_CALL UndoManager::removeUndoManagerListener( const Reference< XUndoManagerListener >& i_listener ) throw (RuntimeException)
362 : : {
363 [ # # ]: 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
364 [ # # ]: 0 : m_pImpl->getUndoHelper().removeUndoManagerListener( i_listener );
365 : 0 : }
366 : :
367 : : //------------------------------------------------------------------------------------------------------------------
368 : 6 : void SAL_CALL UndoManager::lock( ) throw (RuntimeException)
369 : : {
370 [ + - ]: 6 : UndoManagerMethodGuard aGuard( *m_pImpl );
371 [ + - ]: 6 : m_pImpl->getUndoHelper().lock();
372 : 6 : }
373 : :
374 : : //------------------------------------------------------------------------------------------------------------------
375 : 8 : void SAL_CALL UndoManager::unlock( ) throw (NotLockedException, RuntimeException)
376 : : {
377 [ + - ]: 8 : UndoManagerMethodGuard aGuard( *m_pImpl );
378 [ + + ]: 8 : m_pImpl->getUndoHelper().unlock();
379 : 6 : }
380 : :
381 : : //------------------------------------------------------------------------------------------------------------------
382 : 10 : ::sal_Bool SAL_CALL UndoManager::isLocked( ) throw (RuntimeException)
383 : : {
384 [ + - ]: 10 : UndoManagerMethodGuard aGuard( *m_pImpl );
385 [ + - ]: 10 : return m_pImpl->getUndoHelper().isLocked();
386 : : }
387 : :
388 : : //------------------------------------------------------------------------------------------------------------------
389 : 46 : Reference< XInterface > SAL_CALL UndoManager::getParent( ) throw (RuntimeException)
390 : : {
391 [ + - ]: 46 : UndoManagerMethodGuard aGuard( *m_pImpl );
392 [ + - ]: 46 : return *&m_pImpl->getParent();
393 : : }
394 : :
395 : : //------------------------------------------------------------------------------------------------------------------
396 : 0 : void SAL_CALL UndoManager::setParent( const Reference< XInterface >& i_parent ) throw (NoSupportException, RuntimeException)
397 : : {
398 [ # # ]: 0 : UndoManagerMethodGuard aGuard( *m_pImpl );
399 : : (void)i_parent;
400 [ # # ][ # # ]: 0 : throw NoSupportException( ::rtl::OUString(), m_pImpl->getThis() );
401 : : }
402 : :
403 : : //------------------------------------------------------------------------------------------------------------------
404 : 34 : void SAL_CALL UndoManager::addModifyListener( const Reference< XModifyListener >& i_listener ) throw (RuntimeException)
405 : : {
406 [ + - ]: 34 : UndoManagerMethodGuard aGuard( *m_pImpl );
407 [ + - ]: 34 : m_pImpl->getUndoHelper().addModifyListener( i_listener );
408 : 34 : }
409 : :
410 : : //------------------------------------------------------------------------------------------------------------------
411 : 34 : void SAL_CALL UndoManager::removeModifyListener( const Reference< XModifyListener >& i_listener ) throw (RuntimeException)
412 : : {
413 [ + - ]: 34 : UndoManagerMethodGuard aGuard( *m_pImpl );
414 [ + - ]: 34 : m_pImpl->getUndoHelper().removeModifyListener( i_listener );
415 : 34 : }
416 : :
417 : : //......................................................................................................................
418 : : } // namespace chart
419 : : //......................................................................................................................
420 : :
421 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|