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