sc/source/ui/unoobj/cellvaluebinding.cxx |   98 +++++++++++++++++--------------
 sc/source/ui/unoobj/cellvaluebinding.hxx |   28 ++++----
 2 files changed, 68 insertions(+), 58 deletions(-)

New commits:
commit 7510cca63690ea97eb02a43f698fc183c3d0434a
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Mar 26 15:56:02 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Mar 28 06:42:46 2024 +0100

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

diff --git a/sc/source/ui/unoobj/cellvaluebinding.cxx 
b/sc/source/ui/unoobj/cellvaluebinding.cxx
index fd8b43f9578e..7c4865726bef 100644
--- a/sc/source/ui/unoobj/cellvaluebinding.cxx
+++ b/sc/source/ui/unoobj/cellvaluebinding.cxx
@@ -54,10 +54,7 @@ namespace calc
     using namespace ::com::sun::star::form::binding;
 
     OCellValueBinding::OCellValueBinding( const Reference< 
XSpreadsheetDocument >& _rxDocument, bool _bListPos )
-        :OCellValueBinding_Base( m_aMutex )
-        ,OCellValueBinding_PBase( OCellValueBinding_Base::rBHelper )
-        ,m_xDocument( _rxDocument )
-        ,m_aModifyListeners( m_aMutex )
+        :m_xDocument( _rxDocument )
         ,m_bInitialized( false )
         ,m_bListPos( _bListPos )
     {
@@ -76,7 +73,7 @@ namespace calc
 
     OCellValueBinding::~OCellValueBinding( )
     {
-        if ( !OCellValueBinding_Base::rBHelper.bDisposed )
+        if ( !m_bDisposed )
         {
             acquire();  // prevent duplicate dtor
             dispose();
@@ -87,7 +84,7 @@ namespace calc
 
     IMPLEMENT_FORWARD_XTYPEPROVIDER2( OCellValueBinding, 
OCellValueBinding_Base, OCellValueBinding_PBase )
 
-    void SAL_CALL OCellValueBinding::disposing()
+    void OCellValueBinding::disposing( std::unique_lock<std::mutex>& rGuard )
     {
         Reference<XModifyBroadcaster> xBroadcaster( m_xCell, UNO_QUERY );
         if ( xBroadcaster.is() )
@@ -95,7 +92,7 @@ namespace calc
             xBroadcaster->removeModifyListener( this );
         }
 
-        WeakComponentImplHelperBase::disposing();
+        WeakComponentImplHelperBase::disposing(rGuard);
 
         // TODO: clean up here whatever you need to clean up (e.g. deregister 
as XEventListener
         // for the cell)
@@ -106,7 +103,7 @@ namespace calc
         return createPropertySetInfo( getInfoHelper() ) ;
     }
 
-    ::cppu::IPropertyArrayHelper& SAL_CALL OCellValueBinding::getInfoHelper()
+    ::cppu::IPropertyArrayHelper& OCellValueBinding::getInfoHelper()
     {
         return *OCellValueBinding_PABase::getArrayHelper();
     }
@@ -118,7 +115,7 @@ namespace calc
         return new ::cppu::OPropertyArrayHelper(aProps);
     }
 
-    void SAL_CALL OCellValueBinding::getFastPropertyValue( Any& _rValue, 
sal_Int32 _nHandle ) const
+    void OCellValueBinding::getFastPropertyValue( 
std::unique_lock<std::mutex>& /*rGuard*/, Any& _rValue, sal_Int32 _nHandle ) 
const
     {
         OSL_ENSURE( _nHandle == PROP_HANDLE_BOUND_CELL, 
"OCellValueBinding::getFastPropertyValue: invalid handle!" );
             // we only have this one property...
@@ -131,9 +128,14 @@ namespace calc
 
     Sequence< Type > SAL_CALL OCellValueBinding::getSupportedValueTypes(  )
     {
-        checkDisposed( );
+        std::unique_lock<std::mutex> aGuard(m_aMutex);
+        throwIfDisposed(aGuard);
         checkInitialized( );
+        return getSupportedValueTypes(aGuard);
+    }
 
+    Sequence< Type > OCellValueBinding::getSupportedValueTypes( 
std::unique_lock<std::mutex>& /*rGuard*/  ) const
+    {
         sal_Int32 nCount = m_xCellText.is() ? 3 : m_xCell.is() ? 1 : 0;
         if ( m_bListPos )
             ++nCount;
@@ -163,11 +165,16 @@ namespace calc
 
     sal_Bool SAL_CALL OCellValueBinding::supportsType( const Type& aType )
     {
-        checkDisposed( );
+        std::unique_lock<std::mutex> aGuard(m_aMutex);
+        throwIfDisposed(aGuard);
         checkInitialized( );
+        return supportsType(aGuard, aType);
+    }
 
+    bool OCellValueBinding::supportsType( std::unique_lock<std::mutex>& 
rGuard, const Type& aType ) const
+    {
         // look up in our sequence
-        const Sequence< Type > aSupportedTypes( getSupportedValueTypes() );
+        const Sequence< Type > aSupportedTypes( getSupportedValueTypes(rGuard) 
);
         for ( auto const & i : aSupportedTypes )
             if ( aType == i )
                 return true;
@@ -177,9 +184,10 @@ namespace calc
 
     Any SAL_CALL OCellValueBinding::getValue( const Type& aType )
     {
-        checkDisposed( );
+        std::unique_lock<std::mutex> aGuard(m_aMutex);
+        throwIfDisposed(aGuard);
         checkInitialized( );
-        checkValueType( aType );
+        checkValueType( aGuard, aType );
 
         Any aReturn;
         switch ( aType.getTypeClass() )
@@ -263,10 +271,11 @@ namespace calc
 
     void SAL_CALL OCellValueBinding::setValue( const Any& aValue )
     {
-        checkDisposed( );
+        std::unique_lock<std::mutex> aGuard(m_aMutex);
+        throwIfDisposed(aGuard);
         checkInitialized( );
         if ( aValue.hasValue() )
-            checkValueType( aValue.getValueType() );
+            checkValueType( aGuard, aValue.getValueType() );
 
         switch ( aValue.getValueType().getTypeClass() )
         {
@@ -390,30 +399,22 @@ namespace calc
         }
     }
 
-    void OCellValueBinding::checkDisposed( ) const
-    {
-        if ( OCellValueBinding_Base::rBHelper.bInDispose || 
OCellValueBinding_Base::rBHelper.bDisposed )
-            throw DisposedException();
-            // TODO: is it worth having an error message here?
-    }
-
     void OCellValueBinding::checkInitialized()
     {
         if ( !m_bInitialized )
             throw NotInitializedException("CellValueBinding is not 
initialized", getXWeak());
     }
 
-    void OCellValueBinding::checkValueType( const Type& _rType ) const
+    void OCellValueBinding::checkValueType( std::unique_lock<std::mutex>& 
rGuard, const Type& _rType ) const
     {
-        OCellValueBinding* pNonConstThis = const_cast< OCellValueBinding* >( 
this );
-        if ( !pNonConstThis->supportsType( _rType ) )
+        if ( !supportsType( rGuard, _rType ) )
         {
             OUString sMessage = "The given type (" +
                 _rType.getTypeName() +
                 ") is not supported by this binding.";
                 // TODO: localize this error message
 
-            throw IncompatibleTypesException( sMessage, *pNonConstThis );
+            throw IncompatibleTypesException( sMessage, 
const_cast<OCellValueBinding&>(*this) );
                 // TODO: alternatively use a type converter service for this?
         }
     }
@@ -442,13 +443,19 @@ namespace calc
     void SAL_CALL OCellValueBinding::addModifyListener( const Reference< 
XModifyListener >& _rxListener )
     {
        if ( _rxListener.is() )
-           m_aModifyListeners.addInterface( _rxListener );
+       {
+           std::unique_lock<std::mutex> aGuard(m_aMutex);
+           m_aModifyListeners.addInterface( aGuard, _rxListener );
+       }
     }
 
     void SAL_CALL OCellValueBinding::removeModifyListener( const Reference< 
XModifyListener >& _rxListener )
     {
        if ( _rxListener.is() )
-           m_aModifyListeners.removeInterface( _rxListener );
+       {
+           std::unique_lock<std::mutex> aGuard(m_aMutex);
+           m_aModifyListeners.removeInterface( aGuard, _rxListener );
+       }
     }
 
     void OCellValueBinding::notifyModified()
@@ -456,22 +463,25 @@ namespace calc
         EventObject aEvent;
         aEvent.Source.set(*this);
 
-        ::comphelper::OInterfaceIteratorHelper3 aIter( m_aModifyListeners );
-        while ( aIter.hasMoreElements() )
-        {
-            try
-            {
-                aIter.next()->modified( aEvent );
-            }
-            catch( const RuntimeException& )
+        std::unique_lock<std::mutex> aGuard(m_aMutex);
+        m_aModifyListeners.forEach(aGuard,
+            [&aEvent, &aGuard] (const 
css::uno::Reference<css::util::XModifyListener> & l)
             {
-                // silent this
-            }
-            catch( const Exception& )
-            {
-                TOOLS_WARN_EXCEPTION( "sc", 
"OCellValueBinding::notifyModified: caught a (non-runtime) exception!" );
-            }
-        }
+                aGuard.unlock();
+                try
+                {
+                    l->modified( aEvent );
+                }
+                catch( const RuntimeException& )
+                {
+                    // silent this
+                }
+                catch( const Exception& )
+                {
+                    TOOLS_WARN_EXCEPTION( "sc", 
"OCellValueBinding::notifyModified: caught a (non-runtime) exception!" );
+                }
+                aGuard.lock();
+            });
     }
 
     void SAL_CALL OCellValueBinding::modified( const EventObject& /* aEvent */ 
)
diff --git a/sc/source/ui/unoobj/cellvaluebinding.hxx 
b/sc/source/ui/unoobj/cellvaluebinding.hxx
index 511303f7edcd..8c77523f4ab0 100644
--- a/sc/source/ui/unoobj/cellvaluebinding.hxx
+++ b/sc/source/ui/unoobj/cellvaluebinding.hxx
@@ -21,10 +21,9 @@
 
 #include <com/sun/star/form/binding/XValueBinding.hpp>
 #include <com/sun/star/util/XModifyBroadcaster.hpp>
-#include <cppuhelper/compbase.hxx>
-#include <cppuhelper/basemutex.hxx>
-#include <comphelper/interfacecontainer3.hxx>
-#include <comphelper/propertycontainer.hxx>
+#include <comphelper/compbase.hxx>
+#include <comphelper/interfacecontainer4.hxx>
+#include <comphelper/propertycontainer2.hxx>
 #include <comphelper/uno3.hxx>
 #include <comphelper/proparrhlp.hxx>
 #include <com/sun/star/lang/XServiceInfo.hpp>
@@ -41,20 +40,20 @@ namespace calc
 
     class OCellValueBinding;
     // the base for our interfaces
-    typedef ::cppu::WeakComponentImplHelper <   
css::form::binding::XValueBinding
+    typedef ::comphelper::WeakComponentImplHelper <   
css::form::binding::XValueBinding
                                             ,   css::lang::XServiceInfo
                                             ,   css::util::XModifyBroadcaster
                                             ,   css::util::XModifyListener
                                             ,   css::lang::XInitialization
                                             >   OCellValueBinding_Base;
     // the base for the property handling
-    typedef ::comphelper::OPropertyContainer        OCellValueBinding_PBase;
+    typedef ::comphelper::OPropertyContainer2        OCellValueBinding_PBase;
     // the second base for property handling
     typedef ::comphelper::OPropertyArrayUsageHelper< OCellValueBinding >
                                                     OCellValueBinding_PABase;
 
-    class OCellValueBinding :public ::cppu::BaseMutex
-                            ,public OCellValueBinding_Base      // order 
matters! before OCellValueBinding_PBase, so rBHelper gets initialized
+    class OCellValueBinding :
+                             public OCellValueBinding_Base      // order 
matters! before OCellValueBinding_PBase, so rBHelper gets initialized
                             ,public OCellValueBinding_PBase
                             ,public OCellValueBinding_PABase
     {
@@ -65,7 +64,7 @@ namespace calc
                     m_xCell;                /// the cell we're bound to, for 
double value access
         css::uno::Reference< css::text::XTextRange >
                     m_xCellText;            /// the cell we're bound to, for 
text access
-        ::comphelper::OInterfaceContainerHelper3<css::util::XModifyListener>
+        ::comphelper::OInterfaceContainerHelper4<css::util::XModifyListener>
                     m_aModifyListeners;     /// our modify listeners
         bool        m_bInitialized;         /// has 
XInitialization::initialize been called?
         bool        m_bListPos;             /// constructed as 
ListPositionCellBinding?
@@ -95,7 +94,7 @@ namespace calc
         virtual void SAL_CALL setValue( const css::uno::Any& aValue ) override;
 
         // OComponentHelper/XComponent
-        virtual void SAL_CALL disposing() override;
+        virtual void disposing(std::unique_lock<std::mutex>& rGuard) override;
 
         // XServiceInfo
         virtual OUString SAL_CALL getImplementationName(  ) override;
@@ -106,8 +105,8 @@ namespace calc
         virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL 
getPropertySetInfo(  ) override;
 
         // OPropertySetHelper
-        virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() 
override;
-        virtual void SAL_CALL getFastPropertyValue( css::uno::Any& _rValue, 
sal_Int32 _nHandle ) const override;
+        virtual ::cppu::IPropertyArrayHelper& getInfoHelper() override;
+        virtual void getFastPropertyValue( std::unique_lock<std::mutex>& 
rGuard, css::uno::Any& _rValue, sal_Int32 _nHandle ) const override;
 
         // ::comphelper::OPropertyArrayUsageHelper
         virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const 
override;
@@ -124,9 +123,10 @@ namespace calc
         virtual void SAL_CALL initialize( const css::uno::Sequence< 
css::uno::Any >& aArguments ) override;
 
     private:
-        void    checkDisposed( ) const;
-        void    checkValueType( const css::uno::Type& _rType ) const;
+        void    checkValueType( std::unique_lock<std::mutex>& rGuard, const 
css::uno::Type& _rType ) const;
         void    checkInitialized();
+        css::uno::Sequence< css::uno::Type > 
getSupportedValueTypes(std::unique_lock<std::mutex>& rGuard) const;
+        bool    supportsType( std::unique_lock<std::mutex>& rGuard, const 
css::uno::Type& aType ) const;
 
         /** notifies our modify listeners
             @precond

Reply via email to