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 )
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 Any( _rAddressDescription ),
121 && ( aAddress >>= _rAddress );
125 CellRangeAddress& _rAddress )
const
130 Any( _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!" );
184 Reference< XPropertySet > xBindingProps( _rxBinding, UNO_QUERY );
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!" );
213 Reference< XPropertySet > xSourceProps( _rxSource, UNO_QUERY );
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?" );
246 if ( xDocumentFactory.is() )
248 const Sequence<OUString> aAvailableServices = xDocumentFactory->getAvailableServiceNames( );
250 bYesItIs = std::any_of( aAvailableServices.begin(), aAvailableServices.end(), StringCompare( _rService ) );
254 catch(
const Exception& )
270 Reference< XSpreadsheetDocument >( _rxDocument, UNO_QUERY ),
277 bool bAllow(
false );
290 bool bAllow(
false );
293 if ( xBindable.is() )
306 Reference< XSpreadsheetDocument >( _rxDocument, UNO_QUERY ),
328 Reference< XServiceInfo > xSI( _rxComponent, UNO_QUERY );
329 bool bDoes = xSI.is() && xSI->supportsService( _rService );
335 Reference< XValueBinding > xBinding;
337 if ( xBindable.is() )
338 xBinding = xBindable->getValueBinding();
344 Reference< XListEntrySource > xSource;
347 xSource =
xSink->getListEntrySource();
354 OSL_PRECOND( xBindable.is(),
"FormCellBindingHelper::setBinding: the object is not bindable!" );
355 if ( xBindable.is() )
356 xBindable->setValueBinding( _rxBinding );
362 OSL_PRECOND(
xSink.is(),
"FormCellBindingHelper::setListSource: the object is no list entry sink!" );
364 xSink->setListEntrySource( _rxSource );
368 const Any& _rArgumentValue )
const
370 Reference< XInterface > xReturn;
372 Reference< XMultiServiceFactory > xDocumentFactory(
m_xDocument, UNO_QUERY );
373 OSL_ENSURE( xDocumentFactory.is(),
"FormCellBindingHelper::createDocumentDependentInstance: no document service factory!" );
374 if ( xDocumentFactory.is() )
378 if ( !_rArgumentName.isEmpty() )
381 aArg.Name = _rArgumentName;
382 aArg.Value = _rArgumentValue;
384 Sequence< Any > aArgs{
Any(aArg) };
385 xReturn = xDocumentFactory->createInstanceWithArguments( _rService, aArgs );
389 xReturn = xDocumentFactory->createInstance( _rService );
394 OSL_FAIL(
"FormCellBindingHelper::createDocumentDependentInstance: could not create the binding at the document!" );
401 const OUString& _rOutputProperty, Any& _rOutputValue,
bool _bIsRange )
const
403 bool bSuccess =
false;
413 OSL_ENSURE(
xConverter.is(),
"FormCellBindingHelper::doConvertAddressRepresentations: could not get a converter service!" );
418 xConverter->setPropertyValue( _rInputProperty, _rInputValue );
419 _rOutputValue =
xConverter->getPropertyValue( _rOutputProperty );
Reference< XOfficeDatabaseDocument > m_xDocument
#define TOOLS_WARN_EXCEPTION(area, stream)
Reference< XTypeConverter > xConverter
tools::SvRef< SvBaseLink > xSink
constexpr OUStringLiteral SERVICE_LISTINDEXCELLBINDING
constexpr OUStringLiteral PROPERTY_LIST_CELL_RANGE
constexpr OUStringLiteral SERVICE_ADDRESS_CONVERSION
constexpr OUStringLiteral SERVICE_CELLRANGELISTSOURCE
constexpr OUStringLiteral PROPERTY_ADDRESS
constexpr OUStringLiteral PROPERTY_FILE_REPRESENTATION
constexpr OUStringLiteral SERVICE_RANGEADDRESS_CONVERSION
constexpr OUStringLiteral SERVICE_CELLVALUEBINDING
constexpr OUStringLiteral PROPERTY_BOUND_CELL
constexpr OUStringLiteral SERVICE_SPREADSHEET_DOCUMENT