include/svx/IAccessibleParent.hxx                 |    6 ++-
 sc/source/ui/Accessibility/AccessibleDocument.cxx |   42 ++++++++--------------
 svx/source/accessibility/ChildrenManagerImpl.cxx  |    7 ++-
 svx/source/accessibility/ChildrenManagerImpl.hxx  |    2 -
 sw/inc/accmap.hxx                                 |    2 -
 sw/source/core/access/accmap.cxx                  |    2 -
 6 files changed, 28 insertions(+), 33 deletions(-)

New commits:
commit a419343d759ff2f3dda850de6f12c251a8d102af
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Mon Apr 14 13:43:15 2025 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Apr 15 13:27:25 2025 +0200

    Avoid some casting in ScChildrenShapes
    
    Change-Id: Ic57ffd1d932f9613716b63902d5565f1f8f6ef0f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184145
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/include/svx/IAccessibleParent.hxx 
b/include/svx/IAccessibleParent.hxx
index 50530c0a0f85..8a5f5685c686 100644
--- a/include/svx/IAccessibleParent.hxx
+++ b/include/svx/IAccessibleParent.hxx
@@ -88,11 +88,13 @@ public:
     /// @throws css::uno::RuntimeException
     virtual AccessibleControlShape* GetAccControlShapeFromModel
         (css::beans::XPropertySet*){return nullptr;};
+
+    //Return a raw pointer here rather than a reference, so that subclasses 
can override and return a subtype pointer.
     /// @throws css::uno::RuntimeException
-    virtual  css::uno::Reference<
-            css::accessibility::XAccessible>
+    virtual css::accessibility::XAccessible*
         GetAccessibleCaption (const css::uno::Reference<
             css::drawing::XShape>&){return nullptr;};
+
     virtual bool IsDocumentSelAll(){ return false; }
 };
 
diff --git a/sc/source/ui/Accessibility/AccessibleDocument.cxx 
b/sc/source/ui/Accessibility/AccessibleDocument.cxx
index 740df71d777d..0764572bd251 100644
--- a/sc/source/ui/Accessibility/AccessibleDocument.cxx
+++ b/sc/source/ui/Accessibility/AccessibleDocument.cxx
@@ -220,7 +220,7 @@ public:
 
     virtual ::accessibility::AccessibleControlShape* 
GetAccControlShapeFromModel
         (css::beans::XPropertySet* pSet) override;
-    virtual css::uno::Reference< css::accessibility::XAccessible>
+    virtual ::accessibility::AccessibleShape*
         GetAccessibleCaption (const css::uno::Reference<css::drawing::XShape>& 
xShape) override;
     ///=====  Internal  
========================================================
     void SetDrawBroadcaster();
@@ -473,7 +473,7 @@ bool ScChildrenShapes::ReplaceChild 
(::accessibility::AccessibleShape* pCurrentC
     return nullptr;
 }
 
