2015-05-22 09:36:24 -05:00
// 22 may 2015
# include "uipriv_windows.h"
struct datetimepicker {
uiDateTimePicker d ;
HWND hwnd ;
} ;
2015-05-29 17:03:24 -05:00
uiDefineControlType ( uiDateTimePicker , uiTypeDateTimePicker , struct datetimepicker )
2015-05-22 09:36:24 -05:00
2015-05-29 18:48:27 -05:00
static uintptr_t datetimepickerHandle ( uiControl * c )
{
struct datetimepicker * d = ( struct datetimepicker * ) c ;
return ( uintptr_t ) ( d - > hwnd ) ;
}
2015-05-22 09:36:24 -05:00
// TODO
2015-06-01 15:16:01 -05:00
// TODO DTM_GETIDEALSIZE results in something too big
2015-05-22 09:36:24 -05:00
// 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 datetimepickerPreferredSize ( uiControl * c , uiSizing * d , intmax_t * width , intmax_t * height )
{
* width = uiWindowsDlgUnitsToX ( entryWidth , d - > Sys - > BaseX ) ;
* height = uiWindowsDlgUnitsToY ( entryHeight , d - > Sys - > BaseY ) ;
}
2015-05-22 12:24:07 -05:00
uiDateTimePicker * finishNewDateTimePicker ( DWORD style , WCHAR * format )
2015-05-22 09:36:24 -05:00
{
struct datetimepicker * d ;
2015-05-29 19:53:12 -05:00
d = ( struct datetimepicker * ) uiWindowsNewSingleHWNDControl ( uiTypeDateTimePicker ( ) ) ;
2015-05-22 09:36:24 -05:00
2015-06-02 11:16:14 -05:00
d - > hwnd = uiWindowsUtilCreateControlHWND ( WS_EX_CLIENTEDGE ,
2015-05-29 17:03:24 -05:00
DATETIMEPICK_CLASSW , L " " ,
style | WS_TABSTOP ,
hInstance , NULL ,
TRUE ) ;
2015-05-22 09:36:24 -05:00
2015-05-22 12:24:07 -05:00
if ( format ! = NULL )
if ( SendMessageW ( d - > hwnd , DTM_SETFORMAT , 0 , ( LPARAM ) format ) = = 0 )
logLastError ( " error applying format string to date/time picker in finishNewDateTimePicker() " ) ;
2015-05-29 18:48:27 -05:00
uiControl ( d ) - > Handle = datetimepickerHandle ;
2015-05-22 09:36:24 -05:00
uiControl ( d ) - > PreferredSize = datetimepickerPreferredSize ;
return uiDateTimePicker ( d ) ;
}
2015-06-01 08:48:30 -05:00
# define GLI(what, buf, n) GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, what, buf, n)
2015-05-22 12:24:07 -05:00
// Windows has no combined date/time prebuilt constant; we have to build the format string ourselves
2015-06-02 10:56:44 -05:00
// Fortunately, because the date/time picker (on Vista, at least) does NOT respond to date/time format changes with its standard format styles, we only need to do this when creating the control as well.
2015-06-03 11:35:02 -05:00
// TODO really we need to send any WM_WININICHANGE messages back...
2015-05-22 09:36:24 -05:00
uiDateTimePicker * uiNewDateTimePicker ( void )
{
2015-05-22 12:24:07 -05:00
WCHAR * date , * time , * datetime ;
int ndate , ntime ;
int n ;
uiDateTimePicker * dtp ;
// TODO verify that this always returns a century year
ndate = GLI ( LOCALE_SSHORTDATE , NULL , 0 ) ;
if ( ndate = = 0 )
logLastError ( " error getting date string length in uiNewDateTimePicker() " ) ;
date = ( WCHAR * ) uiAlloc ( ndate * sizeof ( WCHAR ) , " WCHAR[] " ) ;
if ( GLI ( LOCALE_SSHORTDATE , date , ndate ) = = 0 )
logLastError ( " error geting date string in uiNewDateTimePicker() " ) ;
ntime = GLI ( LOCALE_STIMEFORMAT , NULL , 0 ) ;
if ( ndate = = 0 )
logLastError ( " error getting time string length in uiNewDateTimePicker() " ) ;
time = ( WCHAR * ) uiAlloc ( ntime * sizeof ( WCHAR ) , " WCHAR[] " ) ;
if ( GLI ( LOCALE_STIMEFORMAT , time , ntime ) = = 0 )
logLastError ( " error geting time string in uiNewDateTimePicker() " ) ;
n = _scwprintf ( L " %s %s " , date , time ) ;
datetime = ( WCHAR * ) uiAlloc ( ( n + 1 ) * sizeof ( WCHAR ) , " WCHAR[] " ) ;
snwprintf ( datetime , n + 1 , L " %s %s " , date , time ) ;
dtp = finishNewDateTimePicker ( 0 , datetime ) ;
uiFree ( datetime ) ;
uiFree ( time ) ;
uiFree ( date ) ;
return dtp ;
2015-05-22 09:36:24 -05:00
}
uiDateTimePicker * uiNewDatePicker ( void )
{
2015-05-22 12:24:07 -05:00
return finishNewDateTimePicker ( DTS_SHORTDATECENTURYFORMAT , NULL ) ;
2015-05-22 09:36:24 -05:00
}
uiDateTimePicker * uiNewTimePicker ( void )
{
2015-05-22 12:24:07 -05:00
return finishNewDateTimePicker ( DTS_TIMEFORMAT , NULL ) ;
2015-05-22 09:36:24 -05:00
}