More GTK+ control migration.

This commit is contained in:
Pietro Gagliardi 2015-08-27 23:00:34 -04:00
parent f73b384fd9
commit 56db594d4d
9 changed files with 89 additions and 150 deletions

View File

@ -2,12 +2,10 @@
osCFILES = \
unix/alloc.c \
unix/bin.c \
unix/box.c \
unix/button.c \
unix/checkbox.c \
unix/combobox.c \
unix/container.c \
unix/control.c \
unix/datetimepicker.c \
unix/entry.c \

View File

@ -19,9 +19,9 @@ uiUnixDefineControl(
static void onToggled(GtkToggleButton *b, gpointer data)
{
struct checkbox *c = (struct checkbox *) data;
uiCheckbox *c = uiCheckbox(data);
(*(c->onToggled))(uiCheckbox(c), c->onToggledData);
(*(c->onToggled))(c, c->onToggledData);
}
static void defaultOnToggled(uiCheckbox *c, void *data)

View File

@ -18,9 +18,9 @@ uiUnixDefineControl(
static void onChanged(GtkEditable *editable, gpointer data)
{
struct entry *e = (struct entry *) data;
uiEntry *e = uiEntry(data);
(*(e->onChanged))(uiEntry(e), e->onChangedData);
(*(e->onChanged))(e, e->onChangedData);
}
static void defaultOnChanged(uiEntry *e, void *data)

View File

@ -1,33 +1,25 @@
// 11 june 2015
#include "uipriv_unix.h"
struct label {
uiLabel l;
struct uiLabel {
uiUnixControl c;
GtkWidget *widget;
GtkMisc *misc;
GtkLabel *label;
};
uiDefineControlType(uiLabel, uiTypeLabel, struct label)
uiUnixDefineControl(
uiLabel, // type name
uiLabelType // type function
)
static uintptr_t labelHandle(uiControl *c)
char *uiLabelText(uiLabel *l)
{
struct label *l = (struct label *) c;
return (uintptr_t) (l->widget);
}
static char *labelText(uiLabel *ll)
{
struct label *l = (struct label *) ll;
return uiUnixStrdupText(gtk_label_get_text(l->label));
}
static void labelSetText(uiLabel *ll, const char *text)
void uiLabelSetText(uiLabel *l, const char *text)
{
struct label *l = (struct label *) ll;
gtk_label_set_text(l->label, text);
// changing the text might necessitate a change in the label's size
uiControlQueueResize(uiControl(l));
@ -35,21 +27,17 @@ static void labelSetText(uiLabel *ll, const char *text)
uiLabel *uiNewLabel(const char *text)
{
struct label *l;
uiLabel *l;
l = (struct label *) uiNewControl(uiTypeLabel());
l = (uiLabel *) uiNewControl(uiTypeLabel());
l->widget = gtk_label_new(text);
l->misc = GTK_MISC(l->widget);
l->label = GTK_LABEL(l->widget);
uiUnixMakeSingleWidgetControl(uiControl(l), l->widget);
gtk_misc_set_alignment(l->misc, 0, 0);
uiControl(l)->Handle = labelHandle;
uiUnixFinishNewControl(l, uiLabel);
uiLabel(l)->Text = labelText;
uiLabel(l)->SetText = labelSetText;
return uiLabel(l);
return l;
}

View File

@ -1,25 +1,19 @@
// 11 june 2015
#include "uipriv_unix.h"
struct progressbar {
uiProgressBar p;
struct uiProgressBar {
uiUnixControl c;
GtkWidget *widget;
GtkProgressBar *pbar;
};
uiDefineControlType(uiProgressBar, uiTypeProgressBar, struct progressbar)
uiUnixDefineControl(
uiProgressBar, // type name
uiProgressBarType // type function
)
static uintptr_t progressbarHandle(uiControl *c)
void uiProgressBarSetValue(uiProgressBar *p, int value)
{
struct progressbar *p = (struct progressbar *) c;
return (uintptr_t) (p->widget);
}
static void progressbarSetValue(uiProgressBar *pp, int value)
{
struct progressbar *p = (struct progressbar *) pp;
if (value < 0 || value > 100)
complain("value %d out of range in progressbarSetValue()", value);
gtk_progress_bar_set_fraction(p->pbar, ((gdouble) value) / 100);
@ -27,17 +21,14 @@ static void progressbarSetValue(uiProgressBar *pp, int value)
uiProgressBar *uiNewProgressBar(void)
{
struct progressbar *p;
uiProgressBar *p;
p = (struct progressbar *) uiNewControl(uiTypeProgressBar());
p = (uiProgressBar *) uiNewControl(uiTypeProgressBar());
p->widget = gtk_progress_bar_new();
p->pbar = GTK_PROGRESS_BAR(p->widget);
uiUnixMakeSingleWidgetControl(uiControl(p), p->widget);
uiControl(p)->Handle = progressbarHandle;
uiUnixFinishNewControl(p, uiProgressBar);
uiProgressBar(p)->SetValue = progressbarSetValue;
return uiProgressBar(p);
return p;
}

View File

@ -4,28 +4,28 @@
// on GTK+ a uiRadioButtons is a GtkBox with each of the GtkRadioButtons as children
struct radiobuttons {
uiRadioButtons r;
GtkWidget *boxWidget;
GtkContainer *boxContainer;
uiUnixControl c;
GtkWidget *widget;
GtkContainer *container;
GtkBox *box;
GPtrArray *buttons;
};
uiDefineControlType(uiRadioButtons, uiTypeRadioButtons, struct radiobuttons)
static void onDestroy(uiRadioButtons *);
// TODO destroy
uiUnixDefineControlWithOnDestroy(
uiRadioButtons, // type name
uiRadioButtonsType, // type function
onDestroy(this); // on destroy
)
// TODO note that the handle of a uiRadioButtons is undefined (or at least highly platform-dependent and unreliable)
static uintptr_t radiobuttonsHandle(uiControl *c)
static void onDestroy(uiRadioButtons *r)
{
struct radiobuttons *r = (struct radiobuttons *) c;
return (uintptr_t) (r->boxWidget);
// TODO
}
static void radiobuttonsAppend(uiRadioButtons *rr, const char *text)
void uiRadiobuttonsAppend(uiRadioButtons *r, const char *text)
{
struct radiobuttons *r = (struct radiobuttons *) rr;
GtkWidget *rb;
GtkRadioButton *previous;
@ -33,7 +33,7 @@ static void radiobuttonsAppend(uiRadioButtons *rr, const char *text)
if (r->buttons->len > 0)
previous = GTK_RADIO_BUTTON(g_ptr_array_index(r->buttons, 0));
rb = gtk_radio_button_new_with_label_from_widget(previous, text);
gtk_container_add(r->boxContainer, rb);
gtk_container_add(r->container, rb);
g_ptr_array_add(r->buttons, rb);
gtk_widget_show(rb);
uiControlQueueResize(uiControl(r));
@ -41,20 +41,17 @@ static void radiobuttonsAppend(uiRadioButtons *rr, const char *text)
uiRadioButtons *uiNewRadioButtons(void)
{
struct radiobuttons *r;
uiRadioButtons *r;
r = (struct radiobuttons *) uiNewControl(uiTypeRadioButtons());
r = (uiRadioButtons *) uiNewControl(uiTypeRadioButtons());
r->boxWidget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
r->boxContainer = GTK_CONTAINER(r->boxWidget);
r->box = GTK_BOX(r->boxWidget);
uiUnixMakeSingleWidgetControl(uiControl(r), r->boxWidget);
r->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
r->container = GTK_CONTAINER(r->widget);
r->box = GTK_BOX(r->widget);
r->buttons = g_ptr_array_new();
uiControl(r)->Handle = radiobuttonsHandle;
uiUnixFinishNewControl(r, uiRadioButtons);
uiRadioButtons(r)->Append = radiobuttonsAppend;
return uiRadioButtons(r);
return r;
}

View File

@ -1,32 +1,27 @@
// 11 june 2015
#include "uipriv_unix.h"
struct separator {
uiSeparator s;
struct uiSeparator {
uiUnixControl c;
GtkWidget *widget;
GtkSeparator *separator;
};
uiDefineControlType(uiSeparator, uiTypeSeparator, struct separator)
static uintptr_t separatorHandle(uiControl *c)
{
struct separator *s = (struct separator *) c;
return (uintptr_t) (s->widget);
}
uiUnixDefineControl(
uiSeparator, // type name
uiSeparatorType // type function
)
uiSeparator *uiNewHorizontalSeparator(void)
{
struct separator *s;
uiSeparator *s;
s = (struct separator *) uiNewControl(uiTypeSeparator());
s = (uiSeparator *) uiNewControl(uiTypeSeparator());
s->widget = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
s->separator = GTK_SEPARATOR(s->widget);
uiUnixMakeSingleWidgetControl(uiControl(s), s->widget);
uiControl(s)->Handle = separatorHandle;
uiUnixFinishNewControl(s, uiSeparator);
return uiSeparator(s);
return s;
}

View File

@ -1,8 +1,8 @@
// 11 june 2015
#include "uipriv_unix.h"
struct slider {
uiSlider s;
struct uiSlider {
uiUnixControl c;
GtkWidget *widget;
GtkRange *range;
GtkScale *scale;
@ -11,20 +11,16 @@ struct slider {
gulong onChangedSignal;
};
uiDefineControlType(uiSlider, uiTypeSlider, struct slider)
uiUnixDefineControl(
uiSlider, // type name
uiSliderType // type function
)
static void onChanged(GtkRange *range, gpointer data)
{
struct slider *s = (struct slider *) data;
uiSlider *s = uiSlider(data);
(*(s->onChanged))(uiSlider(s), s->onChangedData);
}
static uintptr_t sliderHandle(uiControl *c)
{
struct slider *s = (struct slider *) c;
return (uintptr_t) (s->widget);
(*(s->onChanged))(s, s->onChangedData);
}
static void defaultOnChanged(uiSlider *s, void *data)
@ -32,53 +28,42 @@ static void defaultOnChanged(uiSlider *s, void *data)
// do nothing
}
static intmax_t sliderValue(uiSlider *ss)
intmax_t uiSliderValue(uiSlider *s)
{
struct slider *s = (struct slider *) ss;
return (intmax_t) gtk_range_get_value(s->range);
}
static void sliderSetValue(uiSlider *ss, intmax_t value)
void uiSliderSetValue(uiSlider *s, intmax_t value)
{
struct slider *s = (struct slider *) ss;
// we need to inhibit sending of ::value-changed because this WILL send a ::value-changed otherwise
g_signal_handler_block(s->range, s->onChangedSignal);
gtk_range_set_value(s->range, value);
g_signal_handler_unblock(s->range, s->onChangedSignal);
}
static void sliderOnChanged(uiSlider *ss, void (*f)(uiSlider *, void *), void *data)
void uiSliderOnChanged(uiSlider *s, void (*f)(uiSlider *, void *), void *data)
{
struct slider *s = (struct slider *) ss;
s->onChanged = f;
s->onChangedData = data;
}
uiSlider *uiNewSlider(intmax_t min, intmax_t max)
{
struct slider *s;
uiSlider *s;
s = (struct slider *) uiNewControl(uiTypeSlider());
s = (uiSlider *) uiNewControl(uiTypeSlider());
s->widget = gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, min, max, 1);
s->range = GTK_RANGE(s->widget);
s->scale = GTK_SCALE(s->widget);
uiUnixMakeSingleWidgetControl(uiControl(s), s->widget);
// TODO needed?
gtk_scale_set_digits(s->scale, 0);
s->onChangedSignal = g_signal_connect(s->scale, "value-changed", G_CALLBACK(onChanged), s);
s->onChanged = defaultOnChanged;
uiSliderOnChanged(s, defaultOnChanged, NULL);
uiControl(s)->Handle = sliderHandle;
uiUnixFinishNewControl(s, uiSlider);
uiSlider(s)->Value = sliderValue;
uiSlider(s)->SetValue = sliderSetValue;
uiSlider(s)->OnChanged = sliderOnChanged;
return uiSlider(s);
return s;
}

View File

@ -1,8 +1,8 @@
// 11 june 2015
#include "uipriv_unix.h"
struct spinbox {
uiSpinbox s;
struct uiSpinbox {
uiUnixControl c;
GtkWidget *widget;
GtkEntry *entry;
GtkSpinButton *spinButton;
@ -11,20 +11,16 @@ struct spinbox {
gulong onChangedSignal;
};
uiDefineControlType(uiSpinbox, uiTypeSpinbox, struct spinbox)
uiUnixDefineControl(
uiSpinbox, // type name
uiSpinboxType // type function
)
static void onChanged(GtkSpinButton *sb, gpointer data)
{
struct spinbox *s = (struct spinbox *) data;
uiSpinbox *s = uiSpinbox(data);
(*(s->onChanged))(uiSpinbox(s), s->onChangedData);
}
static uintptr_t spinboxHandle(uiControl *c)
{
struct spinbox *s = (struct spinbox *) c;
return (uintptr_t) (s->widget);
(*(s->onChanged))(s, s->onChangedData);
}
static void defaultOnChanged(uiSpinbox *s, void *data)
@ -32,17 +28,13 @@ static void defaultOnChanged(uiSpinbox *s, void *data)
// do nothing
}
static intmax_t spinboxValue(uiSpinbox *ss)
intmax_t uiSpinboxValue(uiSpinbox *s)
{
struct spinbox *s = (struct spinbox *) ss;
return (intmax_t) gtk_spin_button_get_value(s->spinButton);
}
static void spinboxSetValue(uiSpinbox *ss, intmax_t value)
void uiSpinboxSetValue(uiSpinbox *s, intmax_t value)
{
struct spinbox *s = (struct spinbox *) ss;
// we need to inhibit sending of ::value-changed because this WILL send a ::value-changed otherwise
g_signal_handler_block(s->spinButton, s->onChangedSignal);
// TODO does this clamp?
@ -50,39 +42,32 @@ static void spinboxSetValue(uiSpinbox *ss, intmax_t value)
g_signal_handler_unblock(s->spinButton, s->onChangedSignal);
}
static void spinboxOnChanged(uiSpinbox *ss, void (*f)(uiSpinbox *, void *), void *data)
void uiSpinboxOnChanged(uiSpinbox *s, void (*f)(uiSpinbox *, void *), void *data)
{
struct spinbox *s = (struct spinbox *) ss;
s->onChanged = f;
s->onChangedData = data;
}
uiSpinbox *uiNewSpinbox(intmax_t min, intmax_t max)
{
struct spinbox *s;
uiSpinbox *s;
if (min >= max)
complain("error: min >= max in uiNewSpinbox()");
s = (struct spinbox *) uiNewControl(uiTypeSpinbox());
s = (uiSpinbox *) uiNewControl(uiTypeSpinbox());
s->widget = gtk_spin_button_new_with_range(min, max, 1);
s->entry = GTK_ENTRY(s->widget);
s->spinButton = GTK_SPIN_BUTTON(s->widget);
uiUnixMakeSingleWidgetControl(uiControl(s), s->widget);
// TODO needed?
gtk_spin_button_set_digits(s->spinButton, 0);
s->onChangedSignal = g_signal_connect(s->spinButton, "value-changed", G_CALLBACK(onChanged), s);
s->onChanged = defaultOnChanged;
uiSpinboxOnChanged(s, defaultOnChanged, NULL);
uiControl(s)->Handle = spinboxHandle;
uiUnixFinishNewControl(s, uiSpinbox);
uiSpinbox(s)->Value = spinboxValue;
uiSpinbox(s)->SetValue = spinboxSetValue;
uiSpinbox(s)->OnChanged = spinboxOnChanged;
return uiSpinbox(s);
return s;
}