Reimplemented GTK+ uiCheckbox.
This commit is contained in:
parent
cf4dd17bb4
commit
c73b506709
|
@ -9,10 +9,18 @@ struct checkbox {
|
||||||
GtkCheckButton *checkButton;
|
GtkCheckButton *checkButton;
|
||||||
void (*onToggled)(uiCheckbox *, void *);
|
void (*onToggled)(uiCheckbox *, void *);
|
||||||
void *onToggledData;
|
void *onToggledData;
|
||||||
|
gulong onToggledSignal;
|
||||||
};
|
};
|
||||||
|
|
||||||
uiDefineControlType(uiCheckbox, uiTypeCheckbox, struct checkbox)
|
uiDefineControlType(uiCheckbox, uiTypeCheckbox, struct checkbox)
|
||||||
|
|
||||||
|
static void onToggled(GtkToggleButton *b, gpointer data)
|
||||||
|
{
|
||||||
|
struct checkbox *c = (struct checkbox *) data;
|
||||||
|
|
||||||
|
(*(c->onToggled))(uiCheckbox(c), c->onToggledData);
|
||||||
|
}
|
||||||
|
|
||||||
static uintptr_t checkboxHandle(uiControl *cc)
|
static uintptr_t checkboxHandle(uiControl *cc)
|
||||||
{
|
{
|
||||||
struct checkbox *c = (struct checkbox *) cc;
|
struct checkbox *c = (struct checkbox *) cc;
|
||||||
|
@ -29,14 +37,14 @@ static char *checkboxText(uiCheckbox *cc)
|
||||||
{
|
{
|
||||||
struct checkbox *c = (struct checkbox *) cc;
|
struct checkbox *c = (struct checkbox *) cc;
|
||||||
|
|
||||||
return PUT_CODE_HERE;
|
return uiUnixStrdupText(gtk_button_get_label(c->button));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void checkboxSetText(uiCheckbox *cc, const char *text)
|
static void checkboxSetText(uiCheckbox *cc, const char *text)
|
||||||
{
|
{
|
||||||
struct checkbox *c = (struct checkbox *) cc;
|
struct checkbox *c = (struct checkbox *) cc;
|
||||||
|
|
||||||
PUT_CODE_HERE;
|
gtk_button_set_label(GTK_BUTTON(c->button), text);
|
||||||
// changing the text might necessitate a change in the checkbox's size
|
// changing the text might necessitate a change in the checkbox's size
|
||||||
uiControlQueueResize(uiControl(c));
|
uiControlQueueResize(uiControl(c));
|
||||||
}
|
}
|
||||||
|
@ -53,14 +61,21 @@ static int checkboxChecked(uiCheckbox *cc)
|
||||||
{
|
{
|
||||||
struct checkbox *c = (struct checkbox *) cc;
|
struct checkbox *c = (struct checkbox *) cc;
|
||||||
|
|
||||||
return PUT_CODE_HERE;
|
return gtk_toggle_button_get_active(c->toggleButton) != FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void checkboxSetChecked(uiCheckbox *cc, int checked)
|
static void checkboxSetChecked(uiCheckbox *cc, int checked)
|
||||||
{
|
{
|
||||||
struct checkbox *c = (struct checkbox *) cc;
|
struct checkbox *c = (struct checkbox *) cc;
|
||||||
|
gboolean active;
|
||||||
|
|
||||||
PUT_CODE_HERE;
|
active = FALSE;
|
||||||
|
if (checked)
|
||||||
|
active = TRUE;
|
||||||
|
// we need to inhibit sending of ::toggled because this WILL send a ::toggled otherwise
|
||||||
|
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)
|
uiCheckbox *uiNewCheckbox(const char *text)
|
||||||
|
@ -75,6 +90,7 @@ uiCheckbox *uiNewCheckbox(const char *text)
|
||||||
c->checkButton = GTK_CHECK_BUTTON(c->widget);
|
c->checkButton = GTK_CHECK_BUTTON(c->widget);
|
||||||
uiUnixMakeSingleWidgetControl(uiControl(c), c->widget);
|
uiUnixMakeSingleWidgetControl(uiControl(c), c->widget);
|
||||||
|
|
||||||
|
c->onToggledSignal = g_signal_connect(c->widget, "toggled", G_CALLBACK(onToggled), c);
|
||||||
c->onToggled = defaultOnToggled;
|
c->onToggled = defaultOnToggled;
|
||||||
|
|
||||||
uiControl(c)->Handle = checkboxHandle;
|
uiControl(c)->Handle = checkboxHandle;
|
||||||
|
|
|
@ -12,67 +12,13 @@ struct checkbox {
|
||||||
gulong onToggledSignal;
|
gulong onToggledSignal;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void onToggled(GtkToggleButton *b, gpointer data)
|
|
||||||
{
|
|
||||||
struct checkbox *c = (struct checkbox *) data;
|
|
||||||
|
|
||||||
(*(c->onToggled))(uiCheckbox(c), c->onToggledData);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void defaultOnToggled(uiCheckbox *c, void *data)
|
static void defaultOnToggled(uiCheckbox *c, void *data)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onDestroy(void *data)
|
|
||||||
{
|
|
||||||
struct checkbox *c = (struct checkbox *) data;
|
|
||||||
|
|
||||||
uiFree(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *checkboxText(uiCheckbox *cc)
|
|
||||||
{
|
|
||||||
struct checkbox *c = (struct checkbox *) cc;
|
|
||||||
|
|
||||||
return uiUnixStrdupText(gtk_button_get_label(c->button));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void checkboxSetText(uiCheckbox *cc, const char *text)
|
|
||||||
{
|
|
||||||
struct checkbox *c = (struct checkbox *) cc;
|
|
||||||
|
|
||||||
gtk_button_set_label(GTK_BUTTON(c->button), text);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void checkboxOnToggled(uiCheckbox *cc, void (*f)(uiCheckbox *, void *), void *data)
|
|
||||||
{
|
|
||||||
struct checkbox *c = (struct checkbox *) cc;
|
|
||||||
|
|
||||||
c->onToggled = f;
|
|
||||||
c->onToggledData = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
gboolean active;
|
|
||||||
|
|
||||||
active = FALSE;
|
|
||||||
if (checked)
|
|
||||||
active = TRUE;
|
|
||||||
// we need to inhibit sending of ::toggled because this WILL send a ::toggled otherwise
|
|
||||||
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)
|
uiCheckbox *uiNewCheckbox(const char *text)
|
||||||
{
|
{
|
||||||
|
@ -80,7 +26,6 @@ uiCheckbox *uiNewCheckbox(const char *text)
|
||||||
|
|
||||||
c = uiNew(struct checkbox);
|
c = uiNew(struct checkbox);
|
||||||
|
|
||||||
c->onToggledSignal = g_signal_connect(c->widget, "toggled", G_CALLBACK(onToggled), c);
|
|
||||||
c->onToggled = defaultOnToggled;
|
c->onToggled = defaultOnToggled;
|
||||||
|
|
||||||
uiCheckbox(c)->Text = checkboxText;
|
uiCheckbox(c)->Text = checkboxText;
|
||||||
|
|
Loading…
Reference in New Issue