svtools/source/control/accessibleruler.cxx |  120 +++++++++++++++--------------
 svtools/source/control/accessibleruler.hxx |   20 ----
 svx/source/inc/tablemodel.hxx              |   14 +--
 svx/source/table/tablemodel.cxx            |   40 +++------
 4 files changed, 92 insertions(+), 102 deletions(-)

New commits:
commit c59a2c22e930d323b95f42089928baa1cad4224a
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Apr 2 15:45:52 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Apr 2 19:28:57 2024 +0200

    convert TableModel to comphelper::WeakComponentImplHelper
    
    Change-Id: I548a33e93c14c40c6cd500e3306a8e4279e73f52
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165678
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/svx/source/inc/tablemodel.hxx b/svx/source/inc/tablemodel.hxx
index 7a2cf4851c7e..3446604bc722 100644
--- a/svx/source/inc/tablemodel.hxx
+++ b/svx/source/inc/tablemodel.hxx
@@ -23,8 +23,8 @@
 #include <sal/types.h>
 #include <com/sun/star/util/XBroadcaster.hpp>
 #include <com/sun/star/table/XTable.hpp>
-#include <cppuhelper/compbase.hxx>
-#include <cppuhelper/basemutex.hxx>
+#include <comphelper/compbase.hxx>
+#include <comphelper/interfacecontainer4.hxx>
 #include "celltypes.hxx"
 
 struct _xmlTextWriter;
@@ -48,9 +48,9 @@ protected:
     ~ICellRange() {}
 };
 
-typedef ::cppu::WeakComponentImplHelper< css::table::XTable, 
css::util::XBroadcaster > TableModelBase;
+typedef ::comphelper::WeakComponentImplHelper< css::table::XTable, 
css::util::XBroadcaster > TableModelBase;
 
-class TableModel final : public ::cppu::BaseMutex,
+class TableModel final :
                    public TableModelBase,
                    public ICellRange
 {
@@ -99,7 +99,7 @@ public:
     virtual ::sal_Int32 SAL_CALL getColumnCount() override;
 
     // XComponent
-    virtual void SAL_CALL dispose(  ) override;
+//    virtual void disposing(std::unique_lock<std::mutex>& rGuard) override;
 
     // XModifiable
     virtual sal_Bool SAL_CALL isModified(  ) override;
@@ -158,7 +158,7 @@ private:
 private:
     /** this function is called upon disposing the component
     */
-    virtual void SAL_CALL disposing() override;
+    virtual void disposing(std::unique_lock<std::mutex>& rGuard) override;
 
     /// @throws css::lang::IndexOutOfBoundsException
     TableRowRef const & getRow( sal_Int32 nRow ) const;
@@ -180,6 +180,8 @@ private:
     bool mbNotifyPending;
 
     sal_Int32 mnNotifyLock;
+
+    comphelper::OInterfaceContainerHelper4<css::util::XModifyListener> 
maModifyListeners;
 };
 
 class TableModelNotifyGuard
diff --git a/svx/source/table/tablemodel.cxx b/svx/source/table/tablemodel.cxx
index dc0f10e16109..c2d0af6444ef 100644
--- a/svx/source/table/tablemodel.cxx
+++ b/svx/source/table/tablemodel.cxx
@@ -94,8 +94,7 @@ template< class Vec, class Iter, class Entry > static 
sal_Int32 insert_range( Ve
 
 
 TableModel::TableModel( SdrTableObj* pTableObj )
-: TableModelBase( m_aMutex  )
-, mpTableObj( pTableObj )
+: mpTableObj( pTableObj )
 , mbModified( false )
 , mbNotifyPending( false )
 , mnNotifyLock( 0 )
@@ -103,8 +102,7 @@ TableModel::TableModel( SdrTableObj* pTableObj )
 }
 
 TableModel::TableModel( SdrTableObj* pTableObj, const TableModelRef& 
xSourceTable )
-: TableModelBase( m_aMutex  )
-, mpTableObj( pTableObj )
+: mpTableObj( pTableObj )
 , mbModified( false )
 , mbNotifyPending( false )
 , mnNotifyLock( 0 )
