21#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
22#include <com/sun/star/lang/NotInitializedException.hpp>
23#include <com/sun/star/lang/NullPointerException.hpp>
24#include <com/sun/star/table/XCellRange.hpp>
25#include <com/sun/star/text/XTextRange.hpp>
26#include <com/sun/star/sheet/XCellRangeAddressable.hpp>
27#include <com/sun/star/sheet/FormulaResult.hpp>
28#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
29#include <com/sun/star/util/XModifyBroadcaster.hpp>
30#include <com/sun/star/container/XIndexAccess.hpp>
31#include <com/sun/star/beans/PropertyAttribute.hpp>
32#include <com/sun/star/beans/NamedValue.hpp>
39#define PROP_HANDLE_RANGE_ADDRESS 1
49 using namespace ::com::sun::star::form::binding;
56 ,m_bInitialized( false )
58 OSL_PRECOND(
m_xDocument.is(),
"OCellListSource::OCellListSource: invalid document!" );
61 registerPropertyNoMember(
64 PropertyAttribute::BOUND | PropertyAttribute::READONLY,
66 css::uno::Any(CellRangeAddress())
70 OCellListSource::~OCellListSource( )
72 if ( !OCellListSource_Base::rBHelper.bDisposed )
85 ::osl::MutexGuard aGuard(
m_aMutex );
87 Reference<XModifyBroadcaster> xBroadcaster( m_xRange, UNO_QUERY );
88 if ( xBroadcaster.is() )
90 xBroadcaster->removeModifyListener(
this );
93 EventObject aDisposeEvent( *
this );
94 m_aListEntryListeners.disposeAndClear( aDisposeEvent );
96 WeakComponentImplHelperBase::disposing();
101 Reference< XPropertySetInfo > SAL_CALL OCellListSource::getPropertySetInfo( )
103 return createPropertySetInfo( getInfoHelper() ) ;
108 return *OCellListSource_PABase::getArrayHelper();
113 Sequence< Property > aProps;
114 describeProperties( aProps );
115 return new ::cppu::OPropertyArrayHelper(aProps);
118 void SAL_CALL OCellListSource::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle )
const
123 _rValue <<= getRangeAddress( );
126 void OCellListSource::checkDisposed( )
const
128 if ( OCellListSource_Base::rBHelper.bInDispose || OCellListSource_Base::rBHelper.bDisposed )
129 throw DisposedException();
133 void OCellListSource::checkInitialized()
135 if ( !m_bInitialized )
136 throw NotInitializedException(
"CellListSource is not initialized", getXWeak());
139 OUString SAL_CALL OCellListSource::getImplementationName( )
141 return "com.sun.star.comp.sheet.OCellListSource";
144 sal_Bool SAL_CALL OCellListSource::supportsService(
const OUString& _rServiceName )
149 Sequence< OUString > SAL_CALL OCellListSource::getSupportedServiceNames( )
151 return {
"com.sun.star.table.CellRangeListSource",
152 "com.sun.star.form.binding.ListEntrySource"};
155 CellRangeAddress OCellListSource::getRangeAddress( )
const
157 OSL_PRECOND( m_xRange.is(),
"OCellListSource::getRangeAddress: invalid range!" );
159 CellRangeAddress aAddress;
160 Reference< XCellRangeAddressable > xRangeAddress( m_xRange, UNO_QUERY );
161 if ( xRangeAddress.is() )
162 aAddress = xRangeAddress->getRangeAddress( );
166 OUString OCellListSource::getCellTextContent_noCheck( sal_Int32 _nRangeRelativeRow, css::uno::Any* pAny )
170 OSL_PRECOND( m_xRange.is(),
"OCellListSource::getRangeAddress: invalid range!" );
175 Reference< XCell > xCell( m_xRange->getCellByPosition( 0, _nRangeRelativeRow ));
183 Reference< XTextRange > xCellText;
184 xCellText.set( xCell, UNO_QUERY);
187 sText = xCellText->getString();
191 switch (xCell->getType())
193 case CellContentType_VALUE:
194 *pAny <<= xCell->getValue();
196 case CellContentType_TEXT:
199 case CellContentType_FORMULA:
200 if (xCell->getError())
204 Reference< XPropertySet > xProp( xCell, UNO_QUERY);
207 sal_Int32 nResultType;
208 if ((xProp->getPropertyValue(
"FormulaResultType2") >>= nResultType) &&
209 nResultType == FormulaResult::VALUE)
210 *pAny <<= xCell->getValue();
216 case CellContentType_EMPTY:
217 *pAny <<= OUString();
227 sal_Int32 SAL_CALL OCellListSource::getListEntryCount( )
229 ::osl::MutexGuard aGuard(
m_aMutex );
233 CellRangeAddress aAddress( getRangeAddress( ) );
234 return aAddress.EndRow - aAddress.StartRow + 1;
237 OUString SAL_CALL OCellListSource::getListEntry( sal_Int32 _nPosition )
239 ::osl::MutexGuard aGuard(
m_aMutex );
243 if ( _nPosition >= getListEntryCount() )
244 throw IndexOutOfBoundsException();
246 return getCellTextContent_noCheck( _nPosition,
nullptr );
249 Sequence< OUString > SAL_CALL OCellListSource::getAllListEntries( )
251 ::osl::MutexGuard aGuard(
m_aMutex );
255 Sequence< OUString > aAllEntries( getListEntryCount() );
256 OUString* pAllEntries = aAllEntries.getArray();
257 for ( sal_Int32
i = 0;
i < aAllEntries.getLength(); ++
i )
259 *pAllEntries++ = getCellTextContent_noCheck(
i,
nullptr );
265 Sequence< OUString > SAL_CALL OCellListSource::getAllListEntriesTyped( Sequence< Any >& rDataValues )
267 ::osl::MutexGuard aGuard(
m_aMutex );
271 const sal_Int32
nCount = getListEntryCount();
272 Sequence< OUString > aAllEntries(
nCount );
273 rDataValues = Sequence< Any >(
nCount );
274 OUString* pAllEntries = aAllEntries.getArray();
275 Any* pDataValues = rDataValues.getArray();
278 *pAllEntries++ = getCellTextContent_noCheck(
i, pDataValues++ );
284 void SAL_CALL OCellListSource::addListEntryListener(
const Reference< XListEntryListener >& _rxListener )
286 ::osl::MutexGuard aGuard(
m_aMutex );
290 if ( !_rxListener.is() )
291 throw NullPointerException();
293 m_aListEntryListeners.addInterface( _rxListener );
296 void SAL_CALL OCellListSource::removeListEntryListener(
const Reference< XListEntryListener >& _rxListener )
298 ::osl::MutexGuard aGuard(
m_aMutex );
302 if ( !_rxListener.is() )
303 throw NullPointerException();
305 m_aListEntryListeners.removeInterface( _rxListener );
308 void SAL_CALL OCellListSource::modified(
const EventObject& )
313 void OCellListSource::notifyModified()
331 TOOLS_WARN_EXCEPTION(
"sc",
"OCellListSource::notifyModified: caught a (non-runtime) exception!" );
337 void SAL_CALL OCellListSource::disposing(
const EventObject& aEvent )
339 Reference<XInterface> xRangeInt( m_xRange, UNO_QUERY );
340 if ( xRangeInt ==
aEvent.Source )
347 void SAL_CALL OCellListSource::initialize(
const Sequence< Any >& _rArguments )
349 if ( m_bInitialized )
350 throw RuntimeException(
"CellListSource is already initialized", getXWeak());
353 CellRangeAddress aRangeAddress;
354 bool bFoundAddress =
false;
356 for (
const Any& rArg : _rArguments )
359 if ( rArg >>= aValue )
361 if ( aValue.Name ==
"CellRange" )
363 if ( aValue.Value >>= aRangeAddress )
365 bFoundAddress =
true;
372 if ( !bFoundAddress )
381 Reference< XIndexAccess > xSheets(
m_xDocument->getSheets( ), UNO_QUERY);
382 OSL_ENSURE( xSheets.is(),
"OCellListSource::initialize: could not retrieve the sheets!" );
387 Reference< XCellRange > xSheet(xSheets->getByIndex( aRangeAddress.Sheet ), UNO_QUERY);
388 OSL_ENSURE( xSheet.is(),
"OCellListSource::initialize: NULL sheet, but no exception!" );
393 m_xRange.set(xSheet->getCellRangeByPosition(
394 aRangeAddress.StartColumn, aRangeAddress.StartRow,
395 aRangeAddress.EndColumn, aRangeAddress.EndRow));
396 OSL_ENSURE( Reference< XCellRangeAddressable >( m_xRange, UNO_QUERY ).is(),
"OCellListSource::initialize: either NULL range, or cell without address access!" );
403 TOOLS_WARN_EXCEPTION(
"sc",
"OCellListSource::initialize: caught an exception while retrieving the cell object!" );
406 if ( !m_xRange.is() )
409 Reference<XModifyBroadcaster> xBroadcaster( m_xRange, UNO_QUERY );
410 if ( xBroadcaster.is() )
412 xBroadcaster->addModifyListener(
this );
428 m_bInitialized =
true;
#define PROP_HANDLE_RANGE_ADDRESS
OCellListSource(const css::uno::Reference< css::sheet::XSpreadsheetDocument > &_rxDocument)
has XInitialization::initialize been called?
bool hasMoreElements() const
css::uno::Reference< ListenerT > const & next()
Reference< XOfficeDatabaseDocument > m_xDocument
#define TOOLS_WARN_EXCEPTION(area, stream)
::comphelper::OPropertyContainer OCellListSource_PBase
::cppu::WeakComponentImplHelper< css::form::binding::XListEntryTypedSource, css::util::XModifyListener, css::lang::XServiceInfo, css::lang::XInitialization > OCellListSource_Base
void checkDisposed(bool _bThrow)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)