diff --git a/interface/wx/anybutton.h b/interface/wx/anybutton.h index 15e31a0010..f4e2c2446a 100644 --- a/interface/wx/anybutton.h +++ b/interface/wx/anybutton.h @@ -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() diff --git a/src/msw/anybutton.cpp b/src/msw/anybutton.cpp index 3c9e6bb1ea..78ec983ef1 100644 --- a/src/msw/anybutton.cpp +++ b/src/msw/anybutton.cpp @@ -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(); }