Reimplemented tableAddColumn for real.
This commit is contained in:
parent
d6ff23dacb
commit
dd37255fa1
|
@ -1,5 +1,16 @@
|
|||
// 8 december 2014
|
||||
|
||||
static void addColumn(struct table *t, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
t->nColumns++;
|
||||
t->columnTypes = tableRealloc(t->columnTypes, t->nColumns * sizeof (int), "adding the new column type to the current Table's list of column types");
|
||||
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);
|
||||
}
|
||||
|
||||
HANDLER(apiHandlers)
|
||||
{
|
||||
switch (uMsg) {
|
||||
|
@ -15,8 +26,9 @@ HANDLER(apiHandlers)
|
|||
*lResult = (LRESULT) (t->font);
|
||||
return TRUE;
|
||||
case tableAddColumn:
|
||||
// TODO
|
||||
return FALSE;
|
||||
addColumn(t, wParam, lParam);
|
||||
*lResult = 0;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
@ -29,14 +29,13 @@ static void drawCell(struct table *t, HDC dc, struct drawCellParams *p)
|
|||
|
||||
static void draw(struct table *t, HDC dc, RECT cliprect, RECT client)
|
||||
{
|
||||
LRESULT i, n;
|
||||
intptr_t i;
|
||||
RECT r;
|
||||
int x = 0;
|
||||
HFONT prevfont, newfont;
|
||||
struct drawCellParams p;
|
||||
|
||||
n = SendMessageW(t->header, HDM_GETITEMCOUNT, 0, 0);
|
||||
for (i = 0; i < n; i++) {
|
||||
for (i = 0; i < t->nColumns; i++) {
|
||||
SendMessage(t->header, HDM_GETITEMRECT, (WPARAM) i, (LPARAM) (&r));
|
||||
r.top = client.top;
|
||||
r.bottom = client.bottom;
|
||||
|
|
|
@ -50,6 +50,8 @@ struct table {
|
|||
HWND hwnd;
|
||||
HWND header;
|
||||
HFONT font;
|
||||
intptr_t nColumns;
|
||||
int *columnTypes;
|
||||
};
|
||||
|
||||
#include "util.h"
|
||||
|
@ -72,9 +74,7 @@ static const handlerfunc handlers[] = {
|
|||
|
||||
static void initDummyTableStuff(struct table *t)
|
||||
{
|
||||
headerAddColumn(t, L"Column 1");
|
||||
headerAddColumn(t, L"Column 2");
|
||||
headerAddColumn(t, L"Column 3");
|
||||
// nothing yet...
|
||||
}
|
||||
|
||||
static LRESULT CALLBACK tableWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
|
|
|
@ -15,6 +15,7 @@ static BOOL runHandlers(const handlerfunc list[], struct table *t, UINT uMsg, WP
|
|||
|
||||
// memory allocation stuff
|
||||
// each of these functions do an implicit ZeroMemory()
|
||||
// these also make tableRealloc(NULL, ...) act like realloc(NULL, ...) (that is, same as tableAlloc(...)/malloc(...))
|
||||
// we're using LocalAlloc() because:
|
||||
// - whether the malloc() family supports the last-error code is undefined
|
||||
// - the HeapAlloc() family DOES NOT support the last-error code; you're supposed to use Windows exceptions, and I can't find a clean way to do this with MinGW-w64 that doesn't rely on inline assembly or external libraries (unless they added __try/__except blocks)
|
||||
|
@ -35,6 +36,8 @@ static void *tableRealloc(void *p, size_t size, const char *panicMessage)
|
|||
{
|
||||
HLOCAL out;
|
||||
|
||||
if (p == NULL)
|
||||
return tableAlloc(size, panicMessage);
|
||||
out = LocalReAlloc((HLOCAL) p, size, LMEM_ZEROINIT);
|
||||
if (out == NULL)
|
||||
panic(panicMessage);
|
||||
|
|
Loading…
Reference in New Issue