From 6f5b5dc4e4ae8da5c22ee1fdae1a216f34ab18a6 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 9 Apr 2015 23:47:03 -0400 Subject: [PATCH] Decided that uiCheckboxSetChecked() should NOT trigger an event. This required changing the GTK+ backend to make it so; the Windows and Mac OS X backends are fine (setting their checkbox state programmatically will not send a signal; thanks to ThunderSnow in irc.freenode.net/#macdev for confirming this for Mac OS X). --- checkbox_unix.c | 11 +++++++++-- ui.h | 1 - 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/checkbox_unix.c b/checkbox_unix.c index c0d509ef..ddf9edac 100644 --- a/checkbox_unix.c +++ b/checkbox_unix.c @@ -4,6 +4,7 @@ struct checkbox { void (*onToggled)(uiControl *, void *); void *onToggledData; + gulong onToggledSignal; }; static void onToggled(GtkToggleButton *b, gpointer data) @@ -38,10 +39,10 @@ uiControl *uiNewCheckbox(const char *text) NULL); widget = GTK_WIDGET(uiControlHandle(c)); - g_signal_connect(widget, "toggled", G_CALLBACK(onToggled), c); cc = uiNew(struct checkbox); g_signal_connect(widget, "destroy", G_CALLBACK(onDestroy), cc); + cc->onToggledSignal = g_signal_connect(widget, "toggled", G_CALLBACK(onToggled), c); cc->onToggled = defaultOnToggled; c->data = cc; @@ -73,10 +74,16 @@ int uiCheckboxChecked(uiControl *c) void uiCheckboxSetChecked(uiControl *c, int checked) { + struct checkbox *cc = (struct checkbox *) (c->data); + GtkToggleButton *button; gboolean active; active = FALSE; if (checked) active = TRUE; - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(uiControlHandle(c)), active); + // we need to inhibit sending of ::toggled because this WILL send a ::toggled otherwise + button = GTK_TOGGLE_BUTTON(uiControlHandle(c)); + g_signal_handler_block(button, cc->onToggledSignal); + gtk_toggle_button_set_active(button, active); + g_signal_handler_unblock(button, cc->onToggledSignal); } diff --git a/ui.h b/ui.h index 7013a360..a6925857 100644 --- a/ui.h +++ b/ui.h @@ -85,7 +85,6 @@ char *uiCheckboxText(uiControl *); void uiCheckboxSetText(uiControl *, const char *); void uiCheckboxOnToggled(uiControl *, void (*)(uiControl *, void *), void *); int uiCheckboxChecked(uiControl *); -// TODO should this trigger an event? void uiCheckboxSetChecked(uiControl *, int); #endif