summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-12-09 20:32:49 -0500
committerPietro Gagliardi <[email protected]>2014-12-09 20:32:49 -0500
commitdd37255fa1362073efa9bf91287456cba9ad4cf5 (patch)
treec9ddbb1184e9a56addf40245e41ba2b497648b7e
parentd6ff23dacbb2f91d83c92030a0de5a135c8b8c47 (diff)
Reimplemented tableAddColumn for real.
-rw-r--r--wintable/new/api.h16
-rw-r--r--wintable/new/draw.h5
-rw-r--r--wintable/new/main.c6
-rw-r--r--wintable/new/util.h3
4 files changed, 22 insertions, 8 deletions
diff --git a/wintable/new/api.h b/wintable/new/api.h
index f066a19..6ebf800 100644
--- a/wintable/new/api.h
+++ b/wintable/new/api.h
@@ -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;
}
diff --git a/wintable/new/draw.h b/wintable/new/draw.h
index 9d86550..4f30036 100644
--- a/wintable/new/draw.h
+++ b/wintable/new/draw.h
@@ -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;
diff --git a/wintable/new/main.c b/wintable/new/main.c
index d296fc3..8e15f0f 100644
--- a/wintable/new/main.c
+++ b/wintable/new/main.c
@@ -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)
diff --git a/wintable/new/util.h b/wintable/new/util.h
index d2f18fb..7ed8e98 100644
--- a/wintable/new/util.h
+++ b/wintable/new/util.h
@@ -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);