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_SVX_SOURCE_INC_FMUNDO_HXX
21 #define INCLUDED_SVX_SOURCE_INC_FMUNDO_HXX
23 #include <svx/svdundo.hxx>
24 #include <svx/svdouno.hxx>
25 #include "fmscriptingenv.hxx"
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>
39 #include <svl/lstner.hxx>
46 struct PropertySetInfo
;
47 class ScriptEventListenerWrapper
;
49 class FmUndoPropertyAction final
: public SdrUndoAction
51 css::uno::Reference
< css::beans::XPropertySet
> xObj
;
52 OUString aPropertyName
;
53 css::uno::Any aNewValue
;
54 css::uno::Any aOldValue
;
57 FmUndoPropertyAction(FmFormModel
& rMod
, const css::beans::PropertyChangeEvent
& evt
);
59 virtual void Undo() override
;
60 virtual void Redo() override
;
62 virtual OUString
GetComment() const override
;
66 class FmUndoContainerAction final
: public SdrUndoAction
75 FmUndoContainerAction(FmFormModel
& rMod
,
77 const css::uno::Reference
< css::container::XIndexContainer
>& xCont
,
78 const css::uno::Reference
< css::uno::XInterface
>& xElem
,
80 virtual ~FmUndoContainerAction() override
;
82 virtual void Undo() override
;
83 virtual void Redo() override
;
85 static void DisposeElement( const css::uno::Reference
< css::uno::XInterface
>& xElem
);
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
103 class FmUndoModelReplaceAction final
: public SdrUndoAction
105 css::uno::Reference
< css::awt::XControlModel
> m_xReplaced
;
106 SdrUnoObj
* m_pObject
;
109 FmUndoModelReplaceAction(FmFormModel
& rMod
, SdrUnoObj
* pObject
, const css::uno::Reference
< css::awt::XControlModel
>& xReplaced
);
110 virtual ~FmUndoModelReplaceAction() override
;
112 virtual void Undo() override
;
113 virtual void Redo() override
{ Undo(); }
115 virtual OUString
GetComment() const override
;
117 static void DisposeElement( const css::uno::Reference
< css::awt::XControlModel
>& xReplaced
);
120 typedef std::map
<css::uno::Reference
< css::beans::XPropertySet
>, PropertySetInfo
> PropertySetInfoCache
;
122 class FmXUndoEnvironment final
123 : public ::cppu::WeakImplHelper
< css::beans::XPropertyChangeListener
124 , css::container::XContainerListener
125 , css::util::XModifyListener
130 FmXUndoEnvironment(FmFormModel
& _rModel
);
131 virtual ~FmXUndoEnvironment() override
;
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();
138 void Lock() { osl_atomic_increment( &m_Locks
); }
139 void UnLock() { osl_atomic_decrement( &m_Locks
); }
140 bool IsLocked() const { return m_Locks
!= 0; }
143 struct Accessor
{ friend class FmFormModel
; private: Accessor() { } };
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
);
150 void SetReadOnly( bool bRead
, const Accessor
& ) { bReadOnly
= bRead
; }
151 bool IsReadOnly() const {return bReadOnly
;}
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
);
158 static void Inserted(FmFormObj
* pObj
);
159 static void Removed(FmFormObj
* pObj
);
163 virtual void SAL_CALL
disposing(const css::lang::EventObject
& Source
) override
;
165 // XPropertyChangeListener
166 virtual void SAL_CALL
propertyChange(const css::beans::PropertyChangeEvent
& evt
) override
;
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
;
174 virtual void SAL_CALL
modified( const css::lang::EventObject
& aEvent
) override
;
179 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
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
);
185 void implSetModified();
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
);
191 std::unique_ptr
<PropertySetInfoCache
> m_pPropertySetCache
;
192 ::rtl::Reference
<svxform::FormScriptingEnvironment
> m_pScriptingEnv
;
193 oslInterlockedCount m_Locks
;
194 ::osl::Mutex m_aMutex
;
197 rtl::Reference
< ScriptEventListenerWrapper
> m_vbaListener
;
201 #endif // INCLUDED_SVX_SOURCE_INC_FMUNDO_HXX
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */