xref: /AOO41X/main/extensions/source/propctrlr/eformshelper.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef EXTENSIONS_SOURCE_PROPCTRLR_EFORMSHELPER_HXX
29*cdf0e10cSrcweir #define EXTENSIONS_SOURCE_PROPCTRLR_EFORMSHELPER_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "pcrcommon.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir /** === begin UNO includes === **/
34*cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/xforms/XModel.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/xforms/XFormsSupplier.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/form/binding/XBindableValue.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/form/binding/XListEntrySource.hpp>
40*cdf0e10cSrcweir /** === end UNO includes === **/
41*cdf0e10cSrcweir #include <osl/mutex.hxx>
42*cdf0e10cSrcweir #include <tools/string.hxx>
43*cdf0e10cSrcweir #include <comphelper/listenernotification.hxx>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #include <vector>
46*cdf0e10cSrcweir #include <set>
47*cdf0e10cSrcweir #include <map>
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir //........................................................................
50*cdf0e10cSrcweir namespace pcr
51*cdf0e10cSrcweir {
52*cdf0e10cSrcweir //........................................................................
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir     typedef ::std::map< ::rtl::OUString, ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >, ::std::less< ::rtl::OUString > >
55*cdf0e10cSrcweir             MapStringToPropertySet;
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir 	//====================================================================
58*cdf0e10cSrcweir 	//= EFormsHelper
59*cdf0e10cSrcweir 	//====================================================================
60*cdf0e10cSrcweir 	class EFormsHelper
61*cdf0e10cSrcweir 	{
62*cdf0e10cSrcweir     protected:
63*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
64*cdf0e10cSrcweir                         m_xControlModel;
65*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XBindableValue >
66*cdf0e10cSrcweir                         m_xBindableControl;
67*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::xforms::XFormsSupplier >
68*cdf0e10cSrcweir                         m_xDocument;
69*cdf0e10cSrcweir         PropertyChangeListeners
70*cdf0e10cSrcweir                         m_aPropertyListeners;
71*cdf0e10cSrcweir         MapStringToPropertySet
72*cdf0e10cSrcweir                         m_aSubmissionUINames;   // only filled upon request
73*cdf0e10cSrcweir         MapStringToPropertySet
74*cdf0e10cSrcweir                         m_aBindingUINames;      // only filled upon request
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir     public:
77*cdf0e10cSrcweir         EFormsHelper(
78*cdf0e10cSrcweir             ::osl::Mutex& _rMutex,
79*cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControlModel,
80*cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _rxContextDocument
81*cdf0e10cSrcweir         );
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir         /** determines whether the given document is an eForm
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir             If this method returns <FALSE/>, you cannot instantiate a EFormsHelper with
86*cdf0e10cSrcweir             this document, since then no of it's functionality will be available.
87*cdf0e10cSrcweir         */
88*cdf0e10cSrcweir         static  bool
89*cdf0e10cSrcweir                 isEForm(
90*cdf0e10cSrcweir                     const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _rxContextDocument
91*cdf0e10cSrcweir                 ) SAL_THROW(());
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir         /** registers a listener to be notified when any aspect of the binding changes.
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir             The listener will be registered at the current binding of the control model. If the binding
96*cdf0e10cSrcweir             changes (see <method>setBinding</method>), the listener will be revoked from the old binding,
97*cdf0e10cSrcweir             registered at the new binding, and for all properties which differ between both bindings,
98*cdf0e10cSrcweir             the listener will be notified.
99*cdf0e10cSrcweir             @see revokeBindingListener
100*cdf0e10cSrcweir         */
101*cdf0e10cSrcweir         void    registerBindingListener(
102*cdf0e10cSrcweir                     const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxBindingListener
103*cdf0e10cSrcweir                 );
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir         /** revokes the binding listener which has previously been registered
106*cdf0e10cSrcweir             @see registerBindingListener
107*cdf0e10cSrcweir         */
108*cdf0e10cSrcweir         void    revokeBindingListener(
109*cdf0e10cSrcweir                     const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxBindingListener
110*cdf0e10cSrcweir                 );
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir         /** checks whether it's possible to bind the control model to a given XSD data type
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir             @param _nDataType
115*cdf0e10cSrcweir                 the data type which should be bound. If this is -1, <TRUE/> is returned if the control model
116*cdf0e10cSrcweir                 can be bound to <em>any</em> data type.
117*cdf0e10cSrcweir         */
118*cdf0e10cSrcweir         bool    canBindToDataType( sal_Int32 _nDataType = -1 ) const SAL_THROW(());
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir         /** checks whether the control model cna be bound to any XSD data type
121*cdf0e10cSrcweir         */
122*cdf0e10cSrcweir         bool    canBindToAnyDataType() const SAL_THROW(()) { return canBindToDataType( -1 ); }
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir         /** checks whether the control model is a source for list entries, as supplied by XML data bindings
125*cdf0e10cSrcweir         */
126*cdf0e10cSrcweir         bool    isListEntrySink() const SAL_THROW(());
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir         /** retrieves the names of all XForms models in the document the control lives in
129*cdf0e10cSrcweir         */
130*cdf0e10cSrcweir         void    getFormModelNames( ::std::vector< ::rtl::OUString >& /* [out] */ _rModelNames ) const SAL_THROW(());
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir         /** retrieves the names of all bindings for a given model
133*cdf0e10cSrcweir             @see getFormModelNames
134*cdf0e10cSrcweir         */
135*cdf0e10cSrcweir         void    getBindingNames( const ::rtl::OUString& _rModelName, ::std::vector< ::rtl::OUString >& /* [out] */ _rBindingNames ) const SAL_THROW(());
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir         /// retrieves the XForms model (within the control model's document) with the given name
138*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::xforms::XModel >
139*cdf0e10cSrcweir                 getFormModelByName( const ::rtl::OUString& _rModelName ) const SAL_THROW(());
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir         /** retrieves the model which the active binding of the control model belongs to
142*cdf0e10cSrcweir         */
143*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::xforms::XModel >
144*cdf0e10cSrcweir                 getCurrentFormModel() const SAL_THROW(());
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir         /** retrieves the name of the model which the active binding of the control model belongs to
147*cdf0e10cSrcweir         */
148*cdf0e10cSrcweir         ::rtl::OUString
149*cdf0e10cSrcweir                 getCurrentFormModelName() const SAL_THROW(());
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir         /** retrieves the binding instance which is currently attached to the control model
152*cdf0e10cSrcweir         */
153*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
154*cdf0e10cSrcweir                 getCurrentBinding() const SAL_THROW(());
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir         /** retrieves the name of the binding instance which is currently attached to the control model
157*cdf0e10cSrcweir         */
158*cdf0e10cSrcweir         ::rtl::OUString
159*cdf0e10cSrcweir                 getCurrentBindingName() const SAL_THROW(());
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir         /** sets a new binding at the control model
162*cdf0e10cSrcweir         */
163*cdf0e10cSrcweir         void    setBinding( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxBinding ) SAL_THROW(());
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir         /** retrieves the binding instance which is currently used as list source for the control model
166*cdf0e10cSrcweir             @see isListEntrySink
167*cdf0e10cSrcweir         */
168*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >
169*cdf0e10cSrcweir                 getCurrentListSourceBinding() const SAL_THROW(());
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir         /** sets a new list source at the control model
172*cdf0e10cSrcweir             @see isListEntrySink
173*cdf0e10cSrcweir         */
174*cdf0e10cSrcweir         void    setListSourceBinding( const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >& _rxListSource ) SAL_THROW(());
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir         /** retrieves a given binding for a given model, or creates a new one
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir             @param _rTargetModel
179*cdf0e10cSrcweir                 the name of the model to create a binding for. Must not be empty
180*cdf0e10cSrcweir             @param _rBindingName
181*cdf0e10cSrcweir                 the name of the binding to retrieve. If the model denoted by <arg>_rTargetModel</arg> does not
182*cdf0e10cSrcweir                 have a binding with this name, a new binding is created and returned.
183*cdf0e10cSrcweir         */
184*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
185*cdf0e10cSrcweir             getOrCreateBindingForModel( const ::rtl::OUString& _rTargetModel, const ::rtl::OUString& _rBindingName ) const SAL_THROW(());
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir         /** types of sub-elements of a model
188*cdf0e10cSrcweir         */
189*cdf0e10cSrcweir         enum ModelElementType
190*cdf0e10cSrcweir         {
191*cdf0e10cSrcweir             Submission,
192*cdf0e10cSrcweir             Binding
193*cdf0e10cSrcweir         };
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir         /** retrieves the name of a model's sub-element, as to be shown in the UI
196*cdf0e10cSrcweir             @see getModelElementFromUIName
197*cdf0e10cSrcweir             @see getAllElementUINames
198*cdf0e10cSrcweir         */
199*cdf0e10cSrcweir         ::rtl::OUString
200*cdf0e10cSrcweir                 getModelElementUIName(
201*cdf0e10cSrcweir                     const ModelElementType _eType,
202*cdf0e10cSrcweir                     const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxElement
203*cdf0e10cSrcweir                 ) const SAL_THROW(());
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir         /** retrieves the submission object for an UI name
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir             Note that <member>getAllElementUINames</member> must have been called before, for the given element type
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir             @see getModelElementUIName
210*cdf0e10cSrcweir             @see getAllElementUINames
211*cdf0e10cSrcweir         */
212*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
213*cdf0e10cSrcweir                 getModelElementFromUIName(
214*cdf0e10cSrcweir                     const ModelElementType _eType,
215*cdf0e10cSrcweir                     const ::rtl::OUString& _rUIName
216*cdf0e10cSrcweir                 ) const SAL_THROW(());
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir         /** retrieves the UI names of all elements of all models in our document
219*cdf0e10cSrcweir             @param _eType
220*cdf0e10cSrcweir                 the type of elements for which the names should be retrieved
221*cdf0e10cSrcweir             @param _rElementNames
222*cdf0e10cSrcweir                 the array of element names
223*cdf0e10cSrcweir             @see getModelElementUIName
224*cdf0e10cSrcweir             @see getModelElementFromUIName
225*cdf0e10cSrcweir         */
226*cdf0e10cSrcweir         void    getAllElementUINames(
227*cdf0e10cSrcweir                     const ModelElementType _eType,
228*cdf0e10cSrcweir                     ::std::vector< ::rtl::OUString >& /* [out] */ _rElementNames,
229*cdf0e10cSrcweir                     bool _bPrepentEmptyEntry
230*cdf0e10cSrcweir                 );
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir     protected:
233*cdf0e10cSrcweir         void    firePropertyChanges(
234*cdf0e10cSrcweir                     const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxOldProps,
235*cdf0e10cSrcweir                     const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxNewProps,
236*cdf0e10cSrcweir                     ::std::set< ::rtl::OUString >& _rFilter
237*cdf0e10cSrcweir                 ) const;
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir         /** fires a change in a single property, if the property value changed, and if we have a listener
240*cdf0e10cSrcweir             interested in property changes
241*cdf0e10cSrcweir         */
242*cdf0e10cSrcweir         void    firePropertyChange(
243*cdf0e10cSrcweir                     const ::rtl::OUString& _rName,
244*cdf0e10cSrcweir                     const ::com::sun::star::uno::Any& _rOldValue,
245*cdf0e10cSrcweir                     const ::com::sun::star::uno::Any& _rNewValue
246*cdf0e10cSrcweir                 ) const;
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir     private:
249*cdf0e10cSrcweir         void impl_switchBindingListening_throw( bool _bDoListening, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener );
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir         /// implementation for both <member>getOrCreateBindingForModel</member>
252*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
253*cdf0e10cSrcweir             implGetOrCreateBinding( const ::rtl::OUString& _rTargetModel, const ::rtl::OUString& _rBindingName ) const SAL_THROW(());
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir         void
256*cdf0e10cSrcweir             impl_toggleBindingPropertyListening_throw( bool _bDoListen, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxConcreteListenerOrNull );
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir     private:
259*cdf0e10cSrcweir         EFormsHelper();                                 // never implemented
260*cdf0e10cSrcweir         EFormsHelper( const EFormsHelper& );            // never implemented
261*cdf0e10cSrcweir         EFormsHelper& operator=( const EFormsHelper& ); // never implemented
262*cdf0e10cSrcweir 	};
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir //........................................................................
265*cdf0e10cSrcweir } // namespace pcr
266*cdf0e10cSrcweir //........................................................................
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir #endif // EXTENSIONS_SOURCE_PROPCTRLR_EFORMSHELPER_HXX
269*cdf0e10cSrcweir 
270