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().
This commit is contained in:
Vadim Zeitlin
2021-10-21 18:26:29 +01:00
parent b403624f22
commit eba93fb5e7
2 changed files with 9 additions and 8 deletions

View File

@@ -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;

View File

@@ -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;
}