summaryrefslogtreecommitdiff
path: root/wintable/header.h
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2015-01-08 01:45:06 -0500
committerPietro Gagliardi <[email protected]>2015-01-08 01:45:06 -0500
commit1dcdcd522cf1e63fd61f4ca376d4108a775a1565 (patch)
tree5133c81d0638edc99f5af6f9e57716d8c3ddcdba /wintable/header.h
parent224bdb40874ff65880f21bda2b85ceebb4a69312 (diff)
Collected all of the metric updating stuff into a single update() function. Far from optimal, but much better.
Diffstat (limited to 'wintable/header.h')
-rw-r--r--wintable/header.h41
1 files changed, 5 insertions, 36 deletions
diff --git a/wintable/header.h b/wintable/header.h
index 5652029..863d3d0 100644
--- a/wintable/header.h
+++ b/wintable/header.h
@@ -22,6 +22,9 @@ static void destroyHeader(struct table *t)
panic("error destroying Table header");
}
+// to avoid weird bugs, the only functions allowed to call this one are the horizontal scroll functions
+// when we need to reposition the header in a situation other than a user-initiated scroll, we use a dummy scroll (hscrollby(t, 0))
+// see update() in update.h
static void repositionHeader(struct table *t)
{
RECT r;
@@ -58,40 +61,6 @@ static void headerAddColumn(struct table *t, WCHAR *name)
panic("error adding column to Table header");
}
-// TODO make a better name for this?
-// TODO move to hscroll.h?
-// TODO organize this in general...
-// TODO because of this function's new extended functionality only hscrollto() is allowed to call repositionHeader()
-static void updateTableWidth(struct table *t)
-{
- HDITEMW item;
- intptr_t i;
- RECT client;
-
- t->width = 0;
- // TODO count dividers?
- // TODO use columnWidth()
- for (i = 0; i < t->nColumns; i++) {
- ZeroMemory(&item, sizeof (HDITEMW));
- item.mask = HDI_WIDTH;
- if (SendMessageW(t->header, HDM_GETITEM, (WPARAM) i, (LPARAM) (&item)) == FALSE)
- panic("error getting Table column width for updateTableWidth()");
- t->width += item.cxy;
- }
-
- if (GetClientRect(t->hwnd, &client) == 0)
- panic("error getting Table client rect in updateTableWidth()");
- t->hpagesize = client.right - client.left;
-
- // this part is critical: if we resize the columns to less than the client area width, then the following hscrollby() will make t->hscrollpos negative, which does very bad things
- // note to self: do this regardless of whether the table width or the client area width was changed
- if (t->hpagesize > t->width)
- t->hpagesize = t->width;
-
- // do a dummy scroll to update the horizontal scrollbar to use the new width
- hscrollby(t, 0);
-}
-
HANDLER(headerNotifyHandler)
{
NMHDR *nmhdr = (NMHDR *) lParam;
@@ -100,10 +69,10 @@ HANDLER(headerNotifyHandler)
return FALSE;
if (nmhdr->code != HDN_ITEMCHANGED)
return FALSE;
- updateTableWidth(t);
+ update(t, TRUE);
// TODO make more intelligent
+ // (TODO is it actually needed?)
InvalidateRect(t->hwnd, NULL, TRUE);
- // TODO UpdateWindow()?
*lResult = 0;
return TRUE;
}