svx/source/sdr/contact/objectcontactofpageview.cxx |   31 ++++++++++++++++-----
 1 file changed, 25 insertions(+), 6 deletions(-)

New commits:
commit 2dde0bf99ed11feb32d361303bb15fbd6d33ec0e
Author:     Armin Le Grand (allotropia) <armin.le.grand.ext...@allotropia.de>
AuthorDate: Wed Jul 5 16:02:26 2023 +0200
Commit:     Armin Le Grand <armin.le.gr...@me.com>
CommitDate: Thu Jul 6 15:21:15 2023 +0200

    tdf#122735 get the correct ActiveViewContact
    
    In ObjectContactOfPageView::getActiveViewContact() the decision
    which ViewContact is to be returned depends on if the SdrObjList
    fetched from the SdrPageView is a SdrObject or a SdrPage.
    
    Both are derived from SdrObjList, so to decide that the helpers
    getSdrObjectFromSdrObjList and getSdrPageFromSdrObjList are
    used.
    
    For SdrObject the 1st will return ptr, 2nd nullptr. For SdrPage
    the 1st and 2nd will return ptr due to 1st trying to return
    something useful by getting up the hierarchy and return the
    SdrPage the SdrObjList/SdrObject is inserted (as the name says).
    
    This means that here the test for SdrObject *has* to be used 1st
    to correctly decide of what nature SdrObjList is.
    
    NOTE: Here it would also be possible to use dynamic_cast(s) to
    the classes to test for, but tooling is virtual/faster.
    
    Change-Id: I113afceddd3210aa63960d248f7c7356f82cf413
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154065
    Tested-by: Jenkins
    Reviewed-by: Armin Le Grand <armin.le.gr...@me.com>

diff --git a/svx/source/sdr/contact/objectcontactofpageview.cxx 
b/svx/source/sdr/contact/objectcontactofpageview.cxx
index ce0ca6463370..e07cf01bb86c 100644
--- a/svx/source/sdr/contact/objectcontactofpageview.cxx
+++ b/svx/source/sdr/contact/objectcontactofpageview.cxx
@@ -303,15 +303,34 @@ namespace sdr::contact
 
             if(pActiveGroupList)
             {
-                if(nullptr != pActiveGroupList->getSdrPageFromSdrObjList())
+                // tdf#122735
+                // Here it is necessary to check for SdrObject 1st, that may
+                // return nullptr if it is not a SdrObject/SdrObjGroup.
+                // Checking for SrPage OTOH will *always* try to return
+                // something useful due to 
SdrObjGroup::getSdrPageFromSdrObjList
+                // using getSdrPageFromSdrObject which will recursively go up 
the
+                // hierarchy to get the SdrPage the SdrObject belongs to, so
+                // this will *not* be nullptr for e.g. a SdrObjGroup if the
+                // SdrObjGroup is inserted to a SdrPage.
+                // NOTE: It is also possible to use dynamic_cast<SdrObjGroup*>
+                //       here, but getSdrObjectFromSdrObjList and
+                //       getSdrPageFromSdrObjListexist  to not need to do that
+                SdrObject* 
pSdrObject(pActiveGroupList->getSdrObjectFromSdrObjList());
+
+                if(nullptr != pSdrObject)
                 {
-                    // It's a Page itself
-                    return 
&(pActiveGroupList->getSdrPageFromSdrObjList()->GetViewContact());
+                    // It is a group object
+                    return &(pSdrObject->GetViewContact());
                 }
-                else if(pActiveGroupList->getSdrObjectFromSdrObjList())
+                else
                 {
-                    // Group object
-                    return 
&(pActiveGroupList->getSdrObjectFromSdrObjList()->GetViewContact());
+                    SdrPage* 
pSdrPage(pActiveGroupList->getSdrPageFromSdrObjList());
+
+                    if(nullptr != pSdrPage)
+                    {
+                        // It's a Page itself
+                        return &(pSdrPage->GetViewContact());
+                    }
                 }
             }
             else if(GetSdrPage())

Reply via email to