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 #ifndef EXTENSIONS_PROPCTRLR_CELLBINDINGHELPER_HXX 29*cdf0e10cSrcweir #define EXTENSIONS_PROPCTRLR_CELLBINDINGHELPER_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir /** === begin UNO includes === **/ 32*cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/sheet/XSpreadsheetDocument.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/table/CellAddress.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/table/CellRangeAddress.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/form/binding/XValueBinding.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/form/binding/XListEntrySource.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/sheet/XSpreadsheet.hpp> 41*cdf0e10cSrcweir /** === end UNO includes === **/ 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir //............................................................................ 44*cdf0e10cSrcweir namespace pcr 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir //............................................................................ 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir //======================================================================== 49*cdf0e10cSrcweir //= CellBindingHelper 50*cdf0e10cSrcweir //======================================================================== 51*cdf0e10cSrcweir /** encapsulates functionality related to binding a form control to a spreadsheet cell 52*cdf0e10cSrcweir */ 53*cdf0e10cSrcweir class CellBindingHelper 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir protected: 56*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > 57*cdf0e10cSrcweir m_xControlModel; // the model we work for 58*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument > 59*cdf0e10cSrcweir m_xDocument; // the document where the model lives 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir public: 62*cdf0e10cSrcweir /** ctor 63*cdf0e10cSrcweir @param _rxControlModel 64*cdf0e10cSrcweir the control model which is or will be bound 65*cdf0e10cSrcweir */ 66*cdf0e10cSrcweir CellBindingHelper( 67*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControlModel, 68*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _rxContextDocument 69*cdf0e10cSrcweir ); 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir public: 72*cdf0e10cSrcweir /** determines whether the given model is a spreadsheet document model 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir <p>If this method returns <FALSE/>, you cannot instantiate a CellBindingHelper with 75*cdf0e10cSrcweir the document, since then no of it's functionality will be available.</p> 76*cdf0e10cSrcweir */ 77*cdf0e10cSrcweir static sal_Bool isSpreadsheetDocument( 78*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _rxContextDocument 79*cdf0e10cSrcweir ); 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir /** gets a cell binding for the given address 82*cdf0e10cSrcweir @precond 83*cdf0e10cSrcweir isCellBindingAllowed returns <TRUE/> 84*cdf0e10cSrcweir */ 85*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding > 86*cdf0e10cSrcweir createCellBindingFromStringAddress( 87*cdf0e10cSrcweir const ::rtl::OUString& _rAddress, 88*cdf0e10cSrcweir bool _bSupportIntegerExchange = false 89*cdf0e10cSrcweir ) const; 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir /** creates a cell binding (supporting integer exchange, if requested) for 92*cdf0e10cSrcweir the given address object 93*cdf0e10cSrcweir */ 94*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding > 95*cdf0e10cSrcweir createCellBindingFromAddress( 96*cdf0e10cSrcweir const ::com::sun::star::table::CellAddress& _rAddress, 97*cdf0e10cSrcweir bool _bSupportIntegerExchange = false 98*cdf0e10cSrcweir ) const; 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir /** gets a cell range list source binding for the given address 101*cdf0e10cSrcweir */ 102*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource > 103*cdf0e10cSrcweir createCellListSourceFromStringAddress( const ::rtl::OUString& _rAddress ) const; 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir /** creates a string representation for the given value binding's address 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir <p>If the sheet of the bound cell is the same as the sheet which our control belongs 108*cdf0e10cSrcweir to, then the sheet name is omitted in the resulting string representation.</p> 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir @precond 111*cdf0e10cSrcweir The binding is a valid cell binding, or <NULL/> 112*cdf0e10cSrcweir @see isCellBinding 113*cdf0e10cSrcweir */ 114*cdf0e10cSrcweir ::rtl::OUString getStringAddressFromCellBinding( 115*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding >& _rxBinding 116*cdf0e10cSrcweir ) const; 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir /** creates an address object for the given value binding's address 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir @precond 121*cdf0e10cSrcweir The binding is a valid cell binding, or <NULL/> 122*cdf0e10cSrcweir @return 123*cdf0e10cSrcweir <FALSE/> if and only if an error occured and no valid address could be obtained 124*cdf0e10cSrcweir @see isCellBinding 125*cdf0e10cSrcweir */ 126*cdf0e10cSrcweir bool getAddressFromCellBinding( 127*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding >& _rxBinding, 128*cdf0e10cSrcweir ::com::sun::star::table::CellAddress& _rAddress 129*cdf0e10cSrcweir ) const; 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir /** creates a string representation for the given list source's range address 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir <p>If the sheet of the cell range which acts as list source is the same as the 134*cdf0e10cSrcweir sheet which our control belongs to, then the sheet name is omitted in the 135*cdf0e10cSrcweir resulting string representation.</p> 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir @precond 138*cdf0e10cSrcweir The object is a valid cell range list source, or <NULL/> 139*cdf0e10cSrcweir @see isCellRangeListSource 140*cdf0e10cSrcweir */ 141*cdf0e10cSrcweir ::rtl::OUString getStringAddressFromCellListSource( 142*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >& _rxSource 143*cdf0e10cSrcweir ) const; 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir /** returns the current binding of our control model, if any. 146*cdf0e10cSrcweir */ 147*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding > 148*cdf0e10cSrcweir getCurrentBinding( ) const; 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir /** returns the current external list source of the control model, if any 151*cdf0e10cSrcweir */ 152*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource > 153*cdf0e10cSrcweir getCurrentListSource( ) const; 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir /** sets a new binding for our control model 156*cdf0e10cSrcweir @precond 157*cdf0e10cSrcweir the control model is bindable (which is implied by <member>isCellBindingAllowed</member> 158*cdf0e10cSrcweir returning <TRUE/>) 159*cdf0e10cSrcweir */ 160*cdf0e10cSrcweir void setBinding( 161*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding >& _rxBinding 162*cdf0e10cSrcweir ); 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir /** sets a list source for our control model 165*cdf0e10cSrcweir @precond 166*cdf0e10cSrcweir the control model is a list sink (which is implied by <member>isListCellRangeAllowed</member> 167*cdf0e10cSrcweir returning <TRUE/>) 168*cdf0e10cSrcweir */ 169*cdf0e10cSrcweir void setListSource( 170*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >& _rxSource 171*cdf0e10cSrcweir ); 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir /** checks whether it's possible to bind the control model to a spreadsheet cell 174*cdf0e10cSrcweir */ 175*cdf0e10cSrcweir bool isCellBindingAllowed( ) const; 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir /** checks whether it's possible to bind the control model to a spreadsheet cell, 178*cdf0e10cSrcweir with exchanging integer values 179*cdf0e10cSrcweir */ 180*cdf0e10cSrcweir bool isCellIntegerBindingAllowed( ) const; 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir /** checks whether it's possible to bind the control model to range of spreadsheet cells 183*cdf0e10cSrcweir supplying the list entries 184*cdf0e10cSrcweir */ 185*cdf0e10cSrcweir bool isListCellRangeAllowed( ) const; 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir /** checks whether a given binding is a spreadsheet cell binding 188*cdf0e10cSrcweir */ 189*cdf0e10cSrcweir bool isCellBinding( 190*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding >& _rxBinding 191*cdf0e10cSrcweir ) const; 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir /** checks whether a given binding is a spreadsheet cell binding, exchanging 194*cdf0e10cSrcweir integer values 195*cdf0e10cSrcweir */ 196*cdf0e10cSrcweir bool isCellIntegerBinding( 197*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding >& _rxBinding 198*cdf0e10cSrcweir ) const; 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir /** checks whether a given list source is a spreadsheet cell list source 201*cdf0e10cSrcweir */ 202*cdf0e10cSrcweir bool isCellRangeListSource( 203*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >& _rxSource 204*cdf0e10cSrcweir ) const; 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir /** retrieves the index of the sheet which our control belongs to 207*cdf0e10cSrcweir @return the index of the sheet which our control belongs to or -1, if an error occured 208*cdf0e10cSrcweir */ 209*cdf0e10cSrcweir sal_Int16 getControlSheetIndex( 210*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheet >& _out_rxSheet 211*cdf0e10cSrcweir ) const; 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir protected: 214*cdf0e10cSrcweir /** creates an address object from a string representation of a cell address 215*cdf0e10cSrcweir */ 216*cdf0e10cSrcweir bool convertStringAddress( 217*cdf0e10cSrcweir const ::rtl::OUString& _rAddressDescription, 218*cdf0e10cSrcweir ::com::sun::star::table::CellAddress& /* [out] */ _rAddress 219*cdf0e10cSrcweir ) const; 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir /** creates an address range object from a string representation of a cell range address 222*cdf0e10cSrcweir */ 223*cdf0e10cSrcweir bool convertStringAddress( 224*cdf0e10cSrcweir const ::rtl::OUString& _rAddressDescription, 225*cdf0e10cSrcweir ::com::sun::star::table::CellRangeAddress& /* [out] */ _rAddress 226*cdf0e10cSrcweir ) const; 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir /** determines if our document is a spreadsheet document, *and* can supply 229*cdf0e10cSrcweir the given service 230*cdf0e10cSrcweir */ 231*cdf0e10cSrcweir bool isSpreadsheetDocumentWhichSupplies( const ::rtl::OUString& _rService ) const; 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir /** checkes whether a given component supports a given servive 234*cdf0e10cSrcweir */ 235*cdf0e10cSrcweir bool doesComponentSupport( 236*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent, 237*cdf0e10cSrcweir const ::rtl::OUString& _rService 238*cdf0e10cSrcweir ) const; 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir /** uses the document (it's factory interface, respectively) to create a component instance 241*cdf0e10cSrcweir @param _rService 242*cdf0e10cSrcweir the service name 243*cdf0e10cSrcweir @param _rArgumentName 244*cdf0e10cSrcweir the name of the single argument to pass during creation. May be empty, in this case 245*cdf0e10cSrcweir no arguments are passed 246*cdf0e10cSrcweir @param _rArgumentValue 247*cdf0e10cSrcweir the value of the instantiation argument. Not evaluated if <arg>_rArgumentName</arg> 248*cdf0e10cSrcweir is empty. 249*cdf0e10cSrcweir */ 250*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 251*cdf0e10cSrcweir createDocumentDependentInstance( 252*cdf0e10cSrcweir const ::rtl::OUString& _rService, 253*cdf0e10cSrcweir const ::rtl::OUString& _rArgumentName, 254*cdf0e10cSrcweir const ::com::sun::star::uno::Any& _rArgumentValue 255*cdf0e10cSrcweir ) const; 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir /** converts an address representation into another one 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir @param _rInputProperty 260*cdf0e10cSrcweir the input property name for the conversion service 261*cdf0e10cSrcweir @param _rInputValue 262*cdf0e10cSrcweir the input property value for the conversion service 263*cdf0e10cSrcweir @param _rOutputProperty 264*cdf0e10cSrcweir the output property name for the conversion service 265*cdf0e10cSrcweir @param _rOutputValue 266*cdf0e10cSrcweir the output property value for the conversion service 267*cdf0e10cSrcweir @param _bIsRange 268*cdf0e10cSrcweir if <TRUE/>, the RangeAddressConversion service will be used, else 269*cdf0e10cSrcweir the AddressConversion service 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir @return 272*cdf0e10cSrcweir <TRUE/> if any only if the conversion was successfull 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir @see com::sun::star::table::CellAddressConversion 275*cdf0e10cSrcweir @see com::sun::star::table::CellRangeAddressConversion 276*cdf0e10cSrcweir */ 277*cdf0e10cSrcweir bool doConvertAddressRepresentations( 278*cdf0e10cSrcweir const ::rtl::OUString& _rInputProperty, 279*cdf0e10cSrcweir const ::com::sun::star::uno::Any& _rInputValue, 280*cdf0e10cSrcweir const ::rtl::OUString& _rOutputProperty, 281*cdf0e10cSrcweir ::com::sun::star::uno::Any& _rOutputValue, 282*cdf0e10cSrcweir bool _bIsRange 283*cdf0e10cSrcweir ) const SAL_THROW(()); 284*cdf0e10cSrcweir }; 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir //............................................................................ 287*cdf0e10cSrcweir } // namespace pcr 288*cdf0e10cSrcweir //............................................................................ 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir #endif // EXTENSIONS_PROPCTRLR_CELLBINDINGHELPER_HXX 291