Fixed up unix/checkbox.c and made a few minor changes to unix/button.c. I think this is indeed better, yes.
This commit is contained in:
parent
9bc8704c83
commit
ab0470f7e5
|
@ -64,8 +64,9 @@ uiButton *uiNewButton(const char *text)
|
||||||
b->widget = WIDGET(b);
|
b->widget = WIDGET(b);
|
||||||
b->button = GTK_BUTTON(b->widget);
|
b->button = GTK_BUTTON(b->widget);
|
||||||
|
|
||||||
g_signal_connect(b->widget, "clicked", G_CALLBACK(onClicked), b);
|
|
||||||
g_signal_connect(b->widget, "destroy", G_CALLBACK(onDestroy), b);
|
g_signal_connect(b->widget, "destroy", G_CALLBACK(onDestroy), b);
|
||||||
|
|
||||||
|
g_signal_connect(b->widget, "clicked", G_CALLBACK(onClicked), b);
|
||||||
b->onClicked = defaultOnClicked;
|
b->onClicked = defaultOnClicked;
|
||||||
|
|
||||||
uiButton(b)->Text = buttonText;
|
uiButton(b)->Text = buttonText;
|
||||||
|
|
|
@ -3,6 +3,10 @@
|
||||||
|
|
||||||
struct checkbox {
|
struct checkbox {
|
||||||
uiCheckbox c;
|
uiCheckbox c;
|
||||||
|
GtkWidget *widget;
|
||||||
|
GtkButton *button;
|
||||||
|
GtkToggleButton *toggleButton;
|
||||||
|
GtkCheckButton *checkButton;
|
||||||
void (*onToggled)(uiCheckbox *, void *);
|
void (*onToggled)(uiCheckbox *, void *);
|
||||||
void *onToggledData;
|
void *onToggledData;
|
||||||
gulong onToggledSignal;
|
gulong onToggledSignal;
|
||||||
|
@ -27,19 +31,21 @@ static void onDestroy(GtkWidget *widget, gpointer data)
|
||||||
uiFree(c);
|
uiFree(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CHECKBOX(c) GTK_CHECK_BUTTON(uiControlHandle(uiControl(c)))
|
static char *checkboxText(uiCheckbox *cc)
|
||||||
|
|
||||||
static char *getText(uiCheckbox *c)
|
|
||||||
{
|
{
|
||||||
return g_strdup(gtk_button_get_label(GTK_BUTTON(CHECKBOX(c))));
|
struct checkbox *c = (struct checkbox *) cc;
|
||||||
|
|
||||||
|
return g_strdup(gtk_button_get_label(c->button));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setText(uiCheckbox *c, const char *text)
|
static void checkboxSetText(uiCheckbox *cc, const char *text)
|
||||||
{
|
{
|
||||||
gtk_button_set_label(GTK_BUTTON(CHECKBOX(c)), text);
|
struct checkbox *c = (struct checkbox *) cc;
|
||||||
|
|
||||||
|
gtk_button_set_label(GTK_BUTTON(c->button), text);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setOnToggled(uiCheckbox *cc, void (*f)(uiCheckbox *, void *), void *data)
|
static void checkboxOnToggled(uiCheckbox *cc, void (*f)(uiCheckbox *, void *), void *data)
|
||||||
{
|
{
|
||||||
struct checkbox *c = (struct checkbox *) cc;
|
struct checkbox *c = (struct checkbox *) cc;
|
||||||
|
|
||||||
|
@ -47,31 +53,30 @@ static void setOnToggled(uiCheckbox *cc, void (*f)(uiCheckbox *, void *), void *
|
||||||
c->onToggledData = data;
|
c->onToggledData = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getChecked(uiCheckbox *c)
|
static int checkboxChecked(uiCheckbox *cc)
|
||||||
{
|
{
|
||||||
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(CHECKBOX(c))) != FALSE;
|
struct checkbox *c = (struct checkbox *) cc;
|
||||||
}
|
|
||||||
|
return gtk_toggle_button_get_active(c->toggleButton) != FALSE;
|
||||||
static void setChecked(uiCheckbox *cc, int checked)
|
}
|
||||||
|
|
||||||
|
static void checkboxSetChecked(uiCheckbox *cc, int checked)
|
||||||
{
|
{
|
||||||
struct checkbox *c = (struct checkbox *) cc;
|
struct checkbox *c = (struct checkbox *) cc;
|
||||||
GtkToggleButton *button;
|
|
||||||
gboolean active;
|
gboolean active;
|
||||||
|
|
||||||
active = FALSE;
|
active = FALSE;
|
||||||
if (checked)
|
if (checked)
|
||||||
active = TRUE;
|
active = TRUE;
|
||||||
// we need to inhibit sending of ::toggled because this WILL send a ::toggled otherwise
|
// we need to inhibit sending of ::toggled because this WILL send a ::toggled otherwise
|
||||||
button = GTK_TOGGLE_BUTTON(CHECKBOX(c));
|
g_signal_handler_block(c->toggleButton, c->onToggledSignal);
|
||||||
g_signal_handler_block(button, c->onToggledSignal);
|
gtk_toggle_button_set_active(c->toggleButton, active);
|
||||||
gtk_toggle_button_set_active(button, active);
|
g_signal_handler_unblock(c->toggleButton, c->onToggledSignal);
|
||||||
g_signal_handler_unblock(button, c->onToggledSignal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uiCheckbox *uiNewCheckbox(const char *text)
|
uiCheckbox *uiNewCheckbox(const char *text)
|
||||||
{
|
{
|
||||||
struct checkbox *c;
|
struct checkbox *c;
|
||||||
GtkWidget *widget;
|
|
||||||
|
|
||||||
c = uiNew(struct checkbox);
|
c = uiNew(struct checkbox);
|
||||||
|
|
||||||
|
@ -80,16 +85,21 @@ uiCheckbox *uiNewCheckbox(const char *text)
|
||||||
"label", text,
|
"label", text,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
widget = GTK_WIDGET(CHECKBOX(c));
|
c->widget = WIDGET(c);
|
||||||
g_signal_connect(widget, "destroy", G_CALLBACK(onDestroy), c);
|
c->button = GTK_BUTTON(c->widget);
|
||||||
c->onToggledSignal = g_signal_connect(widget, "toggled", G_CALLBACK(onToggled), c);
|
c->toggleButton = GTK_TOGGLE_BUTTON(c->widget);
|
||||||
|
c->checkButton = GTK_CHECK_BUTTON(c->widget);
|
||||||
|
|
||||||
|
g_signal_connect(c->widget, "destroy", G_CALLBACK(onDestroy), c);
|
||||||
|
|
||||||
|
c->onToggledSignal = g_signal_connect(c->widget, "toggled", G_CALLBACK(onToggled), c);
|
||||||
c->onToggled = defaultOnToggled;
|
c->onToggled = defaultOnToggled;
|
||||||
|
|
||||||
uiCheckbox(c)->Text = getText;
|
uiCheckbox(c)->Text = checkboxText;
|
||||||
uiCheckbox(c)->SetText = setText;
|
uiCheckbox(c)->SetText = checkboxSetText;
|
||||||
uiCheckbox(c)->OnToggled = setOnToggled;
|
uiCheckbox(c)->OnToggled = checkboxOnToggled;
|
||||||
uiCheckbox(c)->Checked = getChecked;
|
uiCheckbox(c)->Checked = checkboxChecked;
|
||||||
uiCheckbox(c)->SetChecked = setChecked;
|
uiCheckbox(c)->SetChecked = checkboxSetChecked;
|
||||||
|
|
||||||
return uiCheckbox(c);
|
return uiCheckbox(c);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue