Bring wxMSW wxBitmap::SetBitmapXXX(wxBitmap()) in line with wxGTK.

Remove or reset the corresponding bitmap if the provided one is invalid
instead of asserting, this is what wxGTK does and this behaviour seems to be
more useful.

Also document this behaviour as it's now implemented in both wxMSW and wxGTK.

Closes #13569.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76415 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-04-27 22:40:05 +00:00
parent ec112197f2
commit 555e57912e
2 changed files with 41 additions and 6 deletions

View File

@@ -672,6 +672,31 @@ wxBitmap wxAnyButton::DoGetBitmap(State which) const
void wxAnyButton::DoSetBitmap(const wxBitmap& bitmap, State which)
{
if ( !bitmap.IsOk() )
{
if ( m_imageData )
{
// Normal image is special: setting it enables images for the
// button and resetting it to nothing disables all of them.
if ( which == State_Normal )
{
delete m_imageData;
m_imageData = NULL;
}
else
{
// Replace the removed bitmap with the normal one.
wxBitmap bmpNormal = m_imageData->GetBitmap(State_Normal);
m_imageData->SetBitmap(which == State_Disabled
? bmpNormal.ConvertToDisabled()
: bmpNormal,
which);
}
}
return;
}
#if wxUSE_UXTHEME
wxXPButtonImageData *oldData = NULL;
#endif // wxUSE_UXTHEME
@@ -758,9 +783,8 @@ void wxAnyButton::DoSetBitmapMargins(wxCoord x, wxCoord y)
void wxAnyButton::DoSetBitmapPosition(wxDirection dir)
{
wxCHECK_RET( m_imageData, "SetBitmap() must be called first" );
m_imageData->SetBitmapPosition(dir);
if ( m_imageData )
m_imageData->SetBitmapPosition(dir);
InvalidateBestSize();
}