From eba93fb5e7ede9cc792fa337626ef773747e491f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 21 Oct 2021 18:26:29 +0100 Subject: [PATCH] Fix setting size of wxGenericStaticBitmap We must call SetInitialSize() in Create() in order to take the size argument passed to ctor/Create() into account -- it was completely ignored previously. But calling SetBitmap() must not change the initial size, as it can also be done later, so just change the current size there instead (which is consistent with wxMSW version and original behaviour, so keep it like this, even though it's not totally clear if all ports do it). Remove the now unused wxGenericStaticBitmap::GetBitmapSize(). --- include/wx/generic/statbmpg.h | 9 ++------- src/generic/statbmpg.cpp | 8 +++++++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/wx/generic/statbmpg.h b/include/wx/generic/statbmpg.h index bb49ba93bc..0ca3ff2e44 100644 --- a/include/wx/generic/statbmpg.h +++ b/include/wx/generic/statbmpg.h @@ -38,7 +38,8 @@ public: virtual void SetBitmap(const wxBitmap& bitmap) wxOVERRIDE { m_bitmap = bitmap; - SetInitialSize(GetBitmapSize()); + InvalidateBestSize(); + SetSize(GetBestSize()); Refresh(); } @@ -53,12 +54,6 @@ public: virtual ScaleMode GetScaleMode() const wxOVERRIDE { return m_scaleMode; } private: - wxSize GetBitmapSize() - { - return m_bitmap.IsOk() ? m_bitmap.GetScaledSize() - : wxSize(16, 16); // this is completely arbitrary - } - void OnPaint(wxPaintEvent& event); wxBitmap m_bitmap; diff --git a/src/generic/statbmpg.cpp b/src/generic/statbmpg.cpp index 26404a5529..115796b357 100644 --- a/src/generic/statbmpg.cpp +++ b/src/generic/statbmpg.cpp @@ -34,7 +34,13 @@ bool wxGenericStaticBitmap::Create(wxWindow *parent, wxWindowID id, wxDefaultValidator, name)) return false; m_scaleMode = Scale_None; - SetBitmap(bitmap); + + // Don't call SetBitmap() here, as it changes the size and refreshes the + // window unnecessarily, when we don't need either of these side effects + // here. + m_bitmap = bitmap; + SetInitialSize(size); + Bind(wxEVT_PAINT, &wxGenericStaticBitmap::OnPaint, this); return true; }