1*2a97ec55SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2a97ec55SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2a97ec55SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2a97ec55SAndrew Rist * distributed with this work for additional information 6*2a97ec55SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2a97ec55SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2a97ec55SAndrew Rist * "License"); you may not use this file except in compliance 9*2a97ec55SAndrew Rist * with the License. You may obtain a copy of the License at 10*2a97ec55SAndrew Rist * 11*2a97ec55SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*2a97ec55SAndrew Rist * 13*2a97ec55SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2a97ec55SAndrew Rist * software distributed under the License is distributed on an 15*2a97ec55SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2a97ec55SAndrew Rist * KIND, either express or implied. See the License for the 17*2a97ec55SAndrew Rist * specific language governing permissions and limitations 18*2a97ec55SAndrew Rist * under the License. 19*2a97ec55SAndrew Rist * 20*2a97ec55SAndrew Rist *************************************************************/ 21*2a97ec55SAndrew Rist 22*2a97ec55SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_extensions.hxx" 26cdf0e10cSrcweir #include "eformshelper.hxx" 27cdf0e10cSrcweir #include "formstrings.hxx" 28cdf0e10cSrcweir #ifndef _EXTENSIONS_FORMCTRLR_PROPRESID_HRC_ 29cdf0e10cSrcweir #include "formresid.hrc" 30cdf0e10cSrcweir #endif 31cdf0e10cSrcweir #ifndef _EXTENSIONS_PROPCTRLR_MODULEPRC_HXX_ 32cdf0e10cSrcweir #include "modulepcr.hxx" 33cdf0e10cSrcweir #endif 34cdf0e10cSrcweir #include "propeventtranslation.hxx" 35cdf0e10cSrcweir #include "formbrowsertools.hxx" 36cdf0e10cSrcweir 37cdf0e10cSrcweir /** === begin UNO includes === **/ 38cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 39cdf0e10cSrcweir #include <com/sun/star/form/FormComponentType.hpp> 40cdf0e10cSrcweir #include <com/sun/star/xforms/XFormsUIHelper1.hpp> 41cdf0e10cSrcweir #include <com/sun/star/xsd/DataTypeClass.hpp> 42cdf0e10cSrcweir #include <com/sun/star/form/binding/XListEntrySink.hpp> 43cdf0e10cSrcweir /** === end UNO includes === **/ 44cdf0e10cSrcweir #include <tools/diagnose_ex.h> 45cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 46cdf0e10cSrcweir 47cdf0e10cSrcweir #include <functional> 48cdf0e10cSrcweir #include <algorithm> 49cdf0e10cSrcweir 50cdf0e10cSrcweir //........................................................................ 51cdf0e10cSrcweir namespace pcr 52cdf0e10cSrcweir { 53cdf0e10cSrcweir //........................................................................ 54cdf0e10cSrcweir 55cdf0e10cSrcweir using namespace ::com::sun::star; 56cdf0e10cSrcweir using namespace ::com::sun::star::uno; 57cdf0e10cSrcweir using namespace ::com::sun::star::beans; 58cdf0e10cSrcweir using namespace ::com::sun::star::container; 59cdf0e10cSrcweir using namespace ::com::sun::star::form::binding; 60cdf0e10cSrcweir using namespace ::com::sun::star::xsd; 61cdf0e10cSrcweir using namespace ::com::sun::star::lang; 62cdf0e10cSrcweir using namespace ::com::sun::star::form; 63cdf0e10cSrcweir 64cdf0e10cSrcweir //==================================================================== 65cdf0e10cSrcweir //= file-local helpers 66cdf0e10cSrcweir //==================================================================== 67cdf0e10cSrcweir namespace 68cdf0e10cSrcweir { 69cdf0e10cSrcweir //-------------------------------------------------------------------- composeModelElementUIName(const::rtl::OUString & _rModelName,const::rtl::OUString & _rElementName)70cdf0e10cSrcweir ::rtl::OUString composeModelElementUIName( const ::rtl::OUString& _rModelName, const ::rtl::OUString& _rElementName ) 71cdf0e10cSrcweir { 72cdf0e10cSrcweir ::rtl::OUStringBuffer aBuffer; 73cdf0e10cSrcweir aBuffer.appendAscii( "[" ); 74cdf0e10cSrcweir aBuffer.append( _rModelName ); 75cdf0e10cSrcweir aBuffer.appendAscii( "] " ); 76cdf0e10cSrcweir aBuffer.append( _rElementName ); 77cdf0e10cSrcweir return aBuffer.makeStringAndClear(); 78cdf0e10cSrcweir } 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir //==================================================================== 82cdf0e10cSrcweir //= EFormsHelper 83cdf0e10cSrcweir //==================================================================== 84cdf0e10cSrcweir //-------------------------------------------------------------------- EFormsHelper(::osl::Mutex & _rMutex,const Reference<XPropertySet> & _rxControlModel,const Reference<frame::XModel> & _rxContextDocument)85cdf0e10cSrcweir EFormsHelper::EFormsHelper( ::osl::Mutex& _rMutex, const Reference< XPropertySet >& _rxControlModel, const Reference< frame::XModel >& _rxContextDocument ) 86cdf0e10cSrcweir :m_xControlModel( _rxControlModel ) 87cdf0e10cSrcweir ,m_aPropertyListeners( _rMutex ) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir OSL_ENSURE( _rxControlModel.is(), "EFormsHelper::EFormsHelper: invalid control model!" ); 90cdf0e10cSrcweir m_xBindableControl = m_xBindableControl.query( _rxControlModel ); 91cdf0e10cSrcweir 92cdf0e10cSrcweir m_xDocument = m_xDocument.query( _rxContextDocument ); 93cdf0e10cSrcweir OSL_ENSURE( m_xDocument.is(), "EFormsHelper::EFormsHelper: invalid document!" ); 94cdf0e10cSrcweir 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 97cdf0e10cSrcweir //-------------------------------------------------------------------- isEForm(const Reference<frame::XModel> & _rxContextDocument)98cdf0e10cSrcweir bool EFormsHelper::isEForm( const Reference< frame::XModel >& _rxContextDocument ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir try 101cdf0e10cSrcweir { 102cdf0e10cSrcweir Reference< xforms::XFormsSupplier > xDocument( _rxContextDocument, UNO_QUERY ); 103cdf0e10cSrcweir if ( !xDocument.is() ) 104cdf0e10cSrcweir return false; 105cdf0e10cSrcweir 106cdf0e10cSrcweir return xDocument->getXForms().is(); 107cdf0e10cSrcweir } 108cdf0e10cSrcweir catch( const Exception& ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir OSL_ENSURE( sal_False, "EFormsHelper::isEForm: caught an exception!" ); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir return false; 113cdf0e10cSrcweir } 114cdf0e10cSrcweir 115cdf0e10cSrcweir //-------------------------------------------------------------------- canBindToDataType(sal_Int32 _nDataType) const116cdf0e10cSrcweir bool EFormsHelper::canBindToDataType( sal_Int32 _nDataType ) const SAL_THROW(()) 117cdf0e10cSrcweir { 118cdf0e10cSrcweir if ( !m_xBindableControl.is() ) 119cdf0e10cSrcweir // cannot bind at all 120cdf0e10cSrcweir return false; 121cdf0e10cSrcweir 122cdf0e10cSrcweir // some types cannot be bound, independent from the control type 123cdf0e10cSrcweir if ( ( DataTypeClass::hexBinary == _nDataType ) 124cdf0e10cSrcweir || ( DataTypeClass::base64Binary == _nDataType ) 125cdf0e10cSrcweir || ( DataTypeClass::QName == _nDataType ) 126cdf0e10cSrcweir || ( DataTypeClass::NOTATION == _nDataType ) 127cdf0e10cSrcweir ) 128cdf0e10cSrcweir return false; 129cdf0e10cSrcweir 130cdf0e10cSrcweir bool bCan = false; 131cdf0e10cSrcweir try 132cdf0e10cSrcweir { 133cdf0e10cSrcweir // classify the control model 134cdf0e10cSrcweir sal_Int16 nControlType = FormComponentType::CONTROL; 135cdf0e10cSrcweir OSL_VERIFY( m_xControlModel->getPropertyValue( PROPERTY_CLASSID ) >>= nControlType ); 136cdf0e10cSrcweir 137cdf0e10cSrcweir // some lists 138cdf0e10cSrcweir sal_Int16 nNumericCompatibleTypes[] = { DataTypeClass::DECIMAL, DataTypeClass::FLOAT, DataTypeClass::DOUBLE, 0 }; 139cdf0e10cSrcweir sal_Int16 nDateCompatibleTypes[] = { DataTypeClass::DATE, 0 }; 140cdf0e10cSrcweir sal_Int16 nTimeCompatibleTypes[] = { DataTypeClass::TIME, 0 }; 141cdf0e10cSrcweir sal_Int16 nCheckboxCompatibleTypes[] = { DataTypeClass::BOOLEAN, DataTypeClass::STRING, DataTypeClass::anyURI, 0 }; 142cdf0e10cSrcweir sal_Int16 nRadiobuttonCompatibleTypes[] = { DataTypeClass::STRING, DataTypeClass::anyURI, 0 }; 143cdf0e10cSrcweir sal_Int16 nFormattedCompatibleTypes[] = { DataTypeClass::DECIMAL, DataTypeClass::FLOAT, DataTypeClass::DOUBLE, DataTypeClass::DATETIME, DataTypeClass::DATE, DataTypeClass::TIME, 0 }; 144cdf0e10cSrcweir 145cdf0e10cSrcweir sal_Int16* pCompatibleTypes = NULL; 146cdf0e10cSrcweir switch ( nControlType ) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir case FormComponentType::SPINBUTTON: 149cdf0e10cSrcweir case FormComponentType::NUMERICFIELD: 150cdf0e10cSrcweir pCompatibleTypes = nNumericCompatibleTypes; 151cdf0e10cSrcweir break; 152cdf0e10cSrcweir case FormComponentType::DATEFIELD: 153cdf0e10cSrcweir pCompatibleTypes = nDateCompatibleTypes; 154cdf0e10cSrcweir break; 155cdf0e10cSrcweir case FormComponentType::TIMEFIELD: 156cdf0e10cSrcweir pCompatibleTypes = nTimeCompatibleTypes; 157cdf0e10cSrcweir break; 158cdf0e10cSrcweir case FormComponentType::CHECKBOX: 159cdf0e10cSrcweir pCompatibleTypes = nCheckboxCompatibleTypes; 160cdf0e10cSrcweir break; 161cdf0e10cSrcweir case FormComponentType::RADIOBUTTON: 162cdf0e10cSrcweir pCompatibleTypes = nRadiobuttonCompatibleTypes; 163cdf0e10cSrcweir break; 164cdf0e10cSrcweir 165cdf0e10cSrcweir case FormComponentType::TEXTFIELD: 166cdf0e10cSrcweir { 167cdf0e10cSrcweir // both the normal text field, and the formatted field, claim to be a TEXTFIELD 168cdf0e10cSrcweir // need to distinguish by service name 169cdf0e10cSrcweir Reference< XServiceInfo > xSI( m_xControlModel, UNO_QUERY ); 170cdf0e10cSrcweir OSL_ENSURE( xSI.is(), "EFormsHelper::canBindToDataType: a control model which has no service info?" ); 171cdf0e10cSrcweir if ( xSI.is() ) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir if ( xSI->supportsService( SERVICE_COMPONENT_FORMATTEDFIELD ) ) 174cdf0e10cSrcweir { 175cdf0e10cSrcweir pCompatibleTypes = nFormattedCompatibleTypes; 176cdf0e10cSrcweir break; 177cdf0e10cSrcweir } 178cdf0e10cSrcweir } 179cdf0e10cSrcweir // NO break here! 180cdf0e10cSrcweir } 181cdf0e10cSrcweir case FormComponentType::LISTBOX: 182cdf0e10cSrcweir case FormComponentType::COMBOBOX: 183cdf0e10cSrcweir // edit fields and list/combo boxes can be bound to anything 184cdf0e10cSrcweir bCan = true; 185cdf0e10cSrcweir } 186cdf0e10cSrcweir 187cdf0e10cSrcweir if ( !bCan && pCompatibleTypes ) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir if ( _nDataType == -1 ) 190cdf0e10cSrcweir { 191cdf0e10cSrcweir // the control can be bound to at least one type, and exactly this is being asked for 192cdf0e10cSrcweir bCan = true; 193cdf0e10cSrcweir } 194cdf0e10cSrcweir else 195cdf0e10cSrcweir { 196cdf0e10cSrcweir while ( *pCompatibleTypes && !bCan ) 197cdf0e10cSrcweir bCan = ( *pCompatibleTypes++ == _nDataType ); 198cdf0e10cSrcweir } 199cdf0e10cSrcweir } 200cdf0e10cSrcweir } 201cdf0e10cSrcweir catch( const Exception& ) 202cdf0e10cSrcweir { 203cdf0e10cSrcweir OSL_ENSURE( sal_False, "EFormsHelper::canBindToDataType: caught an exception!" ); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir return bCan; 207cdf0e10cSrcweir } 208cdf0e10cSrcweir 209cdf0e10cSrcweir //-------------------------------------------------------------------- isListEntrySink() const210cdf0e10cSrcweir bool EFormsHelper::isListEntrySink() const SAL_THROW(()) 211cdf0e10cSrcweir { 212cdf0e10cSrcweir bool bIs = false; 213cdf0e10cSrcweir try 214cdf0e10cSrcweir { 215cdf0e10cSrcweir Reference< XListEntrySink > xAsSink( m_xControlModel, UNO_QUERY ); 216cdf0e10cSrcweir bIs = xAsSink.is(); 217cdf0e10cSrcweir } 218cdf0e10cSrcweir catch( const Exception& ) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir OSL_ENSURE( sal_False, "EFormsHelper::isListEntrySink: caught an exception!" ); 221cdf0e10cSrcweir } 222cdf0e10cSrcweir return bIs; 223cdf0e10cSrcweir } 224cdf0e10cSrcweir 225cdf0e10cSrcweir //-------------------------------------------------------------------- impl_switchBindingListening_throw(bool _bDoListening,const Reference<XPropertyChangeListener> & _rxListener)226cdf0e10cSrcweir void EFormsHelper::impl_switchBindingListening_throw( bool _bDoListening, const Reference< XPropertyChangeListener >& _rxListener ) 227cdf0e10cSrcweir { 228cdf0e10cSrcweir Reference< XPropertySet > xBindingProps; 229cdf0e10cSrcweir if ( m_xBindableControl.is() ) 230cdf0e10cSrcweir xBindingProps = xBindingProps.query( m_xBindableControl->getValueBinding() ); 231cdf0e10cSrcweir if ( !xBindingProps.is() ) 232cdf0e10cSrcweir return; 233cdf0e10cSrcweir 234cdf0e10cSrcweir if ( _bDoListening ) 235cdf0e10cSrcweir { 236cdf0e10cSrcweir xBindingProps->addPropertyChangeListener( ::rtl::OUString(), _rxListener ); 237cdf0e10cSrcweir } 238cdf0e10cSrcweir else 239cdf0e10cSrcweir { 240cdf0e10cSrcweir xBindingProps->removePropertyChangeListener( ::rtl::OUString(), _rxListener ); 241cdf0e10cSrcweir } 242cdf0e10cSrcweir } 243cdf0e10cSrcweir 244cdf0e10cSrcweir //-------------------------------------------------------------------- registerBindingListener(const Reference<XPropertyChangeListener> & _rxBindingListener)245cdf0e10cSrcweir void EFormsHelper::registerBindingListener( const Reference< XPropertyChangeListener >& _rxBindingListener ) 246cdf0e10cSrcweir { 247cdf0e10cSrcweir if ( !_rxBindingListener.is() ) 248cdf0e10cSrcweir return; 249cdf0e10cSrcweir impl_toggleBindingPropertyListening_throw( true, _rxBindingListener ); 250cdf0e10cSrcweir } 251cdf0e10cSrcweir 252cdf0e10cSrcweir //-------------------------------------------------------------------- impl_toggleBindingPropertyListening_throw(bool _bDoListen,const Reference<XPropertyChangeListener> & _rxConcreteListenerOrNull)253cdf0e10cSrcweir void EFormsHelper::impl_toggleBindingPropertyListening_throw( bool _bDoListen, const Reference< XPropertyChangeListener >& _rxConcreteListenerOrNull ) 254cdf0e10cSrcweir { 255cdf0e10cSrcweir if ( !_bDoListen ) 256cdf0e10cSrcweir { 257cdf0e10cSrcweir ::std::auto_ptr< ::cppu::OInterfaceIteratorHelper > pListenerIterator = m_aPropertyListeners.createIterator(); 258cdf0e10cSrcweir while ( pListenerIterator->hasMoreElements() ) 259cdf0e10cSrcweir { 260cdf0e10cSrcweir PropertyEventTranslation* pTranslator = dynamic_cast< PropertyEventTranslation* >( pListenerIterator->next() ); 261cdf0e10cSrcweir OSL_ENSURE( pTranslator, "EFormsHelper::impl_toggleBindingPropertyListening_throw: invalid listener element in my container!" ); 262cdf0e10cSrcweir if ( !pTranslator ) 263cdf0e10cSrcweir continue; 264cdf0e10cSrcweir 265cdf0e10cSrcweir Reference< XPropertyChangeListener > xEventSourceTranslator( pTranslator ); 266cdf0e10cSrcweir if ( _rxConcreteListenerOrNull.is() ) 267cdf0e10cSrcweir { 268cdf0e10cSrcweir if ( pTranslator->getDelegator() == _rxConcreteListenerOrNull ) 269cdf0e10cSrcweir { 270cdf0e10cSrcweir impl_switchBindingListening_throw( false, xEventSourceTranslator ); 271cdf0e10cSrcweir m_aPropertyListeners.removeListener( xEventSourceTranslator ); 272cdf0e10cSrcweir break; 273cdf0e10cSrcweir } 274cdf0e10cSrcweir } 275cdf0e10cSrcweir else 276cdf0e10cSrcweir { 277cdf0e10cSrcweir impl_switchBindingListening_throw( false, xEventSourceTranslator ); 278cdf0e10cSrcweir } 279cdf0e10cSrcweir } 280cdf0e10cSrcweir } 281cdf0e10cSrcweir else 282cdf0e10cSrcweir { 283cdf0e10cSrcweir if ( _rxConcreteListenerOrNull.is() ) 284cdf0e10cSrcweir { 285cdf0e10cSrcweir Reference< XPropertyChangeListener > xEventSourceTranslator( new PropertyEventTranslation( _rxConcreteListenerOrNull, m_xBindableControl ) ); 286cdf0e10cSrcweir m_aPropertyListeners.addListener( xEventSourceTranslator ); 287cdf0e10cSrcweir impl_switchBindingListening_throw( true, xEventSourceTranslator ); 288cdf0e10cSrcweir } 289cdf0e10cSrcweir else 290cdf0e10cSrcweir { 291cdf0e10cSrcweir ::std::auto_ptr< ::cppu::OInterfaceIteratorHelper > pListenerIterator = m_aPropertyListeners.createIterator(); 292cdf0e10cSrcweir while ( pListenerIterator->hasMoreElements() ) 293cdf0e10cSrcweir { 294cdf0e10cSrcweir Reference< XPropertyChangeListener > xListener( pListenerIterator->next(), UNO_QUERY ); 295cdf0e10cSrcweir impl_switchBindingListening_throw( true, xListener ); 296cdf0e10cSrcweir } 297cdf0e10cSrcweir } 298cdf0e10cSrcweir } 299cdf0e10cSrcweir } 300cdf0e10cSrcweir 301cdf0e10cSrcweir //-------------------------------------------------------------------- revokeBindingListener(const Reference<XPropertyChangeListener> & _rxBindingListener)302cdf0e10cSrcweir void EFormsHelper::revokeBindingListener( const Reference< XPropertyChangeListener >& _rxBindingListener ) 303cdf0e10cSrcweir { 304cdf0e10cSrcweir impl_toggleBindingPropertyListening_throw( false, _rxBindingListener ); 305cdf0e10cSrcweir } 306cdf0e10cSrcweir 307cdf0e10cSrcweir //-------------------------------------------------------------------- getFormModelNames(::std::vector<::rtl::OUString> & _rModelNames) const308cdf0e10cSrcweir void EFormsHelper::getFormModelNames( ::std::vector< ::rtl::OUString >& /* [out] */ _rModelNames ) const SAL_THROW(()) 309cdf0e10cSrcweir { 310cdf0e10cSrcweir if ( m_xDocument.is() ) 311cdf0e10cSrcweir { 312cdf0e10cSrcweir try 313cdf0e10cSrcweir { 314cdf0e10cSrcweir _rModelNames.resize( 0 ); 315cdf0e10cSrcweir 316cdf0e10cSrcweir Reference< XNameContainer > xForms( m_xDocument->getXForms() ); 317cdf0e10cSrcweir OSL_ENSURE( xForms.is(), "EFormsHelper::getFormModelNames: invalid forms container!" ); 318cdf0e10cSrcweir if ( xForms.is() ) 319cdf0e10cSrcweir { 320cdf0e10cSrcweir Sequence< ::rtl::OUString > aModelNames = xForms->getElementNames(); 321cdf0e10cSrcweir _rModelNames.resize( aModelNames.getLength() ); 322cdf0e10cSrcweir ::std::copy( aModelNames.getConstArray(), aModelNames.getConstArray() + aModelNames.getLength(), 323cdf0e10cSrcweir _rModelNames.begin() 324cdf0e10cSrcweir ); 325cdf0e10cSrcweir } 326cdf0e10cSrcweir } 327cdf0e10cSrcweir catch( const Exception& ) 328cdf0e10cSrcweir { 329cdf0e10cSrcweir OSL_ENSURE( sal_False, "EFormsHelper::getFormModelNames: caught an exception!" ); 330cdf0e10cSrcweir } 331cdf0e10cSrcweir } 332cdf0e10cSrcweir } 333cdf0e10cSrcweir 334cdf0e10cSrcweir //-------------------------------------------------------------------- getBindingNames(const::rtl::OUString & _rModelName,::std::vector<::rtl::OUString> & _rBindingNames) const335cdf0e10cSrcweir void EFormsHelper::getBindingNames( const ::rtl::OUString& _rModelName, ::std::vector< ::rtl::OUString >& /* [out] */ _rBindingNames ) const SAL_THROW(()) 336cdf0e10cSrcweir { 337cdf0e10cSrcweir _rBindingNames.resize( 0 ); 338cdf0e10cSrcweir try 339cdf0e10cSrcweir { 340cdf0e10cSrcweir Reference< xforms::XModel > xModel( getFormModelByName( _rModelName ) ); 341cdf0e10cSrcweir if ( xModel.is() ) 342cdf0e10cSrcweir { 343cdf0e10cSrcweir Reference< XNameAccess > xBindings( xModel->getBindings(), UNO_QUERY ); 344cdf0e10cSrcweir OSL_ENSURE( xBindings.is(), "EFormsHelper::getBindingNames: invalid bindings container obtained from the model!" ); 345cdf0e10cSrcweir if ( xBindings.is() ) 346cdf0e10cSrcweir { 347cdf0e10cSrcweir Sequence< ::rtl::OUString > aNames = xBindings->getElementNames(); 348cdf0e10cSrcweir _rBindingNames.resize( aNames.getLength() ); 349cdf0e10cSrcweir ::std::copy( aNames.getConstArray(), aNames.getConstArray() + aNames.getLength(), _rBindingNames.begin() ); 350cdf0e10cSrcweir } 351cdf0e10cSrcweir } 352cdf0e10cSrcweir } 353cdf0e10cSrcweir catch( const Exception& ) 354cdf0e10cSrcweir { 355cdf0e10cSrcweir OSL_ENSURE( sal_False, "EFormsHelper::getBindingNames: caught an exception!" ); 356cdf0e10cSrcweir } 357cdf0e10cSrcweir } 358cdf0e10cSrcweir 359cdf0e10cSrcweir //-------------------------------------------------------------------- getFormModelByName(const::rtl::OUString & _rModelName) const360cdf0e10cSrcweir Reference< xforms::XModel > EFormsHelper::getFormModelByName( const ::rtl::OUString& _rModelName ) const SAL_THROW(()) 361cdf0e10cSrcweir { 362cdf0e10cSrcweir Reference< xforms::XModel > xReturn; 363cdf0e10cSrcweir try 364cdf0e10cSrcweir { 365cdf0e10cSrcweir Reference< XNameContainer > xForms( m_xDocument->getXForms() ); 366cdf0e10cSrcweir OSL_ENSURE( xForms.is(), "EFormsHelper::getFormModelByName: invalid forms container!" ); 367cdf0e10cSrcweir if ( xForms.is() ) 368cdf0e10cSrcweir OSL_VERIFY( xForms->getByName( _rModelName ) >>= xReturn ); 369cdf0e10cSrcweir } 370cdf0e10cSrcweir catch( const Exception& ) 371cdf0e10cSrcweir { 372cdf0e10cSrcweir OSL_ENSURE( sal_False, "EFormsHelper::getFormModelByName: caught an exception!" ); 373cdf0e10cSrcweir } 374cdf0e10cSrcweir return xReturn; 375cdf0e10cSrcweir } 376cdf0e10cSrcweir 377cdf0e10cSrcweir //-------------------------------------------------------------------- getCurrentFormModel() const378cdf0e10cSrcweir Reference< xforms::XModel > EFormsHelper::getCurrentFormModel() const SAL_THROW(()) 379cdf0e10cSrcweir { 380cdf0e10cSrcweir Reference< xforms::XModel > xModel; 381cdf0e10cSrcweir try 382cdf0e10cSrcweir { 383cdf0e10cSrcweir Reference< XPropertySet > xBinding( getCurrentBinding() ); 384cdf0e10cSrcweir if ( xBinding.is() ) 385cdf0e10cSrcweir { 386cdf0e10cSrcweir OSL_VERIFY( xBinding->getPropertyValue( PROPERTY_MODEL ) >>= xModel ); 387cdf0e10cSrcweir } 388cdf0e10cSrcweir } 389cdf0e10cSrcweir catch( const Exception& ) 390cdf0e10cSrcweir { 391cdf0e10cSrcweir OSL_ENSURE( sal_False, "EFormsHelper::getCurrentFormModel: caught an exception!" ); 392cdf0e10cSrcweir } 393cdf0e10cSrcweir return xModel; 394cdf0e10cSrcweir } 395cdf0e10cSrcweir 396cdf0e10cSrcweir //-------------------------------------------------------------------- getCurrentFormModelName() const397cdf0e10cSrcweir ::rtl::OUString EFormsHelper::getCurrentFormModelName() const SAL_THROW(()) 398cdf0e10cSrcweir { 399cdf0e10cSrcweir ::rtl::OUString sModelName; 400cdf0e10cSrcweir try 401cdf0e10cSrcweir { 402cdf0e10cSrcweir Reference< xforms::XModel > xFormsModel( getCurrentFormModel() ); 403cdf0e10cSrcweir if ( xFormsModel.is() ) 404cdf0e10cSrcweir sModelName = xFormsModel->getID(); 405cdf0e10cSrcweir } 406cdf0e10cSrcweir catch( const Exception& ) 407cdf0e10cSrcweir { 408cdf0e10cSrcweir OSL_ENSURE( sal_False, "EFormsHelper::getCurrentFormModel: caught an exception!" ); 409cdf0e10cSrcweir } 410cdf0e10cSrcweir return sModelName; 411cdf0e10cSrcweir } 412cdf0e10cSrcweir 413cdf0e10cSrcweir //-------------------------------------------------------------------- getCurrentBinding() const414cdf0e10cSrcweir Reference< XPropertySet > EFormsHelper::getCurrentBinding() const SAL_THROW(()) 415cdf0e10cSrcweir { 416cdf0e10cSrcweir Reference< XPropertySet > xBinding; 417cdf0e10cSrcweir 418cdf0e10cSrcweir try 419cdf0e10cSrcweir { 420cdf0e10cSrcweir if ( m_xBindableControl.is() ) 421cdf0e10cSrcweir xBinding = xBinding.query( m_xBindableControl->getValueBinding() ); 422cdf0e10cSrcweir } 423cdf0e10cSrcweir catch( const Exception& ) 424cdf0e10cSrcweir { 425cdf0e10cSrcweir OSL_ENSURE( sal_False, "EFormsHelper::getCurrentBinding: caught an exception!" ); 426cdf0e10cSrcweir } 427cdf0e10cSrcweir 428cdf0e10cSrcweir return xBinding; 429cdf0e10cSrcweir } 430cdf0e10cSrcweir 431cdf0e10cSrcweir //-------------------------------------------------------------------- getCurrentBindingName() const432cdf0e10cSrcweir ::rtl::OUString EFormsHelper::getCurrentBindingName() const SAL_THROW(()) 433cdf0e10cSrcweir { 434cdf0e10cSrcweir ::rtl::OUString sBindingName; 435cdf0e10cSrcweir try 436cdf0e10cSrcweir { 437cdf0e10cSrcweir Reference< XPropertySet > xBinding( getCurrentBinding() ); 438cdf0e10cSrcweir if ( xBinding.is() ) 439cdf0e10cSrcweir xBinding->getPropertyValue( PROPERTY_BINDING_ID ) >>= sBindingName; 440cdf0e10cSrcweir } 441cdf0e10cSrcweir catch( const Exception& ) 442cdf0e10cSrcweir { 443cdf0e10cSrcweir OSL_ENSURE( sal_False, "EFormsHelper::getCurrentBindingName: caught an exception!" ); 444cdf0e10cSrcweir } 445cdf0e10cSrcweir return sBindingName; 446cdf0e10cSrcweir } 447cdf0e10cSrcweir 448cdf0e10cSrcweir //-------------------------------------------------------------------- getCurrentListSourceBinding() const449cdf0e10cSrcweir Reference< XListEntrySource > EFormsHelper::getCurrentListSourceBinding() const SAL_THROW(()) 450cdf0e10cSrcweir { 451cdf0e10cSrcweir Reference< XListEntrySource > xReturn; 452cdf0e10cSrcweir try 453cdf0e10cSrcweir { 454cdf0e10cSrcweir Reference< XListEntrySink > xAsSink( m_xControlModel, UNO_QUERY ); 455cdf0e10cSrcweir OSL_ENSURE( xAsSink.is(), "EFormsHelper::getCurrentListSourceBinding: you should have used isListEntrySink before!" ); 456cdf0e10cSrcweir if ( xAsSink.is() ) 457cdf0e10cSrcweir xReturn = xAsSink->getListEntrySource(); 458cdf0e10cSrcweir } 459cdf0e10cSrcweir catch( const Exception& ) 460cdf0e10cSrcweir { 461cdf0e10cSrcweir OSL_ENSURE( sal_False, "EFormsHelper::getCurrentListSourceBinding: caught an exception!" ); 462cdf0e10cSrcweir } 463cdf0e10cSrcweir return xReturn; 464cdf0e10cSrcweir } 465cdf0e10cSrcweir 466cdf0e10cSrcweir //-------------------------------------------------------------------- setListSourceBinding(const Reference<XListEntrySource> & _rxListSource)467cdf0e10cSrcweir void EFormsHelper::setListSourceBinding( const Reference< XListEntrySource >& _rxListSource ) SAL_THROW(()) 468cdf0e10cSrcweir { 469cdf0e10cSrcweir try 470cdf0e10cSrcweir { 471cdf0e10cSrcweir Reference< XListEntrySink > xAsSink( m_xControlModel, UNO_QUERY ); 472cdf0e10cSrcweir OSL_ENSURE( xAsSink.is(), "EFormsHelper::setListSourceBinding: you should have used isListEntrySink before!" ); 473cdf0e10cSrcweir if ( xAsSink.is() ) 474cdf0e10cSrcweir xAsSink->setListEntrySource( _rxListSource ); 475cdf0e10cSrcweir } 476cdf0e10cSrcweir catch( const Exception& ) 477cdf0e10cSrcweir { 478cdf0e10cSrcweir OSL_ENSURE( sal_False, "EFormsHelper::setListSourceBinding: caught an exception!" ); 479cdf0e10cSrcweir } 480cdf0e10cSrcweir } 481cdf0e10cSrcweir 482cdf0e10cSrcweir //-------------------------------------------------------------------- setBinding(const Reference<::com::sun::star::beans::XPropertySet> & _rxBinding)483cdf0e10cSrcweir void EFormsHelper::setBinding( const Reference< ::com::sun::star::beans::XPropertySet >& _rxBinding ) SAL_THROW(()) 484cdf0e10cSrcweir { 485cdf0e10cSrcweir if ( !m_xBindableControl.is() ) 486cdf0e10cSrcweir return; 487cdf0e10cSrcweir 488cdf0e10cSrcweir try 489cdf0e10cSrcweir { 490cdf0e10cSrcweir Reference< XPropertySet > xOldBinding( m_xBindableControl->getValueBinding(), UNO_QUERY ); 491cdf0e10cSrcweir 492cdf0e10cSrcweir Reference< XValueBinding > xBinding( _rxBinding, UNO_QUERY ); 493cdf0e10cSrcweir OSL_ENSURE( xBinding.is() || !_rxBinding.is(), "EFormsHelper::setBinding: invalid binding!" ); 494cdf0e10cSrcweir 495cdf0e10cSrcweir impl_toggleBindingPropertyListening_throw( false, NULL ); 496cdf0e10cSrcweir m_xBindableControl->setValueBinding( xBinding ); 497cdf0e10cSrcweir impl_toggleBindingPropertyListening_throw( true, NULL ); 498cdf0e10cSrcweir 499cdf0e10cSrcweir ::std::set< ::rtl::OUString > aSet; 500cdf0e10cSrcweir firePropertyChanges( xOldBinding, _rxBinding, aSet ); 501cdf0e10cSrcweir } 502cdf0e10cSrcweir catch( const Exception& ) 503cdf0e10cSrcweir { 504cdf0e10cSrcweir OSL_ENSURE( sal_False, "EFormsHelper::setBinding: caught an exception!" ); 505cdf0e10cSrcweir } 506cdf0e10cSrcweir } 507cdf0e10cSrcweir 508cdf0e10cSrcweir //-------------------------------------------------------------------- getOrCreateBindingForModel(const::rtl::OUString & _rTargetModel,const::rtl::OUString & _rBindingName) const509cdf0e10cSrcweir Reference< XPropertySet > EFormsHelper::getOrCreateBindingForModel( const ::rtl::OUString& _rTargetModel, const ::rtl::OUString& _rBindingName ) const SAL_THROW(()) 510cdf0e10cSrcweir { 511cdf0e10cSrcweir OSL_ENSURE( _rBindingName.getLength(), "EFormsHelper::getOrCreateBindingForModel: invalid binding name!" ); 512cdf0e10cSrcweir return implGetOrCreateBinding( _rTargetModel, _rBindingName ); 513cdf0e10cSrcweir } 514cdf0e10cSrcweir 515cdf0e10cSrcweir //-------------------------------------------------------------------- implGetOrCreateBinding(const::rtl::OUString & _rTargetModel,const::rtl::OUString & _rBindingName) const516cdf0e10cSrcweir Reference< XPropertySet > EFormsHelper::implGetOrCreateBinding( const ::rtl::OUString& _rTargetModel, const ::rtl::OUString& _rBindingName ) const SAL_THROW(()) 517cdf0e10cSrcweir { 518cdf0e10cSrcweir OSL_ENSURE( !( !_rTargetModel.getLength() && _rBindingName .getLength() ), "EFormsHelper::implGetOrCreateBinding: no model, but a binding name?" ); 519cdf0e10cSrcweir 520cdf0e10cSrcweir Reference< XPropertySet > xBinding; 521cdf0e10cSrcweir try 522cdf0e10cSrcweir { 523cdf0e10cSrcweir ::rtl::OUString sTargetModel( _rTargetModel ); 524cdf0e10cSrcweir // determine the model which the binding should belong to 525cdf0e10cSrcweir if ( !sTargetModel.getLength() ) 526cdf0e10cSrcweir { 527cdf0e10cSrcweir ::std::vector< ::rtl::OUString > aModelNames; 528cdf0e10cSrcweir getFormModelNames( aModelNames ); 529cdf0e10cSrcweir if ( !aModelNames.empty() ) 530cdf0e10cSrcweir sTargetModel = *aModelNames.begin(); 531cdf0e10cSrcweir OSL_ENSURE( sTargetModel.getLength(), "EFormsHelper::implGetOrCreateBinding: unable to obtain a default model!" ); 532cdf0e10cSrcweir } 533cdf0e10cSrcweir Reference< xforms::XModel > xModel( getFormModelByName( sTargetModel ) ); 534cdf0e10cSrcweir Reference< XNameAccess > xBindingNames( xModel.is() ? xModel->getBindings() : Reference< XSet >(), UNO_QUERY ); 535cdf0e10cSrcweir if ( xBindingNames.is() ) 536cdf0e10cSrcweir { 537cdf0e10cSrcweir // get or create the binding instance 538cdf0e10cSrcweir if ( _rBindingName.getLength() ) 539cdf0e10cSrcweir { 540cdf0e10cSrcweir if ( xBindingNames->hasByName( _rBindingName ) ) 541cdf0e10cSrcweir OSL_VERIFY( xBindingNames->getByName( _rBindingName ) >>= xBinding ); 542cdf0e10cSrcweir else 543cdf0e10cSrcweir { 544cdf0e10cSrcweir xBinding = xModel->createBinding( ); 545cdf0e10cSrcweir if ( xBinding.is() ) 546cdf0e10cSrcweir { 547cdf0e10cSrcweir xBinding->setPropertyValue( PROPERTY_BINDING_ID, makeAny( _rBindingName ) ); 548cdf0e10cSrcweir xModel->getBindings()->insert( makeAny( xBinding ) ); 549cdf0e10cSrcweir } 550cdf0e10cSrcweir } 551cdf0e10cSrcweir } 552cdf0e10cSrcweir else 553cdf0e10cSrcweir { 554cdf0e10cSrcweir xBinding = xModel->createBinding( ); 555cdf0e10cSrcweir if ( xBinding.is() ) 556cdf0e10cSrcweir { 557cdf0e10cSrcweir // find a nice name for it 558cdf0e10cSrcweir String sBaseName( PcrRes( RID_STR_BINDING_UI_NAME ) ); 559cdf0e10cSrcweir sBaseName += String::CreateFromAscii( " " ); 560cdf0e10cSrcweir String sNewName; 561cdf0e10cSrcweir sal_Int32 nNumber = 1; 562cdf0e10cSrcweir do 563cdf0e10cSrcweir { 564cdf0e10cSrcweir sNewName = sBaseName + ::rtl::OUString::valueOf( nNumber++ ); 565cdf0e10cSrcweir } 566cdf0e10cSrcweir while ( xBindingNames->hasByName( sNewName ) ); 567cdf0e10cSrcweir Reference< XNamed > xName( xBinding, UNO_QUERY_THROW ); 568cdf0e10cSrcweir xName->setName( sNewName ); 569cdf0e10cSrcweir // and insert into the model 570cdf0e10cSrcweir xModel->getBindings()->insert( makeAny( xBinding ) ); 571cdf0e10cSrcweir } 572cdf0e10cSrcweir } 573cdf0e10cSrcweir } 574cdf0e10cSrcweir } 575cdf0e10cSrcweir catch( const Exception& ) 576cdf0e10cSrcweir { 577cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 578cdf0e10cSrcweir } 579cdf0e10cSrcweir 580cdf0e10cSrcweir return xBinding; 581cdf0e10cSrcweir } 582cdf0e10cSrcweir 583cdf0e10cSrcweir //-------------------------------------------------------------------- 584cdf0e10cSrcweir namespace 585cdf0e10cSrcweir { 586cdf0e10cSrcweir //................................................................ 587cdf0e10cSrcweir struct PropertyBagInserter : public ::std::unary_function< Property, void > 588cdf0e10cSrcweir { 589cdf0e10cSrcweir private: 590cdf0e10cSrcweir PropertyBag& m_rProperties; 591cdf0e10cSrcweir 592cdf0e10cSrcweir public: PropertyBagInserterpcr::__anon0f4e8eb90211::PropertyBagInserter593cdf0e10cSrcweir PropertyBagInserter( PropertyBag& rProperties ) : m_rProperties( rProperties ) { } 594cdf0e10cSrcweir operator ()pcr::__anon0f4e8eb90211::PropertyBagInserter595cdf0e10cSrcweir void operator()( const Property& _rProp ) 596cdf0e10cSrcweir { 597cdf0e10cSrcweir m_rProperties.insert( _rProp ); 598cdf0e10cSrcweir } 599cdf0e10cSrcweir }; 600cdf0e10cSrcweir 601cdf0e10cSrcweir //................................................................ collectPropertiesGetInfo(const Reference<XPropertySet> & _rxProps,PropertyBag & _rBag)602cdf0e10cSrcweir Reference< XPropertySetInfo > collectPropertiesGetInfo( const Reference< XPropertySet >& _rxProps, PropertyBag& _rBag ) 603cdf0e10cSrcweir { 604cdf0e10cSrcweir Reference< XPropertySetInfo > xInfo; 605cdf0e10cSrcweir if ( _rxProps.is() ) 606cdf0e10cSrcweir xInfo = _rxProps->getPropertySetInfo(); 607cdf0e10cSrcweir if ( xInfo.is() ) 608cdf0e10cSrcweir { 609cdf0e10cSrcweir Sequence< Property > aProperties = xInfo->getProperties(); 610cdf0e10cSrcweir ::std::for_each( aProperties.getConstArray(), aProperties.getConstArray() + aProperties.getLength(), 611cdf0e10cSrcweir PropertyBagInserter( _rBag ) 612cdf0e10cSrcweir ); 613cdf0e10cSrcweir } 614cdf0e10cSrcweir return xInfo; 615cdf0e10cSrcweir } 616cdf0e10cSrcweir } 617cdf0e10cSrcweir 618cdf0e10cSrcweir //-------------------------------------------------------------------- getModelElementUIName(const EFormsHelper::ModelElementType _eType,const Reference<XPropertySet> & _rxElement) const619cdf0e10cSrcweir ::rtl::OUString EFormsHelper::getModelElementUIName( const EFormsHelper::ModelElementType _eType, const Reference< XPropertySet >& _rxElement ) const SAL_THROW(()) 620cdf0e10cSrcweir { 621cdf0e10cSrcweir ::rtl::OUString sUIName; 622cdf0e10cSrcweir try 623cdf0e10cSrcweir { 624cdf0e10cSrcweir // determine the model which the element belongs to 625cdf0e10cSrcweir Reference< xforms::XFormsUIHelper1 > xHelper; 626cdf0e10cSrcweir if ( _rxElement.is() ) 627cdf0e10cSrcweir _rxElement->getPropertyValue( PROPERTY_MODEL ) >>= xHelper; 628cdf0e10cSrcweir OSL_ENSURE( xHelper.is(), "EFormsHelper::getModelElementUIName: invalid element or model!" ); 629cdf0e10cSrcweir if ( xHelper.is() ) 630cdf0e10cSrcweir { 631cdf0e10cSrcweir ::rtl::OUString sElementName = ( _eType == Submission ) ? xHelper->getSubmissionName( _rxElement, sal_True ) : xHelper->getBindingName( _rxElement, sal_True ); 632cdf0e10cSrcweir Reference< xforms::XModel > xModel( xHelper, UNO_QUERY_THROW ); 633cdf0e10cSrcweir sUIName = composeModelElementUIName( xModel->getID(), sElementName ); 634cdf0e10cSrcweir } 635cdf0e10cSrcweir } 636cdf0e10cSrcweir catch( const Exception& ) 637cdf0e10cSrcweir { 638cdf0e10cSrcweir OSL_ENSURE( sal_False, "EFormsHelper::getModelElementUIName: caught an exception!" ); 639cdf0e10cSrcweir } 640cdf0e10cSrcweir 641cdf0e10cSrcweir return sUIName; 642cdf0e10cSrcweir } 643cdf0e10cSrcweir 644cdf0e10cSrcweir //-------------------------------------------------------------------- getModelElementFromUIName(const EFormsHelper::ModelElementType _eType,const::rtl::OUString & _rUIName) const645cdf0e10cSrcweir Reference< XPropertySet > EFormsHelper::getModelElementFromUIName( const EFormsHelper::ModelElementType _eType, const ::rtl::OUString& _rUIName ) const SAL_THROW(()) 646cdf0e10cSrcweir { 647cdf0e10cSrcweir const MapStringToPropertySet& rMapUINameToElement( ( _eType == Submission ) ? m_aSubmissionUINames : m_aBindingUINames ); 648cdf0e10cSrcweir MapStringToPropertySet::const_iterator pos = rMapUINameToElement.find( _rUIName ); 649cdf0e10cSrcweir OSL_ENSURE( pos != rMapUINameToElement.end(), "EFormsHelper::getModelElementFromUIName: didn't find it!" ); 650cdf0e10cSrcweir 651cdf0e10cSrcweir return ( pos != rMapUINameToElement.end() ) ? pos->second : Reference< XPropertySet >(); 652cdf0e10cSrcweir } 653cdf0e10cSrcweir 654cdf0e10cSrcweir //-------------------------------------------------------------------- getAllElementUINames(const ModelElementType _eType,::std::vector<::rtl::OUString> & _rElementNames,bool _bPrepentEmptyEntry)655cdf0e10cSrcweir void EFormsHelper::getAllElementUINames( const ModelElementType _eType, ::std::vector< ::rtl::OUString >& /* [out] */ _rElementNames, bool _bPrepentEmptyEntry ) 656cdf0e10cSrcweir { 657cdf0e10cSrcweir MapStringToPropertySet& rMapUINameToElement( ( _eType == Submission ) ? m_aSubmissionUINames : m_aBindingUINames ); 658cdf0e10cSrcweir rMapUINameToElement.clear(); 659cdf0e10cSrcweir _rElementNames.resize( 0 ); 660cdf0e10cSrcweir 661cdf0e10cSrcweir if ( _bPrepentEmptyEntry ) 662cdf0e10cSrcweir rMapUINameToElement[ ::rtl::OUString() ] = Reference< XPropertySet >(); 663cdf0e10cSrcweir 664cdf0e10cSrcweir try 665cdf0e10cSrcweir { 666cdf0e10cSrcweir // obtain the model names 667cdf0e10cSrcweir ::std::vector< ::rtl::OUString > aModels; 668cdf0e10cSrcweir getFormModelNames( aModels ); 669cdf0e10cSrcweir _rElementNames.reserve( aModels.size() * 2 ); // heuristics 670cdf0e10cSrcweir 671cdf0e10cSrcweir // for every model, obtain the element 672cdf0e10cSrcweir for ( ::std::vector< ::rtl::OUString >::const_iterator pModelName = aModels.begin(); 673cdf0e10cSrcweir pModelName != aModels.end(); 674cdf0e10cSrcweir ++pModelName 675cdf0e10cSrcweir ) 676cdf0e10cSrcweir { 677cdf0e10cSrcweir Reference< xforms::XModel > xModel = getFormModelByName( *pModelName ); 678cdf0e10cSrcweir OSL_ENSURE( xModel.is(), "EFormsHelper::getAllElementUINames: inconsistency in the models!" ); 679cdf0e10cSrcweir Reference< xforms::XFormsUIHelper1 > xHelper( xModel, UNO_QUERY ); 680cdf0e10cSrcweir 681cdf0e10cSrcweir Reference< XIndexAccess > xElements; 682cdf0e10cSrcweir if ( xModel.is() ) 683cdf0e10cSrcweir xElements = xElements.query( ( _eType == Submission ) ? xModel->getSubmissions() : xModel->getBindings() ); 684cdf0e10cSrcweir if ( !xElements.is() ) 685cdf0e10cSrcweir break; 686cdf0e10cSrcweir 687cdf0e10cSrcweir sal_Int32 nElementCount = xElements->getCount(); 688cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nElementCount; ++i ) 689cdf0e10cSrcweir { 690cdf0e10cSrcweir Reference< XPropertySet > xElement( xElements->getByIndex( i ), UNO_QUERY ); 691cdf0e10cSrcweir OSL_ENSURE( xElement.is(), "EFormsHelper::getAllElementUINames: empty element!" ); 692cdf0e10cSrcweir if ( !xElement.is() ) 693cdf0e10cSrcweir continue; 694cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 695cdf0e10cSrcweir { 696cdf0e10cSrcweir Reference< xforms::XModel > xElementsModel; 697cdf0e10cSrcweir xElement->getPropertyValue( PROPERTY_MODEL ) >>= xElementsModel; 698cdf0e10cSrcweir OSL_ENSURE( xElementsModel == xModel, "EFormsHelper::getAllElementUINames: inconsistency in the model-element relationship!" ); 699cdf0e10cSrcweir if ( !( xElementsModel == xModel ) ) 700cdf0e10cSrcweir xElement->setPropertyValue( PROPERTY_MODEL, makeAny( xModel ) ); 701cdf0e10cSrcweir } 702cdf0e10cSrcweir #endif 703cdf0e10cSrcweir ::rtl::OUString sElementName = ( _eType == Submission ) ? xHelper->getSubmissionName( xElement, sal_True ) : xHelper->getBindingName( xElement, sal_True ); 704cdf0e10cSrcweir ::rtl::OUString sUIName = composeModelElementUIName( *pModelName, sElementName ); 705cdf0e10cSrcweir 706cdf0e10cSrcweir OSL_ENSURE( rMapUINameToElement.find( sUIName ) == rMapUINameToElement.end(), "EFormsHelper::getAllElementUINames: duplicate name!" ); 707cdf0e10cSrcweir rMapUINameToElement.insert( MapStringToPropertySet::value_type( sUIName, xElement ) ); 708cdf0e10cSrcweir } 709cdf0e10cSrcweir } 710cdf0e10cSrcweir } 711cdf0e10cSrcweir catch( const Exception& ) 712cdf0e10cSrcweir { 713cdf0e10cSrcweir OSL_ENSURE( sal_False, "EFormsHelper::getAllElementUINames: caught an exception!" ); 714cdf0e10cSrcweir } 715cdf0e10cSrcweir 716cdf0e10cSrcweir _rElementNames.resize( rMapUINameToElement.size() ); 717cdf0e10cSrcweir ::std::transform( rMapUINameToElement.begin(), rMapUINameToElement.end(), _rElementNames.begin(), ::std::select1st< MapStringToPropertySet::value_type >() ); 718cdf0e10cSrcweir } 719cdf0e10cSrcweir 720cdf0e10cSrcweir //-------------------------------------------------------------------- firePropertyChange(const::rtl::OUString & _rName,const Any & _rOldValue,const Any & _rNewValue) const721cdf0e10cSrcweir void EFormsHelper::firePropertyChange( const ::rtl::OUString& _rName, const Any& _rOldValue, const Any& _rNewValue ) const 722cdf0e10cSrcweir { 723cdf0e10cSrcweir if ( m_aPropertyListeners.empty() ) 724cdf0e10cSrcweir return; 725cdf0e10cSrcweir 726cdf0e10cSrcweir if ( _rOldValue == _rNewValue ) 727cdf0e10cSrcweir return; 728cdf0e10cSrcweir 729cdf0e10cSrcweir try 730cdf0e10cSrcweir { 731cdf0e10cSrcweir PropertyChangeEvent aEvent; 732cdf0e10cSrcweir 733cdf0e10cSrcweir aEvent.Source = m_xBindableControl.get(); 734cdf0e10cSrcweir aEvent.PropertyName = _rName; 735cdf0e10cSrcweir aEvent.OldValue = _rOldValue; 736cdf0e10cSrcweir aEvent.NewValue = _rNewValue; 737cdf0e10cSrcweir 738cdf0e10cSrcweir const_cast< EFormsHelper* >( this )->m_aPropertyListeners.notify( aEvent, &XPropertyChangeListener::propertyChange ); 739cdf0e10cSrcweir } 740cdf0e10cSrcweir catch( const Exception& ) 741cdf0e10cSrcweir { 742cdf0e10cSrcweir OSL_ENSURE( sal_False, "EFormsHelper::firePropertyChange: caught an exception!" ); 743cdf0e10cSrcweir } 744cdf0e10cSrcweir } 745cdf0e10cSrcweir 746cdf0e10cSrcweir //-------------------------------------------------------------------- firePropertyChanges(const Reference<XPropertySet> & _rxOldProps,const Reference<XPropertySet> & _rxNewProps,::std::set<::rtl::OUString> & _rFilter) const747cdf0e10cSrcweir void EFormsHelper::firePropertyChanges( const Reference< XPropertySet >& _rxOldProps, const Reference< XPropertySet >& _rxNewProps, ::std::set< ::rtl::OUString >& _rFilter ) const 748cdf0e10cSrcweir { 749cdf0e10cSrcweir if ( m_aPropertyListeners.empty() ) 750cdf0e10cSrcweir return; 751cdf0e10cSrcweir 752cdf0e10cSrcweir try 753cdf0e10cSrcweir { 754cdf0e10cSrcweir PropertyBag aProperties; 755cdf0e10cSrcweir Reference< XPropertySetInfo > xOldInfo = collectPropertiesGetInfo( _rxOldProps, aProperties ); 756cdf0e10cSrcweir Reference< XPropertySetInfo > xNewInfo = collectPropertiesGetInfo( _rxNewProps, aProperties ); 757cdf0e10cSrcweir 758cdf0e10cSrcweir for ( PropertyBag::const_iterator aProp = aProperties.begin(); 759cdf0e10cSrcweir aProp != aProperties.end(); 760cdf0e10cSrcweir ++aProp 761cdf0e10cSrcweir ) 762cdf0e10cSrcweir { 763cdf0e10cSrcweir if ( _rFilter.find( aProp->Name ) != _rFilter.end() ) 764cdf0e10cSrcweir continue; 765cdf0e10cSrcweir 766cdf0e10cSrcweir Any aOldValue( NULL, aProp->Type ); 767cdf0e10cSrcweir if ( xOldInfo.is() && xOldInfo->hasPropertyByName( aProp->Name ) ) 768cdf0e10cSrcweir aOldValue = _rxOldProps->getPropertyValue( aProp->Name ); 769cdf0e10cSrcweir 770cdf0e10cSrcweir Any aNewValue( NULL, aProp->Type ); 771cdf0e10cSrcweir if ( xNewInfo.is() && xNewInfo->hasPropertyByName( aProp->Name ) ) 772cdf0e10cSrcweir aNewValue = _rxNewProps->getPropertyValue( aProp->Name ); 773cdf0e10cSrcweir 774cdf0e10cSrcweir firePropertyChange( aProp->Name, aOldValue, aNewValue ); 775cdf0e10cSrcweir } 776cdf0e10cSrcweir } 777cdf0e10cSrcweir catch( const Exception& ) 778cdf0e10cSrcweir { 779cdf0e10cSrcweir OSL_ENSURE( sal_False, "EFormsHelper::firePropertyChanges: caught an exception!" ); 780cdf0e10cSrcweir } 781cdf0e10cSrcweir } 782cdf0e10cSrcweir 783cdf0e10cSrcweir //........................................................................ 784cdf0e10cSrcweir } // namespace pcr 785cdf0e10cSrcweir //........................................................................ 786cdf0e10cSrcweir 787