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:
parent
5aed7a5815
commit
6f5b5dc4e4
|
@ -4,6 +4,7 @@
|
||||||
struct checkbox {
|
struct checkbox {
|
||||||
void (*onToggled)(uiControl *, void *);
|
void (*onToggled)(uiControl *, void *);
|
||||||
void *onToggledData;
|
void *onToggledData;
|
||||||
|
gulong onToggledSignal;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void onToggled(GtkToggleButton *b, gpointer data)
|
static void onToggled(GtkToggleButton *b, gpointer data)
|
||||||
|
@ -38,10 +39,10 @@ uiControl *uiNewCheckbox(const char *text)
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
widget = GTK_WIDGET(uiControlHandle(c));
|
widget = GTK_WIDGET(uiControlHandle(c));
|
||||||
g_signal_connect(widget, "toggled", G_CALLBACK(onToggled), c);
|
|
||||||
|
|
||||||
cc = uiNew(struct checkbox);
|
cc = uiNew(struct checkbox);
|
||||||
g_signal_connect(widget, "destroy", G_CALLBACK(onDestroy), cc);
|
g_signal_connect(widget, "destroy", G_CALLBACK(onDestroy), cc);
|
||||||
|
cc->onToggledSignal = g_signal_connect(widget, "toggled", G_CALLBACK(onToggled), c);
|
||||||
cc->onToggled = defaultOnToggled;
|
cc->onToggled = defaultOnToggled;
|
||||||
c->data = cc;
|
c->data = cc;
|
||||||
|
|
||||||
|
@ -73,10 +74,16 @@ int uiCheckboxChecked(uiControl *c)
|
||||||
|
|
||||||
void uiCheckboxSetChecked(uiControl *c, int checked)
|
void uiCheckboxSetChecked(uiControl *c, int checked)
|
||||||
{
|
{
|
||||||
|
struct checkbox *cc = (struct checkbox *) (c->data);
|
||||||
|
GtkToggleButton *button;
|
||||||
gboolean active;
|
gboolean active;
|
||||||
|
|
||||||
active = FALSE;
|
active = FALSE;
|
||||||
if (checked)
|
if (checked)
|
||||||
active = TRUE;
|
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
1
ui.h
|
@ -85,7 +85,6 @@ char *uiCheckboxText(uiControl *);
|
||||||
void uiCheckboxSetText(uiControl *, const char *);
|
void uiCheckboxSetText(uiControl *, const char *);
|
||||||
void uiCheckboxOnToggled(uiControl *, void (*)(uiControl *, void *), void *);
|
void uiCheckboxOnToggled(uiControl *, void (*)(uiControl *, void *), void *);
|
||||||
int uiCheckboxChecked(uiControl *);
|
int uiCheckboxChecked(uiControl *);
|
||||||
// TODO should this trigger an event?
|
|
||||||
void uiCheckboxSetChecked(uiControl *, int);
|
void uiCheckboxSetChecked(uiControl *, int);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue