xref: /aoo41x/main/svx/source/inc/fmvwimp.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 #ifndef _SVX_FMVWIMP_HXX
28 #define _SVX_FMVWIMP_HXX
29 
30 #include "svx/svdmark.hxx"
31 #include "fmdocumentclassification.hxx"
32 
33 /** === begin UNO includes === **/
34 #include <com/sun/star/form/XForm.hpp>
35 #include <com/sun/star/container/XIndexAccess.hpp>
36 #include <com/sun/star/container/XEnumeration.hpp>
37 #include <com/sun/star/form/runtime/XFormController.hpp>
38 #include <com/sun/star/form/runtime/XFormControllerContext.hpp>
39 #include <com/sun/star/container/XContainerListener.hpp>
40 #include <com/sun/star/container/ContainerEvent.hpp>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <com/sun/star/awt/XFocusListener.hpp>
43 #include <com/sun/star/sdb/SQLErrorEvent.hpp>
44 #include <com/sun/star/sdbc/XDataSource.hpp>
45 /** === end UNO includes === **/
46 
47 #include <comphelper/stl_types.hxx>
48 #include <tools/link.hxx>
49 #include <tools/string.hxx>
50 #include <cppuhelper/implbase2.hxx>
51 #include <cppuhelper/implbase3.hxx>
52 #include <comphelper/uno3.hxx>
53 #include <comphelper/componentcontext.hxx>
54 #include <rtl/ref.hxx>
55 
56 //class SdrPageViewWinRec;
57 class SdrPageWindow;
58 
59 class SdrPageView;
60 class SdrObject;
61 class FmFormObj;
62 class FmFormModel;
63 class FmFormView;
64 class FmFormShell;
65 class Window;
66 class OutputDevice;
67 class SdrUnoObj;
68 class SdrView;
69 
70 FORWARD_DECLARE_INTERFACE(awt,XControl)
71 FORWARD_DECLARE_INTERFACE(awt,XWindow)
72 FORWARD_DECLARE_INTERFACE(beans,XPropertySet)
73 FORWARD_DECLARE_INTERFACE(util,XNumberFormats)
74 
75 class FmXFormView;
76 
77 namespace svx {
78 	class ODataAccessDescriptor;
79 	struct OXFormsDescriptor;
80 }
81 
82 //==================================================================
83 // FormViewPageWindowAdapter
84 //==================================================================
85 typedef ::cppu::WeakImplHelper2 <   ::com::sun::star::container::XIndexAccess
86                                 ,   ::com::sun::star::form::runtime::XFormControllerContext
87                                 >   FormViewPageWindowAdapter_Base;
88 
89 class FormViewPageWindowAdapter : public FormViewPageWindowAdapter_Base
90 {
91 	friend class FmXFormView;
92 
93 	::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > >   m_aControllerList;
94     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer >                            m_xControlContainer;
95     ::comphelper::ComponentContext                                                                          m_aContext;
96 	FmXFormView*				m_pViewImpl;
97 	Window*						m_pWindow;
98 
99 protected:
100 	~FormViewPageWindowAdapter();
101 
102 public:
103 	FormViewPageWindowAdapter(	const ::comphelper::ComponentContext& _rContext,
104 		const SdrPageWindow&, FmXFormView* pView);
105 		//const SdrPageViewWinRec*, FmXFormView* pView);
106 
107     // XElementAccess
108     virtual ::com::sun::star::uno::Type SAL_CALL getElementType() throw(::com::sun::star::uno::RuntimeException);
109 	virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException);
110 
111     // XEnumerationAccess
112 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration >  SAL_CALL createEnumeration() throw(::com::sun::star::uno::RuntimeException);
113 
114     // XIndexAccess
115 	virtual sal_Int32 SAL_CALL getCount() throw(::com::sun::star::uno::RuntimeException);
116 	virtual ::com::sun::star::uno::Any SAL_CALL getByIndex(sal_Int32 _Index) throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
117 
118     // XFormControllerContext
119     virtual void SAL_CALL makeVisible( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _Control ) throw (::com::sun::star::uno::RuntimeException);
120 
121 	const ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > >& GetList() {return m_aControllerList;}
122 
123 protected:
124 	::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >  getController( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& xForm ) const;
125 	void setController(
126             const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& xForm,
127             const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxParentController );
128     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer >  getControlContainer() const { return m_xControlContainer; }
129 	void updateTabOrder( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& _rxForm );
130 	void dispose();
131 	Window* getWindow() const {return m_pWindow;}
132 };
133 
134 typedef ::rtl::Reference< FormViewPageWindowAdapter >   PFormViewPageWindowAdapter;
135 typedef ::std::vector< PFormViewPageWindowAdapter >     PageWindowAdapterList;
136 typedef ::std::set  <   ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >
137                     ,   ::comphelper::OInterfaceCompare< ::com::sun::star::form::XForm >
138                     >   SetOfForms;
139 typedef ::std::map  <   ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer >
140                     ,   SetOfForms
141                     ,   ::comphelper::OInterfaceCompare< ::com::sun::star::awt::XControlContainer >
142                     >   MapControlContainerToSetOfForms;
143 class SdrModel;
144 //==================================================================
145 // FmXFormView
146 //==================================================================
147 class FmXFormView :	public ::cppu::WeakImplHelper3<
148 							::com::sun::star::form::XFormControllerListener,
149 							::com::sun::star::awt::XFocusListener,
150 							::com::sun::star::container::XContainerListener>
151 {
152 	friend class FmFormView;
153 	friend class FmFormShell;
154 	friend class FmXFormShell;
155 	friend class FormViewPageWindowAdapter;
156 	class ObjectRemoveListener;
157 	friend class ObjectRemoveListener;
158 
159     ::comphelper::ComponentContext                                                      m_aContext;
160 	::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow>					m_xWindow;
161     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >           m_xLastCreatedControlModel;
162 
163 	FmFormObj*		m_pMarkedGrid;
164 	FmFormView*		m_pView;
165 	sal_uIntPtr		m_nActivationEvent;
166 	sal_uIntPtr		m_nErrorMessageEvent;	// event for an asynchronous error message. See also m_aAsyncError
167 	sal_uIntPtr		m_nAutoFocusEvent;		// event for asynchronously setting the focus to a control
168     sal_uIntPtr		m_nControlWizardEvent;  // event for asynchronously setting the focus to a control
169 
170 	::com::sun::star::sdb::SQLErrorEvent
171 					m_aAsyncError;			// error event which is to be displayed asyn. See m_nErrorMessageEvent.
172 
173 	PageWindowAdapterList
174                     m_aPageWindowAdapters;  // to be filled in alive mode only
175     MapControlContainerToSetOfForms
176                     m_aNeedTabOrderUpdate;
177 
178 	// Liste der markierten Object, dient zur Restauration beim Umschalten von Alive in DesignMode
179 	SdrMarkList				m_aMark;
180 	ObjectRemoveListener*	m_pWatchStoredList;
181 
182 	bool            m_bFirstActivation;
183     bool            m_isTabOrderUpdateSuspended;
184 
185 	FmFormShell* GetFormShell() const;
186 
187 	void removeGridWindowListening();
188 
189 protected:
190 	FmXFormView( const ::comphelper::ComponentContext& _rContext, FmFormView* _pView );
191 	~FmXFormView();
192 
193 	void	saveMarkList( sal_Bool _bSmartUnmark = sal_True );
194 	void	restoreMarkList( SdrMarkList& _rRestoredMarkList );
195 	void	stopMarkListWatching();
196 	void	startMarkListWatching();
197 
198 	void	notifyViewDying( );
199 		// notifies this impl class that the anti-impl instance (m_pView) is going to die
200 
201 public:
202 	// UNO Anbindung
203 
204 // ::com::sun::star::lang::XEventListener
205 	virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw(::com::sun::star::uno::RuntimeException);
206 
207 // ::com::sun::star::container::XContainerListener
208 	virtual void SAL_CALL elementInserted(const  ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
209 	virtual void SAL_CALL elementReplaced(const  ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
210 	virtual void SAL_CALL elementRemoved(const  ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
211 
212 // ::com::sun::star::form::XFormControllerListener
213 	virtual void SAL_CALL formActivated(const ::com::sun::star::lang::EventObject& rEvent) throw(::com::sun::star::uno::RuntimeException);
214 	virtual void SAL_CALL formDeactivated(const ::com::sun::star::lang::EventObject& rEvent) throw(::com::sun::star::uno::RuntimeException);
215 
216 	// XFocusListener
217 	virtual void SAL_CALL focusGained( const ::com::sun::star::awt::FocusEvent& e ) throw (::com::sun::star::uno::RuntimeException);
218     virtual void SAL_CALL focusLost( const ::com::sun::star::awt::FocusEvent& e ) throw (::com::sun::star::uno::RuntimeException);
219 
220 	FmFormView* getView() const {return m_pView;}
221     PFormViewPageWindowAdapter  findWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer >& _rxCC ) const;
222 
223     ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >
224             getFormController( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& _rxForm, const OutputDevice& _rDevice ) const;
225 
226 	// activation handling
227 	inline	bool        hasEverBeenActivated( ) const { return !m_bFirstActivation; }
228 	inline	void		setHasBeenActivated( ) { m_bFirstActivation = false; }
229 
230 			void		onFirstViewActivation( const FmFormModel* _pDocModel );
231 
232     /** suspends the calls to activateTabOrder, which normally happen whenever for any ControlContainer of the view,
233         new controls are inserted. Cannot be nested, i.e. you need to call resumeTabOrderUpdate before calling
234         suspendTabOrderUpdate, again.
235     */
236     void    suspendTabOrderUpdate();
237 
238     /** resumes calls to activateTabOrder, and also does all pending calls which were collected since the last
239         suspendTabOrderUpdate call.
240     */
241     void    resumeTabOrderUpdate();
242 
243     void    onCreatedFormObject( FmFormObj& _rFormObject );
244 
245     static bool
246             isFocusable(
247                 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& i_rControl
248             );
249 
250 private:
251 	//void addWindow(const SdrPageViewWinRec*);
252 	void addWindow(const SdrPageWindow&);
253 	void removeWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer >& _rxCC );
254 	void Activate(sal_Bool bSync = sal_False);
255 	void Deactivate(sal_Bool bDeactivateController = sal_True);
256 
257 	SdrObject*	implCreateFieldControl( const ::svx::ODataAccessDescriptor& _rColumnDescriptor );
258 	SdrObject*	implCreateXFormsControl( const ::svx::OXFormsDescriptor &_rDesc );
259 
260 	static bool createControlLabelPair(
261         const ::comphelper::ComponentContext& _rContext,
262         OutputDevice& _rOutDev,
263         sal_Int32 _nXOffsetMM,
264         sal_Int32 _nYOffsetMM,
265         const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxField,
266         const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats >& _rxNumberFormats,
267         sal_uInt16 _nControlObjectID,
268         const ::rtl::OUString& _rFieldPostfix,
269         sal_uInt32 _nInventor,
270         sal_uInt16 _nLabelObjectID,
271         SdrPage* _pLabelPage,
272         SdrPage* _pControlPage,
273         SdrModel* _pModel,
274         SdrUnoObj*& _rpLabel,
275         SdrUnoObj*& _rpControl
276 	);
277 
278     bool    createControlLabelPair(
279         OutputDevice& _rOutDev,
280         sal_Int32 _nXOffsetMM,
281         sal_Int32 _nYOffsetMM,
282         const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxField,
283         const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats >& _rxNumberFormats,
284         sal_uInt16 _nControlObjectID,
285         const ::rtl::OUString& _rFieldPostfix,
286         SdrUnoObj*& _rpLabel,
287         SdrUnoObj*& _rpControl,
288         const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource >& _rxDataSource = NULL,
289         const ::rtl::OUString& _rDataSourceName = ::rtl::OUString(),
290         const ::rtl::OUString& _rCommand= ::rtl::OUString(),
291         const sal_Int32 _nCommandType = -1
292     );
293 
294 	void ObjectRemovedInAliveMode(const SdrObject* pObject);
295 
296 	// asynchronously displays an error message. See also OnDelayedErrorMessage.
297 	void	displayAsyncErrorMessage( const ::com::sun::star::sdb::SQLErrorEvent& _rEvent );
298 
299 	// cancels all pending async events
300 	void cancelEvents();
301 
302 	/// the the auto focus to the first (in terms of the tab order) control
303 	void AutoFocus( sal_Bool _bSync = sal_False );
304 	DECL_LINK( OnActivate, void* );
305 	DECL_LINK( OnAutoFocus, void* );
306 	DECL_LINK( OnDelayedErrorMessage, void* );
307     DECL_LINK( OnStartControlWizard, void* );
308 
309 private:
310     ::svxform::DocumentType impl_getDocumentType() const;
311 };
312 
313 
314 
315 #endif // _SVX_FMVWIMP_HXX
316 
317