Mostly done with the implementation of checkboxes!
This commit is contained in:
parent
cc165b48ff
commit
7ba7222976
|
@ -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?
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -31,6 +31,7 @@ static const handlerfunc lbuttonDownHandlers[] = {
|
|||
};
|
||||
|
||||
static const handlerfunc lbuttonUpHandlers[] = {
|
||||
checkboxMouseUpHandler,
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue