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:24:26 -05:00
|
|
|
typedef struct singleHWND singleHWND;
|
2015-04-07 00:33:26 -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-09 16:24:26 -05:00
|
|
|
void (*onWM_DESTROY)(uiControl *);
|
2015-04-12 19:08:32 -05:00
|
|
|
uiParent *parent;
|
2015-04-11 14:34:16 -05:00
|
|
|
BOOL userHid;
|
|
|
|
BOOL containerHid;
|
|
|
|
BOOL userDisabled;
|
|
|
|
BOOL 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-04-16 00:52:31 -05:00
|
|
|
singleHWND *s = (singleHWND *) (c->Internal);
|
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-09 16:24:26 -05:00
|
|
|
// the data structures are destroyed in the subclass procedure
|
2015-04-07 23:43:35 -05:00
|
|
|
}
|
|
|
|
|
2015-04-06 21:26:53 -05:00
|
|
|
static uintptr_t singleHandle(uiControl *c)
|
|
|
|
{
|
2015-04-16 00:52:31 -05:00
|
|
|
singleHWND *s = (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-12 19:08:32 -05:00
|
|
|
static void singleSetParent(uiControl *c, uiParent *parent)
|
2015-04-09 15:21:09 -05:00
|
|
|
{
|
2015-04-16 00:52:31 -05:00
|
|
|
singleHWND *s = (singleHWND *) (c->Internal);
|
2015-04-12 19:08:32 -05:00
|
|
|
uiParent *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)
|
|
|
|
newParentHWND = uiParentHWND(s->parent);
|
|
|
|
if (SetParent(s->hwnd, newParentHWND) == NULL)
|
|
|
|
logLastError("error setting control parent in singleSetParent()");
|
|
|
|
if (oldparent != NULL)
|
|
|
|
uiParentUpdate(oldparent);
|
|
|
|
if (s->parent != NULL)
|
|
|
|
uiParentUpdate(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-04-16 00:52:31 -05:00
|
|
|
singleHWND *s = (singleHWND *) (c->Internal);
|
2015-04-09 16:24:26 -05:00
|
|
|
|
|
|
|
if (MoveWindow(s->hwnd, x, y, width, height, TRUE) == 0)
|
2015-04-06 21:26:53 -05:00
|
|
|
logLastError("error moving control in singleResize()");
|
|
|
|
}
|
|
|
|
|
2015-04-11 14:34:16 -05:00
|
|
|
static int singleVisible(uiControl *c)
|
|
|
|
{
|
2015-04-16 00:52:31 -05:00
|
|
|
singleHWND *s = (singleHWND *) (c->Internal);
|
2015-04-11 14:34:16 -05:00
|
|
|
|
|
|
|
if (s->userHid)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void singleShow(uiControl *c)
|
|
|
|
{
|
2015-04-16 00:52:31 -05:00
|
|
|
singleHWND *s = (singleHWND *) (c->Internal);
|
2015-04-11 14:34:16 -05:00
|
|
|
|
|
|
|
s->userHid = FALSE;
|
|
|
|
if (!s->containerHid) {
|
|
|
|
ShowWindow(s->hwnd, SW_SHOW);
|
2015-04-12 19:08:32 -05:00
|
|
|
if (s->parent != NULL)
|
2015-04-12 21:57:05 -05:00
|
|
|
uiParentUpdate(s->parent);
|
2015-04-11 14:34:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void singleHide(uiControl *c)
|
|
|
|
{
|
2015-04-16 00:52:31 -05:00
|
|
|
singleHWND *s = (singleHWND *) (c->Internal);
|
2015-04-11 14:34:16 -05:00
|
|
|
|
|
|
|
s->userHid = TRUE;
|
|
|
|
ShowWindow(s->hwnd, SW_HIDE);
|
2015-04-12 19:08:32 -05:00
|
|
|
if (s->parent != NULL)
|
2015-04-12 21:57:05 -05:00
|
|
|
uiParentUpdate(s->parent);
|
2015-04-11 14:34:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void singleContainerShow(uiControl *c)
|
|
|
|
{
|
2015-04-16 00:52:31 -05:00
|
|
|
singleHWND *s = (singleHWND *) (c->Internal);
|
2015-04-11 14:34:16 -05:00
|
|
|
|
|
|
|
s->containerHid = FALSE;
|
|
|
|
if (!s->userHid) {
|
|
|
|
ShowWindow(s->hwnd, SW_SHOW);
|
2015-04-12 19:08:32 -05:00
|
|
|
if (s->parent != NULL)
|
2015-04-12 21:57:05 -05:00
|
|
|
uiParentUpdate(s->parent);
|
2015-04-11 14:34:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void singleContainerHide(uiControl *c)
|
|
|
|
{
|
2015-04-16 00:52:31 -05:00
|
|
|
singleHWND *s = (singleHWND *) (c->Internal);
|
2015-04-11 14:34:16 -05:00
|
|
|
|
|
|
|
s->containerHid = TRUE;
|
|
|
|
ShowWindow(s->hwnd, SW_HIDE);
|
2015-04-12 19:08:32 -05:00
|
|
|
if (s->parent != NULL)
|
2015-04-12 21:57:05 -05:00
|
|
|
uiParentUpdate(s->parent);
|
2015-04-11 14:34:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void singleEnable(uiControl *c)
|
|
|
|
{
|
2015-04-16 00:52:31 -05:00
|
|
|
singleHWND *s = (singleHWND *) (c->Internal);
|
2015-04-11 14:34:16 -05:00
|
|
|
|
|
|
|
s->userDisabled = FALSE;
|
|
|
|
if (!s->containerDisabled)
|
|
|
|
EnableWindow(s->hwnd, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void singleDisable(uiControl *c)
|
|
|
|
{
|
2015-04-16 00:52:31 -05:00
|
|
|
singleHWND *s = (singleHWND *) (c->Internal);
|
2015-04-11 14:34:16 -05:00
|
|
|
|
|
|
|
s->userDisabled = TRUE;
|
|
|
|
EnableWindow(s->hwnd, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void singleContainerEnable(uiControl *c)
|
|
|
|
{
|
2015-04-16 00:52:31 -05:00
|
|
|
singleHWND *s = (singleHWND *) (c->Internal);
|
2015-04-11 14:34:16 -05:00
|
|
|
|
|
|
|
s->containerDisabled = FALSE;
|
|
|
|
if (!s->userDisabled)
|
|
|
|
EnableWindow(s->hwnd, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void singleContainerDisable(uiControl *c)
|
|
|
|
{
|
2015-04-16 00:52:31 -05:00
|
|
|
singleHWND *s = (singleHWND *) (c->Internal);
|
2015-04-11 14:34:16 -05:00
|
|
|
|
|
|
|
s->containerDisabled = TRUE;
|
|
|
|
EnableWindow(s->hwnd, FALSE);
|
|
|
|
}
|
|
|
|
|
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-04-16 00:52:31 -05:00
|
|
|
singleHWND *s = (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-07 23:51:50 -05:00
|
|
|
case WM_DESTROY:
|
2015-04-09 16:24:26 -05:00
|
|
|
(*(s->onWM_DESTROY))(c);
|
|
|
|
uiFree(s);
|
2015-04-07 23:51:50 -05:00
|
|
|
break;
|
|
|
|
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-04-16 00:52:31 -05:00
|
|
|
void uiWindowsNewControl(uiControl *c, uiWindowsNewControlParams *p)
|
2015-04-06 21:26:53 -05:00
|
|
|
{
|
2015-04-09 16:24:26 -05:00
|
|
|
singleHWND *s;
|
2015-04-06 21:26:53 -05:00
|
|
|
|
2015-04-09 16:24:26 -05:00
|
|
|
s = uiNew(singleHWND);
|
|
|
|
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-04-07 01:46:27 -05:00
|
|
|
logLastError("error creating control in uiWindowsNewControl()");
|
2015-04-09 16:24:26 -05:00
|
|
|
s->onWM_COMMAND = p->onWM_COMMAND;
|
|
|
|
s->onWM_NOTIFY = p->onWM_NOTIFY;
|
|
|
|
s->onWM_DESTROY = p->onWM_DESTROY;
|
|
|
|
|
2015-04-16 00:52:31 -05:00
|
|
|
c->Destroy = singleDestroy;
|
|
|
|
c->Handle = singleHandle;
|
|
|
|
c->SetParent = singleSetParent;
|
|
|
|
c->Resize = singleResize;
|
|
|
|
c->Visible = singleVisible;
|
|
|
|
c->Show = singleShow;
|
|
|
|
c->Hide = singleHide;
|
|
|
|
c->ContainerShow = singleContainerShow;
|
|
|
|
c->ContainerHide = singleContainerHide;
|
|
|
|
c->Enable = singleEnable;
|
|
|
|
c->Disable = singleDisable;
|
|
|
|
c->ContainerEnable = singleContainerEnable;
|
|
|
|
c->ContainerDisable = singleContainerDisable;
|
2015-04-09 16:24:26 -05:00
|
|
|
|
2015-04-10 16:53:59 -05:00
|
|
|
if (p->useStandardControlFont)
|
|
|
|
SendMessageW(s->hwnd, WM_SETFONT, (WPARAM) hMessageFont, (LPARAM) TRUE);
|
|
|
|
|
2015-04-09 16:24:26 -05:00
|
|
|
if ((*fv_SetWindowSubclass)(s->hwnd, singleSubclassProc, 0, (DWORD_PTR) c) == FALSE)
|
2015-04-07 01:46:27 -05:00
|
|
|
logLastError("error subclassing Windows control in uiWindowsNewControl()");
|
2015-04-07 00:33:26 -05:00
|
|
|
|
2015-04-16 00:52:31 -05:00
|
|
|
c->Internal = s;
|
2015-04-07 03:02:21 -05:00
|
|
|
}
|
2015-04-09 10:12:01 -05:00
|
|
|
|
|
|
|
char *uiWindowsControlText(uiControl *c)
|
|
|
|
{
|
2015-04-16 00:52:31 -05:00
|
|
|
singleHWND *s = (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-04-16 00:52:31 -05:00
|
|
|
singleHWND *s = (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);
|
|
|
|
}
|