More uiSpinbox functionality.

This commit is contained in:
Pietro Gagliardi 2015-05-19 18:17:30 -04:00
parent 13f926b397
commit 44153a32df
3 changed files with 68 additions and 11 deletions

View File

@ -3,6 +3,13 @@
static uiSpinbox *spinbox; static uiSpinbox *spinbox;
#define CHANGED(what) \
static void on ## what ## Changed(ui ## what *this, void *data) \
{ \
printf("on %s changed\n", #what); \
}
CHANGED(Spinbox)
uiBox *makePage4(void) uiBox *makePage4(void)
{ {
uiBox *page4; uiBox *page4;
@ -10,6 +17,7 @@ uiBox *makePage4(void)
page4 = newVerticalBox(); page4 = newVerticalBox();
spinbox = uiNewSpinbox(); spinbox = uiNewSpinbox();
uiSpinboxOnChanged(spinbox, onSpinboxChanged, NULL);
uiBoxAppend(page4, uiControl(spinbox), 0); uiBoxAppend(page4, uiControl(spinbox), 0);
return page4; return page4;

View File

@ -142,6 +142,9 @@ interface Group from Control {
func NewGroup(text *const char) *Group; func NewGroup(text *const char) *Group;
interface Spinbox from Control { interface Spinbox from Control {
func Value(void) intmax_t;
// TODO SetValue()
func OnChanged(f *func(s *Spinbox, data *void), data *void);
}; };
func NewSpinbox(void) *Spinbox; func NewSpinbox(void) *Spinbox;

View File

@ -6,25 +6,45 @@ struct spinbox {
HWND hwnd; HWND hwnd;
HWND updown; HWND updown;
void (*baseResize)(uiControl *, intmax_t, intmax_t, intmax_t, intmax_t, uiSizing *); void (*baseResize)(uiControl *, intmax_t, intmax_t, intmax_t, intmax_t, uiSizing *);
void (*onChanged)(uiSpinbox *, void *);
void *onChangedData;
BOOL inhibitChanged;
}; };
// utility functions
static intmax_t value(struct spinbox *s)
{
BOOL neededCap = FALSE;
LRESULT val;
// This verifies the value put in, capping it automatically.
// We don't need to worry about checking for an error; that flag should really be called "did we have to cap?".
// We DO need to set the value in case of a cap though.
// TODO wine only?
val = SendMessageW(s->updown, UDM_GETPOS32, 0, (LPARAM) (&neededCap));
if (neededCap) {
s->inhibitChanged = TRUE;
SendMessageW(s->updown, UDM_SETPOS32, 0, (LPARAM) val);
s->inhibitChanged = FALSE;
}
return (intmax_t) val;
}
// control implementation
static BOOL onWM_COMMAND(uiControl *c, WORD code, LRESULT *lResult) static BOOL onWM_COMMAND(uiControl *c, WORD code, LRESULT *lResult)
{ {
struct spinbox *s = (struct spinbox *) c; struct spinbox *s = (struct spinbox *) c;
BOOL neededCap = FALSE;
LRESULT val;
if (code != EN_CHANGE) if (code != EN_CHANGE)
return FALSE; return FALSE;
// This verifies the value put in, capping it automatically. if (s->inhibitChanged)
// We don't need to worry about checking for an error; that flag should really be called "did we have to cap?". return FALSE;
// We DO need to set the value in case of a cap though. // value() does the work for us
// TODO if we have change events, we need to make sure doing this doesn't trigger a double event value(s);
// TODO wine only? (*(s->onChanged))(uiSpinbox(s), s->onChangedData);
val = SendMessageW(s->updown, UDM_GETPOS32, 0, (LPARAM) (&neededCap)); return TRUE;
if (neededCap)
SendMessageW(s->updown, UDM_SETPOS32, 0, (LPARAM) val);
return FALSE;
} }
static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult) static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult)
@ -86,6 +106,27 @@ static void spinboxResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width,
recreateUpDown(s); recreateUpDown(s);
} }
// TODO does it go here relative of other things?
static void defaultOnChanged(uiSpinbox *s, void *data)
{
// do nothing
}
static intmax_t spinboxValue(uiSpinbox *ss)
{
struct spinbox *s = (struct spinbox *) ss;
return value(s);
}
static void spinboxOnChanged(uiSpinbox *ss, void (*f)(uiSpinbox *, void *), void *data)
{
struct spinbox *s = (struct spinbox *) ss;
s->onChanged = f;
s->onChangedData = data;
}
uiSpinbox *uiNewSpinbox(void) uiSpinbox *uiNewSpinbox(void)
{ {
struct spinbox *s; struct spinbox *s;
@ -111,9 +152,14 @@ uiSpinbox *uiNewSpinbox(void)
recreateUpDown(s); recreateUpDown(s);
s->onChanged = defaultOnChanged;
uiControl(s)->PreferredSize = spinboxPreferredSize; uiControl(s)->PreferredSize = spinboxPreferredSize;
s->baseResize = uiControl(s)->Resize; s->baseResize = uiControl(s)->Resize;
uiControl(s)->Resize = spinboxResize; uiControl(s)->Resize = spinboxResize;
uiSpinbox(s)->Value = spinboxValue;
uiSpinbox(s)->OnChanged = spinboxOnChanged;
return uiSpinbox(s); return uiSpinbox(s);
} }