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 : #include <com/sun/star/uno/XComponentContext.hpp>
37 :
38 : #include <comphelper/stl_types.hxx>
39 : #include <tools/link.hxx>
40 : #include <cppuhelper/implbase2.hxx>
41 : #include <cppuhelper/implbase3.hxx>
42 : #include <comphelper/uno3.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 : css::uno::Reference<css::uno::XComponentContext> m_xContext;
90 : FmXFormView* m_pViewImpl;
91 : Window* m_pWindow;
92 :
93 : protected:
94 : ~FormViewPageWindowAdapter();
95 :
96 : public:
97 : FormViewPageWindowAdapter( const css::uno::Reference<css::uno::XComponentContext>& _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 181 : 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 324 : ::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 73 : 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 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow> m_xWindow;
154 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xLastCreatedControlModel;
155 :
156 : FmFormObj* m_pMarkedGrid;
157 : FmFormView* m_pView;
158 : sal_uIntPtr m_nActivationEvent;
159 : sal_uIntPtr m_nErrorMessageEvent; // event for an asynchronous error message. See also m_aAsyncError
160 : sal_uIntPtr m_nAutoFocusEvent; // event for asynchronously setting the focus to a control
161 : sal_uIntPtr m_nControlWizardEvent; // event for asynchronously setting the focus to a control
162 :
163 : ::com::sun::star::sdb::SQLErrorEvent
164 : m_aAsyncError; // error event which is to be displayed asyn. See m_nErrorMessageEvent.
165 :
166 : PageWindowAdapterList
167 : m_aPageWindowAdapters; // to be filled in alive mode only
168 : MapControlContainerToSetOfForms
169 : m_aNeedTabOrderUpdate;
170 :
171 : // Liste der markierten Object, dient zur Restauration beim Umschalten von Alive in DesignMode
172 : SdrMarkList m_aMark;
173 : ObjectRemoveListener* m_pWatchStoredList;
174 :
175 : bool m_bFirstActivation;
176 : bool m_isTabOrderUpdateSuspended;
177 :
178 : FmFormShell* GetFormShell() const;
179 :
180 : void removeGridWindowListening();
181 :
182 : protected:
183 : FmXFormView( FmFormView* _pView );
184 : ~FmXFormView();
185 :
186 : void saveMarkList( sal_Bool _bSmartUnmark = sal_True );
187 : void restoreMarkList( SdrMarkList& _rRestoredMarkList );
188 : void stopMarkListWatching();
189 : void startMarkListWatching();
190 :
191 : void notifyViewDying( );
192 : // notifies this impl class that the anti-impl instance (m_pView) is going to die
193 :
194 : public:
195 : // UNO Anbindung
196 :
197 : // ::com::sun::star::lang::XEventListener
198 : virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw(::com::sun::star::uno::RuntimeException);
199 :
200 : // ::com::sun::star::container::XContainerListener
201 : virtual void SAL_CALL elementInserted(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
202 : virtual void SAL_CALL elementReplaced(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
203 : virtual void SAL_CALL elementRemoved(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
204 :
205 : // ::com::sun::star::form::XFormControllerListener
206 : virtual void SAL_CALL formActivated(const ::com::sun::star::lang::EventObject& rEvent) throw(::com::sun::star::uno::RuntimeException);
207 : virtual void SAL_CALL formDeactivated(const ::com::sun::star::lang::EventObject& rEvent) throw(::com::sun::star::uno::RuntimeException);
208 :
209 : // XFocusListener
210 : virtual void SAL_CALL focusGained( const ::com::sun::star::awt::FocusEvent& e ) throw (::com::sun::star::uno::RuntimeException);
211 : virtual void SAL_CALL focusLost( const ::com::sun::star::awt::FocusEvent& e ) throw (::com::sun::star::uno::RuntimeException);
212 :
213 4 : FmFormView* getView() const {return m_pView;}
214 : PFormViewPageWindowAdapter findWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer >& _rxCC ) const;
215 :
216 : ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >
217 : getFormController( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& _rxForm, const OutputDevice& _rDevice ) const;
218 :
219 : // activation handling
220 146 : inline bool hasEverBeenActivated( ) const { return !m_bFirstActivation; }
221 71 : inline void setHasBeenActivated( ) { m_bFirstActivation = false; }
222 :
223 : void onFirstViewActivation( const FmFormModel* _pDocModel );
224 :
225 : /** suspends the calls to activateTabOrder, which normally happen whenever for any ControlContainer of the view,
226 : new controls are inserted. Cannot be nested, i.e. you need to call resumeTabOrderUpdate before calling
227 : suspendTabOrderUpdate, again.
228 : */
229 : void suspendTabOrderUpdate();
230 :
231 : /** resumes calls to activateTabOrder, and also does all pending calls which were collected since the last
232 : suspendTabOrderUpdate call.
233 : */
234 : void resumeTabOrderUpdate();
235 :
236 : void onCreatedFormObject( FmFormObj& _rFormObject );
237 :
238 : static bool
239 : isFocusable(
240 : const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& i_rControl
241 : );
242 :
243 : private:
244 : //void addWindow(const SdrPageViewWinRec*);
245 : void addWindow(const SdrPageWindow&);
246 : void removeWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer >& _rxCC );
247 : void Activate(sal_Bool bSync = sal_False);
248 : void Deactivate(sal_Bool bDeactivateController = sal_True);
249 :
250 : SdrObject* implCreateFieldControl( const ::svx::ODataAccessDescriptor& _rColumnDescriptor );
251 : SdrObject* implCreateXFormsControl( const ::svx::OXFormsDescriptor &_rDesc );
252 :
253 : static bool createControlLabelPair(
254 : OutputDevice& _rOutDev,
255 : sal_Int32 _nXOffsetMM,
256 : sal_Int32 _nYOffsetMM,
257 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxField,
258 : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats >& _rxNumberFormats,
259 : sal_uInt16 _nControlObjectID,
260 : const OUString& _rFieldPostfix,
261 : sal_uInt32 _nInventor,
262 : sal_uInt16 _nLabelObjectID,
263 : SdrPage* _pLabelPage,
264 : SdrPage* _pControlPage,
265 : SdrModel* _pModel,
266 : SdrUnoObj*& _rpLabel,
267 : SdrUnoObj*& _rpControl
268 : );
269 :
270 : bool createControlLabelPair(
271 : OutputDevice& _rOutDev,
272 : sal_Int32 _nXOffsetMM,
273 : sal_Int32 _nYOffsetMM,
274 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxField,
275 : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats >& _rxNumberFormats,
276 : sal_uInt16 _nControlObjectID,
277 : const OUString& _rFieldPostfix,
278 : SdrUnoObj*& _rpLabel,
279 : SdrUnoObj*& _rpControl,
280 : const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource >& _rxDataSource = NULL,
281 : const OUString& _rDataSourceName = OUString(),
282 : const OUString& _rCommand= OUString(),
283 : const sal_Int32 _nCommandType = -1
284 : );
285 :
286 : void ObjectRemovedInAliveMode(const SdrObject* pObject);
287 :
288 : // asynchronously displays an error message. See also OnDelayedErrorMessage.
289 : void displayAsyncErrorMessage( const ::com::sun::star::sdb::SQLErrorEvent& _rEvent );
290 :
291 : // cancels all pending async events
292 : void cancelEvents();
293 :
294 : /// the auto focus to the first (in terms of the tab order) control
295 : void AutoFocus( sal_Bool _bSync = sal_False );
296 : DECL_LINK( OnActivate, void* );
297 : DECL_LINK( OnAutoFocus, void* );
298 : DECL_LINK( OnDelayedErrorMessage, void* );
299 : DECL_LINK( OnStartControlWizard, void* );
300 :
301 : private:
302 : ::svxform::DocumentType impl_getDocumentType() const;
303 : };
304 :
305 :
306 :
307 : #endif // _SVX_FMVWIMP_HXX
308 :
309 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|