Override DoEnable() instead of Enable() in wxGTK controls

This is slightly simpler, as it doesn't require checking whether the
control state really changes or not (it always does if DoEnable() is
called) and allows disabling the controls before creating them, e.g.
code like

    wxButton* const b = new wxButton();
    b->Disable();
    b->Create(this, wxID_OK);

works as expected now instead of spewing GTK+ errors.
This commit is contained in:
Vadim Zeitlin
2018-12-09 01:31:43 +01:00
parent 5ba1ba1162
commit 96f3832d52
12 changed files with 50 additions and 39 deletions

View File

@@ -23,8 +23,6 @@ public:
m_isPressed = false;
}
virtual bool Enable( bool enable = true ) wxOVERRIDE;
// implementation
// --------------
@@ -41,6 +39,8 @@ public:
protected:
virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const wxOVERRIDE;
virtual void DoEnable(bool enable) wxOVERRIDE;
virtual wxBitmap DoGetBitmap(State which) const wxOVERRIDE;
virtual void DoSetBitmap(const wxBitmap& bitmap, State which) wxOVERRIDE;
virtual void DoSetBitmapPosition(wxDirection dir) wxOVERRIDE;

View File

@@ -39,7 +39,6 @@ public:
bool GetValue() const wxOVERRIDE;
virtual void SetLabel( const wxString& label ) wxOVERRIDE;
virtual bool Enable( bool enable = true ) wxOVERRIDE;
static wxVisualAttributes
GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
@@ -52,6 +51,8 @@ protected:
virtual void DoApplyWidgetStyle(GtkRcStyle *style) wxOVERRIDE;
virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const wxOVERRIDE;
virtual void DoEnable(bool enable) wxOVERRIDE;
void DoSet3StateValue(wxCheckBoxState state) wxOVERRIDE;
wxCheckBoxState DoGet3StateValue() const wxOVERRIDE;

View File

@@ -141,6 +141,8 @@ protected:
virtual void DoApplyWidgetStyle(GtkRcStyle *style) wxOVERRIDE;
virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const wxOVERRIDE;
virtual void DoEnable(bool enable) wxOVERRIDE;
virtual bool GTKNeedsToFilterSameWindowFocus() const wxOVERRIDE { return true; }
virtual bool GTKWidgetNeedsMnemonic() const wxOVERRIDE;

View File

@@ -41,7 +41,6 @@ public:
virtual void SetLabel(const wxString& label) wxOVERRIDE;
virtual void SetValue(bool val);
virtual bool GetValue() const;
virtual bool Enable( bool enable = true ) wxOVERRIDE;
static wxVisualAttributes
GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
@@ -52,6 +51,8 @@ protected:
virtual void DoApplyWidgetStyle(GtkRcStyle *style) wxOVERRIDE;
virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const wxOVERRIDE;
virtual void DoEnable(bool enable) wxOVERRIDE;
private:
typedef wxControl base_type;

View File

@@ -44,8 +44,6 @@ public:
static wxVisualAttributes
GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
virtual bool Enable( bool enable = true ) wxOVERRIDE;
// implementation
int m_pos;
@@ -56,6 +54,8 @@ protected:
virtual wxSize DoGetBestSize() const wxOVERRIDE;
virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const wxOVERRIDE;
virtual void DoEnable(bool enable) wxOVERRIDE;
private:
typedef wxSpinButtonBase base_type;

View File

@@ -95,7 +95,6 @@ public:
// Overridden wxWindow methods
virtual void SetWindowStyleFlag( long style ) wxOVERRIDE;
virtual bool Enable( bool enable = true ) wxOVERRIDE;
// Implementation from now on
void OnDropFiles( wxDropFilesEvent &event );
@@ -178,6 +177,8 @@ protected:
private:
void Init();
virtual void DoEnable(bool enable) wxOVERRIDE;
// overridden wxTextEntry virtual methods
virtual GtkEditable *GetEditable() const wxOVERRIDE;
virtual GtkEntry *GetEntry() const wxOVERRIDE;

