Require window pointer for default wxGtkImage BitmapProvider

Originally a NULL window pointer indicated that a disabled bitmap
was not needed, but now the pointer is always needed for scaling.
This commit is contained in:
Paul Cornett 2022-03-19 14:32:15 -07:00
parent f6c1230f71
commit 28ca585d12
3 changed files with 6 additions and 26 deletions

View file

@ -5,9 +5,6 @@
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#include "wx/bmpbndl.h"
#include "wx/math.h"
// Class that can be used in place of GtkImage, to allow drawing of alternate
// bitmaps, such as HiDPI or disabled.
@ -32,7 +29,7 @@ public:
static GType Type();
static GtkWidget* New(BitmapProvider* provider);
static GtkWidget* New(wxWindow* win = NULL);
static GtkWidget* New(wxWindow* win);
// Use bitmaps from the given bundle, the logical bitmap size is the
// default size of the bundle.

View file

@ -7,14 +7,13 @@
#include "wx/wxprec.h"
#include "wx/bmpbndl.h"
#include "wx/log.h"
#include "wx/window.h"
#include "wx/gtk/private/wrapgtk.h"
#include "wx/gtk/private/image.h"
GdkWindow* wxGetTopLevelGDK();
namespace
{
@ -29,8 +28,6 @@ struct BitmapProviderDefault: wxGtkImage::BitmapProvider
virtual wxBitmap Get() const wxOVERRIDE;
virtual void Set(const wxBitmapBundle& bitmap) wxOVERRIDE;
// This pointer can be null if there is no associated window.
wxWindow* const m_win;
// All the bitmaps we use.
@ -43,26 +40,12 @@ struct BitmapProviderDefault: wxGtkImage::BitmapProvider
double BitmapProviderDefault::GetScale() const
{
if ( m_win )
{
return m_win->GetDPIScaleFactor();
}
// We expect to always have a window by the time this function is called,
// so while we try to do something reasonable even if we don't have it,
// at least log it because this is not expected to happen.
wxLogDebug("No window in wxGtkImage, using main window scale.");
#if GTK_CHECK_VERSION(3,10,0)
return gdk_window_get_scale_factor(wxGetTopLevelGDK());
#else
return 1.0;
#endif
return m_win->GetDPIScaleFactor();
}
wxBitmap BitmapProviderDefault::Get() const
{
if ( m_win && !m_win->IsEnabled() )
if (!m_win->IsEnabled())
{
if ( !m_bitmapDisabled.IsOk() && m_bitmapBundle.IsOk() )
m_bitmapDisabled = GetAtScale(m_bitmapBundle).CreateDisabled();

View file

@ -288,7 +288,7 @@ bool wxNotebook::SetPageImage( size_t page, int image )
{
if (pageData->m_image == NULL)
{
pageData->m_image = wxGtkImage::New();
pageData->m_image = wxGtkImage::New(this);
gtk_widget_show(pageData->m_image);
gtk_box_pack_start(GTK_BOX(pageData->m_box),
pageData->m_image, false, false, m_padding);
@ -484,7 +484,7 @@ bool wxNotebook::InsertPage( size_t position,
const wxBitmapBundle bundle = GetBitmapBundle(imageId);
if ( bundle.IsOk() )
{
pageData->m_image = wxGtkImage::New();
pageData->m_image = wxGtkImage::New(this);
WX_GTK_IMAGE(pageData->m_image)->Set(bundle);
gtk_box_pack_start(GTK_BOX(pageData->m_box),
pageData->m_image, false, false, m_padding);