2015-05-22 16:41:36 -05:00
// 22 may 2015
# include "uipriv_windows.h"
// see http://stackoverflow.com/questions/25494914/is-there-something-like-cdn-filecancel-analogous-to-cdn-fileok-for-getting-when#comment40420049_25494914
struct dialogDisableWindow {
HWND hwnd ;
uintmax_t n ;
2015-05-31 10:01:10 -05:00
BOOL prevstate ;
2015-05-22 16:41:36 -05:00
UT_hash_handle hh ;
} ;
static struct dialogDisableWindow * windows = NULL ;
void dialogHelperRegisterWindow ( HWND hwnd )
{
struct dialogDisableWindow * d ;
HASH_FIND_PTR ( windows , & hwnd , d ) ;
if ( d ! = NULL )
complain ( " window handle %p already register in dialogHelperRegisterWindow() " , hwnd ) ;
d = uiNew ( struct dialogDisableWindow ) ;
d - > hwnd = hwnd ;
HASH_ADD_PTR ( windows , hwnd , d ) ;
}
void dialogHelperUnregisterWindow ( HWND hwnd )
{
struct dialogDisableWindow * d ;
HASH_FIND_PTR ( windows , & hwnd , d ) ;
if ( d = = NULL )
complain ( " window handle %p not registered in dialogHelperUnregisterWindow() " , hwnd ) ;
HASH_DEL ( windows , d ) ;
uiFree ( d ) ;
}
static void dialogBegin ( void )
{
struct dialogDisableWindow * d ;
2015-05-31 10:01:10 -05:00
BOOL prevstate ;
2015-05-22 16:41:36 -05:00
for ( d = windows ; d ! = NULL ; d = d - > hh . next ) {
2015-05-31 10:01:10 -05:00
prevstate = EnableWindow ( d - > hwnd , FALSE ) ;
// store the previous state in case the window was already disabled by the user
// (TODO test)
// note the !; EnableWindow() returns TRUE if window was previously /disabled/
if ( d - > n = = 0 )
d - > prevstate = ! prevstate ;
2015-05-22 16:41:36 -05:00
d - > n + + ;
}
}
static void dialogEnd ( void )
{
struct dialogDisableWindow * d ;
for ( d = windows ; d ! = NULL ; d = d - > hh . next ) {
d - > n - - ;
if ( d - > n = = 0 )
2015-05-31 10:01:10 -05:00
EnableWindow ( d - > hwnd , d - > prevstate ) ;
2015-05-22 16:41:36 -05:00
}
}
# define dialogHelperClass L"libui_dialogHelperClass"
static LRESULT CALLBACK dialogHelperWndProc ( HWND hwnd , UINT uMsg , WPARAM wParam , LPARAM lParam )
{
switch ( uMsg ) {
case WM_CREATE :
dialogBegin ( ) ;
break ;
case WM_ENABLE :
if ( wParam ! = ( WPARAM ) FALSE ) // enabling
dialogEnd ( ) ;
break ;
}
return DefWindowProcW ( hwnd , uMsg , wParam , lParam ) ;
}
ATOM initDialogHelper ( HICON hDefaultIcon , HCURSOR hDefaultCursor )
{
WNDCLASSW wc ;
ZeroMemory ( & wc , sizeof ( WNDCLASSW ) ) ;
wc . lpszClassName = dialogHelperClass ;
wc . lpfnWndProc = dialogHelperWndProc ;
wc . hInstance = hInstance ;
wc . hIcon = hDefaultIcon ;
wc . hCursor = hDefaultCursor ;
wc . hbrBackground = ( HBRUSH ) ( COLOR_BTNFACE + 1 ) ;
return RegisterClassW ( & wc ) ;
}
2015-05-22 18:14:25 -05:00
HWND beginDialogHelper ( void )
2015-05-22 16:41:36 -05:00
{
HWND hwnd ;
hwnd = CreateWindowExW ( 0 ,
dialogHelperClass , L " libui dialog helper " ,
WS_OVERLAPPEDWINDOW ,
0 , 0 , 100 , 100 ,
NULL , NULL , hInstance , NULL ) ;
if ( hwnd = = NULL )
logLastError ( " error creating dialog helper in beginDialogHelper() " ) ;
2015-05-22 18:14:25 -05:00
return hwnd ;
2015-05-22 16:41:36 -05:00
}
2015-05-22 18:14:25 -05:00
void endDialogHelper ( HWND hwnd )
2015-05-22 16:41:36 -05:00
{
if ( DestroyWindow ( hwnd ) = = 0 )
logLastError ( " error cleaning up after dialog helper in endDialogHelper() " ) ;
}