From 7ba7222976b1260065d633855830ffd20e153bf0 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 22 Dec 2014 20:15:10 -0500 Subject: [PATCH] Mostly done with the implementation of checkboxes! --- wintable/new/checkboxes.h | 68 +++++++++++++++++++++++++++++++++++++++ wintable/new/draw.h | 7 +++- wintable/new/events.h | 1 + wintable/new/main.c | 4 +++ wintable/new/select.h | 5 +++ 5 files changed, 84 insertions(+), 1 deletion(-) diff --git a/wintable/new/checkboxes.h b/wintable/new/checkboxes.h index 11dea56..4308817 100644 --- a/wintable/new/checkboxes.h +++ b/wintable/new/checkboxes.h @@ -176,3 +176,71 @@ HANDLER(checkboxMouseLeaveHandler) *lResult = 0; return TRUE; } + +HANDLER(checkboxMouseDownHandler) +{ + struct rowcol rc; + RECT r; + POINT pt; + + rc = lParamToRowColumn(t, lParam); + if (rc.row == -1 || rc.column == -1) + return FALSE; + if (t->columnTypes[rc.column] != tableColumnCheckbox) + return FALSE; + if (!rowColumnToClientRect(t, rc, &r)) + return FALSE; + toCheckboxRect(t, &r, 0); + pt.x = GET_X_LPARAM(lParam); + pt.y = GET_Y_LPARAM(lParam); + if (PtInRect(&r, pt) == 0) + return FALSE; + t->checkboxMouseDown = TRUE; + t->checkboxMouseDownRow = rc.row; + t->checkboxMouseDownColumn = rc.column; + // TODO redraw the whole cell? + if (InvalidateRect(t->hwnd, &r, TRUE) == 0) + panic("error redrawing Table checkbox after mouse down"); + *lResult = 0; + return TRUE; +} + +// TODO get rid of this +struct rowcol lastCheckbox; + +HANDLER(checkboxMouseUpHandler) +{ + struct rowcol rc; + RECT r; + POINT pt; + + if (!t->checkboxMouseDown) + return FALSE; + // the logic behind goto wrongUp is that the mouse must be released on the same checkbox + rc = lParamToRowColumn(t, lParam); + if (rc.row == -1 || rc.column == -1) + goto wrongUp; + if (rc.row != t->checkboxMouseDownRow && rc.column != t->checkboxMouseDownColumn) + goto wrongUp; + if (t->columnTypes[rc.column] != tableColumnCheckbox) + goto wrongUp; + if (!rowColumnToClientRect(t, rc, &r)) + goto wrongUp; + toCheckboxRect(t, &r, 0); + pt.x = GET_X_LPARAM(lParam); + pt.y = GET_Y_LPARAM(lParam); + if (PtInRect(&r, pt) == 0) + goto wrongUp; + // TODO send toggle event +lastCheckbox = rc; + t->checkboxMouseDown = FALSE; + // TODO redraw the whole cell? + if (InvalidateRect(t->hwnd, &r, TRUE) == 0) + panic("error redrawing Table checkbox after mouse up"); + *lResult = 0; + return TRUE; +wrongUp: + // TODO redraw the invalid cell + t->checkboxMouseDown = FALSE; + return FALSE; // TODO really? +} diff --git a/wintable/new/draw.h b/wintable/new/draw.h index 42e6e4f..e7ca331 100644 --- a/wintable/new/draw.h +++ b/wintable/new/draw.h @@ -57,7 +57,12 @@ static void drawCell(struct table *t, HDC dc, struct drawCellParams *p) case tableColumnCheckbox: toCheckboxRect(t, &r, p->xoff); SetDCBrushColor(dc, RGB(255, 0, 0)); - if (t->checkboxMouseOverLast) { + if (p->row == lastCheckbox.row && p->column == lastCheckbox.column) + SetDCBrushColor(dc, RGB(128, 0, 128)); + if (t->checkboxMouseDown) { + if (p->row == t->checkboxMouseDownRow && p->column == t->checkboxMouseDownColumn) + SetDCBrushColor(dc, RGB(0, 0, 255)); + } else if (t->checkboxMouseOverLast) { // TODO else? pt.x = GET_X_LPARAM(t->checkboxMouseOverLastPoint); pt.y = GET_Y_LPARAM(t->checkboxMouseOverLastPoint); if (PtInRect(&r, pt) != 0) diff --git a/wintable/new/events.h b/wintable/new/events.h index a814638..fbd1522 100644 --- a/wintable/new/events.h +++ b/wintable/new/events.h @@ -31,6 +31,7 @@ static const handlerfunc lbuttonDownHandlers[] = { }; static const handlerfunc lbuttonUpHandlers[] = { + checkboxMouseUpHandler, NULL, }; diff --git a/wintable/new/main.c b/wintable/new/main.c index 43e4391..56aee2f 100644 --- a/wintable/new/main.c +++ b/wintable/new/main.c @@ -32,6 +32,7 @@ // - WM_THEMECHANGED, etc. // - see if vertical centering is really what we want or if we just want to offset by a few pixels or so // - going right from column 0 to column 2 with the right arrow key deselects +// - make sure all error messages involving InvalidateRect() are consistent with regards to "redrawing" and "queueing for redraw" #define tableWindowClass L"gouitable" @@ -77,6 +78,9 @@ struct table { int checkboxHeight; BOOL checkboxMouseOverLast; LPARAM checkboxMouseOverLastPoint; + BOOL checkboxMouseDown; + intptr_t checkboxMouseDownRow; + intptr_t checkboxMouseDownColumn; }; #include "util.h" diff --git a/wintable/new/select.h b/wintable/new/select.h index b0210fe..0539e52 100644 --- a/wintable/new/select.h +++ b/wintable/new/select.h @@ -101,6 +101,9 @@ noScroll: } } +// TODO make this needless +HANDLER(checkboxMouseDownHandler); + // TODO which WM_xBUTTONDOWNs? HANDLER(mouseDownSelectHandler) { @@ -109,6 +112,8 @@ HANDLER(mouseDownSelectHandler) rc = lParamToRowColumn(t, lParam); // don't check if lParamToRowColumn() returned row -1 or column -1; we want deselection behavior doselect(t, rc.row, rc.column); + // TODO separate this from here + checkboxMouseDownHandler(t, uMsg, wParam, lParam, lResult); *lResult = 0; return TRUE; }