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