More spinbox and slider work.
This commit is contained in:
parent
1f7b6ca1ed
commit
7a86dc92cb
|
@ -11,6 +11,8 @@ static uiProgressBar *pbar;
|
||||||
uintmax_t value; \
|
uintmax_t value; \
|
||||||
printf("on %s changed\n", #what); \
|
printf("on %s changed\n", #what); \
|
||||||
value = ui ## what ## Value(this); \
|
value = ui ## what ## Value(this); \
|
||||||
|
uiSpinboxSetValue(spinbox, value); \
|
||||||
|
uiSliderSetValue(slider, value); \
|
||||||
uiProgressBarSetValue(pbar, value); \
|
uiProgressBarSetValue(pbar, value); \
|
||||||
}
|
}
|
||||||
CHANGED(Spinbox)
|
CHANGED(Spinbox)
|
||||||
|
|
|
@ -141,9 +141,12 @@ interface Group from Control {
|
||||||
};
|
};
|
||||||
func NewGroup(text *const char) *Group;
|
func NewGroup(text *const char) *Group;
|
||||||
|
|
||||||
|
// spinbox/slider rules:
|
||||||
|
// setting value outside of range will automatically clamp
|
||||||
|
|
||||||
interface Spinbox from Control {
|
interface Spinbox from Control {
|
||||||
func Value(void) intmax_t;
|
func Value(void) intmax_t;
|
||||||
// TODO SetValue()
|
func SetValue(value intmax_t);
|
||||||
func OnChanged(f *func(s *Spinbox, data *void), data *void);
|
func OnChanged(f *func(s *Spinbox, data *void), data *void);
|
||||||
};
|
};
|
||||||
func NewSpinbox(void) *Spinbox;
|
func NewSpinbox(void) *Spinbox;
|
||||||
|
@ -156,7 +159,7 @@ func NewProgressBar(void) *ProgressBar;
|
||||||
|
|
||||||
interface Slider from Control {
|
interface Slider from Control {
|
||||||
func Value(void) intmax_t;
|
func Value(void) intmax_t;
|
||||||
// TODO SetValue()
|
func SetValue(value intmax_t);
|
||||||
func OnChanged(f *func(s *Slider, data *void), data *void);
|
func OnChanged(f *func(s *Slider, data *void), data *void);
|
||||||
};
|
};
|
||||||
func NewSlider(void) *Slider;
|
func NewSlider(void) *Slider;
|
||||||
|
|
|
@ -62,6 +62,14 @@ static intmax_t sliderValue(uiSlider *ss)
|
||||||
return (intmax_t) SendMessageW(s->hwnd, TBM_GETPOS, 0, 0);
|
return (intmax_t) SendMessageW(s->hwnd, TBM_GETPOS, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void sliderSetValue(uiSlider *ss, intmax_t value)
|
||||||
|
{
|
||||||
|
struct slider *s = (struct slider *) ss;
|
||||||
|
|
||||||
|
// don't use TBM_SETPOSNOTIFY; that triggers an event
|
||||||
|
SendMessageW(s->hwnd, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) value);
|
||||||
|
}
|
||||||
|
|
||||||
static void sliderOnChanged(uiSlider *ss, void (*f)(uiSlider *, void *), void *data)
|
static void sliderOnChanged(uiSlider *ss, void (*f)(uiSlider *, void *), void *data)
|
||||||
{
|
{
|
||||||
struct slider *s = (struct slider *) ss;
|
struct slider *s = (struct slider *) ss;
|
||||||
|
@ -103,6 +111,7 @@ uiSlider *uiNewSlider(void)
|
||||||
uiControl(s)->PreferredSize = sliderPreferredSize;
|
uiControl(s)->PreferredSize = sliderPreferredSize;
|
||||||
|
|
||||||
uiSlider(s)->Value = sliderValue;
|
uiSlider(s)->Value = sliderValue;
|
||||||
|
uiSlider(s)->SetValue = sliderSetValue;
|
||||||
uiSlider(s)->OnChanged = sliderOnChanged;
|
uiSlider(s)->OnChanged = sliderOnChanged;
|
||||||
|
|
||||||
return uiSlider(s);
|
return uiSlider(s);
|
||||||
|
|
|
@ -81,11 +81,20 @@ static void spinboxPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, int
|
||||||
static void recreateUpDown(struct spinbox *s)
|
static void recreateUpDown(struct spinbox *s)
|
||||||
{
|
{
|
||||||
HWND parent;
|
HWND parent;
|
||||||
|
BOOL preserve = FALSE;
|
||||||
|
intmax_t current;
|
||||||
|
// wine uses this type
|
||||||
|
INT min, max;
|
||||||
|
|
||||||
parent = GetAncestor(s->hwnd, GA_PARENT);
|
parent = GetAncestor(s->hwnd, GA_PARENT);
|
||||||
if (s->updown != NULL)
|
if (s->updown != NULL) {
|
||||||
|
preserve = TRUE;
|
||||||
|
current = value(s);
|
||||||
|
SendMessageW(s->updown, UDM_GETRANGE32, (WPARAM) (&min), (LPARAM) (&max));
|
||||||
if (DestroyWindow(s->updown) == 0)
|
if (DestroyWindow(s->updown) == 0)
|
||||||
logLastError("error destroying old updown in recreateUpDown()");
|
logLastError("error destroying old updown in recreateUpDown()");
|
||||||
|
}
|
||||||
|
s->inhibitChanged = TRUE;
|
||||||
s->updown = CreateWindowExW(0,
|
s->updown = CreateWindowExW(0,
|
||||||
UPDOWN_CLASSW, L"",
|
UPDOWN_CLASSW, L"",
|
||||||
// no WS_VISIBLE; we set visibility ourselves
|
// no WS_VISIBLE; we set visibility ourselves
|
||||||
|
@ -98,11 +107,17 @@ static void recreateUpDown(struct spinbox *s)
|
||||||
if (s->updown == NULL)
|
if (s->updown == NULL)
|
||||||
logLastError("error creating updown in recreateUpDown()");
|
logLastError("error creating updown in recreateUpDown()");
|
||||||
SendMessageW(s->updown, UDM_SETBUDDY, (WPARAM) (s->hwnd), 0);
|
SendMessageW(s->updown, UDM_SETBUDDY, (WPARAM) (s->hwnd), 0);
|
||||||
|
if (preserve) {
|
||||||
|
SendMessageW(s->updown, UDM_SETRANGE32, (WPARAM) min, (LPARAM) max);
|
||||||
|
SendMessageW(s->updown, UDM_SETPOS32, 0, (LPARAM) current);
|
||||||
|
} else {
|
||||||
// TODO
|
// TODO
|
||||||
SendMessageW(s->updown, UDM_SETRANGE32, 0, 100);
|
SendMessageW(s->updown, UDM_SETRANGE32, 0, 100);
|
||||||
SendMessageW(s->updown, UDM_SETPOS32, 0, 0);
|
SendMessageW(s->updown, UDM_SETPOS32, 0, 0);
|
||||||
|
}
|
||||||
if (uiControlContainerVisible(uiControl(s)))
|
if (uiControlContainerVisible(uiControl(s)))
|
||||||
ShowWindow(s->updown, SW_SHOW);
|
ShowWindow(s->updown, SW_SHOW);
|
||||||
|
s->inhibitChanged = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void spinboxResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
|
static void spinboxResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
|
||||||
|
@ -126,6 +141,15 @@ static intmax_t spinboxValue(uiSpinbox *ss)
|
||||||
return value(s);
|
return value(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void spinboxSetValue(uiSpinbox *ss, intmax_t value)
|
||||||
|
{
|
||||||
|
struct spinbox *s = (struct spinbox *) ss;
|
||||||
|
|
||||||
|
s->inhibitChanged = TRUE;
|
||||||
|
SendMessageW(s->updown, UDM_SETPOS32, 0, (LPARAM) value);
|
||||||
|
s->inhibitChanged = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static void spinboxOnChanged(uiSpinbox *ss, void (*f)(uiSpinbox *, void *), void *data)
|
static void spinboxOnChanged(uiSpinbox *ss, void (*f)(uiSpinbox *, void *), void *data)
|
||||||
{
|
{
|
||||||
struct spinbox *s = (struct spinbox *) ss;
|
struct spinbox *s = (struct spinbox *) ss;
|
||||||
|
@ -167,6 +191,7 @@ uiSpinbox *uiNewSpinbox(void)
|
||||||
uiControl(s)->Resize = spinboxResize;
|
uiControl(s)->Resize = spinboxResize;
|
||||||
|
|
||||||
uiSpinbox(s)->Value = spinboxValue;
|
uiSpinbox(s)->Value = spinboxValue;
|
||||||
|
uiSpinbox(s)->SetValue = spinboxSetValue;
|
||||||
uiSpinbox(s)->OnChanged = spinboxOnChanged;
|
uiSpinbox(s)->OnChanged = spinboxOnChanged;
|
||||||
|
|
||||||
return uiSpinbox(s);
|
return uiSpinbox(s);
|
||||||
|
|
Loading…
Reference in New Issue