2015-08-30 11:25:53 -05:00
|
|
|
// 20 may 2015
|
2016-04-22 19:14:12 -05:00
|
|
|
#include "uipriv_windows.hpp"
|
2015-08-30 11:25:53 -05:00
|
|
|
|
|
|
|
struct uiSlider {
|
|
|
|
uiWindowsControl c;
|
|
|
|
HWND hwnd;
|
|
|
|
void (*onChanged)(uiSlider *, void *);
|
|
|
|
void *onChangedData;
|
|
|
|
};
|
|
|
|
|
|
|
|
uiWindowsDefineControlWithOnDestroy(
|
|
|
|
uiSlider, // type name
|
|
|
|
uiSliderType, // type function
|
2016-04-23 15:52:53 -05:00
|
|
|
uiWindowsUnregisterWM_HSCROLLHandler(me->hwnd); // on destroy
|
2015-08-30 11:25:53 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
static BOOL onWM_HSCROLL(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult)
|
|
|
|
{
|
|
|
|
uiSlider *s = uiSlider(c);
|
|
|
|
|
|
|
|
(*(s->onChanged))(s, s->onChangedData);
|
|
|
|
*lResult = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
|
|
|
#define sliderWidth 107 /* this is actually the shorter progress bar width, but Microsoft doesn't indicate a width */
|
|
|
|
#define sliderHeight 15
|
|
|
|
|
2015-08-31 16:50:23 -05:00
|
|
|
static void minimumSize(uiWindowsControl *c, uiWindowsSizing *d, intmax_t *width, intmax_t *height)
|
2015-08-30 11:25:53 -05:00
|
|
|
{
|
|
|
|
*width = uiWindowsDlgUnitsToX(sliderWidth, d->BaseX);
|
|
|
|
*height = uiWindowsDlgUnitsToY(sliderHeight, d->BaseY);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void defaultOnChanged(uiSlider *s, void *data)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
intmax_t uiSliderValue(uiSlider *s)
|
|
|
|
{
|
|
|
|
return (intmax_t) SendMessageW(s->hwnd, TBM_GETPOS, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiSliderSetValue(uiSlider *s, intmax_t value)
|
|
|
|
{
|
|
|
|
// don't use TBM_SETPOSNOTIFY; that triggers an event
|
|
|
|
SendMessageW(s->hwnd, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiSliderOnChanged(uiSlider *s, void (*f)(uiSlider *, void *), void *data)
|
|
|
|
{
|
|
|
|
s->onChanged = f;
|
|
|
|
s->onChangedData = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
uiSlider *uiNewSlider(intmax_t min, intmax_t max)
|
|
|
|
{
|
|
|
|
uiSlider *s;
|
|
|
|
|
|
|
|
s = (uiSlider *) uiNewControl(uiSliderType());
|
|
|
|
|
2015-08-31 11:33:44 -05:00
|
|
|
s->hwnd = uiWindowsEnsureCreateControlHWND(0,
|
2015-08-30 11:25:53 -05:00
|
|
|
TRACKBAR_CLASSW, L"",
|
|
|
|
TBS_HORZ | TBS_TOOLTIPS | TBS_TRANSPARENTBKGND | WS_TABSTOP,
|
|
|
|
hInstance, NULL,
|
|
|
|
TRUE);
|
|
|
|
|
|
|
|
uiWindowsRegisterWM_HSCROLLHandler(s->hwnd, onWM_HSCROLL, uiControl(s));
|
|
|
|
uiSliderOnChanged(s, defaultOnChanged, NULL);
|
|
|
|
|
|
|
|
SendMessageW(s->hwnd, TBM_SETRANGEMIN, (WPARAM) TRUE, (LPARAM) min);
|
|
|
|
SendMessageW(s->hwnd, TBM_SETRANGEMAX, (WPARAM) TRUE, (LPARAM) max);
|
|
|
|
SendMessageW(s->hwnd, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) min);
|
|
|
|
|
|
|
|
uiWindowsFinishNewControl(s, uiSlider);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|