@@ -311,15 +309,6 @@ std::vector<sal_Int32> TableModel::getColumnWidths()
     return aRet;
 }
 
-// XComponent
-
-
-void TableModel::dispose()
-{
-    ::SolarMutexGuard aGuard;
-    TableModelBase::dispose();
-}
-
 
 // XModifiable
 
@@ -347,13 +336,15 @@ void SAL_CALL TableModel::setModified( sal_Bool bModified 
)
 
 void SAL_CALL TableModel::addModifyListener( const 
uno::Reference<util::XModifyListener>& xListener )
 {
-    rBHelper.addListener( cppu::UnoType<util::XModifyListener>::get() , 
xListener );
+    std::unique_lock aGuard(m_aMutex);
+    maModifyListeners.addInterface( aGuard, xListener );
 }
 
 
 void SAL_CALL TableModel::removeModifyListener( const 
uno::Reference<util::XModifyListener>& xListener )
 {
-    rBHelper.removeListener( cppu::UnoType<util::XModifyListener>::get() , 
xListener );
+    std::unique_lock aGuard(m_aMutex);
+    maModifyListeners.removeInterface( aGuard, xListener );
 }
 
 
@@ -486,8 +477,11 @@ sal_Int32 TableModel::getColumnCountImpl() const
 }
 
 
-void TableModel::disposing()
+void TableModel::disposing(std::unique_lock<std::mutex>& rGuard)
 {
+    rGuard.unlock(); // do not hold this while taking solar mutex
+    ::SolarMutexGuard aGuard;
+
     if( !maRows.empty() )
     {
         for( auto& rpRow : maRows )
@@ -515,6 +509,8 @@ void TableModel::disposing()
     }
 
     mpTableObj = nullptr;
+
+    rGuard.lock();
 }
 
 