-css::uno::Reference < css::accessibility::XAccessible >
+::accessibility::AccessibleShape*
 ScChildrenShapes::GetAccessibleCaption (const css::uno::Reference < 
css::drawing::XShape>& xShape)
 {
     GetCount(); // populate
@@ -481,10 +481,7 @@ ScChildrenShapes::GetAccessibleCaption (const 
css::uno::Reference < css::drawing
     if (it == maShapesMap.end())
         return nullptr;
     ScAccessibleShapeData* pShape = it->second;
-    rtl::Reference< ::accessibility::AccessibleShape > xNewChild( 
pShape->pAccShape );
-    if(xNewChild)
-        return xNewChild;
-    return nullptr;
+    return pShape->pAccShape.get();
 }
 
 sal_Int32 ScChildrenShapes::GetCount() const
@@ -1033,30 +1030,25 @@ bool ScChildrenShapes::FindSelectedShapesChanges(const 
uno::Reference<drawing::X
             if( pMarkedObj == pFocusedObj && pUpObj )
             {
                 uno::Reference< drawing::XShape > xUpGroupXShape 
(pUpObj->getUnoShape(), uno::UNO_QUERY);
-                uno::Reference < XAccessible > xAccGroupShape =
+                ::accessibility::AccessibleShape* pAccGroupShape =
                     const_cast<ScChildrenShapes*>(this)->GetAccessibleCaption( 
xUpGroupXShape );
-                if( xAccGroupShape.is() )
+                if( pAccGroupShape )
                 {
-                    ::accessibility::AccessibleShape* pAccGroupShape =
-                        static_cast< ::accessibility::AccessibleShape* 
>(xAccGroupShape.get());
-                    if( pAccGroupShape )
+                    sal_Int64 nCount =  
pAccGroupShape->getAccessibleChildCount();
+                    for( sal_Int64 i = 0; i < nCount; i++ )
                     {
-                        sal_Int64 nCount =  
pAccGroupShape->getAccessibleChildCount();
-                        for( sal_Int64 i = 0; i < nCount; i++ )
+                        uno::Reference<XAccessible> xAccShape = 
pAccGroupShape->getAccessibleChild(i);
+                        if (xAccShape.is())
                         {
-                            uno::Reference<XAccessible> xAccShape = 
pAccGroupShape->getAccessibleChild(i);
-                            if (xAccShape.is())
+                            ::accessibility::AccessibleShape* pChildAccShape = 
 static_cast< ::accessibility::AccessibleShape* >(xAccShape.get());
+                            uno::Reference< drawing::XShape > xChildShape = 
pChildAccShape->GetXShape();
+                            if (xChildShape == xMarkedXShape)
+                            {
+                                
pChildAccShape->SetState(AccessibleStateType::FOCUSED);
+                            }
+                            else
                             {
-                                ::accessibility::AccessibleShape* 
pChildAccShape =  static_cast< ::accessibility::AccessibleShape* 
>(xAccShape.get());
-                                uno::Reference< drawing::XShape > xChildShape 
= pChildAccShape->GetXShape();
-                                if (xChildShape == xMarkedXShape)
-                                {
-                                    
pChildAccShape->SetState(AccessibleStateType::FOCUSED);
-                                }
-                                else
-                                {
-                                    
pChildAccShape->ResetState(AccessibleStateType::FOCUSED);
-                                }
+                                
pChildAccShape->ResetState(AccessibleStateType::FOCUSED);
                             }
                         }
                     }
diff --git a/svx/source/accessibility/ChildrenManagerImpl.cxx 
b/svx/source/accessibility/ChildrenManagerImpl.cxx
index 5d950014bff8..2bcad6d8332f 100644
--- a/svx/source/accessibility/ChildrenManagerImpl.cxx
+++ b/svx/source/accessibility/ChildrenManagerImpl.cxx
@@ -820,14 +820,15 @@ AccessibleControlShape * 
ChildrenManagerImpl::GetAccControlShapeFromModel(css::b
     }
     return nullptr;
 }
-uno::Reference<XAccessible>
+
+AccessibleShape*
     ChildrenManagerImpl::GetAccessibleCaption (const 
uno::Reference<drawing::XShape>& xShape)
 {
     auto I = std::find_if(maVisibleChildren.begin(), maVisibleChildren.end(),
         [&xShape](const ChildDescriptor& rChild) { return rChild.mxShape.get() 
== xShape.get(); });
     if (I != maVisibleChildren.end())
-        return I->mxAccessibleShape;
-    return uno::Reference<XAccessible> ();
+        return I->mxAccessibleShape.get();
+    return nullptr;
 }
 
 /** Update the <const>SELECTED</const> and the <const>FOCUSED</const> state
diff --git a/svx/source/accessibility/ChildrenManagerImpl.hxx 
b/svx/source/accessibility/ChildrenManagerImpl.hxx
index 121a893bfea2..fe4d21b6c5eb 100644
--- a/svx/source/accessibility/ChildrenManagerImpl.hxx
+++ b/svx/source/accessibility/ChildrenManagerImpl.hxx
@@ -261,7 +261,7 @@ public:
     // Add the impl method for IAccessibleParent interface
     virtual AccessibleControlShape* GetAccControlShapeFromModel
         (css::beans::XPropertySet* pSet) override;
-    virtual css::uno::Reference<css::accessibility::XAccessible>
+    virtual AccessibleShape*
         GetAccessibleCaption (const css::uno::Reference<css::drawing::XShape>& 
xShape) override;
 
 private:
diff --git a/sw/inc/accmap.hxx b/sw/inc/accmap.hxx
index e782acc2ba2b..886899c08faf 100644
--- a/sw/inc/accmap.hxx
+++ b/sw/inc/accmap.hxx
@@ -271,7 +271,7 @@ public:
     ) override;
     virtual ::accessibility::AccessibleControlShape* 
GetAccControlShapeFromModel
         (css::beans::XPropertySet* pSet) override;
-    virtual css::uno::Reference< css::accessibility::XAccessible >   
GetAccessibleCaption (
+    virtual css::accessibility::XAccessible*   GetAccessibleCaption (
         const css::uno::Reference< css::drawing::XShape > & xShape) override;
 
     // additional Core/Pixel conversions for internal use; also works
diff --git a/sw/source/core/access/accmap.cxx b/sw/source/core/access/accmap.cxx
index 75e11394f5a5..9d6de6ca9fc0 100644
--- a/sw/source/core/access/accmap.cxx
+++ b/sw/source/core/access/accmap.cxx
@@ -3010,7 +3010,7 @@ bool SwAccessibleMap::ReplaceChild (
     return nullptr;
 }
 
-css::uno::Reference< XAccessible >
+XAccessible*
     SwAccessibleMap::GetAccessibleCaption (const css::uno::Reference< 
css::drawing::XShape >&)
 {
     return nullptr;

Reply via email to