Set up the framework for tracking scrolling.
This commit is contained in:
parent
afc2f25e85
commit
450dba41a1
|
@ -3,8 +3,15 @@
|
|||
|
||||
#define areaClass L"libui_uiAreaClass"
|
||||
|
||||
static void doPaint(uiArea *a, uiAreaHandler *ah, HDC dc, RECT *client, RECT *clip)
|
||||
struct uiArea {
|
||||
// uiWindowsControl c;
|
||||
HWND hwnd;
|
||||
uiAreaHandler *ah;
|
||||
};
|
||||
|
||||
static void doPaint(uiArea *a, HDC dc, RECT *client, RECT *clip)
|
||||
{
|
||||
uiAreaHandler *ah = a->ah;
|
||||
uiAreaDrawParams dp;
|
||||
|
||||
dp.Context = newContext(dc);
|
||||
|
@ -29,51 +36,36 @@ static void doPaint(uiArea *a, uiAreaHandler *ah, HDC dc, RECT *client, RECT *cl
|
|||
(*(ah->Draw))(ah, a, &dp);
|
||||
}
|
||||
|
||||
struct areainit {
|
||||
uiArea *a;
|
||||
uiAreaHandler *ah;
|
||||
};
|
||||
|
||||
#define gwlpArea 0
|
||||
#define gwlpAreaHandler (sizeof (uiArea *))
|
||||
|
||||
static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
uiArea *a;
|
||||
uiAreaHandler *ah;
|
||||
struct areainit *ai;
|
||||
CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam;
|
||||
HDC dc;
|
||||
PAINTSTRUCT ps;
|
||||
RECT client;
|
||||
|
||||
a = (uiArea *) GetWindowLongPtrW(hwnd, gwlpArea);
|
||||
ah = (uiAreaHandler *) GetWindowLongPtrW(hwnd, gwlpAreaHandler);
|
||||
//TODO if (a == NULL) {
|
||||
if (ah == NULL) {
|
||||
if (uMsg == WM_NCCREATE) {
|
||||
ai = (struct areainit *) (cs->lpCreateParams);
|
||||
SetWindowLongPtrW(hwnd, gwlpArea, (LONG_PTR) (ai->a));
|
||||
SetWindowLongPtrW(hwnd, gwlpAreaHandler, (LONG_PTR) (ai->ah));
|
||||
}
|
||||
a = (uiArea *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
||||
if (a == NULL) {
|
||||
if (uMsg == WM_CREATE)
|
||||
SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) (cs->lpCreateParams));
|
||||
// fall through to DefWindowProcW() anyway
|
||||
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
switch (uMsg) {
|
||||
case WM_PAINT:
|
||||
dc = BeginPaint(hwnd, &ps);
|
||||
dc = BeginPaint(a->hwnd, &ps);
|
||||
if (dc == NULL)
|
||||
logLastError("error beginning paint in areaWndProc");
|
||||
if (GetClientRect(hwnd, &client) == 0)
|
||||
if (GetClientRect(a->hwnd, &client) == 0)
|
||||
logLastError("error getting client rect in WM_PAINT in areaWndProc()");
|
||||
doPaint(a, ah, dc, &client, &(ps.rcPaint));
|
||||
EndPaint(hwnd, &ps);
|
||||
doPaint(a, dc, &client, &(ps.rcPaint));
|
||||
EndPaint(a->hwnd, &ps);
|
||||
return 0;
|
||||
case WM_PRINTCLIENT:
|
||||
if (GetClientRect(hwnd, &client) == 0)
|
||||
if (GetClientRect(a->hwnd, &client) == 0)
|
||||
logLastError("error getting client rect in WM_PRINTCLIENT in areaWndProc()");
|
||||
doPaint(a, ah, (HDC) wParam, &client, &client);
|
||||
doPaint(a, (HDC) wParam, &client, &client);
|
||||
return 0;
|
||||
}
|
||||
return DefWindowProc(hwnd, uMsg, wParam, lParam);
|
||||
|
@ -91,7 +83,6 @@ ATOM registerAreaClass(void)
|
|||
//TODO wc.hCursor = hDefaultCursor;
|
||||
wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wc.cbWndExtra = sizeof (uiArea *) + sizeof (uiAreaHandler *);
|
||||
return RegisterClassW(&wc);
|
||||
}
|
||||
|
||||
|
@ -103,13 +94,23 @@ void unregisterAreaClass(void)
|
|||
|
||||
HWND makeArea(DWORD exstyle, DWORD style, int x, int y, int cx, int cy, HWND parent, uiAreaHandler *ah)
|
||||
{
|
||||
struct areainit ai;
|
||||
uiArea *a;
|
||||
|
||||
ai.a = NULL;
|
||||
ai.ah = ah;
|
||||
return CreateWindowExW(exstyle,
|
||||
// TODO
|
||||
a = malloc(sizeof (uiArea));
|
||||
|
||||
a->ah = ah;
|
||||
|
||||
a->hwnd = CreateWindowExW(exstyle,
|
||||
areaClass, L"",
|
||||
style | WS_HSCROLL | WS_VSCROLL,
|
||||
x, y, cx, cy,
|
||||
parent, NULL, hInstance, &ai);
|
||||
parent, NULL, hInstance, a);
|
||||
|
||||
return a->hwnd;
|
||||
}
|
||||
|
||||
void areaUpdateScroll(HWND area)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
|
|
@ -14,3 +14,5 @@ extern HRESULT logHRESULT(const char *, HRESULT);
|
|||
extern HRESULT logMemoryExhausted(const char *);
|
||||
|
||||
extern uiDrawContext *newContext(HDC);
|
||||
|
||||
extern void areaUpdateScroll(HWND);
|
||||
|
|
|
@ -11,6 +11,8 @@ struct handler {
|
|||
|
||||
static HWND area;
|
||||
static struct handler h;
|
||||
static HWND nhspinb;
|
||||
static HWND nvspinb;
|
||||
|
||||
static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p)
|
||||
{
|
||||
|
@ -89,38 +91,33 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p)
|
|||
|
||||
static uintmax_t handlerHScrollMax(uiAreaHandler *a, uiArea *area)
|
||||
{
|
||||
return 0;//TODO return gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(nhspinb));
|
||||
WCHAR c[50];
|
||||
|
||||
GetWindowTextW(nhspinb, c, 50);
|
||||
return _wtoi(c);
|
||||
}
|
||||
|
||||
static uintmax_t handlerVScrollMax(uiAreaHandler *a, uiArea *area)
|
||||
{
|
||||
return 0;//TODO return gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(nvspinb));
|
||||
}
|
||||
WCHAR c[50];
|
||||
|
||||
/* TODO
|
||||
static void recalcScroll(GtkSpinButton *sb, gpointer data)
|
||||
{
|
||||
areaUpdateScroll(area);
|
||||
GetWindowTextW(nvspinb, c, 50);
|
||||
return _wtoi(c);
|
||||
}
|
||||
|
||||
static GtkWidget *makeSpinbox(int min)
|
||||
{
|
||||
GtkWidget *sb;
|
||||
|
||||
sb = gtk_spin_button_new_with_range(min, 100000, 1);
|
||||
gtk_spin_button_set_digits(GTK_SPIN_BUTTON(sb), 0);
|
||||
g_signal_connect(sb, "value-changed", G_CALLBACK(recalcScroll), NULL);
|
||||
return sb;
|
||||
}
|
||||
*/
|
||||
|
||||
static void repos(HWND hwnd)
|
||||
{
|
||||
RECT r;
|
||||
|
||||
GetClientRect(hwnd, &r);
|
||||
SetWindowPos(area, NULL, r.left + 12, r.top + 12,
|
||||
r.right - r.left - 24, r.bottom - r.top - 24,
|
||||
SetWindowPos(nhspinb, NULL, r.left + 12, r.top + 12,
|
||||
120, 20,
|
||||
SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
|
||||
SetWindowPos(nvspinb, NULL, r.left + 12 + 120 + 6, r.top + 12,
|
||||
120, 20,
|
||||
SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
|
||||
SetWindowPos(area, NULL, r.left + 12, r.top + 12 + 20 + 6,
|
||||
r.right - r.left - 24, r.bottom - r.top - 24 - 20 - 6,
|
||||
SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
|
||||
}
|
||||
|
||||
|
@ -129,6 +126,11 @@ static LRESULT CALLBACK wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar
|
|||
WINDOWPOS *wp = (WINDOWPOS *) lParam;
|
||||
|
||||
switch (uMsg) {
|
||||
case WM_COMMAND:
|
||||
if (((HWND) lParam) == nhspinb || ((HWND) lParam) == nvspinb)
|
||||
if (HIWORD(wParam) == EN_CHANGE)
|
||||
areaUpdateScroll(area);
|
||||
break;
|
||||
case WM_WINDOWPOSCHANGED:
|
||||
if ((wp->flags & SWP_NOSIZE) != 0)
|
||||
break;
|
||||
|
@ -176,23 +178,22 @@ int main(void)
|
|||
mainwin,
|
||||
(uiAreaHandler *) (&h));
|
||||
|
||||
/* TODO
|
||||
gtk_grid_attach(GTK_GRID(grid),
|
||||
gtk_label_new("H Count"),
|
||||
0, 0, 1, 1);
|
||||
nhspinb = makeSpinbox(0);
|
||||
gtk_grid_attach(GTK_GRID(grid), nhspinb,
|
||||
1, 0, 1, 1);
|
||||
nhspinb = CreateWindowExW(WS_EX_CLIENTEDGE,
|
||||
L"edit", L"0",
|
||||
ES_NUMBER | WS_CHILD | WS_VISIBLE,
|
||||
0, 0, 100, 100,
|
||||
mainwin, NULL, hInstance, NULL);
|
||||
|
||||
gtk_grid_attach(GTK_GRID(grid),
|
||||
gtk_label_new("V Count"),
|
||||
0, 1, 1, 1);
|
||||
nvspinb = makeSpinbox(0);
|
||||
gtk_grid_attach(GTK_GRID(grid), nvspinb,
|
||||
1, 1, 1, 1);
|
||||
*/
|
||||
nvspinb = CreateWindowExW(WS_EX_CLIENTEDGE,
|
||||
L"edit", L"0",
|
||||
ES_NUMBER | WS_CHILD | WS_VISIBLE,
|
||||
0, 0, 100, 100,
|
||||
mainwin, NULL, hInstance, NULL);
|
||||
|
||||
// initial state
|
||||
repos(mainwin);
|
||||
areaUpdateScroll(area);
|
||||
|
||||
ShowWindow(mainwin, SW_SHOWDEFAULT);
|
||||
UpdateWindow(mainwin);
|
||||
|
||||
|
|
Loading…
Reference in New Issue