diff options
| author | Pietro Gagliardi <[email protected]> | 2014-10-20 13:06:26 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-10-20 13:06:26 -0400 |
| commit | 47e2b2cb51d58bc1976e42c5a0ad438d42b5a996 (patch) | |
| tree | 19e1867e696f8af72697cf82ec307a8c208e3351 | |
| parent | 8ef034e83623c0fa30c6c3a6d43e52c9992be900 (diff) | |
Added keyboard selection changes.
| -rw-r--r-- | wintable/main.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/wintable/main.c b/wintable/main.c index 5f95689..c616fa4 100644 --- a/wintable/main.c +++ b/wintable/main.c @@ -34,7 +34,7 @@ struct table { intptr_t selected; intptr_t count; intptr_t firstVisible; - intptr_t pagesize; + intptr_t pagesize; // in rows int wheelCarry; }; @@ -68,6 +68,43 @@ static void redrawAll(struct table *t) abort(); } +static void keySelect(struct table *t, WPARAM wParam, LPARAM lParam) +{ + // TODO what happens if up/page up is pressed with nothing selected? + if (t->count == 0) // don't try to do anything if there's nothing to do + return; + switch (wParam) { + case VK_UP: + t->selected--; + break; + case VK_DOWN: + t->selected++; + break; + case VK_PRIOR: + t->selected -= t->pagesize; + break; + case VK_NEXT: + t->selected += t->pagesize; + break; + case VK_HOME: + t->selected = 0; + break; + case VK_END: + t->selected = t->count - 1; + break; + default: + // don't touch anything + return; + } + if (t->selected < 0) + t->selected = 0; + if (t->selected >= t->count) + t->selected = t->count - 1; + // TODO update only the old and new selected items + redrawAll(t); + // TODO scroll to the selected item if it's not entirely visible +} + static void selectItem(struct table *t, WPARAM wParam, LPARAM lParam) { int x, y; @@ -332,6 +369,9 @@ t->selected = 5;t->count=100;//TODO // TODO ensure giving focus works right redrawAll(t); return 0; + case WM_KEYDOWN: + keySelect(t, wParam, lParam); + return 0; default: return DefWindowProcW(hwnd, uMsg, wParam, lParam); } |
