2015-05-14 18:28:30 -05:00
|
|
|
// 6 april 2015
|
|
|
|
#include "uipriv_windows.h"
|
|
|
|
|
|
|
|
struct singleHWND {
|
2015-05-18 21:32:22 -05:00
|
|
|
uiControl *c;
|
2015-05-14 18:28:30 -05:00
|
|
|
HWND hwnd;
|
|
|
|
void (*onDestroy)(void *);
|
|
|
|
void *onDestroyData;
|
|
|
|
};
|
|
|
|
|
2015-05-18 21:32:22 -05:00
|
|
|
void osSingleDestroy(void *internal)
|
2015-05-14 18:28:30 -05:00
|
|
|
{
|
2015-05-18 21:32:22 -05:00
|
|
|
struct singleHWND *s = (struct singleHWND *) internal;
|
2015-05-14 18:28:30 -05:00
|
|
|
|
|
|
|
(*(s->onDestroy))(s->onDestroyData);
|
|
|
|
if (DestroyWindow(s->hwnd) == 0)
|
|
|
|
logLastError("error destroying control in singleDestroy()");
|
|
|
|
uiFree(s);
|
|
|
|
}
|
|
|
|
|
2015-05-18 21:32:22 -05:00
|
|
|
uintptr_t osSingleHandle(void *internal)
|
2015-05-14 18:28:30 -05:00
|
|
|
{
|
2015-05-18 21:32:22 -05:00
|
|
|
struct singleHWND *s = (struct singleHWND *) internal;
|
2015-05-14 18:28:30 -05:00
|
|
|
|
|
|
|
return (uintptr_t) (s->hwnd);
|
|
|
|
}
|
|
|
|
|
2015-05-18 21:32:22 -05:00
|
|
|
void osSingleSetParent(void *internal, uiControl *oldParent, uiControl *newParent)
|
2015-05-14 18:28:30 -05:00
|
|
|
{
|
2015-05-18 21:32:22 -05:00
|
|
|
struct singleHWND *s = (struct singleHWND *) internal;
|
2015-05-14 18:28:30 -05:00
|
|
|
HWND newParentHWND;
|
|
|
|
|
|
|
|
newParentHWND = utilWindow;
|
2015-05-18 21:32:22 -05:00
|
|
|
if (newParent != NULL)
|
|
|
|
newParentHWND = (HWND) uiControlHandle(newParent);
|
2015-05-14 18:28:30 -05:00
|
|
|
if (SetParent(s->hwnd, newParentHWND) == NULL)
|
2015-05-18 21:32:22 -05:00
|
|
|
logLastError("error setting control parent in osSingleSetParent()");
|
2015-05-14 18:28:30 -05:00
|
|
|
}
|
|
|
|
|
2015-05-18 21:32:22 -05:00
|
|
|
void osSingleResize(void *internal, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
|
2015-05-14 18:28:30 -05:00
|
|
|
{
|
2015-05-18 21:32:22 -05:00
|
|
|
struct singleHWND *s = (struct singleHWND *) internal;
|
2015-05-14 18:28:30 -05:00
|
|
|
|
2015-05-18 11:04:52 -05:00
|
|
|
moveWindow(s->hwnd, x, y, width, height, d);
|
2015-05-14 18:28:30 -05:00
|
|
|
}
|
|
|
|
|
2015-05-18 21:32:22 -05:00
|
|
|
uiSizing *osSingleSizing(void *internal, uiControl *c)
|
2015-05-14 18:28:30 -05:00
|
|
|
{
|
2015-05-18 10:46:50 -05:00
|
|
|
return uiWindowsSizing(c);
|
2015-05-14 18:28:30 -05:00
|
|
|
}
|
|
|
|
|
2015-05-18 21:32:22 -05:00
|
|
|
void osSingleShow(void *internal)
|
2015-05-14 18:28:30 -05:00
|
|
|
{
|
2015-05-18 21:32:22 -05:00
|
|
|
struct singleHWND *s = (struct singleHWND *) internal;
|
2015-05-14 18:28:30 -05:00
|
|
|
|
2015-05-18 21:32:22 -05:00
|
|
|
ShowWindow(s->hwnd, SW_SHOW);
|
2015-05-14 18:28:30 -05:00
|
|
|
}
|
|
|
|
|
2015-05-18 21:32:22 -05:00
|
|
|
void osSingleHide(void *internal)
|
2015-05-14 18:28:30 -05:00
|
|
|
{
|
2015-05-18 21:32:22 -05:00
|
|
|
struct singleHWND *s = (struct singleHWND *) internal;
|
2015-05-14 18:28:30 -05:00
|
|
|
|
2015-05-15 17:34:17 -05:00
|
|
|
ShowWindow(s->hwnd, SW_HIDE);
|
|
|
|
}
|
|
|
|
|
2015-05-18 21:32:22 -05:00
|
|
|
void osSingleEnable(void *internal)
|
2015-05-15 17:34:17 -05:00
|
|
|
{
|
2015-05-18 21:32:22 -05:00
|
|
|
struct singleHWND *s = (struct singleHWND *) internal;
|
2015-05-15 17:34:17 -05:00
|
|
|
|
2015-05-18 21:32:22 -05:00
|
|
|
EnableWindow(s->hwnd, TRUE);
|
2015-05-15 17:34:17 -05:00
|
|
|
}
|
|
|
|
|
2015-05-18 21:32:22 -05:00
|
|
|
void osSingleDisable(void *internal)
|
2015-05-15 17:34:17 -05:00
|
|
|
{
|
2015-05-18 21:32:22 -05:00
|
|
|
struct singleHWND *s = (struct singleHWND *) internal;
|
2015-05-14 18:28:30 -05:00
|
|
|
|
|
|
|
EnableWindow(s->hwnd, FALSE);
|
|
|
|
}
|
|
|
|
|
2015-05-18 21:32:22 -05:00
|
|
|
// TODO integrate these two with the main control.c
|
2015-05-14 18:28:30 -05:00
|
|
|
static void singleSysFunc(uiControl *c, uiControlSysFuncParams *p)
|
|
|
|
{
|
|
|
|
struct singleHWND *s = (struct singleHWND *) (c->Internal);
|
|
|
|
|
|
|
|
switch (p->Func) {
|
|
|
|
case uiWindowsSysFuncHasTabStops:
|
|
|
|
if (IsWindowEnabled(s->hwnd) != 0)
|
|
|
|
if ((getStyle(s->hwnd) & WS_TABSTOP) != 0)
|
|
|
|
p->HasTabStops = TRUE;
|
|
|
|
return;
|
2015-05-16 00:45:20 -05:00
|
|
|
case uiWindowsSysFuncSetZOrder:
|
2015-05-14 18:28:30 -05:00
|
|
|
// TODO
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
complain("unknown p->Func %d in singleSysFunc()", p->Func);
|
|
|
|
}
|
|
|
|
|
2015-05-16 00:55:34 -05:00
|
|
|
static int singleStartZOrder(uiControl *c, uiControlSysFuncParams *p)
|
2015-05-14 18:28:30 -05:00
|
|
|
{
|
|
|
|
// TODO
|
2015-05-16 00:55:34 -05:00
|
|
|
return 0;
|
2015-05-14 18:28:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiWindowsMakeControl(uiControl *c, uiWindowsMakeControlParams *p)
|
|
|
|
{
|
|
|
|
struct singleHWND *s;
|
|
|
|
|
|
|
|
s = uiNew(struct singleHWND);
|
2015-05-18 21:32:22 -05:00
|
|
|
s->c = c;
|
2015-05-14 18:28:30 -05:00
|
|
|
s->hwnd = CreateWindowExW(p->dwExStyle,
|
|
|
|
p->lpClassName, p->lpWindowName,
|
|
|
|
p->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,
|
2015-05-14 21:33:19 -05:00
|
|
|
utilWindow, NULL, p->hInstance, p->lpParam);
|
2015-05-14 18:28:30 -05:00
|
|
|
if (s->hwnd == NULL)
|
|
|
|
logLastError("error creating control in uiWindowsMakeControl()");
|
2015-05-20 21:46:50 -05:00
|
|
|
|
2015-05-14 18:28:30 -05:00
|
|
|
s->onDestroy = p->onDestroy;
|
|
|
|
s->onDestroyData = p->onDestroyData;
|
|
|
|
|
|
|
|
if (p->useStandardControlFont)
|
|
|
|
SendMessageW(s->hwnd, WM_SETFONT, (WPARAM) hMessageFont, (LPARAM) TRUE);
|
|
|
|
|
2015-05-18 21:32:22 -05:00
|
|
|
makeControl(uiControl(c), s);
|
|
|
|
|
2015-05-14 18:28:30 -05:00
|
|
|
// PreferredSize() implemented by the individual controls
|
|
|
|
uiControl(c)->SysFunc = singleSysFunc;
|
|
|
|
uiControl(c)->StartZOrder = singleStartZOrder;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *uiWindowsControlText(uiControl *c)
|
|
|
|
{
|
2015-05-18 21:32:22 -05:00
|
|
|
HWND hwnd;
|
2015-05-14 18:28:30 -05:00
|
|
|
WCHAR *wtext;
|
|
|
|
char *text;
|
|
|
|
|
2015-05-18 21:32:22 -05:00
|
|
|
hwnd = (HWND) uiControlHandle(c);
|
|
|
|
wtext = windowText(hwnd);
|
2015-05-14 18:28:30 -05:00
|
|
|
text = toUTF8(wtext);
|
|
|
|
uiFree(wtext);
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiWindowsControlSetText(uiControl *c, const char *text)
|
|
|
|
{
|
2015-05-18 21:32:22 -05:00
|
|
|
HWND hwnd;
|
2015-05-14 18:28:30 -05:00
|
|
|
WCHAR *wtext;
|
|
|
|
|
2015-05-18 21:32:22 -05:00
|
|
|
hwnd = (HWND) uiControlHandle(c);
|
2015-05-14 18:28:30 -05:00
|
|
|
wtext = toUTF16(text);
|
2015-05-18 21:32:22 -05:00
|
|
|
if (SetWindowTextW(hwnd, wtext) == 0)
|
2015-05-14 18:28:30 -05:00
|
|
|
logLastError("error setting control text in uiWindowsControlSetText()");
|
|
|
|
uiFree(wtext);
|
|
|
|
}
|