X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9ff9d30c0aab3b281ef9b380eac17435556c5088..68f64b40bfdffd1fc4967dc422a7d89b42545d82:/src/gtk/tglbtn.cpp?ds=sidebyside diff --git a/src/gtk/tglbtn.cpp b/src/gtk/tglbtn.cpp index 162d9b396f..3880012995 100644 --- a/src/gtk/tglbtn.cpp +++ b/src/gtk/tglbtn.cpp @@ -7,7 +7,7 @@ // Created: 08.02.01 // RCS-ID: $Id$ // Copyright: (c) 2000 Johnny C. Norris II -// License: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // For compilers that support precompilation, includes "wx.h". @@ -31,8 +31,6 @@ static void gtk_togglebutton_clicked_callback(GtkWidget *WXUNUSED(widget), wxTog if (!cb->m_hasVMT || g_blockEventsOnDrag) return; - if (cb->m_blockEvent) return; - // Generate a wx event. wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, cb->GetId()); event.SetInt(cb->GetValue()); @@ -41,7 +39,7 @@ static void gtk_togglebutton_clicked_callback(GtkWidget *WXUNUSED(widget), wxTog } } -DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED) +wxDEFINE_EVENT( wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEvent ); // ------------------------------------------------------------------------ // wxBitmapToggleButton @@ -55,8 +53,6 @@ bool wxBitmapToggleButton::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString &name) { - m_blockEvent = false; - if (!PreCreation(parent, pos, size) || !CreateBase(parent, id, pos, size, style, validator, name )) { @@ -85,6 +81,18 @@ bool wxBitmapToggleButton::Create(wxWindow *parent, wxWindowID id, return true; } +void wxBitmapToggleButton::GTKDisableEvents() +{ + g_signal_handlers_block_by_func(m_widget, + (gpointer) gtk_togglebutton_clicked_callback, this); +} + +void wxBitmapToggleButton::GTKEnableEvents() +{ + g_signal_handlers_unblock_by_func(m_widget, + (gpointer) gtk_togglebutton_clicked_callback, this); +} + // void SetValue(bool state) // Set the value of the toggle button. void wxBitmapToggleButton::SetValue(bool state) @@ -94,11 +102,11 @@ void wxBitmapToggleButton::SetValue(bool state) if (state == GetValue()) return; - m_blockEvent = true; + GTKDisableEvents(); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_widget), state); - m_blockEvent = false; + GTKEnableEvents(); } // bool GetValue() const @@ -124,7 +132,7 @@ void wxBitmapToggleButton::OnSetBitmap() { if (!m_bitmap.Ok()) return; - GtkWidget* image = ((GtkBin*)m_widget)->child; + GtkWidget* image = gtk_bin_get_child(GTK_BIN(m_widget)); if (image == NULL) { image = gtk_image_new(); @@ -138,10 +146,17 @@ 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); + gtk_widget_set_sensitive(gtk_bin_get_child(GTK_BIN(m_widget)), enable); + + if (!isEnabled && enable) + { + GTKFixSensitivity(); + } return true; } @@ -149,7 +164,7 @@ bool wxBitmapToggleButton::Enable(bool enable /*=true*/) void wxBitmapToggleButton::DoApplyWidgetStyle(GtkRcStyle *style) { gtk_widget_modify_style(m_widget, style); - gtk_widget_modify_style(GTK_BIN(m_widget)->child, style); + gtk_widget_modify_style(gtk_bin_get_child(GTK_BIN(m_widget)), style); } GdkWindow * @@ -194,8 +209,6 @@ bool wxToggleButton::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString &name) { - m_blockEvent = false; - if (!PreCreation(parent, pos, size) || !CreateBase(parent, id, pos, size, style, validator, name )) { @@ -220,6 +233,18 @@ bool wxToggleButton::Create(wxWindow *parent, wxWindowID id, return true; } +void wxToggleButton::GTKDisableEvents() +{ + g_signal_handlers_block_by_func(m_widget, + (gpointer) gtk_togglebutton_clicked_callback, this); +} + +void wxToggleButton::GTKEnableEvents() +{ + g_signal_handlers_unblock_by_func(m_widget, + (gpointer) gtk_togglebutton_clicked_callback, this); +} + // void SetValue(bool state) // Set the value of the toggle button. void wxToggleButton::SetValue(bool state) @@ -229,11 +254,11 @@ void wxToggleButton::SetValue(bool state) if (state == GetValue()) return; - m_blockEvent = true; + GTKDisableEvents(); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_widget), state); - m_blockEvent = false; + GTKEnableEvents(); } // bool GetValue() const @@ -242,7 +267,7 @@ bool wxToggleButton::GetValue() const { wxCHECK_MSG(m_widget != NULL, false, wxT("invalid toggle button")); - return GTK_TOGGLE_BUTTON(m_widget)->active; + return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_widget)) != 0; } void wxToggleButton::SetLabel(const wxString& label) @@ -255,15 +280,18 @@ void wxToggleButton::SetLabel(const wxString& label) gtk_button_set_label(GTK_BUTTON(m_widget), wxGTK_CONV(labelGTK)); - ApplyWidgetStyle( false ); + GTKApplyWidgetStyle( false ); } bool wxToggleButton::Enable(bool enable /*=true*/) { - if (!wxControl::Enable(enable)) + if (!base_type::Enable(enable)) return false; - gtk_widget_set_sensitive(GTK_BIN(m_widget)->child, enable); + gtk_widget_set_sensitive(gtk_bin_get_child(GTK_BIN(m_widget)), enable); + + if (enable) + GTKFixSensitivity(); return true; } @@ -271,7 +299,7 @@ bool wxToggleButton::Enable(bool enable /*=true*/) void wxToggleButton::DoApplyWidgetStyle(GtkRcStyle *style) { gtk_widget_modify_style(m_widget, style); - gtk_widget_modify_style(GTK_BIN(m_widget)->child, style); + gtk_widget_modify_style(gtk_bin_get_child(GTK_BIN(m_widget)), style); } GdkWindow *