summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-11-07 10:12:06 -0500
committerPietro Gagliardi <[email protected]>2014-11-07 10:12:06 -0500
commit3cb5017b35154237ea862d3856ef945eb7790005 (patch)
treee7f4e780335602d53ff22139241d1153d3538e75
parentbc5955bc356fae0285c6f95ccfc8f32ec3174487 (diff)
Implemented horizontal scrolling. Horizontally scrolled drawing not yet implemented.
-rw-r--r--wintable/main.c85
1 files changed, 82 insertions, 3 deletions
diff --git a/wintable/main.c b/wintable/main.c
index 0b5e210..74d1a0b 100644
--- a/wintable/main.c
+++ b/wintable/main.c
@@ -46,7 +46,7 @@ struct table {
HIMAGELIST imagelist;
int imagelistHeight;
intptr_t width;
- intptr_t hpageSize;
+ intptr_t hpagesize;
intptr_t hpos;
};
@@ -94,6 +94,82 @@ static RECT realClientRect(struct table *t)
return r;
}
+static void hscrollto(struct table *t, intptr_t newpos)
+{
+ SCROLLINFO si;
+
+ if (newpos < 0)
+ newpos = 0;
+ if (newpos > (t->width - t->hpagesize))
+ newpos = (t->width - t->hpagesize);
+
+ // negative because ScrollWindowEx() is "backwards"
+ if (ScrollWindowEx(t->hwnd, -(newpos - t->hpos), 0,
+ NULL, NULL, NULL, NULL,
+ SW_ERASE | SW_INVALIDATE) == ERROR)
+ abort();
+ t->hpos = newpos;
+ // TODO text in header controls doesn't redraw?
+
+ // TODO put this in a separate function? same for vscroll?
+ ZeroMemory(&si, sizeof (SCROLLINFO));
+ si.cbSize = sizeof (SCROLLINFO);
+ si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
+ si.nPage = t->hpagesize;
+ si.nMin = 0;
+ si.nMax = t->width - 1; // nMax is inclusive
+ si.nPos = t->hpos;
+ SetScrollInfo(t->hwnd, SB_HORZ, &si, TRUE);
+}
+
+static void hscrollby(struct table *t, intptr_t n)
+{
+ hscrollto(t, t->hpos + n);
+}
+
+// unfortunately horizontal wheel scrolling was only added in Vista
+
+static void hscroll(struct table *t, WPARAM wParam)
+{
+ SCROLLINFO si;
+ intptr_t newpos;
+
+ ZeroMemory(&si, sizeof (SCROLLINFO));
+ si.cbSize = sizeof (SCROLLINFO);
+ si.fMask = SIF_POS | SIF_TRACKPOS;
+ if (GetScrollInfo(t->hwnd, SB_HORZ, &si) == 0)
+ abort();
+
+ newpos = t->hpos;
+ switch (LOWORD(wParam)) {
+ case SB_LEFT:
+ newpos = 0;
+ break;
+ case SB_RIGHT:
+ newpos = t->width - t->hpagesize;
+ break;
+ case SB_LINELEFT:
+ newpos--;
+ break;
+ case SB_LINERIGHT:
+ newpos++;
+ break;
+ case SB_PAGELEFT:
+ newpos -= t->hpagesize;
+ break;
+ case SB_PAGERIGHT:
+ newpos += t->hpagesize;
+ break;
+ case SB_THUMBPOSITION:
+ newpos = (intptr_t) (si.nPos);
+ break;
+ case SB_THUMBTRACK:
+ newpos = (intptr_t) (si.nTrackPos);
+ }
+
+ hscrollto(t, newpos);
+}
+
static void recomputeHScroll(struct table *t)
{
HDITEMW item;
@@ -114,12 +190,12 @@ static void recomputeHScroll(struct table *t)
if (GetClientRect(t->hwnd, &r) == 0)
abort();
- t->hpageSize = r.right - r.left;
+ t->hpagesize = r.right - r.left;
ZeroMemory(&si, sizeof (SCROLLINFO));
si.cbSize = sizeof (SCROLLINFO);
si.fMask = SIF_PAGE | SIF_RANGE;
- si.nPage = t->hpageSize;
+ si.nPage = t->hpagesize;
si.nMin = 0;
si.nMax = t->width - 1; // - 1 because endpoints inclusive
SetScrollInfo(t->hwnd, SB_HORZ, &si, TRUE);
@@ -533,6 +609,9 @@ if (ImageList_GetIconSize(t->imagelist, &unused, &(t->imagelistHeight)) == 0)abo
case WM_MOUSEWHEEL:
wheelscroll(t, wParam);
return 0;
+ case WM_HSCROLL:
+ hscroll(t, wParam);
+ return 0;
case WM_SIZE:
resize(t);
return 0;