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