Added keyboard selection changes.
This commit is contained in:
parent
8ef034e836
commit
47e2b2cb51
|
@ -34,7 +34,7 @@ struct table {
|
||||||
intptr_t selected;
|
intptr_t selected;
|
||||||
intptr_t count;
|
intptr_t count;
|
||||||
intptr_t firstVisible;
|
intptr_t firstVisible;
|
||||||
intptr_t pagesize;
|
intptr_t pagesize; // in rows
|
||||||
int wheelCarry;
|
int wheelCarry;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -68,6 +68,43 @@ static void redrawAll(struct table *t)
|
||||||
abort();
|
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)
|
static void selectItem(struct table *t, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
|
@ -332,6 +369,9 @@ t->selected = 5;t->count=100;//TODO
|
||||||
// TODO ensure giving focus works right
|
// TODO ensure giving focus works right
|
||||||
redrawAll(t);
|
redrawAll(t);
|
||||||
return 0;
|
return 0;
|
||||||
|
case WM_KEYDOWN:
|
||||||
|
keySelect(t, wParam, lParam);
|
||||||
|
return 0;
|
||||||
default:
|
default:
|
||||||
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue