/src/libreoffice/svx/source/inc/fmundo.hxx
Line | Count | Source (jump to first uncovered line) |
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 | | #ifndef INCLUDED_SVX_SOURCE_INC_FMUNDO_HXX |
21 | | #define INCLUDED_SVX_SOURCE_INC_FMUNDO_HXX |
22 | | |
23 | | #include <svx/svdundo.hxx> |
24 | | #include <svx/svdouno.hxx> |
25 | | #include "fmscriptingenv.hxx" |
26 | | |
27 | | #include <com/sun/star/util/XModifyListener.hpp> |
28 | | #include <com/sun/star/beans/XPropertySet.hpp> |
29 | | #include <com/sun/star/beans/XPropertyChangeListener.hpp> |
30 | | #include <com/sun/star/beans/PropertyChangeEvent.hpp> |
31 | | #include <com/sun/star/script/ScriptEventDescriptor.hpp> |
32 | | #include <com/sun/star/container/XIndexContainer.hpp> |
33 | | #include <com/sun/star/container/XContainerListener.hpp> |
34 | | #include <com/sun/star/container/ContainerEvent.hpp> |
35 | | #include <com/sun/star/container/XNameContainer.hpp> |
36 | | #include <cppuhelper/implbase.hxx> |
37 | | |
38 | | |
39 | | #include <svl/lstner.hxx> |
40 | | #include <memory> |
41 | | #include <map> |
42 | | |
43 | | class FmFormModel; |
44 | | class FmFormObj; |
45 | | class SdrObject; |
46 | | struct PropertySetInfo; |
47 | | class ScriptEventListenerWrapper; |
48 | | |
49 | | class FmUndoPropertyAction final : public SdrUndoAction |
50 | | { |
51 | | css::uno::Reference< css::beans::XPropertySet> xObj; |
52 | | OUString aPropertyName; |
53 | | css::uno::Any aNewValue; |
54 | | css::uno::Any aOldValue; |
55 | | |
56 | | public: |
57 | | FmUndoPropertyAction(FmFormModel& rMod, const css::beans::PropertyChangeEvent& evt); |
58 | | |
59 | | virtual void Undo() override; |
60 | | virtual void Redo() override; |
61 | | |
62 | | virtual OUString GetComment() const override; |
63 | | |
64 | | }; |
65 | | |
66 | | class FmUndoContainerAction final : public SdrUndoAction |
67 | | { |
68 | | public: |
69 | | enum Action |
70 | | { |
71 | | Inserted = 1, |
72 | | Removed = 2 |
73 | | }; |
74 | | |
75 | | FmUndoContainerAction(FmFormModel& rMod, |
76 | | Action _eAction, |
77 | | const css::uno::Reference< css::container::XIndexContainer >& xCont, |
78 | | const css::uno::Reference< css::uno::XInterface >& xElem, |
79 | | sal_Int32 nIdx); |
80 | | virtual ~FmUndoContainerAction() override; |
81 | | |
82 | | virtual void Undo() override; |
83 | | virtual void Redo() override; |
84 | | |
85 | | static void DisposeElement( const css::uno::Reference< css::uno::XInterface >& xElem ); |
86 | | |
87 | | private: |
88 | | void implReInsert( ); |
89 | | void implReRemove( ); |
90 | | |
91 | | css::uno::Reference< css::container::XIndexContainer > |
92 | | m_xContainer; // container which the action applies to |
93 | | css::uno::Reference< css::uno::XInterface > |
94 | | m_xElement; // object not owned by the action |
95 | | css::uno::Reference< css::uno::XInterface > |
96 | | m_xOwnElement; // object owned by the action |
97 | | sal_Int32 m_nIndex; // index of the object within its container |
98 | | css::uno::Sequence< css::script::ScriptEventDescriptor > |
99 | | m_aEvents; // events of the object |
100 | | Action m_eAction; |
101 | | }; |
102 | | |
103 | | class FmUndoModelReplaceAction final : public SdrUndoAction |
104 | | { |
105 | | css::uno::Reference< css::awt::XControlModel> m_xReplaced; |
106 | | SdrUnoObj* m_pObject; |
107 | | |
108 | | public: |
109 | | FmUndoModelReplaceAction(FmFormModel& rMod, SdrUnoObj* pObject, const css::uno::Reference< css::awt::XControlModel>& xReplaced); |
110 | | virtual ~FmUndoModelReplaceAction() override; |
111 | | |
112 | | virtual void Undo() override; |
113 | 0 | virtual void Redo() override { Undo(); } |
114 | | |
115 | | virtual OUString GetComment() const override; |
116 | | |
117 | | static void DisposeElement( const css::uno::Reference< css::awt::XControlModel>& xReplaced ); |
118 | | }; |
119 | | |
120 | | typedef std::map<css::uno::Reference< css::beans::XPropertySet >, PropertySetInfo> PropertySetInfoCache; |
121 | | |
122 | | class FmXUndoEnvironment final |
123 | | : public ::cppu::WeakImplHelper< css::beans::XPropertyChangeListener |
124 | | , css::container::XContainerListener |
125 | | , css::util::XModifyListener |
126 | | > |
127 | | , public SfxListener |
128 | | { |
129 | | public: |
130 | | FmXUndoEnvironment(FmFormModel& _rModel); |
131 | | virtual ~FmXUndoEnvironment() override; |
132 | | |
133 | | // UNO binding |
134 | | // SMART_UNO_DECLARATION(FmXUndoEnvironment, ::cppu::OWeakObject); |
135 | | // virtual sal_Bool queryInterface(UsrUik, css::uno::Reference< css::uno::XInterface>&); |
136 | | // virtual css::uno::Sequence< css::uno::Reference< css::reflection::XIdlClass>> getIdlClasses(); |
137 | | |
138 | 0 | void Lock() { osl_atomic_increment( &m_Locks ); } |
139 | 0 | void UnLock() { osl_atomic_decrement( &m_Locks ); } |
140 | 0 | bool IsLocked() const { return m_Locks != 0; } |
141 | | |
142 | | // access control |
143 | 162k | struct Accessor { friend class FmFormModel; private: Accessor() { } }; |
144 | | |
145 | | // addition and removal of form collections |
146 | | void AddForms( const css::uno::Reference< css::container::XNameContainer>& rForms ); |
147 | | void RemoveForms( const css::uno::Reference< css::container::XNameContainer>& rForms ); |
148 | | |
149 | | // readonly-ness |
150 | 162k | void SetReadOnly( bool bRead, const Accessor& ) { bReadOnly = bRead; } |
151 | 162k | bool IsReadOnly() const {return bReadOnly;} |
152 | | |
153 | | // Methods for assigning controls to forms, |
154 | | // used by the page and the undo environment |
155 | | void Inserted(SdrObject* pObj); |
156 | | void Removed(SdrObject* pObj); |
157 | | |
158 | | static void Inserted(FmFormObj* pObj); |
159 | | static void Removed(FmFormObj* pObj); |
160 | | |
161 | | private: |
162 | | // XEventListener |
163 | | virtual void SAL_CALL disposing(const css::lang::EventObject& Source) override; |
164 | | |
165 | | // XPropertyChangeListener |
166 | | virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent& evt) override; |
167 | | |
168 | | // XContainerListener |
169 | | virtual void SAL_CALL elementInserted(const css::container::ContainerEvent& rEvent) override; |
170 | | virtual void SAL_CALL elementReplaced(const css::container::ContainerEvent& rEvent) override; |
171 | | virtual void SAL_CALL elementRemoved(const css::container::ContainerEvent& rEvent) override; |
172 | | |
173 | | // XModifyListener |
174 | | virtual void SAL_CALL modified( const css::lang::EventObject& aEvent ) override; |
175 | | |
176 | | void ModeChanged(); |
177 | | void dispose(); |
178 | | |
179 | | virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override; |
180 | | |
181 | | void AddElement(const css::uno::Reference< css::uno::XInterface>& Element); |
182 | | void RemoveElement(const css::uno::Reference< css::uno::XInterface>& Element); |
183 | | void TogglePropertyListening(const css::uno::Reference< css::uno::XInterface>& Element); |
184 | | |
185 | | void implSetModified(); |
186 | | |
187 | | void switchListening( const css::uno::Reference< css::container::XIndexContainer >& _rxContainer, bool _bStartListening ); |
188 | | void switchListening( const css::uno::Reference< css::uno::XInterface >& _rxObject, bool _bStartListening ); |
189 | | |
190 | | FmFormModel& rModel; |
191 | | std::unique_ptr<PropertySetInfoCache> m_pPropertySetCache; |
192 | | ::rtl::Reference<svxform::FormScriptingEnvironment> m_pScriptingEnv; |
193 | | oslInterlockedCount m_Locks; |
194 | | ::osl::Mutex m_aMutex; |
195 | | bool bReadOnly; |
196 | | bool m_bDisposed; |
197 | | rtl::Reference< ScriptEventListenerWrapper > m_vbaListener; |
198 | | }; |
199 | | |
200 | | |
201 | | #endif // INCLUDED_SVX_SOURCE_INC_FMUNDO_HXX |
202 | | |
203 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |