From 525296aec519a38ddbc942c9de34320d30c2c46d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 7 Jan 2016 18:43:01 +0100 Subject: [PATCH] Preserve the button attributes when setting its bitmap in wxGTK The button label font and colour could be lost when its bitmap was set because this could result in the recreation of the GtkLabel, internally. Fix this by reapplying the styles to the possibly recreated label when changing the bitmap or its position in the button. --- src/gtk/anybutton.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/gtk/anybutton.cpp b/src/gtk/anybutton.cpp index 8088bab14b..16e7b4a22d 100644 --- a/src/gtk/anybutton.cpp +++ b/src/gtk/anybutton.cpp @@ -230,6 +230,11 @@ void wxAnyButton::DoSetBitmap(const wxBitmap& bitmap, State which) { image = gtk_image_new(); gtk_button_set_image(GTK_BUTTON(m_widget), image); + + // Setting the image recreates the label, so we need to + // reapply the styles to it to preserve the existing text + // font and colour if they're different from defaults. + GTKApplyWidgetStyle(); } else // image presence or absence didn't change { @@ -411,6 +416,11 @@ void wxAnyButton::DoSetBitmapPosition(wxDirection dir) } gtk_button_set_image_position(GTK_BUTTON(m_widget), gtkpos); + + // As in DoSetBitmap() above, the above call can invalidate the label + // style, so reapply it to preserve its font and colour. + GTKApplyWidgetStyle(); + InvalidateBestSize(); } #endif // GTK+ 2.10+