]> git.saurik.com Git - wxWidgets.git/commitdiff
Refresh wxMSW wxStaticBitmap when its size changes.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 9 Feb 2013 00:35:54 +0000 (00:35 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 9 Feb 2013 00:35:54 +0000 (00:35 +0000)
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
interface/wx/statbmp.h
src/msw/statbmp.cpp

index 9466edf5122f352c3b587efa5bb9d4a2e735f638..6d5802c0085c9afa86dc45ca84e82678cbb02fca 100644 (file)
@@ -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);
 };
 
index 048bf90be95f8ecfc38a658839d1e6a277e055f6..ffbbb1a93c5bdc79f8cd1c303b64dd418af3d087 100644 (file)
     If you want to display larger images portably, you may use generic
     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}
     @category{ctrl}
     @appearance{staticbitmap}
index 469d3e68c45a4b280e85b479fda9130e8957089c..34aec58c0917b1fb6c368a2cfb1cb4b12f263132 100644 (file)
 #include <stdio.h>
 
 // ---------------------------------------------------------------------------
-// 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))