Added uiSlider.
This commit is contained in:
parent
854f036197
commit
e1744b17a2
|
@ -2,6 +2,7 @@
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
static uiSpinbox *spinbox;
|
static uiSpinbox *spinbox;
|
||||||
|
static uiSlider *slider;
|
||||||
static uiProgressBar *pbar;
|
static uiProgressBar *pbar;
|
||||||
|
|
||||||
#define CHANGED(what) \
|
#define CHANGED(what) \
|
||||||
|
@ -13,6 +14,7 @@ static uiProgressBar *pbar;
|
||||||
uiProgressBarSetValue(pbar, value); \
|
uiProgressBarSetValue(pbar, value); \
|
||||||
}
|
}
|
||||||
CHANGED(Spinbox)
|
CHANGED(Spinbox)
|
||||||
|
CHANGED(Slider)
|
||||||
|
|
||||||
uiBox *makePage4(void)
|
uiBox *makePage4(void)
|
||||||
{
|
{
|
||||||
|
@ -24,6 +26,10 @@ uiBox *makePage4(void)
|
||||||
uiSpinboxOnChanged(spinbox, onSpinboxChanged, NULL);
|
uiSpinboxOnChanged(spinbox, onSpinboxChanged, NULL);
|
||||||
uiBoxAppend(page4, uiControl(spinbox), 0);
|
uiBoxAppend(page4, uiControl(spinbox), 0);
|
||||||
|
|
||||||
|
slider = uiNewSlider();
|
||||||
|
uiSliderOnChanged(slider, onSliderChanged, NULL);
|
||||||
|
uiBoxAppend(page4, uiControl(slider), 0);
|
||||||
|
|
||||||
pbar = uiNewProgressBar();
|
pbar = uiNewProgressBar();
|
||||||
uiBoxAppend(page4, uiControl(pbar), 0);
|
uiBoxAppend(page4, uiControl(pbar), 0);
|
||||||
|
|
||||||
|
|
|
@ -154,6 +154,13 @@ interface ProgressBar from Control {
|
||||||
};
|
};
|
||||||
func NewProgressBar(void) *ProgressBar;
|
func NewProgressBar(void) *ProgressBar;
|
||||||
|
|
||||||
|
interface Slider from Control {
|
||||||
|
func Value(void) intmax_t;
|
||||||
|
// TODO SetValue()
|
||||||
|
func OnChanged(f *func(s *Slider, data *void), data *void);
|
||||||
|
};
|
||||||
|
func NewSlider(void) *Slider;
|
||||||
|
|
||||||
interface Menu {
|
interface Menu {
|
||||||
func AppendItem(name *const char) *MenuItem;
|
func AppendItem(name *const char) *MenuItem;
|
||||||
func AppendCheckItem(name *const char) *MenuItem;
|
func AppendCheckItem(name *const char) *MenuItem;
|
||||||
|
|
|
@ -16,6 +16,7 @@ osCFILES = \
|
||||||
windows/parent.c \
|
windows/parent.c \
|
||||||
windows/progressbar.c \
|
windows/progressbar.c \
|
||||||
windows/resize.c \
|
windows/resize.c \
|
||||||
|
windows/slider.c \
|
||||||
windows/spinbox.c \
|
windows/spinbox.c \
|
||||||
windows/tab.c \
|
windows/tab.c \
|
||||||
windows/text.c \
|
windows/text.c \
|
||||||
|
|
|
@ -147,6 +147,7 @@ void uiWindowsMakeControl(uiControl *c, uiWindowsMakeControlParams *p)
|
||||||
logLastError("error creating control in uiWindowsMakeControl()");
|
logLastError("error creating control in uiWindowsMakeControl()");
|
||||||
s->onWM_COMMAND = p->onWM_COMMAND;
|
s->onWM_COMMAND = p->onWM_COMMAND;
|
||||||
s->onWM_NOTIFY = p->onWM_NOTIFY;
|
s->onWM_NOTIFY = p->onWM_NOTIFY;
|
||||||
|
s->onWM_HSCROLL = p->onWM_HSCROLL;
|
||||||
|
|
||||||
s->onDestroy = p->onDestroy;
|
s->onDestroy = p->onDestroy;
|
||||||
s->onDestroyData = p->onDestroyData;
|
s->onDestroyData = p->onDestroyData;
|
||||||
|
|
|
@ -0,0 +1,105 @@
|
||||||
|
// 20 may 2015
|
||||||
|
#include "uipriv_windows.h"
|
||||||
|
|
||||||
|
struct slider {
|
||||||
|
uiSlider s;
|
||||||
|
HWND hwnd;
|
||||||
|
void (*baseResize)(uiControl *, intmax_t, intmax_t, intmax_t, intmax_t, uiSizing *);
|
||||||
|
void (*onChanged)(uiSlider *, void *);
|
||||||
|
void *onChangedData;
|
||||||
|
};
|
||||||
|
|
||||||
|
static BOOL onWM_COMMAND(uiControl *c, WORD code, LRESULT *lResult)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOL onWM_HSCROLL(uiControl *c, WORD code, LRESULT *lResult)
|
||||||
|
{
|
||||||
|
struct slider *s = (struct slider *) c;
|
||||||
|
|
||||||
|
(*(s->onChanged))(uiSlider(s), s->onChangedData);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void onDestroy(void *data)
|
||||||
|
{
|
||||||
|
struct slider *s = (struct slider *) data;
|
||||||
|
|
||||||
|
uiFree(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
||||||
|
#define entryWidth 107 /* this is actually the shorter progress bar width, but Microsoft only indicates as wide as necessary */
|
||||||
|
#define entryHeight 14
|
||||||
|
|
||||||
|
static void sliderPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
||||||
|
{
|
||||||
|
*width = uiWindowsDlgUnitsToX(entryWidth, d->Sys->BaseX);
|
||||||
|
*height = uiWindowsDlgUnitsToY(entryHeight, d->Sys->BaseY);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO does it go here relative of other things?
|
||||||
|
static void defaultOnChanged(uiSlider *s, void *data)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
static intmax_t sliderValue(uiSlider *ss)
|
||||||
|
{
|
||||||
|
struct slider *s = (struct slider *) ss;
|
||||||
|
|
||||||
|
return (intmax_t) SendMessageW(s->hwnd, TBM_GETPOS, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void sliderOnChanged(uiSlider *ss, void (*f)(uiSlider *, void *), void *data)
|
||||||
|
{
|
||||||
|
struct slider *s = (struct slider *) ss;
|
||||||
|
|
||||||
|
s->onChanged = f;
|
||||||
|
s->onChangedData = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
uiSlider *uiNewSlider(void)
|
||||||
|
{
|
||||||
|
struct slider *s;
|
||||||
|
uiWindowsMakeControlParams p;
|
||||||
|
|
||||||
|
s = uiNew(struct slider);
|
||||||
|
uiTyped(s)->Type = uiTypeSlider();
|
||||||
|
|
||||||
|
p.dwExStyle = 0;
|
||||||
|
p.lpClassName = TRACKBAR_CLASSW;
|
||||||
|
p.lpWindowName = L"";
|
||||||
|
// TODO TBS_TRANSPARENTBKGND when making Vista-only
|
||||||
|
p.dwStyle = TBS_HORZ | TBS_TOOLTIPS | WS_TABSTOP;
|
||||||
|
p.hInstance = hInstance;
|
||||||
|
p.lpParam = NULL;
|
||||||
|
p.useStandardControlFont = TRUE;
|
||||||
|
p.onWM_COMMAND = onWM_COMMAND;
|
||||||
|
p.onWM_NOTIFY = onWM_NOTIFY;
|
||||||
|
p.onWM_HSCROLL = onWM_HSCROLL;
|
||||||
|
p.onDestroy = onDestroy;
|
||||||
|
p.onDestroyData = s;
|
||||||
|
uiWindowsMakeControl(uiControl(s), &p);
|
||||||
|
|
||||||
|
s->hwnd = (HWND) uiControlHandle(uiControl(s));
|
||||||
|
|
||||||
|
SendMessageW(s->hwnd, TBM_SETRANGEMIN, (WPARAM) TRUE, (LPARAM) 0);
|
||||||
|
SendMessageW(s->hwnd, TBM_SETRANGEMAX, (WPARAM) TRUE, (LPARAM) 100);
|
||||||
|
|
||||||
|
s->onChanged = defaultOnChanged;
|
||||||
|
|
||||||
|
uiControl(s)->PreferredSize = sliderPreferredSize;
|
||||||
|
|
||||||
|
uiSlider(s)->Value = sliderValue;
|
||||||
|
uiSlider(s)->OnChanged = sliderOnChanged;
|
||||||
|
|
||||||
|
return uiSlider(s);
|
||||||
|
}
|
Loading…
Reference in New Issue