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
|
|
|
|
};
|
|
|
|
|
|
|
|
static void drawCell(struct table *t, HDC dc, struct drawCellParams *p)
|
|
|
|
{
|
|
|
|
RECT r;
|
2015-01-07 18:00:56 -06:00
|
|
|
WCHAR *text;
|
2014-12-13 10:49:36 -06:00
|
|
|
HBRUSH background;
|
|
|
|
int textColor;
|
2014-12-21 17:45:37 -06:00
|
|
|
POINT pt;
|
2014-12-22 20:28:17 -06:00
|
|
|
int cbState;
|
2014-12-23 13:43:33 -06:00
|
|
|
RECT cellrect;
|
2015-01-07 13:41:35 -06:00
|
|
|
HDC idc;
|
|
|
|
HBITMAP previbitmap;
|
|
|
|
BLENDFUNCTION bf;
|
2014-12-08 20:42:00 -06:00
|
|
|
|
2014-12-13 10:49:36 -06:00
|
|
|
// TODO verify these two
|
|
|
|
background = (HBRUSH) (COLOR_WINDOW + 1);
|
|
|
|
textColor = COLOR_WINDOWTEXT;
|
2014-12-23 13:43:33 -06:00
|
|
|
if (t->selectedRow == p->row) {
|
2014-12-13 10:49:36 -06:00
|
|
|
// 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;
|
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-13 10:49:36 -06:00
|
|
|
if (FillRect(dc, &r, background) == 0)
|
|
|
|
panic("error filling Table cell background");
|
2014-12-23 13:43:33 -06:00
|
|
|
cellrect = r; // save for drawing the focus rect
|
2014-12-12 09:47:23 -06:00
|
|
|
|
2014-12-19 19:48:02 -06:00
|
|
|
switch (t->columnTypes[p->column]) {
|
|
|
|
case tableColumnText:
|
2014-12-20 20:10:44 -06:00
|
|
|
toCellContentRect(t, &r, p->xoff, 0, 0); // TODO get the text height
|
2014-12-19 19:48:02 -06:00
|
|
|
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");
|
2015-01-07 18:00:56 -06:00
|
|
|
text = (WCHAR *) notify(t, tableNotificationGetCellData, p->row, p->column, 0);
|
|
|
|
if (DrawTextExW(dc, text, -1, &r, DT_END_ELLIPSIS | DT_LEFT | DT_NOPREFIX | DT_SINGLELINE, NULL) == 0)
|
2014-12-19 19:48:02 -06:00
|
|
|
panic("error drawing Table cell text");
|
2015-01-07 18:00:56 -06:00
|
|
|
notify(t, tableNotificationFinishedWithCellData, p->row, p->column, (uintptr_t) text);
|
2014-12-20 19:12:08 -06:00
|
|
|
break;
|
2015-01-07 13:41:35 -06:00
|
|
|
case tableColumnImage:
|
|
|
|
toCellContentRect(t, &r, p->xoff, tableImageWidth(), tableImageHeight());
|
|
|
|
idc = CreateCompatibleDC(dc);
|
|
|
|
if (idc == NULL)
|
|
|
|
panic("error creating compatible DC for Table image cell drawing");
|
|
|
|
previbitmap = SelectObject(idc, testbitmap);
|
|
|
|
if (previbitmap == NULL)
|
|
|
|
panic("error selecting Table cell image into compatible DC for image drawing");
|
|
|
|
ZeroMemory(&bf, sizeof (BLENDFUNCTION));
|
|
|
|
bf.BlendOp = AC_SRC_OVER;
|
|
|
|
bf.BlendFlags = 0;
|
|
|
|
bf.SourceConstantAlpha = 255; // per-pixel alpha values
|
|
|
|
bf.AlphaFormat = AC_SRC_ALPHA;
|
|
|
|
// TODO 16 and 16 are the width and height of the image; we would need to get that out somehow
|
|
|
|
if (AlphaBlend(dc, r.left, r.top, r.right - r.left, r.bottom - r.top,
|
|
|
|
idc, 0, 0, 16, 16, bf) == FALSE)
|
|
|
|
panic("error drawing image into Table cell");
|
|
|
|
if (SelectObject(idc, previbitmap) != testbitmap)
|
|
|
|
panic("error deselecting Table cell image for drawing image");
|
|
|
|
if (DeleteDC(idc) == 0)
|
|
|
|
panic("error deleting Table compatible DC for image cell drawing");
|
|
|
|
break;
|
2014-12-20 19:12:08 -06:00
|
|
|
case tableColumnCheckbox:
|
2014-12-21 01:09:09 -06:00
|
|
|
toCheckboxRect(t, &r, p->xoff);
|
2014-12-22 20:28:17 -06:00
|
|
|
cbState = 0;
|
2014-12-22 19:15:10 -06:00
|
|
|
if (p->row == lastCheckbox.row && p->column == lastCheckbox.column)
|
2014-12-22 20:28:17 -06:00
|
|
|
cbState |= checkboxStateChecked;
|
|
|
|
if (t->checkboxMouseDown)
|
2014-12-22 19:15:10 -06:00
|
|
|
if (p->row == t->checkboxMouseDownRow && p->column == t->checkboxMouseDownColumn)
|
2014-12-22 20:28:17 -06:00
|
|
|
cbState |= checkboxStatePushed;
|
|
|
|
if (t->checkboxMouseOverLast) {
|
2014-12-21 17:45:37 -06:00
|
|
|
pt.x = GET_X_LPARAM(t->checkboxMouseOverLastPoint);
|
|
|
|
pt.y = GET_Y_LPARAM(t->checkboxMouseOverLastPoint);
|
|
|
|
if (PtInRect(&r, pt) != 0)
|
2014-12-22 20:28:17 -06:00
|
|
|
cbState |= checkboxStateHot;
|
2014-12-21 17:45:37 -06:00
|
|
|
}
|
2014-12-22 20:28:17 -06:00
|
|
|
drawCheckbox(t, dc, &r, cbState);
|
2014-12-20 19:12:08 -06:00
|
|
|
break;
|
2014-12-19 19:48:02 -06:00
|
|
|
}
|
2014-12-23 13:43:33 -06:00
|
|
|
|
|
|
|
// TODO in front of or behind the cell contents?
|
|
|
|
if (t->selectedRow == p->row && t->selectedColumn == p->column)
|
|
|
|
if (DrawFocusRect(dc, &cellrect) == 0)
|
|
|
|
panic("error drawing focus rect on current Table cell");
|
2014-12-08 20:42:00 -06:00
|
|
|
}
|
|
|
|
|
2014-12-23 13:43:33 -06:00
|
|
|
// TODO use cliprect
|
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
|
|
|
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
|
|
|
|
|
|
|
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;
|
2014-12-12 15:37:48 -06:00
|
|
|
for (i = t->vscrollpos; i < t->count; i++) {
|
2014-12-12 09:47:23 -06:00
|
|
|
p.row = i;
|
|
|
|
p.x = client.left - t->hscrollpos;
|
|
|
|
for (j = 0; j < t->nColumns; j++) {
|
|
|
|
p.column = j;
|
2014-12-14 15:23:32 -06:00
|
|
|
p.width = columnWidth(t, p.column);
|
2014-12-12 09:47:23 -06:00
|
|
|
drawCell(t, dc, &p);
|
|
|
|
p.x += p.width;
|
|
|
|
}
|
|
|
|
p.y += p.height;
|
2014-12-23 13:21:27 -06:00
|
|
|
if (p.y >= client.bottom) // >= because RECT.bottom is the first pixel outside the rect
|
|
|
|
break;
|
2014-12-12 09:47:23 -06:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2015-01-06 02:27:29 -06:00
|
|
|
|
|
|
|
// TODO redraw selected row on focus change
|
|
|
|
// TODO here or in select.h?
|