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