Implemented focus coloring and redrawing.

This commit is contained in:
Pietro Gagliardi 2014-10-20 12:10:30 -04:00
parent 4e0dc24dc6
commit 8ef034e836
1 changed files with 19 additions and 4 deletions

View File

@ -237,20 +237,28 @@ static void drawItems(struct table *t, HDC dc, RECT cliprect)
for (i = first; i < last; i++) { for (i = first; i < last; i++) {
RECT rsel; RECT rsel;
HBRUSH background; HBRUSH background;
int textColor;
WCHAR msg[100]; WCHAR msg[100];
// TODO check errors // TODO check errors
// TODO verify correct colors
rsel.left = r.left; rsel.left = r.left;
rsel.top = y; rsel.top = y;
rsel.right = r.right - r.left; rsel.right = r.right - r.left;
rsel.bottom = y + tm.tmHeight; rsel.bottom = y + tm.tmHeight;
// TODO verify these two
background = (HBRUSH) (COLOR_WINDOW + 1); background = (HBRUSH) (COLOR_WINDOW + 1);
textColor = COLOR_WINDOWTEXT;
if (t->selected == i) { if (t->selected == i) {
// these are the colors wine uses (http://source.winehq.org/source/dlls/comctl32/listview.c)
// the two for unfocused are also suggested by http://stackoverflow.com/questions/10428710/windows-forms-inactive-highlight-color
background = (HBRUSH) (COLOR_HIGHLIGHT + 1); background = (HBRUSH) (COLOR_HIGHLIGHT + 1);
SetTextColor(dc, GetSysColor(COLOR_HIGHLIGHTTEXT)); textColor = COLOR_HIGHLIGHTTEXT;
} else if (GetFocus() != t->hwnd) {
SetTextColor(dc, GetSysColor(COLOR_WINDOWTEXT)); background = (HBRUSH) (COLOR_BTNFACE + 1);
textColor = COLOR_BTNTEXT;
}
}
SetTextColor(dc, GetSysColor(textColor));
FillRect(dc, &rsel, background); FillRect(dc, &rsel, background);
SetBkMode(dc, TRANSPARENT); SetBkMode(dc, TRANSPARENT);
TextOutW(dc, r.left, y, msg, wsprintf(msg, L"Item %d", i)); TextOutW(dc, r.left, y, msg, wsprintf(msg, L"Item %d", i));
@ -317,6 +325,13 @@ t->selected = 5;t->count=100;//TODO
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
selectItem(t, wParam, lParam); selectItem(t, wParam, lParam);
return 0; return 0;
case WM_SETFOCUS:
case WM_KILLFOCUS:
// all we need to do here is redraw the highlight
// TODO localize to just the selected item
// TODO ensure giving focus works right
redrawAll(t);
return 0;
default: default:
return DefWindowProcW(hwnd, uMsg, wParam, lParam); return DefWindowProcW(hwnd, uMsg, wParam, lParam);
} }