include/svx/shapepropertynotifier.hxx        |   14 ++++-----
 include/svx/svdobj.hxx                       |   14 ++-------
 include/svx/unoshape.hxx                     |    5 ++-
 svx/source/svdraw/svdobj.cxx                 |   16 ++++------
 svx/source/unodraw/shapepropertynotifier.cxx |   25 ++++++++--------
 svx/source/unodraw/unoshape.cxx              |   40 +++++++++++++++------------
 sw/source/core/unocore/unodraw.cxx           |    2 -
 7 files changed, 56 insertions(+), 60 deletions(-)

New commits:
commit 95f69903640f8b6d3c0c5798b74339d0ae62bd05
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Feb 14 19:05:18 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Feb 15 07:25:55 2023 +0000

    osl::Mutex->std::mutex in SvxShape
    
    Change-Id: I4b2d13dcd87f49cb73e7239102498629239005d0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147036
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/include/svx/shapepropertynotifier.hxx 
b/include/svx/shapepropertynotifier.hxx
index bcc6c357f05a..c34f536408f2 100644
--- a/include/svx/shapepropertynotifier.hxx
+++ b/include/svx/shapepropertynotifier.hxx
@@ -21,7 +21,7 @@
 #define INCLUDED_SVX_SHAPEPROPERTYNOTIFIER_HXX
 
 #include <svx/svxdllapi.h>
-#include <comphelper/multiinterfacecontainer3.hxx>
+#include <comphelper/multiinterfacecontainer4.hxx>
 #include <rtl/ustring.hxx>
 #include <o3tl/enumarray.hxx>
 
@@ -102,12 +102,12 @@ namespace svx
                 the owner instance of the notifier. Will be used as 
css.lang.EventObject.Source when
                 notifying events.
         */
-        PropertyChangeNotifier( ::cppu::OWeakObject& _rOwner, ::osl::Mutex& 
_rMutex );
+        PropertyChangeNotifier( ::cppu::OWeakObject& _rOwner );
         ~PropertyChangeNotifier();
 
         // listener maintenance
-        void addPropertyChangeListener( const OUString& _rPropertyName, const 
css::uno::Reference< css::beans::XPropertyChangeListener >& _rxListener );
-        void removePropertyChangeListener( const OUString& _rPropertyName, 
const css::uno::Reference< css::beans::XPropertyChangeListener >& _rxListener );
+        void addPropertyChangeListener( std::unique_lock<std::mutex>& rGuard, 
const OUString& _rPropertyName, const css::uno::Reference< 
css::beans::XPropertyChangeListener >& _rxListener );
+        void removePropertyChangeListener( std::unique_lock<std::mutex>& 
rGuard, const OUString& _rPropertyName, const css::uno::Reference< 
css::beans::XPropertyChangeListener >& _rxListener );
 
         /** registers an PropertyValueProvider
         */
@@ -118,11 +118,11 @@ namespace svx
             If no property value provider for the given property ID is 
registered, this is worth an assertion in a
             non-product build, and otherwise ignored.
         */
-        void    notifyPropertyChange( const ShapePropertyProviderId _eProperty 
) const;
+        void    notifyPropertyChange( std::unique_lock<std::mutex>& rGuard, 
const ShapePropertyProviderId _eProperty ) const;
 
         /** is called to dispose the instance
         */
-        void    disposing();
+        void    disposing(std::unique_lock<std::mutex>& rGuard);
 
     private:
         PropertyChangeNotifier(const PropertyChangeNotifier&) = delete;
@@ -130,7 +130,7 @@ namespace svx
 
         ::cppu::OWeakObject&            m_rContext;
         o3tl::enumarray<ShapePropertyProviderId, 
std::unique_ptr<PropertyValueProvider>>  m_aProviders;
-        
comphelper::OMultiTypeInterfaceContainerHelperVar3<css::beans::XPropertyChangeListener,
 OUString> m_aPropertyChangeListeners;
+        comphelper::OMultiTypeInterfaceContainerHelperVar4<OUString, 
css::beans::XPropertyChangeListener> m_aPropertyChangeListeners;
     };
 
 
