xref: /aoo41x/main/svx/source/inc/fmundo.hxx (revision 3334a7e6)
1*3334a7e6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*3334a7e6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*3334a7e6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*3334a7e6SAndrew Rist  * distributed with this work for additional information
6*3334a7e6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*3334a7e6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*3334a7e6SAndrew Rist  * "License"); you may not use this file except in compliance
9*3334a7e6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*3334a7e6SAndrew Rist  *
11*3334a7e6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*3334a7e6SAndrew Rist  *
13*3334a7e6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*3334a7e6SAndrew Rist  * software distributed under the License is distributed on an
15*3334a7e6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*3334a7e6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*3334a7e6SAndrew Rist  * specific language governing permissions and limitations
18*3334a7e6SAndrew Rist  * under the License.
19*3334a7e6SAndrew Rist  *
20*3334a7e6SAndrew Rist  *************************************************************/
21*3334a7e6SAndrew Rist 
22*3334a7e6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _SVX_FMUNDO_HXX
25cdf0e10cSrcweir #define _SVX_FMUNDO_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <svx/svdundo.hxx>
28cdf0e10cSrcweir #include <svx/svdouno.hxx>
29cdf0e10cSrcweir #include "fmscriptingenv.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir 
32cdf0e10cSrcweir /** === begin UNO includes === **/
33cdf0e10cSrcweir #include <com/sun/star/util/XModifyListener.hpp>
34cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
35cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyChangeListener.hpp>
36cdf0e10cSrcweir #include <com/sun/star/beans/PropertyChangeEvent.hpp>
37cdf0e10cSrcweir #include <com/sun/star/script/ScriptEvent.hpp>
38cdf0e10cSrcweir #include <com/sun/star/script/ScriptEventDescriptor.hpp>
39cdf0e10cSrcweir #include <com/sun/star/container/XIndexContainer.hpp>
40cdf0e10cSrcweir #include <com/sun/star/container/XContainerListener.hpp>
41cdf0e10cSrcweir #include <com/sun/star/container/ContainerEvent.hpp>
42cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
43cdf0e10cSrcweir /** === end UNO includes === **/
44cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #include <svl/lstner.hxx>
48cdf0e10cSrcweir #include <comphelper/uno3.hxx>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir class FmFormModel;
51cdf0e10cSrcweir class FmFormObj;
52cdf0e10cSrcweir class SdrObject;
53cdf0e10cSrcweir class FmXFormView;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir FORWARD_DECLARE_INTERFACE(awt,XControl)
56cdf0e10cSrcweir FORWARD_DECLARE_INTERFACE(awt,XControlContainer)
57cdf0e10cSrcweir //FORWARD_DECLARE_INTERFACE(uno,Reference)
58cdf0e10cSrcweir 
59cdf0e10cSrcweir //==================================================================
60cdf0e10cSrcweir // FmUndoPropertyAction
61cdf0e10cSrcweir //==================================================================
62cdf0e10cSrcweir class FmUndoPropertyAction: public SdrUndoAction
63cdf0e10cSrcweir {
64cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> xObj;
65cdf0e10cSrcweir 	::rtl::OUString			aPropertyName;
66cdf0e10cSrcweir 	::com::sun::star::uno::Any			aNewValue;
67cdf0e10cSrcweir 	::com::sun::star::uno::Any			aOldValue;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir public:
70cdf0e10cSrcweir 	FmUndoPropertyAction(FmFormModel& rMod, const ::com::sun::star::beans::PropertyChangeEvent& evt);
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	virtual void Undo();
73cdf0e10cSrcweir 	virtual void Redo();
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	virtual String			GetComment() const;
76cdf0e10cSrcweir 
77cdf0e10cSrcweir };
78cdf0e10cSrcweir 
79cdf0e10cSrcweir //==================================================================
80cdf0e10cSrcweir // FmUndoContainerAction
81cdf0e10cSrcweir //==================================================================
82cdf0e10cSrcweir class FmUndoContainerAction: public SdrUndoAction
83cdf0e10cSrcweir {
84cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >
85cdf0e10cSrcweir                     m_xContainer;   // container which the action applies to
86cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
87cdf0e10cSrcweir                     m_xElement;     // object not owned by the action
88cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
89cdf0e10cSrcweir                     m_xOwnElement;	// object owned by the action
90cdf0e10cSrcweir 	sal_Int32       m_nIndex;       // index of the object within it's container
91cdf0e10cSrcweir 	::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >
92cdf0e10cSrcweir                     m_aEvents;      // events of the object
93cdf0e10cSrcweir 
94cdf0e10cSrcweir public:
95cdf0e10cSrcweir 	enum Action
96cdf0e10cSrcweir 	{
97cdf0e10cSrcweir 		Inserted = 1,
98cdf0e10cSrcweir 		Removed	 = 2
99cdf0e10cSrcweir 	};
100cdf0e10cSrcweir 
101cdf0e10cSrcweir private:
102cdf0e10cSrcweir 	Action				m_eAction;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir public:
105cdf0e10cSrcweir 	FmUndoContainerAction(FmFormModel& rMod,
106cdf0e10cSrcweir 						  Action _eAction,
107cdf0e10cSrcweir 						  const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& xCont,
108cdf0e10cSrcweir 						  const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xElem,
109cdf0e10cSrcweir 						  sal_Int32 nIdx = -1);
110cdf0e10cSrcweir 	~FmUndoContainerAction();
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 	virtual void Undo();
113cdf0e10cSrcweir 	virtual void Redo();
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	static void DisposeElement( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xElem );
116cdf0e10cSrcweir 
117cdf0e10cSrcweir protected:
118cdf0e10cSrcweir     void    implReInsert( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) );
119cdf0e10cSrcweir     void    implReRemove( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) );
120cdf0e10cSrcweir };
121cdf0e10cSrcweir 
122cdf0e10cSrcweir //==================================================================
123cdf0e10cSrcweir // FmUndoModelReplaceAction
124cdf0e10cSrcweir //==================================================================
125cdf0e10cSrcweir class FmUndoModelReplaceAction : public SdrUndoAction
126cdf0e10cSrcweir {
127cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel>	m_xReplaced;
128cdf0e10cSrcweir 	SdrUnoObj*			m_pObject;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir public:
131cdf0e10cSrcweir 	FmUndoModelReplaceAction(FmFormModel& rMod, SdrUnoObj* pObject, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel>& xReplaced);
132cdf0e10cSrcweir 	~FmUndoModelReplaceAction();
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 	virtual void Undo();
Redo()135cdf0e10cSrcweir 	virtual void Redo()	{ Undo(); }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	virtual String			GetComment() const;
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 	static void DisposeElement( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel>& xReplaced );
140cdf0e10cSrcweir };
141cdf0e10cSrcweir 
142cdf0e10cSrcweir //========================================================================
143cdf0e10cSrcweir class SVX_DLLPRIVATE FmXUndoEnvironment
144cdf0e10cSrcweir 	: public ::cppu::WeakImplHelper3<	::com::sun::star::beans::XPropertyChangeListener
145cdf0e10cSrcweir 									,	::com::sun::star::container::XContainerListener
146cdf0e10cSrcweir 									,	::com::sun::star::util::XModifyListener
147cdf0e10cSrcweir 									>
148cdf0e10cSrcweir 	, public SfxListener
149cdf0e10cSrcweir 						   //	public ::cppu::OWeakObject
150cdf0e10cSrcweir {
151cdf0e10cSrcweir 	FmFormModel& rModel;
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     void*                                   m_pPropertySetCache;
154cdf0e10cSrcweir     ::svxform::PFormScriptingEnvironment    m_pScriptingEnv;
155cdf0e10cSrcweir     oslInterlockedCount                     m_Locks;
156cdf0e10cSrcweir     ::osl::Mutex                            m_aMutex;
157cdf0e10cSrcweir     sal_Bool                                bReadOnly;
158cdf0e10cSrcweir     bool                                    m_bDisposed;
159cdf0e10cSrcweir 
160cdf0e10cSrcweir public:
161cdf0e10cSrcweir 	FmXUndoEnvironment(FmFormModel& _rModel);
162cdf0e10cSrcweir 	~FmXUndoEnvironment();
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 	// UNO Anbindung
165cdf0e10cSrcweir 	//	SMART_UNO_DECLARATION(FmXUndoEnvironment, ::cppu::OWeakObject);
166cdf0e10cSrcweir 	//	virtual sal_Bool queryInterface(UsrUik, ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>&);
167cdf0e10cSrcweir 	//	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass>>	getIdlClasses(void);
168cdf0e10cSrcweir 
Lock()169cdf0e10cSrcweir 	void Lock() { osl_incrementInterlockedCount( &m_Locks ); }
UnLock()170cdf0e10cSrcweir 	void UnLock() { osl_decrementInterlockedCount( &m_Locks ); }
IsLocked() const171cdf0e10cSrcweir 	sal_Bool IsLocked() const { return m_Locks != 0; }
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     // access control
AccessorFmXUndoEnvironment::Accessor174cdf0e10cSrcweir     struct Accessor { friend class FmFormModel; private: Accessor() { } };
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     // addition and removal of form collections
177cdf0e10cSrcweir 	void AddForms( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer>& rForms );
178cdf0e10cSrcweir 	void RemoveForms( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer>& rForms );
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     // readonly-ness
SetReadOnly(sal_Bool bRead,const Accessor &)181cdf0e10cSrcweir 	void SetReadOnly( sal_Bool bRead, const Accessor& ) { bReadOnly = bRead; }
IsReadOnly() const182cdf0e10cSrcweir 	sal_Bool IsReadOnly() const {return bReadOnly;}
183cdf0e10cSrcweir 
184cdf0e10cSrcweir protected:
185cdf0e10cSrcweir     // XEventListener
186cdf0e10cSrcweir     virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException );
187cdf0e10cSrcweir 
188cdf0e10cSrcweir     // XPropertyChangeListener
189cdf0e10cSrcweir     virtual void SAL_CALL propertyChange(const ::com::sun::star::beans::PropertyChangeEvent& evt) throw(::com::sun::star::uno::RuntimeException);
190cdf0e10cSrcweir 
191cdf0e10cSrcweir     // XContainerListener
192cdf0e10cSrcweir     virtual void SAL_CALL elementInserted(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
193cdf0e10cSrcweir     virtual void SAL_CALL elementReplaced(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
194cdf0e10cSrcweir     virtual void SAL_CALL elementRemoved(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
195cdf0e10cSrcweir 
196cdf0e10cSrcweir     // XModifyListener
197cdf0e10cSrcweir     virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
198cdf0e10cSrcweir 
199cdf0e10cSrcweir 	void ModeChanged();
200cdf0e10cSrcweir 	void dispose();
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 	virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
203cdf0e10cSrcweir 
204cdf0e10cSrcweir private:
205cdf0e10cSrcweir 	void AddElement(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& Element);
206cdf0e10cSrcweir 	void RemoveElement(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& Element);
207cdf0e10cSrcweir 	void TogglePropertyListening(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& Element);
208cdf0e10cSrcweir 
209cdf0e10cSrcweir     void    implSetModified();
210cdf0e10cSrcweir 
211cdf0e10cSrcweir     void    switchListening( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& _rxContainer, bool _bStartListening ) SAL_THROW(());
212cdf0e10cSrcweir     void    switchListening( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxObject, bool _bStartListening ) SAL_THROW(());
213cdf0e10cSrcweir     ::com::sun::star::uno::Reference< com::sun::star::script::XScriptListener > m_vbaListener;
214cdf0e10cSrcweir public:
215cdf0e10cSrcweir 	// Methoden zur Zuordnung von Controls zu Forms,
216cdf0e10cSrcweir 	// werden von der Seite und der UndoUmgebung genutzt
217cdf0e10cSrcweir 	void Inserted(SdrObject* pObj);
218cdf0e10cSrcweir 	void Removed(SdrObject* pObj);
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 	void Inserted(FmFormObj* pObj);
221cdf0e10cSrcweir 	void Removed(FmFormObj* pObj);
222cdf0e10cSrcweir };
223cdf0e10cSrcweir 
224cdf0e10cSrcweir 
225cdf0e10cSrcweir #endif	//_SVX_FMUNDO_HXX
226cdf0e10cSrcweir 
227