Implemented tableNotificationGetCellData et al for text columns.

This commit is contained in:
Pietro Gagliardi 2015-01-07 19:00:56 -05:00
parent f263d9ced8
commit b3c0a7acaf
3 changed files with 44 additions and 6 deletions

View File

@ -13,8 +13,7 @@ struct drawCellParams {
static void drawCell(struct table *t, HDC dc, struct drawCellParams *p)
{
RECT r;
WCHAR msg[200];
int n;
WCHAR *text;
HBRUSH background;
int textColor;
POINT pt;
@ -54,9 +53,10 @@ static void drawCell(struct table *t, HDC dc, struct drawCellParams *p)
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)
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)
panic("error drawing Table cell text");
notify(t, tableNotificationFinishedWithCellData, p->row, p->column, (uintptr_t) text);
break;
case tableColumnImage:
toCellContentRect(t, &r, p->xoff, tableImageWidth(), tableImageHeight());

View File

@ -42,10 +42,10 @@ enum {
// data parameter is pointer, same as tableNotificationGetCellData
// not sent for checkboxes
// no return
tableNotificationFinishedWithData,
tableNotificationFinishedWithCellData,
// data is zero
// no return
tableNotificationToggleCellCheck,
tableNotificationToggleCellCheckbox,
};
typedef struct tableNM tableNM;

View File

@ -54,10 +54,48 @@ void mainwinResize(HWND hwnd, UINT state, int cx, int cy)
LRESULT CALLBACK mainwndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
NMHDR *nmhdr = (NMHDR *) lParam;
tableNM *nm = (tableNM *) lParam;
WCHAR *text;
int n;
switch (uMsg) {
HANDLE_MSG(hwnd, WM_CREATE, mainwinCreate);
HANDLE_MSG(hwnd, WM_SIZE, mainwinResize);
HANDLE_MSG(hwnd, WM_DESTROY, mainwinDestroy);
case WM_NOTIFY:
if (nmhdr->hwndFrom != tablehwnd)
break;
switch (nmhdr->code) {
case tableNotificationGetCellData:
switch (nm->columnType) {
case tableColumnText:
n = _scwprintf(L"mainwin (%d,%d)", nm->row, nm->column);
text = (WCHAR *) malloc((n + 1) * sizeof (WCHAR));
if (text == NULL)
panic("(table program) error allocating string");
_swprintf(text, L"mainwin (%d,%d)", nm->row, nm->column);
return (LRESULT) text;
case tableColumnImage:
return (LRESULT) testbitmap;
case tableColumnCheckbox:
; // TODO
}
panic("(test program) unreachable");
case tableNotificationFinishedWithCellData:
switch (nm->columnType) {
case tableColumnText:
free((void *) (nm->data));
break;
case tableColumnImage:
// do nothing
break;
}
return 0;
case tableNotificationToggleCellCheckbox:
; // TODO
}
break;
}
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
}