diff --git a/include/svx/svdobj.hxx b/include/svx/svdobj.hxx
index 6b779775bc3d..08ef71a168a8 100644
--- a/include/svx/svdobj.hxx
+++ b/include/svx/svdobj.hxx
@@ -79,7 +79,7 @@ enum class PointerStyle;
 class Graphic;
 class SvxShape;
 namespace svx { enum class ShapePropertyProviderId; }
-
+namespace svx { class PropertyValueProvider; }
 namespace basegfx
 {
     class B2DPoint;
@@ -91,7 +91,6 @@ namespace sdr { class ObjectUser; }
 namespace sdr::properties { class BaseProperties; }
 namespace sdr::contact { class ViewContact; }
 
-namespace svx { class PropertyChangeNotifier; }
 namespace com::sun::star::drawing { class XShape; }
 namespace svx::diagram { class IDiagramHelper; }
 
@@ -782,15 +781,6 @@ public:
 
     static SdrObject* getSdrObjectFromXShape( const css::uno::Reference< 
css::uno::XInterface >& xInt );
 
-    // retrieves the instance responsible for notifying changes in the 
properties of the shape associated with
-    // the SdrObject
-    //
-    // @precond
-    //     There already exists an SvxShape instance associated with the 
SdrObject
-    // @throws css::uno::RuntimeException
-    //     if there does nt yet exists an SvxShape instance associated with 
the SdrObject.
-    svx::PropertyChangeNotifier& getShapePropertyChangeNotifier();
-
     // notifies a change in the given property, to all applicable listeners 
registered at the associated SvxShape
     //
     // This method is equivalent to calling 
getShapePropertyChangeNotifier().notifyPropertyChange( _eProperty ),
@@ -798,6 +788,8 @@ public:
     // case the method will silently return without doing anything.
     void notifyShapePropertyChange( const svx::ShapePropertyProviderId 
_eProperty ) const;
 
+    void registerProvider( const svx::ShapePropertyProviderId _eProperty, 
std::unique_ptr<svx::PropertyValueProvider> propProvider );
+
     // transformation interface for StarOfficeAPI. This implements support for
     // homogen 3x3 matrices containing the transformation of the SdrObject. At 
the
     // moment it contains a shearX, rotation and translation, but for setting 
all linear
diff --git a/include/svx/unoshape.hxx b/include/svx/unoshape.hxx
index 9828f08fcb26..e2a5d47e22be 100644
--- a/include/svx/unoshape.hxx
+++ b/include/svx/unoshape.hxx
@@ -97,7 +97,6 @@ typedef ::cppu::WeakAggImplHelper12<
     css::beans::XMultiPropertyStates> SvxShape_UnoImplHelper;
 
 class SVXCORE_DLLPUBLIC SvxShape :
-                 public cppu::BaseMutex,
                  public SvxShape_UnoImplHelper,
                  public SfxListener
 {
@@ -177,7 +176,8 @@ public:
     /// @throws css::uno::RuntimeException
     css::uno::Any GetBitmap( bool bMetaFile = false ) const;
 
-    svx::PropertyChangeNotifier& getShapePropertyChangeNotifier();
+    void notifyPropertyChange(svx::ShapePropertyProviderId eProp);
+    void registerProvider(svx::ShapePropertyProviderId eProp, 
std::unique_ptr<svx::PropertyValueProvider> provider);
 
     void setShapeKind( SdrObjKind nKind );
     SdrObjKind getShapeKind() const;
@@ -312,6 +312,7 @@ private:
     /// CTOR-Impl
     SVX_DLLPRIVATE void impl_construct();
 
+    std::mutex m_aMutex;
     css::awt::Size maSize;
     css::awt::Point maPosition;
     OUString maShapeType;
diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx
index f9e061d59e17..e733c2d83871 100644
--- a/svx/source/svdraw/svdobj.cxx
+++ b/svx/source/svdraw/svdobj.cxx
@@ -2960,25 +2960,23 @@ css::uno::Reference< css::drawing::XShape > 
SdrObject::getUnoShape()
     return xShape;
 }
 
-svx::PropertyChangeNotifier& SdrObject::getShapePropertyChangeNotifier()
+void SdrObject::notifyShapePropertyChange( const svx::ShapePropertyProviderId 
_eProperty ) const
 {
     DBG_TESTSOLARMUTEX();
 
-    SvxShape* pSvxShape = getSvxShape();
-    ENSURE_OR_THROW( pSvxShape, "no SvxShape, yet!" );
-    return pSvxShape->getShapePropertyChangeNotifier();
+    SvxShape* pSvxShape = const_cast< SdrObject* >( this )->getSvxShape();
+    if ( pSvxShape )
+        return pSvxShape->notifyPropertyChange( _eProperty );
 }
 
-void SdrObject::notifyShapePropertyChange( const svx::ShapePropertyProviderId 
_eProperty ) const
+void SdrObject::registerProvider( const svx::ShapePropertyProviderId 
_eProperty, std::unique_ptr<svx::PropertyValueProvider> provider )
 {
     DBG_TESTSOLARMUTEX();
 
-    SvxShape* pSvxShape = const_cast< SdrObject* >( this )->getSvxShape();
-    if ( pSvxShape )
-        return 
pSvxShape->getShapePropertyChangeNotifier().notifyPropertyChange( _eProperty );
+    SvxShape* pSvxShape = getSvxShape();
+    return pSvxShape->registerProvider( _eProperty, std::move(provider) );
 }
 
-
 // transformation interface for StarOfficeAPI. This implements support for
 // homogeneous 3x3 matrices containing the transformation of the SdrObject. At 
the
 // moment it contains a shearX, rotation and translation, but for setting all 
linear
diff --git a/svx/source/unodraw/shapepropertynotifier.cxx 
b/svx/source/unodraw/shapepropertynotifier.cxx
index 1ffb6cf6f678..a1b1ad07a626 100644
--- a/svx/source/unodraw/shapepropertynotifier.cxx
+++ b/svx/source/unodraw/shapepropertynotifier.cxx
@@ -63,9 +63,8 @@ namespace svx
         _out_rValue = xContextProps->getPropertyValue( getPropertyName() );
     }
 
