2015-06-11 18:07:06 -05:00
|
|
|
// 11 june 2015
|
|
|
|
#include "uipriv_unix.h"
|
|
|
|
|
2015-08-27 22:00:34 -05:00
|
|
|
struct uiSpinbox {
|
|
|
|
uiUnixControl c;
|
2015-06-27 18:46:11 -05:00
|
|
|
GtkWidget *widget;
|
|
|
|
GtkEntry *entry;
|
|
|
|
GtkSpinButton *spinButton;
|
2015-06-14 19:02:38 -05:00
|
|
|
void (*onChanged)(uiSpinbox *, void *);
|
|
|
|
void *onChangedData;
|
2015-07-01 18:11:51 -05:00
|
|
|
gulong onChangedSignal;
|
2015-06-11 18:07:06 -05:00
|
|
|
};
|
|
|
|
|
2016-04-25 19:00:25 -05:00
|
|
|
uiUnixControlAllDefaults(uiSpinbox)
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-07-01 10:21:06 -05:00
|
|
|
static void onChanged(GtkSpinButton *sb, gpointer data)
|
|
|
|
{
|
2015-08-27 22:00:34 -05:00
|
|
|
uiSpinbox *s = uiSpinbox(data);
|
2015-07-01 10:21:06 -05:00
|
|
|
|
2015-08-27 22:00:34 -05:00
|
|
|
(*(s->onChanged))(s, s->onChangedData);
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void defaultOnChanged(uiSpinbox *s, void *data)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2016-06-13 19:55:50 -05:00
|
|
|
int uiSpinboxValue(uiSpinbox *s)
|
2015-06-11 18:07:06 -05:00
|
|
|
{
|
2016-06-13 19:55:50 -05:00
|
|
|
return gtk_spin_button_get_value(s->spinButton);
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|
|
|
|
|
2016-06-13 19:55:50 -05:00
|
|
|
void uiSpinboxSetValue(uiSpinbox *s, int value)
|
2015-06-11 18:07:06 -05:00
|
|
|
{
|
2015-07-01 18:11:51 -05:00
|
|
|
// we need to inhibit sending of ::value-changed because this WILL send a ::value-changed otherwise
|
|
|
|
g_signal_handler_block(s->spinButton, s->onChangedSignal);
|
2016-05-22 19:11:52 -05:00
|
|
|
// this clamps for us
|
2015-07-01 10:21:06 -05:00
|
|
|
gtk_spin_button_set_value(s->spinButton, (gdouble) value);
|
2015-07-01 18:11:51 -05:00
|
|
|
g_signal_handler_unblock(s->spinButton, s->onChangedSignal);
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|
|
|
|
|
2015-08-27 22:00:34 -05:00
|
|
|
void uiSpinboxOnChanged(uiSpinbox *s, void (*f)(uiSpinbox *, void *), void *data)
|
2015-06-11 18:07:06 -05:00
|
|
|
{
|
|
|
|
s->onChanged = f;
|
|
|
|
s->onChangedData = data;
|
|
|
|
}
|
|
|
|
|
2016-06-13 19:55:50 -05:00
|
|
|
uiSpinbox *uiNewSpinbox(int min, int max)
|
2015-06-11 18:07:06 -05:00
|
|
|
{
|
2015-08-27 22:00:34 -05:00
|
|
|
uiSpinbox *s;
|
2016-06-13 19:55:50 -05:00
|
|
|
int temp;
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2016-05-22 19:11:52 -05:00
|
|
|
if (min >= max) {
|
|
|
|
temp = min;
|
|
|
|
min = max;
|
|
|
|
max = temp;
|
|
|
|
}
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2016-04-25 19:00:25 -05:00
|
|
|
uiUnixNewControl(uiSpinbox, s);
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-06-27 18:46:11 -05:00
|
|
|
s->widget = gtk_spin_button_new_with_range(min, max, 1);
|
|
|
|
s->entry = GTK_ENTRY(s->widget);
|
|
|
|
s->spinButton = GTK_SPIN_BUTTON(s->widget);
|
|
|
|
|
2016-05-22 23:41:56 -05:00
|
|
|
// ensure integers, just to be safe
|
2015-06-27 18:46:11 -05:00
|
|
|
gtk_spin_button_set_digits(s->spinButton, 0);
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-07-01 18:11:51 -05:00
|
|
|
s->onChangedSignal = g_signal_connect(s->spinButton, "value-changed", G_CALLBACK(onChanged), s);
|
2015-08-27 22:00:34 -05:00
|
|
|
uiSpinboxOnChanged(s, defaultOnChanged, NULL);
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-08-27 22:00:34 -05:00
|
|
|
return s;
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|