vcl/unx/gtk3/gtkinst.cxx |   31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

New commits:
commit b6c3adf356ca5f7b6f3d80e6062b58c92e6e2a11
Author:     Caolán McNamara <[email protected]>
AuthorDate: Fri Nov 5 10:41:57 2021 +0000
Commit:     Caolán McNamara <[email protected]>
CommitDate: Fri Nov 5 12:35:06 2021 +0100

    gtk4: return existing label widget text on querying button label text
    
    Change-Id: Ic8a544eae09c80b172340b4c3abe00244fe7a711
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124738
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <[email protected]>

diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index a5a1e37ce93a..a0678b789283 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -4494,15 +4494,9 @@ namespace
         gtk_label_set_label(pLabel, MapToGtkAccelerator(rText).getStr());
     }
 
-    OUString get_button_label(GtkButton* pButton)
-    {
-        const gchar* pStr = gtk_button_get_label(pButton);
-        return OUString(pStr, pStr ? strlen(pStr) : 0, RTL_TEXTENCODING_UTF8);
-    }
-
-    void set_button_label(GtkButton* pButton, const OUString& rText)
-    {
 #if GTK_CHECK_VERSION(4, 0, 0)
+    GtkLabel* get_button_label_widget(GtkButton* pButton)
+    {
         GtkWidget* pChild = gtk_button_get_child(pButton);
         GtkLabel* pLabel = GTK_IS_LABEL(pChild) ? GTK_LABEL(pChild) : nullptr;
         if (!pLabel && pChild)
@@ -4515,16 +4509,31 @@ namespace
                     break;
             }
         }
-        if (pLabel)
+        return pLabel;
+    }
+#endif
+
+    OUString get_button_label(GtkButton* pButton)
+    {
+#if GTK_CHECK_VERSION(4, 0, 0)
+        if (GtkLabel* pLabel = get_button_label_widget(pButton))
+            return ::get_label(pLabel);
+#endif
+        const gchar* pStr = gtk_button_get_label(pButton);
+        return OUString(pStr, pStr ? strlen(pStr) : 0, RTL_TEXTENCODING_UTF8);
+    }
+
+    void set_button_label(GtkButton* pButton, const OUString& rText)
+    {
+#if GTK_CHECK_VERSION(4, 0, 0)
+        if (GtkLabel* pLabel = get_button_label_widget(pButton))
         {
             ::set_label(pLabel, rText);
             gtk_widget_set_visible(GTK_WIDGET(pLabel), true);
+            return;
         }
-        else
-            gtk_button_set_label(pButton, MapToGtkAccelerator(rText).getStr());
-#else
-        gtk_button_set_label(pButton, MapToGtkAccelerator(rText).getStr());
 #endif
+        gtk_button_set_label(pButton, MapToGtkAccelerator(rText).getStr());
     }
 
 #if GTK_CHECK_VERSION(4, 0, 0)
commit 9cfa15e06ed6d6c5c555fa5623c0d962bceee30e
Author:     Caolán McNamara <[email protected]>
AuthorDate: Fri Nov 5 10:33:45 2021 +0000
Commit:     Caolán McNamara <[email protected]>
CommitDate: Fri Nov 5 12:34:48 2021 +0100

    gtk4: update an existing label on changing button label text
    
    instead of throwing away all contents and replacing with a label e.g.
    for color selector keep the optional image in "automatic"/"no fill"
    
    Change-Id: Ifb29f83d5a5b95c91050c28f1d5bedaafba42d83
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124737
    Tested-by: Caolán McNamara <[email protected]>
    Reviewed-by: Caolán McNamara <[email protected]>

diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index 8d7bc7077a28..a5a1e37ce93a 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -4502,7 +4502,29 @@ namespace
 
     void set_button_label(GtkButton* pButton, const OUString& rText)
     {
+#if GTK_CHECK_VERSION(4, 0, 0)
+        GtkWidget* pChild = gtk_button_get_child(pButton);
+        GtkLabel* pLabel = GTK_IS_LABEL(pChild) ? GTK_LABEL(pChild) : nullptr;
+        if (!pLabel && pChild)
+        {
+            for (GtkWidget* pBoxChild = gtk_widget_get_first_child(pChild);
+                 pBoxChild; pBoxChild = gtk_widget_get_next_sibling(pBoxChild))
+            {
+                pLabel = GTK_IS_LABEL(pBoxChild) ? GTK_LABEL(pBoxChild) : 
nullptr;
+                if (pLabel)
+                    break;
+            }
+        }
+        if (pLabel)
+        {
+            ::set_label(pLabel, rText);
+            gtk_widget_set_visible(GTK_WIDGET(pLabel), true);
+        }
+        else
+            gtk_button_set_label(pButton, MapToGtkAccelerator(rText).getStr());
+#else
         gtk_button_set_label(pButton, MapToGtkAccelerator(rText).getStr());
+#endif
     }
 
 #if GTK_CHECK_VERSION(4, 0, 0)

Reply via email to