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-08 17:04:46 -05:00
|
|
|
uintptr_t parent;
|
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-09 16:24:26 -05:00
|
|
|
singleHWND *s = (singleHWND *) (c->internal);
|
|
|
|
|
|
|
|
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-09 16:24:26 -05:00
|
|
|
singleHWND *s = (singleHWND *) (c->internal);
|
|
|
|
|
|
|
|
return (uintptr_t) (s->hwnd);
|
2015-04-06 21:26:53 -05:00
|
|
|
}
|
|
|
|
|
2015-04-08 17:04:46 -05:00
|
|
|
static void singleSetParent(uiControl *c, uintptr_t parent)
|
2015-04-06 23:23:01 -05:00
|
|
|
{
|
2015-04-09 16:24:26 -05:00
|
|
|
singleHWND *s = (singleHWND *) (c->internal);
|
2015-04-08 17:04:46 -05:00
|
|
|
|
|
|
|
s->parent = parent;
|
|
|
|
if (SetParent(s->hwnd, (HWND) (s->parent)) == NULL)
|
2015-04-09 15:21:09 -05:00
|
|
|
logLastError("error setting control parent in singleSetParent()");
|
2015-04-08 17:04:46 -05:00
|
|
|
updateParent(s->parent);
|
2015-04-06 23:23:01 -05:00
|
|
|
}
|
2015-04-06 21:26:53 -05:00
|
|
|
|
2015-04-09 15:21:09 -05:00
|
|
|
static void singleRemoveParent(uiControl *c)
|
|
|
|
{
|
2015-04-09 16:24:26 -05:00
|
|
|
singleHWND *s = (singleHWND *) (c->internal);
|
2015-04-09 15:21:09 -05:00
|
|
|
uintptr_t oldparent;
|
|
|
|
|
|
|
|
oldparent = s->parent;
|
|
|
|
s->parent = 0;
|
|
|
|
if (SetParent(s->hwnd, initialParent) == NULL)
|
|
|
|
logLastError("error removing control parent in singleSetParent()");
|
|
|
|
updateParent(oldparent);
|
|
|
|
}
|
|
|
|
|
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-09 16:24:26 -05:00
|
|
|
singleHWND *s = (singleHWND *) (c->internal);
|
|
|
|
|
|
|
|
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-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;
|
|
|
|
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:43:35 -05:00
|
|
|
uiFree(c);
|
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-07 00:33:26 -05:00
|
|
|
uiControl *uiWindowsNewControl(uiWindowsNewControlParams *p)
|
2015-04-06 21:26:53 -05:00
|
|
|
{
|
2015-04-09 16:24:26 -05:00
|
|
|
uiControl *c;
|
|
|
|
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;
|
|
|
|
|
|
|
|
c = uiNew(uiControl);
|
|
|
|
c->destroy = singleDestroy;
|
|
|
|
c->handle = singleHandle;
|
|
|
|
c->setParent = singleSetParent;
|
|
|
|
c->removeParent = singleRemoveParent;
|
|
|
|
c->resize = singleResize;
|
|
|
|
|
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-10 16:53:59 -05:00
|
|
|
c->internal = s;
|
2015-04-09 16:24:26 -05:00
|
|
|
return c;
|
2015-04-07 03:02:21 -05:00
|
|
|
}
|
2015-04-09 10:12:01 -05:00
|
|
|
|
|
|
|
char *uiWindowsControlText(uiControl *c)
|
|
|
|
{
|
2015-04-09 16:24:26 -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-09 16:24:26 -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);
|
|
|
|
}
|