From 7f427f9cc289882b12bf53e9ed3c1c5faa05a549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Fri, 22 Feb 2008 19:57:54 +0000 Subject: [PATCH] fixed wxBitmapButton to use focus and hover bitmaps correctly git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@52007 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/gtk/bmpbuttn.h | 2 ++ src/gtk/bmpbuttn.cpp | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+) 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