@@ -543,18 +539,14 @@ void TableModel::unlockBroadcasts()
 
 void TableModel::notifyModification()
 {
-    ::osl::MutexGuard guard( m_aMutex );
     if( (mnNotifyLock == 0) && mpTableObj )
     {
         mbNotifyPending = false;
 
-        ::cppu::OInterfaceContainerHelper * pModifyListeners = 
rBHelper.getContainer( cppu::UnoType<util::XModifyListener>::get() );
-        if( pModifyListeners )
-        {
-            lang::EventObject aSource;
-            aSource.Source = getXWeak();
-            pModifyListeners->notifyEach(&util::XModifyListener::modified, 
aSource);
-        }
+        lang::EventObject aSource;
+        aSource.Source = getXWeak();
+        std::unique_lock aGuard(m_aMutex);
+        maModifyListeners.notifyEach(aGuard, &util::XModifyListener::modified, 
aSource);
     }
     else
     {
commit b89c2909d48c9e4838d589085882e356439dcbbb
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Apr 2 14:51:22 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Apr 2 19:28:48 2024 +0200

    convert SvtRulerAccessible to comphelper::WeakComponentImplHelper
    
    Change-Id: Ibd37a38bf1fe6c2669af11b0c4eca957954f64bf
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165676
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/svtools/source/control/accessibleruler.cxx 
b/svtools/source/control/accessibleruler.cxx
index cf7436f2d034..a4a8b6b7c7cf 100644
--- a/svtools/source/control/accessibleruler.cxx
+++ b/svtools/source/control/accessibleruler.cxx
@@ -42,7 +42,6 @@ using namespace ::com::sun::star::accessibility;
 SvtRulerAccessible::SvtRulerAccessible(
     uno::Reference< XAccessible > xParent, Ruler& rRepr, OUString aName ) :
 
-    SvtRulerAccessible_Base( m_aMutex ),
     msName(std::move( aName )),
     mxParent(std::move( xParent )),
     mpRepr( &rRepr ),
@@ -52,8 +51,7 @@ SvtRulerAccessible::SvtRulerAccessible(
 
 SvtRulerAccessible::~SvtRulerAccessible()
 {
-
-    if( IsAlive() )
+    if( !m_bDisposed )
     {
         osl_atomic_increment( &m_refCount );
         dispose();      // set mpRepr = NULL & release all children
@@ -78,14 +76,10 @@ sal_Bool SAL_CALL SvtRulerAccessible::containsPoint( const 
awt::Point& rPoint )
 
 uno::Reference< XAccessible > SAL_CALL 
SvtRulerAccessible::getAccessibleAtPoint( const awt::Point& )
 {
-    ::osl::MutexGuard           aGuard( m_aMutex );
-
-    ThrowExceptionIfNotAlive();
-
-    uno::Reference< XAccessible >   xRet;
+    std::unique_lock aGuard( m_aMutex );
+    throwIfDisposed(aGuard);
 
-
-    return xRet;
+    return uno::Reference< XAccessible >();
 }
 
 awt::Rectangle SAL_CALL SvtRulerAccessible::getBounds()
@@ -114,9 +108,8 @@ awt::Size SAL_CALL SvtRulerAccessible::getSize()
 
 bool SvtRulerAccessible::isVisible()
 {
-    ::osl::MutexGuard           aGuard( m_aMutex );
-
-    ThrowExceptionIfNotAlive();
+    std::unique_lock aGuard( m_aMutex );
+    throwIfDisposed(aGuard);
 
     return mpRepr->IsVisible();
 }
@@ -124,9 +117,8 @@ bool SvtRulerAccessible::isVisible()
 //=====  XAccessibleContext  ==================================================
 sal_Int64 SAL_CALL SvtRulerAccessible::getAccessibleChildCount()
 {
-    ::osl::MutexGuard   aGuard( m_aMutex );
-
-    ThrowExceptionIfNotAlive();
+    std::unique_lock aGuard( m_aMutex );
+    throwIfDisposed(aGuard);
 
     return 0;
 }
@@ -145,7 +137,8 @@ uno::Reference< XAccessible > SAL_CALL 
SvtRulerAccessible::getAccessibleParent()
 
 sal_Int64 SAL_CALL SvtRulerAccessible::getAccessibleIndexInParent()
 {
-    ::osl::MutexGuard   aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
+
     //  Use a simple but slow solution for now.  Optimize later.
 
     //  Iterate over all the parent's children and search for this object.
@@ -195,16 +188,17 @@ uno::Reference< XAccessibleRelationSet > SAL_CALL 
SvtRulerAccessible::getAccessi
 
 sal_Int64 SAL_CALL SvtRulerAccessible::getAccessibleStateSet()
 {
-    ::osl::MutexGuard                       aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
+
     sal_Int64 nStateSet = 0;
 
-    if( IsAlive() )
+    if( !m_bDisposed )
     {
         nStateSet |= AccessibleStateType::ENABLED;
 
         nStateSet |= AccessibleStateType::SHOWING;
 
-        if( isVisible() )
+        if( mpRepr->IsVisible() )
             nStateSet |= AccessibleStateType::VISIBLE;
 
         if ( mpRepr->GetStyle() & WB_HORZ )
@@ -218,7 +212,8 @@ sal_Int64 SAL_CALL 
SvtRulerAccessible::getAccessibleStateSet()
 
 lang::Locale SAL_CALL SvtRulerAccessible::getLocale()
 {
-    ::osl::MutexGuard                           aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
+
     if( mxParent.is() )
     {
         uno::Reference< XAccessibleContext >    xParentContext( 
mxParent->getAccessibleContext() );
@@ -234,7 +229,7 @@ void SAL_CALL 
SvtRulerAccessible::addAccessibleEventListener( const uno::Referen
 {
     if (xListener.is())
     {
-        ::osl::MutexGuard   aGuard( m_aMutex );
+        std::unique_lock aGuard( m_aMutex );
         if (!mnClientId)
             mnClientId = comphelper::AccessibleEventNotifier::registerClient( 
);
         comphelper::AccessibleEventNotifier::addEventListener( mnClientId, 
xListener );
@@ -246,7 +241,7 @@ void SAL_CALL 
SvtRulerAccessible::removeAccessibleEventListener( const uno::Refe
     if (!(xListener.is() && mnClientId))
         return;
 
-    ::osl::MutexGuard   aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
 
     sal_Int32 nListenerCount = 
comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, xListener 
);
     if ( !nListenerCount )
@@ -262,29 +257,43 @@ void SAL_CALL 
SvtRulerAccessible::removeAccessibleEventListener( const uno::Refe
 
 void SAL_CALL SvtRulerAccessible::grabFocus()
 {
-    SolarMutexGuard     aSolarGuard;
-    ::osl::MutexGuard   aGuard( m_aMutex );
-
-    ThrowExceptionIfNotAlive();
+    VclPtr<Ruler> xRepr;
+    {
+        std::unique_lock aGuard( m_aMutex );
+        xRepr = mpRepr;
+    }
+    if (!xRepr)
+        throw css::lang::DisposedException(OUString(), 
static_cast<cppu::OWeakObject*>(this));
 
-    mpRepr->GrabFocus();
+    SolarMutexGuard     aSolarGuard;
+    xRepr->GrabFocus();
 }
 
 sal_Int32 SvtRulerAccessible::getForeground(  )
 {
-    SolarMutexGuard     aSolarGuard;
-    ::osl::MutexGuard   aGuard( m_aMutex );
-    ThrowExceptionIfNotAlive();
+    VclPtr<Ruler> xRepr;
+    {
+        std::unique_lock aGuard( m_aMutex );
+        xRepr = mpRepr;
+    }
+    if (!xRepr)
+        throw css::lang::DisposedException(OUString(), 
static_cast<cppu::OWeakObject*>(this));
 
-    return sal_Int32(mpRepr->GetControlForeground());
+    SolarMutexGuard     aSolarGuard;
+    return sal_Int32(xRepr->GetControlForeground());
 }
 sal_Int32 SvtRulerAccessible::getBackground(  )
 {
-    SolarMutexGuard     aSolarGuard;
-    ::osl::MutexGuard   aGuard( m_aMutex );
-    ThrowExceptionIfNotAlive();
+    VclPtr<Ruler> xRepr;
+    {
+        std::unique_lock aGuard( m_aMutex );
+        xRepr = mpRepr;
+    }
+    if (!xRepr)
+        throw css::lang::DisposedException(OUString(), 
static_cast<cppu::OWeakObject*>(this));
 
-    return sal_Int32(mpRepr->GetControlBackground());
+    SolarMutexGuard     aSolarGuard;
+    return sal_Int32(xRepr->GetControlBackground());
 }
 
 // XServiceInfo
@@ -309,12 +318,8 @@ Sequence< sal_Int8 > SAL_CALL 
SvtRulerAccessible::getImplementationId()
     return css::uno::Sequence<sal_Int8>();
 }
 
-void SAL_CALL SvtRulerAccessible::disposing()
+void SvtRulerAccessible::disposing(std::unique_lock<std::mutex>&)
 {
-    if( rBHelper.bDisposed )
-        return;
-
-    ::osl::MutexGuard   aGuard( m_aMutex );
     mpRepr = nullptr;      // object dies with representation
 
     // Send a disposing to all listeners.
@@ -328,27 +333,30 @@ void SAL_CALL SvtRulerAccessible::disposing()
 
 tools::Rectangle SvtRulerAccessible::GetBoundingBoxOnScreen()
 {
-    SolarMutexGuard     aSolarGuard;
-    ::osl::MutexGuard   aGuard( m_aMutex );
+    VclPtr<Ruler> xRepr;
+    {
+        std::unique_lock aGuard( m_aMutex );
+        xRepr = mpRepr;
+    }
+    if (!xRepr)
+        throw css::lang::DisposedException(OUString(), 
static_cast<cppu::OWeakObject*>(this));
 
-    ThrowExceptionIfNotAlive();
-    return tools::Rectangle( mpRepr->GetParent()->OutputToAbsoluteScreenPixel( 
mpRepr->GetPosPixel() ), mpRepr->GetSizePixel() );
+    SolarMutexGuard     aSolarGuard;
+    return tools::Rectangle( xRepr->GetParent()->OutputToAbsoluteScreenPixel( 
xRepr->GetPosPixel() ), xRepr->GetSizePixel() );
 }
 
 tools::Rectangle SvtRulerAccessible::GetBoundingBox()
 {
-    SolarMutexGuard     aSolarGuard;
-    ::osl::MutexGuard   aGuard( m_aMutex );
-
-    ThrowExceptionIfNotAlive();
-
-    return tools::Rectangle( mpRepr->GetPosPixel(), mpRepr->GetSizePixel() );
-}
+    VclPtr<Ruler> xRepr;
+    {
+        std::unique_lock aGuard( m_aMutex );
+        xRepr = mpRepr;
+    }
+    if (!xRepr)
+        throw css::lang::DisposedException(OUString(), 
static_cast<cppu::OWeakObject*>(this));
 
-void SvtRulerAccessible::ThrowExceptionIfNotAlive()
-{
-    if( rBHelper.bDisposed || rBHelper.bInDispose )
-        throw lang::DisposedException();
+    SolarMutexGuard     aSolarGuard;
+    return tools::Rectangle( xRepr->GetPosPixel(), xRepr->GetSizePixel() );
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svtools/source/control/accessibleruler.hxx 
b/svtools/source/control/accessibleruler.hxx
index ba03d0843a2b..7db02b6ddc92 100644
--- a/svtools/source/control/accessibleruler.hxx
+++ b/svtools/source/control/accessibleruler.hxx
@@ -27,15 +27,14 @@
 #include <com/sun/star/uno/Reference.hxx>
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #include <cppuhelper/interfacecontainer.h>
-#include <cppuhelper/compbase.hxx>
-#include <cppuhelper/basemutex.hxx>
+#include <comphelper/compbase.hxx>
 #include <vcl/vclptr.hxx>
 
 namespace tools { class Rectangle; }
 class Ruler;
 
 
-typedef ::cppu::WeakComponentImplHelper<
+typedef ::comphelper::WeakComponentImplHelper<
             css::accessibility::XAccessible,
             css::accessibility::XAccessibleComponent,
             css::accessibility::XAccessibleContext,
@@ -43,7 +42,7 @@ typedef ::cppu::WeakComponentImplHelper<
             css::lang::XServiceInfo >
             SvtRulerAccessible_Base;
 
-class SvtRulerAccessible final : public ::cppu::BaseMutex, public 
SvtRulerAccessible_Base
+class SvtRulerAccessible final : public SvtRulerAccessible_Base
 {
 public:
     //=====  internal  ========================================================
@@ -146,13 +145,7 @@ private:
 
     virtual ~SvtRulerAccessible() override;
 
-    virtual void SAL_CALL disposing() override;
-
-    /// @returns true if it's disposed or in disposing
-    inline bool IsAlive() const;
-
-    /// @throws DisposedException if it's not alive
-    void ThrowExceptionIfNotAlive();
+    virtual void disposing(std::unique_lock<std::mutex>& rGuard) override;
 
     /// @Return the object's current bounding box relative to the desktop.
     ///
@@ -178,11 +171,6 @@ private:
     sal_uInt32 mnClientId;
 };
 
-inline bool SvtRulerAccessible::IsAlive() const
-{
-    return !rBHelper.bDisposed && !rBHelper.bInDispose;
-}
-
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to