-    PropertyChangeNotifier::PropertyChangeNotifier( ::cppu::OWeakObject& 
_rOwner, ::osl::Mutex& _rMutex )
+    PropertyChangeNotifier::PropertyChangeNotifier( ::cppu::OWeakObject& 
_rOwner )
         :m_rContext( _rOwner )
-        ,m_aPropertyChangeListeners( _rMutex )
     {
     }
 
@@ -83,7 +82,7 @@ namespace svx
         m_aProviders[ _eProperty ] = std::move(_rProvider);
     }
 
-    void PropertyChangeNotifier::notifyPropertyChange( const 
ShapePropertyProviderId _eProperty ) const
+    void PropertyChangeNotifier::notifyPropertyChange( 
std::unique_lock<std::mutex>& rGuard, const ShapePropertyProviderId _eProperty 
) const
     {
         auto & provPos = m_aProviders[ _eProperty ];
         OSL_ENSURE( provPos, "PropertyChangeNotifier::notifyPropertyChange: no 
factory!" );
@@ -92,8 +91,8 @@ namespace svx
 
         const OUString & sPropertyName( provPos->getPropertyName() );
 
-        ::comphelper::OInterfaceContainerHelper3<XPropertyChangeListener>* 
pPropListeners = m_aPropertyChangeListeners.getContainer( sPropertyName );
-        ::comphelper::OInterfaceContainerHelper3<XPropertyChangeListener>* 
pAllListeners = m_aPropertyChangeListeners.getContainer( OUString() );
+        ::comphelper::OInterfaceContainerHelper4<XPropertyChangeListener>* 
pPropListeners = m_aPropertyChangeListeners.getContainer( rGuard, sPropertyName 
);
+        ::comphelper::OInterfaceContainerHelper4<XPropertyChangeListener>* 
pAllListeners = m_aPropertyChangeListeners.getContainer( rGuard, OUString() );
         if ( !pPropListeners && !pAllListeners )
             return;
 
@@ -106,9 +105,9 @@ namespace svx
             provPos->getCurrentValue( aEvent.NewValue );
 
             if ( pPropListeners )
-                pPropListeners->notifyEach( 
&XPropertyChangeListener::propertyChange, aEvent );
+                pPropListeners->notifyEach( rGuard, 
&XPropertyChangeListener::propertyChange, aEvent );
             if ( pAllListeners )
-                pAllListeners->notifyEach( 
&XPropertyChangeListener::propertyChange, aEvent );
+                pAllListeners->notifyEach( rGuard, 
&XPropertyChangeListener::propertyChange, aEvent );
         }
         catch( const Exception& )
         {
@@ -117,23 +116,23 @@ namespace svx
     }
 
 
-    void PropertyChangeNotifier::addPropertyChangeListener( const OUString& 
_rPropertyName, const Reference< XPropertyChangeListener >& _rxListener )
+    void PropertyChangeNotifier::addPropertyChangeListener( 
std::unique_lock<std::mutex>& rGuard, const OUString& _rPropertyName, const 
Reference< XPropertyChangeListener >& _rxListener )
     {
-        m_aPropertyChangeListeners.addInterface( _rPropertyName, _rxListener );
+        m_aPropertyChangeListeners.addInterface( rGuard, _rPropertyName, 
_rxListener );
     }
 
 
-    void PropertyChangeNotifier::removePropertyChangeListener( const OUString& 
_rPropertyName, const Reference< XPropertyChangeListener >& _rxListener )
+    void PropertyChangeNotifier::removePropertyChangeListener( 
std::unique_lock<std::mutex>& rGuard, const OUString& _rPropertyName, const 
Reference< XPropertyChangeListener >& _rxListener )
     {
-        m_aPropertyChangeListeners.removeInterface( _rPropertyName, 
_rxListener );
+        m_aPropertyChangeListeners.removeInterface( rGuard, _rPropertyName, 
_rxListener );
     }
 
 
-    void PropertyChangeNotifier::disposing()
+    void PropertyChangeNotifier::disposing(std::unique_lock<std::mutex>& 
rGuard)
     {
         EventObject aEvent;
         aEvent.Source = m_rContext;
-        m_aPropertyChangeListeners.disposeAndClear( aEvent );
+        m_aPropertyChangeListeners.disposeAndClear( rGuard, aEvent );
     }
 
 
diff --git a/svx/source/unodraw/unoshape.cxx b/svx/source/unodraw/unoshape.cxx
index d5859fa3ca55..4ee178c5e58a 100644
--- a/svx/source/unodraw/unoshape.cxx
+++ b/svx/source/unodraw/unoshape.cxx
@@ -125,15 +125,14 @@ struct SvxShapeImpl
     ::unotools::WeakReference< SdrObject > mxCreatedObj;
 
     // for xComponent
-    ::comphelper::OInterfaceContainerHelper3<css::lang::XEventListener> 
maDisposeListeners;
+    ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> 
maDisposeListeners;
     svx::PropertyChangeNotifier       maPropertyNotifier;
 
-    SvxShapeImpl( SvxShape& _rAntiImpl, ::osl::Mutex& _rMutex )
+    SvxShapeImpl( SvxShape& _rAntiImpl )
         :mnObjId( SdrObjKind::NONE )
         ,mpMaster( nullptr )
         ,mbDisposing( false )
-        ,maDisposeListeners( _rMutex )
-        ,maPropertyNotifier( _rAntiImpl, _rMutex )
+        ,maPropertyNotifier( _rAntiImpl )
     {
     }
 };
