summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wintable/new/hscroll.h1
-rw-r--r--wintable/new/main.c2
-rw-r--r--wintable/new/scroll.h24
-rw-r--r--wintable/new/vscroll.h24
4 files changed, 46 insertions, 5 deletions
diff --git a/wintable/new/hscroll.h b/wintable/new/hscroll.h
index a2534b5..1560490 100644
--- a/wintable/new/hscroll.h
+++ b/wintable/new/hscroll.h
@@ -13,6 +13,7 @@ static struct scrollParams hscrollParams(struct table *t)
p.length = t->width;
p.scale = 1;
p.post = repositionHeader;
+ p.wheelCarry = &(t->hwheelCarry);
return p;
}
diff --git a/wintable/new/main.c b/wintable/new/main.c
index 0482d04..00bc5fb 100644
--- a/wintable/new/main.c
+++ b/wintable/new/main.c
@@ -62,6 +62,8 @@ struct table {
intptr_t count;
intptr_t vscrollpos; // in rows
intptr_t vpagesize; // in rows
+ int hwheelCarry;
+ int vwheelCarry;
};
#include "util.h"
diff --git a/wintable/new/scroll.h b/wintable/new/scroll.h
index 81b49c5..1f333a8 100644
--- a/wintable/new/scroll.h
+++ b/wintable/new/scroll.h
@@ -6,6 +6,7 @@ struct scrollParams {
intptr_t length;
intptr_t scale;
void (*post)(struct table *);
+ int *wheelCarry;
};
static void scrollto(struct table *t, int which, struct scrollParams *p, intptr_t pos)
@@ -104,3 +105,26 @@ static void scroll(struct table *t, int which, struct scrollParams *p, WPARAM wP
}
scrollto(t, which, p, pos);
}
+
+static void wheelscroll(struct table *t, int which, struct scrollParams *p, WPARAM wParam, LPARAM lParam)
+{
+ int delta;
+ int lines;
+ UINT scrollAmount;
+
+ delta = GET_WHEEL_DELTA_WPARAM(wParam);
+ // TODO make a note of what the appropriate hscroll constant is
+ if (SystemParametersInfoW(SPI_GETWHEELSCROLLLINES, 0, &scrollAmount, 0) == 0)
+ // TODO use scrollAmount == 3 instead?
+ panic("error getting wheel scroll amount in wheelscroll()");
+ if (scrollAmount == WHEEL_PAGESCROLL)
+ scrollAmount = p->pagesize;
+ if (scrollAmount == 0) // no mouse wheel scrolling (or t->pagesize == 0)
+ return;
+ // the rest of this is basically http://blogs.msdn.com/b/oldnewthing/archive/2003/08/07/54615.aspx and http://blogs.msdn.com/b/oldnewthing/archive/2003/08/11/54624.aspx
+ // see those pages for information on subtleties
+ delta += *(p->wheelCarry);
+ lines = delta * ((int) scrollAmount) / WHEEL_DELTA;
+ *(p->wheelCarry) = delta - lines * WHEEL_DELTA / ((int) scrollAmount);
+ scrollby(t, which, p, -lines);
+}
diff --git a/wintable/new/vscroll.h b/wintable/new/vscroll.h
index bcab488..a1dc4c4 100644
--- a/wintable/new/vscroll.h
+++ b/wintable/new/vscroll.h
@@ -13,6 +13,7 @@ static struct scrollParams vscrollParams(struct table *t)
p.length = t->count;
p.scale = rowht(t);
p.post = NULL;
+ p.wheelCarry = &(t->vwheelCarry);
return p;
}
@@ -40,12 +41,25 @@ static void vscroll(struct table *t, WPARAM wParam, LPARAM lParam)
scroll(t, SB_VERT, &p, wParam, lParam);
}
+static void vwheelscroll(struct table *t, WPARAM wParam, LPARAM lParam)
+{
+ struct scrollParams p;
+
+ p = vscrollParams(t);
+ wheelscroll(t, SB_VERT, &p, wParam, lParam);
+}
+
// TODO WM_MOUSEWHEEL
HANDLER(vscrollHandler)
{
- if (uMsg != WM_VSCROLL)
- return FALSE;
- vscroll(t, wParam, lParam);
- *lResult = 0;
- return TRUE;
+ switch (uMsg) {
+ case WM_VSCROLL:
+ vscroll(t, wParam, lParam);
+ *lResult = 0;
+ return TRUE;
+ case WM_MOUSEWHEEL:
+ vwheelscroll(t, wParam, lParam);
+ // TODO what to return?
+ }
+ return FALSE;
}