summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2024-04-02 14:51:22 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2024-04-02 19:28:48 +0200
commitb89c2909d48c9e4838d589085882e356439dcbbb (patch)
treedba4e8cea54d9f61d78e8900d91725b0eb91efb8
parent58c4457a902c846229dc3383cc31bbc8f4b3aed9 (diff)
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.grandin@collabora.co.uk>
-rw-r--r--svtools/source/control/accessibleruler.cxx120
-rw-r--r--svtools/source/control/accessibleruler.hxx20
2 files changed, 68 insertions, 72 deletions
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: */