nss: upgrade to release 3.73
[LibreOffice.git] / chart2 / source / model / main / UndoManager.cxx
blobf295bc288eb2aaf59b5997c52fcd28975cbe085b
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 "UndoManager.hxx"
21 #include <ChartViewHelper.hxx>
23 #include <com/sun/star/frame/XModel.hpp>
24 #include <com/sun/star/lang/DisposedException.hpp>
25 #include <com/sun/star/lang/NoSupportException.hpp>
27 #include <framework/undomanagerhelper.hxx>
28 #include <framework/imutex.hxx>
29 #include <officecfg/Office/Common.hxx>
30 #include <svl/undo.hxx>
32 namespace chart
35 using ::com::sun::star::uno::Reference;
36 using ::com::sun::star::uno::XInterface;
37 using ::com::sun::star::uno::UNO_QUERY;
38 using ::com::sun::star::uno::Sequence;
39 using ::com::sun::star::lang::DisposedException;
40 using ::com::sun::star::document::XUndoManager;
41 using ::com::sun::star::document::XUndoAction;
42 using ::com::sun::star::document::XUndoManagerListener;
43 using ::com::sun::star::lang::NoSupportException;
44 using ::com::sun::star::util::XModifyListener;
45 using ::com::sun::star::frame::XModel;
47 namespace impl
49 class UndoManager_Impl : public ::framework::IUndoManagerImplementation
51 public:
52 UndoManager_Impl( UndoManager& i_antiImpl, ::cppu::OWeakObject& i_parent, ::osl::Mutex& i_mutex )
53 :m_rAntiImpl( i_antiImpl )
54 ,m_rParent( i_parent )
55 ,m_rMutex( i_mutex )
56 ,m_bDisposed( false )
57 ,m_aUndoManager()
58 ,m_aUndoHelper( *this )
60 m_aUndoManager.SetMaxUndoActionCount(
61 officecfg::Office::Common::Undo::Steps::get());
64 virtual ~UndoManager_Impl()
68 ::osl::Mutex& getMutex();
69 // IUndoManagerImplementation
70 virtual SfxUndoManager& getImplUndoManager() override;
71 virtual Reference< XUndoManager > getThis() override;
73 // attribute access
74 ::cppu::OWeakObject& getParent() { return m_rParent; }
75 ::framework::UndoManagerHelper& getUndoHelper() { return m_aUndoHelper; }
77 // public interface
79 /// is called when the owner of the UndoManager is being disposed
80 void disposing();
82 /// checks whether we're already disposed, throws a DisposedException if so
83 void checkDisposed_lck();
85 private:
86 UndoManager& m_rAntiImpl;
87 ::cppu::OWeakObject& m_rParent;
88 ::osl::Mutex& m_rMutex;
89 bool m_bDisposed;
91 SfxUndoManager m_aUndoManager;
92 ::framework::UndoManagerHelper m_aUndoHelper;
95 ::osl::Mutex& UndoManager_Impl::getMutex()
97 return m_rMutex;
100 SfxUndoManager& UndoManager_Impl::getImplUndoManager()
102 return m_aUndoManager;
105 Reference< XUndoManager > UndoManager_Impl::getThis()
107 return &m_rAntiImpl;
110 void UndoManager_Impl::disposing()
113 ::osl::MutexGuard aGuard( m_rMutex );
114 m_bDisposed = true;
116 m_aUndoHelper.disposing();
119 void UndoManager_Impl::checkDisposed_lck()
121 if ( m_bDisposed )
122 throw DisposedException( OUString(), getThis() );
125 namespace {
127 /** guard for public UNO methods of the UndoManager
129 The only purpose of this guard is to check for the instance being disposed already. Everything else,
130 in particular the IMutexGuard functionality required by the UndoManagerHelper class, is a dummy only,
131 as all involved classes (means we ourselves, the UndoManagerHelper, the SfxUndoManager, and the Undo actions
132 we create) are inherently thread-safe, thus need no external lock (in particular no SolarMutex!).
134 class UndoManagerMethodGuard : public ::framework::IMutexGuard
136 public:
137 explicit UndoManagerMethodGuard( UndoManager_Impl& i_impl )
139 ::osl::MutexGuard aGuard( i_impl.getMutex() );
140 // throw if the instance is already disposed
141 i_impl.checkDisposed_lck();
143 virtual ~UndoManagerMethodGuard()
147 // IMutexGuard
148 virtual void clear() override;
149 virtual ::framework::IMutex& getGuardedMutex() override;
152 class DummyMutex : public ::framework::IMutex
154 public:
155 virtual ~DummyMutex() {}
156 virtual void acquire() override { }
157 virtual void release() override { }
162 ::framework::IMutex& UndoManagerMethodGuard::getGuardedMutex()
164 static DummyMutex s_aDummyMutex;
165 return s_aDummyMutex;
168 void UndoManagerMethodGuard::clear()
170 // nothing to do. This interface implementation is a dummy.
174 using impl::UndoManagerMethodGuard;
176 UndoManager::UndoManager( ::cppu::OWeakObject& i_parent, ::osl::Mutex& i_mutex )
177 :m_pImpl( new impl::UndoManager_Impl( *this, i_parent, i_mutex ) )
181 UndoManager::~UndoManager()
185 void SAL_CALL UndoManager::acquire() throw ()
187 m_pImpl->getParent().acquire();
190 void SAL_CALL UndoManager::release() throw ()
192 m_pImpl->getParent().release();
195 void UndoManager::disposing()
197 m_pImpl->disposing();
200 void SAL_CALL UndoManager::enterUndoContext( const OUString& i_title )
202 UndoManagerMethodGuard aGuard( *m_pImpl );
203 m_pImpl->getUndoHelper().enterUndoContext( i_title, aGuard );
206 void SAL_CALL UndoManager::enterHiddenUndoContext( )
208 UndoManagerMethodGuard aGuard( *m_pImpl );
209 m_pImpl->getUndoHelper().enterHiddenUndoContext( aGuard );
212 void SAL_CALL UndoManager::leaveUndoContext( )
214 UndoManagerMethodGuard aGuard( *m_pImpl );
215 m_pImpl->getUndoHelper().leaveUndoContext( aGuard );
218 void SAL_CALL UndoManager::addUndoAction( const Reference< XUndoAction >& i_action )
220 UndoManagerMethodGuard aGuard( *m_pImpl );
221 m_pImpl->getUndoHelper().addUndoAction( i_action, aGuard );
224 void SAL_CALL UndoManager::undo( )
226 UndoManagerMethodGuard aGuard( *m_pImpl );
227 m_pImpl->getUndoHelper().undo( aGuard );
229 ChartViewHelper::setViewToDirtyState( Reference< XModel >( getParent(), UNO_QUERY ) );
232 void SAL_CALL UndoManager::redo( )
234 UndoManagerMethodGuard aGuard( *m_pImpl );
235 m_pImpl->getUndoHelper().redo( aGuard );
237 ChartViewHelper::setViewToDirtyState( Reference< XModel >( getParent(), UNO_QUERY ) );
240 sal_Bool SAL_CALL UndoManager::isUndoPossible( )
242 UndoManagerMethodGuard aGuard( *m_pImpl );
243 return m_pImpl->getUndoHelper().isUndoPossible();
246 sal_Bool SAL_CALL UndoManager::isRedoPossible( )
248 UndoManagerMethodGuard aGuard( *m_pImpl );
249 return m_pImpl->getUndoHelper().isRedoPossible();
252 OUString SAL_CALL UndoManager::getCurrentUndoActionTitle( )
254 UndoManagerMethodGuard aGuard( *m_pImpl );
255 return m_pImpl->getUndoHelper().getCurrentUndoActionTitle();
258 OUString SAL_CALL UndoManager::getCurrentRedoActionTitle( )
260 UndoManagerMethodGuard aGuard( *m_pImpl );
261 return m_pImpl->getUndoHelper().getCurrentRedoActionTitle();
264 Sequence< OUString > SAL_CALL UndoManager::getAllUndoActionTitles( )
266 UndoManagerMethodGuard aGuard( *m_pImpl );
267 return m_pImpl->getUndoHelper().getAllUndoActionTitles();
270 Sequence< OUString > SAL_CALL UndoManager::getAllRedoActionTitles( )
272 UndoManagerMethodGuard aGuard( *m_pImpl );
273 return m_pImpl->getUndoHelper().getAllRedoActionTitles();
276 void SAL_CALL UndoManager::clear( )
278 UndoManagerMethodGuard aGuard( *m_pImpl );
279 m_pImpl->getUndoHelper().clear( aGuard );
282 void SAL_CALL UndoManager::clearRedo( )
284 UndoManagerMethodGuard aGuard( *m_pImpl );
285 m_pImpl->getUndoHelper().clearRedo( aGuard );
288 void SAL_CALL UndoManager::reset( )
290 UndoManagerMethodGuard aGuard( *m_pImpl );
291 m_pImpl->getUndoHelper().reset( aGuard );
294 void SAL_CALL UndoManager::addUndoManagerListener( const Reference< XUndoManagerListener >& i_listener )
296 UndoManagerMethodGuard aGuard( *m_pImpl );
297 m_pImpl->getUndoHelper().addUndoManagerListener( i_listener );
300 void SAL_CALL UndoManager::removeUndoManagerListener( const Reference< XUndoManagerListener >& i_listener )
302 UndoManagerMethodGuard aGuard( *m_pImpl );
303 m_pImpl->getUndoHelper().removeUndoManagerListener( i_listener );
306 void SAL_CALL UndoManager::lock( )
308 UndoManagerMethodGuard aGuard( *m_pImpl );
309 m_pImpl->getUndoHelper().lock();
312 void SAL_CALL UndoManager::unlock( )
314 UndoManagerMethodGuard aGuard( *m_pImpl );
315 m_pImpl->getUndoHelper().unlock();
318 sal_Bool SAL_CALL UndoManager::isLocked( )
320 UndoManagerMethodGuard aGuard( *m_pImpl );
321 return m_pImpl->getUndoHelper().isLocked();
324 Reference< XInterface > SAL_CALL UndoManager::getParent( )
326 UndoManagerMethodGuard aGuard( *m_pImpl );
327 return m_pImpl->getParent();
330 void SAL_CALL UndoManager::setParent( const Reference< XInterface >& )
332 UndoManagerMethodGuard aGuard( *m_pImpl );
333 throw NoSupportException( OUString(), m_pImpl->getThis() );
336 void SAL_CALL UndoManager::addModifyListener( const Reference< XModifyListener >& i_listener )
338 UndoManagerMethodGuard aGuard( *m_pImpl );
339 m_pImpl->getUndoHelper().addModifyListener( i_listener );
342 void SAL_CALL UndoManager::removeModifyListener( const Reference< XModifyListener >& i_listener )
344 UndoManagerMethodGuard aGuard( *m_pImpl );
345 m_pImpl->getUndoHelper().removeModifyListener( i_listener );
348 } // namespace chart
350 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */