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->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, "clicked", G_CALLBACK(onClicked), b);
|
||||
b->onClicked = defaultOnClicked;
|
||||
|
||||
uiButton(b)->Text = buttonText;
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
|
||||
struct checkbox {
|
||||
uiCheckbox c;
|
||||
GtkWidget *widget;
|
||||
GtkButton *button;
|
||||
GtkToggleButton *toggleButton;
|
||||
GtkCheckButton *checkButton;
|
||||
void (*onToggled)(uiCheckbox *, void *);
|
||||
void *onToggledData;
|
||||
gulong onToggledSignal;
|
||||
|
@ -27,19 +31,21 @@ static void onDestroy(GtkWidget *widget, gpointer data)
|
|||
uiFree(c);
|
||||
}
|
||||
|
||||
#define CHECKBOX(c) GTK_CHECK_BUTTON(uiControlHandle(uiControl(c)))
|
||||
|
||||
static char *getText(uiCheckbox *c)
|
||||
static char *checkboxText(uiCheckbox *cc)
|
||||
{
|
||||
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;
|
||||
|
||||
|
@ -47,31 +53,30 @@ static void setOnToggled(uiCheckbox *cc, void (*f)(uiCheckbox *, void *), void *
|
|||
c->onToggledData = data;
|
||||
}
|
||||
|
||||
static int getChecked(uiCheckbox *c)
|
||||
{
|
||||
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(CHECKBOX(c))) != FALSE;
|
||||
}
|
||||
|
||||
static void setChecked(uiCheckbox *cc, int checked)
|
||||
static int checkboxChecked(uiCheckbox *cc)
|
||||
{
|
||||
struct checkbox *c = (struct checkbox *) cc;
|
||||
|
||||
return gtk_toggle_button_get_active(c->toggleButton) != FALSE;
|
||||
}
|
||||
|
||||
static void checkboxSetChecked(uiCheckbox *cc, int checked)
|
||||
{
|
||||
struct checkbox *c = (struct checkbox *) cc;
|
||||
GtkToggleButton *button;
|
||||
gboolean active;
|
||||
|
||||
active = FALSE;
|
||||
if (checked)
|
||||
active = TRUE;
|
||||
// we need to inhibit sending of ::toggled because this WILL send a ::toggled otherwise
|
||||
button = GTK_TOGGLE_BUTTON(CHECKBOX(c));
|
||||
g_signal_handler_block(button, c->onToggledSignal);
|
||||
gtk_toggle_button_set_active(button, active);
|
||||
g_signal_handler_unblock(button, c->onToggledSignal);
|
||||
g_signal_handler_block(c->toggleButton, c->onToggledSignal);
|
||||
gtk_toggle_button_set_active(c->toggleButton, active);
|
||||
g_signal_handler_unblock(c->toggleButton, c->onToggledSignal);
|
||||
}
|
||||
|
||||
uiCheckbox *uiNewCheckbox(const char *text)
|
||||
{
|
||||
struct checkbox *c;
|
||||
GtkWidget *widget;
|
||||
|
||||
c = uiNew(struct checkbox);
|
||||
|
||||
|
@ -80,16 +85,21 @@ uiCheckbox *uiNewCheckbox(const char *text)
|
|||
"label", text,
|
||||
NULL);
|
||||
|
||||
widget = GTK_WIDGET(CHECKBOX(c));
|
||||
g_signal_connect(widget, "destroy", G_CALLBACK(onDestroy), c);
|
||||
c->onToggledSignal = g_signal_connect(widget, "toggled", G_CALLBACK(onToggled), c);
|
||||
c->widget = WIDGET(c);
|
||||
c->button = GTK_BUTTON(c->widget);
|
||||
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;
|
||||
|
||||
uiCheckbox(c)->Text = getText;
|
||||
uiCheckbox(c)->SetText = setText;
|
||||
uiCheckbox(c)->OnToggled = setOnToggled;
|
||||
uiCheckbox(c)->Checked = getChecked;
|
||||
uiCheckbox(c)->SetChecked = setChecked;
|
||||
uiCheckbox(c)->Text = checkboxText;
|
||||
uiCheckbox(c)->SetText = checkboxSetText;
|
||||
uiCheckbox(c)->OnToggled = checkboxOnToggled;
|
||||
uiCheckbox(c)->Checked = checkboxChecked;
|
||||
uiCheckbox(c)->SetChecked = checkboxSetChecked;
|
||||
|
||||
return uiCheckbox(c);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue