2014-12-08 09:01:41 -06:00
|
|
|
// 8 december 2014
|
|
|
|
|
2014-12-08 20:42:00 -06:00
|
|
|
struct drawCellParams {
|
|
|
|
intptr_t row;
|
|
|
|
intptr_t column;
|
|
|
|
LONG x;
|
|
|
|
LONG y;
|
|
|
|
LONG width; // of column
|
|
|
|
LONG height; // rowHeight()
|
|
|
|
LRESULT xoff; // result of HDM_GETBITMAPMARGIN
|
|
|
|
};
|
|
|
|
|
2014-12-12 09:47:23 -06:00
|
|
|
//TODO delete when done
|
|
|
|
static int current = 0;
|
|
|
|
|
2014-12-08 20:42:00 -06:00
|
|
|
static void drawCell(struct table *t, HDC dc, struct drawCellParams *p)
|
|
|
|
{
|
|
|
|
RECT r;
|
|
|
|
WCHAR msg[200];
|
|
|
|
int n;
|
|
|
|
|
2014-12-12 09:47:23 -06:00
|
|
|
r.left = p->x;//TODO + p->xoff;
|
2014-12-08 20:42:00 -06:00
|
|
|
r.right = p->x + p->width;
|
|
|
|
r.top = p->y;
|
|
|
|
r.bottom = p->y + p->height;
|
2014-12-08 20:43:07 -06:00
|
|
|
// TODO fill this rect with the appropriate background color
|
|
|
|
// TODO then vertical center content
|
2014-12-08 20:42:00 -06:00
|
|
|
n = wsprintf(msg, L"(%d,%d)", p->row, p->column);
|
2014-12-12 09:47:23 -06:00
|
|
|
|
|
|
|
FillRect(dc, &r, (HBRUSH) (current + 1));
|
|
|
|
current++;
|
|
|
|
if (current >= 31)
|
|
|
|
current = 0;
|
|
|
|
|
|
|
|
r.left += p->xoff;
|
2014-12-08 20:42:00 -06:00
|
|
|
if (DrawTextExW(dc, msg, n, &r, DT_END_ELLIPSIS | DT_LEFT | DT_NOPREFIX | DT_SINGLELINE, NULL) == 0)
|
|
|
|
panic("error drawing Table cell text");
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:01:41 -06:00
|
|
|
static void draw(struct table *t, HDC dc, RECT cliprect, RECT client)
|
|
|
|
{
|
2014-12-12 09:47:23 -06:00
|
|
|
intptr_t i, j;
|
2014-12-08 09:40:51 -06:00
|
|
|
RECT r;
|
|
|
|
int x = 0;
|
2014-12-08 15:23:55 -06:00
|
|
|
HFONT prevfont, newfont;
|
2014-12-08 20:42:00 -06:00
|
|
|
struct drawCellParams p;
|
2014-12-08 09:40:51 -06:00
|
|
|
|
2014-12-08 15:23:55 -06:00
|
|
|
prevfont = selectFont(t, dc, &newfont);
|
2014-12-12 09:47:23 -06:00
|
|
|
|
|
|
|
current = 0;
|
|
|
|
|
|
|
|
client.top += t->headerHeight;
|
|
|
|
|
2014-12-08 20:42:00 -06:00
|
|
|
ZeroMemory(&p, sizeof (struct drawCellParams));
|
|
|
|
p.height = rowHeight(t, dc, FALSE);
|
|
|
|
p.xoff = SendMessageW(t->header, HDM_GETBITMAPMARGIN, 0, 0);
|
2014-12-12 09:47:23 -06:00
|
|
|
|
|
|
|
p.y = client.top;
|
|
|
|
for (i = 0; i < t->count; i++) {
|
|
|
|
p.row = i;
|
|
|
|
p.x = client.left - t->hscrollpos;
|
|
|
|
for (j = 0; j < t->nColumns; j++) {
|
|
|
|
p.column = j;
|
|
|
|
// TODO error check
|
|
|
|
SendMessage(t->header, HDM_GETITEMRECT, (WPARAM) j, (LPARAM) (&r));
|
|
|
|
p.width = r.right - r.left;
|
|
|
|
drawCell(t, dc, &p);
|
|
|
|
p.x += p.width;
|
|
|
|
}
|
|
|
|
p.y += p.height;
|
|
|
|
}
|
|
|
|
|
2014-12-08 15:23:55 -06:00
|
|
|
deselectFont(dc, prevfont, newfont);
|
2014-12-08 09:01:41 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
HANDLER(drawHandlers)
|
|
|
|
{
|
|
|
|
HDC dc;
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
RECT client;
|
|
|
|
RECT r;
|
|
|
|
|
|
|
|
if (uMsg != WM_PAINT && uMsg != WM_PRINTCLIENT)
|
|
|
|
return FALSE;
|
|
|
|
if (GetClientRect(t->hwnd, &client) == 0)
|
|
|
|
panic("error getting client rect for Table painting");
|
2014-12-08 14:54:55 -06:00
|
|
|
if (uMsg == WM_PAINT) {
|
2014-12-08 09:01:41 -06:00
|
|
|
dc = BeginPaint(t->hwnd, &ps);
|
|
|
|
if (dc == NULL)
|
|
|
|
panic("error beginning Table painting");
|
|
|
|
r = ps.rcPaint;
|
|
|
|
} else {
|
|
|
|
dc = (HDC) wParam;
|
|
|
|
r = client;
|
|
|
|
}
|
|
|
|
draw(t, dc, r, client);
|
2014-12-08 14:54:55 -06:00
|
|
|
if (uMsg == WM_PAINT)
|
2014-12-08 09:01:41 -06:00
|
|
|
EndPaint(t->hwnd, &ps);
|
2014-12-08 14:54:55 -06:00
|
|
|
// this is correct for WM_PRINTCLIENT; see http://stackoverflow.com/a/27362258/3408572
|
2014-12-08 09:01:41 -06:00
|
|
|
*lResult = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|