LibreOffice Module chart2 (master) 1
UndoManager.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
20#include "UndoManager.hxx"
21#include <ChartModel.hxx>
22#include <ChartViewHelper.hxx>
23
24#include <com/sun/star/frame/XModel.hpp>
25#include <com/sun/star/lang/DisposedException.hpp>
26#include <com/sun/star/lang/NoSupportException.hpp>
27
29#include <framework/imutex.hxx>
30#include <officecfg/Office/Common.hxx>
31#include <svl/undo.hxx>
32
33namespace chart
34{
35
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::Sequence;
40 using ::com::sun::star::lang::DisposedException;
41 using ::com::sun::star::document::XUndoManager;
42 using ::com::sun::star::document::XUndoAction;
43 using ::com::sun::star::document::XUndoManagerListener;
44 using ::com::sun::star::lang::NoSupportException;
45 using ::com::sun::star::util::XModifyListener;
46 using ::com::sun::star::frame::XModel;
47
48 namespace impl
49 {
51 {
52 public:
53 UndoManager_Impl( UndoManager& i_antiImpl, ::chart::ChartModel& i_parent, ::osl::Mutex& i_mutex )
54 :m_rAntiImpl( i_antiImpl )
55 ,m_rParent( i_parent )
56 ,m_rMutex( i_mutex )
57 ,m_bDisposed( false )
58 ,m_aUndoHelper( *this )
59 {
61 officecfg::Office::Common::Undo::Steps::get());
62 }
63
65 {
66 }
67
68 ::osl::Mutex& getMutex();
69 // IUndoManagerImplementation
70 virtual SfxUndoManager& getImplUndoManager() override;
71 virtual Reference< XUndoManager > getThis() override;
72
73 // attribute access
74 ::chart::ChartModel& getParent() { return m_rParent; }
76
77 // public interface
78
80 void disposing();
81
83 void checkDisposed_lck();
84
85 private:
87 ::chart::ChartModel& m_rParent;
88 ::osl::Mutex& m_rMutex;
90
93 };
94
96 {
97 return m_rMutex;
98 }
99
101 {
102 return m_aUndoManager;
103 }
104
106 {
107 return &m_rAntiImpl;
108 }
109
111 {
112 {
113 ::osl::MutexGuard aGuard( m_rMutex );
114 m_bDisposed = true;
115 }
117 }
118
120 {
121 if ( m_bDisposed )
122 throw DisposedException( OUString(), getThis() );
123 }
124
125 namespace {
126
134 class UndoManagerMethodGuard : public ::framework::IMutexGuard
135 {
136 public:
137 explicit UndoManagerMethodGuard( UndoManager_Impl& i_impl )
138 {
139 ::osl::MutexGuard aGuard( i_impl.getMutex() );
140 // throw if the instance is already disposed
141 i_impl.checkDisposed_lck();
142 }
143 virtual ~UndoManagerMethodGuard()
144 {
145 }
146
147 // IMutexGuard
148 virtual void clear() override;
149 virtual ::framework::IMutex& getGuardedMutex() override;
150 };
151
152 class DummyMutex : public ::framework::IMutex
153 {
154 public:
155 virtual ~DummyMutex() {}
156 virtual void acquire() override { }
157 virtual void release() override { }
158 };
159
160 }
161
162 ::framework::IMutex& UndoManagerMethodGuard::getGuardedMutex()
163 {
164 static DummyMutex s_aDummyMutex;
165 return s_aDummyMutex;
166 }
167
168 void UndoManagerMethodGuard::clear()
169 {
170 // nothing to do. This interface implementation is a dummy.
171 }
172 }
173
174 using impl::UndoManagerMethodGuard;
175
176 UndoManager::UndoManager( ::chart::ChartModel& i_parent, ::osl::Mutex& i_mutex )
177 :m_pImpl( new impl::UndoManager_Impl( *this, i_parent, i_mutex ) )
178 {
179 }
180
182 {
183 }
184
185 void SAL_CALL UndoManager::acquire() noexcept
186 {
187 m_pImpl->getParent().acquire();
188 }
189
190 void SAL_CALL UndoManager::release() noexcept
191 {
192 m_pImpl->getParent().release();
193 }
194
196 {
197 m_pImpl->disposing();
198 }
199
200 void SAL_CALL UndoManager::enterUndoContext( const OUString& i_title )
201 {
202 UndoManagerMethodGuard aGuard( *m_pImpl );
203 m_pImpl->getUndoHelper().enterUndoContext( i_title, aGuard );
204 }
205
207 {
208 UndoManagerMethodGuard aGuard( *m_pImpl );
209 m_pImpl->getUndoHelper().enterHiddenUndoContext( aGuard );
210 }
211
213 {
214 UndoManagerMethodGuard aGuard( *m_pImpl );
215 m_pImpl->getUndoHelper().leaveUndoContext( aGuard );
216 }
217
218 void SAL_CALL UndoManager::addUndoAction( const Reference< XUndoAction >& i_action )
219 {
220 UndoManagerMethodGuard aGuard( *m_pImpl );
221 m_pImpl->getUndoHelper().addUndoAction( i_action, aGuard );
222 }
223
224 void SAL_CALL UndoManager::undo( )
225 {
226 UndoManagerMethodGuard aGuard( *m_pImpl );
227 m_pImpl->getUndoHelper().undo( aGuard );
228
230 }
231
232 void SAL_CALL UndoManager::redo( )
233 {
234 UndoManagerMethodGuard aGuard( *m_pImpl );
235 m_pImpl->getUndoHelper().redo( aGuard );
236
238 }
239
241 {
242 UndoManagerMethodGuard aGuard( *m_pImpl );
243 return m_pImpl->getUndoHelper().isUndoPossible();
244 }
245
247 {
248 UndoManagerMethodGuard aGuard( *m_pImpl );
249 return m_pImpl->getUndoHelper().isRedoPossible();
250 }
251
253 {
254 UndoManagerMethodGuard aGuard( *m_pImpl );
255 return m_pImpl->getUndoHelper().getCurrentUndoActionTitle();
256 }
257
259 {
260 UndoManagerMethodGuard aGuard( *m_pImpl );
261 return m_pImpl->getUndoHelper().getCurrentRedoActionTitle();
262 }
263
265 {
266 UndoManagerMethodGuard aGuard( *m_pImpl );
267 return m_pImpl->getUndoHelper().getAllUndoActionTitles();
268 }
269
271 {
272 UndoManagerMethodGuard aGuard( *m_pImpl );
273 return m_pImpl->getUndoHelper().getAllRedoActionTitles();
274 }
275
276 void SAL_CALL UndoManager::clear( )
277 {
278 UndoManagerMethodGuard aGuard( *m_pImpl );
279 m_pImpl->getUndoHelper().clear( aGuard );
280 }
281
282 void SAL_CALL UndoManager::clearRedo( )
283 {
284 UndoManagerMethodGuard aGuard( *m_pImpl );
285 m_pImpl->getUndoHelper().clearRedo( aGuard );
286 }
287
288 void SAL_CALL UndoManager::reset( )
289 {
290 UndoManagerMethodGuard aGuard( *m_pImpl );
291 m_pImpl->getUndoHelper().reset( aGuard );
292 }
293
295 {
296 UndoManagerMethodGuard aGuard( *m_pImpl );
297 m_pImpl->getUndoHelper().addUndoManagerListener( i_listener );
298 }
299
300 void SAL_CALL UndoManager::removeUndoManagerListener( const Reference< XUndoManagerListener >& i_listener )
301 {
302 UndoManagerMethodGuard aGuard( *m_pImpl );
303 m_pImpl->getUndoHelper().removeUndoManagerListener( i_listener );
304 }
305
306 void SAL_CALL UndoManager::lock( )
307 {
308 UndoManagerMethodGuard aGuard( *m_pImpl );
309 m_pImpl->getUndoHelper().lock();
310 }
311
312 void SAL_CALL UndoManager::unlock( )
313 {
314 UndoManagerMethodGuard aGuard( *m_pImpl );
315 m_pImpl->getUndoHelper().unlock();
316 }
317
319 {
320 UndoManagerMethodGuard aGuard( *m_pImpl );
321 return m_pImpl->getUndoHelper().isLocked();
322 }
323
325 {
326 UndoManagerMethodGuard aGuard( *m_pImpl );
327 return m_pImpl->getParent();
328 }
329
330 void SAL_CALL UndoManager::setParent( const Reference< XInterface >& )
331 {
332 UndoManagerMethodGuard aGuard( *m_pImpl );
333 throw NoSupportException( OUString(), m_pImpl->getThis() );
334 }
335
337 {
338 UndoManagerMethodGuard aGuard( *m_pImpl );
339 m_pImpl->getUndoHelper().addModifyListener( i_listener );
340 }
341
343 {
344 UndoManagerMethodGuard aGuard( *m_pImpl );
345 m_pImpl->getUndoHelper().removeModifyListener( i_listener );
346 }
347
348} // namespace chart
349
350/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
void SetMaxUndoActionCount(size_t nMaxUndoActionCount)
static void setViewToDirtyState(const rtl::Reference<::chart::ChartModel > &xChartModel)
virtual void SAL_CALL redo() override
virtual css::uno::Sequence< OUString > SAL_CALL getAllUndoActionTitles() override
virtual void SAL_CALL release() noexcept override
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
virtual void SAL_CALL lock() override
virtual void SAL_CALL setParent(const css::uno::Reference< css::uno::XInterface > &Parent) override
virtual sal_Bool SAL_CALL isLocked() override
virtual void SAL_CALL unlock() override
virtual sal_Bool SAL_CALL isUndoPossible() override
virtual void SAL_CALL addUndoAction(const css::uno::Reference< css::document::XUndoAction > &i_action) override
virtual sal_Bool SAL_CALL isRedoPossible() override
virtual OUString SAL_CALL getCurrentUndoActionTitle() override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent() override
virtual ~UndoManager()
virtual void SAL_CALL clearRedo() override
virtual void SAL_CALL addUndoManagerListener(const css::uno::Reference< css::document::XUndoManagerListener > &i_listener) override
virtual OUString SAL_CALL getCurrentRedoActionTitle() override
virtual void SAL_CALL enterHiddenUndoContext() override
virtual void SAL_CALL leaveUndoContext() override
virtual void SAL_CALL removeUndoManagerListener(const css::uno::Reference< css::document::XUndoManagerListener > &i_listener) override
virtual void SAL_CALL reset() override
virtual void SAL_CALL acquire() noexcept override
virtual void SAL_CALL enterUndoContext(const OUString &i_title) override
UndoManager(::chart::ChartModel &i_parent, ::osl::Mutex &i_mutex)
virtual void SAL_CALL clear() override
virtual void SAL_CALL undo() override
virtual css::uno::Sequence< OUString > SAL_CALL getAllRedoActionTitles() override
std::unique_ptr< impl::UndoManager_Impl > m_pImpl
Definition: UndoManager.hxx:87
virtual SfxUndoManager & getImplUndoManager() override
virtual Reference< XUndoManager > getThis() override
void disposing()
is called when the owner of the UndoManager is being disposed
void checkDisposed_lck()
checks whether we're already disposed, throws a DisposedException if so
::chart::ChartModel & getParent()
Definition: UndoManager.cxx:74
::chart::ChartModel & m_rParent
Definition: UndoManager.cxx:87
::framework::UndoManagerHelper m_aUndoHelper
Definition: UndoManager.cxx:92
::framework::UndoManagerHelper & getUndoHelper()
Definition: UndoManager.cxx:75
UndoManager_Impl(UndoManager &i_antiImpl, ::chart::ChartModel &i_parent, ::osl::Mutex &i_mutex)
Definition: UndoManager.cxx:53
unsigned char sal_Bool