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-07 00:33:26 -05:00
|
|
|
typedef struct uiSingleHWNDControl uiSingleHWNDControl;
|
|
|
|
|
|
|
|
struct uiSingleHWNDControl {
|
|
|
|
uiControl control;
|
|
|
|
HWND hwnd;
|
|
|
|
BOOL (*onWM_COMMAND)(uiControl *, WPARAM, LPARAM, void *, LRESULT *);
|
|
|
|
BOOL (*onWM_NOTIFY)(uiControl *, WPARAM, LPARAM, void *, LRESULT *);
|
|
|
|
void *onCommandNotifyData;
|
2015-04-07 00:51:17 -05:00
|
|
|
void (*preferredSize)(uiControl *, int, int, LONG, intmax_t *, intmax_t *);
|
2015-04-07 03:02:21 -05:00
|
|
|
void *data;
|
2015-04-07 00:33:26 -05:00
|
|
|
};
|
2015-04-06 21:26:53 -05:00
|
|
|
|
2015-04-06 23:23:01 -05:00
|
|
|
#define S(c) ((uiSingleHWNDControl *) (c))
|
|
|
|
|
2015-04-06 21:26:53 -05:00
|
|
|
static uintptr_t singleHandle(uiControl *c)
|
|
|
|
{
|
2015-04-06 23:23:01 -05:00
|
|
|
return (uintptr_t) (S(c)->hwnd);
|
2015-04-06 21:26:53 -05:00
|
|
|
}
|
|
|
|
|
2015-04-07 11:17:05 -05:00
|
|
|
static void singleSetParent(uiControl *c, uintptr_t parentHWND)
|
2015-04-06 23:23:01 -05:00
|
|
|
{
|
|
|
|
if (SetParent(S(c)->hwnd, (HWND) parentHWND) == NULL)
|
|
|
|
logLastError("error changing control parent in singleSetParent()");
|
|
|
|
}
|
2015-04-06 21:26:53 -05:00
|
|
|
|
2015-04-07 11:17:05 -05:00
|
|
|
static uiSize singlePreferredSize(uiControl *c, uiSizing *d)
|
2015-04-07 00:51:17 -05:00
|
|
|
{
|
|
|
|
uiSize size;
|
|
|
|
|
|
|
|
(*(S(c)->preferredSize))(c,
|
|
|
|
d->baseX, d->baseY, d->internalLeading,
|
|
|
|
&(size.width), &(size.height));
|
|
|
|
return size;
|
|
|
|
}
|
2015-04-07 00:33:26 -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-06 23:23:01 -05:00
|
|
|
if (MoveWindow(S(c)->hwnd, x, y, width, height, TRUE) == 0)
|
2015-04-06 21:26:53 -05:00
|
|
|
logLastError("error moving control in singleResize()");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void singleContainerShow(uiControl *c)
|
|
|
|
{
|
2015-04-06 23:23:01 -05:00
|
|
|
ShowWindow(S(c)->hwnd, SW_SHOW);
|
2015-04-06 21:26:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void singleContainerHide(uiControl *c)
|
|
|
|
{
|
2015-04-06 23:23:01 -05:00
|
|
|
ShowWindow(S(c)->hwnd, SW_HIDE);
|
2015-04-06 21:26:53 -05:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
uiSingleHWNDControl *c = (uiSingleHWNDControl *) dwRefData;
|
|
|
|
LRESULT lResult;
|
|
|
|
|
|
|
|
switch (uMsg) {
|
|
|
|
case msgCOMMAND:
|
|
|
|
if ((*(c->onWM_COMMAND))((uiControl *) c, wParam, lParam, c->onCommandNotifyData, &lResult) != FALSE)
|
|
|
|
return lResult;
|
|
|
|
break;
|
|
|
|
case msgNOTIFY:
|
|
|
|
if ((*(c->onWM_NOTIFY))((uiControl *) c, wParam, lParam, c->onCommandNotifyData, &lResult) != FALSE)
|
|
|
|
return lResult;
|
|
|
|
break;
|
|
|
|
case WM_NCDESTROY:
|
|
|
|
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
|
|
|
{
|
|
|
|
uiSingleHWNDControl *c;
|
|
|
|
|
|
|
|
c = uiNew(uiSingleHWNDControl);
|
2015-04-07 00:33:26 -05:00
|
|
|
c->hwnd = CreateWindowExW(p->dwExStyle,
|
|
|
|
p->lpClassName, L"",
|
|
|
|
p->dwStyle | WS_CHILD | WS_VISIBLE,
|
2015-04-06 21:26:53 -05:00
|
|
|
0, 0,
|
|
|
|
100, 100,
|
|
|
|
// TODO specify control IDs properly
|
2015-04-07 00:33:26 -05:00
|
|
|
initialParent, NULL, p->hInstance, NULL);
|
2015-04-06 21:26:53 -05:00
|
|
|
if (c->hwnd == NULL)
|
2015-04-07 01:46:27 -05:00
|
|
|
logLastError("error creating control in uiWindowsNewControl()");
|
2015-04-06 21:26:53 -05:00
|
|
|
|
|
|
|
c->control.handle = singleHandle;
|
2015-04-06 23:23:01 -05:00
|
|
|
c->control.setParent = singleSetParent;
|
2015-04-07 00:51:17 -05:00
|
|
|
c->control.preferredSize = singlePreferredSize;
|
2015-04-06 21:26:53 -05:00
|
|
|
c->control.resize = singleResize;
|
|
|
|
c->control.containerShow = singleContainerShow;
|
|
|
|
c->control.containerHide = singleContainerHide;
|
|
|
|
|
2015-04-07 00:33:26 -05:00
|
|
|
c->onWM_COMMAND = p->onWM_COMMAND;
|
|
|
|
c->onWM_NOTIFY = p->onWM_NOTIFY;
|
|
|
|
c->onCommandNotifyData = p->onCommandNotifyData;
|
2015-04-07 00:51:17 -05:00
|
|
|
c->preferredSize = p->preferredSize;
|
|
|
|
|
2015-04-07 03:02:21 -05:00
|
|
|
c->data = p->data;
|
|
|
|
|
2015-04-07 02:12:34 -05:00
|
|
|
if ((*fv_SetWindowSubclass)(c->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
|
|
|
|
|
|
|
return (uiControl *) c;
|
2015-04-06 21:26:53 -05:00
|
|
|
}
|
2015-04-07 03:02:21 -05:00
|
|
|
|
|
|
|
void *uiWindowsControlData(uiControl *c)
|
|
|
|
{
|
|
|
|
return S(c)->data;
|
|
|
|
}
|