@@ -195,7 +194,7 @@ sal_Int16 GetTextFitToSizeScale(SdrObject* pObject)
 
 SvxShape::SvxShape( SdrObject* pObject )
 :   maSize(100,100)
-,   mpImpl( new SvxShapeImpl( *this, m_aMutex ) )
+,   mpImpl( new SvxShapeImpl( *this ) )
 ,   mbIsMultiPropertyCall(false)
 ,   mpPropSet(getSvxMapProvider().GetPropertySet(SVXMAP_SHAPE, 
SdrObject::GetGlobalDrawObjectItemPool()))
 ,   maPropMapEntries(getSvxMapProvider().GetMap(SVXMAP_SHAPE))
@@ -208,7 +207,7 @@ SvxShape::SvxShape( SdrObject* pObject )
 
 SvxShape::SvxShape( SdrObject* pObject, o3tl::span<const 
SfxItemPropertyMapEntry> pEntries, const SvxItemPropertySet* pPropertySet )
 :   maSize(100,100)
-,   mpImpl( new SvxShapeImpl( *this, m_aMutex ) )
+,   mpImpl( new SvxShapeImpl( *this ) )
 ,   mbIsMultiPropertyCall(false)
 ,   mpPropSet(pPropertySet)
 ,   maPropMapEntries(pEntries)
