Added wheel scrolling.
This commit is contained in:
parent
d5b4d06cb4
commit
5080e84398
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue