From 10b7659acd06e7f2fb2f63b8dd975601cb4e5b86 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 17 Oct 2021 00:56:22 +0200 Subject: [PATCH 1/2] Ensure all buttons with images have associated wxGtkImage Replace GtkImage with wxGtkImage if necessary, to ensure that we can always use our own class, to profit from its support for high DPI images, even for the buttons using stock IDs and so creating GtkImage by default. See #19288. --- src/gtk/anybutton.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/gtk/anybutton.cpp b/src/gtk/anybutton.cpp index 95c32aeabc..cbf60116c7 100644 --- a/src/gtk/anybutton.cpp +++ b/src/gtk/anybutton.cpp @@ -190,12 +190,9 @@ void wxAnyButton::GTKDoShowBitmap(const wxBitmap& bitmap) if (image == NULL) image = gtk_bin_get_child(GTK_BIN(m_widget)); - wxCHECK_RET(GTK_IS_IMAGE(image), "must have image widget"); + wxCHECK_RET(WX_GTK_IS_IMAGE(image), "must have image widget"); - if (WX_GTK_IS_IMAGE(image)) - WX_GTK_IMAGE(image)->Set(bitmap); - else - gtk_image_set_from_pixbuf(GTK_IMAGE(image), bitmap.GetPixbuf()); + WX_GTK_IMAGE(image)->Set(bitmap); } wxBitmap wxAnyButton::DoGetBitmap(State which) const @@ -220,6 +217,14 @@ void wxAnyButton::DoSetBitmap(const wxBitmap& bitmap, State which) else { GtkWidget *image = gtk_button_get_image(GTK_BUTTON(m_widget)); + if ( image && !WX_GTK_IS_IMAGE(image) ) + { + // This must be the GtkImage created for stock buttons, we + // want to replace it with our own wxGtkImage as only it + // handles showing appropriately-sized bitmaps in high DPI. + image = NULL; + } + if ( image && !bitmap.IsOk() ) { gtk_container_remove(GTK_CONTAINER(m_widget), image); From 4e366b2cfb133cf6850460e04e1c75a35df8f128 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 17 Oct 2021 23:25:45 +0200 Subject: [PATCH 2/2] Remove unused code in wxGTK wxAnyButton The GtkImage can always be retrieved using the appropriate GTK function, there is no need to get the button child directly any longer. --- src/gtk/anybutton.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/gtk/anybutton.cpp b/src/gtk/anybutton.cpp index cbf60116c7..878946c4c8 100644 --- a/src/gtk/anybutton.cpp +++ b/src/gtk/anybutton.cpp @@ -186,10 +186,7 @@ void wxAnyButton::GTKDoShowBitmap(const wxBitmap& bitmap) { wxCHECK_RET(bitmap.IsOk(), "invalid bitmap"); - GtkWidget* image = gtk_button_get_image(GTK_BUTTON(m_widget)); - if (image == NULL) - image = gtk_bin_get_child(GTK_BIN(m_widget)); - + GtkWidget* const image = gtk_button_get_image(GTK_BUTTON(m_widget)); wxCHECK_RET(WX_GTK_IS_IMAGE(image), "must have image widget"); WX_GTK_IMAGE(image)->Set(bitmap);