2015-05-14 12:42:28 -05:00
|
|
|
// 26 april 2015
|
2016-04-22 19:37:28 -05:00
|
|
|
#include "uipriv_windows.hpp"
|
2015-05-14 12:42:28 -05:00
|
|
|
|
2015-08-30 18:32:05 -05:00
|
|
|
// Code for the HWND of the following uiControls:
|
|
|
|
// - uiBox
|
|
|
|
// - uiRadioButtons
|
2015-05-14 12:42:28 -05:00
|
|
|
|
2016-04-26 21:17:42 -05:00
|
|
|
struct containerInit {
|
2016-04-28 16:18:51 -05:00
|
|
|
uiWindowsControl *c;
|
|
|
|
void (*onResize)(uiWindowsControl *);
|
2016-04-26 21:17:42 -05:00
|
|
|
};
|
|
|
|
|
2015-05-14 12:42:28 -05:00
|
|
|
static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
RECT r;
|
|
|
|
HDC dc;
|
|
|
|
PAINTSTRUCT ps;
|
2016-04-26 21:17:42 -05:00
|
|
|
CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam;
|
|
|
|
WINDOWPOS *wp = (WINDOWPOS *) lParam;
|
2016-04-28 16:18:51 -05:00
|
|
|
MINMAXINFO *mm = (MINMAXINFO *) lParam;
|
2016-04-26 21:17:42 -05:00
|
|
|
struct containerInit *init;
|
2016-04-28 16:18:51 -05:00
|
|
|
uiWindowsControl *c;
|
|
|
|
void (*onResize)(uiWindowsControl *);
|
|
|
|
uintmax_t minwid, minht;
|
2015-05-18 08:52:37 -05:00
|
|
|
LRESULT lResult;
|
2015-05-14 12:42:28 -05:00
|
|
|
|
2015-05-18 08:52:37 -05:00
|
|
|
if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE)
|
|
|
|
return lResult;
|
2015-05-14 12:42:28 -05:00
|
|
|
switch (uMsg) {
|
2016-04-26 21:17:42 -05:00
|
|
|
case WM_CREATE:
|
|
|
|
init = (struct containerInit *) (cs->lpParam);
|
|
|
|
SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) (init->onResize));
|
2016-04-28 16:18:51 -05:00
|
|
|
SetWindowLongPtrW(hwnd, 0, (LONG_PTR) (init->c));
|
2016-04-26 21:17:42 -05:00
|
|
|
break; // defer to DefWindowProc()
|
|
|
|
case WM_WINDOWPOSCHANGED:
|
|
|
|
if ((wp->flags & SWP_NOSIZE) != 0)
|
|
|
|
break; // defer to DefWindowProc();
|
2016-04-28 16:18:51 -05:00
|
|
|
onResize = (void (*)(uiControl *)) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
|
|
|
c = (uiWindowsControl *) GetWindowLongPtrW(hwnd, 0);
|
2016-04-26 21:17:42 -05:00
|
|
|
(*(onResize))(data);
|
|
|
|
return 0;
|
2016-04-28 16:18:51 -05:00
|
|
|
case WM_GETMINMAXINFO:
|
|
|
|
lResult = DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
|
|
|
c = (uiWindowsControl *) GetWindowLongPtrW(hwnd, 0);
|
|
|
|
uiWindowsControlMinimumSize(c, &minwid, &minht);
|
|
|
|
mmi->ptMinTrackSize.x = minwid;
|
|
|
|
mmi->ptMinTrackSize.y = minht;
|
|
|
|
return lResult;
|
2015-05-14 12:42:28 -05:00
|
|
|
case WM_PAINT:
|
2015-06-06 15:01:32 -05:00
|
|
|
dc = BeginPaint(hwnd, &ps);
|
2016-04-22 19:37:28 -05:00
|
|
|
if (dc == NULL) {
|
|
|
|
logLastError(L"error beginning container paint");
|
|
|
|
// bail out; hope DefWindowProc() catches us
|
|
|
|
break;
|
|
|
|
}
|
2015-05-14 12:42:28 -05:00
|
|
|
r = ps.rcPaint;
|
|
|
|
paintContainerBackground(hwnd, dc, &r);
|
|
|
|
EndPaint(hwnd, &ps);
|
|
|
|
return 0;
|
|
|
|
// tab controls use this to draw the background of the tab area
|
|
|
|
case WM_PRINTCLIENT:
|
2016-04-28 15:59:26 -05:00
|
|
|
if (uiWindowsEnsureGetClientRect(hwnd, &r) == 0) {
|
2016-04-22 19:37:28 -05:00
|
|
|
logLastError(L"error getting client rect");
|
|
|
|
// likewise
|
|
|
|
break;
|
|
|
|
}
|
2015-05-14 12:42:28 -05:00
|
|
|
paintContainerBackground(hwnd, (HDC) wParam, &r);
|
|
|
|
return 0;
|
|
|
|
case WM_ERASEBKGND:
|
|
|
|
// avoid some flicker
|
|
|
|
// we draw the whole update area anyway
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
ATOM initContainer(HICON hDefaultIcon, HCURSOR hDefaultCursor)
|
|
|
|
{
|
|
|
|
WNDCLASSW wc;
|
|
|
|
|
|
|
|
ZeroMemory(&wc, sizeof (WNDCLASSW));
|
|
|
|
wc.lpszClassName = containerClass;
|
|
|
|
wc.lpfnWndProc = containerWndProc;
|
|
|
|
wc.hInstance = hInstance;
|
|
|
|
wc.hIcon = hDefaultIcon;
|
|
|
|
wc.hCursor = hDefaultCursor;
|
|
|
|
wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
|
2016-04-26 21:17:42 -05:00
|
|
|
wc.cbWndExtra = sizeof (void *);
|
2015-05-14 12:42:28 -05:00
|
|
|
return RegisterClassW(&wc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uninitContainer(void)
|
|
|
|
{
|
|
|
|
if (UnregisterClassW(containerClass, hInstance) == 0)
|
2016-04-23 20:38:51 -05:00
|
|
|
logLastError(L"error unregistering container window class");
|
2015-05-14 12:42:28 -05:00
|
|
|
}
|
|
|
|
|
2016-04-28 16:18:51 -05:00
|
|
|
HWND uiWindowsMakeContainer(uiWindowsControl *c, void (*onResize)(uiWindowsControl *))
|
2015-05-14 12:42:28 -05:00
|
|
|
{
|
2016-04-26 21:17:42 -05:00
|
|
|
struct containerInit init;
|
|
|
|
|
|
|
|
// TODO onResize cannot be NULL
|
2016-04-28 16:18:51 -05:00
|
|
|
init.c = c;
|
2016-04-26 21:17:42 -05:00
|
|
|
init.onResize = onResize;
|
2015-08-31 11:33:44 -05:00
|
|
|
return uiWindowsEnsureCreateControlHWND(WS_EX_CONTROLPARENT,
|
2015-05-29 19:44:30 -05:00
|
|
|
containerClass, L"",
|
|
|
|
0,
|
2016-04-26 21:17:42 -05:00
|
|
|
hInstance, (LPVOID) (&init),
|
2015-05-29 19:44:30 -05:00
|
|
|
FALSE);
|
2015-05-14 12:42:28 -05:00
|
|
|
}
|