1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
32 /** base class for sub components of an SfxBaseModel, which share their ref count and lifetime with the SfxBaseModel
34 class SfxModelSubComponent
37 /** checks whether the instance is alive, i.e. properly initialized, and not yet disposed
39 void MethodEntryCheck()
41 m_rModel
.MethodEntryCheck( true );
45 SfxModelSubComponent( SfxBaseModel
& i_model
)
49 virtual ~SfxModelSubComponent();
51 void acquireModel() { m_rModel
.acquire(); }
52 void releaseModel() { m_rModel
.release(); }
55 const SfxBaseModel
& getBaseModel() const { return m_rModel
; }
56 SfxBaseModel
& getBaseModel() { return m_rModel
; }
59 SfxBaseModel
& m_rModel
;
65 enum AllowedModelState
67 // not yet initialized
69 // fully alive, i.e. initialized, and not yet disposed
73 SfxModelGuard( SfxBaseModel
const & i_rModel
, const AllowedModelState i_eState
= E_FULLY_ALIVE
)
76 i_rModel
.MethodEntryCheck( i_eState
!= E_INITIALIZING
);
78 SfxModelGuard( SfxModelSubComponent
& i_rSubComponent
)
81 i_rSubComponent
.MethodEntryCheck();
90 SolarMutexClearableGuard m_aGuard
;
95 //= DocumentUndoManager
97 struct DocumentUndoManager_Impl
;
98 class DocumentUndoManager
:public ::cppu::WeakImplHelper
<css::document::XUndoManager
>
99 ,public SfxModelSubComponent
101 friend struct DocumentUndoManager_Impl
;
104 DocumentUndoManager( SfxBaseModel
& i_document
);
105 virtual ~DocumentUndoManager() override
;
106 DocumentUndoManager(const DocumentUndoManager
&) = delete;
107 DocumentUndoManager
& operator=(const DocumentUndoManager
&) = delete;
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;
118 virtual void SAL_CALL
acquire( ) noexcept override
;
119 virtual void SAL_CALL
release( ) noexcept override
;
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
;
150 std::unique_ptr
< DocumentUndoManager_Impl
> m_pImpl
;
157 #endif // INCLUDED_SFX2_SOURCE_INC_DOCUNDOMANAGER_HXX
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */