2015-04-06 21:26:53 -05:00
|
|
|
// 6 april 2015
|
2015-04-06 23:26:27 -05:00
|
|
|
#include "uipriv_windows.h"
|
2015-04-06 21:26:53 -05:00
|
|
|
|
2015-04-09 16:57:08 -05:00
|
|
|
struct singleHWND {
|
2015-04-07 00:33:26 -05:00
|
|
|
HWND hwnd;
|
2015-04-09 17:54:14 -05:00
|
|
|
BOOL (*onWM_COMMAND)(uiControl *, WORD, LRESULT *);
|
2015-04-09 18:07:41 -05:00
|
|
|
BOOL (*onWM_NOTIFY)(uiControl *, NMHDR *, LRESULT *);
|
2015-04-18 17:02:16 -05:00
|
|
|
void (*onDestroy)(void *);
|
|
|
|
void *onDestroyData;
|
2015-04-29 00:37:49 -05:00
|
|
|
uiContainer *parent;
|
|
|
|
int hidden;
|
2015-05-04 08:51:57 -05:00
|
|
|
int userDisabled;
|
|
|
|
int containerDisabled;
|
2015-04-07 00:33:26 -05:00
|
|
|
};
|
2015-04-06 21:26:53 -05:00
|
|
|
|
2015-04-07 23:43:35 -05:00
|
|
|
static void singleDestroy(uiControl *c)
|
|
|
|
{
|
2015-05-04 14:51:23 -05:00
|
|
|
struct singleHWND *s = (struct singleHWND *) (c->Internal);
|
2015-04-09 16:24:26 -05:00
|
|
|
|
2015-04-19 21:52:51 -05:00
|
|
|
if (s->parent != NULL)
|
2015-04-29 00:37:49 -05:00
|
|
|
complain("attempt to destroy a uiControl at %p while it still has a parent", c);
|
2015-04-18 17:07:57 -05:00
|
|
|
SendMessageW(s->hwnd, msgCanDestroyNow, 0, 0);
|
|
|
|
(*(s->onDestroy))(s->onDestroyData);
|
2015-04-09 16:24:26 -05:00
|
|
|
if (DestroyWindow(s->hwnd) == 0)
|
2015-04-07 23:43:35 -05:00
|
|
|
logLastError("error destroying control in singleDestroy()");
|
2015-04-18 17:07:57 -05:00
|
|
|
uiFree(s);
|
2015-04-07 23:43:35 -05:00
|
|
|
}
|
|
|
|
|
2015-04-06 21:26:53 -05:00
|
|
|
static uintptr_t singleHandle(uiControl *c)
|
|
|
|
{
|
2015-05-04 14:51:23 -05:00
|
|
|
struct singleHWND *s = (struct singleHWND *) (c->Internal);
|
2015-04-09 16:24:26 -05:00
|
|
|
|
|
|
|
return (uintptr_t) (s->hwnd);
|
2015-04-06 21:26:53 -05:00
|
|
|
}
|
|
|
|
|
2015-04-29 00:37:49 -05:00
|
|
|
static void singleSetParent(uiControl *c, uiContainer *parent)
|
2015-04-09 15:21:09 -05:00
|
|
|
{
|
2015-05-04 14:51:23 -05:00
|
|
|
struct singleHWND *s = (struct singleHWND *) (c->Internal);
|
2015-04-29 00:37:49 -05:00
|
|
|
uiContainer *oldparent;
|
2015-04-14 09:20:07 -05:00
|
|
|
HWND newParentHWND;
|
2015-04-09 15:21:09 -05:00
|
|
|
|
|
|
|
oldparent = s->parent;
|
2015-04-14 09:20:07 -05:00
|
|
|
s->parent = parent;
|
|
|
|
newParentHWND = initialParent;
|
|
|
|
if (s->parent != NULL)
|
2015-04-29 00:37:49 -05:00
|
|
|
newParentHWND = (HWND) uiControlHandle(uiControl(s->parent));
|
2015-04-14 09:20:07 -05:00
|
|
|
if (SetParent(s->hwnd, newParentHWND) == NULL)
|
|
|
|
logLastError("error setting control parent in singleSetParent()");
|
|
|
|
if (oldparent != NULL)
|
2015-04-29 00:37:49 -05:00
|
|
|
uiContainerUpdate(oldparent);
|
2015-04-14 09:20:07 -05:00
|
|
|
if (s->parent != NULL)
|
2015-04-29 00:37:49 -05:00
|
|
|
uiContainerUpdate(s->parent);
|
2015-04-09 15:21:09 -05:00
|
|
|
}
|
|
|
|
|
2015-04-06 21:26:53 -05:00
|
|
|
static void singleResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
|
|
|
|
{
|
2015-05-04 14:51:23 -05:00
|
|
|
struct singleHWND *s = (struct singleHWND *) (c->Internal);
|
2015-04-09 16:24:26 -05:00
|
|
|
|
2015-05-05 14:10:37 -05:00
|
|
|
uiWindowsResizeHWND(s->hwnd, x, y, width, height, d);
|
2015-04-06 21:26:53 -05:00
|
|
|
}
|
|
|
|
|
2015-04-11 14:34:16 -05:00
|
|
|
static int singleVisible(uiControl *c)
|
|
|
|
{
|
2015-05-04 14:51:23 -05:00
|
|
|
struct singleHWND *s = (struct singleHWND *) (c->Internal);
|
2015-04-11 14:34:16 -05:00
|
|
|
|
2015-04-29 00:37:49 -05:00
|
|
|
return !s->hidden;
|
2015-04-11 14:34:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void singleShow(uiControl *c)
|
|
|
|
{
|
2015-05-04 14:51:23 -05:00
|
|
|
struct singleHWND *s = (struct singleHWND *) (c->Internal);
|
2015-04-11 14:34:16 -05:00
|
|
|
|
2015-04-29 00:37:49 -05:00
|
|
|
ShowWindow(s->hwnd, SW_SHOW);
|
2015-04-29 13:25:34 -05:00
|
|
|
s->hidden = 0;
|
2015-04-12 19:08:32 -05:00
|
|
|
if (s->parent != NULL)
|
2015-04-29 00:37:49 -05:00
|
|
|
uiContainerUpdate(s->parent);
|
2015-04-11 14:34:16 -05:00
|
|
|
}
|
|
|
|
|
2015-04-29 00:37:49 -05:00
|
|
|
static void singleHide(uiControl *c)
|
2015-04-11 14:34:16 -05:00
|
|
|
{
|
2015-05-04 14:51:23 -05:00
|
|
|
struct singleHWND *s = (struct singleHWND *) (c->Internal);
|
2015-04-11 14:34:16 -05:00
|
|
|
|
|
|
|
ShowWindow(s->hwnd, SW_HIDE);
|
2015-04-29 13:25:34 -05:00
|
|
|
s->hidden = 1;
|
2015-04-12 19:08:32 -05:00
|
|
|
if (s->parent != NULL)
|
2015-04-29 00:37:49 -05:00
|
|
|
uiContainerUpdate(s->parent);
|
2015-04-11 14:34:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void singleEnable(uiControl *c)
|
|
|
|
{
|
2015-05-04 14:51:23 -05:00
|
|
|
struct singleHWND *s = (struct singleHWND *) (c->Internal);
|
2015-04-11 14:34:16 -05:00
|
|
|
|
2015-05-04 08:51:57 -05:00
|
|
|
s->userDisabled = 0;
|
|
|
|
if (!s->containerDisabled)
|
|
|
|
EnableWindow(s->hwnd, TRUE);
|
2015-04-11 14:34:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void singleDisable(uiControl *c)
|
|
|
|
{
|
2015-05-04 14:51:23 -05:00
|
|
|
struct singleHWND *s = (struct singleHWND *) (c->Internal);
|
2015-04-11 14:34:16 -05:00
|
|
|
|
2015-05-04 08:51:57 -05:00
|
|
|
s->userDisabled = 1;
|
2015-04-11 14:34:16 -05:00
|
|
|
EnableWindow(s->hwnd, FALSE);
|
|
|
|
}
|
|
|
|
|
2015-05-04 10:09:28 -05:00
|
|
|
static void singleSysFunc(uiControl *c, uiControlSysFuncParams *p)
|
2015-05-04 08:51:57 -05:00
|
|
|
{
|
2015-05-04 14:51:23 -05:00
|
|
|
struct singleHWND *s = (struct singleHWND *) (c->Internal);
|
2015-05-04 08:51:57 -05:00
|
|
|
|
|
|
|
switch (p->Func) {
|
2015-05-04 10:09:28 -05:00
|
|
|
case uiWindowsSysFuncContainerEnable:
|
2015-05-04 08:51:57 -05:00
|
|
|
s->containerDisabled = 0;
|
|
|
|
if (!s->userDisabled)
|
|
|
|
EnableWindow(s->hwnd, TRUE);
|
|
|
|
return;
|
|
|
|
case uiWindowsSysFuncContainerDisable:
|
|
|
|
s->containerDisabled = 1;
|
|
|
|
EnableWindow(s->hwnd, FALSE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
complain("unknown p->Func %d in singleSysFunc()", p->Func);
|
|
|
|
}
|
|
|
|
|
2015-04-07 01:46:27 -05:00
|
|
|
static LRESULT CALLBACK singleSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
|
|
|
|
{
|
2015-04-09 16:24:26 -05:00
|
|
|
uiControl *c = (uiControl *) dwRefData;
|
2015-05-04 14:51:23 -05:00
|
|
|
struct singleHWND *s = (struct singleHWND *) (c->Internal);
|
2015-04-07 01:46:27 -05:00
|
|
|
LRESULT lResult;
|
|
|
|
|
|
|
|
switch (uMsg) {
|
|
|
|
case msgCOMMAND:
|
2015-04-09 17:54:14 -05:00
|
|
|
if ((*(s->onWM_COMMAND))(c, HIWORD(wParam), &lResult) != FALSE)
|
2015-04-07 01:46:27 -05:00
|
|
|
return lResult;
|
|
|
|
break;
|
|
|
|
case msgNOTIFY:
|
2015-04-09 18:07:41 -05:00
|
|
|
if ((*(s->onWM_NOTIFY))(c, (NMHDR *) lParam, &lResult) != FALSE)
|
2015-04-07 01:46:27 -05:00
|
|
|
return lResult;
|
|
|
|
break;
|
2015-04-29 00:37:49 -05:00
|
|
|
case WM_NCDESTROY:
|
2015-04-07 01:46:27 -05:00
|
|
|
if ((*fv_RemoveWindowSubclass)(hwnd, singleSubclassProc, uIdSubclass) == FALSE)
|
|
|
|
logLastError("error removing Windows control subclass in singleSubclassProc()");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2015-05-02 19:51:00 -05:00
|
|
|
void uiWindowsMakeControl(uiControl *c, uiWindowsMakeControlParams *p)
|
2015-04-06 21:26:53 -05:00
|
|
|
{
|
2015-05-04 14:51:23 -05:00
|
|
|
struct singleHWND *s;
|
2015-04-06 21:26:53 -05:00
|
|
|
|
2015-05-04 14:51:23 -05:00
|
|
|
s = uiNew(struct singleHWND);
|
2015-04-09 16:24:26 -05:00
|
|
|
s->hwnd = CreateWindowExW(p->dwExStyle,
|
2015-04-08 19:01:33 -05:00
|
|
|
p->lpClassName, p->lpWindowName,
|
2015-04-07 00:33:26 -05:00
|
|
|
p->dwStyle | WS_CHILD | WS_VISIBLE,
|
2015-04-06 21:26:53 -05:00
|
|
|
0, 0,
|
2015-04-11 09:34:26 -05:00
|
|
|
// use a nonzero initial size just in case some control breaks with a zero initial size
|
2015-04-06 21:26:53 -05:00
|
|
|
100, 100,
|
2015-04-07 00:33:26 -05:00
|
|
|
initialParent, NULL, p->hInstance, NULL);
|
2015-04-09 16:24:26 -05:00
|
|
|
if (s->hwnd == NULL)
|
2015-05-02 19:51:00 -05:00
|
|
|
logLastError("error creating control in uiWindowsMakeControl()");
|
2015-04-09 16:24:26 -05:00
|
|
|
s->onWM_COMMAND = p->onWM_COMMAND;
|
|
|
|
s->onWM_NOTIFY = p->onWM_NOTIFY;
|
2015-04-18 17:02:16 -05:00
|
|
|
|
|
|
|
s->onDestroy = p->onDestroy;
|
|
|
|
s->onDestroyData = p->onDestroyData;
|
2015-04-09 16:24:26 -05:00
|
|
|
|
2015-04-29 00:37:49 -05:00
|
|
|
if (p->useStandardControlFont)
|
|
|
|
SendMessageW(s->hwnd, WM_SETFONT, (WPARAM) hMessageFont, (LPARAM) TRUE);
|
|
|
|
|
2015-04-30 12:30:00 -05:00
|
|
|
// this handles redirected notification messages
|
2015-04-29 00:37:49 -05:00
|
|
|
if ((*fv_SetWindowSubclass)(s->hwnd, singleSubclassProc, 0, (DWORD_PTR) c) == FALSE)
|
2015-05-02 19:51:00 -05:00
|
|
|
logLastError("error subclassing Windows control in uiWindowsMakeControl()");
|
2015-04-29 00:37:49 -05:00
|
|
|
|
2015-05-03 13:44:46 -05:00
|
|
|
uiControl(c)->Internal = s;
|
|
|
|
uiControl(c)->Destroy = singleDestroy;
|
|
|
|
uiControl(c)->Handle = singleHandle;
|
|
|
|
uiControl(c)->SetParent = singleSetParent;
|
|
|
|
uiControl(c)->Resize = singleResize;
|
|
|
|
uiControl(c)->Visible = singleVisible;
|
|
|
|
uiControl(c)->Show = singleShow;
|
|
|
|
uiControl(c)->Hide = singleHide;
|
|
|
|
uiControl(c)->Enable = singleEnable;
|
|
|
|
uiControl(c)->Disable = singleDisable;
|
2015-05-04 08:51:57 -05:00
|
|
|
uiControl(c)->SysFunc = singleSysFunc;
|
2015-04-07 03:02:21 -05:00
|
|
|
}
|
2015-04-09 10:12:01 -05:00
|
|
|
|
|
|
|
char *uiWindowsControlText(uiControl *c)
|
|
|
|
{
|
2015-05-04 14:51:23 -05:00
|
|
|
struct singleHWND *s = (struct singleHWND *) (c->Internal);
|
2015-04-09 10:12:01 -05:00
|
|
|
WCHAR *wtext;
|
|
|
|
char *text;
|
|
|
|
|
2015-04-09 16:24:26 -05:00
|
|
|
wtext = windowText(s->hwnd);
|
2015-04-09 10:12:01 -05:00
|
|
|
text = toUTF8(wtext);
|
|
|
|
uiFree(wtext);
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiWindowsControlSetText(uiControl *c, const char *text)
|
|
|
|
{
|
2015-05-04 14:51:23 -05:00
|
|
|
struct singleHWND *s = (struct singleHWND *) (c->Internal);
|
2015-04-09 10:12:01 -05:00
|
|
|
WCHAR *wtext;
|
|
|
|
|
|
|
|
wtext = toUTF16(text);
|
2015-04-09 16:24:26 -05:00
|
|
|
if (SetWindowTextW(s->hwnd, wtext) == 0)
|
2015-04-09 10:12:01 -05:00
|
|
|
logLastError("error setting control text in uiWindowsControlSetText()");
|
|
|
|
uiFree(wtext);
|
|
|
|
}
|
2015-05-05 14:10:37 -05:00
|
|
|
|
|
|
|
void uiWindowsResizeHWND(HWND hwnd, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
|
|
|
|
{
|
|
|
|
d->sys->dwp = DeferWindowPos(d->sys->dwp, hwnd, NULL, x, y, width, height, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
|
|
|
|
if (d->sys->dwp == NULL)
|
|
|
|
logLastError("error queuing window for resize in uiWindowsResizeHWND()");
|
|
|
|
}
|