2015-09-16 22:15:42 -05:00
|
|
|
// 8 september 2015
|
2016-04-23 14:39:51 -05:00
|
|
|
#include "uipriv_windows.hpp"
|
|
|
|
#include "area.hpp"
|
2015-09-16 22:15:42 -05:00
|
|
|
|
|
|
|
static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
uiArea *a;
|
|
|
|
CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam;
|
2015-12-18 11:00:46 -06:00
|
|
|
RECT client;
|
2015-09-16 22:15:42 -05:00
|
|
|
WINDOWPOS *wp = (WINDOWPOS *) lParam;
|
2015-12-18 11:00:46 -06:00
|
|
|
LRESULT lResult;
|
2015-09-16 22:15:42 -05:00
|
|
|
|
|
|
|
a = (uiArea *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
|
|
|
if (a == NULL) {
|
2015-12-18 13:21:35 -06:00
|
|
|
if (uMsg == WM_CREATE) {
|
|
|
|
a = (uiArea *) (cs->lpCreateParams);
|
|
|
|
// assign a->hwnd here so we can use it immediately
|
|
|
|
a->hwnd = hwnd;
|
|
|
|
SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) a);
|
|
|
|
}
|
2015-09-16 22:15:42 -05:00
|
|
|
// fall through to DefWindowProcW() anyway
|
|
|
|
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2015-12-18 11:00:46 -06:00
|
|
|
// always recreate the render target if necessary
|
|
|
|
if (a->rt == NULL)
|
|
|
|
a->rt = makeHWNDRenderTarget(a->hwnd);
|
|
|
|
|
|
|
|
if (areaDoDraw(a, uMsg, wParam, lParam, &lResult) != FALSE)
|
|
|
|
return lResult;
|
|
|
|
|
|
|
|
if (uMsg == WM_WINDOWPOSCHANGED) {
|
2015-09-16 22:15:42 -05:00
|
|
|
if ((wp->flags & SWP_NOSIZE) != 0)
|
2015-12-18 11:00:46 -06:00
|
|
|
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
2016-04-28 15:59:26 -05:00
|
|
|
if (uiWindowsEnsureGetClientRect(a->hwnd, &client) == 0)
|
2016-04-23 14:39:51 -05:00
|
|
|
logLastError(L"error getting client rect of uiArea for WM_WINDOWPOSCHANGED handling");
|
2015-12-18 11:00:46 -06:00
|
|
|
areaDrawOnResize(a, &client);
|
2015-12-19 13:43:34 -06:00
|
|
|
areaScrollOnResize(a, &client);
|
2015-09-16 22:15:42 -05:00
|
|
|
return 0;
|
|
|
|
}
|
2015-12-18 11:00:46 -06:00
|
|
|
|
|
|
|
if (areaDoScroll(a, uMsg, wParam, lParam, &lResult) != FALSE)
|
|
|
|
return lResult;
|
|
|
|
if (areaDoEvents(a, uMsg, wParam, lParam, &lResult) != FALSE)
|
|
|
|
return lResult;
|
|
|
|
|
|
|
|
// nothing done
|
2015-09-16 22:15:42 -05:00
|
|
|
return DefWindowProc(hwnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2015-10-09 10:17:58 -05:00
|
|
|
// control implementation
|
|
|
|
|
2016-04-29 12:50:08 -05:00
|
|
|
uiWindowsControlAllDefaults(uiArea)
|
|
|
|
|
|
|
|
static void uiAreaMinimumSize(uiWindowsControl *c, intmax_t *width, intmax_t *height)
|
2015-10-09 10:17:58 -05:00
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
*width = 0;
|
|
|
|
*height = 0;
|
|
|
|
}
|
|
|
|
|
2015-11-27 20:45:30 -06:00
|
|
|
ATOM registerAreaClass(HICON hDefaultIcon, HCURSOR hDefaultCursor)
|
|
|
|
{
|
|
|
|
WNDCLASSW wc;
|
|
|
|
|
|
|
|
ZeroMemory(&wc, sizeof (WNDCLASSW));
|
|
|
|
wc.lpszClassName = areaClass;
|
|
|
|
wc.lpfnWndProc = areaWndProc;
|
|
|
|
wc.hInstance = hInstance;
|
|
|
|
wc.hIcon = hDefaultIcon;
|
|
|
|
wc.hCursor = hDefaultCursor;
|
|
|
|
wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
|
2015-12-04 20:04:51 -06:00
|
|
|
// TODO specify CS_HREDRAW/CS_VREDRAW in addition to or instead of calling InvalidateRect(NULL) in WM_WINDOWPOSCHANGED above, or not at all?
|
2015-11-27 20:45:30 -06:00
|
|
|
return RegisterClassW(&wc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void unregisterArea(void)
|
2015-09-16 22:15:42 -05:00
|
|
|
{
|
|
|
|
if (UnregisterClassW(areaClass, hInstance) == 0)
|
2016-04-23 14:39:51 -05:00
|
|
|
logLastError(L"error unregistering uiArea window class");
|
2015-09-16 22:15:42 -05:00
|
|
|
}
|
|
|
|
|
2015-12-18 11:00:46 -06:00
|
|
|
void uiAreaSetSize(uiArea *a, intmax_t width, intmax_t height)
|
2015-10-09 10:17:58 -05:00
|
|
|
{
|
2015-12-18 11:00:46 -06:00
|
|
|
a->scrollWidth = width;
|
|
|
|
a->scrollHeight = height;
|
|
|
|
areaUpdateScroll(a);
|
2015-10-09 10:17:58 -05:00
|
|
|
}
|
|
|
|
|
2015-10-09 14:27:57 -05:00
|
|
|
void uiAreaQueueRedrawAll(uiArea *a)
|
|
|
|
{
|
|
|
|
// don't erase the background; we do that ourselves in doPaint()
|
|
|
|
if (InvalidateRect(a->hwnd, NULL, FALSE) == 0)
|
2016-04-23 14:39:51 -05:00
|
|
|
logLastError(L"error queueing uiArea redraw");
|
2015-10-09 14:27:57 -05:00
|
|
|
}
|
|
|
|
|
2016-01-24 20:50:10 -06:00
|
|
|
void uiAreaScrollTo(uiArea *a, double x, double y, double width, double height)
|
2016-01-24 20:41:34 -06:00
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2015-10-09 10:17:58 -05:00
|
|
|
uiArea *uiNewArea(uiAreaHandler *ah)
|
2015-09-16 22:15:42 -05:00
|
|
|
{
|
|
|
|
uiArea *a;
|
|
|
|
|
2016-04-29 12:50:08 -05:00
|
|
|
uiWindowsNewControl(uiArea, a);
|
2015-09-16 22:15:42 -05:00
|
|
|
|
|
|
|
a->ah = ah;
|
2015-12-18 11:00:46 -06:00
|
|
|
a->scrolling = FALSE;
|
|
|
|
clickCounterReset(&(a->cc));
|
|
|
|
|
2015-12-18 13:21:35 -06:00
|
|
|
// a->hwnd is assigned in areaWndProc()
|
|
|
|
uiWindowsEnsureCreateControlHWND(0,
|
2015-12-18 11:00:46 -06:00
|
|
|
areaClass, L"",
|
|
|
|
0,
|
|
|
|
hInstance, a,
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
uiArea *uiNewScrollingArea(uiAreaHandler *ah, intmax_t width, intmax_t height)
|
|
|
|
{
|
|
|
|
uiArea *a;
|
|
|
|
|
2016-04-29 12:50:08 -05:00
|
|
|
uiWindowsNewControl(uiArea, a);
|
2015-12-18 11:00:46 -06:00
|
|
|
|
|
|
|
a->ah = ah;
|
|
|
|
a->scrolling = TRUE;
|
|
|
|
a->scrollWidth = width;
|
|
|
|
a->scrollHeight = height;
|
2015-09-16 22:15:42 -05:00
|
|
|
clickCounterReset(&(a->cc));
|
|
|
|
|
2015-12-18 13:21:35 -06:00
|
|
|
// a->hwnd is assigned in areaWndProc()
|
|
|
|
uiWindowsEnsureCreateControlHWND(0,
|
2015-10-09 10:17:58 -05:00
|
|
|
areaClass, L"",
|
|
|
|
WS_HSCROLL | WS_VSCROLL,
|
|
|
|
hInstance, a,
|
|
|
|
FALSE);
|
2015-09-16 22:15:42 -05:00
|
|
|
|
2015-12-18 14:05:49 -06:00
|
|
|
// set initial scrolling parameters
|
2015-12-18 13:21:35 -06:00
|
|
|
areaUpdateScroll(a);
|
2015-12-18 11:00:46 -06:00
|
|
|
|
2015-10-09 10:17:58 -05:00
|
|
|
return a;
|
2015-09-16 22:15:42 -05:00
|
|
|
}
|