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/branches/WX_3_0_BRANCH@76404 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-04-27 22:38:55 +00:00
parent 635517ca85
commit 4e61289210
3 changed files with 42 additions and 6 deletions

View File

@@ -646,6 +646,7 @@ wxMSW:
- Fix loading of top to bottom BMP files in wxBitmap (Artur Wieczorek). - Fix loading of top to bottom BMP files in wxBitmap (Artur Wieczorek).
- Fix resource leak in wxStaticBitmap with RGBA icons (Artur Wieczorek). - Fix resource leak in wxStaticBitmap with RGBA icons (Artur Wieczorek).
- Fix toolbar repainting after deleting a tool from it (Artur Wieczorek). - Fix toolbar repainting after deleting a tool from it (Artur Wieczorek).
- Allow resetting bitmaps used in wxButton (Artur Wieczorek).
- Fix handling of deleting directories in wxFileSystemWatcher (Eric Raijmakers). - Fix handling of deleting directories in wxFileSystemWatcher (Eric Raijmakers).
- Disable the use of new style wxDirDialog under Vista to work around a bug in - Disable the use of new style wxDirDialog under Vista to work around a bug in
its implementation under this system (jtrauntvein). its implementation under this system (jtrauntvein).

View File

@@ -102,9 +102,8 @@ public:
states. states.
@param bitmap @param bitmap
The bitmap to display in the button. Under wxGTK the bitmap can be The bitmap to display in the button. If the bitmap is invalid, any
invalid to remove the currently displayed bitmap, however this is currently shown bitmaps are removed from the button.
not supported in wxMSW currently.
@param dir @param dir
The position of the bitmap inside the button. By default it is 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. 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. 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() @see GetBitmapCurrent()
@since 2.9.1 (available as wxBitmapButton::SetBitmapHover() in previous @since 2.9.1 (available as wxBitmapButton::SetBitmapHover() in previous
@@ -129,6 +131,12 @@ public:
/** /**
Sets the bitmap for the disabled button appearance. 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(), @see GetBitmapDisabled(), SetBitmapLabel(),
SetBitmapPressed(), SetBitmapFocus() SetBitmapPressed(), SetBitmapFocus()
@@ -140,6 +148,9 @@ public:
Sets the bitmap for the button appearance when it has the keyboard Sets the bitmap for the button appearance when it has the keyboard
focus. focus.
If @a bitmap is invalid, the normal bitmap will be used in the focused
state.
@see GetBitmapFocus(), SetBitmapLabel(), @see GetBitmapFocus(), SetBitmapLabel(),
SetBitmapPressed(), SetBitmapDisabled() SetBitmapPressed(), SetBitmapDisabled()

View File

@@ -671,6 +671,31 @@ wxBitmap wxAnyButton::DoGetBitmap(State which) const
void wxAnyButton::DoSetBitmap(const wxBitmap& bitmap, State which) 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 #if wxUSE_UXTHEME
wxXPButtonImageData *oldData = NULL; wxXPButtonImageData *oldData = NULL;
#endif // wxUSE_UXTHEME #endif // wxUSE_UXTHEME
@@ -757,8 +782,7 @@ void wxAnyButton::DoSetBitmapMargins(wxCoord x, wxCoord y)
void wxAnyButton::DoSetBitmapPosition(wxDirection dir) void wxAnyButton::DoSetBitmapPosition(wxDirection dir)
{ {
wxCHECK_RET( m_imageData, "SetBitmap() must be called first" ); if ( m_imageData )
m_imageData->SetBitmapPosition(dir); m_imageData->SetBitmapPosition(dir);
InvalidateBestSize(); InvalidateBestSize();
} }