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
This commit is contained in:
Vadim Zeitlin
2013-02-09 00:35:54 +00:00
parent 4bd1fc29b2
commit 05942059ef
3 changed files with 22 additions and 1 deletions

View File

@@ -76,6 +76,7 @@ protected:
void DoPaintManually(wxPaintEvent& event); void DoPaintManually(wxPaintEvent& event);
#endif // !__WXWINCE__ #endif // !__WXWINCE__
void WXHandleSize(wxSizeEvent& event);
// we can have either an icon or a bitmap // we can have either an icon or a bitmap
bool m_isIcon; bool m_isIcon;
@@ -86,6 +87,7 @@ protected:
private: private:
DECLARE_DYNAMIC_CLASS(wxStaticBitmap) DECLARE_DYNAMIC_CLASS(wxStaticBitmap)
wxDECLARE_EVENT_TABLE();
wxDECLARE_NO_COPY_CLASS(wxStaticBitmap); wxDECLARE_NO_COPY_CLASS(wxStaticBitmap);
}; };

View File

@@ -17,6 +17,12 @@
If you want to display larger images portably, you may use generic If you want to display larger images portably, you may use generic
implementation wxGenericStaticBitmap declared in \<wx/generic/statbmpg.h\>. implementation wxGenericStaticBitmap declared in \<wx/generic/statbmpg.h\>.
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} @library{wxcore}
@category{ctrl} @category{ctrl}
@appearance{staticbitmap} @appearance{staticbitmap}

View File

@@ -42,9 +42,13 @@
#include <stdio.h> #include <stdio.h>
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// macors // macros
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
wxBEGIN_EVENT_TABLE(wxStaticBitmap, wxStaticBitmapBase)
EVT_SIZE(wxStaticBitmap::WXHandleSize)
wxEND_EVENT_TABLE()
// =========================================================================== // ===========================================================================
// implementation // implementation
// =========================================================================== // ===========================================================================
@@ -206,6 +210,15 @@ wxSize wxStaticBitmap::DoGetBestClientSize() const
return size; 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__ #ifndef __WXWINCE__
void wxStaticBitmap::DoPaintManually(wxPaintEvent& WXUNUSED(event)) void wxStaticBitmap::DoPaintManually(wxPaintEvent& WXUNUSED(event))