From 05942059ef5ba8ebb6c7829776796a5be4e61262 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 9 Feb 2013 00:35:54 +0000 Subject: [PATCH] Refresh wxMSW wxStaticBitmap when its size changes. As MSW native control centers the image, it must be entirely redrawn when the area in which the image is centered changes, but it doesn't happen by default, so do it ourselves explicitly. Also explain that this centering behaviour is platform-specific and shouldn't be relied upon. Closes #4564. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73485 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/statbmp.h | 2 ++ interface/wx/statbmp.h | 6 ++++++ src/msw/statbmp.cpp | 15 ++++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/wx/msw/statbmp.h b/include/wx/msw/statbmp.h index 9466edf512..6d5802c008 100644 --- a/include/wx/msw/statbmp.h +++ b/include/wx/msw/statbmp.h @@ -76,6 +76,7 @@ protected: void DoPaintManually(wxPaintEvent& event); #endif // !__WXWINCE__ + void WXHandleSize(wxSizeEvent& event); // we can have either an icon or a bitmap bool m_isIcon; @@ -86,6 +87,7 @@ protected: private: DECLARE_DYNAMIC_CLASS(wxStaticBitmap) + wxDECLARE_EVENT_TABLE(); wxDECLARE_NO_COPY_CLASS(wxStaticBitmap); }; diff --git a/interface/wx/statbmp.h b/interface/wx/statbmp.h index 048bf90be9..ffbbb1a93c 100644 --- a/interface/wx/statbmp.h +++ b/interface/wx/statbmp.h @@ -17,6 +17,12 @@ If you want to display larger images portably, you may use generic implementation wxGenericStaticBitmap declared in \. + Notice that for the best results, the size of the control should be the + same as the size of the image displayed in it, as happens by default if + if it's not resized explicitly. Otherwise, behaviour depends on the + platform: under MSW, the bitmap is drawn centred inside the control, while + elsewhere it is drawn at the origin of the control. + @library{wxcore} @category{ctrl} @appearance{staticbitmap} diff --git a/src/msw/statbmp.cpp b/src/msw/statbmp.cpp index 469d3e68c4..34aec58c09 100644 --- a/src/msw/statbmp.cpp +++ b/src/msw/statbmp.cpp @@ -42,9 +42,13 @@ #include // --------------------------------------------------------------------------- -// macors +// macros // --------------------------------------------------------------------------- +wxBEGIN_EVENT_TABLE(wxStaticBitmap, wxStaticBitmapBase) + EVT_SIZE(wxStaticBitmap::WXHandleSize) +wxEND_EVENT_TABLE() + // =========================================================================== // implementation // =========================================================================== @@ -206,6 +210,15 @@ wxSize wxStaticBitmap::DoGetBestClientSize() const return size; } +void wxStaticBitmap::WXHandleSize(wxSizeEvent& event) +{ + // Invalidate everything when our size changes as the image position (it's + // drawn centred in the window client area) changes. + Refresh(); + + event.Skip(); +} + #ifndef __WXWINCE__ void wxStaticBitmap::DoPaintManually(wxPaintEvent& WXUNUSED(event)) -- 2.45.2