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-18 17:02:16 -05:00
|
|
|
void (*onDestroy)(void *);
|
|
|
|
void *onDestroyData;
|
2015-04-29 00:37:49 -05:00
|
|
|
uiContainer *parent;
|
|
|
|
int hidden;
|
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
|
|
|
|
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-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-29 00:37:49 -05:00
|
|
|
static void singleSetParent(uiControl *c, uiContainer *parent)
|
2015-04-09 15:21:09 -05:00
|
|
|
{
|
2015-04-16 00:52:31 -05:00
|
|
|
singleHWND *s = (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-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
|
|
|
|
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-04-16 00:52:31 -05:00
|
|
|
singleHWND *s = (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-04-16 00:52:31 -05:00
|
|
|
singleHWND *s = (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-04-16 00:52:31 -05:00
|
|
|
singleHWND *s = (singleHWND *) (c->Internal);
|
2015-04-11 14:34:16 -05:00
|
|
|
|
2015-04-29 00:37:49 -05:00
|
|
|
EnableWindow(s->hwnd, TRUE);
|
2015-04-11 14:34:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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-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-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-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
|
|
|
|
|
|
|
c->Internal = s;
|
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->Enable = singleEnable;
|
|
|
|
c->Disable = singleDisable;
|
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);
|
|
|
|
}
|