2015-05-20 09:29:57 -05:00
// 20 may 2015
# include "uipriv_windows.h"
2015-05-20 10:22:29 -05:00
// TODOs
2015-05-20 12:43:29 -05:00
// - investigate overriding WM_ERASEBKGND to simulate TBS_TRANSPARENTBKGND; windows xp tries to do this it seems for tab controls but doesn't really do a good job of it
2015-05-20 12:25:45 -05:00
// - wine does not clamp TBM_SETPOS
2015-05-20 10:22:29 -05:00
2015-05-20 09:29:57 -05:00
struct slider {
uiSlider s ;
HWND hwnd ;
void ( * baseResize ) ( uiControl * , intmax_t , intmax_t , intmax_t , intmax_t , uiSizing * ) ;
void ( * onChanged ) ( uiSlider * , void * ) ;
void * onChangedData ;
2015-05-29 17:03:24 -05:00
void ( * baseCommitDestroy ) ( uiControl * ) ;
2015-05-20 09:29:57 -05:00
} ;
2015-05-29 17:03:24 -05:00
uiDefineControlType ( uiSlider , uiTypeSlider , struct slider )
2015-05-21 13:52:21 -05:00
static BOOL onWM_HSCROLL ( uiControl * c , HWND hwnd , WORD code , LRESULT * lResult )
2015-05-20 09:29:57 -05:00
{
struct slider * s = ( struct slider * ) c ;
( * ( s - > onChanged ) ) ( uiSlider ( s ) , s - > onChangedData ) ;
2015-05-20 10:22:29 -05:00
* lResult = 0 ;
2015-05-20 09:29:57 -05:00
return TRUE ;
}
2015-05-29 17:03:24 -05:00
static void sliderCommitDestroy ( uiControl * c )
2015-05-20 09:29:57 -05:00
{
2015-05-29 17:03:24 -05:00
struct slider * s = ( struct slider * ) c ;
2015-05-20 09:29:57 -05:00
2015-05-21 12:04:57 -05:00
uiWindowsUnregisterWM_HSCROLLHandler ( s - > hwnd ) ;
2015-05-29 17:03:24 -05:00
( * ( s - > baseCommitDestroy ) ) ( uiControl ( s ) ) ;
2015-05-20 09:29:57 -05:00
}
2015-05-29 18:48:27 -05:00
static uintptr_t sliderHandle ( uiControl * c )
{
struct slider * s = ( struct slider * ) c ;
return ( uintptr_t ) ( s - > hwnd ) ;
}
2015-05-20 09:29:57 -05:00
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
2015-05-20 12:43:29 -05:00
# define sliderWidth 107 /* this is actually the shorter progress bar width, but Microsoft doesn't indicate a width */
# define sliderHeight 15
2015-05-20 09:29:57 -05:00
static void sliderPreferredSize ( uiControl * c , uiSizing * d , intmax_t * width , intmax_t * height )
{
2015-05-20 12:43:29 -05:00
* width = uiWindowsDlgUnitsToX ( sliderWidth , d - > Sys - > BaseX ) ;
* height = uiWindowsDlgUnitsToY ( sliderHeight , d - > Sys - > BaseY ) ;
2015-05-20 09:29:57 -05:00
}
// 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 ) ;
}
2015-05-20 11:24:06 -05:00
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 ) ;
}
2015-05-20 09:29:57 -05:00
static void sliderOnChanged ( uiSlider * ss , void ( * f ) ( uiSlider * , void * ) , void * data )
{
struct slider * s = ( struct slider * ) ss ;
s - > onChanged = f ;
s - > onChangedData = data ;
}
2015-05-20 12:25:45 -05:00
uiSlider * uiNewSlider ( intmax_t min , intmax_t max )
2015-05-20 09:29:57 -05:00
{
struct slider * s ;
2015-05-29 17:03:24 -05:00
s = ( struct slider * ) uiWindowsNewSingleHWNDControl ( uiTypeSlider ( ) ) ;
s - > hwnd = uiWindowsNewSingleHWNDControl ( 0 ,
TRACKBAR_CLASSW , L " " ,
// TODO TBS_TRANSPARENTBKGND when making Vista-only
TBS_HORZ | TBS_TOOLTIPS | WS_TABSTOP ,
hInstance , NULL ,
TRUE ) ;
2015-05-21 12:04:57 -05:00
uiWindowsRegisterWM_HSCROLLHandler ( s - > hwnd , onWM_HSCROLL , uiControl ( s ) ) ;
2015-05-20 09:29:57 -05:00
2015-05-20 12:25:45 -05:00
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 ) ;
2015-05-20 09:29:57 -05:00
s - > onChanged = defaultOnChanged ;
2015-05-29 18:48:27 -05:00
uiControl ( s ) - > Handle = sliderHandle ;
2015-05-20 09:29:57 -05:00
uiControl ( s ) - > PreferredSize = sliderPreferredSize ;
2015-05-29 17:03:24 -05:00
s - > baseCommitDestroy = uiControl ( s ) - > CommitDestroy ;
uiControl ( s ) - > CommitDestroy = sliderCommitDestroy ;
2015-05-20 09:29:57 -05:00
uiSlider ( s ) - > Value = sliderValue ;
2015-05-20 11:24:06 -05:00
uiSlider ( s ) - > SetValue = sliderSetValue ;
2015-05-20 09:29:57 -05:00
uiSlider ( s ) - > OnChanged = sliderOnChanged ;
return uiSlider ( s ) ;
}