From 8f0f1ad3b5578c0a03b763f563e3d546785c517d Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 12 Nov 2014 21:58:21 -0500 Subject: [PATCH] Added cell focusing to the new Windows Table. Checkbox columns need keyboard accessibility too. For now, focus is only applied with a mouse click. --- wintable/main.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/wintable/main.c b/wintable/main.c index 28b6243..02d4172 100644 --- a/wintable/main.c +++ b/wintable/main.c @@ -76,6 +76,7 @@ struct table { HIMAGELIST checkboxes; HTHEME theme; int *columnTypes; + intptr_t focusedColumn; }; static LONG rowHeight(struct table *t) @@ -141,6 +142,25 @@ static void repositionHeader(struct table *t) t->headerHeight = headerpos.cy; } +static intptr_t hitTestColumn(struct table *t, int x) +{ + HDITEMW item; + intptr_t i; + + // TODO count dividers + for (i = 0; i < t->nColumns; i++) { + ZeroMemory(&item, sizeof (HDITEMW)); + item.mask = HDI_WIDTH; + if (SendMessageW(t->header, HDM_GETITEM, (WPARAM) i, (LPARAM) (&item)) == FALSE) + abort(); + if (x < item.cxy) + return i; + x -= item.cxy; // not yet + } + // no column + return -1; +} + static void addColumn(struct table *t, WPARAM wParam, LPARAM lParam) { HDITEMW item; @@ -334,6 +354,7 @@ static void selectItem(struct table *t, WPARAM wParam, LPARAM lParam) t->selected = y; if (t->selected >= t->count) t->selected = -1; + t->focusedColumn = hitTestColumn(t, x); finishSelect(t); } @@ -534,6 +555,14 @@ static void drawItem(struct table *t, HDC dc, intptr_t i, LONG y, LONG height, R case tableColumnCheckbox: ;// TODO } + if (t->selected == i && t->focusedColumn == j) { + rsel.left = headeritem.left; + rsel.top = y; + rsel.right = headeritem.right; + rsel.bottom = y + height; + if (DrawFocusRect(dc, &rsel) == 0) + abort(); + } } } @@ -633,6 +662,7 @@ if (ImageList_GetIconSize(t->imagelist, &unused, &(t->imagelistHeight)) == 0)abo } } t->checkboxes = makeCheckboxImageList(t->hwnd, &(t->theme)); + t->focusedColumn = -1; SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) t); } // even if we did the above, fall through