include/vcl/weld.hxx           |    3 +-
 sw/source/ui/fldui/flddb.cxx   |    5 ---
 vcl/inc/salvtables.hxx         |    2 -
 vcl/source/app/salvtables.cxx  |   15 ++++-------
 vcl/source/window/printdlg.cxx |    2 -
 vcl/unx/gtk3/gtkinst.cxx       |   54 +++++++++++++++++++++--------------------
 6 files changed, 36 insertions(+), 45 deletions(-)

New commits:
commit c391dddb4e6ba514a85e7a2e498db1c7b1d300b2
Author:     Caolán McNamara <[email protected]>
AuthorDate: Wed Mar 9 12:42:52 2022 +0000
Commit:     Caolán McNamara <[email protected]>
CommitDate: Wed Mar 9 21:15:18 2022 +0100

    gtk4: remove set_accessible_relation_label_for
    
    and merge the contents of the old set_accessible_relation_labeled_by
    into that so there's only the need to have one call.
    
    Change-Id: I1c109fddd59219c4364103bf00d4d5b140bbdeab
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131253
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <[email protected]>

diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index 1b2ebb5f819d..5d3842a5247a 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -209,8 +209,9 @@ public:
 
     virtual OUString get_accessible_description() const = 0;
 
+    // After this call this widget is only accessiblity labelled by pLabel and
+    // pLabel only accessiblity labels this widget
     virtual void set_accessible_relation_labeled_by(weld::Widget* pLabel) = 0;
-    virtual void set_accessible_relation_label_for(weld::Widget* pLabeled) = 0;
 
     virtual void set_tooltip_text(const OUString& rTip) = 0;
     virtual OUString get_tooltip_text() const = 0;
diff --git a/sw/source/ui/fldui/flddb.cxx b/sw/source/ui/fldui/flddb.cxx
index d59da9aabf63..a792c1e1afed 100644
--- a/sw/source/ui/fldui/flddb.cxx
+++ b/sw/source/ui/fldui/flddb.cxx
@@ -330,9 +330,7 @@ void SwFieldDBPage::TypeHdl(const weld::TreeView* pBox)
             m_xFormatLB->hide();
 
             weld::Widget& rWidget = m_xNumFormatLB->get_widget();
-            m_xNewFormatRB->set_accessible_relation_label_for(&rWidget);
             rWidget.set_accessible_relation_labeled_by(m_xNewFormatRB.get());
-            m_xFormatLB->set_accessible_relation_label_for(nullptr);
 
             if (pBox)   // type was changed by user
                 m_xDBFormatRB->set_active(true);
@@ -371,10 +369,7 @@ void SwFieldDBPage::TypeHdl(const weld::TreeView* pBox)
             m_xNumFormatLB->hide();
             m_xFormatLB->show();
 
-            
m_xNewFormatRB->set_accessible_relation_label_for(m_xFormatLB.get());
             
m_xFormatLB->set_accessible_relation_labeled_by(m_xNewFormatRB.get());
-            weld::Widget& rWidget = m_xNumFormatLB->get_widget();
-            rWidget.set_accessible_relation_label_for(nullptr);
 
             if( IsFieldEdit() )
             {
diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx
index b4822d7c60e8..5f8ceb6b9ae3 100644
--- a/vcl/inc/salvtables.hxx
+++ b/vcl/inc/salvtables.hxx
@@ -298,8 +298,6 @@ public:
 
     virtual void set_accessible_relation_labeled_by(weld::Widget* pLabel) 
override;
 
-    virtual void set_accessible_relation_label_for(weld::Widget* pLabeled) 
override;
-
     virtual void set_tooltip_text(const OUString& rTip) override;
 
     virtual OUString get_tooltip_text() const override;
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index c320b43c8592..c21d66a15d0a 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -408,16 +408,13 @@ OUString SalInstanceWidget::get_accessible_description() 
const
 
 void SalInstanceWidget::set_accessible_relation_labeled_by(weld::Widget* 
pLabel)
 {
-    vcl::Window* pAtkLabel
+    if (vcl::Window* pOldLabel = m_xWidget->GetAccessibleRelationLabeledBy())
+        pOldLabel->SetAccessibleRelationLabelFor(nullptr);
+    vcl::Window* pA11yLabel
         = pLabel ? dynamic_cast<SalInstanceWidget&>(*pLabel).getWidget() : 
nullptr;
-    m_xWidget->SetAccessibleRelationLabeledBy(pAtkLabel);
-}
-
-void SalInstanceWidget::set_accessible_relation_label_for(weld::Widget* 
pLabeled)
-{
-    vcl::Window* pAtkLabeled
-        = pLabeled ? dynamic_cast<SalInstanceWidget&>(*pLabeled).getWidget() : 
nullptr;
-    m_xWidget->SetAccessibleRelationLabelFor(pAtkLabeled);
+    m_xWidget->SetAccessibleRelationLabeledBy(pA11yLabel);
+    if (pA11yLabel)
+        pA11yLabel->SetAccessibleRelationLabelFor(m_xWidget);
 }
 
 void SalInstanceWidget::set_tooltip_text(const OUString& rTip)
diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx
index bb89ebbd5e9b..bce9870d41bc 100644
--- a/vcl/source/window/printdlg.cxx
+++ b/vcl/source/window/printdlg.cxx
@@ -1687,9 +1687,7 @@ void PrintDialog::setupOptionalUI()
         mxPagesBoxTitleTxt->show();
         mxPagesBtn->hide();
 
-        
mxPagesBoxTitleTxt->set_accessible_relation_label_for(mxNupPagesBox.get());
         
mxNupPagesBox->set_accessible_relation_labeled_by(mxPagesBoxTitleTxt.get());
-        mxPagesBtn->set_accessible_relation_label_for(nullptr);
     }
 
     // update enable states
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index 499b45c47d03..a16c6cc7f75f 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -3784,39 +3784,41 @@ public:
         AtkRelationSet *pRelationSet = atk_object_ref_relation_set(pAtkObject);
         AtkRelation *pRelation = 
atk_relation_set_get_relation_by_type(pRelationSet, ATK_RELATION_LABELLED_BY);
         if (pRelation)
-            atk_relation_set_remove(pRelationSet, pRelation);
-        if (pAtkLabel)
         {
-            AtkObject *obj_array[1];
-            obj_array[0] = pAtkLabel;
-            pRelation = atk_relation_new(obj_array, 1, 
ATK_RELATION_LABELLED_BY);
-            atk_relation_set_add(pRelationSet, pRelation);
+            // clear ATK_RELATION_LABEL_FOR from old label
+            GPtrArray* pOldLabelTarget = atk_relation_get_target(pRelation);
+            guint nElements = pOldLabelTarget ? pOldLabelTarget->len : 0;
+            for (guint i = 0; i < nElements; ++i)
+            {
+                gpointer pOldLabelObject = g_ptr_array_index(pOldLabelTarget, 
i);
+                AtkRelationSet *pOldLabelRelationSet = 
atk_object_ref_relation_set(ATK_OBJECT(pOldLabelObject));
+                if (AtkRelation *pOldLabelRelation = 
atk_relation_set_get_relation_by_type(pRelationSet, ATK_RELATION_LABEL_FOR))
+                    atk_relation_set_remove(pOldLabelRelationSet, 
pOldLabelRelation);
+                g_object_unref(pOldLabelRelationSet);
+            }
+            atk_relation_set_remove(pRelationSet, pRelation);
         }
-        g_object_unref(pRelationSet);
-#endif
-    }
 
-    virtual void set_accessible_relation_label_for(weld::Widget* pLabeled) 
override
-    {
-#if !GTK_CHECK_VERSION(4, 0, 0)
-        AtkObject* pAtkObject = gtk_widget_get_accessible(m_pWidget);
-        if (!pAtkObject)
-            return;
-        AtkObject *pAtkLabeled = pLabeled ? 
gtk_widget_get_accessible(dynamic_cast<GtkInstanceWidget&>(*pLabeled).getWidget())
 : nullptr;
-        AtkRelationSet *pRelationSet = atk_object_ref_relation_set(pAtkObject);
-        AtkRelation *pRelation = 
atk_relation_set_get_relation_by_type(pRelationSet, ATK_RELATION_LABEL_FOR);
-        if (pRelation)
-            atk_relation_set_remove(pRelationSet, pRelation);
-        if (pAtkLabeled)
+        if (pAtkLabel)
         {
-            AtkObject *obj_array[1];
-            obj_array[0] = pAtkLabeled;
-            pRelation = atk_relation_new(obj_array, 1, ATK_RELATION_LABEL_FOR);
+            AtkObject *obj_array_labelled_by[1];
+            obj_array_labelled_by[0] = pAtkLabel;
+            pRelation = atk_relation_new(obj_array_labelled_by, 1, 
ATK_RELATION_LABELLED_BY);
             atk_relation_set_add(pRelationSet, pRelation);
+
+            // add ATK_RELATION_LABEL_FOR to new label to match
+            AtkRelationSet *pNewLabelRelationSet = 
atk_object_ref_relation_set(pAtkLabel);
+            AtkRelation *pNewLabelRelation = 
atk_relation_set_get_relation_by_type(pNewLabelRelationSet, 
ATK_RELATION_LABEL_FOR);
+            if (pNewLabelRelation)
+                atk_relation_set_remove(pNewLabelRelationSet, pRelation);
+            AtkObject *obj_array_label_for[1];
+            obj_array_label_for[0] = pAtkObject;
+            pNewLabelRelation = atk_relation_new(obj_array_label_for, 1, 
ATK_RELATION_LABEL_FOR);
+            atk_relation_set_add(pNewLabelRelationSet, pNewLabelRelation);
+            g_object_unref(pNewLabelRelationSet);
         }
+
         g_object_unref(pRelationSet);
-#else
-        (void)pLabeled;
 #endif
     }
 

Reply via email to