summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2021-11-05 10:33:45 +0000
committerCaolán McNamara <caolanm@redhat.com>2021-11-05 12:34:48 +0100
commit9cfa15e06ed6d6c5c555fa5623c0d962bceee30e (patch)
tree40f409f785d20950f2ad86aca5393d7dadaae778 /vcl
parent85676ff5ba14832f10613aa74528f402d65974e4 (diff)
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 <caolanm@redhat.com> Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/unx/gtk3/gtkinst.cxx22
1 files changed, 22 insertions, 0 deletions
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)