include/comphelper/propshlp.hxx | 9 +- sc/inc/chartuno.hxx | 21 +++--- sc/source/ui/unoobj/celllistsource.cxx | 104 +++++++++++++++------------------ sc/source/ui/unoobj/celllistsource.hxx | 26 ++++---- sc/source/ui/unoobj/chartuno.cxx | 8 -- 5 files changed, 79 insertions(+), 89 deletions(-)
New commits: commit 9462674c6501f1d04bc7bdea08b6035bf88ae0df Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Tue Mar 26 15:46:24 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Wed Mar 27 19:11:03 2024 +0100 convert ScChartObj to comphelper::WeakComponentImplHelper Change-Id: I94974713ce5acff13aa0c12a782f9f3fdf004f55 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165363 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sc/inc/chartuno.hxx b/sc/inc/chartuno.hxx index 8eba30e630f5..b09ba9243c24 100644 --- a/sc/inc/chartuno.hxx +++ b/sc/inc/chartuno.hxx @@ -23,7 +23,7 @@ #include <rtl/ref.hxx> #include <svl/lstner.hxx> #include <comphelper/proparrhlp.hxx> -#include <comphelper/propertycontainer.hxx> +#include <comphelper/propertycontainer2.hxx> #include <com/sun/star/table/XTableChart.hpp> #include <com/sun/star/table/XTableCharts.hpp> @@ -32,8 +32,7 @@ #include <com/sun/star/container/XEnumerationAccess.hpp> #include <com/sun/star/container/XIndexAccess.hpp> #include <com/sun/star/container/XNamed.hpp> -#include <cppuhelper/basemutex.hxx> -#include <cppuhelper/compbase.hxx> +#include <comphelper/compbase.hxx> #include <cppuhelper/implbase.hxx> class ScDocShell; @@ -89,17 +88,17 @@ public: virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; }; -typedef ::cppu::WeakComponentImplHelper< +typedef ::comphelper::WeakComponentImplHelper< css::table::XTableChart, css::document::XEmbeddedObjectSupplier, css::container::XNamed, css::lang::XServiceInfo > ScChartObj_Base; -typedef ::comphelper::OPropertyContainer ScChartObj_PBase; +typedef ::comphelper::OPropertyContainer2 ScChartObj_PBase; typedef ::comphelper::OPropertyArrayUsageHelper< ScChartObj > ScChartObj_PABase; -class ScChartObj final : public ::cppu::BaseMutex - ,public ScChartObj_Base +class ScChartObj final : + public ScChartObj_Base ,public ScChartObj_PBase ,public ScChartObj_PABase ,public SfxListener @@ -113,10 +112,10 @@ private: void GetData_Impl( ScRangeListRef& rRanges, bool& rColHeaders, bool& rRowHeaders ) const; // ::comphelper::OPropertySetHelper - virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; - virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const css::uno::Any& rValue ) override; - using ::cppu::OPropertySetHelper::getFastPropertyValue; - virtual void SAL_CALL getFastPropertyValue( css::uno::Any& rValue, sal_Int32 nHandle ) const override; + virtual ::cppu::IPropertyArrayHelper& getInfoHelper() override; + virtual void setFastPropertyValue_NoBroadcast( std::unique_lock<std::mutex>& rGuard, sal_Int32 nHandle, const css::uno::Any& rValue ) override; + using ::comphelper::OPropertySetHelper::getFastPropertyValue; + virtual void getFastPropertyValue( std::unique_lock<std::mutex>& rGuard, css::uno::Any& rValue, sal_Int32 nHandle ) const override; // ::comphelper::OPropertyArrayUsageHelper virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const override; diff --git a/sc/source/ui/unoobj/chartuno.cxx b/sc/source/ui/unoobj/chartuno.cxx index c905d68aff0a..f3e4be6863e5 100644 --- a/sc/source/ui/unoobj/chartuno.cxx +++ b/sc/source/ui/unoobj/chartuno.cxx @@ -406,9 +406,7 @@ sal_Bool SAL_CALL ScChartsObj::hasByName( const OUString& aName ) } ScChartObj::ScChartObj(ScDocShell* pDocSh, SCTAB nT, OUString aN) - :ScChartObj_Base( m_aMutex ) - ,ScChartObj_PBase( ScChartObj_Base::rBHelper ) - ,pDocShell( pDocSh ) + :pDocShell( pDocSh ) ,nTab( nT ) ,aChartName(std::move( aN )) { @@ -519,7 +517,7 @@ void ScChartObj::Update_Impl( const ScRangeListRef& rRanges, bool bColHeaders, b return *ScChartObj_PABase::getArrayHelper(); } -void ScChartObj::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const uno::Any& rValue ) +void ScChartObj::setFastPropertyValue_NoBroadcast( std::unique_lock<std::mutex>& /*rGuard*/, sal_Int32 nHandle, const uno::Any& rValue ) { switch ( nHandle ) { @@ -551,7 +549,7 @@ void ScChartObj::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const uno: } } -void ScChartObj::getFastPropertyValue( uno::Any& rValue, sal_Int32 nHandle ) const +void ScChartObj::getFastPropertyValue( std::unique_lock<std::mutex>& /*rGuard*/, uno::Any& rValue, sal_Int32 nHandle ) const { switch ( nHandle ) { commit a95bff116e1da140b9abe9742ceeb9a3caed43d5 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Tue Mar 26 15:42:52 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Wed Mar 27 19:10:54 2024 +0100 convert OCellListSource to comphelper::WeakComponentImplHelper Change-Id: Iec9a3d20868c96dfe23141930b660e08773b5833 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165362 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/include/comphelper/propshlp.hxx b/include/comphelper/propshlp.hxx index e605a4d65812..d5f148de4893 100644 --- a/include/comphelper/propshlp.hxx +++ b/include/comphelper/propshlp.hxx @@ -44,11 +44,10 @@ namespace comphelper This is a modified copy of the cppuhelper::OPropertySetHelper class, except that is uses std::mutex instead of osl::Mutex. */ -class UNLESS_MERGELIBS(COMPHELPER_DLLPUBLIC) OPropertySetHelper - : public virtual comphelper::UnoImplBase, - public css::beans::XMultiPropertySet, - public css::beans::XFastPropertySet, - public css::beans::XPropertySet +class COMPHELPER_DLLPUBLIC OPropertySetHelper : public virtual comphelper::UnoImplBase, + public css::beans::XMultiPropertySet, + public css::beans::XFastPropertySet, + public css::beans::XPropertySet { public: OPropertySetHelper(); diff --git a/sc/source/ui/unoobj/celllistsource.cxx b/sc/source/ui/unoobj/celllistsource.cxx index bca1e0a6956f..21c98d72f894 100644 --- a/sc/source/ui/unoobj/celllistsource.cxx +++ b/sc/source/ui/unoobj/celllistsource.cxx @@ -49,10 +49,7 @@ namespace calc using namespace ::com::sun::star::form::binding; OCellListSource::OCellListSource( const Reference< XSpreadsheetDocument >& _rxDocument ) - :OCellListSource_Base( m_aMutex ) - ,OCellListSource_PBase( OCellListSource_Base::rBHelper ) - ,m_xDocument( _rxDocument ) - ,m_aListEntryListeners( m_aMutex ) + :m_xDocument( _rxDocument ) ,m_bInitialized( false ) { OSL_PRECOND( m_xDocument.is(), "OCellListSource::OCellListSource: invalid document!" ); @@ -69,7 +66,7 @@ namespace calc OCellListSource::~OCellListSource( ) { - if ( !OCellListSource_Base::rBHelper.bDisposed ) + if ( !m_bDisposed ) { acquire(); // prevent duplicate dtor dispose(); @@ -80,10 +77,8 @@ namespace calc IMPLEMENT_FORWARD_XTYPEPROVIDER2( OCellListSource, OCellListSource_Base, OCellListSource_PBase ) - void SAL_CALL OCellListSource::disposing() + void OCellListSource::disposing(std::unique_lock<std::mutex>& rGuard) { - ::osl::MutexGuard aGuard( m_aMutex ); - Reference<XModifyBroadcaster> xBroadcaster( m_xRange, UNO_QUERY ); if ( xBroadcaster.is() ) { @@ -91,9 +86,9 @@ namespace calc } EventObject aDisposeEvent( *this ); - m_aListEntryListeners.disposeAndClear( aDisposeEvent ); + m_aListEntryListeners.disposeAndClear( rGuard, aDisposeEvent ); - WeakComponentImplHelperBase::disposing(); + WeakComponentImplHelperBase::disposing(rGuard); // TODO: clean up here whatever you need to clean up (e.g. revoking listeners etc.) } @@ -103,7 +98,7 @@ namespace calc return createPropertySetInfo( getInfoHelper() ) ; } - ::cppu::IPropertyArrayHelper& SAL_CALL OCellListSource::getInfoHelper() + ::cppu::IPropertyArrayHelper& OCellListSource::getInfoHelper() { return *OCellListSource_PABase::getArrayHelper(); } @@ -115,7 +110,7 @@ namespace calc return new ::cppu::OPropertyArrayHelper(aProps); } - void SAL_CALL OCellListSource::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const + void OCellListSource::getFastPropertyValue( std::unique_lock<std::mutex>& /*rGuard*/, Any& _rValue, sal_Int32 _nHandle ) const { OSL_ENSURE( _nHandle == PROP_HANDLE_RANGE_ADDRESS, "OCellListSource::getFastPropertyValue: invalid handle!" ); // we only have this one property... @@ -123,13 +118,6 @@ namespace calc _rValue <<= getRangeAddress( ); } - void OCellListSource::checkDisposed( ) const - { - if ( OCellListSource_Base::rBHelper.bInDispose || OCellListSource_Base::rBHelper.bDisposed ) - throw DisposedException(); - // TODO: is it worth having an error message here? - } - void OCellListSource::checkInitialized() { if ( !m_bInitialized ) @@ -163,7 +151,7 @@ namespace calc return aAddress; } - OUString OCellListSource::getCellTextContent_noCheck( sal_Int32 _nRangeRelativeRow, css::uno::Any* pAny ) + OUString OCellListSource::getCellTextContent_noCheck( std::unique_lock<std::mutex>& /*rGuard*/, sal_Int32 _nRangeRelativeRow, css::uno::Any* pAny ) { OUString sText; @@ -226,37 +214,41 @@ namespace calc sal_Int32 SAL_CALL OCellListSource::getListEntryCount( ) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(); + std::unique_lock<std::mutex> aGuard( m_aMutex ); + throwIfDisposed(aGuard); checkInitialized(); + return getListEntryCount(aGuard); + } + sal_Int32 OCellListSource::getListEntryCount( std::unique_lock<std::mutex>& /*rGuard*/ ) + { CellRangeAddress aAddress( getRangeAddress( ) ); return aAddress.EndRow - aAddress.StartRow + 1; } OUString SAL_CALL OCellListSource::getListEntry( sal_Int32 _nPosition ) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(); + std::unique_lock<std::mutex> aGuard( m_aMutex ); + throwIfDisposed(aGuard); checkInitialized(); if ( _nPosition >= getListEntryCount() ) throw IndexOutOfBoundsException(); - return getCellTextContent_noCheck( _nPosition, nullptr ); + return getCellTextContent_noCheck( aGuard, _nPosition, nullptr ); } Sequence< OUString > SAL_CALL OCellListSource::getAllListEntries( ) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(); + std::unique_lock<std::mutex> aGuard( m_aMutex ); + throwIfDisposed(aGuard); checkInitialized(); - Sequence< OUString > aAllEntries( getListEntryCount() ); + Sequence< OUString > aAllEntries( getListEntryCount(aGuard) ); OUString* pAllEntries = aAllEntries.getArray(); for ( sal_Int32 i = 0; i < aAllEntries.getLength(); ++i ) { - *pAllEntries++ = getCellTextContent_noCheck( i, nullptr ); + *pAllEntries++ = getCellTextContent_noCheck( aGuard, i, nullptr ); } return aAllEntries; @@ -264,18 +256,18 @@ namespace calc Sequence< OUString > SAL_CALL OCellListSource::getAllListEntriesTyped( Sequence< Any >& rDataValues ) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(); + std::unique_lock<std::mutex> aGuard( m_aMutex ); + throwIfDisposed(aGuard); checkInitialized(); - const sal_Int32 nCount = getListEntryCount(); + const sal_Int32 nCount = getListEntryCount(aGuard); Sequence< OUString > aAllEntries( nCount ); rDataValues = Sequence< Any >( nCount ); OUString* pAllEntries = aAllEntries.getArray(); Any* pDataValues = rDataValues.getArray(); for ( sal_Int32 i = 0; i < nCount; ++i ) { - *pAllEntries++ = getCellTextContent_noCheck( i, pDataValues++ ); + *pAllEntries++ = getCellTextContent_noCheck( aGuard, i, pDataValues++ ); } return aAllEntries; @@ -283,26 +275,26 @@ namespace calc void SAL_CALL OCellListSource::addListEntryListener( const Reference< XListEntryListener >& _rxListener ) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(); + std::unique_lock<std::mutex> aGuard( m_aMutex ); + throwIfDisposed(aGuard); checkInitialized(); if ( !_rxListener.is() ) throw NullPointerException(); - m_aListEntryListeners.addInterface( _rxListener ); + m_aListEntryListeners.addInterface( aGuard, _rxListener ); } void SAL_CALL OCellListSource::removeListEntryListener( const Reference< XListEntryListener >& _rxListener ) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(); + std::unique_lock<std::mutex> aGuard( m_aMutex ); + throwIfDisposed(aGuard); checkInitialized(); if ( !_rxListener.is() ) throw NullPointerException(); - m_aListEntryListeners.removeInterface( _rxListener ); + m_aListEntryListeners.removeInterface( aGuard, _rxListener ); } void SAL_CALL OCellListSource::modified( const EventObject& /* aEvent */ ) @@ -312,26 +304,28 @@ namespace calc void OCellListSource::notifyModified() { + std::unique_lock<std::mutex> aGuard( m_aMutex ); EventObject aEvent; aEvent.Source.set(*this); - ::comphelper::OInterfaceIteratorHelper3 aIter( m_aListEntryListeners ); - while ( aIter.hasMoreElements() ) - { - try - { - aIter.next()->allEntriesChanged( aEvent ); - } - catch( const RuntimeException& ) - { - // silent this - } - catch( const Exception& ) + m_aListEntryListeners.forEach(aGuard, + [&aEvent, &aGuard] (const css::uno::Reference<css::form::binding::XListEntryListener>& l) { - TOOLS_WARN_EXCEPTION( "sc", "OCellListSource::notifyModified: caught a (non-runtime) exception!" ); - } - } - + aGuard.unlock(); + try + { + l->allEntriesChanged( aEvent ); + } + catch( const RuntimeException& ) + { + // silent this + } + catch( const Exception& ) + { + TOOLS_WARN_EXCEPTION( "sc", "OCellListSource::notifyModified: caught a (non-runtime) exception!" ); + } + aGuard.lock(); + }); } void SAL_CALL OCellListSource::disposing( const EventObject& aEvent ) diff --git a/sc/source/ui/unoobj/celllistsource.hxx b/sc/source/ui/unoobj/celllistsource.hxx index c919c18ec27e..96eb5caa500a 100644 --- a/sc/source/ui/unoobj/celllistsource.hxx +++ b/sc/source/ui/unoobj/celllistsource.hxx @@ -20,10 +20,9 @@ #pragma once #include <com/sun/star/form/binding/XListEntryTypedSource.hpp> -#include <cppuhelper/compbase.hxx> -#include <cppuhelper/basemutex.hxx> -#include <comphelper/interfacecontainer3.hxx> -#include <comphelper/propertycontainer.hxx> +#include <comphelper/compbase.hxx> +#include <comphelper/interfacecontainer4.hxx> +#include <comphelper/propertycontainer2.hxx> #include <comphelper/uno3.hxx> #include <comphelper/proparrhlp.hxx> #include <com/sun/star/table/CellRangeAddress.hpp> @@ -41,19 +40,18 @@ namespace calc class OCellListSource; // the base for our interfaces - typedef ::cppu::WeakComponentImplHelper < css::form::binding::XListEntryTypedSource + typedef ::comphelper::WeakComponentImplHelper < css::form::binding::XListEntryTypedSource , css::util::XModifyListener , css::lang::XServiceInfo , css::lang::XInitialization > OCellListSource_Base; // the base for the property handling - typedef ::comphelper::OPropertyContainer OCellListSource_PBase; + typedef ::comphelper::OPropertyContainer2 OCellListSource_PBase; // the second base for property handling typedef ::comphelper::OPropertyArrayUsageHelper< OCellListSource > OCellListSource_PABase; - class OCellListSource :public ::cppu::BaseMutex - ,public OCellListSource_Base // order matters! before OCellListSource_PBase, so rBHelper gets initialized + class OCellListSource :public OCellListSource_Base // order matters! before OCellListSource_PBase, so rBHelper gets initialized ,public OCellListSource_PBase ,public OCellListSource_PABase { @@ -62,7 +60,7 @@ namespace calc m_xDocument; /// the document where our cell lives css::uno::Reference< css::table::XCellRange > m_xRange; /// the range of cells we're bound to - ::comphelper::OInterfaceContainerHelper3<css::form::binding::XListEntryListener> + ::comphelper::OInterfaceContainerHelper4<css::form::binding::XListEntryListener> m_aListEntryListeners; /// our listeners bool m_bInitialized; /// has XInitialization::initialize been called? @@ -94,7 +92,7 @@ namespace calc virtual css::uno::Sequence< OUString > SAL_CALL getAllListEntriesTyped( css::uno::Sequence< css::uno::Any >& rDataValues ) override; // OComponentHelper/XComponent - virtual void SAL_CALL disposing() override; + virtual void disposing( std::unique_lock<std::mutex>& ) override; // XServiceInfo virtual OUString SAL_CALL getImplementationName( ) override; @@ -105,8 +103,8 @@ namespace calc virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; // OPropertySetHelper - virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; - virtual void SAL_CALL getFastPropertyValue( css::uno::Any& _rValue, sal_Int32 _nHandle ) const override; + virtual ::cppu::IPropertyArrayHelper& getInfoHelper() override; + virtual void getFastPropertyValue( std::unique_lock<std::mutex>& rGuard, css::uno::Any& _rValue, sal_Int32 _nHandle ) const override; // ::comphelper::OPropertyArrayUsageHelper virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override; @@ -119,7 +117,6 @@ namespace calc virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override; private: - void checkDisposed( ) const; void checkInitialized(); /** retrieves the actual address of our cell range @@ -139,12 +136,15 @@ namespace calc */ OUString getCellTextContent_noCheck( + std::unique_lock<std::mutex>& rGuard, sal_Int32 _nRangeRelativeRow, css::uno::Any* pAny ); void notifyModified(); + sal_Int32 getListEntryCount(std::unique_lock<std::mutex>& rGuard); + private: OCellListSource( const OCellListSource& ) = delete; OCellListSource& operator=( const OCellListSource& ) = delete;