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());
}
}
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED)
+wxDEFINE_EVENT( wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEvent )
// ------------------------------------------------------------------------
// wxBitmapToggleButton
const wxValidator& validator,
const wxString &name)
{
- m_blockEvent = false;
-
if (!PreCreation(parent, pos, size) ||
!CreateBase(parent, id, pos, size, style, validator, name ))
{
// Create the gtk widget.
m_widget = gtk_toggle_button_new();
+ g_object_ref(m_widget);
if (style & wxNO_BORDER)
gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );
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)
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
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;
}
const wxValidator& validator,
const wxString &name)
{
- m_blockEvent = false;
-
if (!PreCreation(parent, pos, size) ||
!CreateBase(parent, id, pos, size, style, validator, name ))
{
// Create the gtk widget.
m_widget = gtk_toggle_button_new_with_mnemonic("");
+ g_object_ref(m_widget);
SetLabel(label);
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)
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
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;
}