2015-05-29 13:56:11 -05:00
|
|
|
// 27 may 2015
|
2015-05-14 18:28:30 -05:00
|
|
|
#include "uipriv_windows.h"
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
// TODO Edit ,s/Util/HWND/g ?
|
2015-05-14 18:28:30 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
HWND uiWindowsUtilCreateControlHWND(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, HINSTANCE hInstance, LPVOID lpParam, BOOL useStandardControlFont)
|
2015-05-14 18:28:30 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
HWND hwnd;
|
2015-05-14 18:28:30 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
hwnd = CreateWindowExW(dwExStyle,
|
|
|
|
lpClassName, lpWIndowName,
|
|
|
|
dwStyle | WS_CHILD | WS_VISIBLE,
|
|
|
|
0, 0,
|
|
|
|
// use a nonzero initial size just in case some control breaks with a zero initial size
|
|
|
|
100, 100,
|
|
|
|
utilWindow, NULL, hInstance, lpParam);
|
|
|
|
if (hwnd == NULL)
|
|
|
|
logLastError("error creating window in uiWindowsUtilCreateControlHWND()");
|
|
|
|
if (useStandardControlFont)
|
|
|
|
SendMessageW(hwnd, WM_SETFONT, (WPARAM) hMessageFont, (LPARAM) TRUE);
|
|
|
|
return hwnd;
|
2015-05-14 18:28:30 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
#define HWND(c) ((HWND) uiControlHandle((c)))
|
|
|
|
|
|
|
|
void uiWindowsUtilDestroy(HWND hwnd)
|
2015-05-14 18:28:30 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
if (DestroyWindow(hwnd) == 0)
|
|
|
|
logLastError("error destroying window in uiWindowsUtilDestroyWindow()");
|
|
|
|
}
|
2015-05-14 18:28:30 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
static void singleHWNDCommitDestroy(uiControl *c)
|
|
|
|
{
|
|
|
|
uiWindowsUtilDestroy(HWND(c));
|
2015-05-14 18:28:30 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
void uiWindowsUtilSetParent(HWND hwnd, uiControl *parent)
|
2015-05-14 18:28:30 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
HWND newParent;
|
2015-05-14 18:28:30 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
newParent = utilWindow;
|
|
|
|
if (parent != NULL)
|
|
|
|
newParent = HWND(parent);
|
|
|
|
if (SetParent(hwnd, newParent) == 0)
|
|
|
|
logLastError("error changing window parent in uiWindowsUtilSetParent()");
|
2015-05-14 18:28:30 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
static void singleHWNDCommitSetParent(uiControl *c, uiControl *parent)
|
2015-05-14 18:28:30 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
uiWindowsUtilSetParent(HWND(c), parent);
|
|
|
|
}
|
2015-05-14 18:28:30 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
void uiWindowsUtilResize(HWND hwnd, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
|
|
|
|
{
|
|
|
|
moveWindow(hwnd, x, y, width, height, d);
|
2015-05-14 18:28:30 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
static void singleHWNDResize(HWND hwnd, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
|
2015-05-14 18:28:30 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
uiWindowsUtilResize(HWND(c), x, y, width, height, d);
|
2015-05-14 18:28:30 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
static uiSizing *singleHWNDSizing(uiControl *c)
|
2015-05-14 18:28:30 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
// TODO change this to take a HWND and the parent
|
|
|
|
return uiWindowsSizing(c);
|
|
|
|
}
|
2015-05-14 18:28:30 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
void uiWIndowsUtilShow(HWND hwnd)
|
|
|
|
{
|
|
|
|
ShowWindow(hwnd, SW_SHOW);
|
2015-05-14 18:28:30 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
static void singleHWNDCommitShow(uiControl *c)
|
2015-05-14 18:28:30 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
uiWindowsUtilShow(HWND(c));
|
|
|
|
}
|
2015-05-14 18:28:30 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
void uiWindowsUtilHide(HWND hwnd)
|
|
|
|
{
|
|
|
|
ShowWindow(hwnd, SW_HIDE);
|
2015-05-15 17:34:17 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
static void singleHWNDCommitHide(uiControl *c)
|
2015-05-15 17:34:17 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
uiWindowsUtilHide(HWND(c));
|
|
|
|
}
|
2015-05-15 17:34:17 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
void uiWIndowsUtilEnable(HWND hwnd)
|
|
|
|
{
|
|
|
|
EnableWindow(hwnd, TRUE);
|
2015-05-15 17:34:17 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
static void singleHWNDCommitEnable(uiControl *c)
|
2015-05-15 17:34:17 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
uiWindowsUtilEnable(HWND(c));
|
|
|
|
}
|
2015-05-14 18:28:30 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
void uiWindowsUtilDisable(HWND hwnd)
|
|
|
|
{
|
|
|
|
EnableWindow(hwnd, FALSE);
|
2015-05-14 18:28:30 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
static void singleHWNDCommitDisable(uiControl *c)
|
2015-05-14 18:28:30 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
uiWindowsUtilDisable(HWND(c));
|
|
|
|
}
|
2015-05-14 18:28:30 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
void uiWindowsUtilSysFunc(HWND hwnd, uiControlSysFuncParams *p)
|
|
|
|
{
|
2015-05-14 18:28:30 -05:00
|
|
|
switch (p->Func) {
|
2015-05-29 13:56:11 -05:00
|
|
|
case uiControlSysFuncNop:
|
|
|
|
return;
|
2015-05-14 18:28:30 -05:00
|
|
|
case uiWindowsSysFuncHasTabStops:
|
2015-05-29 13:56:11 -05:00
|
|
|
if ((getStyle(hwnd) & WS_TABSTOP) != 0)
|
|
|
|
p->HasTabStops = TRUE;
|
2015-05-14 18:28:30 -05:00
|
|
|
return;
|
2015-05-16 00:45:20 -05:00
|
|
|
case uiWindowsSysFuncSetZOrder:
|
2015-05-29 13:56:11 -05:00
|
|
|
setWindowInsertAfter(hwnd, p->InsertAfter);
|
|
|
|
p->InsertAfter = hwnd;
|
2015-05-14 18:28:30 -05:00
|
|
|
return;
|
|
|
|
}
|
2015-05-29 13:56:11 -05:00
|
|
|
complain("unknown uiControlSysFunc() function %d in uiWindowsUtilSysFunc()", p->Func);
|
2015-05-14 18:28:30 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
static void singleHWNDSysFunc(uiControl *c, uiControlSysFuncParams *p)
|
2015-05-14 18:28:30 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
uiWindowsUtilSysFunc(HWND(c), p);
|
2015-05-14 18:28:30 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
void uiWindowsUtilStartZOrder(HWND hwnd, uiControlSysFuncParams *p)
|
2015-05-14 18:28:30 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
HWND insertAfter;
|
2015-05-14 18:28:30 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
// see http://stackoverflow.com/questions/30491418/
|
|
|
|
insertAfter = GetWindow(hwnd, GW_HWNDPREV);
|
|
|
|
if (insertAfter == NULL)
|
|
|
|
logLastError("error getting insert after window in uiWindowsUtilStartZOrder()");
|
|
|
|
p->InsertAfter = insertAfter;
|
2015-05-14 18:28:30 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
static void singleHWNDStartZOrder(uiControl *c, uiControlSysFuncParams *p)
|
2015-05-14 18:28:30 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
uiWindowsUtilStartZOrder(HWND(c), p);
|
2015-05-14 18:28:30 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 19:40:54 -05:00
|
|
|
void setSingleHWNDFuncs(uiControl *c)
|
2015-05-14 18:28:30 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
uiControl(c)->CommitDestroy = singleHWNDCommitDestroy;
|
|
|
|
uiControl(c)->CommitSetParent = singleHWNDCommitSetParent;
|
|
|
|
uiControl(c)->Resize = singleHWNDResize;
|
|
|
|
uiControl(c)->Sizing = singleHWNDSizing;
|
|
|
|
uiControl(c)->CommitShow = singleHWNDCommitShow;
|
|
|
|
uiControl(c)->CommitHide = singleHWNDCommitHide
|
|
|
|
uiControl(c)->CommitEnable = singleHWNDCommitEnable;
|
|
|
|
uiControl(c)->CommitDisable = singleHWNDCommitDisable;
|
|
|
|
uiControl(c)->SysFunc = singleHWNDSysFunc;
|
|
|
|
uiControl(c)->StartZOrder = singleHWNDStartZOrder;
|
2015-05-29 19:40:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
uiControl *uiWindowsNewSingleHWNDControl(uintmax_t type)
|
|
|
|
{
|
|
|
|
uiControl *c;
|
|
|
|
|
|
|
|
c = uiNewControl(type);
|
|
|
|
setSingleHWNDFuncs(c);
|
2015-05-29 13:56:11 -05:00
|
|
|
return c;
|
2015-05-14 18:28:30 -05:00
|
|
|
}
|