]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix changing the size of the bitmaps in wxMSW wxButton.
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 14 Mar 2011 11:54:39 +0000 (11:54 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 14 Mar 2011 11:54:39 +0000 (11:54 +0000)
The size of the wxImageList used to store the bitmaps wasn't updated before
and so the old bitmap size continued to be used even after changing the actual
bitmaps.

Recreate wxXPButtonImageData to ensure that the image list size does change.

Closes #12909.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67187 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

interface/wx/button.h
src/msw/button.cpp

index 617a48c8cf10a6c684e240f326500059e9e7dc2e..697fc73f6ccdb02eb0e247b026ffddcec4eee5c0 100644 (file)
         get reasonably good behaviour on all platforms.
 
     All of the bitmaps must be of the same size and the normal bitmap must be
-    set first (to a valid bitmap), before setting any other ones.
+    set first (to a valid bitmap), before setting any other ones. Also, if the
+    size of the bitmaps is changed later, you need to change the size of the
+    normal bitmap before setting any other bitmaps with the new size (and you
+    do need to reset all of them as their original values can be lost when the
+    normal bitmap size changes).
 
     The position of the image inside the button be configured using
     SetBitmapPosition(). By default the image is on the left of the text.
index 50ea2ad9f2d62c028715e6cee52c14b25b0d16e6..280947275dbb5ec0c2723df69b7135c4ca4cd924 100644 (file)
@@ -987,6 +987,30 @@ wxBitmap wxButton::DoGetBitmap(State which) const
 
 void wxButton::DoSetBitmap(const wxBitmap& bitmap, State which)
 {
+#if wxUSE_UXTHEME
+    wxXPButtonImageData *oldData = NULL;
+#endif // wxUSE_UXTHEME
+
+    // Check if we already had bitmaps of different size.
+    if ( m_imageData &&
+          bitmap.GetSize() != m_imageData->GetBitmap(State_Normal).GetSize() )
+    {
+        wxASSERT_MSG( which == State_Normal,
+                      "Must set normal bitmap with the new size first" );
+
+#if wxUSE_UXTHEME
+        if ( ShowsLabel() && wxUxThemeEngine::GetIfActive() )
+        {
+            // We can't change the size of the images stored in wxImageList
+            // in wxXPButtonImageData::m_iml so force recreating it below but
+            // keep the current data to copy its values into the new one.
+            oldData = static_cast<wxXPButtonImageData *>(m_imageData);
+            m_imageData = NULL;
+        }
+#endif // wxUSE_UXTHEME
+        //else: wxODButtonImageData doesn't require anything special
+    }
+
     // allocate the image data when the first bitmap is set
     if ( !m_imageData )
     {
@@ -998,6 +1022,20 @@ void wxButton::DoSetBitmap(const wxBitmap& bitmap, State which)
         if ( ShowsLabel() && wxUxThemeEngine::GetIfActive() )
         {
             m_imageData = new wxXPButtonImageData(this, bitmap);
+
+            if ( oldData )
+            {
+                // Preserve the old values in case the user changed them.
+                m_imageData->SetBitmapPosition(oldData->GetBitmapPosition());
+
+                const wxSize oldMargins = oldData->GetBitmapMargins();
+                m_imageData->SetBitmapMargins(oldMargins.x, oldMargins.y);
+
+                // No need to preserve the bitmaps though as they were of wrong
+                // size anyhow.
+
+                delete oldData;
+            }
         }
         else
 #endif // wxUSE_UXTHEME