21#include <com/sun/star/form/binding/XBindableValue.hpp>
22#include <com/sun/star/form/binding/XListEntrySink.hpp>
23#include <com/sun/star/form/FormComponentType.hpp>
24#include <com/sun/star/form/XGridColumnFactory.hpp>
25#include <com/sun/star/container/XChild.hpp>
26#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
27#include <com/sun/star/form/XFormsSupplier.hpp>
28#include <com/sun/star/form/XForm.hpp>
29#include <com/sun/star/lang/XServiceInfo.hpp>
30#include <com/sun/star/lang/XMultiServiceFactory.hpp>
31#include <com/sun/star/beans/NamedValue.hpp>
32#include <com/sun/star/sheet/XSpreadsheet.hpp>
34#include <osl/diagnose.h>
56 using namespace ::com::sun::star::form::binding;
67 explicit StringCompare( OUString _aReference ) :
m_sReference(
std::move( _aReference )) { }
69 bool operator()( std::u16string_view _rCompare )
71 return ( _rCompare == m_sReference );
78 :m_xControlModel( _rxControlModel )
80 OSL_ENSURE(
m_xControlModel.is(),
"CellBindingHelper::CellBindingHelper: invalid control model!" );
82 m_xDocument.set(_rxContextDocument, css::uno::UNO_QUERY);
83 OSL_ENSURE(
m_xDocument.is(),
"CellBindingHelper::CellBindingHelper: This is no spreadsheet document!" );
86 "CellBindingHelper::CellBindingHelper: the document cannot convert address representations!" );
92 return Reference< XSpreadsheetDocument >::query( _rxContextDocument ).is();
98 sal_Int16 nSheetIndex = -1;
107 Reference< XForm > xParentAsForm;
if ( xCheck.is() ) xParentAsForm.set(xCheck->getParent(), css::uno::UNO_QUERY);
108 Reference< XGridColumnFactory > xParentAsGrid;
if ( xCheck.is() ) xParentAsGrid.set(xCheck->getParent(), css::uno::UNO_QUERY);
110 while ( ( xParentAsForm.is() || xParentAsGrid.is() ) && xCheck.is() )
112 xCheck.set(xCheck->getParent(), css::uno::UNO_QUERY);
113 xParentAsForm.set(xCheck.is() ? xCheck->getParent() : Reference< XForm >(), css::uno::UNO_QUERY);
114 xParentAsGrid.set(xCheck.is() ? xCheck->getParent() : Reference< XGridColumnFactory >(), css::uno::UNO_QUERY);
119 Reference< XIndexAccess > xSheets(
m_xDocument->getSheets(), UNO_QUERY );
120 if ( xSheets.is() && xFormsCollection.is() )
122 for ( sal_Int32
i = 0;
i < xSheets->getCount(); ++
i )
124 Reference< XDrawPageSupplier > xSuppPage( xSheets->getByIndex(
i ), UNO_QUERY_THROW );
125 Reference< XFormsSupplier > xSuppForms( xSuppPage->getDrawPage(), UNO_QUERY_THROW );
127 if ( xSuppForms->getForms() == xFormsCollection )
129 nSheetIndex =
static_cast<sal_Int16
>(
i);
130 _out_rxSheet.set( xSuppPage, UNO_QUERY_THROW );
150 Any( _rAddressDescription ),
155 && ( aAddress >>= _rAddress );
160 const OUString& _rOutputProperty, Any& _rOutputValue,
bool _bIsRange )
const
162 bool bSuccess =
false;
172 OSL_ENSURE(
xConverter.is(),
"CellBindingHelper::doConvertAddressRepresentations: could not get a converter service!" );
177 Reference< XSpreadsheet > xSheet;
179 xConverter->setPropertyValue( _rInputProperty, _rInputValue );
180 _rOutputValue =
xConverter->getPropertyValue( _rOutputProperty );
185 TOOLS_WARN_EXCEPTION(
"extensions.propctrlr",
"CellBindingHelper::doConvertAddressRepresentations" );
194 CellRangeAddress& _rAddress )
const
199 Any( _rAddressDescription ),
204 && ( aAddress >>= _rAddress );
222 Reference< XValueBinding > xBinding;
228 CellAddress aAddress;
238 Reference< XListEntrySource > xSource;
240 CellRangeAddress aRangeAddress;
249 ), css::uno::UNO_QUERY);
256 const Any& _rArgumentValue )
const
261 OSL_ENSURE( xDocumentFactory.is(),
"CellBindingHelper::createDocumentDependentInstance: no document service factory!" );
262 if ( xDocumentFactory.is() )
266 if ( !_rArgumentName.isEmpty() )
268 Sequence aArgs{
Any(NamedValue(_rArgumentName, _rArgumentValue)) };
269 xReturn = xDocumentFactory->createInstanceWithArguments( _rService, aArgs );
273 xReturn = xDocumentFactory->createInstance( _rService );
278 OSL_FAIL(
"CellBindingHelper::createDocumentDependentInstance: could not create the binding at the document!" );
286 const Reference< XValueBinding >& _rxBinding, CellAddress& _rAddress )
const
288 OSL_PRECOND( !_rxBinding.is() ||
isCellBinding( _rxBinding ),
"CellBindingHelper::getAddressFromCellBinding: this is no cell binding!" );
290 bool bReturn =
false;
297 Reference< XPropertySet > xBindingProps( _rxBinding, UNO_QUERY );
298 OSL_ENSURE( xBindingProps.is() || !_rxBinding.is(),
"CellBindingHelper::getAddressFromCellBinding: no property set for the binding!" );
299 if ( xBindingProps.is() )
315 CellAddress aAddress;
323 aStringAddress >>= sAddress;
332 OSL_PRECOND( !_rxSource.is() ||
isCellRangeListSource( _rxSource ),
"CellBindingHelper::getStringAddressFromCellListSource: this is no cell list source!" );
341 Reference< XPropertySet > xSourceProps( _rxSource, UNO_QUERY );
342 OSL_ENSURE( xSourceProps.is() || !_rxSource.is(),
"CellBindingHelper::getStringAddressFromCellListSource: no property set for the list source!" );
343 if ( xSourceProps.is() )
345 CellRangeAddress aRangeAddress;
351 aStringAddress >>= sAddress;
356 TOOLS_WARN_EXCEPTION(
"extensions.propctrlr",
"CellBindingHelper::getStringAddressFromCellListSource" );
365 bool bYesItIs =
false;
367 Reference< XServiceInfo > xSI(
m_xDocument, UNO_QUERY );
371 OSL_ENSURE( xDocumentFactory.is(),
"CellBindingHelper::isSpreadsheetDocumentWhichSupplies: spreadsheet document, but no factory?" );
373 if ( xDocumentFactory.is() )
375 const Sequence<OUString> aAvailableServices = xDocumentFactory->getAvailableServiceNames( );
377 bYesItIs = std::any_of(
378 aAvailableServices.begin(),
379 aAvailableServices.end(),
380 StringCompare( _rService )
391 bool bAllow(
false );
409 if ( !xBindable.is() )
422 sal_Int16 nClassId = FormComponentType::CONTROL;
424 if ( FormComponentType::LISTBOX != nClassId )
429 TOOLS_WARN_EXCEPTION(
"extensions.propctrlr",
"CellBindingHelper::isCellIntegerBindingAllowed" );
442 bool bAllow(
false );
445 if ( xBindable.is() )
459 sal_Int16 nClassId = FormComponentType::CONTROL;
461 if ( ( FormComponentType::DATEFIELD == nClassId ) || ( FormComponentType::TIMEFIELD == nClassId ) )
494 Reference< XServiceInfo > xSI( _rxComponent, UNO_QUERY );
495 bool bDoes = xSI.is() && xSI->supportsService( _rService );
502 Reference< XValueBinding > xBinding;
504 if ( xBindable.is() )
505 xBinding = xBindable->getValueBinding();
512 Reference< XListEntrySource > xSource;
515 xSource =
xSink->getListEntrySource();
523 OSL_PRECOND( xBindable.is(),
"CellBindingHelper::setBinding: the object is not bindable!" );
524 if ( xBindable.is() )
525 xBindable->setValueBinding( _rxBinding );
532 OSL_PRECOND(
xSink.is(),
"CellBindingHelper::setListSource: the object is no list entry sink!" );
534 xSink->setListEntrySource( _rxSource );
sal_Int16 getControlSheetIndex(css::uno::Reference< css::sheet::XSpreadsheet > &_out_rxSheet) const
retrieves the index of the sheet which our control belongs to
static bool isCellIntegerBinding(const css::uno::Reference< css::form::binding::XValueBinding > &_rxBinding)
checks whether a given binding is a spreadsheet cell binding, exchanging integer values
static bool isCellRangeListSource(const css::uno::Reference< css::form::binding::XListEntrySource > &_rxSource)
checks whether a given list source is a spreadsheet cell list source
OUString getStringAddressFromCellBinding(const css::uno::Reference< css::form::binding::XValueBinding > &_rxBinding) const
creates a string representation for the given value binding's address
css::uno::Reference< css::form::binding::XValueBinding > createCellBindingFromStringAddress(const OUString &_rAddress, bool _bSupportIntegerExchange) const
gets a cell binding for the given address @precond isCellBindingAllowed returns <TRUE>
css::uno::Reference< css::form::binding::XValueBinding > getCurrentBinding() const
returns the current binding of our control model, if any.
bool isCellIntegerBindingAllowed() const
checks whether it's possible to bind the control model to a spreadsheet cell, with exchanging integer...
static bool isCellBinding(const css::uno::Reference< css::form::binding::XValueBinding > &_rxBinding)
checks whether a given binding is a spreadsheet cell binding
bool getAddressFromCellBinding(const css::uno::Reference< css::form::binding::XValueBinding > &_rxBinding, css::table::CellAddress &_rAddress) const
creates an address object for the given value binding's address
bool doConvertAddressRepresentations(const OUString &_rInputProperty, const css::uno::Any &_rInputValue, const OUString &_rOutputProperty, css::uno::Any &_rOutputValue, bool _bIsRange) const
converts an address representation into another one
bool isCellBindingAllowed() const
checks whether it's possible to bind the control model to a spreadsheet cell
static bool doesComponentSupport(const css::uno::Reference< css::uno::XInterface > &_rxComponent, const OUString &_rService)
checks whether a given component supports a given service
static bool isSpreadsheetDocument(const css::uno::Reference< css::frame::XModel > &_rxContextDocument)
determines whether the given model is a spreadsheet document model
bool isSpreadsheetDocumentWhichSupplies(const OUString &_rService) const
determines if our document is a spreadsheet document, and can supply the given service
void setListSource(const css::uno::Reference< css::form::binding::XListEntrySource > &_rxSource)
sets a list source for our control model @precond the control model is a list sink (which is implied ...
css::uno::Reference< css::form::binding::XValueBinding > createCellBindingFromAddress(const css::table::CellAddress &_rAddress, bool _bSupportIntegerExchange) const
creates a cell binding (supporting integer exchange, if requested) for the given address object
css::uno::Reference< css::uno::XInterface > createDocumentDependentInstance(const OUString &_rService, const OUString &_rArgumentName, const css::uno::Any &_rArgumentValue) const
uses the document (it's factory interface, respectively) to create a component instance
css::uno::Reference< css::form::binding::XListEntrySource > getCurrentListSource() const
returns the current external list source of the control model, if any
CellBindingHelper(const css::uno::Reference< css::beans::XPropertySet > &_rxControlModel, const css::uno::Reference< css::frame::XModel > &_rxContextDocument)
ctor
css::uno::Reference< css::sheet::XSpreadsheetDocument > m_xDocument
void setBinding(const css::uno::Reference< css::form::binding::XValueBinding > &_rxBinding)
sets a new binding for our control model @precond the control model is bindable (which is implied by ...
OUString getStringAddressFromCellListSource(const css::uno::Reference< css::form::binding::XListEntrySource > &_rxSource) const
creates a string representation for the given list source's range address
bool convertStringAddress(const OUString &_rAddressDescription, css::table::CellAddress &_rAddress) const
creates an address object from a string representation of a cell address
bool isListCellRangeAllowed() const
checks whether it's possible to bind the control model to range of spreadsheet cells supplying the li...
css::uno::Reference< css::beans::XPropertySet > m_xControlModel
css::uno::Reference< css::form::binding::XListEntrySource > createCellListSourceFromStringAddress(const OUString &_rAddress) const
gets a cell range list source binding for the given address
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
Reference< XTypeConverter > xConverter
tools::SvRef< SvBaseLink > xSink
a property handler for any virtual string properties