From: Julian Smart Date: Sun, 18 Jan 2009 12:34:23 +0000 (+0000) Subject: Workaround for GTK+ sensitivity bug X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/ad60f9e7b66d326505592cc6dae034cab5826f3b?hp=150ac0dae391f9b8a59894351432e5a1de3b55f7 Workaround for GTK+ sensitivity bug git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58194 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/gtk/control.h b/include/wx/gtk/control.h index cac29c261b..73f03e2945 100644 --- a/include/wx/gtk/control.h +++ b/include/wx/gtk/control.h @@ -94,6 +94,9 @@ protected: // override this and return true. virtual bool UseGTKStyleBase() const { return false; } + // Fix sensitivity due to bug in GTK+ < 2.14 + void GTKFixSensitivity(bool onlyIfUnderMouse = true); + private: DECLARE_DYNAMIC_CLASS(wxControl) }; diff --git a/include/wx/gtk/spinbutt.h b/include/wx/gtk/spinbutt.h index cb7e59778e..5449e2add7 100644 --- a/include/wx/gtk/spinbutt.h +++ b/include/wx/gtk/spinbutt.h @@ -45,6 +45,8 @@ public: static wxVisualAttributes GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + virtual bool Enable( bool enable = true ); + // implementation void OnSize( wxSizeEvent &event ); diff --git a/samples/widgets/widgets.cpp b/samples/widgets/widgets.cpp index ada1bd3364..71b3fb8872 100644 --- a/samples/widgets/widgets.cpp +++ b/samples/widgets/widgets.cpp @@ -848,6 +848,8 @@ void WidgetsFrame::OnSetFont(wxCommandEvent& WXUNUSED(event)) void WidgetsFrame::OnEnable(wxCommandEvent& event) { CurrentPage()->GetWidget()->Enable(event.IsChecked()); + if (CurrentPage()->GetWidget2()) + CurrentPage()->GetWidget2()->Enable(event.IsChecked()); } void WidgetsFrame::OnSetBorder(wxCommandEvent& event) diff --git a/src/gtk/button.cpp b/src/gtk/button.cpp index fabe9a234f..086159189a 100644 --- a/src/gtk/button.cpp +++ b/src/gtk/button.cpp @@ -216,11 +216,18 @@ 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) + { + GTKFixSensitivity(); + } + return true; } diff --git a/src/gtk/checkbox.cpp b/src/gtk/checkbox.cpp index 83a0993410..17c3ff9548 100644 --- a/src/gtk/checkbox.cpp +++ b/src/gtk/checkbox.cpp @@ -217,11 +217,18 @@ 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) + { + GTKFixSensitivity(); + } + return true; } diff --git a/src/gtk/control.cpp b/src/gtk/control.cpp index 06ca9c1de7..4b163a3d9c 100644 --- a/src/gtk/control.cpp +++ b/src/gtk/control.cpp @@ -21,6 +21,8 @@ #include "wx/fontutil.h" #include "wx/gtk/private.h" +#include "wx/utils.h" +#include "wx/sysopt.h" #include "wx/gtk/private/mnemonics.h" @@ -91,6 +93,30 @@ void wxControl::PostCreation(const wxSize& size) SetInitialSize(size); } +// ---------------------------------------------------------------------------- +// Work around a GTK+ bug whereby button is insensitive after being +// enabled +// ---------------------------------------------------------------------------- + +// Fix sensitivity due to bug in GTK+ < 2.14 +void wxControl::GTKFixSensitivity(bool onlyIfUnderMouse) +{ + if (gtk_check_version(2,14,0) +#if wxUSE_SYSTEM_OPTIONS + && (wxSystemOptions::GetOptionInt(wxT("gtk.control.disable-sensitivity-fix")) != 1) +#endif + ) + { + wxPoint pt = wxGetMousePosition(); + wxRect rect(ClientToScreen(wxPoint(0, 0)), GetSize()); + if (!onlyIfUnderMouse || rect.Contains(pt)) + { + Hide(); + Show(); + } + } +} + // ---------------------------------------------------------------------------- // wxControl dealing with labels // ---------------------------------------------------------------------------- diff --git a/src/gtk/radiobox.cpp b/src/gtk/radiobox.cpp index 33f01ccb61..6379116ff7 100644 --- a/src/gtk/radiobox.cpp +++ b/src/gtk/radiobox.cpp @@ -428,6 +428,8 @@ void wxRadioBox::SetString(unsigned int item, const wxString& label) bool wxRadioBox::Enable( bool enable ) { + bool isEnabled = IsEnabled(); + if ( !wxControl::Enable( enable ) ) return false; @@ -442,6 +444,11 @@ bool wxRadioBox::Enable( bool enable ) node = node->GetNext(); } + if (!isEnabled && enable) + { + GTKFixSensitivity(); + } + return true; } diff --git a/src/gtk/radiobut.cpp b/src/gtk/radiobut.cpp index 93e92becbb..779c22e58d 100644 --- a/src/gtk/radiobut.cpp +++ b/src/gtk/radiobut.cpp @@ -138,11 +138,18 @@ 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) + { + GTKFixSensitivity(); + } + return true; } diff --git a/src/gtk/spinbutt.cpp b/src/gtk/spinbutt.cpp index 45138d8ae4..4ed8250624 100644 --- a/src/gtk/spinbutt.cpp +++ b/src/gtk/spinbutt.cpp @@ -175,6 +175,20 @@ void wxSpinButton::OnSize( wxSizeEvent &WXUNUSED(event) ) gtk_widget_set_size_request( m_widget, m_width, m_height ); } +bool wxSpinButton::Enable( bool enable ) +{ + bool isEnabled = IsEnabled(); + + if ( !wxControl::Enable( enable ) ) + return false; + + // Work around lack of visual update when enabling + if (!isEnabled && enable) + GTKFixSensitivity(false /* fix even if not under mouse */); + + return true; +} + void wxSpinButton::GtkDisableEvents() const { g_signal_handlers_block_by_func(m_widget, diff --git a/src/gtk/tglbtn.cpp b/src/gtk/tglbtn.cpp index 63fd5414cc..97306a9a04 100644 --- a/src/gtk/tglbtn.cpp +++ b/src/gtk/tglbtn.cpp @@ -146,11 +146,18 @@ void wxBitmapToggleButton::OnSetBitmap() bool wxBitmapToggleButton::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) + { + GTKFixSensitivity(); + } + return true; } @@ -278,11 +285,18 @@ 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) + { + GTKFixSensitivity(); + } + return true; }