Use proper data structure describing image of owner-drawn wxButton (wxMSW)

When wxButton is switched to owner-drawn mode we need to store its image
data in the dedicated wxODButtonImageData structure. We shouldn't use
in this case wxXPButtonImageData structure because it is dedicated for
native buttons and every time it's updated a BCM_SETIMAGELIST message is
sent to the button what is unnecessary action.
This commit is contained in:
Artur Wieczorek
2021-03-13 23:13:18 +01:00
parent 2af825c6a6
commit 99983325d6

View File

@@ -671,12 +671,12 @@ void wxAnyButton::DoSetBitmap(const wxBitmap& bitmap, State which)
"Must set normal bitmap with the new size first" );
#if wxUSE_UXTHEME
if ( ShowsLabel() && wxUxThemeIsActive() )
// 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 = dynamic_cast<wxXPButtonImageData*>(m_imageData);
if ( oldData )
{
// 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
@@ -1162,6 +1162,24 @@ void wxAnyButton::MakeOwnerDrawn()
{
if ( !IsOwnerDrawn() )
{
// We need to use owner-drawn specific data structure so we have
// to create it and copy the data from native data structure,
// if necessary.
if ( m_imageData && dynamic_cast<wxODButtonImageData*>(m_imageData) == NULL )
{
wxODButtonImageData* newData = new wxODButtonImageData(this, m_imageData->GetBitmap(State_Normal));
for ( int n = 0; n < State_Max; n++ )
{
State st = static_cast<State>(n);
newData->SetBitmap(m_imageData->GetBitmap(st), st);
}
newData->SetBitmapPosition(m_imageData->GetBitmapPosition());
wxSize margs = m_imageData->GetBitmapMargins();
newData->SetBitmapMargins(margs.x, margs.y);
delete m_imageData;
m_imageData = newData;
}
// make it so
wxMSWWinStyleUpdater(GetHwnd()).TurnOff(BS_TYPEMASK).TurnOn(BS_OWNERDRAW);
}