1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SVX_SOURCE_INC_FMVWIMP_HXX
20 #define INCLUDED_SVX_SOURCE_INC_FMVWIMP_HXX
22 #include <sal/config.h>
28 #include <svx/svdmark.hxx>
29 #include <svx/svdobj.hxx>
30 #include "fmdocumentclassification.hxx"
32 #include <com/sun/star/form/XForm.hpp>
33 #include <com/sun/star/container/XIndexAccess.hpp>
34 #include <com/sun/star/form/runtime/XFormController.hpp>
35 #include <com/sun/star/form/runtime/XFormControllerContext.hpp>
36 #include <com/sun/star/container/XContainerListener.hpp>
37 #include <com/sun/star/container/ContainerEvent.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 #include <com/sun/star/uno/XComponentContext.hpp>
43 #include <tools/link.hxx>
44 #include <cppuhelper/implbase.hxx>
45 #include <rtl/ref.hxx>
46 #include <vcl/vclptr.hxx>
55 namespace vcl
{ class Window
; }
59 enum class SdrInventor
: sal_uInt32
;
61 namespace com::sun::star
{
77 class ODataAccessDescriptor
;
78 struct OXFormsDescriptor
;
82 // FormViewPageWindowAdapter
84 typedef ::cppu::WeakImplHelper
< css::container::XIndexAccess
85 , css::form::runtime::XFormControllerContext
86 > FormViewPageWindowAdapter_Base
;
88 class FormViewPageWindowAdapter final
: public FormViewPageWindowAdapter_Base
90 friend class FmXFormView
;
92 ::std::vector
< css::uno::Reference
< css::form::runtime::XFormController
> > m_aControllerList
;
93 css::uno::Reference
< css::awt::XControlContainer
> m_xControlContainer
;
94 css::uno::Reference
<css::uno::XComponentContext
> m_xContext
;
95 FmXFormView
* m_pViewImpl
;
96 VclPtr
<vcl::Window
> m_pWindow
;
99 FormViewPageWindowAdapter( const css::uno::Reference
<css::uno::XComponentContext
>& _rContext
,
100 const SdrPageWindow
&, FmXFormView
* pView
);
101 //const SdrPageViewWinRec*, FmXFormView* pView);
104 virtual css::uno::Type SAL_CALL
getElementType() override
;
105 virtual sal_Bool SAL_CALL
hasElements() override
;
108 virtual sal_Int32 SAL_CALL
getCount() override
;
109 virtual css::uno::Any SAL_CALL
getByIndex(sal_Int32 Index
) override
;
111 // XFormControllerContext
112 virtual void SAL_CALL
makeVisible( const css::uno::Reference
< css::awt::XControl
>& Control
) override
;
114 const ::std::vector
< css::uno::Reference
< css::form::runtime::XFormController
> >& GetList() const {return m_aControllerList
;}
117 virtual ~FormViewPageWindowAdapter() override
;
119 css::uno::Reference
< css::form::runtime::XFormController
> getController( const css::uno::Reference
< css::form::XForm
>& xForm
) const;
121 const css::uno::Reference
< css::form::XForm
>& xForm
,
122 const css::uno::Reference
< css::form::runtime::XFormController
>& _rxParentController
);
123 const css::uno::Reference
< css::awt::XControlContainer
>& getControlContainer() const { return m_xControlContainer
; }
124 void updateTabOrder( const css::uno::Reference
< css::form::XForm
>& _rxForm
);
126 vcl::Window
* getWindow() const {return m_pWindow
;}
129 typedef ::rtl::Reference
< FormViewPageWindowAdapter
> PFormViewPageWindowAdapter
;
130 typedef ::std::set
< css::uno::Reference
< css::form::XForm
> > SetOfForms
;
131 typedef ::std::map
< css::uno::Reference
< css::awt::XControlContainer
>, SetOfForms
> MapControlContainerToSetOfForms
;
134 class FmXFormView
: public ::cppu::WeakImplHelper
<
135 css::form::XFormControllerListener
,
136 css::awt::XFocusListener
,
137 css::container::XContainerListener
>
139 friend class FmFormView
;
140 friend class FmFormShell
;
141 friend class FmXFormShell
;
142 friend class FormViewPageWindowAdapter
;
143 class ObjectRemoveListener
;
144 friend class ObjectRemoveListener
;
146 css::uno::Reference
< css::awt::XWindow
> m_xWindow
;
147 css::uno::Reference
< css::beans::XPropertySet
> m_xLastCreatedControlModel
;
149 FmFormObj
* m_pMarkedGrid
;
151 ImplSVEvent
* m_nActivationEvent
;
152 ImplSVEvent
* m_nErrorMessageEvent
; // event for an asynchronous error message. See also m_aAsyncError
153 ImplSVEvent
* m_nAutoFocusEvent
; // event for asynchronously setting the focus to a control
154 ImplSVEvent
* m_nControlWizardEvent
; // event for asynchronously setting the focus to a control
156 css::sdb::SQLErrorEvent
157 m_aAsyncError
; // error event which is to be displayed asyn. See m_nErrorMessageEvent.
159 std::vector
< PFormViewPageWindowAdapter
>
160 m_aPageWindowAdapters
; // to be filled in alive mode only
161 MapControlContainerToSetOfForms
162 m_aNeedTabOrderUpdate
;
164 // list of selected objects, used for restoration when switching from Alive to DesignMode
166 std::unique_ptr
<ObjectRemoveListener
>
169 bool m_bFirstActivation
;
170 bool m_isTabOrderUpdateSuspended
;
172 FmFormShell
* GetFormShell() const;
175 FmXFormView( FmFormView
* _pView
);
176 virtual ~FmXFormView() override
;
179 void restoreMarkList( SdrMarkList
& _rRestoredMarkList
);
180 void stopMarkListWatching();
181 void startMarkListWatching();
183 void notifyViewDying( );
184 // notifies this impl class that the anti-impl instance (m_pView) is going to die
189 // css::lang::XEventListener
190 virtual void SAL_CALL
disposing(const css::lang::EventObject
& Source
) override
;
192 // css::container::XContainerListener
193 virtual void SAL_CALL
elementInserted(const css::container::ContainerEvent
& rEvent
) override
;
194 virtual void SAL_CALL
elementReplaced(const css::container::ContainerEvent
& rEvent
) override
;
195 virtual void SAL_CALL
elementRemoved(const css::container::ContainerEvent
& rEvent
) override
;
197 // css::form::XFormControllerListener
198 virtual void SAL_CALL
formActivated(const css::lang::EventObject
& rEvent
) override
;
199 virtual void SAL_CALL
formDeactivated(const css::lang::EventObject
& rEvent
) override
;
202 virtual void SAL_CALL
focusGained( const css::awt::FocusEvent
& e
) override
;
203 virtual void SAL_CALL
focusLost( const css::awt::FocusEvent
& e
) override
;
205 FmFormView
* getView() const {return m_pView
;}
206 PFormViewPageWindowAdapter
findWindow( const css::uno::Reference
< css::awt::XControlContainer
>& _rxCC
) const;
208 css::uno::Reference
< css::form::runtime::XFormController
>
209 getFormController( const css::uno::Reference
< css::form::XForm
>& _rxForm
, const OutputDevice
& _rDevice
) const;
211 // activation handling
212 bool hasEverBeenActivated( ) const { return !m_bFirstActivation
; }
213 void setHasBeenActivated( ) { m_bFirstActivation
= false; }
215 void onFirstViewActivation( const FmFormModel
* _pDocModel
);
217 /** suspends the calls to activateTabOrder, which normally happen whenever for any ControlContainer of the view,
218 new controls are inserted. Cannot be nested, i.e. you need to call resumeTabOrderUpdate before calling
219 suspendTabOrderUpdate, again.
221 void suspendTabOrderUpdate();
223 /** resumes calls to activateTabOrder, and also does all pending calls which were collected since the last
224 suspendTabOrderUpdate call.
226 void resumeTabOrderUpdate();
228 void onCreatedFormObject( FmFormObj
const & _rFormObject
);
230 void breakCreateFormObject();
233 isFocusable( const css::uno::Reference
< css::awt::XControl
>& i_rControl
);
236 //void addWindow(const SdrPageViewWinRec*);
237 void addWindow(const SdrPageWindow
&);
238 void removeWindow( const css::uno::Reference
< css::awt::XControlContainer
>& _rxCC
);
239 void Activate(bool bSync
= false);
240 void Deactivate(bool bDeactivateController
= true);
242 SdrObjectUniquePtr
implCreateFieldControl( const svx::ODataAccessDescriptor
& _rColumnDescriptor
);
243 SdrObjectUniquePtr
implCreateXFormsControl( const svx::OXFormsDescriptor
&_rDesc
);
245 static bool createControlLabelPair(
246 OutputDevice
const & _rOutDev
,
247 sal_Int32 _nXOffsetMM
,
248 sal_Int32 _nYOffsetMM
,
249 const css::uno::Reference
< css::beans::XPropertySet
>& _rxField
,
250 const css::uno::Reference
< css::util::XNumberFormats
>& _rxNumberFormats
,
251 SdrObjKind _nControlObjectID
,
252 const OUString
& _rFieldPostfix
,
253 SdrInventor _nInventor
,
254 SdrObjKind _nLabelObjectID
,
256 // tdf#118963 Need a SdrModel for SdrObject creation. To make the
257 // demand clear, hand over a SdrMldel&
260 std::unique_ptr
<SdrUnoObj
, SdrObjectFreeOp
>& _rpLabel
,
261 std::unique_ptr
<SdrUnoObj
, SdrObjectFreeOp
>& _rpControl
264 bool createControlLabelPair(
265 OutputDevice
const & _rOutDev
,
266 sal_Int32 _nXOffsetMM
,
267 sal_Int32 _nYOffsetMM
,
268 const css::uno::Reference
< css::beans::XPropertySet
>& _rxField
,
269 const css::uno::Reference
< css::util::XNumberFormats
>& _rxNumberFormats
,
270 SdrObjKind _nControlObjectID
,
271 const OUString
& _rFieldPostfix
,
272 std::unique_ptr
<SdrUnoObj
, SdrObjectFreeOp
>& _rpLabel
,
273 std::unique_ptr
<SdrUnoObj
, SdrObjectFreeOp
>& _rpControl
,
274 const css::uno::Reference
< css::sdbc::XDataSource
>& _rxDataSource
,
275 const OUString
& _rDataSourceName
,
276 const OUString
& _rCommand
,
277 const sal_Int32 _nCommandType
280 void ObjectRemovedInAliveMode(const SdrObject
* pObject
);
282 // asynchronously displays an error message. See also OnDelayedErrorMessage.
283 void displayAsyncErrorMessage( const css::sdb::SQLErrorEvent
& _rEvent
);
285 // cancels all pending async events
288 /// the auto focus to the first (in terms of the tab order) control
290 DECL_LINK( OnActivate
, void*, void );
291 DECL_LINK( OnAutoFocus
, void*, void );
292 DECL_LINK( OnDelayedErrorMessage
, void*, void );
293 DECL_LINK( OnStartControlWizard
, void*, void );
296 ::svxform::DocumentType
impl_getDocumentType() const;
300 #endif // INCLUDED_SVX_SOURCE_INC_FMVWIMP_HXX
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */