bump product version to 7.2.5.1
[LibreOffice.git] / sfx2 / source / inc / docundomanager.hxx
blob9145e5967d513c265ae4de47d9e788253458ea07
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 #ifndef INCLUDED_SFX2_SOURCE_INC_DOCUNDOMANAGER_HXX
21 #define INCLUDED_SFX2_SOURCE_INC_DOCUNDOMANAGER_HXX
23 #include <sfx2/sfxbasemodel.hxx>
25 #include <com/sun/star/document/XUndoManager.hpp>
27 #include <cppuhelper/implbase.hxx>
28 #include <vcl/svapp.hxx>
30 #include <memory>
32 /** base class for sub components of an SfxBaseModel, which share their ref count and lifetime with the SfxBaseModel
34 class SfxModelSubComponent
36 public:
37 /** checks whether the instance is alive, i.e. properly initialized, and not yet disposed
39 void MethodEntryCheck()
41 m_rModel.MethodEntryCheck( true );
44 protected:
45 SfxModelSubComponent( SfxBaseModel& i_model )
46 :m_rModel( i_model )
49 virtual ~SfxModelSubComponent();
51 void acquireModel() { m_rModel.acquire(); }
52 void releaseModel() { m_rModel.release(); }
54 protected:
55 const SfxBaseModel& getBaseModel() const { return m_rModel; }
56 SfxBaseModel& getBaseModel() { return m_rModel; }
58 private:
59 SfxBaseModel& m_rModel;
62 class SfxModelGuard
64 public:
65 enum AllowedModelState
67 // not yet initialized
68 E_INITIALIZING,
69 // fully alive, i.e. initialized, and not yet disposed
70 E_FULLY_ALIVE
73 SfxModelGuard( SfxBaseModel const & i_rModel, const AllowedModelState i_eState = E_FULLY_ALIVE )
74 : m_aGuard()
76 i_rModel.MethodEntryCheck( i_eState != E_INITIALIZING );
78 SfxModelGuard( SfxModelSubComponent& i_rSubComponent )
79 :m_aGuard()
81 i_rSubComponent.MethodEntryCheck();
84 void clear()
86 m_aGuard.clear();
89 private:
90 SolarMutexClearableGuard m_aGuard;
93 namespace sfx2
95 //= DocumentUndoManager
97 struct DocumentUndoManager_Impl;
98 class DocumentUndoManager :public ::cppu::WeakImplHelper<css::document::XUndoManager>
99 ,public SfxModelSubComponent
101 friend struct DocumentUndoManager_Impl;
103 public:
104 DocumentUndoManager( SfxBaseModel& i_document );
105 virtual ~DocumentUndoManager() override;
106 DocumentUndoManager(const DocumentUndoManager&) = delete;
107 DocumentUndoManager& operator=(const DocumentUndoManager&) = delete;
109 void disposing();
111 // non-UNO API for our owner
112 /** determines whether we have an open Undo context. No mutex locking within this method, no disposal check - this
113 is the responsibility of the owner.
115 bool isInContext() const;
117 // XInterface
118 virtual void SAL_CALL acquire( ) noexcept override;
119 virtual void SAL_CALL release( ) noexcept override;
121 // XUndoManager
122 virtual void SAL_CALL enterUndoContext( const OUString& i_title ) override;
123 virtual void SAL_CALL enterHiddenUndoContext( ) override;
124 virtual void SAL_CALL leaveUndoContext( ) override;
125 virtual void SAL_CALL addUndoAction( const css::uno::Reference< css::document::XUndoAction >& i_action ) override;
126 virtual void SAL_CALL undo( ) override;
127 virtual void SAL_CALL redo( ) override;
128 virtual sal_Bool SAL_CALL isUndoPossible( ) override;
129 virtual sal_Bool SAL_CALL isRedoPossible( ) override;
130 virtual OUString SAL_CALL getCurrentUndoActionTitle( ) override;
131 virtual OUString SAL_CALL getCurrentRedoActionTitle( ) override;
132 virtual css::uno::Sequence< OUString > SAL_CALL getAllUndoActionTitles( ) override;
133 virtual css::uno::Sequence< OUString > SAL_CALL getAllRedoActionTitles( ) override;
134 virtual void SAL_CALL clear( ) override;
135 virtual void SAL_CALL clearRedo( ) override;
136 virtual void SAL_CALL reset( ) override;
137 virtual void SAL_CALL addUndoManagerListener( const css::uno::Reference< css::document::XUndoManagerListener >& i_listener ) override;
138 virtual void SAL_CALL removeUndoManagerListener( const css::uno::Reference< css::document::XUndoManagerListener >& i_listener ) override;
140 // XLockable, base of XUndoManager
141 virtual void SAL_CALL lock( ) override;
142 virtual void SAL_CALL unlock( ) override;
143 virtual sal_Bool SAL_CALL isLocked( ) override;
145 // XChild, base of XUndoManager
146 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent( ) override;
147 virtual void SAL_CALL setParent( const css::uno::Reference< css::uno::XInterface >& Parent ) override;
149 private:
150 std::unique_ptr< DocumentUndoManager_Impl > m_pImpl;
154 } // namespace sfx2
157 #endif // INCLUDED_SFX2_SOURCE_INC_DOCUNDOMANAGER_HXX
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */