More GTK+ control migration.
This commit is contained in:
parent
f73b384fd9
commit
56db594d4d
|
@ -2,12 +2,10 @@
|
||||||
|
|
||||||
osCFILES = \
|
osCFILES = \
|
||||||
unix/alloc.c \
|
unix/alloc.c \
|
||||||
unix/bin.c \
|
|
||||||
unix/box.c \
|
unix/box.c \
|
||||||
unix/button.c \
|
unix/button.c \
|
||||||
unix/checkbox.c \
|
unix/checkbox.c \
|
||||||
unix/combobox.c \
|
unix/combobox.c \
|
||||||
unix/container.c \
|
|
||||||
unix/control.c \
|
unix/control.c \
|
||||||
unix/datetimepicker.c \
|
unix/datetimepicker.c \
|
||||||
unix/entry.c \
|
unix/entry.c \
|
||||||
|
|
|
@ -19,9 +19,9 @@ uiUnixDefineControl(
|
||||||
|
|
||||||
static void onToggled(GtkToggleButton *b, gpointer data)
|
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)
|
static void defaultOnToggled(uiCheckbox *c, void *data)
|
||||||
|
|
|
@ -18,9 +18,9 @@ uiUnixDefineControl(
|
||||||
|
|
||||||
static void onChanged(GtkEditable *editable, gpointer data)
|
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)
|
static void defaultOnChanged(uiEntry *e, void *data)
|
||||||
|
|
|
@ -1,33 +1,25 @@
|
||||||
// 11 june 2015
|
// 11 june 2015
|
||||||
#include "uipriv_unix.h"
|
#include "uipriv_unix.h"
|
||||||
|
|
||||||
struct label {
|
struct uiLabel {
|
||||||
uiLabel l;
|
uiUnixControl c;
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
GtkMisc *misc;
|
GtkMisc *misc;
|
||||||
GtkLabel *label;
|
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));
|
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);
|
gtk_label_set_text(l->label, text);
|
||||||
// changing the text might necessitate a change in the label's size
|
// changing the text might necessitate a change in the label's size
|
||||||
uiControlQueueResize(uiControl(l));
|
uiControlQueueResize(uiControl(l));
|
||||||
|
@ -35,21 +27,17 @@ static void labelSetText(uiLabel *ll, const char *text)
|
||||||
|
|
||||||
uiLabel *uiNewLabel(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->widget = gtk_label_new(text);
|
||||||
l->misc = GTK_MISC(l->widget);
|
l->misc = GTK_MISC(l->widget);
|
||||||
l->label = GTK_LABEL(l->widget);
|
l->label = GTK_LABEL(l->widget);
|
||||||
uiUnixMakeSingleWidgetControl(uiControl(l), l->widget);
|
|
||||||
|
|
||||||
gtk_misc_set_alignment(l->misc, 0, 0);
|
gtk_misc_set_alignment(l->misc, 0, 0);
|
||||||
|
|
||||||
uiControl(l)->Handle = labelHandle;
|
uiUnixFinishNewControl(l, uiLabel);
|
||||||
|
|
||||||
uiLabel(l)->Text = labelText;
|
return l;
|
||||||
uiLabel(l)->SetText = labelSetText;
|
|
||||||
|
|
||||||
return uiLabel(l);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,19 @@
|
||||||
// 11 june 2015
|
// 11 june 2015
|
||||||
#include "uipriv_unix.h"
|
#include "uipriv_unix.h"
|
||||||
|
|
||||||
struct progressbar {
|
struct uiProgressBar {
|
||||||
uiProgressBar p;
|
uiUnixControl c;
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
GtkProgressBar *pbar;
|
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)
|
if (value < 0 || value > 100)
|
||||||
complain("value %d out of range in progressbarSetValue()", value);
|
complain("value %d out of range in progressbarSetValue()", value);
|
||||||
gtk_progress_bar_set_fraction(p->pbar, ((gdouble) value) / 100);
|
gtk_progress_bar_set_fraction(p->pbar, ((gdouble) value) / 100);
|
||||||
|
@ -27,17 +21,14 @@ static void progressbarSetValue(uiProgressBar *pp, int value)
|
||||||
|
|
||||||
uiProgressBar *uiNewProgressBar(void)
|
uiProgressBar *uiNewProgressBar(void)
|
||||||
{
|
{
|
||||||
struct progressbar *p;
|
uiProgressBar *p;
|
||||||
|
|
||||||
p = (struct progressbar *) uiNewControl(uiTypeProgressBar());
|
p = (uiProgressBar *) uiNewControl(uiTypeProgressBar());
|
||||||
|
|
||||||
p->widget = gtk_progress_bar_new();
|
p->widget = gtk_progress_bar_new();
|
||||||
p->pbar = GTK_PROGRESS_BAR(p->widget);
|
p->pbar = GTK_PROGRESS_BAR(p->widget);
|
||||||
uiUnixMakeSingleWidgetControl(uiControl(p), p->widget);
|
|
||||||
|
|
||||||
uiControl(p)->Handle = progressbarHandle;
|
uiUnixFinishNewControl(p, uiProgressBar);
|
||||||
|
|
||||||
uiProgressBar(p)->SetValue = progressbarSetValue;
|
return p;
|
||||||
|
|
||||||
return uiProgressBar(p);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,28 +4,28 @@
|
||||||
// on GTK+ a uiRadioButtons is a GtkBox with each of the GtkRadioButtons as children
|
// on GTK+ a uiRadioButtons is a GtkBox with each of the GtkRadioButtons as children
|
||||||
|
|
||||||
struct radiobuttons {
|
struct radiobuttons {
|
||||||
uiRadioButtons r;
|
uiUnixControl c;
|
||||||
GtkWidget *boxWidget;
|
GtkWidget *widget;
|
||||||
GtkContainer *boxContainer;
|
GtkContainer *container;
|
||||||
GtkBox *box;
|
GtkBox *box;
|
||||||
GPtrArray *buttons;
|
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 void onDestroy(uiRadioButtons *r)
|
||||||
static uintptr_t radiobuttonsHandle(uiControl *c)
|
|
||||||
{
|
{
|
||||||
struct radiobuttons *r = (struct radiobuttons *) c;
|
// TODO
|
||||||
|
|
||||||
return (uintptr_t) (r->boxWidget);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void radiobuttonsAppend(uiRadioButtons *rr, const char *text)
|
void uiRadiobuttonsAppend(uiRadioButtons *r, const char *text)
|
||||||
{
|
{
|
||||||
struct radiobuttons *r = (struct radiobuttons *) rr;
|
|
||||||
GtkWidget *rb;
|
GtkWidget *rb;
|
||||||
GtkRadioButton *previous;
|
GtkRadioButton *previous;
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ static void radiobuttonsAppend(uiRadioButtons *rr, const char *text)
|
||||||
if (r->buttons->len > 0)
|
if (r->buttons->len > 0)
|
||||||
previous = GTK_RADIO_BUTTON(g_ptr_array_index(r->buttons, 0));
|
previous = GTK_RADIO_BUTTON(g_ptr_array_index(r->buttons, 0));
|
||||||
rb = gtk_radio_button_new_with_label_from_widget(previous, text);
|
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);
|
g_ptr_array_add(r->buttons, rb);
|
||||||
gtk_widget_show(rb);
|
gtk_widget_show(rb);
|
||||||
uiControlQueueResize(uiControl(r));
|
uiControlQueueResize(uiControl(r));
|
||||||
|
@ -41,20 +41,17 @@ static void radiobuttonsAppend(uiRadioButtons *rr, const char *text)
|
||||||
|
|
||||||
uiRadioButtons *uiNewRadioButtons(void)
|
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->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
|
||||||
r->boxContainer = GTK_CONTAINER(r->boxWidget);
|
r->container = GTK_CONTAINER(r->widget);
|
||||||
r->box = GTK_BOX(r->boxWidget);
|
r->box = GTK_BOX(r->widget);
|
||||||
uiUnixMakeSingleWidgetControl(uiControl(r), r->boxWidget);
|
|
||||||
|
|
||||||
r->buttons = g_ptr_array_new();
|
r->buttons = g_ptr_array_new();
|
||||||
|
|
||||||
uiControl(r)->Handle = radiobuttonsHandle;
|
uiUnixFinishNewControl(r, uiRadioButtons);
|
||||||
|
|
||||||
uiRadioButtons(r)->Append = radiobuttonsAppend;
|
return r;
|
||||||
|
|
||||||
return uiRadioButtons(r);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +1,27 @@
|
||||||
// 11 june 2015
|
// 11 june 2015
|
||||||
#include "uipriv_unix.h"
|
#include "uipriv_unix.h"
|
||||||
|
|
||||||
struct separator {
|
struct uiSeparator {
|
||||||
uiSeparator s;
|
uiUnixControl c;
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
GtkSeparator *separator;
|
GtkSeparator *separator;
|
||||||
};
|
};
|
||||||
|
|
||||||
uiDefineControlType(uiSeparator, uiTypeSeparator, struct separator)
|
uiUnixDefineControl(
|
||||||
|
uiSeparator, // type name
|
||||||
static uintptr_t separatorHandle(uiControl *c)
|
uiSeparatorType // type function
|
||||||
{
|
)
|
||||||
struct separator *s = (struct separator *) c;
|
|
||||||
|
|
||||||
return (uintptr_t) (s->widget);
|
|
||||||
}
|
|
||||||
|
|
||||||
uiSeparator *uiNewHorizontalSeparator(void)
|
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->widget = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
|
||||||
s->separator = GTK_SEPARATOR(s->widget);
|
s->separator = GTK_SEPARATOR(s->widget);
|
||||||
uiUnixMakeSingleWidgetControl(uiControl(s), s->widget);
|
|
||||||
|
|
||||||
uiControl(s)->Handle = separatorHandle;
|
uiUnixFinishNewControl(s, uiSeparator);
|
||||||
|
|
||||||
return uiSeparator(s);
|
return s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// 11 june 2015
|
// 11 june 2015
|
||||||
#include "uipriv_unix.h"
|
#include "uipriv_unix.h"
|
||||||
|
|
||||||
struct slider {
|
struct uiSlider {
|
||||||
uiSlider s;
|
uiUnixControl c;
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
GtkRange *range;
|
GtkRange *range;
|
||||||
GtkScale *scale;
|
GtkScale *scale;
|
||||||
|
@ -11,20 +11,16 @@ struct slider {
|
||||||
gulong onChangedSignal;
|
gulong onChangedSignal;
|
||||||
};
|
};
|
||||||
|
|
||||||
uiDefineControlType(uiSlider, uiTypeSlider, struct slider)
|
uiUnixDefineControl(
|
||||||
|
uiSlider, // type name
|
||||||
|
uiSliderType // type function
|
||||||
|
)
|
||||||
|
|
||||||
static void onChanged(GtkRange *range, gpointer data)
|
static void onChanged(GtkRange *range, gpointer data)
|
||||||
{
|
{
|
||||||
struct slider *s = (struct slider *) data;
|
uiSlider *s = uiSlider(data);
|
||||||
|
|
||||||
(*(s->onChanged))(uiSlider(s), s->onChangedData);
|
(*(s->onChanged))(s, s->onChangedData);
|
||||||
}
|
|
||||||
|
|
||||||
static uintptr_t sliderHandle(uiControl *c)
|
|
||||||
{
|
|
||||||
struct slider *s = (struct slider *) c;
|
|
||||||
|
|
||||||
return (uintptr_t) (s->widget);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void defaultOnChanged(uiSlider *s, void *data)
|
static void defaultOnChanged(uiSlider *s, void *data)
|
||||||
|
@ -32,53 +28,42 @@ static void defaultOnChanged(uiSlider *s, void *data)
|
||||||
// do nothing
|
// 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);
|
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
|
// we need to inhibit sending of ::value-changed because this WILL send a ::value-changed otherwise
|
||||||
g_signal_handler_block(s->range, s->onChangedSignal);
|
g_signal_handler_block(s->range, s->onChangedSignal);
|
||||||
gtk_range_set_value(s->range, value);
|
gtk_range_set_value(s->range, value);
|
||||||
g_signal_handler_unblock(s->range, s->onChangedSignal);
|
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->onChanged = f;
|
||||||
s->onChangedData = data;
|
s->onChangedData = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
uiSlider *uiNewSlider(intmax_t min, intmax_t max)
|
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->widget = gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, min, max, 1);
|
||||||
s->range = GTK_RANGE(s->widget);
|
s->range = GTK_RANGE(s->widget);
|
||||||
s->scale = GTK_SCALE(s->widget);
|
s->scale = GTK_SCALE(s->widget);
|
||||||
uiUnixMakeSingleWidgetControl(uiControl(s), s->widget);
|
|
||||||
|
|
||||||
// TODO needed?
|
// TODO needed?
|
||||||
gtk_scale_set_digits(s->scale, 0);
|
gtk_scale_set_digits(s->scale, 0);
|
||||||
|
|
||||||
s->onChangedSignal = g_signal_connect(s->scale, "value-changed", G_CALLBACK(onChanged), s);
|
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;
|
return s;
|
||||||
uiSlider(s)->SetValue = sliderSetValue;
|
|
||||||
uiSlider(s)->OnChanged = sliderOnChanged;
|
|
||||||
|
|
||||||
return uiSlider(s);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// 11 june 2015
|
// 11 june 2015
|
||||||
#include "uipriv_unix.h"
|
#include "uipriv_unix.h"
|
||||||
|
|
||||||
struct spinbox {
|
struct uiSpinbox {
|
||||||
uiSpinbox s;
|
uiUnixControl c;
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
GtkEntry *entry;
|
GtkEntry *entry;
|
||||||
GtkSpinButton *spinButton;
|
GtkSpinButton *spinButton;
|
||||||
|
@ -11,20 +11,16 @@ struct spinbox {
|
||||||
gulong onChangedSignal;
|
gulong onChangedSignal;
|
||||||
};
|
};
|
||||||
|
|
||||||
uiDefineControlType(uiSpinbox, uiTypeSpinbox, struct spinbox)
|
uiUnixDefineControl(
|
||||||
|
uiSpinbox, // type name
|
||||||
|
uiSpinboxType // type function
|
||||||
|
)
|
||||||
|
|
||||||
static void onChanged(GtkSpinButton *sb, gpointer data)
|
static void onChanged(GtkSpinButton *sb, gpointer data)
|
||||||
{
|
{
|
||||||
struct spinbox *s = (struct spinbox *) data;
|
uiSpinbox *s = uiSpinbox(data);
|
||||||
|
|
||||||
(*(s->onChanged))(uiSpinbox(s), s->onChangedData);
|
(*(s->onChanged))(s, s->onChangedData);
|
||||||
}
|
|
||||||
|
|
||||||
static uintptr_t spinboxHandle(uiControl *c)
|
|
||||||
{
|
|
||||||
struct spinbox *s = (struct spinbox *) c;
|
|
||||||
|
|
||||||
return (uintptr_t) (s->widget);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void defaultOnChanged(uiSpinbox *s, void *data)
|
static void defaultOnChanged(uiSpinbox *s, void *data)
|
||||||
|
@ -32,17 +28,13 @@ static void defaultOnChanged(uiSpinbox *s, void *data)
|
||||||
// do nothing
|
// 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);
|
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
|
// we need to inhibit sending of ::value-changed because this WILL send a ::value-changed otherwise
|
||||||
g_signal_handler_block(s->spinButton, s->onChangedSignal);
|
g_signal_handler_block(s->spinButton, s->onChangedSignal);
|
||||||
// TODO does this clamp?
|
// TODO does this clamp?
|
||||||
|
@ -50,39 +42,32 @@ static void spinboxSetValue(uiSpinbox *ss, intmax_t value)
|
||||||
g_signal_handler_unblock(s->spinButton, s->onChangedSignal);
|
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->onChanged = f;
|
||||||
s->onChangedData = data;
|
s->onChangedData = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
uiSpinbox *uiNewSpinbox(intmax_t min, intmax_t max)
|
uiSpinbox *uiNewSpinbox(intmax_t min, intmax_t max)
|
||||||
{
|
{
|
||||||
struct spinbox *s;
|
uiSpinbox *s;
|
||||||
|
|
||||||
if (min >= max)
|
if (min >= max)
|
||||||
complain("error: min >= max in uiNewSpinbox()");
|
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->widget = gtk_spin_button_new_with_range(min, max, 1);
|
||||||
s->entry = GTK_ENTRY(s->widget);
|
s->entry = GTK_ENTRY(s->widget);
|
||||||
s->spinButton = GTK_SPIN_BUTTON(s->widget);
|
s->spinButton = GTK_SPIN_BUTTON(s->widget);
|
||||||
uiUnixMakeSingleWidgetControl(uiControl(s), s->widget);
|
|
||||||
|
|
||||||
// TODO needed?
|
// TODO needed?
|
||||||
gtk_spin_button_set_digits(s->spinButton, 0);
|
gtk_spin_button_set_digits(s->spinButton, 0);
|
||||||
|
|
||||||
s->onChangedSignal = g_signal_connect(s->spinButton, "value-changed", G_CALLBACK(onChanged), s);
|
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;
|
return s;
|
||||||
uiSpinbox(s)->SetValue = spinboxSetValue;
|
|
||||||
uiSpinbox(s)->OnChanged = spinboxOnChanged;
|
|
||||||
|
|
||||||
return uiSpinbox(s);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue