From 18982376918c88ec09c2c7fd42ef635e93897b05 Mon Sep 17 00:00:00 2001
From: Noel <noel.grandin@collabora.co.uk>
Date: Thu, 4 Feb 2021 10:22:58 +0200
Subject: use more getSdrObjectFromXShape

Change-Id: Ia237643ab040425f231f781c86e7e060f0b53717
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110400
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
---
 svx/source/accessibility/ShapeTypeHandler.cxx |  4 +--
 svx/source/unodraw/unopage.cxx                | 51 +++++++++++----------------
 svx/source/unodraw/unoshap2.cxx               | 18 ++++------
 svx/source/unodraw/unoshap3.cxx               | 11 ++----
 4 files changed, 33 insertions(+), 51 deletions(-)

(limited to 'svx/source')

diff --git a/svx/source/accessibility/ShapeTypeHandler.cxx b/svx/source/accessibility/ShapeTypeHandler.cxx
index 79aa5807f3a6..03ef0bf86bb6 100644
--- a/svx/source/accessibility/ShapeTypeHandler.cxx
+++ b/svx/source/accessibility/ShapeTypeHandler.cxx
@@ -268,9 +268,9 @@ OUString ShapeTypeHandler::CreateAccessibleBaseName (const uno::Reference<drawin
         case DRAWING_CUSTOM:
             pResourceId = STR_ObjNameSingulCUSTOMSHAPE;
 
-            if (SvxShape* pShape = comphelper::getUnoTunnelImplementation<SvxShape>(rxShape))
+            if (SdrObject* pSdrObject = SdrObject::getSdrObjectFromXShape(rxShape))
             {
-                if (auto pCustomShape = dynamic_cast<SdrObjCustomShape*>(pShape->GetSdrObject()))
+                if (auto pCustomShape = dynamic_cast<SdrObjCustomShape*>(pSdrObject))
                 {
                     if (pCustomShape->IsTextPath())
                         pResourceId = STR_ObjNameSingulFONTWORK;
diff --git a/svx/source/unodraw/unopage.cxx b/svx/source/unodraw/unopage.cxx
index d139fe2ab5c2..23fe9dabd1a6 100644
--- a/svx/source/unodraw/unopage.cxx
+++ b/svx/source/unodraw/unopage.cxx
@@ -288,40 +288,35 @@ void SAL_CALL SvxDrawPage::remove( const Reference< drawing::XShape >& xShape )
     if( (mpModel == nullptr) || (mpPage == nullptr) )
         throw lang::DisposedException();
 
-    SvxShape* pShape = comphelper::getUnoTunnelImplementation<SvxShape>( xShape );
+    SdrObject* pObj = SdrObject::getSdrObjectFromXShape( xShape );
+    if (!pObj)
+        return;
 
-    if (pShape)
+    // remove SdrObject from page
+    const size_t nCount = mpPage->GetObjCount();
+    for( size_t nNum = 0; nNum < nCount; ++nNum )
     {
-        SdrObject* pObj = pShape->GetSdrObject();
-        if (pObj)
+        if(mpPage->GetObj(nNum) == pObj)
         {
-            // remove SdrObject from page
-            const size_t nCount = mpPage->GetObjCount();
-            for( size_t nNum = 0; nNum < nCount; ++nNum )
-            {
-                if(mpPage->GetObj(nNum) == pObj)
-                {
-                    const bool bUndoEnabled = mpModel->IsUndoEnabled();
+            const bool bUndoEnabled = mpModel->IsUndoEnabled();
 
-                    if (bUndoEnabled)
-                    {
-                        mpModel->BegUndo(SvxResId(STR_EditDelete),
-                            pObj->TakeObjNameSingul(), SdrRepeatFunc::Delete);
+            if (bUndoEnabled)
+            {
+                mpModel->BegUndo(SvxResId(STR_EditDelete),
+                    pObj->TakeObjNameSingul(), SdrRepeatFunc::Delete);
 
-                        mpModel->AddUndo(mpModel->GetSdrUndoFactory().CreateUndoDeleteObject(*pObj));
-                    }
+                mpModel->AddUndo(mpModel->GetSdrUndoFactory().CreateUndoDeleteObject(*pObj));
+            }
 
-                    OSL_VERIFY( mpPage->RemoveObject( nNum ) == pObj );
+            OSL_VERIFY( mpPage->RemoveObject( nNum ) == pObj );
 
-                    if (!bUndoEnabled)
-                        SdrObject::Free(pObj);
+            if (!bUndoEnabled)
+                SdrObject::Free(pObj);
 
-                    if (bUndoEnabled)
-                        mpModel->EndUndo();
+            if (bUndoEnabled)
+                mpModel->EndUndo();
 
-                    break;
-                }
-            }
+            break;
         }
     }
 
@@ -386,11 +381,7 @@ namespace
 {
     void lcl_markSdrObjectOfShape( const Reference< drawing::XShape >& _rxShape, SdrView& _rView, SdrPageView& _rPageView )
     {
-        SvxShape* pShape = comphelper::getUnoTunnelImplementation<SvxShape>( _rxShape );
-        if ( !pShape )
-            return;
-
-        SdrObject* pObj = pShape->GetSdrObject();
+        SdrObject* pObj = SdrObject::getSdrObjectFromXShape( _rxShape );
         if ( !pObj )
             return;
 
diff --git a/svx/source/unodraw/unoshap2.cxx b/svx/source/unodraw/unoshap2.cxx
index 1ff2d3e03e9d..2c4487b4cec6 100644
--- a/svx/source/unodraw/unoshap2.cxx
+++ b/svx/source/unodraw/unoshap2.cxx
@@ -224,11 +224,7 @@ void SAL_CALL SvxShapeGroup::remove( const uno::Reference< drawing::XShape >& xS
 {
     ::SolarMutexGuard aGuard;
 
-    SdrObject* pSdrShape = nullptr;
-    SvxShape* pShape = comphelper::getUnoTunnelImplementation<SvxShape>( xShape );
-
-    if( pShape )
-        pSdrShape = pShape->GetSdrObject();
+    SdrObject* pSdrShape = SdrObject::getSdrObjectFromXShape( xShape );
 
     if( !HasSdrObject() || pSdrShape == nullptr || pSdrShape->getParentSdrObjectFromSdrObject() != GetSdrObject() )
         throw uno::RuntimeException();
@@ -414,10 +410,10 @@ void SAL_CALL SvxShapeConnector::connectStart( const uno::Reference< drawing::XC
     ::SolarMutexGuard aGuard;
 
     Reference< drawing::XShape > xRef( xShape, UNO_QUERY );
-    SvxShape* pShape = comphelper::getUnoTunnelImplementation<SvxShape>( xRef );
+    SdrObject* pSdrObject = SdrObject::getSdrObjectFromXShape( xRef );
 
-    if( pShape )
-        GetSdrObject()->ConnectToNode( true, pShape->GetSdrObject() );
+    if( pSdrObject )
+        GetSdrObject()->ConnectToNode( true, pSdrObject );
 
     GetSdrObject()->getSdrModelFromSdrObject().SetChanged();
 }
@@ -428,10 +424,10 @@ void SAL_CALL SvxShapeConnector::connectEnd( const uno::Reference< drawing::XCon
     ::SolarMutexGuard aGuard;
 
     Reference< drawing::XShape > xRef( xShape, UNO_QUERY );
-    SvxShape* pShape = comphelper::getUnoTunnelImplementation<SvxShape>( xRef );
+    SdrObject* pSdrObject = SdrObject::getSdrObjectFromXShape( xRef );
 
-    if( HasSdrObject() && pShape )
-        GetSdrObject()->ConnectToNode( false, pShape->GetSdrObject() );
+    if( HasSdrObject() && pSdrObject )
+        GetSdrObject()->ConnectToNode( false, pSdrObject );
 
     GetSdrObject()->getSdrModelFromSdrObject().SetChanged();
 }
diff --git a/svx/source/unodraw/unoshap3.cxx b/svx/source/unodraw/unoshap3.cxx
index c7d415e38975..f2f29c21fc36 100644
--- a/svx/source/unodraw/unoshap3.cxx
+++ b/svx/source/unodraw/unoshap3.cxx
@@ -136,17 +136,12 @@ void SAL_CALL Svx3DSceneObject::remove( const Reference< drawing::XShape >& xSha
 {
     SolarMutexGuard aGuard;
 
-    SvxShape* pShape = comphelper::getUnoTunnelImplementation<SvxShape>( xShape );
+    SdrObject* pSdrShape = SdrObject::getSdrObjectFromXShape( xShape );
 
-    if(!HasSdrObject() || pShape == nullptr)
+    if(!HasSdrObject() || !pSdrShape ||
+        pSdrShape->getParentSdrObjectFromSdrObject() != GetSdrObject())
         throw uno::RuntimeException();
 
-    SdrObject* pSdrShape = pShape->GetSdrObject();
-    if(pSdrShape == nullptr || pSdrShape->getParentSdrObjectFromSdrObject() != GetSdrObject())
-    {
-        throw uno::RuntimeException();
-    }
-
     SdrObjList& rList = *pSdrShape->getParentSdrObjListFromSdrObject();
 
     const size_t nObjCount = rList.GetObjCount();
-- 
cgit