Implemented checkbox notifications.
This commit is contained in:
parent
10cee92223
commit
7eaadad25c
|
@ -199,9 +199,6 @@ HANDLER(checkboxMouseDownHandler)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO get rid of this
|
|
||||||
struct rowcol lastCheckbox;
|
|
||||||
|
|
||||||
HANDLER(checkboxMouseUpHandler)
|
HANDLER(checkboxMouseUpHandler)
|
||||||
{
|
{
|
||||||
struct rowcol rc;
|
struct rowcol rc;
|
||||||
|
@ -225,8 +222,7 @@ HANDLER(checkboxMouseUpHandler)
|
||||||
pt.y = GET_Y_LPARAM(lParam);
|
pt.y = GET_Y_LPARAM(lParam);
|
||||||
if (PtInRect(&r, pt) == 0)
|
if (PtInRect(&r, pt) == 0)
|
||||||
goto wrongUp;
|
goto wrongUp;
|
||||||
// TODO send toggle event
|
notify(t, tableNotificationCellCheckboxToggled, rc.row, rc.column, 0);
|
||||||
lastCheckbox = rc;
|
|
||||||
t->checkboxMouseDown = FALSE;
|
t->checkboxMouseDown = FALSE;
|
||||||
// TODO redraw the whole cell?
|
// TODO redraw the whole cell?
|
||||||
if (InvalidateRect(t->hwnd, &r, TRUE) == 0)
|
if (InvalidateRect(t->hwnd, &r, TRUE) == 0)
|
||||||
|
|
|
@ -67,13 +67,32 @@ static void drawImageCell(struct table *t, HDC dc, struct drawCellParams *p, REC
|
||||||
notify(t, tableNotificationFinishedWithCellData, p->row, p->column, (uintptr_t) bitmap);
|
notify(t, tableNotificationFinishedWithCellData, p->row, p->column, (uintptr_t) bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void drawCheckboxCell(struct table *t, HDC dc, struct drawCellParams *p, RECT *r)
|
||||||
|
{
|
||||||
|
POINT pt;
|
||||||
|
int cbState;
|
||||||
|
|
||||||
|
toCheckboxRect(t, r, p->xoff);
|
||||||
|
cbState = 0;
|
||||||
|
if (notify(t, tableNotificationGetCellData, p->row, p->column, 0) != 0)
|
||||||
|
cbState |= checkboxStateChecked;
|
||||||
|
if (t->checkboxMouseDown)
|
||||||
|
if (p->row == t->checkboxMouseDownRow && p->column == t->checkboxMouseDownColumn)
|
||||||
|
cbState |= checkboxStatePushed;
|
||||||
|
if (t->checkboxMouseOverLast) {
|
||||||
|
pt.x = GET_X_LPARAM(t->checkboxMouseOverLastPoint);
|
||||||
|
pt.y = GET_Y_LPARAM(t->checkboxMouseOverLastPoint);
|
||||||
|
if (PtInRect(r, pt) != 0)
|
||||||
|
cbState |= checkboxStateHot;
|
||||||
|
}
|
||||||
|
drawCheckbox(t, dc, r, cbState);
|
||||||
|
}
|
||||||
|
|
||||||
static void drawCell(struct table *t, HDC dc, struct drawCellParams *p)
|
static void drawCell(struct table *t, HDC dc, struct drawCellParams *p)
|
||||||
{
|
{
|
||||||
RECT r;
|
RECT r;
|
||||||
HBRUSH background;
|
HBRUSH background;
|
||||||
int textColor;
|
int textColor;
|
||||||
POINT pt;
|
|
||||||
int cbState;
|
|
||||||
RECT cellrect;
|
RECT cellrect;
|
||||||
|
|
||||||
// TODO verify these two
|
// TODO verify these two
|
||||||
|
@ -107,20 +126,7 @@ static void drawCell(struct table *t, HDC dc, struct drawCellParams *p)
|
||||||
drawImageCell(t, dc, p, &r);
|
drawImageCell(t, dc, p, &r);
|
||||||
break;
|
break;
|
||||||
case tableColumnCheckbox:
|
case tableColumnCheckbox:
|
||||||
toCheckboxRect(t, &r, p->xoff);
|
drawCheckboxCell(t, dc, p, &r);
|
||||||
cbState = 0;
|
|
||||||
if (p->row == lastCheckbox.row && p->column == lastCheckbox.column)
|
|
||||||
cbState |= checkboxStateChecked;
|
|
||||||
if (t->checkboxMouseDown)
|
|
||||||
if (p->row == t->checkboxMouseDownRow && p->column == t->checkboxMouseDownColumn)
|
|
||||||
cbState |= checkboxStatePushed;
|
|
||||||
if (t->checkboxMouseOverLast) {
|
|
||||||
pt.x = GET_X_LPARAM(t->checkboxMouseOverLastPoint);
|
|
||||||
pt.y = GET_Y_LPARAM(t->checkboxMouseOverLastPoint);
|
|
||||||
if (PtInRect(&r, pt) != 0)
|
|
||||||
cbState |= checkboxStateHot;
|
|
||||||
}
|
|
||||||
drawCheckbox(t, dc, &r, cbState);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ enum {
|
||||||
tableNotificationFinishedWithCellData,
|
tableNotificationFinishedWithCellData,
|
||||||
// data is zero
|
// data is zero
|
||||||
// no return
|
// no return
|
||||||
tableNotificationToggleCellCheckbox,
|
tableNotificationCellCheckboxToggled,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct tableNM tableNM;
|
typedef struct tableNM tableNM;
|
||||||
|
|
|
@ -51,6 +51,8 @@ void mainwinResize(HWND hwnd, UINT state, int cx, int cy)
|
||||||
MoveWindow(tablehwnd, 0, 0, cx, cy, TRUE);
|
MoveWindow(tablehwnd, 0, 0, cx, cy, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL checkboxstates[100];
|
||||||
|
|
||||||
LRESULT CALLBACK mainwndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
LRESULT CALLBACK mainwndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
NMHDR *nmhdr = (NMHDR *) lParam;
|
NMHDR *nmhdr = (NMHDR *) lParam;
|
||||||
|
@ -58,6 +60,8 @@ LRESULT CALLBACK mainwndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
WCHAR *text;
|
WCHAR *text;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
|
if (uMsg == WM_CREATE)
|
||||||
|
ZeroMemory(checkboxstates, 100 * sizeof (BOOL));
|
||||||
switch (uMsg) {
|
switch (uMsg) {
|
||||||
HANDLE_MSG(hwnd, WM_CREATE, mainwinCreate);
|
HANDLE_MSG(hwnd, WM_CREATE, mainwinCreate);
|
||||||
HANDLE_MSG(hwnd, WM_SIZE, mainwinResize);
|
HANDLE_MSG(hwnd, WM_SIZE, mainwinResize);
|
||||||
|
@ -78,7 +82,7 @@ LRESULT CALLBACK mainwndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
case tableColumnImage:
|
case tableColumnImage:
|
||||||
return (LRESULT) mkbitmap();
|
return (LRESULT) mkbitmap();
|
||||||
case tableColumnCheckbox:
|
case tableColumnCheckbox:
|
||||||
; // TODO
|
return (LRESULT) (checkboxstates[nm->row]);
|
||||||
}
|
}
|
||||||
panic("(test program) unreachable");
|
panic("(test program) unreachable");
|
||||||
case tableNotificationFinishedWithCellData:
|
case tableNotificationFinishedWithCellData:
|
||||||
|
@ -92,8 +96,9 @@ LRESULT CALLBACK mainwndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
case tableNotificationToggleCellCheckbox:
|
case tableNotificationCellCheckboxToggled:
|
||||||
; // TODO
|
checkboxstates[nm->row] = !checkboxstates[nm->row];
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue