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 // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_extensions.hxx" 30*cdf0e10cSrcweir #include "eformspropertyhandler.hxx" 31*cdf0e10cSrcweir #include "formstrings.hxx" 32*cdf0e10cSrcweir #include "formmetadata.hxx" 33*cdf0e10cSrcweir #include "propctrlr.hrc" 34*cdf0e10cSrcweir #include "formbrowsertools.hxx" 35*cdf0e10cSrcweir #include "eformshelper.hxx" 36*cdf0e10cSrcweir #include "handlerhelper.hxx" 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir /** === begin UNO includes === **/ 39*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/inspection/PropertyControlType.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/inspection/XObjectInspectorUI.hpp> 42*cdf0e10cSrcweir /** === end UNO includes === **/ 43*cdf0e10cSrcweir #include <tools/debug.hxx> 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir #include <functional> 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir //------------------------------------------------------------------------ 48*cdf0e10cSrcweir extern "C" void SAL_CALL createRegistryInfo_EFormsPropertyHandler() 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir ::pcr::EFormsPropertyHandler::registerImplementation(); 51*cdf0e10cSrcweir } 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir //........................................................................ 54*cdf0e10cSrcweir namespace pcr 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir //........................................................................ 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir using namespace ::com::sun::star; 59*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 60*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 61*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 62*cdf0e10cSrcweir using namespace ::com::sun::star::xforms; 63*cdf0e10cSrcweir using namespace ::com::sun::star::script; 64*cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs; 65*cdf0e10cSrcweir using namespace ::com::sun::star::form::binding; 66*cdf0e10cSrcweir using namespace ::com::sun::star::inspection; 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir //==================================================================== 69*cdf0e10cSrcweir //= EFormsPropertyHandler 70*cdf0e10cSrcweir //==================================================================== 71*cdf0e10cSrcweir DBG_NAME( EFormsPropertyHandler ) 72*cdf0e10cSrcweir //-------------------------------------------------------------------- 73*cdf0e10cSrcweir EFormsPropertyHandler::EFormsPropertyHandler( const Reference< XComponentContext >& _rxContext ) 74*cdf0e10cSrcweir :EFormsPropertyHandler_Base( _rxContext ) 75*cdf0e10cSrcweir ,m_bSimulatingModelChange( false ) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir DBG_CTOR( EFormsPropertyHandler, NULL ); 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir //-------------------------------------------------------------------- 81*cdf0e10cSrcweir EFormsPropertyHandler::~EFormsPropertyHandler( ) 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir DBG_DTOR( EFormsPropertyHandler, NULL ); 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir //-------------------------------------------------------------------- 87*cdf0e10cSrcweir ::rtl::OUString SAL_CALL EFormsPropertyHandler::getImplementationName_static( ) throw (RuntimeException) 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.EFormsPropertyHandler" ) ); 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir //-------------------------------------------------------------------- 93*cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL EFormsPropertyHandler::getSupportedServiceNames_static( ) throw (RuntimeException) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir Sequence< ::rtl::OUString > aSupported( 1 ); 96*cdf0e10cSrcweir aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.XMLFormsPropertyHandler" ) ); 97*cdf0e10cSrcweir return aSupported; 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir //-------------------------------------------------------------------- 101*cdf0e10cSrcweir ::rtl::OUString EFormsPropertyHandler::getModelNamePropertyValue() const 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir ::rtl::OUString sModelName = m_pHelper->getCurrentFormModelName(); 104*cdf0e10cSrcweir if ( !sModelName.getLength() ) 105*cdf0e10cSrcweir sModelName = m_sBindingLessModelName; 106*cdf0e10cSrcweir return sModelName; 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir //-------------------------------------------------------------------- 110*cdf0e10cSrcweir Any SAL_CALL EFormsPropertyHandler::getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 113*cdf0e10cSrcweir PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) ); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir OSL_ENSURE( m_pHelper.get(), "EFormsPropertyHandler::getPropertyValue: we don't have any SupportedProperties!" ); 116*cdf0e10cSrcweir // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir Any aReturn; 119*cdf0e10cSrcweir try 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir switch ( nPropId ) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir case PROPERTY_ID_LIST_BINDING: 124*cdf0e10cSrcweir aReturn <<= m_pHelper->getCurrentListSourceBinding(); 125*cdf0e10cSrcweir break; 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir case PROPERTY_ID_XML_DATA_MODEL: 128*cdf0e10cSrcweir aReturn <<= getModelNamePropertyValue(); 129*cdf0e10cSrcweir break; 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir case PROPERTY_ID_BINDING_NAME: 132*cdf0e10cSrcweir aReturn <<= m_pHelper->getCurrentBindingName(); 133*cdf0e10cSrcweir break; 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir case PROPERTY_ID_BIND_EXPRESSION: 136*cdf0e10cSrcweir case PROPERTY_ID_XSD_CONSTRAINT: 137*cdf0e10cSrcweir case PROPERTY_ID_XSD_CALCULATION: 138*cdf0e10cSrcweir case PROPERTY_ID_XSD_REQUIRED: 139*cdf0e10cSrcweir case PROPERTY_ID_XSD_RELEVANT: 140*cdf0e10cSrcweir case PROPERTY_ID_XSD_READONLY: 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir Reference< XPropertySet > xBindingProps( m_pHelper->getCurrentBinding() ); 143*cdf0e10cSrcweir if ( xBindingProps.is() ) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir aReturn = xBindingProps->getPropertyValue( _rPropertyName ); 146*cdf0e10cSrcweir DBG_ASSERT( aReturn.getValueType().equals( ::getCppuType( static_cast< ::rtl::OUString* >( NULL ) ) ), 147*cdf0e10cSrcweir "EFormsPropertyHandler::getPropertyValue: invalid BindingExpression value type!" ); 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir else 150*cdf0e10cSrcweir aReturn <<= ::rtl::OUString(); 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir break; 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir default: 155*cdf0e10cSrcweir DBG_ERROR( "EFormsPropertyHandler::getPropertyValue: cannot handle this property!" ); 156*cdf0e10cSrcweir break; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir catch( const Exception& ) 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 162*cdf0e10cSrcweir ::rtl::OString sMessage( "EFormsPropertyHandler::getPropertyValue: caught an exception!" ); 163*cdf0e10cSrcweir sMessage += "\n(have been asked for the \""; 164*cdf0e10cSrcweir sMessage += ::rtl::OString( _rPropertyName.getStr(), _rPropertyName.getLength(), RTL_TEXTENCODING_ASCII_US ); 165*cdf0e10cSrcweir sMessage += "\" property.)"; 166*cdf0e10cSrcweir OSL_ENSURE( sal_False, sMessage.getStr() ); 167*cdf0e10cSrcweir #endif 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir return aReturn; 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir //-------------------------------------------------------------------- 173*cdf0e10cSrcweir void SAL_CALL EFormsPropertyHandler::setPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 176*cdf0e10cSrcweir PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) ); 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir OSL_ENSURE( m_pHelper.get(), "EFormsPropertyHandler::setPropertyValue: we don't have any SupportedProperties!" ); 179*cdf0e10cSrcweir // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir try 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir Any aOldValue = getPropertyValue( _rPropertyName ); 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir switch ( nPropId ) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir case PROPERTY_ID_LIST_BINDING: 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir Reference< XListEntrySource > xSource; 190*cdf0e10cSrcweir OSL_VERIFY( _rValue >>= xSource ); 191*cdf0e10cSrcweir m_pHelper->setListSourceBinding( xSource ); 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir break; 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir case PROPERTY_ID_XML_DATA_MODEL: 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir OSL_VERIFY( _rValue >>= m_sBindingLessModelName ); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir // if the model changed, reset the binding to NULL 200*cdf0e10cSrcweir if ( m_pHelper->getCurrentFormModelName() != m_sBindingLessModelName ) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir ::rtl::OUString sOldBindingName = m_pHelper->getCurrentBindingName(); 203*cdf0e10cSrcweir m_pHelper->setBinding( NULL ); 204*cdf0e10cSrcweir firePropertyChange( PROPERTY_BINDING_NAME, PROPERTY_ID_BINDING_NAME, 205*cdf0e10cSrcweir makeAny( sOldBindingName ), makeAny( ::rtl::OUString() ) ); 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir break; 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir case PROPERTY_ID_BINDING_NAME: 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir ::rtl::OUString sNewBindingName; 213*cdf0e10cSrcweir OSL_VERIFY( _rValue >>= sNewBindingName ); 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir bool bPreviouslyEmptyModel = !m_pHelper->getCurrentFormModel().is(); 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir Reference< XPropertySet > xNewBinding; 218*cdf0e10cSrcweir if ( sNewBindingName.getLength() ) 219*cdf0e10cSrcweir // obtain the binding with this name, for the current model 220*cdf0e10cSrcweir xNewBinding = m_pHelper->getOrCreateBindingForModel( getModelNamePropertyValue(), sNewBindingName ); 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir m_pHelper->setBinding( xNewBinding ); 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir if ( bPreviouslyEmptyModel ) 225*cdf0e10cSrcweir { // simulate a property change for the model property 226*cdf0e10cSrcweir // This is because we "simulate" the Model property by remembering the 227*cdf0e10cSrcweir // value ourself. Other instances might, however, not know this value, 228*cdf0e10cSrcweir // but prefer to retrieve it somewhere else - e.g. from the EFormsHelper 229*cdf0e10cSrcweir // 230*cdf0e10cSrcweir // The really correct solution would be if *all* property handlers 231*cdf0e10cSrcweir // obtain a "current property value" for *all* properties from a central 232*cdf0e10cSrcweir // instance. Then, handler A could ask it for the value of property 233*cdf0e10cSrcweir // X, and this request would be re-routed to handler B, which ultimately 234*cdf0e10cSrcweir // knows the current value. 235*cdf0e10cSrcweir // However, there's no such mechanism in place currently. 236*cdf0e10cSrcweir m_bSimulatingModelChange = true; 237*cdf0e10cSrcweir firePropertyChange( PROPERTY_XML_DATA_MODEL, PROPERTY_ID_XML_DATA_MODEL, 238*cdf0e10cSrcweir makeAny( ::rtl::OUString() ), makeAny( getModelNamePropertyValue() ) ); 239*cdf0e10cSrcweir m_bSimulatingModelChange = false; 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir break; 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir case PROPERTY_ID_BIND_EXPRESSION: 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir Reference< XPropertySet > xBinding( m_pHelper->getCurrentBinding() ); 247*cdf0e10cSrcweir OSL_ENSURE( xBinding.is(), "You should not reach this without an active binding!" ); 248*cdf0e10cSrcweir if ( xBinding.is() ) 249*cdf0e10cSrcweir xBinding->setPropertyValue( PROPERTY_BIND_EXPRESSION, _rValue ); 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir break; 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir case PROPERTY_ID_XSD_REQUIRED: 254*cdf0e10cSrcweir case PROPERTY_ID_XSD_RELEVANT: 255*cdf0e10cSrcweir case PROPERTY_ID_XSD_READONLY: 256*cdf0e10cSrcweir case PROPERTY_ID_XSD_CONSTRAINT: 257*cdf0e10cSrcweir case PROPERTY_ID_XSD_CALCULATION: 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir Reference< XPropertySet > xBindingProps( m_pHelper->getCurrentBinding() ); 260*cdf0e10cSrcweir DBG_ASSERT( xBindingProps.is(), "EFormsPropertyHandler::setPropertyValue: how can I set a property if there's no binding?" ); 261*cdf0e10cSrcweir if ( xBindingProps.is() ) 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir DBG_ASSERT( _rValue.getValueType().equals( ::getCppuType( static_cast< ::rtl::OUString* >( NULL ) ) ), 264*cdf0e10cSrcweir "EFormsPropertyHandler::setPropertyValue: invalid value type!" ); 265*cdf0e10cSrcweir xBindingProps->setPropertyValue( _rPropertyName, _rValue ); 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir break; 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir default: 271*cdf0e10cSrcweir DBG_ERROR( "EFormsPropertyHandler::setPropertyValue: cannot handle this property!" ); 272*cdf0e10cSrcweir break; 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir impl_setContextDocumentModified_nothrow(); 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir Any aNewValue( getPropertyValue( _rPropertyName ) ); 278*cdf0e10cSrcweir firePropertyChange( _rPropertyName, nPropId, aOldValue, aNewValue ); 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir catch( const Exception& ) 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir OSL_ENSURE( sal_False, "EFormsPropertyHandler::setPropertyValue: caught an exception!" ); 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir } 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir //-------------------------------------------------------------------- 287*cdf0e10cSrcweir void EFormsPropertyHandler::onNewComponent() 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir EFormsPropertyHandler_Base::onNewComponent(); 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir Reference< frame::XModel > xDocument( impl_getContextDocument_nothrow() ); 292*cdf0e10cSrcweir DBG_ASSERT( xDocument.is(), "EFormsPropertyHandler::onNewComponent: no document!" ); 293*cdf0e10cSrcweir if ( EFormsHelper::isEForm( xDocument ) ) 294*cdf0e10cSrcweir m_pHelper.reset( new EFormsHelper( m_aMutex, m_xComponent, xDocument ) ); 295*cdf0e10cSrcweir else 296*cdf0e10cSrcweir m_pHelper.reset( NULL ); 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir //-------------------------------------------------------------------- 300*cdf0e10cSrcweir Sequence< Property > SAL_CALL EFormsPropertyHandler::doDescribeSupportedProperties() const 301*cdf0e10cSrcweir { 302*cdf0e10cSrcweir ::std::vector< Property > aProperties; 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir if ( m_pHelper.get() ) 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir if ( m_pHelper->canBindToAnyDataType() ) 307*cdf0e10cSrcweir { 308*cdf0e10cSrcweir aProperties.reserve( 7 ); 309*cdf0e10cSrcweir addStringPropertyDescription( aProperties, PROPERTY_XML_DATA_MODEL ); 310*cdf0e10cSrcweir addStringPropertyDescription( aProperties, PROPERTY_BINDING_NAME ); 311*cdf0e10cSrcweir addStringPropertyDescription( aProperties, PROPERTY_BIND_EXPRESSION ); 312*cdf0e10cSrcweir addStringPropertyDescription( aProperties, PROPERTY_XSD_REQUIRED ); 313*cdf0e10cSrcweir addStringPropertyDescription( aProperties, PROPERTY_XSD_RELEVANT ); 314*cdf0e10cSrcweir addStringPropertyDescription( aProperties, PROPERTY_XSD_READONLY ); 315*cdf0e10cSrcweir addStringPropertyDescription( aProperties, PROPERTY_XSD_CONSTRAINT ); 316*cdf0e10cSrcweir addStringPropertyDescription( aProperties, PROPERTY_XSD_CALCULATION ); 317*cdf0e10cSrcweir } 318*cdf0e10cSrcweir if ( m_pHelper->isListEntrySink() ) 319*cdf0e10cSrcweir { 320*cdf0e10cSrcweir implAddPropertyDescription( aProperties, PROPERTY_LIST_BINDING, 321*cdf0e10cSrcweir ::getCppuType( static_cast< Reference< XListEntrySource > * >( NULL ) ) ); 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir if ( aProperties.empty() ) 326*cdf0e10cSrcweir return Sequence< Property >(); 327*cdf0e10cSrcweir return Sequence< Property >( &(*aProperties.begin()), aProperties.size() ); 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir //-------------------------------------------------------------------- 331*cdf0e10cSrcweir Any SAL_CALL EFormsPropertyHandler::convertToPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rControlValue ) throw (UnknownPropertyException, RuntimeException) 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 334*cdf0e10cSrcweir Any aReturn; 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir OSL_ENSURE( m_pHelper.get(), "EFormsPropertyHandler::convertToPropertyValue: we have no SupportedProperties!" ); 337*cdf0e10cSrcweir if ( !m_pHelper.get() ) 338*cdf0e10cSrcweir return aReturn; 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir PropertyId nPropId( m_pInfoService->getPropertyId( _rPropertyName ) ); 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir ::rtl::OUString sControlValue; 343*cdf0e10cSrcweir switch ( nPropId ) 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir case PROPERTY_ID_LIST_BINDING: 346*cdf0e10cSrcweir { 347*cdf0e10cSrcweir OSL_VERIFY( _rControlValue >>= sControlValue ); 348*cdf0e10cSrcweir Reference< XListEntrySource > xListSource( m_pHelper->getModelElementFromUIName( EFormsHelper::Binding, sControlValue ), UNO_QUERY ); 349*cdf0e10cSrcweir OSL_ENSURE( xListSource.is() || !m_pHelper->getModelElementFromUIName( EFormsHelper::Binding, sControlValue ).is(), 350*cdf0e10cSrcweir "EFormsPropertyHandler::convertToPropertyValue: there's a binding which is no ListEntrySource!" ); 351*cdf0e10cSrcweir aReturn <<= xListSource; 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir break; 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir default: 356*cdf0e10cSrcweir aReturn = EFormsPropertyHandler_Base::convertToPropertyValue( _rPropertyName, _rControlValue ); 357*cdf0e10cSrcweir break; 358*cdf0e10cSrcweir } 359*cdf0e10cSrcweir 360*cdf0e10cSrcweir return aReturn; 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir //-------------------------------------------------------------------- 364*cdf0e10cSrcweir Any SAL_CALL EFormsPropertyHandler::convertToControlValue( const ::rtl::OUString& _rPropertyName, const Any& _rPropertyValue, const Type& _rControlValueType ) throw (UnknownPropertyException, RuntimeException) 365*cdf0e10cSrcweir { 366*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 367*cdf0e10cSrcweir Any aReturn; 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir OSL_ENSURE( m_pHelper.get(), "EFormsPropertyHandler::convertToControlValue: we have no SupportedProperties!" ); 370*cdf0e10cSrcweir if ( !m_pHelper.get() ) 371*cdf0e10cSrcweir return aReturn; 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir PropertyId nPropId( m_pInfoService->getPropertyId( _rPropertyName ) ); 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir OSL_ENSURE( _rControlValueType.getTypeClass() == TypeClass_STRING, 376*cdf0e10cSrcweir "EFormsPropertyHandler::convertToControlValue: all our controls should use strings for value exchange!" ); 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir switch ( nPropId ) 379*cdf0e10cSrcweir { 380*cdf0e10cSrcweir case PROPERTY_ID_LIST_BINDING: 381*cdf0e10cSrcweir { 382*cdf0e10cSrcweir Reference< XPropertySet > xListSourceBinding( _rPropertyValue, UNO_QUERY ); 383*cdf0e10cSrcweir if ( xListSourceBinding.is() ) 384*cdf0e10cSrcweir aReturn <<= m_pHelper->getModelElementUIName( EFormsHelper::Binding, xListSourceBinding ); 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir break; 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir default: 389*cdf0e10cSrcweir aReturn = EFormsPropertyHandler_Base::convertToControlValue( _rPropertyName, _rPropertyValue, _rControlValueType ); 390*cdf0e10cSrcweir break; 391*cdf0e10cSrcweir } 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir return aReturn; 394*cdf0e10cSrcweir } 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir //-------------------------------------------------------------------- 397*cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL EFormsPropertyHandler::getActuatingProperties( ) throw (RuntimeException) 398*cdf0e10cSrcweir { 399*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 400*cdf0e10cSrcweir if ( !m_pHelper.get() ) 401*cdf0e10cSrcweir return Sequence< ::rtl::OUString >(); 402*cdf0e10cSrcweir 403*cdf0e10cSrcweir ::std::vector< ::rtl::OUString > aInterestedInActuations( 2 ); 404*cdf0e10cSrcweir aInterestedInActuations[ 0 ] = PROPERTY_XML_DATA_MODEL; 405*cdf0e10cSrcweir aInterestedInActuations[ 1 ] = PROPERTY_BINDING_NAME; 406*cdf0e10cSrcweir return Sequence< ::rtl::OUString >( &(*aInterestedInActuations.begin()), aInterestedInActuations.size() ); 407*cdf0e10cSrcweir } 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir //-------------------------------------------------------------------- 410*cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL EFormsPropertyHandler::getSupersededProperties( ) throw (RuntimeException) 411*cdf0e10cSrcweir { 412*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 413*cdf0e10cSrcweir if ( !m_pHelper.get() ) 414*cdf0e10cSrcweir return Sequence< ::rtl::OUString >(); 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir Sequence< ::rtl::OUString > aReturn( 1 ); 417*cdf0e10cSrcweir aReturn[ 0 ] = PROPERTY_INPUT_REQUIRED; 418*cdf0e10cSrcweir return aReturn; 419*cdf0e10cSrcweir } 420*cdf0e10cSrcweir 421*cdf0e10cSrcweir //-------------------------------------------------------------------- 422*cdf0e10cSrcweir LineDescriptor SAL_CALL EFormsPropertyHandler::describePropertyLine( const ::rtl::OUString& _rPropertyName, 423*cdf0e10cSrcweir const Reference< XPropertyControlFactory >& _rxControlFactory ) 424*cdf0e10cSrcweir throw (UnknownPropertyException, NullPointerException, RuntimeException) 425*cdf0e10cSrcweir { 426*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 427*cdf0e10cSrcweir if ( !_rxControlFactory.is() ) 428*cdf0e10cSrcweir throw NullPointerException(); 429*cdf0e10cSrcweir if ( !m_pHelper.get() ) 430*cdf0e10cSrcweir throw RuntimeException(); 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir LineDescriptor aDescriptor; 433*cdf0e10cSrcweir sal_Int16 nControlType = PropertyControlType::TextField; 434*cdf0e10cSrcweir ::std::vector< ::rtl::OUString > aListEntries; 435*cdf0e10cSrcweir PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) ); 436*cdf0e10cSrcweir switch ( nPropId ) 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir case PROPERTY_ID_LIST_BINDING: 439*cdf0e10cSrcweir nControlType = PropertyControlType::ListBox; 440*cdf0e10cSrcweir const_cast< EFormsHelper* >( m_pHelper.get() )->getAllElementUINames( EFormsHelper::Binding, aListEntries, true ); 441*cdf0e10cSrcweir break; 442*cdf0e10cSrcweir 443*cdf0e10cSrcweir case PROPERTY_ID_XML_DATA_MODEL: 444*cdf0e10cSrcweir nControlType = PropertyControlType::ListBox; 445*cdf0e10cSrcweir m_pHelper->getFormModelNames( aListEntries ); 446*cdf0e10cSrcweir break; 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir case PROPERTY_ID_BINDING_NAME: 449*cdf0e10cSrcweir { 450*cdf0e10cSrcweir nControlType = PropertyControlType::ComboBox; 451*cdf0e10cSrcweir ::rtl::OUString sCurrentModel( getModelNamePropertyValue() ); 452*cdf0e10cSrcweir if ( sCurrentModel.getLength() ) 453*cdf0e10cSrcweir m_pHelper->getBindingNames( sCurrentModel, aListEntries ); 454*cdf0e10cSrcweir } 455*cdf0e10cSrcweir break; 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir case PROPERTY_ID_BIND_EXPRESSION: aDescriptor.PrimaryButtonId = rtl::OUString::createFromAscii(UID_PROP_DLG_BIND_EXPRESSION); break; 458*cdf0e10cSrcweir case PROPERTY_ID_XSD_REQUIRED: aDescriptor.PrimaryButtonId = rtl::OUString::createFromAscii(UID_PROP_DLG_XSD_REQUIRED); break; 459*cdf0e10cSrcweir case PROPERTY_ID_XSD_RELEVANT: aDescriptor.PrimaryButtonId = rtl::OUString::createFromAscii(UID_PROP_DLG_XSD_RELEVANT); break; 460*cdf0e10cSrcweir case PROPERTY_ID_XSD_READONLY: aDescriptor.PrimaryButtonId = rtl::OUString::createFromAscii(UID_PROP_DLG_XSD_READONLY); break; 461*cdf0e10cSrcweir case PROPERTY_ID_XSD_CONSTRAINT: aDescriptor.PrimaryButtonId = rtl::OUString::createFromAscii(UID_PROP_DLG_XSD_CONSTRAINT); break; 462*cdf0e10cSrcweir case PROPERTY_ID_XSD_CALCULATION: aDescriptor.PrimaryButtonId = rtl::OUString::createFromAscii(UID_PROP_DLG_XSD_CALCULATION); break; 463*cdf0e10cSrcweir 464*cdf0e10cSrcweir default: 465*cdf0e10cSrcweir DBG_ERROR( "EFormsPropertyHandler::describePropertyLine: cannot handle this property!" ); 466*cdf0e10cSrcweir break; 467*cdf0e10cSrcweir } 468*cdf0e10cSrcweir 469*cdf0e10cSrcweir switch ( nControlType ) 470*cdf0e10cSrcweir { 471*cdf0e10cSrcweir case PropertyControlType::ListBox: 472*cdf0e10cSrcweir aDescriptor.Control = PropertyHandlerHelper::createListBoxControl( _rxControlFactory, aListEntries, sal_False, sal_True ); 473*cdf0e10cSrcweir break; 474*cdf0e10cSrcweir case PropertyControlType::ComboBox: 475*cdf0e10cSrcweir aDescriptor.Control = PropertyHandlerHelper::createComboBoxControl( _rxControlFactory, aListEntries, sal_False, sal_True ); 476*cdf0e10cSrcweir break; 477*cdf0e10cSrcweir default: 478*cdf0e10cSrcweir aDescriptor.Control = _rxControlFactory->createPropertyControl( nControlType, sal_False ); 479*cdf0e10cSrcweir break; 480*cdf0e10cSrcweir } 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir aDescriptor.DisplayName = m_pInfoService->getPropertyTranslation( nPropId ); 483*cdf0e10cSrcweir aDescriptor.Category = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Data" ) ); 484*cdf0e10cSrcweir aDescriptor.HelpURL = HelpIdUrl::getHelpURL( m_pInfoService->getPropertyHelpId( nPropId ) ); 485*cdf0e10cSrcweir return aDescriptor; 486*cdf0e10cSrcweir } 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir //-------------------------------------------------------------------- 489*cdf0e10cSrcweir InteractiveSelectionResult SAL_CALL EFormsPropertyHandler::onInteractivePropertySelection( const ::rtl::OUString& _rPropertyName, sal_Bool /*_bPrimary*/, Any& _rData, const Reference< XObjectInspectorUI >& _rxInspectorUI ) throw (UnknownPropertyException, NullPointerException, RuntimeException) 490*cdf0e10cSrcweir { 491*cdf0e10cSrcweir if ( !_rxInspectorUI.is() ) 492*cdf0e10cSrcweir throw NullPointerException(); 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 495*cdf0e10cSrcweir OSL_ENSURE( m_pHelper.get(), "EFormsPropertyHandler::onInteractivePropertySelection: we do not have any SupportedProperties!" ); 496*cdf0e10cSrcweir if ( !m_pHelper.get() ) 497*cdf0e10cSrcweir return InteractiveSelectionResult_Cancelled; 498*cdf0e10cSrcweir 499*cdf0e10cSrcweir PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) ); 500*cdf0e10cSrcweir (void)nPropId; 501*cdf0e10cSrcweir OSL_ENSURE( ( PROPERTY_ID_BINDING_NAME == nPropId ) 502*cdf0e10cSrcweir || ( PROPERTY_ID_BIND_EXPRESSION == nPropId ) 503*cdf0e10cSrcweir || ( PROPERTY_ID_XSD_REQUIRED == nPropId ) 504*cdf0e10cSrcweir || ( PROPERTY_ID_XSD_RELEVANT == nPropId ) 505*cdf0e10cSrcweir || ( PROPERTY_ID_XSD_READONLY == nPropId ) 506*cdf0e10cSrcweir || ( PROPERTY_ID_XSD_CONSTRAINT == nPropId ) 507*cdf0e10cSrcweir || ( PROPERTY_ID_XSD_CALCULATION == nPropId ), "EFormsPropertyHandler::onInteractivePropertySelection: unexpected!" ); 508*cdf0e10cSrcweir 509*cdf0e10cSrcweir try 510*cdf0e10cSrcweir { 511*cdf0e10cSrcweir Reference< XExecutableDialog > xDialog; 512*cdf0e10cSrcweir m_aContext.createComponent( "com.sun.star.xforms.ui.dialogs.AddCondition", xDialog ); 513*cdf0e10cSrcweir Reference< XPropertySet > xDialogProps( xDialog, UNO_QUERY_THROW ); 514*cdf0e10cSrcweir 515*cdf0e10cSrcweir // the model for the dialog to work with 516*cdf0e10cSrcweir Reference< xforms::XModel > xModel( m_pHelper->getCurrentFormModel() ); 517*cdf0e10cSrcweir // the binding for the dialog to work with 518*cdf0e10cSrcweir Reference< XPropertySet > xBinding( m_pHelper->getCurrentBinding() ); 519*cdf0e10cSrcweir // the aspect of the binding which the dialog should modify 520*cdf0e10cSrcweir ::rtl::OUString sFacetName( _rPropertyName ); 521*cdf0e10cSrcweir 522*cdf0e10cSrcweir OSL_ENSURE( xModel.is() && xBinding.is() && sFacetName.getLength(), 523*cdf0e10cSrcweir "EFormsPropertyHandler::onInteractivePropertySelection: something is missing for the dialog initialization!" ); 524*cdf0e10cSrcweir if ( !( xModel.is() && xBinding.is() && sFacetName.getLength() ) ) 525*cdf0e10cSrcweir return InteractiveSelectionResult_Cancelled; 526*cdf0e10cSrcweir 527*cdf0e10cSrcweir xDialogProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FormModel" ) ), makeAny( xModel ) ); 528*cdf0e10cSrcweir xDialogProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Binding" ) ), makeAny( xBinding ) ); 529*cdf0e10cSrcweir xDialogProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FacetName" ) ), makeAny( sFacetName ) ); 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir if ( !xDialog->execute() ) 532*cdf0e10cSrcweir // cancelled 533*cdf0e10cSrcweir return InteractiveSelectionResult_Cancelled; 534*cdf0e10cSrcweir 535*cdf0e10cSrcweir _rData = xDialogProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ConditionValue" ) ) ); 536*cdf0e10cSrcweir return InteractiveSelectionResult_ObtainedValue; 537*cdf0e10cSrcweir } 538*cdf0e10cSrcweir catch( const Exception& ) 539*cdf0e10cSrcweir { 540*cdf0e10cSrcweir OSL_ENSURE( sal_False, "EFormsPropertyHandler::onInteractivePropertySelection: caught an exception!" ); 541*cdf0e10cSrcweir } 542*cdf0e10cSrcweir 543*cdf0e10cSrcweir // something went wrong here ...(but has been asserted already) 544*cdf0e10cSrcweir return InteractiveSelectionResult_Cancelled; 545*cdf0e10cSrcweir } 546*cdf0e10cSrcweir 547*cdf0e10cSrcweir //-------------------------------------------------------------------- 548*cdf0e10cSrcweir void SAL_CALL EFormsPropertyHandler::addPropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener ) throw (RuntimeException) 549*cdf0e10cSrcweir { 550*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 551*cdf0e10cSrcweir EFormsPropertyHandler_Base::addPropertyChangeListener( _rxListener ); 552*cdf0e10cSrcweir if ( m_pHelper.get() ) 553*cdf0e10cSrcweir m_pHelper->registerBindingListener( _rxListener ); 554*cdf0e10cSrcweir } 555*cdf0e10cSrcweir 556*cdf0e10cSrcweir //-------------------------------------------------------------------- 557*cdf0e10cSrcweir void SAL_CALL EFormsPropertyHandler::removePropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener ) throw (RuntimeException) 558*cdf0e10cSrcweir { 559*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 560*cdf0e10cSrcweir if ( m_pHelper.get() ) 561*cdf0e10cSrcweir m_pHelper->revokeBindingListener( _rxListener ); 562*cdf0e10cSrcweir EFormsPropertyHandler_Base::removePropertyChangeListener( _rxListener ); 563*cdf0e10cSrcweir } 564*cdf0e10cSrcweir 565*cdf0e10cSrcweir //-------------------------------------------------------------------- 566*cdf0e10cSrcweir void SAL_CALL EFormsPropertyHandler::actuatingPropertyChanged( const ::rtl::OUString& _rActuatingPropertyName, const Any& _rNewValue, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool ) throw (NullPointerException, RuntimeException) 567*cdf0e10cSrcweir { 568*cdf0e10cSrcweir if ( !_rxInspectorUI.is() ) 569*cdf0e10cSrcweir throw NullPointerException(); 570*cdf0e10cSrcweir 571*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 572*cdf0e10cSrcweir PropertyId nActuatingPropId( impl_getPropertyId_throw( _rActuatingPropertyName ) ); 573*cdf0e10cSrcweir OSL_PRECOND( m_pHelper.get(), "EFormsPropertyHandler::actuatingPropertyChanged: inconsistentcy!" ); 574*cdf0e10cSrcweir // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties 575*cdf0e10cSrcweir 576*cdf0e10cSrcweir DBG_ASSERT( _rxInspectorUI.is(), "EFormsPropertyHandler::actuatingPropertyChanged: invalid callback!" ); 577*cdf0e10cSrcweir if ( !_rxInspectorUI.is() ) 578*cdf0e10cSrcweir return; 579*cdf0e10cSrcweir 580*cdf0e10cSrcweir switch ( nActuatingPropId ) 581*cdf0e10cSrcweir { 582*cdf0e10cSrcweir case PROPERTY_ID_XML_DATA_MODEL: 583*cdf0e10cSrcweir { 584*cdf0e10cSrcweir if ( m_bSimulatingModelChange ) 585*cdf0e10cSrcweir break; 586*cdf0e10cSrcweir ::rtl::OUString sDataModelName; 587*cdf0e10cSrcweir OSL_VERIFY( _rNewValue >>= sDataModelName ); 588*cdf0e10cSrcweir sal_Bool bBoundToSomeModel = 0 != sDataModelName.getLength(); 589*cdf0e10cSrcweir _rxInspectorUI->rebuildPropertyUI( PROPERTY_BINDING_NAME ); 590*cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_BINDING_NAME, bBoundToSomeModel ); 591*cdf0e10cSrcweir } 592*cdf0e10cSrcweir // NO break 593*cdf0e10cSrcweir 594*cdf0e10cSrcweir case PROPERTY_ID_BINDING_NAME: 595*cdf0e10cSrcweir { 596*cdf0e10cSrcweir sal_Bool bHaveABinding = ( m_pHelper->getCurrentBindingName().getLength() > 0 ); 597*cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_BIND_EXPRESSION, bHaveABinding ); 598*cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_XSD_REQUIRED, bHaveABinding ); 599*cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_XSD_RELEVANT, bHaveABinding ); 600*cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_XSD_READONLY, bHaveABinding ); 601*cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_XSD_CONSTRAINT, bHaveABinding ); 602*cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_XSD_CALCULATION, bHaveABinding ); 603*cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_XSD_DATA_TYPE, bHaveABinding ); 604*cdf0e10cSrcweir } 605*cdf0e10cSrcweir break; 606*cdf0e10cSrcweir 607*cdf0e10cSrcweir default: 608*cdf0e10cSrcweir DBG_ERROR( "EFormsPropertyHandler::actuatingPropertyChanged: cannot handle this property!" ); 609*cdf0e10cSrcweir break; 610*cdf0e10cSrcweir } 611*cdf0e10cSrcweir } 612*cdf0e10cSrcweir 613*cdf0e10cSrcweir //........................................................................ 614*cdf0e10cSrcweir } // namespace pcr 615*cdf0e10cSrcweir //........................................................................ 616*cdf0e10cSrcweir 617