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_xmloff.hxx" 30*cdf0e10cSrcweir #include "formcellbinding.hxx" 31*cdf0e10cSrcweir #include <com/sun/star/form/binding/XBindableValue.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/form/binding/XListEntrySink.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/form/XGridColumnFactory.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPageSupplier.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/table/XCellRange.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/form/XFormsSupplier.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/form/XForm.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp> 44*cdf0e10cSrcweir #include "strings.hxx" 45*cdf0e10cSrcweir #include <osl/diagnose.h> 46*cdf0e10cSrcweir #include <rtl/logfile.hxx> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #include <functional> 49*cdf0e10cSrcweir #include <algorithm> 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir //............................................................................ 52*cdf0e10cSrcweir namespace xmloff 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir //............................................................................ 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 57*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 58*cdf0e10cSrcweir using namespace ::com::sun::star::frame; 59*cdf0e10cSrcweir using namespace ::com::sun::star::sheet; 60*cdf0e10cSrcweir using namespace ::com::sun::star::container; 61*cdf0e10cSrcweir using namespace ::com::sun::star::drawing; 62*cdf0e10cSrcweir using namespace ::com::sun::star::table; 63*cdf0e10cSrcweir using namespace ::com::sun::star::form; 64*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 65*cdf0e10cSrcweir using namespace ::com::sun::star::form::binding; 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir namespace 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 70*cdf0e10cSrcweir using ::com::sun::star::uno::XInterface; 71*cdf0e10cSrcweir using ::com::sun::star::container::XChild; 72*cdf0e10cSrcweir using ::com::sun::star::frame::XModel; 73*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir //.................................................................... 76*cdf0e10cSrcweir template< class TYPE > 77*cdf0e10cSrcweir Reference< TYPE > getTypedModelNode( const Reference< XInterface >& _rxModelNode ) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir Reference< TYPE > xTypedNode( _rxModelNode, UNO_QUERY ); 80*cdf0e10cSrcweir if ( xTypedNode.is() ) 81*cdf0e10cSrcweir return xTypedNode; 82*cdf0e10cSrcweir else 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir Reference< XChild > xChild( _rxModelNode, UNO_QUERY ); 85*cdf0e10cSrcweir if ( xChild.is() ) 86*cdf0e10cSrcweir return getTypedModelNode< TYPE >( xChild->getParent() ); 87*cdf0e10cSrcweir else 88*cdf0e10cSrcweir return NULL; 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir //.................................................................... 93*cdf0e10cSrcweir Reference< XModel > getDocument( const Reference< XInterface >& _rxModelNode ) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir return getTypedModelNode< XModel >( _rxModelNode ); 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir //.................................................................... 99*cdf0e10cSrcweir struct StringCompare : public ::std::unary_function< ::rtl::OUString, bool > 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir private: 102*cdf0e10cSrcweir const ::rtl::OUString m_sReference; 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir public: 105*cdf0e10cSrcweir StringCompare( const ::rtl::OUString& _rReference ) : m_sReference( _rReference ) { } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir inline bool operator()( const ::rtl::OUString& _rCompare ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir return ( _rCompare == m_sReference ); 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir }; 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir //======================================================================== 115*cdf0e10cSrcweir //= FormCellBindingHelper 116*cdf0e10cSrcweir //======================================================================== 117*cdf0e10cSrcweir //------------------------------------------------------------------------ 118*cdf0e10cSrcweir FormCellBindingHelper::FormCellBindingHelper( const Reference< XPropertySet >& _rxControlModel, const Reference< XModel >& _rxDocument ) 119*cdf0e10cSrcweir :m_xControlModel( _rxControlModel ) 120*cdf0e10cSrcweir ,m_xDocument( _rxDocument, UNO_QUERY ) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir OSL_ENSURE( m_xControlModel.is(), "FormCellBindingHelper::FormCellBindingHelper: invalid control model!" ); 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir if ( !m_xDocument.is() ) 125*cdf0e10cSrcweir m_xDocument = m_xDocument.query( getDocument( m_xControlModel ) ); 126*cdf0e10cSrcweir OSL_ENSURE( m_xDocument.is(), "FormCellBindingHelper::FormCellBindingHelper: Did not find the spreadsheet document!" ); 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir //------------------------------------------------------------------------ 130*cdf0e10cSrcweir sal_Bool FormCellBindingHelper::livesInSpreadsheetDocument( const Reference< XPropertySet >& _rxControlModel ) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir Reference< XSpreadsheetDocument > xDocument( getDocument( _rxControlModel ), UNO_QUERY ); 133*cdf0e10cSrcweir return xDocument.is(); 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir //------------------------------------------------------------------------ 137*cdf0e10cSrcweir bool FormCellBindingHelper::convertStringAddress( const ::rtl::OUString& _rAddressDescription, CellAddress& /* [out] */ _rAddress, sal_Int16 /*_nAssumeSheet*/ ) const 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir Any aAddress; 140*cdf0e10cSrcweir return doConvertAddressRepresentations( 141*cdf0e10cSrcweir PROPERTY_FILE_REPRESENTATION, 142*cdf0e10cSrcweir makeAny( _rAddressDescription ), 143*cdf0e10cSrcweir PROPERTY_ADDRESS, 144*cdf0e10cSrcweir aAddress, 145*cdf0e10cSrcweir false 146*cdf0e10cSrcweir ) 147*cdf0e10cSrcweir && ( aAddress >>= _rAddress ); 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir //------------------------------------------------------------------------ 151*cdf0e10cSrcweir bool FormCellBindingHelper::convertStringAddress( const ::rtl::OUString& _rAddressDescription, 152*cdf0e10cSrcweir CellRangeAddress& /* [out] */ _rAddress ) const 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir Any aAddress; 155*cdf0e10cSrcweir return doConvertAddressRepresentations( 156*cdf0e10cSrcweir PROPERTY_FILE_REPRESENTATION, 157*cdf0e10cSrcweir makeAny( _rAddressDescription ), 158*cdf0e10cSrcweir PROPERTY_ADDRESS, 159*cdf0e10cSrcweir aAddress, 160*cdf0e10cSrcweir true 161*cdf0e10cSrcweir ) 162*cdf0e10cSrcweir && ( aAddress >>= _rAddress ); 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir //------------------------------------------------------------------------ 166*cdf0e10cSrcweir Reference< XValueBinding > FormCellBindingHelper::createCellBindingFromStringAddress( const ::rtl::OUString& _rAddress, bool _bUseIntegerBinding ) const 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir Reference< XValueBinding > xBinding; 169*cdf0e10cSrcweir if ( !m_xDocument.is() ) 170*cdf0e10cSrcweir // very bad ... 171*cdf0e10cSrcweir return xBinding; 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir // get the UNO representation of the address 174*cdf0e10cSrcweir CellAddress aAddress; 175*cdf0e10cSrcweir if ( !_rAddress.getLength() || !convertStringAddress( _rAddress, aAddress ) ) 176*cdf0e10cSrcweir return xBinding; 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir xBinding = xBinding.query( createDocumentDependentInstance( 179*cdf0e10cSrcweir _bUseIntegerBinding ? SERVICE_LISTINDEXCELLBINDING : SERVICE_CELLVALUEBINDING, 180*cdf0e10cSrcweir PROPERTY_BOUND_CELL, 181*cdf0e10cSrcweir makeAny( aAddress ) 182*cdf0e10cSrcweir ) ); 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir return xBinding; 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir //------------------------------------------------------------------------ 188*cdf0e10cSrcweir Reference< XListEntrySource > FormCellBindingHelper::createCellListSourceFromStringAddress( const ::rtl::OUString& _rAddress ) const 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir Reference< XListEntrySource > xSource; 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir CellRangeAddress aRangeAddress; 193*cdf0e10cSrcweir if ( !convertStringAddress( _rAddress, aRangeAddress ) ) 194*cdf0e10cSrcweir return xSource; 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir // create a range object for this address 197*cdf0e10cSrcweir xSource = xSource.query( createDocumentDependentInstance( 198*cdf0e10cSrcweir SERVICE_CELLRANGELISTSOURCE, 199*cdf0e10cSrcweir PROPERTY_LIST_CELL_RANGE, 200*cdf0e10cSrcweir makeAny( aRangeAddress ) 201*cdf0e10cSrcweir ) ); 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir return xSource; 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir //------------------------------------------------------------------------ 207*cdf0e10cSrcweir ::rtl::OUString FormCellBindingHelper::getStringAddressFromCellBinding( const Reference< XValueBinding >& _rxBinding ) const 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir OSL_PRECOND( !_rxBinding.is() || isCellBinding( _rxBinding ), "FormCellBindingHelper::getStringAddressFromCellBinding: this is no cell binding!" ); 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir ::rtl::OUString sAddress; 212*cdf0e10cSrcweir try 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir Reference< XPropertySet > xBindingProps( _rxBinding, UNO_QUERY ); 215*cdf0e10cSrcweir OSL_ENSURE( xBindingProps.is() || !_rxBinding.is(), "FormCellBindingHelper::getStringAddressFromCellBinding: no property set for the binding!" ); 216*cdf0e10cSrcweir if ( xBindingProps.is() ) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir CellAddress aAddress; 219*cdf0e10cSrcweir xBindingProps->getPropertyValue( PROPERTY_BOUND_CELL ) >>= aAddress; 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir Any aStringAddress; 222*cdf0e10cSrcweir doConvertAddressRepresentations( PROPERTY_ADDRESS, makeAny( aAddress ), 223*cdf0e10cSrcweir PROPERTY_FILE_REPRESENTATION, aStringAddress, false ); 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir aStringAddress >>= sAddress; 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir catch( const Exception& ) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir OSL_ENSURE( sal_False, "FormCellBindingHelper::getStringAddressFromCellBinding: caught an exception!" ); 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir return sAddress; 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir //------------------------------------------------------------------------ 237*cdf0e10cSrcweir ::rtl::OUString FormCellBindingHelper::getStringAddressFromCellListSource( const Reference< XListEntrySource >& _rxSource ) const 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir OSL_PRECOND( !_rxSource.is() || isCellRangeListSource( _rxSource ), "FormCellBindingHelper::getStringAddressFromCellListSource: this is no cell list source!" ); 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir ::rtl::OUString sAddress; 242*cdf0e10cSrcweir try 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir Reference< XPropertySet > xSourceProps( _rxSource, UNO_QUERY ); 245*cdf0e10cSrcweir OSL_ENSURE( xSourceProps.is() || !_rxSource.is(), "FormCellBindingHelper::getStringAddressFromCellListSource: no property set for the list source!" ); 246*cdf0e10cSrcweir if ( xSourceProps.is() ) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir CellRangeAddress aRangeAddress; 249*cdf0e10cSrcweir xSourceProps->getPropertyValue( PROPERTY_LIST_CELL_RANGE ) >>= aRangeAddress; 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir Any aStringAddress; 252*cdf0e10cSrcweir doConvertAddressRepresentations( PROPERTY_ADDRESS, makeAny( aRangeAddress ), 253*cdf0e10cSrcweir PROPERTY_FILE_REPRESENTATION, aStringAddress, true ); 254*cdf0e10cSrcweir aStringAddress >>= sAddress; 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir catch( const Exception& ) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir OSL_ENSURE( sal_False, "FormCellBindingHelper::getStringAddressFromCellListSource: caught an exception!" ); 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir return sAddress; 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir //------------------------------------------------------------------------ 266*cdf0e10cSrcweir bool FormCellBindingHelper::isSpreadsheetDocumentWhichSupplies( const Reference< XSpreadsheetDocument >& _rxDocument, const ::rtl::OUString& _rService ) SAL_THROW(()) 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir bool bYesItIs = false; 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir try 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir Reference< XServiceInfo > xSI( _rxDocument, UNO_QUERY ); 273*cdf0e10cSrcweir if ( xSI.is() && xSI->supportsService( SERVICE_SPREADSHEET_DOCUMENT ) ) 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir Reference< XMultiServiceFactory > xDocumentFactory( _rxDocument, UNO_QUERY ); 276*cdf0e10cSrcweir OSL_ENSURE( xDocumentFactory.is(), "FormCellBindingHelper::isSpreadsheetDocumentWhichSupplies: spreadsheet document, but no factory?" ); 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir Sequence< ::rtl::OUString > aAvailableServices; 279*cdf0e10cSrcweir if ( xDocumentFactory.is() ) 280*cdf0e10cSrcweir aAvailableServices = xDocumentFactory->getAvailableServiceNames( ); 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir const ::rtl::OUString* pFound = ::std::find_if( 283*cdf0e10cSrcweir aAvailableServices.getConstArray(), 284*cdf0e10cSrcweir aAvailableServices.getConstArray() + aAvailableServices.getLength(), 285*cdf0e10cSrcweir StringCompare( _rService ) 286*cdf0e10cSrcweir ); 287*cdf0e10cSrcweir if ( pFound - aAvailableServices.getConstArray() < aAvailableServices.getLength() ) 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir bYesItIs = true; 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir catch( const Exception& ) 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir OSL_ENSURE( sal_False, "FormCellBindingHelper::isSpreadsheetDocumentWhichSupplies: caught an exception!" ); 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir return bYesItIs; 299*cdf0e10cSrcweir } 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir //------------------------------------------------------------------------ 302*cdf0e10cSrcweir bool FormCellBindingHelper::isSpreadsheetDocumentWhichSupplies( const ::rtl::OUString& _rService ) const SAL_THROW(()) 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir return isSpreadsheetDocumentWhichSupplies( m_xDocument, _rService ); 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir //------------------------------------------------------------------------ 308*cdf0e10cSrcweir bool FormCellBindingHelper::isListCellRangeAllowed( const Reference< XModel >& _rxDocument ) 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir return isSpreadsheetDocumentWhichSupplies( 311*cdf0e10cSrcweir Reference< XSpreadsheetDocument >( _rxDocument, UNO_QUERY ), 312*cdf0e10cSrcweir SERVICE_CELLRANGELISTSOURCE 313*cdf0e10cSrcweir ); 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir //------------------------------------------------------------------------ 317*cdf0e10cSrcweir bool FormCellBindingHelper::isListCellRangeAllowed( ) const 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir bool bAllow( false ); 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir Reference< XListEntrySink > xSink( m_xControlModel, UNO_QUERY ); 322*cdf0e10cSrcweir if ( xSink.is() ) 323*cdf0e10cSrcweir { 324*cdf0e10cSrcweir bAllow = isSpreadsheetDocumentWhichSupplies( SERVICE_CELLRANGELISTSOURCE ); 325*cdf0e10cSrcweir } 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir return bAllow; 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir //------------------------------------------------------------------------ 331*cdf0e10cSrcweir bool FormCellBindingHelper::isCellBindingAllowed( ) const 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir bool bAllow( false ); 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir Reference< XBindableValue > xBindable( m_xControlModel, UNO_QUERY ); 336*cdf0e10cSrcweir if ( xBindable.is() ) 337*cdf0e10cSrcweir { 338*cdf0e10cSrcweir // the control can potentially be bound to an external value 339*cdf0e10cSrcweir // Does it live within a Calc document, and is able to supply CellBindings? 340*cdf0e10cSrcweir bAllow = isSpreadsheetDocumentWhichSupplies( SERVICE_CELLVALUEBINDING ); 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir return bAllow; 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir //------------------------------------------------------------------------ 347*cdf0e10cSrcweir bool FormCellBindingHelper::isCellBindingAllowed( const Reference< XModel >& _rxDocument ) 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir return isSpreadsheetDocumentWhichSupplies( 350*cdf0e10cSrcweir Reference< XSpreadsheetDocument >( _rxDocument, UNO_QUERY ), 351*cdf0e10cSrcweir SERVICE_CELLVALUEBINDING 352*cdf0e10cSrcweir ); 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir //------------------------------------------------------------------------ 356*cdf0e10cSrcweir bool FormCellBindingHelper::isCellBinding( const Reference< XValueBinding >& _rxBinding ) const 357*cdf0e10cSrcweir { 358*cdf0e10cSrcweir return doesComponentSupport( _rxBinding.get(), SERVICE_CELLVALUEBINDING ); 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir //------------------------------------------------------------------------ 362*cdf0e10cSrcweir bool FormCellBindingHelper::isCellIntegerBinding( const Reference< XValueBinding >& _rxBinding ) const 363*cdf0e10cSrcweir { 364*cdf0e10cSrcweir return doesComponentSupport( _rxBinding.get(), SERVICE_LISTINDEXCELLBINDING ); 365*cdf0e10cSrcweir } 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir //------------------------------------------------------------------------ 368*cdf0e10cSrcweir bool FormCellBindingHelper::isCellRangeListSource( const Reference< XListEntrySource >& _rxSource ) const 369*cdf0e10cSrcweir { 370*cdf0e10cSrcweir return doesComponentSupport( _rxSource.get(), SERVICE_CELLRANGELISTSOURCE ); 371*cdf0e10cSrcweir } 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir //------------------------------------------------------------------------ 374*cdf0e10cSrcweir bool FormCellBindingHelper::doesComponentSupport( const Reference< XInterface >& _rxComponent, const ::rtl::OUString& _rService ) const 375*cdf0e10cSrcweir { 376*cdf0e10cSrcweir bool bDoes = false; 377*cdf0e10cSrcweir Reference< XServiceInfo > xSI( _rxComponent, UNO_QUERY ); 378*cdf0e10cSrcweir bDoes = xSI.is() && xSI->supportsService( _rService ); 379*cdf0e10cSrcweir return bDoes; 380*cdf0e10cSrcweir } 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir //------------------------------------------------------------------------ 383*cdf0e10cSrcweir Reference< XValueBinding > FormCellBindingHelper::getCurrentBinding( ) const 384*cdf0e10cSrcweir { 385*cdf0e10cSrcweir Reference< XValueBinding > xBinding; 386*cdf0e10cSrcweir Reference< XBindableValue > xBindable( m_xControlModel, UNO_QUERY ); 387*cdf0e10cSrcweir if ( xBindable.is() ) 388*cdf0e10cSrcweir xBinding = xBindable->getValueBinding(); 389*cdf0e10cSrcweir return xBinding; 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir //------------------------------------------------------------------------ 393*cdf0e10cSrcweir Reference< XListEntrySource > FormCellBindingHelper::getCurrentListSource( ) const 394*cdf0e10cSrcweir { 395*cdf0e10cSrcweir Reference< XListEntrySource > xSource; 396*cdf0e10cSrcweir Reference< XListEntrySink > xSink( m_xControlModel, UNO_QUERY ); 397*cdf0e10cSrcweir if ( xSink.is() ) 398*cdf0e10cSrcweir xSource = xSink->getListEntrySource(); 399*cdf0e10cSrcweir return xSource; 400*cdf0e10cSrcweir } 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir //------------------------------------------------------------------------ 403*cdf0e10cSrcweir void FormCellBindingHelper::setBinding( const Reference< XValueBinding >& _rxBinding ) 404*cdf0e10cSrcweir { 405*cdf0e10cSrcweir Reference< XBindableValue > xBindable( m_xControlModel, UNO_QUERY ); 406*cdf0e10cSrcweir OSL_PRECOND( xBindable.is(), "FormCellBindingHelper::setBinding: the object is not bindable!" ); 407*cdf0e10cSrcweir if ( xBindable.is() ) 408*cdf0e10cSrcweir xBindable->setValueBinding( _rxBinding ); 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir //------------------------------------------------------------------------ 412*cdf0e10cSrcweir void FormCellBindingHelper::setListSource( const Reference< XListEntrySource >& _rxSource ) 413*cdf0e10cSrcweir { 414*cdf0e10cSrcweir Reference< XListEntrySink > xSink( m_xControlModel, UNO_QUERY ); 415*cdf0e10cSrcweir OSL_PRECOND( xSink.is(), "FormCellBindingHelper::setListSource: the object is no list entry sink!" ); 416*cdf0e10cSrcweir if ( xSink.is() ) 417*cdf0e10cSrcweir xSink->setListEntrySource( _rxSource ); 418*cdf0e10cSrcweir } 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir //------------------------------------------------------------------------ 421*cdf0e10cSrcweir Reference< XInterface > FormCellBindingHelper::createDocumentDependentInstance( const ::rtl::OUString& _rService, const ::rtl::OUString& _rArgumentName, 422*cdf0e10cSrcweir const Any& _rArgumentValue ) const 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir Reference< XInterface > xReturn; 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir Reference< XMultiServiceFactory > xDocumentFactory( m_xDocument, UNO_QUERY ); 427*cdf0e10cSrcweir OSL_ENSURE( xDocumentFactory.is(), "FormCellBindingHelper::createDocumentDependentInstance: no document service factory!" ); 428*cdf0e10cSrcweir if ( xDocumentFactory.is() ) 429*cdf0e10cSrcweir { 430*cdf0e10cSrcweir try 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir if ( _rArgumentName.getLength() ) 433*cdf0e10cSrcweir { 434*cdf0e10cSrcweir NamedValue aArg; 435*cdf0e10cSrcweir aArg.Name = _rArgumentName; 436*cdf0e10cSrcweir aArg.Value = _rArgumentValue; 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir Sequence< Any > aArgs( 1 ); 439*cdf0e10cSrcweir aArgs[ 0 ] <<= aArg; 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir xReturn = xDocumentFactory->createInstanceWithArguments( _rService, aArgs ); 442*cdf0e10cSrcweir } 443*cdf0e10cSrcweir else 444*cdf0e10cSrcweir { 445*cdf0e10cSrcweir xReturn = xDocumentFactory->createInstance( _rService ); 446*cdf0e10cSrcweir } 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir catch ( const Exception& ) 449*cdf0e10cSrcweir { 450*cdf0e10cSrcweir OSL_ENSURE( sal_False, "FormCellBindingHelper::createDocumentDependentInstance: could not create the binding at the document!" ); 451*cdf0e10cSrcweir } 452*cdf0e10cSrcweir } 453*cdf0e10cSrcweir return xReturn; 454*cdf0e10cSrcweir } 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir //------------------------------------------------------------------------ 457*cdf0e10cSrcweir bool FormCellBindingHelper::doConvertAddressRepresentations( const ::rtl::OUString& _rInputProperty, const Any& _rInputValue, 458*cdf0e10cSrcweir const ::rtl::OUString& _rOutputProperty, Any& _rOutputValue, bool _bIsRange ) const SAL_THROW(()) 459*cdf0e10cSrcweir { 460*cdf0e10cSrcweir bool bSuccess = false; 461*cdf0e10cSrcweir 462*cdf0e10cSrcweir Reference< XPropertySet > xConverter( 463*cdf0e10cSrcweir createDocumentDependentInstance( 464*cdf0e10cSrcweir _bIsRange ? SERVICE_RANGEADDRESS_CONVERSION : SERVICE_ADDRESS_CONVERSION, 465*cdf0e10cSrcweir ::rtl::OUString(), 466*cdf0e10cSrcweir Any() 467*cdf0e10cSrcweir ), 468*cdf0e10cSrcweir UNO_QUERY 469*cdf0e10cSrcweir ); 470*cdf0e10cSrcweir OSL_ENSURE( xConverter.is(), "FormCellBindingHelper::doConvertAddressRepresentations: could not get a converter service!" ); 471*cdf0e10cSrcweir if ( xConverter.is() ) 472*cdf0e10cSrcweir { 473*cdf0e10cSrcweir try 474*cdf0e10cSrcweir { 475*cdf0e10cSrcweir xConverter->setPropertyValue( _rInputProperty, _rInputValue ); 476*cdf0e10cSrcweir _rOutputValue = xConverter->getPropertyValue( _rOutputProperty ); 477*cdf0e10cSrcweir bSuccess = true; 478*cdf0e10cSrcweir } 479*cdf0e10cSrcweir catch( const Exception& ) 480*cdf0e10cSrcweir { 481*cdf0e10cSrcweir OSL_ENSURE( sal_False, "FormCellBindingHelper::doConvertAddressRepresentations: caught an exception!" ); 482*cdf0e10cSrcweir } 483*cdf0e10cSrcweir } 484*cdf0e10cSrcweir 485*cdf0e10cSrcweir return bSuccess; 486*cdf0e10cSrcweir } 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir //............................................................................ 489*cdf0e10cSrcweir } // namespace xmloff 490*cdf0e10cSrcweir //............................................................................ 491