xref: /AOO41X/main/svx/source/inc/fmundo.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef _SVX_FMUNDO_HXX
29*cdf0e10cSrcweir #define _SVX_FMUNDO_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <svx/svdundo.hxx>
32*cdf0e10cSrcweir #include <svx/svdouno.hxx>
33*cdf0e10cSrcweir #include "fmscriptingenv.hxx"
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir /** === begin UNO includes === **/
37*cdf0e10cSrcweir #include <com/sun/star/util/XModifyListener.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyChangeListener.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyChangeEvent.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/script/ScriptEvent.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/script/ScriptEventDescriptor.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/container/XIndexContainer.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/container/XContainerListener.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/container/ContainerEvent.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
47*cdf0e10cSrcweir /** === end UNO includes === **/
48*cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx>
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir #include <svl/lstner.hxx>
52*cdf0e10cSrcweir #include <comphelper/uno3.hxx>
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir class FmFormModel;
55*cdf0e10cSrcweir class FmFormObj;
56*cdf0e10cSrcweir class SdrObject;
57*cdf0e10cSrcweir class FmXFormView;
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir FORWARD_DECLARE_INTERFACE(awt,XControl)
60*cdf0e10cSrcweir FORWARD_DECLARE_INTERFACE(awt,XControlContainer)
61*cdf0e10cSrcweir //FORWARD_DECLARE_INTERFACE(uno,Reference)
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir //==================================================================
64*cdf0e10cSrcweir // FmUndoPropertyAction
65*cdf0e10cSrcweir //==================================================================
66*cdf0e10cSrcweir class FmUndoPropertyAction: public SdrUndoAction
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> xObj;
69*cdf0e10cSrcweir 	::rtl::OUString			aPropertyName;
70*cdf0e10cSrcweir 	::com::sun::star::uno::Any			aNewValue;
71*cdf0e10cSrcweir 	::com::sun::star::uno::Any			aOldValue;
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir public:
74*cdf0e10cSrcweir 	FmUndoPropertyAction(FmFormModel& rMod, const ::com::sun::star::beans::PropertyChangeEvent& evt);
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 	virtual void Undo();
77*cdf0e10cSrcweir 	virtual void Redo();
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 	virtual String			GetComment() const;
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir };
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir //==================================================================
84*cdf0e10cSrcweir // FmUndoContainerAction
85*cdf0e10cSrcweir //==================================================================
86*cdf0e10cSrcweir class FmUndoContainerAction: public SdrUndoAction
87*cdf0e10cSrcweir {
88*cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >
89*cdf0e10cSrcweir                     m_xContainer;   // container which the action applies to
90*cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
91*cdf0e10cSrcweir                     m_xElement;     // object not owned by the action
92*cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
93*cdf0e10cSrcweir                     m_xOwnElement;	// object owned by the action
94*cdf0e10cSrcweir 	sal_Int32       m_nIndex;       // index of the object within it's container
95*cdf0e10cSrcweir 	::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >
96*cdf0e10cSrcweir                     m_aEvents;      // events of the object
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir public:
99*cdf0e10cSrcweir 	enum Action
100*cdf0e10cSrcweir 	{
101*cdf0e10cSrcweir 		Inserted = 1,
102*cdf0e10cSrcweir 		Removed	 = 2
103*cdf0e10cSrcweir 	};
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir private:
106*cdf0e10cSrcweir 	Action				m_eAction;
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir public:
109*cdf0e10cSrcweir 	FmUndoContainerAction(FmFormModel& rMod,
110*cdf0e10cSrcweir 						  Action _eAction,
111*cdf0e10cSrcweir 						  const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& xCont,
112*cdf0e10cSrcweir 						  const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xElem,
113*cdf0e10cSrcweir 						  sal_Int32 nIdx = -1);
114*cdf0e10cSrcweir 	~FmUndoContainerAction();
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir 	virtual void Undo();
117*cdf0e10cSrcweir 	virtual void Redo();
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 	static void DisposeElement( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xElem );
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir protected:
122*cdf0e10cSrcweir     void    implReInsert( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) );
123*cdf0e10cSrcweir     void    implReRemove( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) );
124*cdf0e10cSrcweir };
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir //==================================================================
127*cdf0e10cSrcweir // FmUndoModelReplaceAction
128*cdf0e10cSrcweir //==================================================================
129*cdf0e10cSrcweir class FmUndoModelReplaceAction : public SdrUndoAction
130*cdf0e10cSrcweir {
131*cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel>	m_xReplaced;
132*cdf0e10cSrcweir 	SdrUnoObj*			m_pObject;
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir public:
135*cdf0e10cSrcweir 	FmUndoModelReplaceAction(FmFormModel& rMod, SdrUnoObj* pObject, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel>& xReplaced);
136*cdf0e10cSrcweir 	~FmUndoModelReplaceAction();
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 	virtual void Undo();
139*cdf0e10cSrcweir 	virtual void Redo()	{ Undo(); }
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 	virtual String			GetComment() const;
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir 	static void DisposeElement( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel>& xReplaced );
144*cdf0e10cSrcweir };
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir //========================================================================
147*cdf0e10cSrcweir class SVX_DLLPRIVATE FmXUndoEnvironment
148*cdf0e10cSrcweir 	: public ::cppu::WeakImplHelper3<	::com::sun::star::beans::XPropertyChangeListener
149*cdf0e10cSrcweir 									,	::com::sun::star::container::XContainerListener
150*cdf0e10cSrcweir 									,	::com::sun::star::util::XModifyListener
151*cdf0e10cSrcweir 									>
152*cdf0e10cSrcweir 	, public SfxListener
153*cdf0e10cSrcweir 						   //	public ::cppu::OWeakObject
154*cdf0e10cSrcweir {
155*cdf0e10cSrcweir 	FmFormModel& rModel;
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir     void*                                   m_pPropertySetCache;
158*cdf0e10cSrcweir     ::svxform::PFormScriptingEnvironment    m_pScriptingEnv;
159*cdf0e10cSrcweir     oslInterlockedCount                     m_Locks;
160*cdf0e10cSrcweir     ::osl::Mutex                            m_aMutex;
161*cdf0e10cSrcweir     sal_Bool                                bReadOnly;
162*cdf0e10cSrcweir     bool                                    m_bDisposed;
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir public:
165*cdf0e10cSrcweir 	FmXUndoEnvironment(FmFormModel& _rModel);
166*cdf0e10cSrcweir 	~FmXUndoEnvironment();
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 	// UNO Anbindung
169*cdf0e10cSrcweir 	//	SMART_UNO_DECLARATION(FmXUndoEnvironment, ::cppu::OWeakObject);
170*cdf0e10cSrcweir 	//	virtual sal_Bool queryInterface(UsrUik, ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>&);
171*cdf0e10cSrcweir 	//	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass>>	getIdlClasses(void);
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 	void Lock() { osl_incrementInterlockedCount( &m_Locks ); }
174*cdf0e10cSrcweir 	void UnLock() { osl_decrementInterlockedCount( &m_Locks ); }
175*cdf0e10cSrcweir 	sal_Bool IsLocked() const { return m_Locks != 0; }
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir     // access control
178*cdf0e10cSrcweir     struct Accessor { friend class FmFormModel; private: Accessor() { } };
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir     // addition and removal of form collections
181*cdf0e10cSrcweir 	void AddForms( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer>& rForms );
182*cdf0e10cSrcweir 	void RemoveForms( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer>& rForms );
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir     // readonly-ness
185*cdf0e10cSrcweir 	void SetReadOnly( sal_Bool bRead, const Accessor& ) { bReadOnly = bRead; }
186*cdf0e10cSrcweir 	sal_Bool IsReadOnly() const {return bReadOnly;}
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir protected:
189*cdf0e10cSrcweir     // XEventListener
190*cdf0e10cSrcweir     virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException );
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir     // XPropertyChangeListener
193*cdf0e10cSrcweir     virtual void SAL_CALL propertyChange(const ::com::sun::star::beans::PropertyChangeEvent& evt) throw(::com::sun::star::uno::RuntimeException);
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir     // XContainerListener
196*cdf0e10cSrcweir     virtual void SAL_CALL elementInserted(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
197*cdf0e10cSrcweir     virtual void SAL_CALL elementReplaced(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
198*cdf0e10cSrcweir     virtual void SAL_CALL elementRemoved(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir     // XModifyListener
201*cdf0e10cSrcweir     virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 	void ModeChanged();
204*cdf0e10cSrcweir 	void dispose();
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir 	virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir private:
209*cdf0e10cSrcweir 	void AddElement(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& Element);
210*cdf0e10cSrcweir 	void RemoveElement(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& Element);
211*cdf0e10cSrcweir 	void TogglePropertyListening(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& Element);
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir     void    implSetModified();
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir     void    switchListening( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& _rxContainer, bool _bStartListening ) SAL_THROW(());
216*cdf0e10cSrcweir     void    switchListening( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxObject, bool _bStartListening ) SAL_THROW(());
217*cdf0e10cSrcweir     ::com::sun::star::uno::Reference< com::sun::star::script::XScriptListener > m_vbaListener;
218*cdf0e10cSrcweir public:
219*cdf0e10cSrcweir 	// Methoden zur Zuordnung von Controls zu Forms,
220*cdf0e10cSrcweir 	// werden von der Seite und der UndoUmgebung genutzt
221*cdf0e10cSrcweir 	void Inserted(SdrObject* pObj);
222*cdf0e10cSrcweir 	void Removed(SdrObject* pObj);
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir 	void Inserted(FmFormObj* pObj);
225*cdf0e10cSrcweir 	void Removed(FmFormObj* pObj);
226*cdf0e10cSrcweir };
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir #endif	//_SVX_FMUNDO_HXX
230*cdf0e10cSrcweir 
231