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