2015-04-26 22:33:08 -05:00
|
|
|
// 26 april 2015
|
|
|
|
#include "uipriv_windows.h"
|
|
|
|
|
2015-04-27 00:27:07 -05:00
|
|
|
|
2015-04-26 22:33:08 -05:00
|
|
|
static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2015-04-27 21:17:15 -05:00
|
|
|
uiContainer *cc;
|
|
|
|
struct container *c;
|
2015-04-27 00:07:46 -05:00
|
|
|
CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam;
|
2015-04-29 18:17:26 -05:00
|
|
|
HWND control;
|
|
|
|
NMHDR *nm = (NMHDR *) lParam;
|
2015-04-27 00:27:07 -05:00
|
|
|
RECT r;
|
2015-05-05 08:10:58 -05:00
|
|
|
HDC dc;
|
|
|
|
PAINTSTRUCT ps;
|
2015-04-27 00:07:46 -05:00
|
|
|
|
2015-04-27 21:17:15 -05:00
|
|
|
cc = uiContainer(GetWindowLongPtrW(hwnd, GWLP_USERDATA));
|
|
|
|
if (cc == NULL)
|
2015-04-27 00:07:46 -05:00
|
|
|
if (uMsg == WM_NCCREATE)
|
|
|
|
SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) (cs->lpCreateParams));
|
|
|
|
// DO NOT RETURN DEFWINDOWPROC() HERE
|
|
|
|
// see the next block of comments as to why
|
|
|
|
// instead, we simply check if c == NULL again later
|
|
|
|
|
|
|
|
switch (uMsg) {
|
2015-05-04 22:06:16 -05:00
|
|
|
|
|
|
|
// these are only run if c is not NULL
|
2015-05-15 15:04:10 -05:00
|
|
|
|
2015-05-05 08:10:58 -05:00
|
|
|
case WM_PAINT:
|
|
|
|
if (cc == NULL)
|
|
|
|
break;
|
|
|
|
c = (struct container *) (uiControl(cc)->Internal);
|
|
|
|
dc = BeginPaint(c->hwnd, &ps);
|
2015-05-05 12:01:20 -05:00
|
|
|
if (dc == NULL)
|
|
|
|
logLastError("error beginning container paint in containerWndProc()");
|
2015-05-05 13:00:55 -05:00
|
|
|
r = ps.rcPaint;
|
|
|
|
paintContainerBackground(c->hwnd, dc, &r);
|
|
|
|
EndPaint(c->hwnd, &ps);
|
|
|
|
return 0;
|
2015-05-06 11:39:06 -05:00
|
|
|
// tab controls use this to draw the background of the tab area
|
|
|
|
case WM_PRINTCLIENT:
|
2015-05-05 13:00:55 -05:00
|
|
|
if (cc == NULL)
|
|
|
|
break;
|
|
|
|
c = (struct container *) (uiControl(cc)->Internal);
|
2015-05-05 12:01:20 -05:00
|
|
|
if (GetClientRect(c->hwnd, &r) == 0)
|
|
|
|
logLastError("error getting client rect in containerWndProc()");
|
2015-05-05 13:00:55 -05:00
|
|
|
paintContainerBackground(c->hwnd, (HDC) wParam, &r);
|
2015-05-05 08:10:58 -05:00
|
|
|
return 0;
|
2015-05-05 13:44:10 -05:00
|
|
|
case WM_ERASEBKGND:
|
|
|
|
// avoid some flicker
|
|
|
|
// we draw the whole update area anyway
|
|
|
|
return 1;
|
2015-04-27 00:07:46 -05:00
|
|
|
case msgUpdateChild:
|
2015-04-27 21:17:15 -05:00
|
|
|
if (cc == NULL)
|
2015-04-27 00:07:46 -05:00
|
|
|
break;
|
2015-04-27 21:17:15 -05:00
|
|
|
c = (struct container *) (uiControl(cc)->Internal);
|
|
|
|
if (GetClientRect(c->hwnd, &r) == 0)
|
2015-05-05 12:01:20 -05:00
|
|
|
logLastError("error getting client rect for resize in containerWndProc()");
|
2015-04-27 21:17:15 -05:00
|
|
|
resize(cc, &r);
|
2015-05-11 12:24:10 -05:00
|
|
|
// we used SWP_NOREDRAW for each resize so we can do this here
|
|
|
|
if (InvalidateRect(c->hwnd, NULL, TRUE) == 0)
|
|
|
|
logLastError("error queueing redraw after resize in containerWndProc()");
|
2015-04-27 00:27:07 -05:00
|
|
|
return 0;
|
2015-05-09 13:22:51 -05:00
|
|
|
|
2015-04-27 00:07:46 -05:00
|
|
|
}
|
2015-04-26 22:33:08 -05:00
|
|
|
|
|
|
|
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2015-04-27 09:37:37 -05:00
|
|
|
// subclasses override this and call back here when all children are destroyed
|
|
|
|
static void containerDestroy(uiControl *cc)
|
2015-04-26 22:33:08 -05:00
|
|
|
{
|
2015-04-27 09:37:37 -05:00
|
|
|
struct container *c = (struct container *) (cc->Internal);
|
|
|
|
|
|
|
|
if (c->parent != NULL)
|
|
|
|
complain("attempt to destroy uiContainer %p while it has a parent", cc);
|
|
|
|
if (DestroyWindow(c->hwnd) == 0)
|
|
|
|
logLastError("error destroying uiContainer window in containerDestroy()");
|
|
|
|
uiFree(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uintptr_t containerHandle(uiControl *cc)
|
|
|
|
{
|
|
|
|
struct container *c = (struct container *) (cc->Internal);
|
|
|
|
|
2015-04-27 21:17:15 -05:00
|
|
|
return (uintptr_t) (c->hwnd);
|
2015-04-27 09:37:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void containerSetParent(uiControl *cc, uiContainer *parent)
|
|
|
|
{
|
2015-04-29 00:53:39 -05:00
|
|
|
struct container *c = (struct container *) (cc->Internal);
|
2015-04-27 09:37:37 -05:00
|
|
|
uiContainer *oldparent;
|
|
|
|
HWND newparent;
|
|
|
|
|
|
|
|
oldparent = c->parent;
|
|
|
|
c->parent = parent;
|
|
|
|
newparent = initialParent;
|
|
|
|
if (c->parent != NULL)
|
|
|
|
newparent = (HWND) uiControlHandle(uiControl(c->parent));
|
|
|
|
if (SetParent(c->hwnd, newparent) == 0)
|
|
|
|
logLastError("error changing uiContainer parent in containerSetParent()");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void containerResize(uiControl *cc, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
|
|
|
|
{
|
|
|
|
struct container *c = (struct container *) (cc->Internal);
|
|
|
|
|
2015-05-07 16:40:13 -05:00
|
|
|
moveAndReorderWindow(c->hwnd, d->Sys->InsertAfter, x, y, width, height);
|
2015-05-07 13:33:46 -05:00
|
|
|
d->Sys->InsertAfter = c->hwnd;
|
2015-05-07 11:24:02 -05:00
|
|
|
SendMessageW(c->hwnd, msgUpdateChild, 0, 0);
|
2015-04-27 09:37:37 -05:00
|
|
|
}
|
|
|
|
|
2015-04-27 09:41:19 -05:00
|
|
|
static int containerVisible(uiControl *cc)
|
|
|
|
{
|
|
|
|
struct container *c = (struct container *) (cc->Internal);
|
|
|
|
|
|
|
|
return !c->hidden;
|
|
|
|
}
|
|
|
|
|
2015-04-27 09:37:37 -05:00
|
|
|
static void containerShow(uiControl *cc)
|
|
|
|
{
|
|
|
|
struct container *c = (struct container *) (cc->Internal);
|
|
|
|
|
|
|
|
ShowWindow(c->hwnd, SW_SHOW);
|
2015-04-28 20:35:29 -05:00
|
|
|
// hidden controls don't count in boxes and grids
|
2015-04-29 13:25:34 -05:00
|
|
|
c->hidden = 0;
|
2015-04-28 20:35:29 -05:00
|
|
|
if (c->parent != NULL)
|
|
|
|
uiContainerUpdate(c->parent);
|
2015-04-27 09:37:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void containerHide(uiControl *cc)
|
|
|
|
{
|
|
|
|
struct container *c = (struct container *) (cc->Internal);
|
|
|
|
|
|
|
|
ShowWindow(c->hwnd, SW_HIDE);
|
2015-04-29 13:25:34 -05:00
|
|
|
c->hidden = 1;
|
2015-04-28 20:35:29 -05:00
|
|
|
if (c->parent != NULL)
|
|
|
|
uiContainerUpdate(c->parent);
|
2015-04-27 09:37:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void containerEnable(uiControl *cc)
|
|
|
|
{
|
|
|
|
struct container *c = (struct container *) (cc->Internal);
|
2015-05-04 13:05:36 -05:00
|
|
|
uiControlSysFuncParams p;
|
2015-04-27 09:37:37 -05:00
|
|
|
|
|
|
|
EnableWindow(c->hwnd, TRUE);
|
2015-05-04 13:05:36 -05:00
|
|
|
p.Func = uiWindowsSysFuncContainerEnable;
|
|
|
|
uiControlSysFunc(cc, &p);
|
2015-04-27 09:37:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void containerDisable(uiControl *cc)
|
|
|
|
{
|
|
|
|
struct container *c = (struct container *) (cc->Internal);
|
2015-05-04 13:05:36 -05:00
|
|
|
uiControlSysFuncParams p;
|
2015-04-27 09:37:37 -05:00
|
|
|
|
|
|
|
EnableWindow(c->hwnd, FALSE);
|
2015-05-04 13:05:36 -05:00
|
|
|
p.Func = uiWindowsSysFuncContainerDisable;
|
|
|
|
uiControlSysFunc(cc, &p);
|
2015-04-27 09:37:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void containerUpdate(uiContainer *cc)
|
|
|
|
{
|
|
|
|
struct container *c = (struct container *) (uiControl(cc)->Internal);
|
|
|
|
|
|
|
|
SendMessageW(c->hwnd, msgUpdateChild, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiMakeContainer(uiContainer *cc)
|
|
|
|
{
|
|
|
|
struct container *c;
|
|
|
|
|
|
|
|
c = uiNew(struct container);
|
|
|
|
|
2015-05-03 13:12:45 -05:00
|
|
|
c->hwnd = CreateWindowExW(WS_EX_CONTROLPARENT,
|
2015-04-27 09:37:37 -05:00
|
|
|
containerClass, L"",
|
|
|
|
WS_CHILD | WS_VISIBLE,
|
|
|
|
0, 0,
|
|
|
|
100, 100,
|
|
|
|
initialParent, NULL, hInstance, cc);
|
|
|
|
if (c->hwnd == NULL)
|
|
|
|
logLastError("error creating uiContainer window in uiMakeContainer()");
|
|
|
|
|
|
|
|
uiControl(cc)->Internal = c;
|
|
|
|
uiControl(cc)->Destroy = containerDestroy;
|
|
|
|
uiControl(cc)->Handle = containerHandle;
|
|
|
|
uiControl(cc)->SetParent = containerSetParent;
|
|
|
|
// PreferredSize() is provided by subclasses
|
|
|
|
uiControl(cc)->Resize = containerResize;
|
2015-04-27 09:41:19 -05:00
|
|
|
uiControl(cc)->Visible = containerVisible;
|
2015-04-27 09:37:37 -05:00
|
|
|
uiControl(cc)->Show = containerShow;
|
|
|
|
uiControl(cc)->Hide = containerHide;
|
|
|
|
uiControl(cc)->Enable = containerEnable;
|
|
|
|
uiControl(cc)->Disable = containerDisable;
|
|
|
|
|
|
|
|
// ResizeChildren() is provided by subclasses
|
|
|
|
uiContainer(cc)->Update = containerUpdate;
|
2015-04-26 22:33:08 -05:00
|
|
|
}
|