From 93046dc868b57c1de084500fcff1b5996f283977 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 15 Nov 2014 20:36:56 -0500 Subject: [PATCH] Split the code to compute the last visible item in the new Windows Table into its own function. This is needed for keyboard vertical scrolling. --- wintable/main.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/wintable/main.c b/wintable/main.c index edea173..503a755 100644 --- a/wintable/main.c +++ b/wintable/main.c @@ -148,6 +148,17 @@ static void repositionHeader(struct table *t) t->headerHeight = headerpos.cy; } +// cliprect and rowHeight must be specified here to avoid recomputing things multiple times +static intptr_t lastVisible(struct table *t, RECT cliprect, LONG rowHeight) +{ + intptr_t last; + + last = ((cliprect.bottom + rowHeight - 1) / rowHeight) + t->firstVisible; + if (last >= t->count) + last = t->count; + return last; +} + static intptr_t hitTestColumn(struct table *t, int x) { HDITEMW item; @@ -623,9 +634,7 @@ static void drawItems(struct table *t, HDC dc, RECT cliprect) first = (cliprect.top / height) + t->firstVisible; if (first < 0) first = 0; - last = ((cliprect.bottom + height - 1) / height) + t->firstVisible; - if (last >= t->count) - last = t->count; + last = lastVisible(t, cliprect, height); // now for the first y, discount firstVisible y = (first - t->firstVisible) * height;