From d968078adbfb147e913b9a33fc54242a36f117ce Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Tue, 29 Jan 2008 04:02:33 +0000 Subject: [PATCH 1/1] Remove unnecessary IsRadioButton(). Replace m_blockEvent with g_signal_handlers_block(). Remove wxRadioButton::DoGetBestSize(), it just calls the base. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51427 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/radiobut.h | 10 +--------- include/wx/gtk/window.h | 3 --- src/gtk/radiobut.cpp | 42 +++++++++++++-------------------------- 3 files changed, 15 insertions(+), 40 deletions(-) diff --git a/include/wx/gtk/radiobut.h b/include/wx/gtk/radiobut.h index 98f638b415..2ee6a49085 100644 --- a/include/wx/gtk/radiobut.h +++ b/include/wx/gtk/radiobut.h @@ -42,25 +42,17 @@ public: virtual void SetLabel(const wxString& label); virtual void SetValue(bool val); virtual bool GetValue() const; - virtual bool Enable( bool enable = TRUE ); + virtual bool Enable( bool enable = true ); static wxVisualAttributes GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); - // implementation - - virtual bool IsRadioButton() const { return TRUE; } - - bool m_blockEvent; - protected: virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } - virtual wxSize DoGetBestSize() const; virtual void DoApplyWidgetStyle(GtkRcStyle *style); virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const; -private: DECLARE_DYNAMIC_CLASS(wxRadioButton) }; diff --git a/include/wx/gtk/window.h b/include/wx/gtk/window.h index 9ada466aca..ba3f7222d9 100644 --- a/include/wx/gtk/window.h +++ b/include/wx/gtk/window.h @@ -237,9 +237,6 @@ public: // is this window transparent for the mouse events (as wxStaticBox is)? virtual bool IsTransparentForMouse() const { return false; } - // is this a radiobutton (used by radiobutton code itself only)? - virtual bool IsRadioButton() const { return false; } - // Common scroll event handling code for wxWindow and wxScrollBar wxEventType GetScrollEventType(GtkRange* range); diff --git a/src/gtk/radiobut.cpp b/src/gtk/radiobut.cpp index c4ac7d1175..649a520830 100644 --- a/src/gtk/radiobut.cpp +++ b/src/gtk/radiobut.cpp @@ -10,7 +10,7 @@ // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" -#if wxUSE_RADIOBOX +#if wxUSE_RADIOBTN #include "wx/radiobut.h" @@ -36,8 +36,6 @@ void gtk_radiobutton_clicked_callback( GtkToggleButton *button, wxRadioButton *r if (!button->active) return; - if (rb->m_blockEvent) return; - wxCommandEvent event( wxEVT_COMMAND_RADIOBUTTON_SELECTED, rb->GetId()); event.SetInt( rb->GetValue() ); event.SetEventObject( rb ); @@ -60,8 +58,6 @@ bool wxRadioButton::Create( wxWindow *parent, const wxValidator& validator, const wxString& name ) { - m_blockEvent = false; - if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, validator, name )) { @@ -73,23 +69,16 @@ bool wxRadioButton::Create( wxWindow *parent, if (!HasFlag(wxRB_GROUP)) { // search backward for last group start - wxRadioButton *chief = (wxRadioButton*) NULL; wxWindowList::compatibility_iterator node = parent->GetChildren().GetLast(); - while (node) + for (; node; node = node->GetPrevious()) { wxWindow *child = node->GetData(); - if (child->IsRadioButton()) + if (child->HasFlag(wxRB_GROUP) && wxIsKindOf(child, wxRadioButton)) { - chief = (wxRadioButton*) child; - if (child->HasFlag(wxRB_GROUP)) - break; + radioButtonGroup = gtk_radio_button_get_group( + GTK_RADIO_BUTTON(child->m_widget)); + break; } - node = node->GetPrevious(); - } - if (chief) - { - // we are part of the group started by chief - radioButtonGroup = gtk_radio_button_get_group( GTK_RADIO_BUTTON(chief->m_widget) ); } } @@ -104,7 +93,7 @@ bool wxRadioButton::Create( wxWindow *parent, PostCreation(size); - return TRUE; + return true; } void wxRadioButton::SetLabel( const wxString& label ) @@ -121,7 +110,8 @@ void wxRadioButton::SetValue( bool val ) if (val == GetValue()) return; - m_blockEvent = TRUE; + g_signal_handlers_block_by_func( + m_widget, (void*)gtk_radiobutton_clicked_callback, this); if (val) { @@ -134,12 +124,13 @@ void wxRadioButton::SetValue( bool val ) // as FALSE. Failing silently is probably TRTTD here. } - m_blockEvent = FALSE; + g_signal_handlers_unblock_by_func( + m_widget, (void*)gtk_radiobutton_clicked_callback, this); } bool wxRadioButton::GetValue() const { - wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid radiobutton") ); + wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobutton") ); return GTK_TOGGLE_BUTTON(m_widget)->active; } @@ -147,11 +138,11 @@ bool wxRadioButton::GetValue() const bool wxRadioButton::Enable( bool enable ) { if ( !wxControl::Enable( enable ) ) - return FALSE; + return false; gtk_widget_set_sensitive(GTK_BIN(m_widget)->child, enable); - return TRUE; + return true; } void wxRadioButton::DoApplyWidgetStyle(GtkRcStyle *style) @@ -166,11 +157,6 @@ wxRadioButton::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const return GTK_BUTTON(m_widget)->event_window; } -wxSize wxRadioButton::DoGetBestSize() const -{ - return wxControl::DoGetBestSize(); -} - // static wxVisualAttributes wxRadioButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) -- 2.45.2