21 #include <com/sun/star/form/binding/XBindableValue.hpp>
22 #include <com/sun/star/form/binding/XListEntrySink.hpp>
23 #include <com/sun/star/frame/XModel.hpp>
24 #include <com/sun/star/container/XChild.hpp>
25 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/beans/NamedValue.hpp>
30 #include <osl/diagnose.h>
47 using namespace ::com::sun::star::form::binding;
51 using ::com::sun::star::uno::Reference;
52 using ::com::sun::star::uno::XInterface;
53 using ::com::sun::star::container::XChild;
54 using ::com::sun::star::frame::XModel;
55 using ::com::sun::star::uno::UNO_QUERY;
57 template<
class TYPE >
58 Reference< TYPE > getTypedModelNode(
const Reference< XInterface >& _rxModelNode )
60 Reference< TYPE > xTypedNode( _rxModelNode, UNO_QUERY );
61 if ( xTypedNode.is() )
65 Reference< XChild > xChild( _rxModelNode, UNO_QUERY );
67 return getTypedModelNode< TYPE >( xChild->getParent() );
73 Reference< XModel > getDocument(
const Reference< XInterface >& _rxModelNode )
75 return getTypedModelNode< XModel >( _rxModelNode );
84 explicit StringCompare(
const OUString& _rReference ) : m_sReference( _rReference ) { }
86 bool operator()( std::u16string_view _rCompare )
88 return ( _rCompare == m_sReference );
95 :m_xControlModel( _rxControlModel )
98 OSL_ENSURE(
m_xControlModel.is(),
"FormCellBindingHelper::FormCellBindingHelper: invalid control model!" );
102 OSL_ENSURE(
m_xDocument.is(),
"FormCellBindingHelper::FormCellBindingHelper: Did not find the spreadsheet document!" );
107 Reference< XSpreadsheetDocument > xDocument( getDocument( _rxControlModel ), UNO_QUERY );
108 return xDocument.is();
116 makeAny( _rAddressDescription ),
121 && ( aAddress >>= _rAddress );
125 CellRangeAddress& _rAddress )
const
130 makeAny( _rAddressDescription ),
135 && ( aAddress >>= _rAddress );
140 Reference< XValueBinding > xBinding;
146 CellAddress aAddress;
154 ), css::uno::UNO_QUERY);
161 Reference< XListEntrySource > xSource;
163 CellRangeAddress aRangeAddress;
172 ), css::uno::UNO_QUERY);
179 OSL_PRECOND( !_rxBinding.is() ||
isCellBinding( _rxBinding ),
"FormCellBindingHelper::getStringAddressFromCellBinding: this is no cell binding!" );
185 OSL_ENSURE( xBindingProps.is() || !_rxBinding.is(),
"FormCellBindingHelper::getStringAddressFromCellBinding: no property set for the binding!" );
186 if ( xBindingProps.is() )
188 CellAddress aAddress;
195 aStringAddress >>= sAddress;
208 OSL_PRECOND( !_rxSource.is() ||
isCellRangeListSource( _rxSource ),
"FormCellBindingHelper::getStringAddressFromCellListSource: this is no cell list source!" );
214 OSL_ENSURE( xSourceProps.is() || !_rxSource.is(),
"FormCellBindingHelper::getStringAddressFromCellListSource: no property set for the list source!" );
215 if ( xSourceProps.is() )
217 CellRangeAddress aRangeAddress;
223 aStringAddress >>= sAddress;
236 bool bYesItIs =
false;
240 Reference< XServiceInfo > xSI( _rxDocument, UNO_QUERY );
243 Reference< XMultiServiceFactory > xDocumentFactory( _rxDocument, UNO_QUERY );
244 OSL_ENSURE( xDocumentFactory.is(),
"FormCellBindingHelper::isSpreadsheetDocumentWhichSupplies: spreadsheet document, but no factory?" );
247 if ( xDocumentFactory.is() )
248 aAvailableServices = xDocumentFactory->getAvailableServiceNames( );
250 bYesItIs = std::any_of( aAvailableServices.begin(), aAvailableServices.end(), StringCompare( _rService ) );
253 catch(
const Exception& )
269 Reference< XSpreadsheetDocument >( _rxDocument, UNO_QUERY ),
276 bool bAllow(
false );
289 bool bAllow(
false );
292 if ( xBindable.is() )
305 Reference< XSpreadsheetDocument >( _rxDocument, UNO_QUERY ),
327 Reference< XServiceInfo > xSI( _rxComponent, UNO_QUERY );
328 bool bDoes = xSI.is() && xSI->supportsService( _rService );
334 Reference< XValueBinding > xBinding;
336 if ( xBindable.is() )
337 xBinding = xBindable->getValueBinding();
343 Reference< XListEntrySource > xSource;
346 xSource = xSink->getListEntrySource();
353 OSL_PRECOND( xBindable.is(),
"FormCellBindingHelper::setBinding: the object is not bindable!" );
354 if ( xBindable.is() )
355 xBindable->setValueBinding( _rxBinding );
361 OSL_PRECOND( xSink.is(),
"FormCellBindingHelper::setListSource: the object is no list entry sink!" );
363 xSink->setListEntrySource( _rxSource );
367 const Any& _rArgumentValue )
const
369 Reference< XInterface > xReturn;
371 Reference< XMultiServiceFactory > xDocumentFactory(
m_xDocument, UNO_QUERY );
372 OSL_ENSURE( xDocumentFactory.is(),
"FormCellBindingHelper::createDocumentDependentInstance: no document service factory!" );
373 if ( xDocumentFactory.is() )
377 if ( !_rArgumentName.isEmpty() )
380 aArg.Name = _rArgumentName;
381 aArg.Value = _rArgumentValue;
383 Sequence< Any > aArgs( 1 );
386 xReturn = xDocumentFactory->createInstanceWithArguments( _rService, aArgs );
390 xReturn = xDocumentFactory->createInstance( _rService );
395 OSL_FAIL(
"FormCellBindingHelper::createDocumentDependentInstance: could not create the binding at the document!" );
402 const OUString& _rOutputProperty, Any& _rOutputValue,
bool _bIsRange )
const
404 bool bSuccess =
false;
414 OSL_ENSURE( xConverter.is(),
"FormCellBindingHelper::doConvertAddressRepresentations: could not get a converter service!" );
415 if ( xConverter.is() )
419 xConverter->setPropertyValue( _rInputProperty, _rInputValue );
420 _rOutputValue = xConverter->getPropertyValue( _rOutputProperty );
Reference< XTypeConverter > xConverter
tools::SvRef< SvBaseLink > xSink
Reference< XOfficeDatabaseDocument > m_xDocument
#define SERVICE_SPREADSHEET_DOCUMENT
#define SERVICE_CELLVALUEBINDING
#define PROPERTY_FILE_REPRESENTATION
#define PROPERTY_LIST_CELL_RANGE
#define PROPERTY_BOUND_CELL
#define TOOLS_WARN_EXCEPTION(area, stream)
#define SERVICE_CELLRANGELISTSOURCE
#define SERVICE_RANGEADDRESS_CONVERSION