Bump version to 6.4-15
[LibreOffice.git] / chart2 / source / model / main / UndoManager.cxx
blob023ab553b3452e292a5a8a06346d09ff6bdf5388
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 /** guard for public UNO methods of the UndoManager
127 The only purpose of this guard is to check for the instance being disposed already. Everything else,
128 in particular the IMutexGuard functionality required by the UndoManagerHelper class, is a dummy only,
129 as all involved classes (means we ourselves, the UndoManagerHelper, the SfxUndoManager, and the Undo actions
130 we create) are inherently thread-safe, thus need no external lock (in particular no SolarMutex!).
132 class UndoManagerMethodGuard : public ::framework::IMutexGuard
134 public:
135 explicit UndoManagerMethodGuard( UndoManager_Impl& i_impl )
137 ::osl::MutexGuard aGuard( i_impl.getMutex() );
138 // throw if the instance is already disposed
139 i_impl.checkDisposed_lck();
141 virtual ~UndoManagerMethodGuard()
145 // IMutexGuard
146 virtual void clear() override;
147 virtual ::framework::IMutex& getGuardedMutex() override;
150 class DummyMutex : public ::framework::IMutex
152 public:
153 virtual ~DummyMutex() {}
154 virtual void acquire() override { }
155 virtual void release() override { }
158 ::framework::IMutex& UndoManagerMethodGuard::getGuardedMutex()
160 static DummyMutex s_aDummyMutex;
161 return s_aDummyMutex;
164 void UndoManagerMethodGuard::clear()
166 // nothing to do. This interface implementation is a dummy.
170 using impl::UndoManagerMethodGuard;
172 UndoManager::UndoManager( ::cppu::OWeakObject& i_parent, ::osl::Mutex& i_mutex )
173 :m_pImpl( new impl::UndoManager_Impl( *this, i_parent, i_mutex ) )
177 UndoManager::~UndoManager()
181 void SAL_CALL UndoManager::acquire() throw ()
183 m_pImpl->getParent().acquire();
186 void SAL_CALL UndoManager::release() throw ()
188 m_pImpl->getParent().release();
191 void UndoManager::disposing()
193 m_pImpl->disposing();
196 void SAL_CALL UndoManager::enterUndoContext( const OUString& i_title )
198 UndoManagerMethodGuard aGuard( *m_pImpl );
199 m_pImpl->getUndoHelper().enterUndoContext( i_title, aGuard );
202 void SAL_CALL UndoManager::enterHiddenUndoContext( )
204 UndoManagerMethodGuard aGuard( *m_pImpl );
205 m_pImpl->getUndoHelper().enterHiddenUndoContext( aGuard );
208 void SAL_CALL UndoManager::leaveUndoContext( )
210 UndoManagerMethodGuard aGuard( *m_pImpl );
211 m_pImpl->getUndoHelper().leaveUndoContext( aGuard );
214 void SAL_CALL UndoManager::addUndoAction( const Reference< XUndoAction >& i_action )
216 UndoManagerMethodGuard aGuard( *m_pImpl );
217 m_pImpl->getUndoHelper().addUndoAction( i_action, aGuard );
220 void SAL_CALL UndoManager::undo( )
222 UndoManagerMethodGuard aGuard( *m_pImpl );
223 m_pImpl->getUndoHelper().undo( aGuard );
225 ChartViewHelper::setViewToDirtyState( Reference< XModel >( getParent(), UNO_QUERY ) );
228 void SAL_CALL UndoManager::redo( )
230 UndoManagerMethodGuard aGuard( *m_pImpl );
231 m_pImpl->getUndoHelper().redo( aGuard );
233 ChartViewHelper::setViewToDirtyState( Reference< XModel >( getParent(), UNO_QUERY ) );
236 sal_Bool SAL_CALL UndoManager::isUndoPossible( )
238 UndoManagerMethodGuard aGuard( *m_pImpl );
239 return m_pImpl->getUndoHelper().isUndoPossible();
242 sal_Bool SAL_CALL UndoManager::isRedoPossible( )
244 UndoManagerMethodGuard aGuard( *m_pImpl );
245 return m_pImpl->getUndoHelper().isRedoPossible();
248 OUString SAL_CALL UndoManager::getCurrentUndoActionTitle( )
250 UndoManagerMethodGuard aGuard( *m_pImpl );
251 return m_pImpl->getUndoHelper().getCurrentUndoActionTitle();
254 OUString SAL_CALL UndoManager::getCurrentRedoActionTitle( )
256 UndoManagerMethodGuard aGuard( *m_pImpl );
257 return m_pImpl->getUndoHelper().getCurrentRedoActionTitle();
260 Sequence< OUString > SAL_CALL UndoManager::getAllUndoActionTitles( )
262 UndoManagerMethodGuard aGuard( *m_pImpl );
263 return m_pImpl->getUndoHelper().getAllUndoActionTitles();
266 Sequence< OUString > SAL_CALL UndoManager::getAllRedoActionTitles( )
268 UndoManagerMethodGuard aGuard( *m_pImpl );
269 return m_pImpl->getUndoHelper().getAllRedoActionTitles();
272 void SAL_CALL UndoManager::clear( )
274 UndoManagerMethodGuard aGuard( *m_pImpl );
275 m_pImpl->getUndoHelper().clear( aGuard );
278 void SAL_CALL UndoManager::clearRedo( )
280 UndoManagerMethodGuard aGuard( *m_pImpl );
281 m_pImpl->getUndoHelper().clearRedo( aGuard );
284 void SAL_CALL UndoManager::reset( )
286 UndoManagerMethodGuard aGuard( *m_pImpl );
287 m_pImpl->getUndoHelper().reset( aGuard );
290 void SAL_CALL UndoManager::addUndoManagerListener( const Reference< XUndoManagerListener >& i_listener )
292 UndoManagerMethodGuard aGuard( *m_pImpl );
293 m_pImpl->getUndoHelper().addUndoManagerListener( i_listener );
296 void SAL_CALL UndoManager::removeUndoManagerListener( const Reference< XUndoManagerListener >& i_listener )
298 UndoManagerMethodGuard aGuard( *m_pImpl );
299 m_pImpl->getUndoHelper().removeUndoManagerListener( i_listener );
302 void SAL_CALL UndoManager::lock( )
304 UndoManagerMethodGuard aGuard( *m_pImpl );
305 m_pImpl->getUndoHelper().lock();
308 void SAL_CALL UndoManager::unlock( )
310 UndoManagerMethodGuard aGuard( *m_pImpl );
311 m_pImpl->getUndoHelper().unlock();
314 sal_Bool SAL_CALL UndoManager::isLocked( )
316 UndoManagerMethodGuard aGuard( *m_pImpl );
317 return m_pImpl->getUndoHelper().isLocked();
320 Reference< XInterface > SAL_CALL UndoManager::getParent( )
322 UndoManagerMethodGuard aGuard( *m_pImpl );
323 return m_pImpl->getParent();
326 void SAL_CALL UndoManager::setParent( const Reference< XInterface >& )
328 UndoManagerMethodGuard aGuard( *m_pImpl );
329 throw NoSupportException( OUString(), m_pImpl->getThis() );
332 void SAL_CALL UndoManager::addModifyListener( const Reference< XModifyListener >& i_listener )
334 UndoManagerMethodGuard aGuard( *m_pImpl );
335 m_pImpl->getUndoHelper().addModifyListener( i_listener );
338 void SAL_CALL UndoManager::removeModifyListener( const Reference< XModifyListener >& i_listener )
340 UndoManagerMethodGuard aGuard( *m_pImpl );
341 m_pImpl->getUndoHelper().removeModifyListener( i_listener );
344 } // namespace chart
346 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */