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
|
|
|
|
2016-11-27 16:34:40 -06:00
|
|
|
// TODO handle WM_DESTROY/WM_NCDESTROY
|
|
|
|
// TODO same for other Direct2D stuff
|
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-29 16:08:31 -05:00
|
|
|
uiWindowsEnsureGetClientRect(a->hwnd, &client);
|
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)
|
|
|
|
|
2016-06-13 20:05:40 -05:00
|
|
|
static void uiAreaMinimumSize(uiWindowsControl *c, int *width, int *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);
|
2016-05-29 12:07:48 -05:00
|
|
|
// this is just to be safe; see the InvalidateRect() call in the WM_WINDOWPOSCHANGED handler for more details
|
|
|
|
wc.style = CS_HREDRAW | CS_VREDRAW;
|
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
|
|
|
}
|
|
|
|
|
2016-06-13 20:05:40 -05:00
|
|
|
void uiAreaSetSize(uiArea *a, int width, int 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()
|
2016-05-17 11:41:41 -05:00
|
|
|
invalidateRect(a->hwnd, NULL, FALSE);
|
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
|
|
|
|
}
|
|
|
|
|
2016-10-25 22:24:13 -05:00
|
|
|
void uiAreaBeginUserWindowMove(uiArea *a)
|
|
|
|
{
|
|
|
|
HWND toplevel;
|
|
|
|
|
|
|
|
// TODO restrict execution
|
2016-10-25 22:41:37 -05:00
|
|
|
ReleaseCapture(); // TODO use properly and reset internal data structures
|
|
|
|
toplevel = parentToplevel(a->hwnd);
|
2016-10-25 22:24:13 -05:00
|
|
|
if (toplevel == NULL) {
|
|
|
|
// TODO
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// see http://stackoverflow.com/questions/40249940/how-do-i-initiate-a-user-mouse-driven-move-or-resize-for-custom-window-borders-o#40250654
|
|
|
|
SendMessageW(toplevel, WM_SYSCOMMAND,
|
|
|
|
SC_MOVE | 2, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiAreaBeginUserWindowResize(uiArea *a, uiWindowResizeEdge edge)
|
|
|
|
{
|
|
|
|
HWND toplevel;
|
|
|
|
WPARAM wParam;
|
|
|
|
|
|
|
|
// TODO restrict execution
|
2016-10-25 22:41:37 -05:00
|
|
|
ReleaseCapture(); // TODO use properly and reset internal data structures
|
2016-10-25 22:24:13 -05:00
|
|
|
toplevel = parentToplevel(a->hwnd);
|
|
|
|
if (toplevel == NULL) {
|
|
|
|
// TODO
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// see http://stackoverflow.com/questions/40249940/how-do-i-initiate-a-user-mouse-driven-move-or-resize-for-custom-window-borders-o#40250654
|
|
|
|
wParam = SC_SIZE;
|
|
|
|
switch (edge) {
|
2016-10-25 22:41:37 -05:00
|
|
|
case uiWindowResizeEdgeLeft:
|
2016-10-25 22:24:13 -05:00
|
|
|
wParam |= 1;
|
2016-10-25 22:41:37 -05:00
|
|
|
break;
|
|
|
|
case uiWindowResizeEdgeTop:
|
2016-10-25 22:24:13 -05:00
|
|
|
wParam |= 3;
|
2016-10-25 22:41:37 -05:00
|
|
|
break;
|
|
|
|
case uiWindowResizeEdgeRight:
|
2016-10-25 22:24:13 -05:00
|
|
|
wParam |= 2;
|
2016-10-25 22:41:37 -05:00
|
|
|
break;
|
|
|
|
case uiWindowResizeEdgeBottom:
|
2016-10-25 22:24:13 -05:00
|
|
|
wParam |= 6;
|
2016-10-25 22:41:37 -05:00
|
|
|
break;
|
|
|
|
case uiWindowResizeEdgeTopLeft:
|
2016-10-25 22:24:13 -05:00
|
|
|
wParam |= 4;
|
2016-10-25 22:41:37 -05:00
|
|
|
break;
|
|
|
|
case uiWindowResizeEdgeTopRight:
|
2016-10-25 22:24:13 -05:00
|
|
|
wParam |= 5;
|
2016-10-25 22:41:37 -05:00
|
|
|
break;
|
|
|
|
case uiWindowResizeEdgeBottomLeft:
|
2016-10-25 22:24:13 -05:00
|
|
|
wParam |= 7;
|
2016-10-25 22:41:37 -05:00
|
|
|
break;
|
2016-10-25 22:24:13 -05:00
|
|
|
case uiWindowResizeEdgeBottomRight:
|
|
|
|
wParam |= 8;
|
2016-10-25 22:41:37 -05:00
|
|
|
break;
|
2016-10-25 22:24:13 -05:00
|
|
|
}
|
|
|
|
SendMessageW(toplevel, WM_SYSCOMMAND,
|
|
|
|
wParam, 0);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-06-13 20:05:40 -05:00
|
|
|
uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height)
|
2015-12-18 11:00:46 -06:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|