summaryrefslogtreecommitdiff
path: root/wintable/update.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/update.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/update.h')
-rw-r--r--wintable/update.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/wintable/update.h b/wintable/update.h
new file mode 100644
index 0000000..c4beea7
--- /dev/null
+++ b/wintable/update.h
@@ -0,0 +1,44 @@
+// 8 january 2015
+
+// Whenever a number of things in the Table changes, the update() function needs to be called to update any metrics and scrolling positions.
+// The control font changing is the big one, as that comes with a flag that decides whether or not to redraw everything. We'll need to respect that here.
+
+// TODO actually use redraw here
+static void update(struct table *t, int redraw)
+{
+ RECT client;
+ intptr_t i;
+ intptr_t height;
+
+ // before we do anything we need the client rect
+ if (GetClientRect(t->hwnd, &client) == 0)
+ panic("error getting Table client rect in update()");
+
+ // the first step is to figure out how wide the whole table is
+ // TODO count dividers?
+ t->width = 0;
+ for (i = 0; i < t->nColumns; i++)
+ t->width += columnWidth(t, i);
+
+ // now we need to figure out how much of the width of the table can be seen at once
+ 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
+ // we do this regardless of which of the two has changed, just to be safe
+ if (t->hpagesize > t->width)
+ t->hpagesize = t->width;
+
+ // now we do a dummy horizontal scroll to apply the new width and horizontal page size
+ // this will also reposition and resize the header (the latter in case the font changed), which will be important for the next step
+ hscrollby(t, 0);
+
+ // now that we have the new height of the header, we can fix up vertical scrolling
+ // so let's take the header height away from the client area
+ client.top += t->headerHeight;
+ // and update our page size appropriately
+ height = client.bottom - client.top;
+ t->vpagesize = height / rowht(t);
+ // and do a dummy vertical scroll to apply that
+ vscrollby(t, 0);
+
+ // TODO invalidate /everything/?
+}