From ce39ca74bc413b8a5574f733cd9a44e7b1e9beff Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 14 Mar 2011 11:54:39 +0000 Subject: [PATCH] Fix changing the size of the bitmaps in wxMSW wxButton. 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 | 6 +++++- src/msw/button.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/interface/wx/button.h b/interface/wx/button.h index 617a48c8cf..697fc73f6c 100644 --- a/interface/wx/button.h +++ b/interface/wx/button.h @@ -78,7 +78,11 @@ 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. diff --git a/src/msw/button.cpp b/src/msw/button.cpp index 50ea2ad9f2..280947275d 100644 --- a/src/msw/button.cpp +++ b/src/msw/button.cpp @@ -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(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 -- 2.47.2