diff --git a/docs/changes.txt b/docs/changes.txt index 81a4a77937..92c19d41b4 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -152,6 +152,7 @@ wxGTK: with other applications. - Fix wxNotebook::GetPage{Text,Image}() when they were called from the page change event handler for the first added page (Mikkel S). +- Fixed wxBitmapButton to use focus and hover bitmaps correctly. wxMac: diff --git a/include/wx/gtk/bmpbuttn.h b/include/wx/gtk/bmpbuttn.h index 3af18cfeec..fb21aec10a 100644 --- a/include/wx/gtk/bmpbuttn.h +++ b/include/wx/gtk/bmpbuttn.h @@ -68,6 +68,8 @@ protected: void Init(); private: + void OnFocusChange(wxFocusEvent& event); + DECLARE_DYNAMIC_CLASS(wxBitmapButton) }; diff --git a/src/gtk/bmpbuttn.cpp b/src/gtk/bmpbuttn.cpp index bd7ccfc6be..4869b84acf 100644 --- a/src/gtk/bmpbuttn.cpp +++ b/src/gtk/bmpbuttn.cpp @@ -163,6 +163,13 @@ bool wxBitmapButton::Create( wxWindow *parent, PostCreation(size); + Connect(wxEVT_SET_FOCUS, + wxFocusEventHandler(wxBitmapButton::OnFocusChange), + NULL, this); + Connect(wxEVT_KILL_FOCUS, + wxFocusEventHandler(wxBitmapButton::OnFocusChange), + NULL, this); + return true; } @@ -201,6 +208,12 @@ void wxBitmapButton::OnSetBitmap() else if (m_isSelected) the_one = m_bmpSelected; else if (m_hasFocus) + { + // NB: this is misnomer, m_hasFocus doesn't mean "has focus", but + // "mouse is over the window" + the_one = m_bmpHover; + } + else if (FindFocus() == this) the_one = m_bmpFocus; else the_one = m_bmpNormal; @@ -264,4 +277,10 @@ void wxBitmapButton::EndSelect() OnSetBitmap(); } +void wxBitmapButton::OnFocusChange(wxFocusEvent& event) +{ + event.Skip(); + OnSetBitmap(); +} + #endif // wxUSE_BMPBUTTON