2015-09-08 10:51:12 -05:00
|
|
|
// 8 september 2015
|
|
|
|
#include "area.h"
|
|
|
|
|
|
|
|
#define areaClass L"libui_uiAreaClass"
|
|
|
|
|
2015-09-08 19:31:15 -05:00
|
|
|
struct uiArea {
|
|
|
|
// uiWindowsControl c;
|
|
|
|
HWND hwnd;
|
|
|
|
uiAreaHandler *ah;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void doPaint(uiArea *a, HDC dc, RECT *client, RECT *clip)
|
2015-09-08 10:51:12 -05:00
|
|
|
{
|
2015-09-08 19:31:15 -05:00
|
|
|
uiAreaHandler *ah = a->ah;
|
2015-09-08 10:51:12 -05:00
|
|
|
uiAreaDrawParams dp;
|
|
|
|
|
|
|
|
dp.Context = newContext(dc);
|
|
|
|
|
|
|
|
dp.ClientWidth = client->right - client->left;
|
|
|
|
dp.ClientHeight = client->bottom - client->top;
|
|
|
|
|
|
|
|
dp.ClipX = clip->left;
|
|
|
|
dp.ClipY = clip->top;
|
|
|
|
dp.ClipWidth = clip->right - clip->left;
|
|
|
|
dp.ClipHeight = clip->bottom - clip->top;
|
|
|
|
|
|
|
|
// TODO is this really the best for multimonitor setups?
|
|
|
|
dp.DPIX = GetDeviceCaps(dc, LOGPIXELSX);
|
|
|
|
dp.DPIY = GetDeviceCaps(dc, LOGPIXELSY);
|
|
|
|
|
|
|
|
/* TODO
|
|
|
|
dp.HScrollPos = gtk_adjustment_get_value(ap->ha);
|
|
|
|
dp.VScrollPos = gtk_adjustment_get_value(ap->va);
|
|
|
|
*/
|
|
|
|
|
|
|
|
(*(ah->Draw))(ah, a, &dp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
uiArea *a;
|
|
|
|
CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam;
|
|
|
|
HDC dc;
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
RECT client;
|
|
|
|
|
2015-09-08 19:31:15 -05:00
|
|
|
a = (uiArea *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
|
|
|
if (a == NULL) {
|
|
|
|
if (uMsg == WM_CREATE)
|
|
|
|
SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) (cs->lpCreateParams));
|
2015-09-08 10:51:12 -05:00
|
|
|
// fall through to DefWindowProcW() anyway
|
|
|
|
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (uMsg) {
|
|
|
|
case WM_PAINT:
|
2015-09-08 19:31:15 -05:00
|
|
|
dc = BeginPaint(a->hwnd, &ps);
|
2015-09-08 10:51:12 -05:00
|
|
|
if (dc == NULL)
|
|
|
|
logLastError("error beginning paint in areaWndProc");
|
2015-09-08 19:31:15 -05:00
|
|
|
if (GetClientRect(a->hwnd, &client) == 0)
|
2015-09-08 10:51:12 -05:00
|
|
|
logLastError("error getting client rect in WM_PAINT in areaWndProc()");
|
2015-09-08 19:31:15 -05:00
|
|
|
doPaint(a, dc, &client, &(ps.rcPaint));
|
|
|
|
EndPaint(a->hwnd, &ps);
|
2015-09-08 10:51:12 -05:00
|
|
|
return 0;
|
|
|
|
case WM_PRINTCLIENT:
|
2015-09-08 19:31:15 -05:00
|
|
|
if (GetClientRect(a->hwnd, &client) == 0)
|
2015-09-08 10:51:12 -05:00
|
|
|
logLastError("error getting client rect in WM_PRINTCLIENT in areaWndProc()");
|
2015-09-08 19:31:15 -05:00
|
|
|
doPaint(a, (HDC) wParam, &client, &client);
|
2015-09-08 10:51:12 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return DefWindowProc(hwnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
ATOM registerAreaClass(void)
|
|
|
|
{
|
|
|
|
WNDCLASSW wc;
|
|
|
|
|
|
|
|
ZeroMemory(&wc, sizeof (WNDCLASSW));
|
|
|
|
wc.lpszClassName = areaClass;
|
|
|
|
wc.lpfnWndProc = areaWndProc;
|
|
|
|
wc.hInstance = hInstance;
|
|
|
|
//TODO wc.hIcon = hDefaultIcon;
|
|
|
|
//TODO wc.hCursor = hDefaultCursor;
|
|
|
|
wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
|
|
|
|
wc.style = CS_HREDRAW | CS_VREDRAW;
|
|
|
|
return RegisterClassW(&wc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void unregisterAreaClass(void)
|
|
|
|
{
|
|
|
|
if (UnregisterClassW(areaClass, hInstance) == 0)
|
|
|
|
logLastError("error unregistering uiArea window class in unregisterAreaClass()");
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND makeArea(DWORD exstyle, DWORD style, int x, int y, int cx, int cy, HWND parent, uiAreaHandler *ah)
|
|
|
|
{
|
2015-09-08 19:31:15 -05:00
|
|
|
uiArea *a;
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
a = malloc(sizeof (uiArea));
|
|
|
|
|
|
|
|
a->ah = ah;
|
2015-09-08 10:51:12 -05:00
|
|
|
|
2015-09-08 19:31:15 -05:00
|
|
|
a->hwnd = CreateWindowExW(exstyle,
|
2015-09-08 10:51:12 -05:00
|
|
|
areaClass, L"",
|
|
|
|
style | WS_HSCROLL | WS_VSCROLL,
|
|
|
|
x, y, cx, cy,
|
2015-09-08 19:31:15 -05:00
|
|
|
parent, NULL, hInstance, a);
|
|
|
|
|
|
|
|
return a->hwnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void areaUpdateScroll(HWND area)
|
|
|
|
{
|
|
|
|
// TODO
|
2015-09-08 10:51:12 -05:00
|
|
|
}
|