diff options
| -rw-r--r-- | wintable/draw.h | 8 | ||||
| -rw-r--r-- | wintable/main.h | 4 | ||||
| -rw-r--r-- | wintable/test.c | 38 |
3 files changed, 44 insertions, 6 deletions
diff --git a/wintable/draw.h b/wintable/draw.h index a325d93..19b136a 100644 --- a/wintable/draw.h +++ b/wintable/draw.h @@ -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()); diff --git a/wintable/main.h b/wintable/main.h index 1e8efaa..50e8bff 100644 --- a/wintable/main.h +++ b/wintable/main.h @@ -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; diff --git a/wintable/test.c b/wintable/test.c index 59973e2..1ffad26 100644 --- a/wintable/test.c +++ b/wintable/test.c @@ -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); } |