View File

@@ -69,10 +69,13 @@ wxgtk_button_released_callback(GtkWidget *WXUNUSED(widget), wxAnyButton *button)
// wxAnyButton
//-----------------------------------------------------------------------------
bool wxAnyButton::Enable( bool enable )
void wxAnyButton::DoEnable(bool enable)
{
if (!base_type::Enable(enable))
return false;
// See wxWindow::DoEnable()
if ( !m_widget )
return;
base_type::DoEnable(enable);
gtk_widget_set_sensitive(gtk_bin_get_child(GTK_BIN(m_widget)), enable);
@@ -80,8 +83,6 @@ bool wxAnyButton::Enable( bool enable )
GTKFixSensitivity();
GTKUpdateBitmap();
return true;
}
GdkWindow *wxAnyButton::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const

View File

@@ -222,17 +222,17 @@ void wxCheckBox::SetLabel( const wxString& label )
GTKSetLabelForLabel(GTK_LABEL(m_widgetLabel), label);
}
bool wxCheckBox::Enable( bool enable )
void wxCheckBox::DoEnable(bool enable)
{
if (!base_type::Enable(enable))
return false;
if ( !m_widgetLabel )
return;
base_type::DoEnable(enable);
gtk_widget_set_sensitive( m_widgetLabel, enable );
if (enable)
GTKFixSensitivity();
return true;
}
void wxCheckBox::DoApplyWidgetStyle(GtkRcStyle *style)

View File

@@ -487,8 +487,18 @@ void wxRadioBox::SetString(unsigned int item, const wxString& label)
bool wxRadioBox::Enable( bool enable )
{
if ( !wxControl::Enable( enable ) )
return false;
// Explicitly forward to the base class just because we need to override
// this function to prevent it from being hidden by Enable(int, bool)
// overload.
return wxControl::Enable(enable);
}
void wxRadioBox::DoEnable(bool enable)
{
if ( !m_widget )
return;
wxControl::DoEnable(enable);
wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
while (node)
@@ -503,8 +513,6 @@ bool wxRadioBox::Enable( bool enable )
if (enable)
GTKFixSensitivity();
return true;
}
bool wxRadioBox::Enable(unsigned int item, bool enable)

View File

@@ -149,17 +149,17 @@ bool wxRadioButton::GetValue() const
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_widget)) != 0;
}
bool wxRadioButton::Enable( bool enable )
void wxRadioButton::DoEnable(bool enable)
{
if (!base_type::Enable(enable))
return false;
if ( !m_widget )
return;
base_type::DoEnable(enable);
gtk_widget_set_sensitive(gtk_bin_get_child(GTK_BIN(m_widget)), enable);
if (enable)
GTKFixSensitivity();
return true;
}
void wxRadioButton::DoApplyWidgetStyle(GtkRcStyle *style)

View File

@@ -173,16 +173,16 @@ void wxSpinButton::SetRange(int minVal, int maxVal)
GtkEnableEvents();
}
bool wxSpinButton::Enable( bool enable )
void wxSpinButton::DoEnable(bool enable)
{
if (!base_type::Enable(enable))
return false;
if ( !m_widget )
return;
base_type::DoEnable(enable);
// Work around lack of visual update when enabling
if (enable)
GTKFixSensitivity(false /* fix even if not under mouse */);
return true;
}
void wxSpinButton::GtkDisableEvents() const

View File

@@ -1350,17 +1350,14 @@ void wxTextCtrl::SetEditable( bool editable )
}
}
bool wxTextCtrl::Enable( bool enable )
void wxTextCtrl::DoEnable(bool enable)
{
if (!wxWindowBase::Enable(enable))
{
// nothing to do
return false;
}
if ( !m_text )
return;
wxTextCtrlBase::DoEnable(enable);
gtk_widget_set_sensitive( m_text, enable );
return true;
}
void wxTextCtrl::MarkDirty()