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 INCLUDED_SVX_SOURCE_INC_FMVWIMP_HXX
20 : #define INCLUDED_SVX_SOURCE_INC_FMVWIMP_HXX
21 :
22 : #include <sal/config.h>
23 :
24 : #include <map>
25 :
26 : #include "svx/svdmark.hxx"
27 : #include "fmdocumentclassification.hxx"
28 :
29 : #include <com/sun/star/form/XForm.hpp>
30 : #include <com/sun/star/container/XIndexAccess.hpp>
31 : #include <com/sun/star/container/XEnumeration.hpp>
32 : #include <com/sun/star/form/runtime/XFormController.hpp>
33 : #include <com/sun/star/form/runtime/XFormControllerContext.hpp>
34 : #include <com/sun/star/container/XContainerListener.hpp>
35 : #include <com/sun/star/container/ContainerEvent.hpp>
36 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 : #include <com/sun/star/awt/XFocusListener.hpp>
38 : #include <com/sun/star/sdb/SQLErrorEvent.hpp>
39 : #include <com/sun/star/sdbc/XDataSource.hpp>
40 : #include <com/sun/star/uno/XComponentContext.hpp>
41 :
42 : #include <comphelper/stl_types.hxx>
43 : #include <tools/link.hxx>
44 : #include <cppuhelper/implbase2.hxx>
45 : #include <cppuhelper/implbase3.hxx>
46 : #include <comphelper/uno3.hxx>
47 : #include <rtl/ref.hxx>
48 : #include <vcl/vclptr.hxx>
49 :
50 : class SdrPageWindow;
51 :
52 : class SdrObject;
53 : class FmFormObj;
54 : class FmFormModel;
55 : class FmFormView;
56 : class FmFormShell;
57 : namespace vcl { class Window; }
58 : class OutputDevice;
59 : class SdrUnoObj;
60 : struct ImplSVEvent;
61 :
62 : namespace com { namespace sun { namespace star {
63 : namespace awt {
64 : class XControl;
65 : class XWindow;
66 : }
67 : namespace beans {
68 : class XPropertySet;
69 : }
70 : namespace util {
71 : class XNumberFormats;
72 : }
73 : }}}
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 : css::uno::Reference<css::uno::XComponentContext> m_xContext;
96 : FmXFormView* m_pViewImpl;
97 : VclPtr<vcl::Window> m_pWindow;
98 :
99 : protected:
100 : virtual ~FormViewPageWindowAdapter();
101 :
102 : public:
103 : FormViewPageWindowAdapter( const css::uno::Reference<css::uno::XComponentContext>& _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, std::exception) SAL_OVERRIDE;
109 : virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
110 :
111 : // XIndexAccess
112 : virtual sal_Int32 SAL_CALL getCount() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
113 : 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, std::exception) SAL_OVERRIDE;
114 :
115 : // XFormControllerContext
116 : virtual void SAL_CALL makeVisible( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _Control ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
117 :
118 190 : const ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > >& GetList() {return m_aControllerList;}
119 :
120 : protected:
121 : ::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;
122 : void setController(
123 : const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& xForm,
124 : const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxParentController );
125 1156 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer > getControlContainer() const { return m_xControlContainer; }
126 : void updateTabOrder( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& _rxForm );
127 : void dispose();
128 79 : vcl::Window* getWindow() const {return m_pWindow;}
129 : };
130 :
131 : typedef ::rtl::Reference< FormViewPageWindowAdapter > PFormViewPageWindowAdapter;
132 : typedef ::std::vector< PFormViewPageWindowAdapter > PageWindowAdapterList;
133 : typedef ::std::set < ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >
134 : , ::comphelper::OInterfaceCompare< ::com::sun::star::form::XForm >
135 : > SetOfForms;
136 : typedef ::std::map < ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer >
137 : , SetOfForms
138 : , ::comphelper::OInterfaceCompare< ::com::sun::star::awt::XControlContainer >
139 : > MapControlContainerToSetOfForms;
140 : class SdrModel;
141 :
142 : class FmXFormView : public ::cppu::WeakImplHelper3<
143 : ::com::sun::star::form::XFormControllerListener,
144 : ::com::sun::star::awt::XFocusListener,
145 : ::com::sun::star::container::XContainerListener>
146 : {
147 : friend class FmFormView;
148 : friend class FmFormShell;
149 : friend class FmXFormShell;
150 : friend class FormViewPageWindowAdapter;
151 : class ObjectRemoveListener;
152 : friend class ObjectRemoveListener;
153 :
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 : ImplSVEvent * m_nActivationEvent;
160 : ImplSVEvent * m_nErrorMessageEvent; // event for an asynchronous error message. See also m_aAsyncError
161 : ImplSVEvent * m_nAutoFocusEvent; // event for asynchronously setting the focus to a control
162 : ImplSVEvent * 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( FmFormView* _pView );
185 : virtual ~FmXFormView();
186 :
187 : void saveMarkList( bool _bSmartUnmark = 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, std::exception) SAL_OVERRIDE;
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, std::exception) SAL_OVERRIDE;
203 : virtual void SAL_CALL elementReplaced(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
204 : virtual void SAL_CALL elementRemoved(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
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, std::exception) SAL_OVERRIDE;
208 : virtual void SAL_CALL formDeactivated(const ::com::sun::star::lang::EventObject& rEvent) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
209 :
210 : // XFocusListener
211 : virtual void SAL_CALL focusGained( const ::com::sun::star::awt::FocusEvent& e ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
212 : virtual void SAL_CALL focusLost( const ::com::sun::star::awt::FocusEvent& e ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
213 :
214 2 : 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 560 : inline bool hasEverBeenActivated( ) const { return !m_bFirstActivation; }
222 257 : 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 : void breakCreateFormObject();
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(bool bSync = false);
251 : void Deactivate(bool bDeactivateController = true);
252 :
253 : SdrObject* implCreateFieldControl( const svx::ODataAccessDescriptor& _rColumnDescriptor );
254 : SdrObject* implCreateXFormsControl( const svx::OXFormsDescriptor &_rDesc );
255 :
256 : static bool createControlLabelPair(
257 : OutputDevice& _rOutDev,
258 : sal_Int32 _nXOffsetMM,
259 : sal_Int32 _nYOffsetMM,
260 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxField,
261 : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats >& _rxNumberFormats,
262 : sal_uInt16 _nControlObjectID,
263 : const OUString& _rFieldPostfix,
264 : sal_uInt32 _nInventor,
265 : sal_uInt16 _nLabelObjectID,
266 : SdrPage* _pLabelPage,
267 : SdrPage* _pControlPage,
268 : SdrModel* _pModel,
269 : SdrUnoObj*& _rpLabel,
270 : SdrUnoObj*& _rpControl
271 : );
272 :
273 : bool createControlLabelPair(
274 : OutputDevice& _rOutDev,
275 : sal_Int32 _nXOffsetMM,
276 : sal_Int32 _nYOffsetMM,
277 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxField,
278 : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats >& _rxNumberFormats,
279 : sal_uInt16 _nControlObjectID,
280 : const OUString& _rFieldPostfix,
281 : SdrUnoObj*& _rpLabel,
282 : SdrUnoObj*& _rpControl,
283 : const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource >& _rxDataSource = NULL,
284 : const OUString& _rDataSourceName = OUString(),
285 : const OUString& _rCommand = OUString(),
286 : const sal_Int32 _nCommandType = -1
287 : );
288 :
289 : void ObjectRemovedInAliveMode(const SdrObject* pObject);
290 :
291 : // asynchronously displays an error message. See also OnDelayedErrorMessage.
292 : void displayAsyncErrorMessage( const ::com::sun::star::sdb::SQLErrorEvent& _rEvent );
293 :
294 : // cancels all pending async events
295 : void cancelEvents();
296 :
297 : /// the auto focus to the first (in terms of the tab order) control
298 : void AutoFocus( bool _bSync = false );
299 : DECL_LINK( OnActivate, void* );
300 : DECL_LINK( OnAutoFocus, void* );
301 : DECL_LINK( OnDelayedErrorMessage, void* );
302 : DECL_LINK( OnStartControlWizard, void* );
303 :
304 : private:
305 : ::svxform::DocumentType impl_getDocumentType() const;
306 : };
307 :
308 :
309 :
310 : #endif // INCLUDED_SVX_SOURCE_INC_FMVWIMP_HXX
311 :
312 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|