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

@@ -102,9 +102,8 @@ public:
states.
@param bitmap
The bitmap to display in the button. Under wxGTK the bitmap can be
invalid to remove the currently displayed bitmap, however this is
not supported in wxMSW currently.
The bitmap to display in the button. If the bitmap is invalid, any
currently shown bitmaps are removed from the button.
@param dir
The position of the bitmap inside the button. By default it is
positioned to the left of the text, near to the left button border.
@@ -119,6 +118,9 @@ public:
/**
Sets the bitmap to be shown when the mouse is over the button.
If @a bitmap is invalid, the normal bitmap will be used in the current
state.
@see GetBitmapCurrent()
@since 2.9.1 (available as wxBitmapButton::SetBitmapHover() in previous
@@ -129,6 +131,12 @@ public:
/**
Sets the bitmap for the disabled button appearance.
If @a bitmap is invalid, the disabled bitmap is set to the
automatically generated greyed out version of the normal bitmap, i.e.
the same bitmap as is used by default if this method is not called at
all. Use SetBitmap() with an invalid bitmap to remove the bitmap
completely (for all states).
@see GetBitmapDisabled(), SetBitmapLabel(),
SetBitmapPressed(), SetBitmapFocus()
@@ -140,6 +148,9 @@ public:
Sets the bitmap for the button appearance when it has the keyboard
focus.
If @a bitmap is invalid, the normal bitmap will be used in the focused
state.
@see GetBitmapFocus(), SetBitmapLabel(),
SetBitmapPressed(), SetBitmapDisabled()

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();
}