From 8c99df373ad62501bca85ffe0146172bdfe75f51 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Tue, 30 Oct 2018 22:59:07 -0700 Subject: [PATCH] Fix handling of scaled bitmaps in wxToolBar with GTK+3 We have to draw them ourselves to get the size right. See #18225 --- src/gtk/toolbar.cpp | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/gtk/toolbar.cpp b/src/gtk/toolbar.cpp index d857972eff..b700308c87 100644 --- a/src/gtk/toolbar.cpp +++ b/src/gtk/toolbar.cpp @@ -180,15 +180,20 @@ image_draw(GtkWidget* widget, cairo_t* cr, wxToolBarTool* tool) image_expose_event(GtkWidget* widget, GdkEventExpose*, wxToolBarTool* tool) #endif { +#ifdef __WXGTK3__ + const wxBitmap& bitmap = tool->GetBitmap(); + if (!bitmap.IsOk() || (tool->IsEnabled() && bitmap.GetScaleFactor() <= 1)) + return false; +#else const wxBitmap& bitmap = tool->GetDisabledBitmap(); if (tool->IsEnabled() || !bitmap.IsOk()) return false; +#endif - // draw disabled bitmap ourselves, GtkImage has no way to specify it GtkAllocation alloc; gtk_widget_get_allocation(widget, &alloc); - int x = (alloc.width - bitmap.GetWidth()) / 2; - int y = (alloc.height - bitmap.GetHeight()) / 2; + int x = (alloc.width - bitmap.GetScaledWidth()) / 2; + int y = (alloc.height - bitmap.GetScaledHeight()) / 2; #ifdef __WXGTK3__ bitmap.Draw(cr, x, y); #else @@ -266,9 +271,24 @@ void wxToolBarTool::SetImage() wxCHECK_RET(bitmap.IsOk(), "invalid bitmap for wxToolBar icon"); GtkWidget* image = gtk_tool_button_get_icon_widget(GTK_TOOL_BUTTON(m_item)); - // always use pixbuf, because pixmap mask does not - // work with disabled images in some themes - gtk_image_set_from_pixbuf(GTK_IMAGE(image), bitmap.GetPixbuf()); +#ifdef __WXGTK3__ + if (bitmap.GetScaleFactor() > 1) + { + // Use a scaled pixbuf with the correct logical size. It will be used + // for the disabled state if no disabled bitmap is specifed, otherwise + // the original will be used by our "draw" signal handler. + GdkPixbuf* pixbuf = gdk_pixbuf_scale_simple(bitmap.GetPixbuf(), + bitmap.GetScaledWidth(), bitmap.GetScaledHeight(), GDK_INTERP_BILINEAR); + gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); + g_object_unref(pixbuf); + } + else +#endif + { + // always use pixbuf, because pixmap mask does not + // work with disabled images in some themes + gtk_image_set_from_pixbuf(GTK_IMAGE(image), bitmap.GetPixbuf()); + } } // helper to create a dropdown menu item