2016-04-23 15:47:44 -05:00
// 21 april 2016
2015-05-14 08:43:25 -05:00
/*
This file assumes that you have included < windows . h > and " ui.h " beforehand . It provides API - specific functions for interfacing with foreign controls in Windows .
*/
2015-08-28 20:42:21 -05:00
# ifndef __LIBUI_UI_WINDOWS_H__
# define __LIBUI_UI_WINDOWS_H__
2015-11-16 09:55:44 -06:00
# ifdef __cplusplus
extern " C " {
# endif
2015-08-29 19:38:12 -05:00
typedef struct uiWindowsSizing uiWindowsSizing ;
2015-08-28 20:42:21 -05:00
typedef struct uiWindowsControl uiWindowsControl ;
struct uiWindowsControl {
uiControl c ;
void ( * CommitSetParent ) ( uiWindowsControl * , HWND ) ;
2015-08-29 19:38:12 -05:00
void ( * MinimumSize ) ( uiWindowsControl * , uiWindowsSizing * , intmax_t * , intmax_t * ) ;
2015-08-30 17:24:57 -05:00
void ( * Relayout ) ( uiWindowsControl * , intmax_t , intmax_t , intmax_t , intmax_t ) ;
2015-09-01 20:36:33 -05:00
void ( * AssignControlIDZOrder ) ( uiWindowsControl * , LONG_PTR * , HWND * ) ;
2015-09-02 11:59:57 -05:00
void ( * ArrangeChildrenControlIDsZOrder ) ( uiWindowsControl * ) ;
2015-08-28 20:42:21 -05:00
} ;
2016-04-24 13:15:56 -05:00
# define uiWindowsControl(this) ((uiWindowsControl *) (this))
2015-08-28 20:42:21 -05:00
// TODO document
2015-08-30 17:24:57 -05:00
_UI_EXTERN void uiWindowsControlQueueRelayout ( uiWindowsControl * ) ;
2015-08-28 20:42:21 -05:00
// TODO document
2016-04-24 13:15:56 -05:00
# define uiWindowsDefineControlWithOnDestroy(type, onDestroy) \
2015-08-28 20:42:21 -05:00
static void _ # # type # # CommitDestroy ( uiControl * c ) \
{ \
2016-04-20 18:39:20 -05:00
type * me = type ( c ) ; \
2015-08-28 20:42:21 -05:00
onDestroy ; \
2016-04-20 18:39:20 -05:00
uiWindowsEnsureDestroyWindow ( me - > hwnd ) ; \
2015-08-28 20:42:21 -05:00
} \
static uintptr_t _ # # type # # Handle ( uiControl * c ) \
{ \
return ( uintptr_t ) ( type ( c ) - > hwnd ) ; \
} \
static void _ # # type # # ContainerUpdateState ( uiControl * c ) \
{ \
/* do nothing */ \
} \
static void _ # # type # # CommitSetParent ( uiWindowsControl * c , HWND parent ) \
{ \
uiWindowsEnsureSetParent ( type ( c ) - > hwnd , parent ) ; \
} \
2015-08-30 17:24:57 -05:00
static void _ # # type # # Relayout ( uiWindowsControl * c , intmax_t x , intmax_t y , intmax_t width , intmax_t height ) \
2015-08-28 20:42:21 -05:00
{ \
2016-04-23 16:31:59 -05:00
uiWindowsEnsureMoveWindowDuringResize ( type ( c ) - > hwnd , x , y , width , height ) ; \
2015-08-29 19:38:12 -05:00
} \
2015-09-01 20:36:33 -05:00
static void minimumSize ( uiWindowsControl * c , uiWindowsSizing * d , intmax_t * width , intmax_t * height ) ; \
static void _ # # type # # AssignControlIDZOrder ( uiWindowsControl * c , LONG_PTR * controlID , HWND * insertAfter ) \
{ \
uiWindowsEnsureAssignControlIDZOrder ( type ( c ) - > hwnd , * controlID , * insertAfter ) ; \
( * controlID ) + + ; \
* insertAfter = type ( c ) - > hwnd ; \
2015-09-02 11:59:57 -05:00
} \
static void _ # # type # # ArrangeChildrenControlIDsZOrder ( uiWindowsControl * c ) \
{ \
/* do nothing */ \
2015-09-01 20:36:33 -05:00
}
2015-08-28 20:42:21 -05:00
2016-04-24 13:15:56 -05:00
# define uiWindowsDefineControl(type) \
uiWindowsDefineControlWithOnDestroy ( type , ( void ) me ; )
2015-08-28 20:42:21 -05:00
# define uiWindowsFinishNewControl(variable, type) \
uiControl ( variable ) - > CommitDestroy = _ # # type # # CommitDestroy ; \
uiControl ( variable ) - > Handle = _ # # type # # Handle ; \
uiControl ( variable ) - > ContainerUpdateState = _ # # type # # ContainerUpdateState ; \
uiWindowsControl ( variable ) - > CommitSetParent = _ # # type # # CommitSetParent ; \
2015-08-29 19:38:12 -05:00
uiWindowsControl ( variable ) - > MinimumSize = minimumSize ; \
2015-08-28 20:42:21 -05:00
uiWindowsControl ( variable ) - > Relayout = _ # # type # # Relayout ; \
2015-09-01 20:36:33 -05:00
uiWindowsControl ( variable ) - > AssignControlIDZOrder = _ # # type # # AssignControlIDZOrder ; \
2015-09-02 11:59:57 -05:00
uiWindowsControl ( variable ) - > ArrangeChildrenControlIDsZOrder = _ # # type # # ArrangeChildrenControlIDsZOrder ; \
2015-08-28 20:42:21 -05:00
uiWindowsFinishControl ( uiControl ( variable ) ) ;
2016-04-23 15:47:44 -05:00
// TODO document
2015-08-28 20:42:21 -05:00
_UI_EXTERN HWND uiWindowsEnsureCreateControlHWND ( DWORD dwExStyle , LPCWSTR lpClassName , LPCWSTR lpWindowName , DWORD dwStyle , HINSTANCE hInstance , LPVOID lpParam , BOOL useStandardControlFont ) ;
2016-04-23 15:47:44 -05:00
// TODO document
2015-08-28 20:42:21 -05:00
_UI_EXTERN void uiWindowsEnsureDestroyWindow ( HWND hwnd ) ;
2016-04-23 15:47:44 -05:00
// TODO document
_UI_EXTERN void uiWindowsEnsureSetParent ( HWND hwnd , HWND parent ) ;
2015-08-30 17:24:57 -05:00
2016-04-23 15:47:44 -05:00
// TODO document
2015-09-01 20:36:33 -05:00
_UI_EXTERN void uiWindowsEnsureAssignControlIDZOrder ( HWND hwnd , LONG_PTR controlID , HWND insertAfter ) ;
2016-04-23 15:47:44 -05:00
// TODO document
_UI_EXTERN char * uiWindowsWindowText ( HWND hwnd ) ;
_UI_EXTERN void uiWindowsSetWindowText ( HWND hwnd , const char * text ) ;
// TODO document
_UI_EXTERN intmax_t uiWindowsWindowTextWidth ( HWND hwnd ) ;
// TODO document
// TODO keep uiWindowsControl?
_UI_EXTERN void uiWindowsControlQueueRelayout ( uiWindowsControl * c ) ;
// TODO document
// TODO point out this should only be used in a resize cycle
_UI_EXTERN void uiWindowsEnsureMoveWindowDuringResize ( HWND hwnd , intmax_t x , intmax_t y , intmax_t width , intmax_t height ) ;
// TODO document
_UI_EXTERN void uiWindowsRegisterWM_COMMANDHandler ( HWND hwnd , BOOL ( * handler ) ( uiControl * , HWND , WORD , LRESULT * ) , uiControl * c ) ;
_UI_EXTERN void uiWindowsUnregisterWM_COMMANDHandler ( HWND hwnd ) ;
// TODO document
_UI_EXTERN void uiWindowsRegisterWM_NOTIFYHandler ( HWND hwnd , BOOL ( * handler ) ( uiControl * , HWND , NMHDR * , LRESULT * ) , uiControl * c ) ;
_UI_EXTERN void uiWindowsUnregisterWM_NOTIFYHandler ( HWND hwnd ) ;
// TODO document
_UI_EXTERN void uiWindowsRegisterWM_HSCROLLHandler ( HWND hwnd , BOOL ( * handler ) ( uiControl * , HWND , WORD , LRESULT * ) , uiControl * c ) ;
_UI_EXTERN void uiWindowsUnregisterWM_HSCROLLHandler ( HWND hwnd ) ;
// TODO document
_UI_EXTERN void uiWindowsRegisterReceiveWM_WININICHANGE ( HWND hwnd ) ;
_UI_EXTERN void uiWindowsUnregisterReceiveWM_WININICHANGE ( HWND hwnd ) ;
// everything below here is TODO
_UI_EXTERN void uiWindowsFinishControl ( uiControl * c ) ;
_UI_EXTERN void uiWindowsRearrangeControlIDsZOrder ( uiControl * c ) ;
2015-09-02 11:59:57 -05:00
2015-08-28 20:42:21 -05:00
////////////////////////////////////////////
/////////////////// TODO ///////////////////
////////////////////////////////////////////
2015-06-05 15:56:43 -05:00
// These provide single-HWND implementations of uiControl methods you can use in yours.
2015-05-29 13:56:11 -05:00
_UI_EXTERN void uiWindowsUtilDestroy ( HWND hwnd ) ;
_UI_EXTERN void uiWindowsUtilSetParent ( HWND hwnd , uiControl * parent ) ;
2015-06-01 12:02:43 -05:00
_UI_EXTERN void uiWindowsUtilShow ( HWND hwnd ) ;
2015-05-29 13:56:11 -05:00
_UI_EXTERN void uiWindowsUtilHide ( HWND hwnd ) ;
2015-06-01 12:02:43 -05:00
_UI_EXTERN void uiWindowsUtilEnable ( HWND hwnd ) ;
2015-05-29 13:56:11 -05:00
_UI_EXTERN void uiWindowsUtilDisable ( HWND hwnd ) ;
2015-05-30 16:17:20 -05:00
_UI_EXTERN uintptr_t uiWindowsUtilStartZOrder ( HWND hwnd ) ;
_UI_EXTERN uintptr_t uiWindowsUtilSetZOrder ( HWND hwnd , uintptr_t insertAfter ) ;
_UI_EXTERN int uiWindowsUtilHasTabStops ( HWND hwnd ) ;
2015-06-05 15:56:43 -05:00
2015-05-14 08:43:25 -05:00
// This contains the Windows-specific parts of the uiSizing structure.
// BaseX and BaseY are the dialog base units.
// InternalLeading is the standard control font's internal leading; labels in uiForms use this for correct Y positioning.
2015-05-18 11:04:52 -05:00
// CoordFrom and CoordTo are the window handles to convert coordinates passed to uiControlResize() from and to (viaa MapWindowRect()) before passing to one of the Windows API resizing functions.
2015-08-29 19:38:12 -05:00
struct uiWindowsSizing {
2015-08-31 16:50:23 -05:00
intmax_t XPadding ;
intmax_t YPadding ;
2015-05-14 08:43:25 -05:00
int BaseX ;
int BaseY ;
LONG InternalLeading ;
2015-05-18 11:04:52 -05:00
HWND CoordFrom ;
HWND CoordTo ;
2015-05-14 08:43:25 -05:00
} ;
2015-09-01 06:21:18 -05:00
// Use these to create and destroy uiWindowsSizings.
_UI_EXTERN uiWindowsSizing * uiWindowsNewSizing ( HWND hwnd ) ;
_UI_EXTERN void uiWindowsFreeSizing ( uiWindowsSizing * d ) ;
2015-05-14 08:43:25 -05:00
// Use these in your preferredSize() implementation with baseX and baseY.
# define uiWindowsDlgUnitsToX(dlg, baseX) MulDiv((dlg), baseX, 4)
# define uiWindowsDlgUnitsToY(dlg, baseY) MulDiv((dlg), baseY, 8)
// and use this if you need the text of the window width
_UI_EXTERN intmax_t uiWindowsWindowTextWidth ( HWND hwnd ) ;
2015-06-03 14:49:44 -05:00
// these functions get and set the window text for a single HWND
2015-05-14 08:43:25 -05:00
// the value returned should be freed with uiFreeText()
2015-06-03 13:54:25 -05:00
_UI_EXTERN char * uiWindowsUtilText ( HWND ) ;
_UI_EXTERN void uiWindowsUtilSetText ( HWND , const char * ) ;
2015-05-14 08:43:25 -05:00
2015-06-05 15:56:43 -05:00
// These provide event handling.
// For WM_COMMAND, the WORD parameter is the notification code.
// For WM_HSCROLL, the WORD parameter is the scroll operation.
2015-08-29 19:38:12 -05:00
_UI_EXTERN void uiWindowsRegisterWM_COMMANDHandler ( HWND , BOOL ( * ) ( uiControl * , HWND , WORD , LRESULT * ) , uiControl * ) ;
_UI_EXTERN void uiWindowsRegisterWM_NOTIFYHandler ( HWND , BOOL ( * ) ( uiControl * , HWND , NMHDR * , LRESULT * ) , uiControl * ) ;
_UI_EXTERN void uiWindowsRegisterWM_HSCROLLHandler ( HWND , BOOL ( * ) ( uiControl * , HWND , WORD , LRESULT * ) , uiControl * ) ;
_UI_EXTERN void uiWindowsUnregisterWM_COMMANDHandler ( HWND ) ;
_UI_EXTERN void uiWindowsUnregisterWM_NOTIFYHandler ( HWND ) ;
_UI_EXTERN void uiWindowsUnregisterWM_HSCROLLHandler ( HWND ) ;
_UI_EXTERN void uiWindowsRegisterReceiveWM_WININICHANGE ( HWND ) ;
_UI_EXTERN void uiWindowsUnregisterReceiveWM_WININICHANGE ( HWND ) ;
2015-06-05 15:56:43 -05:00
2015-11-16 09:55:44 -06:00
# ifdef __cplusplus
}
# endif
2015-05-14 08:43:25 -05:00
# endif