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