diff options
author | Caolán McNamara <caolanm@redhat.com> | 2021-11-05 10:41:57 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2021-11-05 12:35:06 +0100 |
commit | b6c3adf356ca5f7b6f3d80e6062b58c92e6e2a11 (patch) | |
tree | e1de3d93e2225eac078bb236be6af38d290d6cab /vcl/unx | |
parent | 9cfa15e06ed6d6c5c555fa5623c0d962bceee30e (diff) |
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 <caolanm@redhat.com>
Diffstat (limited to 'vcl/unx')
-rw-r--r-- | vcl/unx/gtk3/gtkinst.cxx | 35 |
1 files changed, 22 insertions, 13 deletions
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) |