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).

This commit is contained in:
Pietro Gagliardi 2015-04-09 23:47:03 -04:00
parent 5aed7a5815
commit 6f5b5dc4e4
2 changed files with 9 additions and 3 deletions

View File

@ -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);
}

1
ui.h
View File

@ -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