Started migrating GTK+ controls.
This commit is contained in:
parent
46b865a298
commit
f9e4735510
|
@ -3,12 +3,11 @@
|
||||||
|
|
||||||
// TODO clean this up
|
// TODO clean this up
|
||||||
|
|
||||||
struct box {
|
struct uiBox {
|
||||||
uiBox b;
|
uiUnixControl c;
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
GtkContainer *container;
|
GtkContainer *container;
|
||||||
GtkBox *box;
|
GtkBox *box;
|
||||||
void (*baseCommitDestroy)(uiControl *);
|
|
||||||
struct ptrArray *controls; // TODO switch to GArray
|
struct ptrArray *controls; // TODO switch to GArray
|
||||||
int vertical;
|
int vertical;
|
||||||
int padded;
|
int padded;
|
||||||
|
@ -20,11 +19,16 @@ struct boxControl {
|
||||||
int stretchy;
|
int stretchy;
|
||||||
};
|
};
|
||||||
|
|
||||||
uiDefineControlType(uiBox, uiTypeBox, struct box)
|
static void onDestroy(uiBox *b);
|
||||||
|
|
||||||
static void boxCommitDestroy(uiControl *c)
|
uiUnixDefineControlWithOnDestroy(
|
||||||
|
uiBox, // type name
|
||||||
|
uiBoxType, // type function
|
||||||
|
onDestroy(this); // on destroy
|
||||||
|
)
|
||||||
|
|
||||||
|
static void onDestroy(uiBox *b)
|
||||||
{
|
{
|
||||||
struct box *b = (struct box *) c;
|
|
||||||
struct boxControl *bc;
|
struct boxControl *bc;
|
||||||
|
|
||||||
// don't chain up to base here; we need to destroy children ourselves first
|
// don't chain up to base here; we need to destroy children ourselves first
|
||||||
|
@ -38,20 +42,11 @@ static void boxCommitDestroy(uiControl *c)
|
||||||
ptrArrayDestroy(b->controls);
|
ptrArrayDestroy(b->controls);
|
||||||
// kill the size group
|
// kill the size group
|
||||||
g_object_unref(b->stretchygroup);
|
g_object_unref(b->stretchygroup);
|
||||||
// NOW we can chain up to base
|
|
||||||
(*(b->baseCommitDestroy))(uiControl(b));
|
|
||||||
}
|
|
||||||
|
|
||||||
static uintptr_t boxHandle(uiControl *c)
|
|
||||||
{
|
|
||||||
struct box *b = (struct box *) c;
|
|
||||||
|
|
||||||
return (uintptr_t) (b->widget);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void boxContainerUpdateState(uiControl *c)
|
static void boxContainerUpdateState(uiControl *c)
|
||||||
{
|
{
|
||||||
struct box *b = (struct box *) c;
|
uiBox *b = uiBox(c);
|
||||||
struct boxControl *bc;
|
struct boxControl *bc;
|
||||||
uintmax_t i;
|
uintmax_t i;
|
||||||
|
|
||||||
|
@ -61,9 +56,8 @@ static void boxContainerUpdateState(uiControl *c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void boxAppend(uiBox *ss, uiControl *c, int stretchy)
|
void uiBoxAppend(uiBox *b, uiControl *c, int stretchy)
|
||||||
{
|
{
|
||||||
struct box *b = (struct box *) ss;
|
|
||||||
struct boxControl *bc;
|
struct boxControl *bc;
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
|
|
||||||
|
@ -91,9 +85,8 @@ static void boxAppend(uiBox *ss, uiControl *c, int stretchy)
|
||||||
uiControlQueueResize(uiControl(b));
|
uiControlQueueResize(uiControl(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void boxDelete(uiBox *ss, uintmax_t index)
|
void uiBoxDelete(uiBox *b, uintmax_t index)
|
||||||
{
|
{
|
||||||
struct box *b = (struct box *) ss;
|
|
||||||
struct boxControl *bc;
|
struct boxControl *bc;
|
||||||
|
|
||||||
bc = ptrArrayIndex(b->controls, struct boxControl *, index);
|
bc = ptrArrayIndex(b->controls, struct boxControl *, index);
|
||||||
|
@ -105,17 +98,13 @@ static void boxDelete(uiBox *ss, uintmax_t index)
|
||||||
uiControlQueueResize(uiControl(b));
|
uiControlQueueResize(uiControl(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int boxPadded(uiBox *ss)
|
int uiBoxPadded(uiBox *b)
|
||||||
{
|
{
|
||||||
struct box *b = (struct box *) ss;
|
|
||||||
|
|
||||||
return b->padded;
|
return b->padded;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void boxSetPadded(uiBox *ss, int padded)
|
void uiBoxSetPadded(uiBox *b, int padded)
|
||||||
{
|
{
|
||||||
struct box *b = (struct box *) ss;
|
|
||||||
|
|
||||||
b->padded = padded;
|
b->padded = padded;
|
||||||
if (b->padded)
|
if (b->padded)
|
||||||
if (b->vertical)
|
if (b->vertical)
|
||||||
|
@ -129,9 +118,9 @@ static void boxSetPadded(uiBox *ss, int padded)
|
||||||
|
|
||||||
static uiBox *finishNewBox(GtkOrientation orientation)
|
static uiBox *finishNewBox(GtkOrientation orientation)
|
||||||
{
|
{
|
||||||
struct box *b;
|
uiBox *b;
|
||||||
|
|
||||||
b = (struct box *) uiNewControl(uiTypeBox());
|
b = (uiBox *) uiNewControl(uiTypeBox());
|
||||||
|
|
||||||
b->widget = gtk_box_new(orientation, 0);
|
b->widget = gtk_box_new(orientation, 0);
|
||||||
b->container = GTK_CONTAINER(b->widget);
|
b->container = GTK_CONTAINER(b->widget);
|
||||||
|
@ -148,17 +137,10 @@ static uiBox *finishNewBox(GtkOrientation orientation)
|
||||||
|
|
||||||
uiUnixMakeSingleWidgetControl(uiControl(b), b->widget);
|
uiUnixMakeSingleWidgetControl(uiControl(b), b->widget);
|
||||||
|
|
||||||
uiControl(b)->Handle = boxHandle;
|
uiUnixFinishNewControl(b, uiBox);
|
||||||
b->baseCommitDestroy = uiControl(b)->CommitDestroy;
|
|
||||||
uiControl(b)->CommitDestroy = boxCommitDestroy;
|
|
||||||
uiControl(b)->ContainerUpdateState = boxContainerUpdateState;
|
uiControl(b)->ContainerUpdateState = boxContainerUpdateState;
|
||||||
|
|
||||||
uiBox(b)->Append = boxAppend;
|
return b;
|
||||||
uiBox(b)->Delete = boxDelete;
|
|
||||||
uiBox(b)->Padded = boxPadded;
|
|
||||||
uiBox(b)->SetPadded = boxSetPadded;
|
|
||||||
|
|
||||||
return uiBox(b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uiBox *uiNewHorizontalBox(void)
|
uiBox *uiNewHorizontalBox(void)
|
||||||
|
|
|
@ -1,28 +1,24 @@
|
||||||
// 10 june 2015
|
// 10 june 2015
|
||||||
#include "uipriv_unix.h"
|
#include "uipriv_unix.h"
|
||||||
|
|
||||||
struct button {
|
struct uiButton {
|
||||||
uiButton b;
|
uiUnixControl c;
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
GtkButton *button;
|
GtkButton *button;
|
||||||
void (*onClicked)(uiButton *, void *);
|
void (*onClicked)(uiButton *, void *);
|
||||||
void *onClickedData;
|
void *onClickedData;
|
||||||
};
|
};
|
||||||
|
|
||||||
uiDefineControlType(uiButton, uiTypeButton, struct button)
|
uiUnixDefineControl(
|
||||||
|
uiButton, // type name
|
||||||
|
uiButtonType // type function
|
||||||
|
)
|
||||||
|
|
||||||
static void onClicked(GtkButton *button, gpointer data)
|
static void onClicked(GtkButton *button, gpointer data)
|
||||||
{
|
{
|
||||||
struct button *b = (struct button *) data;
|
uiButton *b = uiButton(data);
|
||||||
|
|
||||||
(*(b->onClicked))(uiButton(b), b->onClickedData);
|
(*(b->onClicked))(b, b->onClickedData);
|
||||||
}
|
|
||||||
|
|
||||||
static uintptr_t buttonHandle(uiControl *c)
|
|
||||||
{
|
|
||||||
struct button *b = (struct button *) c;
|
|
||||||
|
|
||||||
return (uintptr_t) (b->widget);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void defaultOnClicked(uiButton *b, void *data)
|
static void defaultOnClicked(uiButton *b, void *data)
|
||||||
|
@ -30,48 +26,37 @@ static void defaultOnClicked(uiButton *b, void *data)
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *buttonText(uiButton *bb)
|
char *uiButtonText(uiButton *b)
|
||||||
{
|
{
|
||||||
struct button *b = (struct button *) bb;
|
|
||||||
|
|
||||||
return uiUnixStrdupText(gtk_button_get_label(b->button));
|
return uiUnixStrdupText(gtk_button_get_label(b->button));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void buttonSetText(uiButton *bb, const char *text)
|
void uiButtonSetText(uiButton *b, const char *text)
|
||||||
{
|
{
|
||||||
struct button *b = (struct button *) bb;
|
|
||||||
|
|
||||||
gtk_button_set_label(b->button, text);
|
gtk_button_set_label(b->button, text);
|
||||||
// changing the text might necessitate a change in the button's size
|
// changing the text might necessitate a change in the button's size
|
||||||
uiControlQueueResize(uiControl(b));
|
uiControlQueueResize(uiControl(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void buttonOnClicked(uiButton *bb, void (*f)(uiButton *, void *), void *data)
|
void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *, void *), void *data)
|
||||||
{
|
{
|
||||||
struct button *b = (struct button *) bb;
|
|
||||||
|
|
||||||
b->onClicked = f;
|
b->onClicked = f;
|
||||||
b->onClickedData = data;
|
b->onClickedData = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
uiButton *uiNewButton(const char *text)
|
uiButton *uiNewButton(const char *text)
|
||||||
{
|
{
|
||||||
struct button *b;
|
uiButton *b;
|
||||||
|
|
||||||
b = (struct button *) uiNewControl(uiTypeButton());
|
b = (uiButton *) uiNewControl(uiTypeButton());
|
||||||
|
|
||||||
b->widget = gtk_button_new_with_label(text);
|
b->widget = gtk_button_new_with_label(text);
|
||||||
b->button = GTK_BUTTON(b->widget);
|
b->button = GTK_BUTTON(b->widget);
|
||||||
uiUnixMakeSingleWidgetControl(uiControl(b), b->widget);
|
|
||||||
|
|
||||||
g_signal_connect(b->widget, "clicked", G_CALLBACK(onClicked), b);
|
g_signal_connect(b->widget, "clicked", G_CALLBACK(onClicked), b);
|
||||||
b->onClicked = defaultOnClicked;
|
uiButtonOnClicked(b, defaultOnClicked, NULL);
|
||||||
|
|
||||||
uiControl(b)->Handle = buttonHandle;
|
uiUnixFinishNewControl(b, uiButton);
|
||||||
|
|
||||||
uiButton(b)->Text = buttonText;
|
return b;
|
||||||
uiButton(b)->SetText = buttonSetText;
|
|
||||||
uiButton(b)->OnClicked = buttonOnClicked;
|
|
||||||
|
|
||||||
return uiButton(b);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// 10 june 2015
|
// 10 june 2015
|
||||||
#include "uipriv_unix.h"
|
#include "uipriv_unix.h"
|
||||||
|
|
||||||
struct checkbox {
|
struct uiCheckbox {
|
||||||
uiCheckbox c;
|
uiUnixControl c;
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
GtkButton *button;
|
GtkButton *button;
|
||||||
GtkToggleButton *toggleButton;
|
GtkToggleButton *toggleButton;
|
||||||
|
@ -12,7 +12,10 @@ struct checkbox {
|
||||||
gulong onToggledSignal;
|
gulong onToggledSignal;
|
||||||
};
|
};
|
||||||
|
|
||||||
uiDefineControlType(uiCheckbox, uiTypeCheckbox, struct checkbox)
|
uiUnixDefineControl(
|
||||||
|
uiCheckbox, // type name
|
||||||
|
uiCheckboxType // type function
|
||||||
|
)
|
||||||
|
|
||||||
static void onToggled(GtkToggleButton *b, gpointer data)
|
static void onToggled(GtkToggleButton *b, gpointer data)
|
||||||
{
|
{
|
||||||
|
@ -21,52 +24,36 @@ static void onToggled(GtkToggleButton *b, gpointer data)
|
||||||
(*(c->onToggled))(uiCheckbox(c), c->onToggledData);
|
(*(c->onToggled))(uiCheckbox(c), c->onToggledData);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uintptr_t checkboxHandle(uiControl *cc)
|
|
||||||
{
|
|
||||||
struct checkbox *c = (struct checkbox *) cc;
|
|
||||||
|
|
||||||
return (uintptr_t) (c->widget);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void defaultOnToggled(uiCheckbox *c, void *data)
|
static void defaultOnToggled(uiCheckbox *c, void *data)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *checkboxText(uiCheckbox *cc)
|
char *uiCheckboxText(uiCheckbox *c)
|
||||||
{
|
{
|
||||||
struct checkbox *c = (struct checkbox *) cc;
|
|
||||||
|
|
||||||
return uiUnixStrdupText(gtk_button_get_label(c->button));
|
return uiUnixStrdupText(gtk_button_get_label(c->button));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void checkboxSetText(uiCheckbox *cc, const char *text)
|
void uiCheckboxSetText(uiCheckbox *c, const char *text)
|
||||||
{
|
{
|
||||||
struct checkbox *c = (struct checkbox *) cc;
|
|
||||||
|
|
||||||
gtk_button_set_label(GTK_BUTTON(c->button), text);
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void checkboxOnToggled(uiCheckbox *cc, void (*f)(uiCheckbox *, void *), void *data)
|
void uiCheckboxOnToggled(uiCheckbox *c, void (*f)(uiCheckbox *, void *), void *data)
|
||||||
{
|
{
|
||||||
struct checkbox *c = (struct checkbox *) cc;
|
|
||||||
|
|
||||||
c->onToggled = f;
|
c->onToggled = f;
|
||||||
c->onToggledData = data;
|
c->onToggledData = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int checkboxChecked(uiCheckbox *cc)
|
int uiCheckboxChecked(uiCheckbox *c)
|
||||||
{
|
{
|
||||||
struct checkbox *c = (struct checkbox *) cc;
|
|
||||||
|
|
||||||
return gtk_toggle_button_get_active(c->toggleButton) != FALSE;
|
return gtk_toggle_button_get_active(c->toggleButton) != FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void checkboxSetChecked(uiCheckbox *cc, int checked)
|
void uiCheckboxSetChecked(uiCheckbox *c, int checked)
|
||||||
{
|
{
|
||||||
struct checkbox *c = (struct checkbox *) cc;
|
|
||||||
gboolean active;
|
gboolean active;
|
||||||
|
|
||||||
active = FALSE;
|
active = FALSE;
|
||||||
|
@ -80,26 +67,19 @@ static void checkboxSetChecked(uiCheckbox *cc, int checked)
|
||||||
|
|
||||||
uiCheckbox *uiNewCheckbox(const char *text)
|
uiCheckbox *uiNewCheckbox(const char *text)
|
||||||
{
|
{
|
||||||
struct checkbox *c;
|
uiCheckbox *c;
|
||||||
|
|
||||||
c = (struct checkbox *) uiNewControl(uiTypeCheckbox());
|
c = (uiCheckbox *) uiNewControl(uiTypeCheckbox());
|
||||||
|
|
||||||
c->widget = gtk_check_button_new_with_label(text);
|
c->widget = gtk_check_button_new_with_label(text);
|
||||||
c->button = GTK_BUTTON(c->widget);
|
c->button = GTK_BUTTON(c->widget);
|
||||||
c->toggleButton = GTK_TOGGLE_BUTTON(c->widget);
|
c->toggleButton = GTK_TOGGLE_BUTTON(c->widget);
|
||||||
c->checkButton = GTK_CHECK_BUTTON(c->widget);
|
c->checkButton = GTK_CHECK_BUTTON(c->widget);
|
||||||
uiUnixMakeSingleWidgetControl(uiControl(c), c->widget);
|
|
||||||
|
|
||||||
c->onToggledSignal = g_signal_connect(c->widget, "toggled", G_CALLBACK(onToggled), c);
|
c->onToggledSignal = g_signal_connect(c->widget, "toggled", G_CALLBACK(onToggled), c);
|
||||||
c->onToggled = defaultOnToggled;
|
uiCheckboxOnToggled(c, defaultOnToggled, NULL);
|
||||||
|
|
||||||
uiControl(c)->Handle = checkboxHandle;
|
uiUnixFinishNewControl(c, uiCheckbox);
|
||||||
|
|
||||||
uiCheckbox(c)->Text = checkboxText;
|
return c;
|
||||||
uiCheckbox(c)->SetText = checkboxSetText;
|
|
||||||
uiCheckbox(c)->OnToggled = checkboxOnToggled;
|
|
||||||
uiCheckbox(c)->Checked = checkboxChecked;
|
|
||||||
uiCheckbox(c)->SetChecked = checkboxSetChecked;
|
|
||||||
|
|
||||||
return uiCheckbox(c);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue