Started to lay down the groundwork for handling selection.

This commit is contained in:
Pietro Gagliardi 2014-12-13 11:49:36 -05:00
parent 980868ef0d
commit 7b9b41d6cc
2 changed files with 35 additions and 9 deletions

View File

@ -18,21 +18,41 @@ static void drawCell(struct table *t, HDC dc, struct drawCellParams *p)
RECT r;
WCHAR msg[200];
int n;
HBRUSH background;
int textColor;
r.left = p->x;//TODO + p->xoff;
// TODO verify these two
background = (HBRUSH) (COLOR_WINDOW + 1);
textColor = COLOR_WINDOWTEXT;
// TODO get rid of the selectedRow/selectedColumn bits
if (t->selectedRow == p->row && t->selectedColumn == p->column) {
// 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);
textColor = COLOR_HIGHLIGHTTEXT;
if (GetFocus() != t->hwnd) {
background = (HBRUSH) (COLOR_BTNFACE + 1);
textColor = COLOR_BTNTEXT;
}
// TODO disabled
}
r.left = p->x;
r.right = p->x + p->width;
r.top = p->y;
r.bottom = p->y + p->height;
// TODO fill this rect with the appropriate background color
// TODO then vertical center content
n = wsprintf(msg, L"(%d,%d)", p->row, p->column);
if (FillRect(dc, &r, background) == 0)
panic("error filling Table cell background");
/* FillRect(dc, &r, (HBRUSH) (current + 1));
current++;
if (current >= 31)
current = 0;
*/
// now offset the content to where inside the cell it should be
r.left += p->xoff;
// TODO vertical center content too
if (SetTextColor(dc, GetSysColor(textColor)) == CLR_INVALID)
panic("error setting Table cell text color");
if (SetBkMode(dc, TRANSPARENT) == 0)
panic("error setting transparent text drawing mode for Table cell");
n = wsprintf(msg, L"(%d,%d)", p->row, p->column);
if (DrawTextExW(dc, msg, n, &r, DT_END_ELLIPSIS | DT_LEFT | DT_NOPREFIX | DT_SINGLELINE, NULL) == 0)
panic("error drawing Table cell text");
}

View File

@ -64,6 +64,8 @@ struct table {
intptr_t vpagesize; // in rows
int hwheelCarry;
int vwheelCarry;
intptr_t selectedRow;
intptr_t selectedColumn;
};
#include "util.h"
@ -92,6 +94,8 @@ static const handlerfunc handlers[] = {
static void initDummyTableStuff(struct table *t)
{
t->count = 100;
t->selectedRow = 2;
t->selectedColumn = 1;
}
static LRESULT CALLBACK tableWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
@ -110,6 +114,8 @@ static LRESULT CALLBACK tableWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
t = (struct table *) tableAlloc(sizeof (struct table), "error allocating internal Table data structure");
t->hwnd = hwnd;
makeHeader(t, cs->hInstance);
t->selectedRow = -1;
t->selectedColumn = -1;
initDummyTableStuff(t);
SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) t);
}