Settled uiSlider and uiSpinbox spurious event inhibition on GTK+.

This commit is contained in:
Pietro Gagliardi 2015-07-01 19:11:51 -04:00
parent 05c7a7b7c7
commit 0966b9448a
2 changed files with 10 additions and 3 deletions

View File

@ -8,6 +8,7 @@ struct slider {
GtkScale *scale;
void (*onChanged)(uiSlider *, void *);
void *onChangedData;
gulong onChangedSignal;
};
uiDefineControlType(uiSlider, uiTypeSlider, struct slider)
@ -42,7 +43,10 @@ static void sliderSetValue(uiSlider *ss, 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)
@ -67,7 +71,7 @@ uiSlider *uiNewSlider(intmax_t min, intmax_t max)
// TODO needed?
gtk_scale_set_digits(s->scale, 0);
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;
uiControl(s)->Handle = sliderHandle;

View File

@ -8,6 +8,7 @@ struct spinbox {
GtkSpinButton *spinButton;
void (*onChanged)(uiSpinbox *, void *);
void *onChangedData;
gulong onChangedSignal;
};
uiDefineControlType(uiSpinbox, uiTypeSpinbox, struct spinbox)
@ -42,9 +43,11 @@ static void spinboxSetValue(uiSpinbox *ss, intmax_t value)
{
struct spinbox *s = (struct spinbox *) ss;
// TODO does this raise an event?
// 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?
gtk_spin_button_set_value(s->spinButton, (gdouble) value);
g_signal_handler_unblock(s->spinButton, s->onChangedSignal);
}
static void spinboxOnChanged(uiSpinbox *ss, void (*f)(uiSpinbox *, void *), void *data)
@ -72,7 +75,7 @@ uiSpinbox *uiNewSpinbox(intmax_t min, intmax_t max)
// TODO needed?
gtk_spin_button_set_digits(s->spinButton, 0);
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;
uiControl(s)->Handle = spinboxHandle;