@@ -290,11 +289,16 @@ sal_Int64 SAL_CALL SvxShape::getSomething( const 
css::uno::Sequence< sal_Int8 >&
 }
 
 
-svx::PropertyChangeNotifier& SvxShape::getShapePropertyChangeNotifier()
+void SvxShape::notifyPropertyChange(svx::ShapePropertyProviderId eProp)
 {
-    return mpImpl->maPropertyNotifier;
+    std::unique_lock g(m_aMutex);
+    mpImpl->maPropertyNotifier.notifyPropertyChange(g, eProp);
 }
 
+void SvxShape::registerProvider(svx::ShapePropertyProviderId eProp, 
std::unique_ptr<svx::PropertyValueProvider> provider)
+{
+    mpImpl->maPropertyNotifier.registerProvider(eProp, std::move(provider));
+}
 
 void SvxShape::impl_construct()
 {
@@ -1195,7 +1199,7 @@ OUString SAL_CALL SvxShape::getShapeType()
 
 void SAL_CALL SvxShape::dispose()
 {
-    ::SolarMutexGuard aGuard;
+    std::unique_lock g(m_aMutex);
 
     if( mpImpl->mbDisposing )
         return; // caught a recursion
@@ -1204,8 +1208,8 @@ void SAL_CALL SvxShape::dispose()
 
     lang::EventObject aEvt;
     aEvt.Source = *static_cast<OWeakAggObject*>(this);
-    mpImpl->maDisposeListeners.disposeAndClear(aEvt);
-    mpImpl->maPropertyNotifier.disposing();
+    mpImpl->maDisposeListeners.disposeAndClear(g, aEvt);
+    mpImpl->maPropertyNotifier.disposing(g);
 
     rtl::Reference<SdrObject> pObject = mxSdrObject;
     if (!pObject)
@@ -1235,13 +1239,15 @@ void SAL_CALL SvxShape::dispose()
 
 void SAL_CALL SvxShape::addEventListener( const Reference< 
lang::XEventListener >& xListener )
 {
-    mpImpl->maDisposeListeners.addInterface(xListener);
+    std::unique_lock g(m_aMutex);
+    mpImpl->maDisposeListeners.addInterface(g, xListener);
 }
 
 
 void SAL_CALL SvxShape::removeEventListener( const Reference< 
lang::XEventListener >& aListener )
 {
-   mpImpl->maDisposeListeners.removeInterface(aListener);
+    std::unique_lock g(m_aMutex);
+    mpImpl->maDisposeListeners.removeInterface(g, aListener);
 }
 
 // XPropertySet
@@ -1269,15 +1275,15 @@ Reference< beans::XPropertySetInfo > const &
 
 void SAL_CALL SvxShape::addPropertyChangeListener( const OUString& 
_propertyName, const Reference< beans::XPropertyChangeListener >& _listener  )
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
-    mpImpl->maPropertyNotifier.addPropertyChangeListener( _propertyName, 
_listener );
+    std::unique_lock g(m_aMutex);
+    mpImpl->maPropertyNotifier.addPropertyChangeListener( g, _propertyName, 
_listener );
 }
 
 
 void SAL_CALL SvxShape::removePropertyChangeListener( const OUString& 
_propertyName, const Reference< beans::XPropertyChangeListener >& _listener  )
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
-    mpImpl->maPropertyNotifier.removePropertyChangeListener( _propertyName, 
_listener );
+    std::unique_lock g(m_aMutex);
+    mpImpl->maPropertyNotifier.removePropertyChangeListener( g, _propertyName, 
_listener );
 }
 
 
diff --git a/sw/source/core/unocore/unodraw.cxx 
b/sw/source/core/unocore/unodraw.cxx
index 78bdde15f0c6..af4502e7449f 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -910,7 +910,7 @@ namespace
     void lcl_addShapePropertyEventFactories( SdrObject& _rObj, SwXShape& 
_rShape )
     {
         auto pProvider = std::make_unique<svx::PropertyValueProvider>( 
_rShape, "AnchorType" );
-        _rObj.getShapePropertyChangeNotifier().registerProvider( 
svx::ShapePropertyProviderId::TextDocAnchor, std::move(pProvider) );
+        _rObj.registerProvider( svx::ShapePropertyProviderId::TextDocAnchor, 
std::move(pProvider) );
     }
 }
 

Reply via email to