Workaround for GTK+ sensitivity bug

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58194 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart 2009-01-18 12:34:23 +00:00
parent 150ac0dae3
commit ad60f9e7b6
10 changed files with 89 additions and 0 deletions

View File

@ -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)
};

View File

@ -45,6 +45,8 @@ public:
static wxVisualAttributes
GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
virtual bool Enable( bool enable = true );
// implementation
void OnSize( wxSizeEvent &event );

View File

@ -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)

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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
// ----------------------------------------------------------------------------

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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,

View File

@ -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;
}