sd/source/ui/accessibility/AccessibleSlideSorterObject.cxx |  165 +------------
 sd/source/ui/inc/AccessibleSlideSorterObject.hxx           |   57 ----
 2 files changed, 22 insertions(+), 200 deletions(-)

New commits:
commit 9d136ee0df1f0a5d40078823828b543f944fa4e7
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Feb 26 13:33:08 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Feb 26 20:10:21 2025 +0100

    sd slidesorter a11y: Drop AccessibleSlideSorterObject::ThrowIfDisposed
    
    Use the base class OCommonAccessibleComponent::ensureAlive
    directly instead.
    
    Change-Id: Idcba10f4c8d9fef18ffc7d4c71d8a129f464c3d7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182249
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/sd/source/ui/accessibility/AccessibleSlideSorterObject.cxx 
b/sd/source/ui/accessibility/AccessibleSlideSorterObject.cxx
index c25cb198ea49..4c6538f35ed8 100644
--- a/sd/source/ui/accessibility/AccessibleSlideSorterObject.cxx
+++ b/sd/source/ui/accessibility/AccessibleSlideSorterObject.cxx
@@ -76,7 +76,7 @@ void AccessibleSlideSorterObject::FireAccessibleEvent (
 Reference<XAccessibleContext> SAL_CALL
     AccessibleSlideSorterObject::getAccessibleContext()
 {
-    ThrowIfDisposed();
+    ensureAlive();
     return this;
 }
 
@@ -84,25 +84,25 @@ Reference<XAccessibleContext> SAL_CALL
 
 sal_Int64 SAL_CALL AccessibleSlideSorterObject::getAccessibleChildCount()
 {
-    ThrowIfDisposed();
+    ensureAlive();
     return 0;
 }
 
 Reference<XAccessible> SAL_CALL 
AccessibleSlideSorterObject::getAccessibleChild (sal_Int64 )
 {
-    ThrowIfDisposed();
+    ensureAlive();
     throw lang::IndexOutOfBoundsException();
 }
 
 Reference<XAccessible> SAL_CALL 
AccessibleSlideSorterObject::getAccessibleParent()
 {
-    ThrowIfDisposed();
+    ensureAlive();
     return mxParent;
 }
 
 sal_Int64 SAL_CALL AccessibleSlideSorterObject::getAccessibleIndexInParent()
 {
-    ThrowIfDisposed();
+    ensureAlive();
     const SolarMutexGuard aSolarGuard;
     sal_Int64 nIndexInParent(-1);
 
@@ -122,19 +122,19 @@ sal_Int64 SAL_CALL 
AccessibleSlideSorterObject::getAccessibleIndexInParent()
 
 sal_Int16 SAL_CALL AccessibleSlideSorterObject::getAccessibleRole()
 {
-    ThrowIfDisposed();
+    ensureAlive();
     return AccessibleRole::SHAPE;
 }
 
 OUString SAL_CALL AccessibleSlideSorterObject::getAccessibleDescription()
 {
-    ThrowIfDisposed();
+    ensureAlive();
     return SdResId(STR_PAGE);
 }
 
 OUString SAL_CALL AccessibleSlideSorterObject::getAccessibleName()
 {
-    ThrowIfDisposed();
+    ensureAlive();
     const SolarMutexGuard aSolarGuard;
 
     SdPage* pPage = GetPage();
@@ -147,14 +147,14 @@ OUString SAL_CALL 
AccessibleSlideSorterObject::getAccessibleName()
 Reference<XAccessibleRelationSet> SAL_CALL
     AccessibleSlideSorterObject::getAccessibleRelationSet()
 {
-    ThrowIfDisposed();
+    ensureAlive();
     return Reference<XAccessibleRelationSet>();
 }
 
 sal_Int64 SAL_CALL
     AccessibleSlideSorterObject::getAccessibleStateSet()
 {
-    ThrowIfDisposed();
+    ensureAlive();
     const SolarMutexGuard aSolarGuard;
     sal_Int64 nStateSet = 0;
 
@@ -182,7 +182,7 @@ sal_Int64 SAL_CALL
 
 lang::Locale SAL_CALL AccessibleSlideSorterObject::getLocale()
 {
-    ThrowIfDisposed();
+    ensureAlive();
     // Delegate request to parent.
     if (mxParent.is())
     {
@@ -234,7 +234,7 @@ void SAL_CALL AccessibleSlideSorterObject::grabFocus()
 
 sal_Int32 SAL_CALL AccessibleSlideSorterObject::getForeground()
 {
-    ThrowIfDisposed ();
+    ensureAlive();
     svtools::ColorConfig aColorConfig;
     Color nColor = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor;
     return static_cast<sal_Int32>(nColor);
@@ -242,7 +242,7 @@ sal_Int32 SAL_CALL 
AccessibleSlideSorterObject::getForeground()
 
 sal_Int32 SAL_CALL AccessibleSlideSorterObject::getBackground()
 {
-    ThrowIfDisposed ();
+    ensureAlive();
     Color nColor = 
Application::GetSettings().GetStyleSettings().GetWindowColor();
     return sal_Int32(nColor);
 }
@@ -262,7 +262,7 @@ sal_Bool SAL_CALL 
AccessibleSlideSorterObject::supportsService (const OUString&
 uno::Sequence< OUString> SAL_CALL
        AccessibleSlideSorterObject::getSupportedServiceNames()
 {
-    ThrowIfDisposed ();
+    ensureAlive();
 
     return uno::Sequence<OUString> {
         u"com.sun.star.accessibility.Accessible"_ustr,
@@ -270,11 +270,6 @@ uno::Sequence< OUString> SAL_CALL
     };
 }
 
-void AccessibleSlideSorterObject::ThrowIfDisposed()
-{
-    ensureAlive();
-}
-
 SdPage* AccessibleSlideSorterObject::GetPage() const
 {
     ::sd::slidesorter::model::SharedPageDescriptor pDescriptor(
diff --git a/sd/source/ui/inc/AccessibleSlideSorterObject.hxx 
b/sd/source/ui/inc/AccessibleSlideSorterObject.hxx
index 748c23817ea3..b8d33bb0a6c5 100644
--- a/sd/source/ui/inc/AccessibleSlideSorterObject.hxx
+++ b/sd/source/ui/inc/AccessibleSlideSorterObject.hxx
@@ -138,15 +138,6 @@ private:
     rtl::Reference<AccessibleSlideSorterView> mxParent;
     sal_uInt16 mnPageNumber;
     ::sd::slidesorter::SlideSorter& mrSlideSorter;
-
-    /** Check whether or not the object has been disposed (or is in the
-        state of being disposed).  If that is the case then
-        DisposedException is thrown to inform the (indirect) caller of the
-        foul deed.
-
-        @throws css::lang::DisposedException
-    */
-    void ThrowIfDisposed();
 };
 
 } // end of namespace ::accessibility
commit deb08fdad2f95fc288b15fca5c6fab8b3804a74e
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Feb 26 13:31:14 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Feb 26 20:10:13 2025 +0100

    sd slidesorter a11y: Use OAccessibleComponentHelper for items
    
    Similar to how
    
        commit b5d197cf4b4fc5f4e6aca5e01e2cc9757293c63e
        Author: Michael Weghorn <m.wegh...@posteo.de>
        Date:   Tue Feb 25 11:51:40 2025 +0100
    
            valueset a11y: Use OAccessibleComponentHelper for ValueSetAcc
    
    did for ValueSetAcc, also derive
    from OAccessibleComponentHelper for AccessibleSlideSorterObject
    to make use of the logic already implemented there
    instead of having to implement all the XAccessibleComponent
    and XAccessibleEventBroadcaster methods manually.
    
    AccessibleSlideSorterObject::getBounds implements what is needed
    to implement OAccessibleComponentHelper::implGetBounds,
    so rename the method (and drop the mutex guard from that
    method, as callers of that method in the base class take
    care of that).
    
    Drop all of the other overrides that are no longer
    needed as the implementation is now provided by
    the OAccessibleComponentHelper base class.
    
    No change in behavior intended or observed when testing
    this with Accerciser and Orca and the qt6 VCL plugin
    with the "Slides" pane in Impress.
    
    Change-Id: I7a7fe4c3e82632e46ac5406e366ee4763f239ec4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182248
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/sd/source/ui/accessibility/AccessibleSlideSorterObject.cxx 
b/sd/source/ui/accessibility/AccessibleSlideSorterObject.cxx
index 50b5a3e02226..c25cb198ea49 100644
--- a/sd/source/ui/accessibility/AccessibleSlideSorterObject.cxx
+++ b/sd/source/ui/accessibility/AccessibleSlideSorterObject.cxx
@@ -55,15 +55,12 @@ AccessibleSlideSorterObject::AccessibleSlideSorterObject(
     sal_uInt16 nPageNumber)
     : mxParent(rxParent),
       mnPageNumber(nPageNumber),
-      mrSlideSorter(rSlideSorter),
-      mnClientId(0)
+      mrSlideSorter(rSlideSorter)
 {
 }
 
 AccessibleSlideSorterObject::~AccessibleSlideSorterObject()
 {
-    if ( ! IsDisposed())
-        dispose();
 }
 
 void AccessibleSlideSorterObject::FireAccessibleEvent (
@@ -71,27 +68,7 @@ void AccessibleSlideSorterObject::FireAccessibleEvent (
     const uno::Any& rOldValue,
     const uno::Any& rNewValue)
 {
-    if (mnClientId != 0)
-    {
-        AccessibleEventObject aEventObject;
-
-        aEventObject.Source = Reference<XWeak>(this);
-        aEventObject.EventId = nEventId;
-        aEventObject.NewValue = rNewValue;
-        aEventObject.OldValue = rOldValue;
-
-        comphelper::AccessibleEventNotifier::addEvent(mnClientId, 
aEventObject);
-    }
-}
-
-void AccessibleSlideSorterObject::disposing(std::unique_lock<std::mutex>&)
-{
-    // Send a disposing to all listeners.
-    if (mnClientId != 0)
-    {
-        
comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing(mnClientId, 
*this);
-        mnClientId =  0;
-    }
+    NotifyAccessibleEvent(nEventId, rOldValue, rNewValue);
 }
 
 //===== XAccessible ===========================================================
@@ -217,77 +194,16 @@ lang::Locale SAL_CALL 
AccessibleSlideSorterObject::getLocale()
     throw IllegalAccessibleComponentStateException();
 }
 
-//===== XAccessibleEventBroadcaster ===========================================
-
-void SAL_CALL AccessibleSlideSorterObject::addAccessibleEventListener(
-    const Reference<XAccessibleEventListener>& rxListener)
-{
-    if (!rxListener.is())
-        return;
-
-    const std::unique_lock aGuard(m_aMutex);
-
-    if (IsDisposed())
-    {
-        uno::Reference<uno::XInterface> x (static_cast<lang::XComponent 
*>(this), uno::UNO_QUERY);
-        rxListener->disposing (lang::EventObject (x));
-    }
-    else
-    {
-        if (mnClientId == 0)
-            mnClientId = comphelper::AccessibleEventNotifier::registerClient();
-        comphelper::AccessibleEventNotifier::addEventListener(mnClientId, 
rxListener);
-    }
-}
-
-void SAL_CALL AccessibleSlideSorterObject::removeAccessibleEventListener(
-    const Reference<XAccessibleEventListener>& rxListener)
-{
-    ThrowIfDisposed();
-    if (!rxListener.is())
-        return;
-
-    const std::unique_lock aGuard(m_aMutex);
-
-    if (!mnClientId)
-        return;
-
-    sal_Int32 nListenerCount = 
comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, 
rxListener );
-    if ( !nListenerCount )
-    {
-        // no listeners anymore
-        // -> revoke ourself. This may lead to the notifier thread dying (if 
we were the last client),
-        // and at least to us not firing any events anymore, in case somebody 
calls
-        // NotifyAccessibleEvent, again
-        comphelper::AccessibleEventNotifier::revokeClient( mnClientId );
-        mnClientId = 0;
-    }
-}
-
 //===== XAccessibleComponent ==================================================
 
-sal_Bool SAL_CALL AccessibleSlideSorterObject::containsPoint(const awt::Point& 
aPoint)
-{
-    ThrowIfDisposed();
-    const awt::Size aSize (getSize());
-    return (aPoint.X >= 0)
-        && (aPoint.X < aSize.Width)
-        && (aPoint.Y >= 0)
-        && (aPoint.Y < aSize.Height);
-}
-
 Reference<XAccessible> SAL_CALL
     AccessibleSlideSorterObject::getAccessibleAtPoint(const awt::Point& )
 {
     return nullptr;
 }
 
-awt::Rectangle SAL_CALL AccessibleSlideSorterObject::getBounds()
+awt::Rectangle AccessibleSlideSorterObject::implGetBounds()
 {
-    ThrowIfDisposed ();
-
-    const SolarMutexGuard aSolarGuard;
-
     ::tools::Rectangle aBBox (
         
mrSlideSorter.GetView().GetLayouter().GetPageObjectLayouter()->GetBoundingBox(
             mrSlideSorter.GetModel().GetPageDescriptor(mnPageNumber),
@@ -311,38 +227,6 @@ awt::Rectangle SAL_CALL 
AccessibleSlideSorterObject::getBounds()
         aBBox.GetHeight());
 }
 
-awt::Point SAL_CALL AccessibleSlideSorterObject::getLocation ()
-{
-    ThrowIfDisposed ();
-    const awt::Rectangle aBBox (getBounds());
-    return awt::Point(aBBox.X, aBBox.Y);
-}
-
-awt::Point SAL_CALL AccessibleSlideSorterObject::getLocationOnScreen()
-{
-    ThrowIfDisposed ();
-
-    const SolarMutexGuard aSolarGuard;
-
-    awt::Point aLocation (getLocation());
-
-    if (mxParent.is())
-    {
-        const awt::Point 
aParentLocationOnScreen(mxParent->getLocationOnScreen());
-        aLocation.X += aParentLocationOnScreen.X;
-        aLocation.Y += aParentLocationOnScreen.Y;
-    }
-
-    return aLocation;
-}
-
-awt::Size SAL_CALL AccessibleSlideSorterObject::getSize()
-{
-    ThrowIfDisposed ();
-    const awt::Rectangle aBBox (getBounds());
-    return awt::Size(aBBox.Width,aBBox.Height);
-}
-
 void SAL_CALL AccessibleSlideSorterObject::grabFocus()
 {
     // nothing to do
@@ -388,17 +272,7 @@ uno::Sequence< OUString> SAL_CALL
 
 void AccessibleSlideSorterObject::ThrowIfDisposed()
 {
-    if (m_bDisposed)
-    {
-        SAL_WARN("sd", "Calling disposed object. Throwing exception:");
-        throw lang::DisposedException (u"object has been already 
disposed"_ustr,
-            static_cast<uno::XWeak*>(this));
-    }
-}
-
-bool AccessibleSlideSorterObject::IsDisposed() const
-{
-    return m_bDisposed;
+    ensureAlive();
 }
 
 SdPage* AccessibleSlideSorterObject::GetPage() const
diff --git a/sd/source/ui/inc/AccessibleSlideSorterObject.hxx 
b/sd/source/ui/inc/AccessibleSlideSorterObject.hxx
index a33b5db78894..748c23817ea3 100644
--- a/sd/source/ui/inc/AccessibleSlideSorterObject.hxx
+++ b/sd/source/ui/inc/AccessibleSlideSorterObject.hxx
@@ -23,9 +23,6 @@
 
 #include <comphelper/compbase.hxx>
 #include <com/sun/star/accessibility/XAccessible.hpp>
-#include <com/sun/star/accessibility/XAccessibleContext.hpp>
-#include <com/sun/star/accessibility/XAccessibleComponent.hpp>
-#include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #include <rtl/ref.hxx>
 
@@ -34,17 +31,11 @@ namespace sd::slidesorter { class SlideSorter; }
 
 namespace accessibility {
 
-typedef comphelper::WeakComponentImplHelper<
-    css::accessibility::XAccessible,
-    css::accessibility::XAccessibleEventBroadcaster,
-    css::accessibility::XAccessibleContext,
-    css::accessibility::XAccessibleComponent,
-    css::lang::XServiceInfo > AccessibleSlideSorterObjectBase;
-
 /** This class makes page objects of the slide sorter accessible.
 */
 class AccessibleSlideSorterObject
-    : public AccessibleSlideSorterObjectBase
+    : public 
cppu::ImplInheritanceHelper<comphelper::OAccessibleComponentHelper,
+                                         css::accessibility::XAccessible, 
css::lang::XServiceInfo>
 {
 public:
     /** Create a new object that represents a page object in the slide
@@ -75,22 +66,11 @@ public:
         const css::uno::Any& rOldValue,
         const css::uno::Any& rNewValue);
 
-    virtual void disposing(std::unique_lock<std::mutex>&) override;
-
     //===== XAccessible =======================================================
 
     virtual css::uno::Reference<css::accessibility::XAccessibleContext > 
SAL_CALL
         getAccessibleContext() override;
 
-    //===== XAccessibleEventBroadcaster =======================================
-    virtual void SAL_CALL
-        addAccessibleEventListener(
-            const 
css::uno::Reference<css::accessibility::XAccessibleEventListener >& rxListener) 
override;
-
-    virtual void SAL_CALL
-        removeAccessibleEventListener(
-            const 
css::uno::Reference<css::accessibility::XAccessibleEventListener >& rxListener 
) override;
-
     //=====  XAccessibleContext  ==============================================
 
     virtual sal_Int64 SAL_CALL
@@ -123,23 +103,14 @@ public:
     virtual css::lang::Locale SAL_CALL
         getLocale() override;
 
-    //=====  XAccessibleComponent  
================================================
-
-    virtual sal_Bool SAL_CALL containsPoint (
-        const css::awt::Point& aPoint) override;
+    // OCommonAccessibleComponent
+    virtual css::awt::Rectangle implGetBounds() override;
 
+    //=====  XAccessibleComponent  
================================================
     virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
         getAccessibleAtPoint (
             const css::awt::Point& aPoint) override;
 
-    virtual css::awt::Rectangle SAL_CALL getBounds() override;
-
-    virtual css::awt::Point SAL_CALL getLocation() override;
-
-    virtual css::awt::Point SAL_CALL getLocationOnScreen() override;
-
-    virtual css::awt::Size SAL_CALL getSize() override;
-
     virtual void SAL_CALL grabFocus() override;
 
     virtual sal_Int32 SAL_CALL getForeground() override;
@@ -167,7 +138,6 @@ private:
     rtl::Reference<AccessibleSlideSorterView> mxParent;
     sal_uInt16 mnPageNumber;
     ::sd::slidesorter::SlideSorter& mrSlideSorter;
-    sal_uInt32 mnClientId;
 
     /** Check whether or not the object has been disposed (or is in the
         state of being disposed).  If that is the case then
@@ -177,14 +147,6 @@ private:
         @throws css::lang::DisposedException
     */
     void ThrowIfDisposed();
-
-    /** Check whether or not the object has been disposed (or is in the
-        state of being disposed).
-
-        @return sal_True, if the object is disposed or in the course
-        of being disposed. Otherwise, sal_False is returned.
-    */
-    bool IsDisposed() const;
 };
 
 } // end of namespace ::accessibility

Reply via email to