Implemented checkbox notifications.

This commit is contained in:
Pietro Gagliardi 2015-01-07 21:34:12 -05:00
parent 10cee92223
commit 7eaadad25c
4 changed files with 32 additions and 25 deletions

View File

@ -199,9 +199,6 @@ HANDLER(checkboxMouseDownHandler)
return TRUE;
}
// TODO get rid of this
struct rowcol lastCheckbox;
HANDLER(checkboxMouseUpHandler)
{
struct rowcol rc;
@ -225,8 +222,7 @@ HANDLER(checkboxMouseUpHandler)
pt.y = GET_Y_LPARAM(lParam);
if (PtInRect(&r, pt) == 0)
goto wrongUp;
// TODO send toggle event
lastCheckbox = rc;
notify(t, tableNotificationCellCheckboxToggled, rc.row, rc.column, 0);
t->checkboxMouseDown = FALSE;
// TODO redraw the whole cell?
if (InvalidateRect(t->hwnd, &r, TRUE) == 0)

View File

@ -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);
}
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)
{
RECT r;
HBRUSH background;
int textColor;
POINT pt;
int cbState;
RECT cellrect;
// TODO verify these two
@ -107,20 +126,7 @@ static void drawCell(struct table *t, HDC dc, struct drawCellParams *p)
drawImageCell(t, dc, p, &r);
break;
case tableColumnCheckbox:
toCheckboxRect(t, &r, p->xoff);
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);
drawCheckboxCell(t, dc, p, &r);
break;
}

View File

@ -45,7 +45,7 @@ enum {
tableNotificationFinishedWithCellData,
// data is zero
// no return
tableNotificationToggleCellCheckbox,
tableNotificationCellCheckboxToggled,
};
typedef struct tableNM tableNM;

View File

@ -51,6 +51,8 @@ void mainwinResize(HWND hwnd, UINT state, int cx, int cy)
MoveWindow(tablehwnd, 0, 0, cx, cy, TRUE);
}
BOOL checkboxstates[100];
LRESULT CALLBACK mainwndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
NMHDR *nmhdr = (NMHDR *) lParam;
@ -58,6 +60,8 @@ LRESULT CALLBACK mainwndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
WCHAR *text;
int n;
if (uMsg == WM_CREATE)
ZeroMemory(checkboxstates, 100 * sizeof (BOOL));
switch (uMsg) {
HANDLE_MSG(hwnd, WM_CREATE, mainwinCreate);
HANDLE_MSG(hwnd, WM_SIZE, mainwinResize);
@ -78,7 +82,7 @@ LRESULT CALLBACK mainwndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case tableColumnImage:
return (LRESULT) mkbitmap();
case tableColumnCheckbox:
; // TODO
return (LRESULT) (checkboxstates[nm->row]);
}
panic("(test program) unreachable");
case tableNotificationFinishedWithCellData:
@ -92,8 +96,9 @@ LRESULT CALLBACK mainwndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
break;
}
return 0;
case tableNotificationToggleCellCheckbox:
; // TODO
case tableNotificationCellCheckboxToggled:
checkboxstates[nm->row] = !checkboxstates[nm->row];
return 0;
}
break;
}