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
This commit is contained in:
@@ -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.
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user