From 30784e55e484de2790c4b264a50a65acf450c000 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 8 Mar 2023 13:15:39 +0200 Subject: convert UnoControlModel and friends to use std::mutex Which means creating a variant of the cppuhelper::OPropertySetHelper helper class which uses a std::mutex. Since we can do virtual base classes now (which the original could not), use that and a new helper class comphelper::UnoImplBase to share std::mutex m_aMutex; bool m_bDisposing; fields that the OPropertySetHelper wants to share with the parent class. Change-Id: I05ad465a3d3653ed4e109137e3e1c58190da8d97 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148474 Tested-by: Jenkins Reviewed-by: Noel Grandin --- toolkit/inc/controls/animatedimages.hxx | 7 +- toolkit/inc/controls/controlmodelcontainerbase.hxx | 8 +- toolkit/inc/controls/dialogcontrol.hxx | 24 +--- toolkit/inc/controls/formattedcontrol.hxx | 14 +- toolkit/inc/controls/roadmapcontrol.hxx | 2 +- toolkit/inc/controls/tabpagecontainer.hxx | 2 +- toolkit/inc/controls/tabpagemodel.hxx | 2 +- toolkit/inc/controls/tkscrollbar.hxx | 2 +- toolkit/inc/controls/unocontrolcontainermodel.hxx | 2 +- toolkit/source/controls/animatedimages.cxx | 46 +++---- .../source/controls/controlmodelcontainerbase.cxx | 18 +-- toolkit/source/controls/dialogcontrol.cxx | 17 +-- toolkit/source/controls/formattedcontrol.cxx | 39 +++--- toolkit/source/controls/grid/gridcontrol.cxx | 11 +- toolkit/source/controls/grid/gridcontrol.hxx | 4 +- toolkit/source/controls/spinningprogress.cxx | 6 +- toolkit/source/controls/tabpagecontainer.cxx | 6 +- toolkit/source/controls/tkspinbutton.cxx | 3 +- toolkit/source/controls/tree/treecontrol.hxx | 6 +- toolkit/source/controls/unocontrolmodel.cxx | 96 ++++++------- toolkit/source/controls/unocontrols.cxx | 148 ++++++++++----------- 21 files changed, 224 insertions(+), 239 deletions(-) (limited to 'toolkit') diff --git a/toolkit/inc/controls/animatedimages.hxx b/toolkit/inc/controls/animatedimages.hxx index a341447c5366..fca49bfa39de 100644 --- a/toolkit/inc/controls/animatedimages.hxx +++ b/toolkit/inc/controls/animatedimages.hxx @@ -72,10 +72,13 @@ namespace toolkit virtual ~AnimatedImagesControlModel() override; css::uno::Any ImplGetDefaultValue( sal_uInt16 nPropId ) const override; - ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; - void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const css::uno::Any& rValue ) override; + ::cppu::IPropertyArrayHelper& getInfoHelper() override; + void setFastPropertyValue_NoBroadcast( + std::unique_lock& rGuard, + sal_Int32 nHandle, const css::uno::Any& rValue ) override; private: + comphelper::OInterfaceContainerHelper4 maContainerListeners; std::vector< css::uno::Sequence< OUString > > maImageSets; }; diff --git a/toolkit/inc/controls/controlmodelcontainerbase.hxx b/toolkit/inc/controls/controlmodelcontainerbase.hxx index 1bbc3f301b16..ae414346c78f 100644 --- a/toolkit/inc/controls/controlmodelcontainerbase.hxx +++ b/toolkit/inc/controls/controlmodelcontainerbase.hxx @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include #include @@ -78,7 +78,7 @@ public: protected: ContainerListenerMultiplexer maContainerListeners; - ::comphelper::OInterfaceContainerHelper3 maChangeListeners; + ::comphelper::OInterfaceContainerHelper4 maChangeListeners; UnoControlModelHolderVector maModels; AllGroups maGroups; @@ -91,7 +91,7 @@ protected: void Clone_Impl(ControlModelContainerBase& _rClone) const; protected: css::uno::Any ImplGetDefaultValue( sal_uInt16 nPropId ) const override; - ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; + ::cppu::IPropertyArrayHelper& getInfoHelper() override; UnoControlModelHolderVector::iterator ImplFindElement( std::u16string_view rName ); @@ -152,7 +152,7 @@ public: virtual void SAL_CALL propertyChange( const css::beans::PropertyChangeEvent& evt ) override; // XEventListener - using cppu::OPropertySetHelper::disposing; + using comphelper::OPropertySetHelper::disposing; virtual void SAL_CALL disposing( const css::lang::EventObject& evt ) override; // XServiceInfo diff --git a/toolkit/inc/controls/dialogcontrol.hxx b/toolkit/inc/controls/dialogcontrol.hxx index b23c60f445f5..3aaf3e50b135 100644 --- a/toolkit/inc/controls/dialogcontrol.hxx +++ b/toolkit/inc/controls/dialogcontrol.hxx @@ -160,13 +160,9 @@ class UnoMultiPageModel final : public ControlModelContainerBase { public: UnoMultiPageModel( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); + UnoMultiPageModel(const UnoMultiPageModel& rOther) : ControlModelContainerBase(rOther) {} virtual ~UnoMultiPageModel() override; - UnoMultiPageModel(UnoMultiPageModel const &) = default; - UnoMultiPageModel(UnoMultiPageModel &&) = default; - UnoMultiPageModel & operator =(UnoMultiPageModel const &) = delete; // due to ControlModelContainerBase - UnoMultiPageModel & operator =(UnoMultiPageModel &&) = delete; // due to ControlModelContainerBase - rtl::Reference Clone() const override; DECLIMPL_SERVICEINFO_DERIVED( UnoMultiPageModel, ControlModelContainerBase, "com.sun.star.awt.UnoMultiPageModel" ) @@ -180,7 +176,7 @@ public: virtual sal_Bool SAL_CALL getGroupControl( ) override; private: virtual css::uno::Any ImplGetDefaultValue( sal_uInt16 nPropId ) const override; - ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; + ::cppu::IPropertyArrayHelper& getInfoHelper() override; }; @@ -239,13 +235,9 @@ class UnoPageModel final : public ControlModelContainerBase { public: UnoPageModel( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); + UnoPageModel(const UnoPageModel& rOther) : ControlModelContainerBase(rOther) {} virtual ~UnoPageModel() override; - UnoPageModel(UnoPageModel const &) = default; - UnoPageModel(UnoPageModel &&) = default; - UnoPageModel & operator =(UnoPageModel const &) = delete; // due to ControlModelContainerBase - UnoPageModel & operator =(UnoPageModel &&) = delete; // due to ControlModelContainerBase - rtl::Reference Clone() const override; DECLIMPL_SERVICEINFO_DERIVED( UnoPageModel, ControlModelContainerBase, "com.sun.star.awt.UnoPageModel" ) @@ -257,7 +249,7 @@ public: virtual sal_Bool SAL_CALL getGroupControl( ) override; private: virtual css::uno::Any ImplGetDefaultValue( sal_uInt16 nPropId ) const override; - ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; + ::cppu::IPropertyArrayHelper& getInfoHelper() override; }; @@ -277,13 +269,9 @@ class UnoFrameModel final : public ControlModelContainerBase { public: UnoFrameModel( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); + UnoFrameModel(const UnoFrameModel& rOther) : ControlModelContainerBase(rOther) {} virtual ~UnoFrameModel() override; - UnoFrameModel(UnoFrameModel const &) = default; - UnoFrameModel(UnoFrameModel &&) = default; - UnoFrameModel & operator =(UnoFrameModel const &) = delete; // due to ControlModelContainerBase - UnoFrameModel & operator =(UnoFrameModel &&) = delete; // due to ControlModelContainerBase - rtl::Reference Clone() const override; DECLIMPL_SERVICEINFO_DERIVED( UnoFrameModel, ControlModelContainerBase, "com.sun.star.awt.UnoFrameModel" ) @@ -293,7 +281,7 @@ public: private: virtual css::uno::Any ImplGetDefaultValue( sal_uInt16 nPropId ) const override; - ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; + ::cppu::IPropertyArrayHelper& getInfoHelper() override; }; class UnoFrameControl final : public ControlContainerBase diff --git a/toolkit/inc/controls/formattedcontrol.hxx b/toolkit/inc/controls/formattedcontrol.hxx index 388d94312aab..c614b42c74d3 100644 --- a/toolkit/inc/controls/formattedcontrol.hxx +++ b/toolkit/inc/controls/formattedcontrol.hxx @@ -72,20 +72,22 @@ namespace toolkit css::uno::Any* _pValues, /// the values of the properties to set sal_Int32* _pValidHandles /// pointer to the valid handles, allowed to be adjusted ) const override; - void impl_updateTextFromValue_nothrow(); - void impl_updateCachedFormatter_nothrow(); - void impl_updateCachedFormatKey_nothrow(); + void impl_updateTextFromValue_nothrow(std::unique_lock& rGuard); + void impl_updateCachedFormatter_nothrow(std::unique_lock& rGuard); + void impl_updateCachedFormatKey_nothrow(std::unique_lock& rGuard); css::uno::Any ImplGetDefaultValue( sal_uInt16 nPropId ) const override; - ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; - sal_Bool SAL_CALL convertFastPropertyValue( + ::cppu::IPropertyArrayHelper& getInfoHelper() override; + bool convertFastPropertyValue( + std::unique_lock& rGuard, css::uno::Any& rConvertedValue, css::uno::Any& rOldValue, sal_Int32 nPropId, const css::uno::Any& rValue ) override; - void SAL_CALL setFastPropertyValue_NoBroadcast( + void setFastPropertyValue_NoBroadcast( + std::unique_lock& rGuard, sal_Int32 nHandle, const css::uno::Any& rValue ) override; diff --git a/toolkit/inc/controls/roadmapcontrol.hxx b/toolkit/inc/controls/roadmapcontrol.hxx index cfc7fbdb9c74..cb6e2cec4533 100644 --- a/toolkit/inc/controls/roadmapcontrol.hxx +++ b/toolkit/inc/controls/roadmapcontrol.hxx @@ -83,7 +83,7 @@ namespace toolkit sal_Int32 GetUniqueID(); css::uno::Any ImplGetDefaultValue( sal_uInt16 nPropId ) const override; - ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; + ::cppu::IPropertyArrayHelper& getInfoHelper() override; public: UnoControlRoadmapModel( const css::uno::Reference< css::uno::XComponentContext >& i_factory ); diff --git a/toolkit/inc/controls/tabpagecontainer.hxx b/toolkit/inc/controls/tabpagecontainer.hxx index d8cc32664406..f9fe2df02d50 100644 --- a/toolkit/inc/controls/tabpagecontainer.hxx +++ b/toolkit/inc/controls/tabpagecontainer.hxx @@ -43,7 +43,7 @@ private: ContainerListenerMultiplexer maContainerListeners; css::uno::Any ImplGetDefaultValue( sal_uInt16 nPropId ) const override; - ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; + ::cppu::IPropertyArrayHelper& getInfoHelper() override; // css::beans::XMultiPropertySet css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; diff --git a/toolkit/inc/controls/tabpagemodel.hxx b/toolkit/inc/controls/tabpagemodel.hxx index 6c12981b28e9..48a84fe5a602 100644 --- a/toolkit/inc/controls/tabpagemodel.hxx +++ b/toolkit/inc/controls/tabpagemodel.hxx @@ -26,7 +26,7 @@ class UnoControlTabPageModel final : public ControlModelContainerBase { css::uno::Any ImplGetDefaultValue( sal_uInt16 nPropId ) const override; - ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; + ::cppu::IPropertyArrayHelper& getInfoHelper() override; public: UnoControlTabPageModel( css::uno::Reference< css::uno::XComponentContext > const & i_factory); diff --git a/toolkit/inc/controls/tkscrollbar.hxx b/toolkit/inc/controls/tkscrollbar.hxx index ec774fa9dfb3..c7948de072e5 100644 --- a/toolkit/inc/controls/tkscrollbar.hxx +++ b/toolkit/inc/controls/tkscrollbar.hxx @@ -33,7 +33,7 @@ namespace toolkit class UnoControlScrollBarModel final : public UnoControlModel { css::uno::Any ImplGetDefaultValue( sal_uInt16 nPropId ) const override; - ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; + ::cppu::IPropertyArrayHelper& getInfoHelper() override; public: UnoControlScrollBarModel( const css::uno::Reference< css::uno::XComponentContext >& i_factory ); diff --git a/toolkit/inc/controls/unocontrolcontainermodel.hxx b/toolkit/inc/controls/unocontrolcontainermodel.hxx index 4fe48cdcab6f..83db8af31b7c 100644 --- a/toolkit/inc/controls/unocontrolcontainermodel.hxx +++ b/toolkit/inc/controls/unocontrolcontainermodel.hxx @@ -27,7 +27,7 @@ class UnoControlContainerModel final : public UnoControlModel { css::uno::Any ImplGetDefaultValue( sal_uInt16 nPropId ) const override; - ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; + ::cppu::IPropertyArrayHelper& getInfoHelper() override; public: UnoControlContainerModel( const css::uno::Reference< css::uno::XComponentContext >& i_factory ); diff --git a/toolkit/source/controls/animatedimages.cxx b/toolkit/source/controls/animatedimages.cxx index d188ab20960b..5d8267998496 100644 --- a/toolkit/source/controls/animatedimages.cxx +++ b/toolkit/source/controls/animatedimages.cxx @@ -211,12 +211,11 @@ namespace toolkit { throw IndexOutOfBoundsException( OUString(), i_context ); } - void lcl_notify( ::osl::ClearableMutexGuard& i_guard, ::cppu::OBroadcastHelper const & i_broadcaseHelper, + void lcl_notify( std::unique_lock& i_guard, comphelper::OInterfaceContainerHelper4& rContainer, void ( SAL_CALL XContainerListener::*i_notificationMethod )( const ContainerEvent& ), const sal_Int32 i_accessor, const Sequence< OUString >& i_imageURLs, const Reference< XInterface >& i_context ) { - ::cppu::OInterfaceContainerHelper* pContainerListeners = i_broadcaseHelper.getContainer( cppu::UnoType::get() ); - if ( pContainerListeners == nullptr ) + if ( !rContainer.getLength(i_guard) ) return; ContainerEvent aEvent; @@ -224,8 +223,7 @@ namespace toolkit { aEvent.Accessor <<= i_accessor; aEvent.Element <<= i_imageURLs; - i_guard.clear(); - pContainerListeners->notifyEach( i_notificationMethod, aEvent ); + rContainer.notifyEach( i_guard, i_notificationMethod, aEvent ); } } @@ -289,7 +287,7 @@ namespace toolkit { } - void SAL_CALL AnimatedImagesControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 i_handle, const Any& i_value ) + void AnimatedImagesControlModel::setFastPropertyValue_NoBroadcast( std::unique_lock& rGuard, sal_Int32 i_handle, const Any& i_value ) { switch ( i_handle ) { @@ -306,7 +304,7 @@ namespace toolkit { break; } - AnimatedImagesControlModel_Base::setFastPropertyValue_NoBroadcast( i_handle, i_value ); + AnimatedImagesControlModel_Base::setFastPropertyValue_NoBroadcast( rGuard, i_handle, i_value ); } @@ -335,7 +333,7 @@ namespace toolkit { } - ::cppu::IPropertyArrayHelper& SAL_CALL AnimatedImagesControlModel::getInfoHelper() + ::cppu::IPropertyArrayHelper& AnimatedImagesControlModel::getInfoHelper() { static UnoPropertyArrayHelper aHelper( ImplGetPropertyIds() ); return aHelper; @@ -386,8 +384,8 @@ namespace toolkit { ::sal_Int32 SAL_CALL AnimatedImagesControlModel::getImageSetCount( ) { - ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); - if ( GetBroadcastHelper().bDisposed || GetBroadcastHelper().bInDispose ) + std::unique_lock aGuard( m_aMutex ); + if ( m_bDisposed ) throw DisposedException(); return maImageSets.size(); @@ -396,8 +394,8 @@ namespace toolkit { Sequence< OUString > SAL_CALL AnimatedImagesControlModel::getImageSet( ::sal_Int32 i_index ) { - ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); - if ( GetBroadcastHelper().bDisposed || GetBroadcastHelper().bInDispose ) + std::unique_lock aGuard( m_aMutex ); + if ( m_bDisposed ) throw DisposedException(); lcl_checkIndex( maImageSets, i_index, *this ); @@ -408,9 +406,9 @@ namespace toolkit { void SAL_CALL AnimatedImagesControlModel::insertImageSet( ::sal_Int32 i_index, const Sequence< OUString >& i_imageURLs ) { - ::osl::ClearableMutexGuard aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); // sanity checks - if ( GetBroadcastHelper().bDisposed || GetBroadcastHelper().bInDispose ) + if ( m_bDisposed ) throw DisposedException(); lcl_checkIndex( maImageSets, i_index, *this, true ); @@ -419,15 +417,15 @@ namespace toolkit { maImageSets.insert( maImageSets.begin() + i_index, i_imageURLs ); // listener notification - lcl_notify( aGuard, m_aBHelper, &XContainerListener::elementInserted, i_index, i_imageURLs, *this ); + lcl_notify( aGuard, maContainerListeners, &XContainerListener::elementInserted, i_index, i_imageURLs, *this ); } void SAL_CALL AnimatedImagesControlModel::replaceImageSet( ::sal_Int32 i_index, const Sequence< OUString >& i_imageURLs ) { - ::osl::ClearableMutexGuard aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); // sanity checks - if ( GetBroadcastHelper().bDisposed || GetBroadcastHelper().bInDispose ) + if ( m_bDisposed ) throw DisposedException(); lcl_checkIndex( maImageSets, i_index, *this ); @@ -436,15 +434,15 @@ namespace toolkit { maImageSets[ i_index ] = i_imageURLs; // listener notification - lcl_notify( aGuard, m_aBHelper, &XContainerListener::elementReplaced, i_index, i_imageURLs, *this ); + lcl_notify( aGuard, maContainerListeners, &XContainerListener::elementReplaced, i_index, i_imageURLs, *this ); } void SAL_CALL AnimatedImagesControlModel::removeImageSet( ::sal_Int32 i_index ) { - ::osl::ClearableMutexGuard aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); // sanity checks - if ( GetBroadcastHelper().bDisposed || GetBroadcastHelper().bInDispose ) + if ( m_bDisposed ) throw DisposedException(); lcl_checkIndex( maImageSets, i_index, *this ); @@ -455,19 +453,21 @@ namespace toolkit { maImageSets.erase( removalPos ); // listener notification - lcl_notify( aGuard, m_aBHelper, &XContainerListener::elementRemoved, i_index, aRemovedElement, *this ); + lcl_notify( aGuard, maContainerListeners, &XContainerListener::elementRemoved, i_index, aRemovedElement, *this ); } void SAL_CALL AnimatedImagesControlModel::addContainerListener( const Reference< XContainerListener >& i_listener ) { - m_aBHelper.addListener( cppu::UnoType::get(), i_listener ); + std::unique_lock aGuard( m_aMutex ); + maContainerListeners.addInterface( aGuard, i_listener ); } void SAL_CALL AnimatedImagesControlModel::removeContainerListener( const Reference< XContainerListener >& i_listener ) { - m_aBHelper.removeListener( cppu::UnoType::get(), i_listener ); + std::unique_lock aGuard( m_aMutex ); + maContainerListeners.removeInterface( aGuard, i_listener ); } } diff --git a/toolkit/source/controls/controlmodelcontainerbase.cxx b/toolkit/source/controls/controlmodelcontainerbase.cxx index b0b37df4cbf7..bec15994a034 100644 --- a/toolkit/source/controls/controlmodelcontainerbase.cxx +++ b/toolkit/source/controls/controlmodelcontainerbase.cxx @@ -168,7 +168,6 @@ static OUString getStepPropertyName( ) ControlModelContainerBase::ControlModelContainerBase( const Reference< XComponentContext >& rxContext ) :ControlModelContainer_IBase( rxContext ) ,maContainerListeners( *this ) - ,maChangeListeners ( GetMutex() ) ,mbGroupsUpToDate( false ) ,m_nTabPageId(0) { @@ -178,7 +177,6 @@ ControlModelContainerBase::ControlModelContainerBase( const Reference< XComponen ControlModelContainerBase::ControlModelContainerBase( const ControlModelContainerBase& rModel ) : ControlModelContainer_IBase( rModel ) , maContainerListeners( *this ) - , maChangeListeners ( GetMutex() ) , mbGroupsUpToDate( false ) , m_nTabPageId( rModel.m_nTabPageId ) { @@ -217,13 +215,13 @@ void SAL_CALL ControlModelContainerBase::dispose( ) // tell our listeners { - ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); EventObject aDisposeEvent; aDisposeEvent.Source = static_cast< XAggregation* >( static_cast< ::cppu::OWeakAggObject* >( this ) ); - maContainerListeners.disposeAndClear( aDisposeEvent ); - maChangeListeners.disposeAndClear( aDisposeEvent ); + maContainerListeners.disposeAndClear( aGuard, aDisposeEvent ); + maChangeListeners.disposeAndClear( aGuard, aDisposeEvent ); } @@ -848,13 +846,15 @@ void SAL_CALL ControlModelContainerBase::getGroupByName( const OUString& _rName, void SAL_CALL ControlModelContainerBase::addChangesListener( const Reference< XChangesListener >& _rxListener ) { - maChangeListeners.addInterface( _rxListener ); + std::unique_lock g(m_aMutex); + maChangeListeners.addInterface( g, _rxListener ); } void SAL_CALL ControlModelContainerBase::removeChangesListener( const Reference< XChangesListener >& _rxListener ) { - maChangeListeners.removeInterface( _rxListener ); + std::unique_lock g(m_aMutex); + maChangeListeners.removeInterface( g, _rxListener ); } @@ -869,7 +869,9 @@ void ControlModelContainerBase::implNotifyTabModelChange( const OUString& _rAcce aEvent.Changes.getArray()[ 0 ].Accessor <<= _rAccessor; - std::vector< Reference< css::util::XChangesListener > > aChangeListeners( maChangeListeners.getElements() ); + std::unique_lock g(m_aMutex); + std::vector< Reference< css::util::XChangesListener > > aChangeListeners( maChangeListeners.getElements(g) ); + g.unlock(); for ( const auto& rListener : aChangeListeners ) rListener->changesOccurred( aEvent ); } diff --git a/toolkit/source/controls/dialogcontrol.cxx b/toolkit/source/controls/dialogcontrol.cxx index 67ee3bcc6719..b9027cbf17d7 100644 --- a/toolkit/source/controls/dialogcontrol.cxx +++ b/toolkit/source/controls/dialogcontrol.cxx @@ -137,9 +137,9 @@ class UnoControlDialogModel : public ControlModelContainerBase protected: css::uno::Reference< css::graphic::XGraphicObject > mxGrfObj; css::uno::Any ImplGetDefaultValue( sal_uInt16 nPropId ) const override; - ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; - // ::cppu::OPropertySetHelper - void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const css::uno::Any& rValue ) override; + ::cppu::IPropertyArrayHelper& getInfoHelper() override; + // ::comphelper::OPropertySetHelper + void setFastPropertyValue_NoBroadcast( std::unique_lock& rGuard, sal_Int32 nHandle, const css::uno::Any& rValue ) override; public: explicit UnoControlDialogModel( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); UnoControlDialogModel( const UnoControlDialogModel& rModel ); @@ -213,7 +213,8 @@ UnoControlDialogModel::UnoControlDialogModel( const UnoControlDialogModel& rMode if ( xSrcNameCont->hasByName( name ) ) xNameCont->insertByName( name, xSrcNameCont->getByName( name ) ); } - setFastPropertyValue_NoBroadcast( BASEPROPERTY_USERFORMCONTAINEES, Any( xNameCont ) ); + std::unique_lock aGuard(m_aMutex); + setFastPropertyValue_NoBroadcast( aGuard, BASEPROPERTY_USERFORMCONTAINEES, Any( xNameCont ) ); } rtl::Reference UnoControlDialogModel::Clone() const @@ -267,9 +268,9 @@ Reference< XPropertySetInfo > UnoControlDialogModel::getPropertySetInfo( ) return xInfo; } -void SAL_CALL UnoControlDialogModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const css::uno::Any& rValue ) +void UnoControlDialogModel::setFastPropertyValue_NoBroadcast( std::unique_lock& rGuard, sal_Int32 nHandle, const css::uno::Any& rValue ) { - ControlModelContainerBase::setFastPropertyValue_NoBroadcast( nHandle, rValue ); + ControlModelContainerBase::setFastPropertyValue_NoBroadcast( rGuard, nHandle, rValue ); try { if ( nHandle == BASEPROPERTY_IMAGEURL && ImplHasProperty( BASEPROPERTY_GRAPHIC ) ) @@ -278,14 +279,14 @@ void SAL_CALL UnoControlDialogModel::setFastPropertyValue_NoBroadcast( sal_Int32 uno::Reference xGraphic; if (rValue >>= sImageURL) { - setPropertyValue( + setPropertyValueImpl(rGuard, GetPropertyName(BASEPROPERTY_GRAPHIC), uno::Any(ImageHelper::getGraphicAndGraphicObjectFromURL_nothrow( mxGrfObj, sImageURL))); } else if (rValue >>= xGraphic) { - setPropertyValue("Graphic", uno::Any(xGraphic)); + setPropertyValueImpl(rGuard, "Graphic", uno::Any(xGraphic)); } } } diff --git a/toolkit/source/controls/formattedcontrol.cxx b/toolkit/source/controls/formattedcontrol.cxx index e96a6986a7d0..ff34f4cbdda7 100644 --- a/toolkit/source/controls/formattedcontrol.cxx +++ b/toolkit/source/controls/formattedcontrol.cxx @@ -154,39 +154,39 @@ namespace toolkit } - void SAL_CALL UnoControlFormattedFieldModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) + void UnoControlFormattedFieldModel::setFastPropertyValue_NoBroadcast( std::unique_lock& rGuard, sal_Int32 nHandle, const Any& rValue ) { - UnoControlModel::setFastPropertyValue_NoBroadcast( nHandle, rValue ); + UnoControlModel::setFastPropertyValue_NoBroadcast( rGuard, nHandle, rValue ); switch ( nHandle ) { case BASEPROPERTY_EFFECTIVE_VALUE: if ( !m_bSettingValueAndText ) - impl_updateTextFromValue_nothrow(); + impl_updateTextFromValue_nothrow(rGuard); break; case BASEPROPERTY_FORMATSSUPPLIER: - impl_updateCachedFormatter_nothrow(); - impl_updateTextFromValue_nothrow(); + impl_updateCachedFormatter_nothrow(rGuard); + impl_updateTextFromValue_nothrow(rGuard); break; case BASEPROPERTY_FORMATKEY: - impl_updateCachedFormatKey_nothrow(); - impl_updateTextFromValue_nothrow(); + impl_updateCachedFormatKey_nothrow(rGuard); + impl_updateTextFromValue_nothrow(rGuard); break; } } - void UnoControlFormattedFieldModel::impl_updateTextFromValue_nothrow() + void UnoControlFormattedFieldModel::impl_updateTextFromValue_nothrow( std::unique_lock& rGuard) { if ( !m_xCachedFormatter.is() ) - impl_updateCachedFormatter_nothrow(); + impl_updateCachedFormatter_nothrow(rGuard); if ( !m_xCachedFormatter.is() ) return; try { Any aEffectiveValue; - getFastPropertyValue( aEffectiveValue, BASEPROPERTY_EFFECTIVE_VALUE ); + getFastPropertyValue( rGuard, aEffectiveValue, BASEPROPERTY_EFFECTIVE_VALUE ); OUString sStringValue; if ( !( aEffectiveValue >>= sStringValue ) ) @@ -201,7 +201,7 @@ namespace toolkit } } - setPropertyValue( GetPropertyName( BASEPROPERTY_TEXT ), Any( sStringValue ) ); + setPropertyValueImpl( rGuard, GetPropertyName( BASEPROPERTY_TEXT ), Any( sStringValue ) ); } catch( const Exception& ) { @@ -210,10 +210,10 @@ namespace toolkit } - void UnoControlFormattedFieldModel::impl_updateCachedFormatter_nothrow() + void UnoControlFormattedFieldModel::impl_updateCachedFormatter_nothrow(std::unique_lock& rGuard) { Any aFormatsSupplier; - getFastPropertyValue( aFormatsSupplier, BASEPROPERTY_FORMATSSUPPLIER ); + getFastPropertyValue( rGuard, aFormatsSupplier, BASEPROPERTY_FORMATSSUPPLIER ); try { Reference< XNumberFormatsSupplier > xSupplier( aFormatsSupplier, UNO_QUERY ); @@ -236,10 +236,10 @@ namespace toolkit } - void UnoControlFormattedFieldModel::impl_updateCachedFormatKey_nothrow() + void UnoControlFormattedFieldModel::impl_updateCachedFormatKey_nothrow(std::unique_lock& rGuard) { Any aFormatKey; - getFastPropertyValue( aFormatKey, BASEPROPERTY_FORMATKEY ); + getFastPropertyValue( rGuard, aFormatKey, BASEPROPERTY_FORMATKEY ); m_aCachedFormat = aFormatKey; } @@ -248,7 +248,7 @@ namespace toolkit { UnoControlModel::dispose(); - ::osl::MutexGuard aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); if ( !m_bRevokedAsClient ) { lcl_revokeDefaultFormatsClient(); @@ -305,7 +305,8 @@ namespace toolkit } - sal_Bool UnoControlFormattedFieldModel::convertFastPropertyValue( + bool UnoControlFormattedFieldModel::convertFastPropertyValue( + std::unique_lock& rGuard, Any& rConvertedValue, Any& rOldValue, sal_Int32 nPropId, const Any& rValue ) { @@ -338,7 +339,7 @@ namespace toolkit if ( bStreamed ) { - getFastPropertyValue( rOldValue, nPropId ); + getFastPropertyValue( rGuard, rOldValue, nPropId ); return !CompareProperties( rConvertedValue, rOldValue ); } @@ -350,7 +351,7 @@ namespace toolkit 1); } - return UnoControlModel::convertFastPropertyValue( rConvertedValue, rOldValue, nPropId, rValue ); + return UnoControlModel::convertFastPropertyValue( rGuard, rConvertedValue, rOldValue, nPropId, rValue ); } diff --git a/toolkit/source/controls/grid/gridcontrol.cxx b/toolkit/source/controls/grid/gridcontrol.cxx index 106e704067aa..d6071046afc8 100644 --- a/toolkit/source/controls/grid/gridcontrol.cxx +++ b/toolkit/source/controls/grid/gridcontrol.cxx @@ -130,7 +130,8 @@ UnoGridModel::UnoGridModel( const UnoGridModel& rModel ) } if ( !xDataModel.is() ) xDataModel = lcl_getDefaultDataModel_throw( m_xContext ); - UnoControlModel::setFastPropertyValue_NoBroadcast( BASEPROPERTY_GRID_DATAMODEL, Any( xDataModel ) ); + std::unique_lock aGuard(m_aMutex); + UnoControlModel::setFastPropertyValue_NoBroadcast( aGuard, BASEPROPERTY_GRID_DATAMODEL, Any( xDataModel ) ); // do *not* use setFastPropertyValue here: The UnoControlModel ctor made a simple copy of all property values, // so before this call here, we share our data model with the own of the clone source. setFastPropertyValue, // then, disposes the old data model - which means the data model which in fact belongs to the clone source. @@ -149,7 +150,7 @@ UnoGridModel::UnoGridModel( const UnoGridModel& rModel ) } if ( !xColumnModel.is() ) xColumnModel = lcl_getDefaultColumnModel_throw( m_xContext ); - UnoControlModel::setFastPropertyValue_NoBroadcast( BASEPROPERTY_GRID_COLUMNMODEL, Any( xColumnModel ) ); + UnoControlModel::setFastPropertyValue_NoBroadcast( aGuard, BASEPROPERTY_GRID_COLUMNMODEL, Any( xColumnModel ) ); // same comment as above: do not use our own setPropertyValue here. } osl_atomic_decrement( &m_refCount ); @@ -188,12 +189,12 @@ void SAL_CALL UnoGridModel::dispose( ) } -void SAL_CALL UnoGridModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) +void UnoGridModel::setFastPropertyValue_NoBroadcast( std::unique_lock& rGuard, sal_Int32 nHandle, const Any& rValue ) { Any aOldSubModel; if ( ( nHandle == BASEPROPERTY_GRID_COLUMNMODEL ) || ( nHandle == BASEPROPERTY_GRID_DATAMODEL ) ) { - aOldSubModel = getFastPropertyValue( nHandle ); + getFastPropertyValue( rGuard, aOldSubModel, nHandle ); if ( aOldSubModel == rValue ) { OSL_ENSURE( false, "UnoGridModel::setFastPropertyValue_NoBroadcast: setting the same value, again!" ); @@ -202,7 +203,7 @@ void SAL_CALL UnoGridModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, } } - UnoControlModel::setFastPropertyValue_NoBroadcast( nHandle, rValue ); + UnoControlModel::setFastPropertyValue_NoBroadcast( rGuard, nHandle, rValue ); if ( aOldSubModel.hasValue() ) lcl_dispose_nothrow( aOldSubModel ); diff --git a/toolkit/source/controls/grid/gridcontrol.hxx b/toolkit/source/controls/grid/gridcontrol.hxx index 435ff2fab089..9b7eae0eaa25 100644 --- a/toolkit/source/controls/grid/gridcontrol.hxx +++ b/toolkit/source/controls/grid/gridcontrol.hxx @@ -42,7 +42,7 @@ class UnoGridModel : public UnoControlModel { protected: css::uno::Any ImplGetDefaultValue( sal_uInt16 nPropId ) const override; - ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; + ::cppu::IPropertyArrayHelper& getInfoHelper() override; public: explicit UnoGridModel( const css::uno::Reference< css::uno::XComponentContext >& i_factory ); @@ -60,7 +60,7 @@ public: OUString SAL_CALL getServiceName() override; // OPropertySetHelper - void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const css::uno::Any& rValue ) override; + void setFastPropertyValue_NoBroadcast( std::unique_lock& rGuard, sal_Int32 nHandle, const css::uno::Any& rValue ) override; // XServiceInfo OUString SAL_CALL getImplementationName() override diff --git a/toolkit/source/controls/spinningprogress.cxx b/toolkit/source/controls/spinningprogress.cxx index 7acac58e5565..851d624a3dd2 100644 --- a/toolkit/source/controls/spinningprogress.cxx +++ b/toolkit/source/controls/spinningprogress.cxx @@ -32,11 +32,7 @@ class SpinningProgressControlModel : public SpinningProgressControlModel_Base { public: explicit SpinningProgressControlModel( css::uno::Reference< css::uno::XComponentContext > const & i_factory ); - - SpinningProgressControlModel(SpinningProgressControlModel const &) = default; - SpinningProgressControlModel(SpinningProgressControlModel &&) = default; - SpinningProgressControlModel & operator =(SpinningProgressControlModel const &) = delete; // due to SpinningProgressControlModel_Base - SpinningProgressControlModel & operator =(SpinningProgressControlModel &&) = delete; // due to SpinningProgressControlModel_Base + SpinningProgressControlModel(const SpinningProgressControlModel& rOther) : SpinningProgressControlModel_Base(rOther) {} virtual rtl::Reference Clone() const override; diff --git a/toolkit/source/controls/tabpagecontainer.cxx b/toolkit/source/controls/tabpagecontainer.cxx index 953c6b075cdf..82c24fdb0681 100644 --- a/toolkit/source/controls/tabpagecontainer.cxx +++ b/toolkit/source/controls/tabpagecontainer.cxx @@ -170,13 +170,13 @@ void SAL_CALL UnoControlTabPageContainerModel::replaceByIndex( ::sal_Int32 /*Ind // XIndexAccess ::sal_Int32 SAL_CALL UnoControlTabPageContainerModel::getCount( ) { - ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); return sal_Int32( m_aTabPageVector.size()); } uno::Any SAL_CALL UnoControlTabPageContainerModel::getByIndex( ::sal_Int32 nIndex ) { - ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); if ( nIndex < 0 || o3tl::make_unsigned(nIndex) > m_aTabPageVector.size() ) throw lang::IndexOutOfBoundsException(); return uno::Any(m_aTabPageVector[nIndex]); @@ -190,7 +190,7 @@ uno::Type SAL_CALL UnoControlTabPageContainerModel::getElementType( ) sal_Bool SAL_CALL UnoControlTabPageContainerModel::hasElements( ) { - ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); return !m_aTabPageVector.empty(); } // XContainer diff --git a/toolkit/source/controls/tkspinbutton.cxx b/toolkit/source/controls/tkspinbutton.cxx index 2040f668859b..9b106ed3a5d6 100644 --- a/toolkit/source/controls/tkspinbutton.cxx +++ b/toolkit/source/controls/tkspinbutton.cxx @@ -41,10 +41,11 @@ class UnoSpinButtonModel : public UnoControlModel { protected: css::uno::Any ImplGetDefaultValue( sal_uInt16 nPropId ) const override; - ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; + ::cppu::IPropertyArrayHelper& getInfoHelper() override; public: explicit UnoSpinButtonModel( const css::uno::Reference< css::uno::XComponentContext >& i_factory ); + UnoSpinButtonModel(const UnoSpinButtonModel & rOther) : UnoControlModel(rOther) {} rtl::Reference Clone() const override { return new UnoSpinButtonModel( *this ); } diff --git a/toolkit/source/controls/tree/treecontrol.hxx b/toolkit/source/controls/tree/treecontrol.hxx index af4793fe91ec..357afddb0f20 100644 --- a/toolkit/source/controls/tree/treecontrol.hxx +++ b/toolkit/source/controls/tree/treecontrol.hxx @@ -30,10 +30,14 @@ class UnoTreeModel : public UnoControlModel { protected: css::uno::Any ImplGetDefaultValue(sal_uInt16 nPropId) const override; - ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; + ::cppu::IPropertyArrayHelper& getInfoHelper() override; public: explicit UnoTreeModel(const css::uno::Reference& i_factory); + UnoTreeModel(const UnoTreeModel& rOther) + : UnoControlModel(rOther) + { + } rtl::Reference Clone() const override; diff --git a/toolkit/source/controls/unocontrolmodel.cxx b/toolkit/source/controls/unocontrolmodel.cxx index 5b68774b678e..a881d2781b1e 100644 --- a/toolkit/source/controls/unocontrolmodel.cxx +++ b/toolkit/source/controls/unocontrolmodel.cxx @@ -110,7 +110,6 @@ static void lcl_ImplMergeFontProperty( FontDescriptor& rFD, sal_uInt16 nPropId, UnoControlModel::UnoControlModel( const Reference< XComponentContext >& rxContext ) :UnoControlModel_Base() - ,OPropertySetHelper( m_aBHelper ) ,maDisposeListeners( *this ) ,m_xContext( rxContext ) { @@ -119,8 +118,7 @@ UnoControlModel::UnoControlModel( const Reference< XComponentContext >& rxContex } UnoControlModel::UnoControlModel( const UnoControlModel& rModel ) - : UnoControlModel_Base() - , OPropertySetHelper( m_aBHelper ) + : UnoControlModel_Base(), OPropertySetHelper() , maData( rModel.maData ) , maDisposeListeners( *this ) , m_xContext( rModel.m_xContext ) @@ -416,7 +414,7 @@ css::uno::Any UnoControlModel::queryAggregation( const css::uno::Type & rType ) { Any aRet = UnoControlModel_Base::queryAggregation( rType ); if ( !aRet.hasValue() ) - aRet = ::cppu::OPropertySetHelper::queryInterface( rType ); + aRet = ::comphelper::OPropertySetHelper::queryInterface( rType ); return aRet; } @@ -424,7 +422,7 @@ css::uno::Any UnoControlModel::queryAggregation( const css::uno::Type & rType ) IMPLEMENT_FORWARD_REFCOUNT( UnoControlModel, UnoControlModel_Base ) // css::lang::XTypeProvider -IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoControlModel, UnoControlModel_Base, ::cppu::OPropertySetHelper ) +IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoControlModel, UnoControlModel_Base, ::comphelper::OPropertySetHelper ) uno::Reference< util::XCloneable > UnoControlModel::createClone() @@ -436,28 +434,26 @@ uno::Reference< util::XCloneable > UnoControlModel::createClone() // css::lang::XComponent void UnoControlModel::dispose( ) { - ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); css::lang::EventObject aEvt; aEvt.Source = static_cast(static_cast(this)); - maDisposeListeners.disposeAndClear( aEvt ); - - m_aBHelper.aLC.disposeAndClear( aEvt ); + maDisposeListeners.disposeAndClear( aGuard, aEvt ); // let the property set helper notify our property listeners - OPropertySetHelper::disposing(); + OPropertySetHelper::disposing(aGuard); } void UnoControlModel::addEventListener( const css::uno::Reference< css::lang::XEventListener >& rxListener ) { - ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); maDisposeListeners.addInterface( rxListener ); } void UnoControlModel::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& rxListener ) { - ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); maDisposeListeners.removeInterface( rxListener ); } @@ -466,11 +462,15 @@ void UnoControlModel::removeEventListener( const css::uno::Reference< css::lang: // css::beans::XPropertyState css::beans::PropertyState UnoControlModel::getPropertyState( const OUString& PropertyName ) { - ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); + return getPropertyStateImpl(aGuard, PropertyName); +} +css::beans::PropertyState UnoControlModel::getPropertyStateImpl( std::unique_lock& rGuard, const OUString& PropertyName ) +{ sal_uInt16 nPropId = GetPropertyId( PropertyName ); - css::uno::Any aValue = getPropertyValue( PropertyName ); + css::uno::Any aValue = getPropertyValueImpl( rGuard, PropertyName ); css::uno::Any aDefault = ImplGetDefaultValue( nPropId ); return CompareProperties( aValue, aDefault ) ? css::beans::PropertyState_DEFAULT_VALUE : css::beans::PropertyState_DIRECT_VALUE; @@ -478,14 +478,15 @@ css::beans::PropertyState UnoControlModel::getPropertyState( const OUString& Pro css::uno::Sequence< css::beans::PropertyState > UnoControlModel::getPropertyStates( const css::uno::Sequence< OUString >& PropertyNames ) { - ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); sal_Int32 nNames = PropertyNames.getLength(); css::uno::Sequence< css::beans::PropertyState > aStates( nNames ); std::transform(PropertyNames.begin(), PropertyNames.end(), aStates.getArray(), - [this](const OUString& rName) -> css::beans::PropertyState { return getPropertyState(rName); }); + [this, &aGuard](const OUString& rName) -> css::beans::PropertyState + { return getPropertyStateImpl(aGuard, rName); }); return aStates; } @@ -494,7 +495,7 @@ void UnoControlModel::setPropertyToDefault( const OUString& PropertyName ) { Any aDefaultValue; { - ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); aDefaultValue = ImplGetDefaultValue( GetPropertyId( PropertyName ) ); } setPropertyValue( PropertyName, aDefaultValue ); @@ -502,7 +503,7 @@ void UnoControlModel::setPropertyToDefault( const OUString& PropertyName ) css::uno::Any UnoControlModel::getPropertyDefault( const OUString& rPropertyName ) { - ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); return ImplGetDefaultValue( GetPropertyId( rPropertyName ) ); } @@ -517,7 +518,7 @@ OUString UnoControlModel::getServiceName( ) void UnoControlModel::write( const css::uno::Reference< css::io::XObjectOutputStream >& OutStream ) { - ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); css::uno::Reference< css::io::XMarkableStream > xMark( OutStream, css::uno::UNO_QUERY ); DBG_ASSERT( xMark.is(), "write: no css::io::XMarkableStream!" ); @@ -529,7 +530,7 @@ void UnoControlModel::write( const css::uno::Reference< css::io::XObjectOutputSt for (const auto& rData : maData) { if ( ( ( GetPropertyAttribs( rData.first ) & css::beans::PropertyAttribute::TRANSIENT ) == 0 ) - && ( getPropertyState( GetPropertyName( rData.first ) ) != css::beans::PropertyState_DEFAULT_VALUE ) ) + && ( getPropertyStateImpl( aGuard, GetPropertyName( rData.first ) ) != css::beans::PropertyState_DEFAULT_VALUE ) ) { aProps.insert( rData.first ); } @@ -747,7 +748,7 @@ void UnoControlModel::write( const css::uno::Reference< css::io::XObjectOutputSt void UnoControlModel::read( const css::uno::Reference< css::io::XObjectInputStream >& InStream ) { - ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); css::uno::Reference< css::io::XMarkableStream > xMark( InStream, css::uno::UNO_QUERY ); DBG_ASSERT( xMark.is(), "read: no css::io::XMarkableStream!" ); @@ -990,7 +991,7 @@ void UnoControlModel::read( const css::uno::Reference< css::io::XObjectInputStre try { - setPropertyValues( aProps, aValues ); + setPropertyValuesImpl( aGuard, aProps, aValues ); } catch ( const Exception& ) { @@ -1001,7 +1002,7 @@ void UnoControlModel::read( const css::uno::Reference< css::io::XObjectInputStre { css::uno::Any aValue; aValue <<= *pFD; - setPropertyValue( GetPropertyName( BASEPROPERTY_FONTDESCRIPTOR ), aValue ); + setPropertyValueImpl( aGuard, GetPropertyName( BASEPROPERTY_FONTDESCRIPTOR ), aValue ); } } @@ -1024,10 +1025,8 @@ css::uno::Sequence< OUString > UnoControlModel::getSupportedServiceNames( ) return { "com.sun.star.awt.UnoControlModel" }; } -sal_Bool UnoControlModel::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nPropId, const Any& rValue ) +bool UnoControlModel::convertFastPropertyValue( std::unique_lock& rGuard, Any & rConvertedValue, Any & rOldValue, sal_Int32 nPropId, const Any& rValue ) { - ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); - bool bVoid = rValue.getValueType().getTypeClass() == css::uno::TypeClass_VOID; if ( bVoid ) { @@ -1140,11 +1139,11 @@ sal_Bool UnoControlModel::convertFastPropertyValue( Any & rConvertedValue, Any & } // the current value - getFastPropertyValue( rOldValue, nPropId ); + getFastPropertyValue( rGuard, rOldValue, nPropId ); return !CompareProperties( rConvertedValue, rOldValue ); } -void UnoControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 nPropId, const css::uno::Any& rValue ) +void UnoControlModel::setFastPropertyValue_NoBroadcast( std::unique_lock& /*rGuard*/, sal_Int32 nPropId, const css::uno::Any& rValue ) { // Missing: the fake solo properties of the FontDescriptor @@ -1156,10 +1155,8 @@ void UnoControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 nPropId, const maData[ nPropId ] = rValue; } -void UnoControlModel::getFastPropertyValue( css::uno::Any& rValue, sal_Int32 nPropId ) const +void UnoControlModel::getFastPropertyValue( std::unique_lock& /*rGuard*/, css::uno::Any& rValue, sal_Int32 nPropId ) const { - ::osl::Guard< ::osl::Mutex > aGuard( const_cast(this)->GetMutex() ); - ImplPropertyTable::const_iterator it = maData.find( nPropId ); const css::uno::Any* pProp = it == maData.end() ? nullptr : &(it->second); @@ -1214,25 +1211,23 @@ void UnoControlModel::getFastPropertyValue( css::uno::Any& rValue, sal_Int32 nPr } // css::beans::XPropertySet -void UnoControlModel::setPropertyValue( const OUString& rPropertyName, const css::uno::Any& rValue ) +void UnoControlModel::setPropertyValueImpl( std::unique_lock& rGuard, const OUString& rPropertyName, const css::uno::Any& rValue ) { sal_Int32 nPropId = static_cast(GetPropertyId( rPropertyName )); DBG_ASSERT( nPropId, "Invalid ID in UnoControlModel::setPropertyValue" ); if( !nPropId ) throw css::beans::UnknownPropertyException(rPropertyName); - setFastPropertyValue( nPropId, rValue ); + setFastPropertyValueImpl( rGuard, nPropId, rValue ); } // css::beans::XFastPropertySet -void UnoControlModel::setFastPropertyValue( sal_Int32 nPropId, const css::uno::Any& rValue ) +void UnoControlModel::setFastPropertyValueImpl( std::unique_lock& rGuard, sal_Int32 nPropId, const css::uno::Any& rValue ) { if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) ) { - ::osl::ClearableMutexGuard aGuard( GetMutex() ); - Any aOldSingleValue; - getFastPropertyValue( aOldSingleValue, BASEPROPERTY_FONTDESCRIPTORPART_START ); + getFastPropertyValue( rGuard, aOldSingleValue, BASEPROPERTY_FONTDESCRIPTORPART_START ); css::uno::Any* pProp = &maData[ BASEPROPERTY_FONTDESCRIPTOR ]; FontDescriptor aOldFontDescriptor; @@ -1248,14 +1243,13 @@ void UnoControlModel::setFastPropertyValue( sal_Int32 nPropId, const css::uno::A // also, we need fire a propertyChange event for the single property, since with // the above line, only an event for the FontDescriptor property will be fired Any aNewSingleValue; - getFastPropertyValue( aNewSingleValue, BASEPROPERTY_FONTDESCRIPTORPART_START ); + getFastPropertyValue( rGuard, aNewSingleValue, BASEPROPERTY_FONTDESCRIPTORPART_START ); - aGuard.clear(); - setFastPropertyValues( 1, &nDescriptorId, &aNewValue, 1 ); - fire( &nPropId, &aNewSingleValue, &aOldSingleValue, 1, false ); + setFastPropertyValues( rGuard, 1, &nDescriptorId, &aNewValue, 1 ); + fire( rGuard, &nPropId, &aNewSingleValue, &aOldSingleValue, 1, false ); } else - setFastPropertyValues( 1, &nPropId, &rValue, 1 ); + setFastPropertyValues( rGuard, 1, &nPropId, &rValue, 1 ); } // css::beans::XMultiPropertySet @@ -1267,8 +1261,12 @@ css::uno::Reference< css::beans::XPropertySetInfo > UnoControlModel::getProperty void UnoControlModel::setPropertyValues( const css::uno::Sequence< OUString >& rPropertyNames, const css::uno::Sequence< css::uno::Any >& Values ) { - ::osl::ClearableMutexGuard aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); + setPropertyValuesImpl(aGuard, rPropertyNames, Values); +} +void UnoControlModel::setPropertyValuesImpl( std::unique_lock& rGuard, const css::uno::Sequence< OUString >& rPropertyNames, const css::uno::Sequence< css::uno::Any >& Values ) +{ sal_Int32 nProps = rPropertyNames.getLength(); if (nProps != Values.getLength()) throw css::lang::IllegalArgumentException("lengths do not match", @@ -1310,16 +1308,8 @@ void UnoControlModel::setPropertyValues( const css::uno::Sequence< OUString >& r if ( nValidHandles ) { ImplNormalizePropertySequence( nProps, pHandles, pValues, &nValidHandles ); - aGuard.clear(); - // clear our guard before calling into setFastPropertyValues - this method - // will implicitly call property listeners, and this should not happen with - // our mutex locked - // #i23451# - setFastPropertyValues( nProps, pHandles, pValues, nValidHandles ); + setFastPropertyValues( rGuard, nProps, pHandles, pValues, nValidHandles ); } - else - aGuard.clear(); - // same as a few lines above // Don't merge FD property into array, as it is sorted if (pFD) @@ -1327,7 +1317,7 @@ void UnoControlModel::setPropertyValues( const css::uno::Sequence< OUString >& r css::uno::Any aValue; aValue <<= *pFD; sal_Int32 nHandle = BASEPROPERTY_FONTDESCRIPTOR; - setFastPropertyValues( 1, &nHandle, &aValue, 1 ); + setFastPropertyValues( rGuard, 1, &nHandle, &aValue, 1 ); } } diff --git a/toolkit/source/controls/unocontrols.cxx b/toolkit/source/controls/unocontrols.cxx index 84fe8ce50774..c8a3f8c839a3 100644 --- a/toolkit/source/controls/unocontrols.cxx +++ b/toolkit/source/controls/unocontrols.cxx @@ -589,9 +589,9 @@ uno::Any GraphicControlModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const return UnoControlModel::ImplGetDefaultValue( nPropId ); } -void SAL_CALL GraphicControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const css::uno::Any& rValue ) +void GraphicControlModel::setFastPropertyValue_NoBroadcast( std::unique_lock& rGuard, sal_Int32 nHandle, const css::uno::Any& rValue ) { - UnoControlModel::setFastPropertyValue_NoBroadcast( nHandle, rValue ); + UnoControlModel::setFastPropertyValue_NoBroadcast( rGuard, nHandle, rValue ); // - ImageAlign and ImagePosition need to correspond to each other // - Graphic and ImageURL need to correspond to each other @@ -605,7 +605,7 @@ void SAL_CALL GraphicControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 n mbAdjustingGraphic = true; OUString sImageURL; OSL_VERIFY( rValue >>= sImageURL ); - setDependentFastPropertyValue( BASEPROPERTY_GRAPHIC, uno::Any( ImageHelper::getGraphicFromURL_nothrow( sImageURL ) ) ); + setDependentFastPropertyValue( rGuard, BASEPROPERTY_GRAPHIC, uno::Any( ImageHelper::getGraphicFromURL_nothrow( sImageURL ) ) ); mbAdjustingGraphic = false; } break; @@ -614,7 +614,7 @@ void SAL_CALL GraphicControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 n if ( !mbAdjustingGraphic && ImplHasProperty( BASEPROPERTY_IMAGEURL ) ) { mbAdjustingGraphic = true; - setDependentFastPropertyValue( BASEPROPERTY_IMAGEURL, uno::Any( OUString() ) ); + setDependentFastPropertyValue( rGuard, BASEPROPERTY_IMAGEURL, uno::Any( OUString() ) ); mbAdjustingGraphic = false; } break; @@ -625,7 +625,7 @@ void SAL_CALL GraphicControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 n mbAdjustingImagePosition = true; sal_Int16 nUNOValue = 0; OSL_VERIFY( rValue >>= nUNOValue ); - setDependentFastPropertyValue( BASEPROPERTY_IMAGEPOSITION, uno::Any( getExtendedImagePosition( nUNOValue ) ) ); + setDependentFastPropertyValue( rGuard, BASEPROPERTY_IMAGEPOSITION, uno::Any( getExtendedImagePosition( nUNOValue ) ) ); mbAdjustingImagePosition = false; } break; @@ -635,7 +635,7 @@ void SAL_CALL GraphicControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 n mbAdjustingImagePosition = true; sal_Int16 nUNOValue = 0; OSL_VERIFY( rValue >>= nUNOValue ); - setDependentFastPropertyValue( BASEPROPERTY_IMAGEALIGN, uno::Any( getCompatibleImageAlign( translateImagePosition( nUNOValue ) ) ) ); + setDependentFastPropertyValue( rGuard, BASEPROPERTY_IMAGEALIGN, uno::Any( getCompatibleImageAlign( translateImagePosition( nUNOValue ) ) ) ); mbAdjustingImagePosition = false; } break; @@ -658,7 +658,8 @@ UnoControlButtonModel::UnoControlButtonModel( const Reference< XComponentContext osl_atomic_increment( &m_refCount ); { - setFastPropertyValue_NoBroadcast( BASEPROPERTY_IMAGEPOSITION, ImplGetDefaultValue( BASEPROPERTY_IMAGEPOSITION ) ); + std::unique_lock aGuard(m_aMutex); + setFastPropertyValue_NoBroadcast( aGuard, BASEPROPERTY_IMAGEPOSITION, ImplGetDefaultValue( BASEPROPERTY_IMAGEPOSITION ) ); // this ensures that our ImagePosition is consistent with our ImageAlign property (since both // defaults are not per se consistent), since both are coupled in setFastPropertyValue_NoBroadcast } @@ -941,9 +942,9 @@ uno::Reference< beans::XPropertySetInfo > UnoControlImageControlModel::getProper return xInfo; } -void SAL_CALL UnoControlImageControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const css::uno::Any& _rValue ) +void UnoControlImageControlModel::setFastPropertyValue_NoBroadcast( std::unique_lock& rGuard, sal_Int32 _nHandle, const css::uno::Any& _rValue ) { - GraphicControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue ); + GraphicControlModel::setFastPropertyValue_NoBroadcast( rGuard, _nHandle, _rValue ); // ScaleImage is an older (and less powerful) version of ScaleMode, but keep both in sync as far as possible try @@ -956,7 +957,7 @@ void SAL_CALL UnoControlImageControlModel::setFastPropertyValue_NoBroadcast( sal mbAdjustingImageScaleMode = true; sal_Int16 nScaleMode( awt::ImageScaleMode::ANISOTROPIC ); OSL_VERIFY( _rValue >>= nScaleMode ); - setDependentFastPropertyValue( BASEPROPERTY_SCALEIMAGE, uno::Any( nScaleMode != awt::ImageScaleMode::NONE ) ); + setDependentFastPropertyValue( rGuard, BASEPROPERTY_SCALEIMAGE, uno::Any( nScaleMode != awt::ImageScaleMode::NONE ) ); mbAdjustingImageScaleMode = false; } break; @@ -966,7 +967,7 @@ void SAL_CALL UnoControlImageControlModel::setFastPropertyValue_NoBroadcast( sal mbAdjustingImageScaleMode = true; bool bScale = true; OSL_VERIFY( _rValue >>= bScale ); - setDependentFastPropertyValue( BASEPROPERTY_IMAGE_SCALE_MODE, uno::Any( bScale ? awt::ImageScaleMode::ANISOTROPIC : awt::ImageScaleMode::NONE ) ); + setDependentFastPropertyValue( rGuard, BASEPROPERTY_IMAGE_SCALE_MODE, uno::Any( bScale ? awt::ImageScaleMode::ANISOTROPIC : awt::ImageScaleMode::NONE ) ); mbAdjustingImageScaleMode = false; } break; @@ -2053,7 +2054,6 @@ private: UnoControlListBoxModel::UnoControlListBoxModel( const Reference< XComponentContext >& rxContext, ConstructorMode const i_mode ) :UnoControlListBoxModel_Base( rxContext ) ,m_xData( new UnoControlListBoxModel_Data( *this ) ) - ,m_aItemListListeners( GetMutex() ) { if ( i_mode == ConstructDefault ) { @@ -2064,7 +2064,6 @@ UnoControlListBoxModel::UnoControlListBoxModel( const Reference< XComponentConte UnoControlListBoxModel::UnoControlListBoxModel( const UnoControlListBoxModel& i_rSource ) :UnoControlListBoxModel_Base( i_rSource ) ,m_xData( new UnoControlListBoxModel_Data( *this ) ) - ,m_aItemListListeners( GetMutex() ) { m_xData->copyItems( *i_rSource.m_xData ); } @@ -2126,16 +2125,16 @@ namespace } -void SAL_CALL UnoControlListBoxModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const uno::Any& rValue ) +void UnoControlListBoxModel::setFastPropertyValue_NoBroadcast( std::unique_lock& rGuard, sal_Int32 nHandle, const uno::Any& rValue ) { - UnoControlModel::setFastPropertyValue_NoBroadcast( nHandle, rValue ); + UnoControlModel::setFastPropertyValue_NoBroadcast( rGuard, nHandle, rValue ); if ( nHandle != BASEPROPERTY_STRINGITEMLIST ) return; // reset selection uno::Sequence aSeq; - setDependentFastPropertyValue( BASEPROPERTY_SELECTEDITEMS, uno::Any(aSeq) ); + setDependentFastPropertyValue( rGuard, BASEPROPERTY_SELECTEDITEMS, uno::Any(aSeq) ); if ( m_xData->m_bSettingLegacyProperty ) return; @@ -2143,7 +2142,7 @@ void SAL_CALL UnoControlListBoxModel::setFastPropertyValue_NoBroadcast( sal_Int3 // synchronize the legacy StringItemList property with our list items Sequence< OUString > aStringItemList; Any aPropValue; - getFastPropertyValue( aPropValue, BASEPROPERTY_STRINGITEMLIST ); + getFastPropertyValue( rGuard, aPropValue, BASEPROPERTY_STRINGITEMLIST ); OSL_VERIFY( aPropValue >>= aStringItemList ); ::std::vector< ListItem > aItems( aStringItemList.getLength() ); @@ -2160,7 +2159,7 @@ void SAL_CALL UnoControlListBoxModel::setFastPropertyValue_NoBroadcast( sal_Int3 // items lang::EventObject aEvent; aEvent.Source = *this; - m_aItemListListeners.notifyEach( &XItemListListener::itemListChanged, aEvent ); + m_aItemListListeners.notifyEach( rGuard, &XItemListListener::itemListChanged, aEvent ); // TODO: OPropertySetHelper calls into this method with the mutex locked ... // which is wrong for the above notifications ... } @@ -2181,51 +2180,51 @@ void UnoControlListBoxModel::ImplNormalizePropertySequence( const sal_Int32 _nCo ::sal_Int32 SAL_CALL UnoControlListBoxModel::getItemCount() { - ::osl::MutexGuard aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); return m_xData->getItemCount(); } void SAL_CALL UnoControlListBoxModel::insertItem( ::sal_Int32 i_nPosition, const OUString& i_rItemText, const OUString& i_rItemImageURL ) { - ::osl::ClearableMutexGuard aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); // SYNCHRONIZED -----> ListItem& rItem( m_xData->insertItem( i_nPosition ) ); rItem.ItemText = i_rItemText; rItem.ItemImageURL = i_rItemImageURL; - impl_handleInsert( i_nPosition, i_rItemText, i_rItemImageURL, aGuard ); + impl_handleInsert( aGuard, i_nPosition, i_rItemText, i_rItemImageURL ); // <----- SYNCHRONIZED } void SAL_CALL UnoControlListBoxModel::insertItemText( ::sal_Int32 i_nPosition, const OUString& i_rItemText ) { - ::osl::ClearableMutexGuard aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); // SYNCHRONIZED -----> ListItem& rItem( m_xData->insertItem( i_nPosition ) ); rItem.ItemText = i_rItemText; - impl_handleInsert( i_nPosition, i_rItemText, ::std::optional< OUString >(), aGuard ); + impl_handleInsert( aGuard, i_nPosition, i_rItemText, ::std::optional< OUString >() ); // <----- SYNCHRONIZED } void SAL_CALL UnoControlListBoxModel::insertItemImage( ::sal_Int32 i_nPosition, const OUString& i_rItemImageURL ) { - ::osl::ClearableMutexGuard aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); // SYNCHRONIZED -----> ListItem& rItem( m_xData->insertItem( i_nPosition ) ); rItem.ItemImageURL = i_rItemImageURL; - impl_handleInsert( i_nPosition, ::std::optional< OUString >(), i_rItemImageURL, aGuard ); + impl_handleInsert( aGuard, i_nPosition, ::std::optional< OUString >(), i_rItemImageURL ); // <----- SYNCHRONIZED } void SAL_CALL UnoControlListBoxModel::removeItem( ::sal_Int32 i_nPosition ) { - ::osl::ClearableMutexGuard aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); // SYNCHRONIZED -----> m_xData->removeItem( i_nPosition ); @@ -2236,7 +2235,7 @@ void SAL_CALL UnoControlListBoxModel::removeItem( ::sal_Int32 i_nPosition ) void SAL_CALL UnoControlListBoxModel::removeAllItems( ) { - ::osl::ClearableMutexGuard aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); // SYNCHRONIZED -----> m_xData->removeAllItems(); @@ -2247,7 +2246,7 @@ void SAL_CALL UnoControlListBoxModel::removeAllItems( ) void SAL_CALL UnoControlListBoxModel::setItemText( ::sal_Int32 i_nPosition, const OUString& i_rItemText ) { - ::osl::ClearableMutexGuard aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); // SYNCHRONIZED -----> ListItem& rItem( m_xData->getItem( i_nPosition ) ); rItem.ItemText = i_rItemText; @@ -2259,7 +2258,7 @@ void SAL_CALL UnoControlListBoxModel::setItemText( ::sal_Int32 i_nPosition, cons void SAL_CALL UnoControlListBoxModel::setItemImage( ::sal_Int32 i_nPosition, const OUString& i_rItemImageURL ) { - ::osl::ClearableMutexGuard aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); // SYNCHRONIZED -----> ListItem& rItem( m_xData->getItem( i_nPosition ) ); rItem.ItemImageURL = i_rItemImageURL; @@ -2271,7 +2270,7 @@ void SAL_CALL UnoControlListBoxModel::setItemImage( ::sal_Int32 i_nPosition, con void SAL_CALL UnoControlListBoxModel::setItemTextAndImage( ::sal_Int32 i_nPosition, const OUString& i_rItemText, const OUString& i_rItemImageURL ) { - ::osl::ClearableMutexGuard aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); // SYNCHRONIZED -----> ListItem& rItem( m_xData->getItem( i_nPosition ) ); rItem.ItemText = i_rItemText; @@ -2284,7 +2283,7 @@ void SAL_CALL UnoControlListBoxModel::setItemTextAndImage( ::sal_Int32 i_nPositi void SAL_CALL UnoControlListBoxModel::setItemData( ::sal_Int32 i_nPosition, const Any& i_rDataValue ) { - osl::MutexGuard aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); ListItem& rItem( m_xData->getItem( i_nPosition ) ); rItem.ItemData = i_rDataValue; } @@ -2292,7 +2291,7 @@ void SAL_CALL UnoControlListBoxModel::setItemData( ::sal_Int32 i_nPosition, cons OUString SAL_CALL UnoControlListBoxModel::getItemText( ::sal_Int32 i_nPosition ) { - ::osl::MutexGuard aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); const ListItem& rItem( m_xData->getItem( i_nPosition ) ); return rItem.ItemText; } @@ -2300,7 +2299,7 @@ OUString SAL_CALL UnoControlListBoxModel::getItemText( ::sal_Int32 i_nPosition ) OUString SAL_CALL UnoControlListBoxModel::getItemImage( ::sal_Int32 i_nPosition ) { - ::osl::MutexGuard aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); const ListItem& rItem( m_xData->getItem( i_nPosition ) ); return rItem.ItemImageURL; } @@ -2308,7 +2307,7 @@ OUString SAL_CALL UnoControlListBoxModel::getItemImage( ::sal_Int32 i_nPosition beans::Pair< OUString, OUString > SAL_CALL UnoControlListBoxModel::getItemTextAndImage( ::sal_Int32 i_nPosition ) { - ::osl::MutexGuard aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); const ListItem& rItem( m_xData->getItem( i_nPosition ) ); return beans::Pair< OUString, OUString >( rItem.ItemText, rItem.ItemImageURL ); } @@ -2316,7 +2315,7 @@ beans::Pair< OUString, OUString > SAL_CALL UnoControlListBoxModel::getItemTextAn Any SAL_CALL UnoControlListBoxModel::getItemData( ::sal_Int32 i_nPosition ) { - osl::MutexGuard aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); const ListItem& rItem( m_xData->getItem( i_nPosition ) ); return rItem.ItemData; } @@ -2324,43 +2323,45 @@ Any SAL_CALL UnoControlListBoxModel::getItemData( ::sal_Int32 i_nPosition ) Sequence< beans::Pair< OUString, OUString > > SAL_CALL UnoControlListBoxModel::getAllItems( ) { - ::osl::MutexGuard aGuard( GetMutex() ); + std::unique_lock aGuard( m_aMutex ); return m_xData->getAllItems(); } void SAL_CALL UnoControlListBoxModel::addItemListListener( const uno::Reference< awt::XItemListListener >& i_Listener ) { + std::unique_lock aGuard( m_aMutex ); if ( i_Listener.is() ) - m_aItemListListeners.addInterface( i_Listener ); + m_aItemListListeners.addInterface( aGuard, i_Listener ); } void SAL_CALL UnoControlListBoxModel::removeItemListListener( const uno::Reference< awt::XItemListListener >& i_Listener ) { + std::unique_lock aGuard( m_aMutex ); if ( i_Listener.is() ) - m_aItemListListeners.removeInterface( i_Listener ); + m_aItemListListeners.removeInterface( aGuard, i_Listener ); } -void UnoControlListBoxModel::impl_getStringItemList( ::std::vector< OUString >& o_rStringItems ) const +void UnoControlListBoxModel::impl_getStringItemList( std::unique_lock& rGuard, ::std::vector< OUString >& o_rStringItems ) const { Sequence< OUString > aStringItemList; Any aPropValue; - getFastPropertyValue( aPropValue, BASEPROPERTY_STRINGITEMLIST ); + getFastPropertyValue( rGuard, aPropValue, BASEPROPERTY_STRINGITEMLIST ); OSL_VERIFY( aPropValue >>= aStringItemList ); comphelper::sequenceToContainer(o_rStringItems, aStringItemList); } -void UnoControlListBoxModel::impl_setStringItemList_nolck( const ::std::vector< OUString >& i_rStringItems ) +void UnoControlListBoxModel::impl_setStringItemList( std::unique_lock& rGuard, const ::std::vector< OUString >& i_rStringItems ) { Sequence< OUString > aStringItems( comphelper::containerToSequence(i_rStringItems) ); m_xData->m_bSettingLegacyProperty = true; try { - setFastPropertyValue( BASEPROPERTY_STRINGITEMLIST, uno::Any( aStringItems ) ); + setFastPropertyValueImpl( rGuard, BASEPROPERTY_STRINGITEMLIST, uno::Any( aStringItems ) ); } catch( const Exception& ) { @@ -2371,13 +2372,15 @@ void UnoControlListBoxModel::impl_setStringItemList_nolck( const ::std::vector< } -void UnoControlListBoxModel::impl_handleInsert( const sal_Int32 i_nItemPosition, const ::std::optional< OUString >& i_rItemText, - const ::std::optional< OUString >& i_rItemImageURL, ::osl::ClearableMutexGuard& i_rClearBeforeNotify ) +void UnoControlListBoxModel::impl_handleInsert( std::unique_lock& rGuard, + const sal_Int32 i_nItemPosition, + const ::std::optional< OUString >& i_rItemText, + const ::std::optional< OUString >& i_rItemImageURL ) { // SYNCHRONIZED -----> // sync with legacy StringItemList property ::std::vector< OUString > aStringItems; - impl_getStringItemList( aStringItems ); + impl_getStringItemList( rGuard, aStringItems ); OSL_ENSURE( o3tl::make_unsigned( i_nItemPosition ) <= aStringItems.size(), "UnoControlListBoxModel::impl_handleInsert" ); if ( o3tl::make_unsigned( i_nItemPosition ) <= aStringItems.size() ) { @@ -2385,22 +2388,22 @@ void UnoControlListBoxModel::impl_handleInsert( const sal_Int32 i_nItemPosition, aStringItems.insert( aStringItems.begin() + i_nItemPosition, sItemText ); } - i_rClearBeforeNotify.clear(); - // <----- SYNCHRONIZED - impl_setStringItemList_nolck( aStringItems ); + impl_setStringItemList( rGuard, aStringItems ); // notify ItemListListeners - impl_notifyItemListEvent_nolck( i_nItemPosition, i_rItemText, i_rItemImageURL, &XItemListListener::listItemInserted ); + impl_notifyItemListEvent( rGuard, i_nItemPosition, i_rItemText, i_rItemImageURL, &XItemListListener::listItemInserted ); } -void UnoControlListBoxModel::impl_handleRemove( const sal_Int32 i_nItemPosition, ::osl::ClearableMutexGuard& i_rClearBeforeNotify ) +void UnoControlListBoxModel::impl_handleRemove( + const sal_Int32 i_nItemPosition, + std::unique_lock& i_rClearBeforeNotify ) { // SYNCHRONIZED -----> const bool bAllItems = ( i_nItemPosition < 0 ); // sync with legacy StringItemList property ::std::vector< OUString > aStringItems; - impl_getStringItemList( aStringItems ); + impl_getStringItemList( i_rClearBeforeNotify, aStringItems ); if ( !bAllItems ) { OSL_ENSURE( o3tl::make_unsigned( i_nItemPosition ) < aStringItems.size(), "UnoControlListBoxModel::impl_handleRemove" ); @@ -2414,55 +2417,50 @@ void UnoControlListBoxModel::impl_handleRemove( const sal_Int32 i_nItemPosition, aStringItems.resize(0); } - i_rClearBeforeNotify.clear(); - // <----- SYNCHRONIZED - impl_setStringItemList_nolck( aStringItems ); + impl_setStringItemList( i_rClearBeforeNotify, aStringItems ); // notify ItemListListeners if ( bAllItems ) { EventObject aEvent( *this ); - m_aItemListListeners.notifyEach( &XItemListListener::allItemsRemoved, aEvent ); + m_aItemListListeners.notifyEach( i_rClearBeforeNotify, &XItemListListener::allItemsRemoved, aEvent ); } else { - impl_notifyItemListEvent_nolck( i_nItemPosition, ::std::optional< OUString >(), ::std::optional< OUString >(), + impl_notifyItemListEvent( i_rClearBeforeNotify, i_nItemPosition, ::std::optional< OUString >(), ::std::optional< OUString >(), &XItemListListener::listItemRemoved ); } } -void UnoControlListBoxModel::impl_handleModify( const sal_Int32 i_nItemPosition, const ::std::optional< OUString >& i_rItemText, - const ::std::optional< OUString >& i_rItemImageURL, ::osl::ClearableMutexGuard& i_rClearBeforeNotify ) +void UnoControlListBoxModel::impl_handleModify( + const sal_Int32 i_nItemPosition, const ::std::optional< OUString >& i_rItemText, + const ::std::optional< OUString >& i_rItemImageURL, + std::unique_lock& i_rClearBeforeNotify ) { // SYNCHRONIZED -----> if ( !!i_rItemText ) { // sync with legacy StringItemList property ::std::vector< OUString > aStringItems; - impl_getStringItemList( aStringItems ); + impl_getStringItemList( i_rClearBeforeNotify, aStringItems ); OSL_ENSURE( o3tl::make_unsigned( i_nItemPosition ) < aStringItems.size(), "UnoControlListBoxModel::impl_handleModify" ); if ( o3tl::make_unsigned( i_nItemPosition ) < aStringItems.size() ) { aStringItems[ i_nItemPosition] = *i_rItemText; } - i_rClearBeforeNotify.clear(); - // <----- SYNCHRONIZED - impl_setStringItemList_nolck( aStringItems ); - } - else - { - i_rClearBeforeNotify.clear(); - // <----- SYNCHRONIZED + impl_setStringItemList( i_rClearBeforeNotify, aStringItems ); } // notify ItemListListeners - impl_notifyItemListEvent_nolck( i_nItemPosition, i_rItemText, i_rItemImageURL, &XItemListListener::listItemModified ); + impl_notifyItemListEvent( i_rClearBeforeNotify, i_nItemPosition, i_rItemText, i_rItemImageURL, &XItemListListener::listItemModified ); } -void UnoControlListBoxModel::impl_notifyItemListEvent_nolck( const sal_Int32 i_nItemPosition, const ::std::optional< OUString >& i_rItemText, +void UnoControlListBoxModel::impl_notifyItemListEvent( + std::unique_lock& rGuard, + const sal_Int32 i_nItemPosition, const ::std::optional< OUString >& i_rItemText, const ::std::optional< OUString >& i_rItemImageURL, void ( SAL_CALL XItemListListener::*NotificationMethod )( const ItemListEvent& ) ) { @@ -2480,7 +2478,7 @@ void UnoControlListBoxModel::impl_notifyItemListEvent_nolck( const sal_Int32 i_n aEvent.ItemImageURL.Value = *i_rItemImageURL; } - m_aItemListListeners.notifyEach( NotificationMethod, aEvent ); + m_aItemListListeners.notifyEach( rGuard, NotificationMethod, aEvent ); } extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * @@ -2940,9 +2938,9 @@ OUString UnoControlComboBoxModel::getServiceName() return "stardiv.vcl.controlmodel.ComboBox"; } -void SAL_CALL UnoControlComboBoxModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const uno::Any& rValue ) +void UnoControlComboBoxModel::setFastPropertyValue_NoBroadcast( std::unique_lock& rGuard, sal_Int32 nHandle, const uno::Any& rValue ) { - UnoControlModel::setFastPropertyValue_NoBroadcast( nHandle, rValue ); + UnoControlModel::setFastPropertyValue_NoBroadcast( rGuard, nHandle, rValue ); if (nHandle != BASEPROPERTY_STRINGITEMLIST || m_xData->m_bSettingLegacyProperty) return; @@ -2950,7 +2948,7 @@ void SAL_CALL UnoControlComboBoxModel::setFastPropertyValue_NoBroadcast( sal_Int // synchronize the legacy StringItemList property with our list items Sequence< OUString > aStringItemList; Any aPropValue; - getFastPropertyValue( aPropValue, BASEPROPERTY_STRINGITEMLIST ); + getFastPropertyValue( rGuard, aPropValue, BASEPROPERTY_STRINGITEMLIST ); OSL_VERIFY( aPropValue >>= aStringItemList ); ::std::vector< ListItem > aItems( aStringItemList.getLength() ); @@ -2967,9 +2965,7 @@ void SAL_CALL UnoControlComboBoxModel::setFastPropertyValue_NoBroadcast( sal_Int // items lang::EventObject aEvent; aEvent.Source = *this; - m_aItemListListeners.notifyEach( &XItemListListener::itemListChanged, aEvent ); - // TODO: OPropertySetHelper calls into this method with the mutex locked ... - // which is wrong for the above notifications ... + m_aItemListListeners.notifyEach( rGuard, &XItemListListener::itemListChanged, aEvent ); } uno::Any UnoControlComboBoxModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const -- cgit