From ca2c70db6f7c4359d11beb660e13bad31fc9d8cb Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Sat, 17 Jan 2009 20:38:43 +0000 Subject: [PATCH] Workaround for GTK+ sensitivity bug git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@58188 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 2 ++ include/wx/gtk/control.h | 3 +++ src/gtk/button.cpp | 5 +++++ src/gtk/checkbox.cpp | 5 +++++ src/gtk/control.cpp | 20 ++++++++++++++++++++ src/gtk/radiobox.cpp | 5 +++++ src/gtk/radiobut.cpp | 5 +++++ src/gtk/tglbtn.cpp | 10 ++++++++++ 8 files changed, 55 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index 18376f9f3b..bbe8c47fec 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -154,6 +154,8 @@ wxGTK: - Fixed printing to use fonts sizes adjustment consistent with wxMSW. - Make colours used by list, tree and status bar controls more consistent with the system theme settings (Tim Kosse). +- Worked around bug in GTK+ < 2.14 where enabling some controls such + as wxButton didn't re-enable sensitivity until the mouse was moved. 2.8.9 ----- diff --git a/include/wx/gtk/control.h b/include/wx/gtk/control.h index 5c7ffcc4dc..1706f77c64 100644 --- a/include/wx/gtk/control.h +++ b/include/wx/gtk/control.h @@ -102,4 +102,7 @@ private: DECLARE_DYNAMIC_CLASS(wxControl) }; +// Fix sensitivity due to bug in GTK+ < 2.14 +void wxGtkFixSensitivity(wxWindow* ctrl); + #endif // _WX_GTK_CONTROL_H_ diff --git a/src/gtk/button.cpp b/src/gtk/button.cpp index a524f34495..bd4e2beec1 100644 --- a/src/gtk/button.cpp +++ b/src/gtk/button.cpp @@ -249,11 +249,16 @@ void wxButton::SetLabel( const wxString &lbl ) bool wxButton::Enable( bool enable ) { + bool isEnabled = IsEnabled(); + if ( !wxControl::Enable( enable ) ) return false; gtk_widget_set_sensitive(GTK_BIN(m_widget)->child, enable); + if (!isEnabled && enable) + wxGtkFixSensitivity(this); + return true; } diff --git a/src/gtk/checkbox.cpp b/src/gtk/checkbox.cpp index 7dcc25d78f..d97adef953 100644 --- a/src/gtk/checkbox.cpp +++ b/src/gtk/checkbox.cpp @@ -209,11 +209,16 @@ void wxCheckBox::SetLabel( const wxString& label ) bool wxCheckBox::Enable( bool enable ) { + bool isEnabled = IsEnabled(); + if ( !wxControl::Enable( enable ) ) return false; gtk_widget_set_sensitive( m_widgetLabel, enable ); + if (!isEnabled && enable) + wxGtkFixSensitivity(this); + return true; } diff --git a/src/gtk/control.cpp b/src/gtk/control.cpp index a75aa6212f..7b0ea23404 100644 --- a/src/gtk/control.cpp +++ b/src/gtk/control.cpp @@ -20,6 +20,7 @@ #endif #include "wx/fontutil.h" +#include "wx/utils.h" #include "wx/gtk/private.h" // ============================================================================ @@ -377,4 +378,23 @@ void wxControl::OnInternalIdle() UpdateWindowUI(wxUPDATE_UI_FROMIDLE); } +// Fix sensitivity due to bug in GTK+ < 2.14 +void wxGtkFixSensitivity(wxWindow* ctrl) +{ +#ifdef __WXGTK24__ + // Work around a GTK+ bug whereby button is insensitive after being + // enabled + if (gtk_check_version(2,14,0)) + { + wxPoint pt = wxGetMousePosition(); + wxRect rect(ctrl->ClientToScreen(wxPoint(0, 0)), ctrl->GetSize()); + if (rect.Contains(pt)) + { + ctrl->Hide(); + ctrl->Show(); + } + } +#endif +} + #endif // wxUSE_CONTROLS diff --git a/src/gtk/radiobox.cpp b/src/gtk/radiobox.cpp index 2f8dd1b50e..b75525767f 100644 --- a/src/gtk/radiobox.cpp +++ b/src/gtk/radiobox.cpp @@ -473,6 +473,8 @@ void wxRadioBox::SetString(unsigned int item, const wxString& label) bool wxRadioBox::Enable( bool enable ) { + bool isEnabled = IsEnabled(); + if ( !wxControl::Enable( enable ) ) return false; @@ -487,6 +489,9 @@ bool wxRadioBox::Enable( bool enable ) node = node->GetNext(); } + if (!isEnabled && enable) + wxGtkFixSensitivity(this); + return true; } diff --git a/src/gtk/radiobut.cpp b/src/gtk/radiobut.cpp index 400b101454..934324c41c 100644 --- a/src/gtk/radiobut.cpp +++ b/src/gtk/radiobut.cpp @@ -151,11 +151,16 @@ bool wxRadioButton::GetValue() const bool wxRadioButton::Enable( bool enable ) { + bool isEnabled = IsEnabled(); + if ( !wxControl::Enable( enable ) ) return FALSE; gtk_widget_set_sensitive(GTK_BIN(m_widget)->child, enable); + if (!isEnabled && enable) + wxGtkFixSensitivity(this); + return TRUE; } diff --git a/src/gtk/tglbtn.cpp b/src/gtk/tglbtn.cpp index c90a09ec6d..a00a5238d4 100644 --- a/src/gtk/tglbtn.cpp +++ b/src/gtk/tglbtn.cpp @@ -145,11 +145,16 @@ void wxToggleBitmapButton::OnSetBitmap() bool wxToggleBitmapButton::Enable(bool enable /*=true*/) { + bool isEnabled = IsEnabled(); + if (!wxControl::Enable(enable)) return false; gtk_widget_set_sensitive(GTK_BIN(m_widget)->child, enable); + if (!isEnabled && enable) + wxGtkFixSensitivity(this); + return true; } @@ -269,11 +274,16 @@ void wxToggleButton::SetLabel(const wxString& label) bool wxToggleButton::Enable(bool enable /*=true*/) { + bool isEnabled = IsEnabled(); + if (!wxControl::Enable(enable)) return false; gtk_widget_set_sensitive(GTK_BIN(m_widget)->child, enable); + if (!isEnabled && enable) + wxGtkFixSensitivity(this); + return true; }