2014-12-08 14:04:43 -06:00
|
|
|
// 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);
|
2015-01-08 00:45:06 -06:00
|
|
|
update(t, TRUE);
|
2015-01-08 01:05:06 -06:00
|
|
|
// TODO only redraw the part of the client area where the new client went, if any
|
|
|
|
// (TODO when — if — adding autoresize, figure this one out)
|
2015-02-17 11:52:50 -06:00
|
|
|
|
|
|
|
// TODO send a notification for all rows?
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setRowCount(struct table *t, intptr_t rc)
|
|
|
|
{
|
|
|
|
intptr_t old, i;
|
|
|
|
|
|
|
|
old = t->count;
|
|
|
|
t->count = rc;
|
|
|
|
// we DO redraw everything because we don't want any rows that should no longer be there to remain on screen!
|
|
|
|
updateAll(t); // DONE
|
|
|
|
// TODO reset checkbox and selection logic if the current row for both no longer exists
|
|
|
|
// TODO really send all these notifications?
|
|
|
|
if (old < t->count) // rows added
|
|
|
|
for (i = old; i < t->count; i++)
|
|
|
|
NotifyWinEvent(EVENT_OBJECT_CREATE, t->hwnd, OBJID_CLIENT, i);
|
|
|
|
else if (old > t->count) // rows removed
|
|
|
|
for (i = old; i > t->count; i++)
|
|
|
|
NotifyWinEvent(EVENT_OBJECT_DESTROY, t->hwnd, OBJID_CLIENT, i);
|
|
|
|
// TODO update existing rows?
|
2014-12-09 19:32:49 -06:00
|
|
|
}
|
|
|
|
|
2014-12-08 14:04:43 -06:00
|
|
|
HANDLER(apiHandlers)
|
|
|
|
{
|
2015-01-07 21:54:29 -06:00
|
|
|
intptr_t *rcp;
|
|
|
|
|
2014-12-08 14:04:43 -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
|
2014-12-08 14:04:43 -06:00
|
|
|
t->font = (HFONT) wParam;
|
|
|
|
SendMessageW(t->header, WM_SETFONT, wParam, lParam);
|
2015-01-08 00:55:45 -06:00
|
|
|
// if we redraw, we have to redraw ALL of it; after all, the font changed!
|
2015-01-08 00:45:06 -06:00
|
|
|
if (LOWORD(lParam) != FALSE)
|
2015-01-08 00:55:45 -06:00
|
|
|
updateAll(t); // DONE
|
|
|
|
else
|
|
|
|
update(t, FALSE); // DONE
|
2014-12-08 14:04:43 -06:00
|
|
|
*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;
|
2015-02-17 11:52:50 -06:00
|
|
|
setRowCount(t, *rcp);
|
2015-01-07 21:54:29 -06:00
|
|
|
*lResult = 0;
|
|
|
|
return TRUE;
|
2015-02-19 21:58:17 -06:00
|
|
|
case tableGetSelection:
|
|
|
|
rcp = (intptr_t *) wParam;
|
|
|
|
if (rcp != NULL)
|
|
|
|
*rcp = t->selectedRow;
|
|
|
|
rcp = (intptr_t *) lParam;
|
|
|
|
if (rcp != NULL)
|
|
|
|
*rcp = t->selectedColumn;
|
|
|
|
*lResult = 0;
|
|
|
|
return TRUE;
|
2014-12-08 14:04:43 -06:00
|
|
|
}
|
|
|
|
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));
|
|
|
|
}
|