andlabs-ui/wintable/api.h

70 lines
2.0 KiB
C
Raw Normal View History

// 8 december 2014
2014-12-09 19:32:49 -06:00
static void addColumn(struct table *t, WPARAM wParam, LPARAM lParam)
{
t->nColumns++;
2014-12-10 19:43:28 -06:00
t->columnTypes = (int *) tableRealloc(t->columnTypes, t->nColumns * sizeof (int), "adding the new column type to the current Table's list of column types");
2014-12-09 19:32:49 -06:00
t->columnTypes[t->nColumns - 1] = (int) wParam;
// TODO make a panicNoErrCode() or panicArg() for this
if (t->columnTypes[t->nColumns - 1] >= nTableColumnTypes)
panic("invalid column type passed to tableAddColumn");
headerAddColumn(t, (WCHAR *) lParam);
update(t, TRUE);
2014-12-09 19:32:49 -06:00
}
HANDLER(apiHandlers)
{
2015-01-07 21:54:29 -06:00
intptr_t *rcp;
BOOL tfbool;
2015-01-07 21:54:29 -06:00
switch (uMsg) {
case WM_SETFONT:
2014-12-08 14:11:42 -06:00
// don't free the old font; see http://blogs.msdn.com/b/oldnewthing/archive/2008/09/12/8945692.aspx
t->font = (HFONT) wParam;
SendMessageW(t->header, WM_SETFONT, wParam, lParam);
// let's ensure the values are strictly TRUE and FALSE just to be safe
tfbool = FALSE;
if (LOWORD(lParam) != FALSE)
tfbool = TRUE;
update(t, tfbool);
// TODO is this needed?
if (tfbool != FALSE)
// TODO check error
InvalidateRect(t->hwnd, NULL, TRUE);
*lResult = 0;
return TRUE;
case WM_GETFONT:
*lResult = (LRESULT) (t->font);
return TRUE;
case tableAddColumn:
2014-12-09 19:32:49 -06:00
addColumn(t, wParam, lParam);
*lResult = 0;
return TRUE;
2015-01-07 21:54:29 -06:00
case tableSetRowCount:
rcp = (intptr_t *) lParam;
t->count = *rcp;
// TODO shouldn't we just redraw everything?
update(t, TRUE);
2015-01-07 21:54:29 -06:00
*lResult = 0;
return TRUE;
}
return FALSE;
}
2015-01-07 16:05:38 -06:00
static LRESULT notify(struct table *t, UINT code, intptr_t row, intptr_t column, uintptr_t data)
{
tableNM nm;
ZeroMemory(&nm, sizeof (tableNM));
nm.nmhdr.hwndFrom = t->hwnd;
// TODO check for error from here? 0 is a valid ID (IDCANCEL)
nm.nmhdr.idFrom = GetDlgCtrlID(t->hwnd);
nm.nmhdr.code = code;
nm.row = row;
nm.column = column;
nm.columnType = t->columnTypes[nm.column];
nm.data = data;
// TODO check for error from GetParent()?
return SendMessageW(GetParent(t->hwnd), WM_NOTIFY, (WPARAM) (nm.nmhdr.idFrom), (LPARAM) (&nm));
}