summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-10-19 23:33:08 -0400
committerPietro Gagliardi <[email protected]>2014-10-19 23:33:08 -0400
commit79d096edebb584b7d59527230b861c72e3fe7305 (patch)
tree8a5f395a5b457de642283e3c77c9948ee3927215
parenta3ad384a340956cc7a4b7deb692c605858ce28e6 (diff)
Worked on vertical scrolilng. Not done.
-rw-r--r--wintable/main.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/wintable/main.c b/wintable/main.c
index 5012efa..0e9a4d8 100644
--- a/wintable/main.c
+++ b/wintable/main.c
@@ -30,8 +30,68 @@ struct table {
intptr_t selected;
intptr_t count;
intptr_t firstVisible;
+ intptr_t pagesize;
};
+static void vscroll(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_VERT, &si) == 0)
+ abort();
+
+ newpos = t->firstVisible;
+ switch (LOWORD(wParam)) {
+ case SB_TOP:
+ newpos = 0;
+ break;
+ case SB_BOTTOM:
+ newpos = t->count - t->pagesize;
+ break;
+ case SB_LINEUP:
+ newpos--;
+ break;
+ case SB_LINEDOWN:
+ newpos++;
+ break;
+ case SB_PAGEUP:
+ newpos -= t->pagesize;
+ break;
+ case SB_PAGEDOWN:
+ newpos += t->pagesize;
+ break;
+ case SB_THUMBPOSITION:
+ newpos = (intptr_t) (si.nPos);
+ break;
+ case SB_THUMBTRACK:
+ newpos = (intptr_t) (si.nTrackPos);
+ }
+ if (newpos < 0)
+ newpos = 0;
+ if (newpos > (t->count - t->pagesize))
+ newpos = (t->count - t->pagesize);
+
+ // negative because ScrollWindowEx() is "backwards"
+ if (ScrollWindowEx(t->hwnd, 0, -(newpos - t->firstVisible),
+ NULL, NULL, NULL, NULL,
+ SW_ERASE | SW_INVALIDATE) == ERROR)
+ abort();
+ t->firstVisible = newpos;
+
+ ZeroMemory(&si, sizeof (SCROLLINFO));
+ si.cbSize = sizeof (SCROLLINFO);
+ si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
+ si.nPage = t->pagesize;
+ si.nMin = 0;
+ si.nMax = t->count - 1; // nMax is inclusive
+ si.nPos = t->firstVisible;
+ SetScrollInfo(t->hwnd, SB_VERT, &si, TRUE);
+}
+
static void drawItems(struct table *t, HDC dc, RECT cliprect)
{
HFONT thisfont, prevfont;
@@ -104,6 +164,8 @@ static LRESULT CALLBACK tableWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
struct table *t;
HDC dc;
PAINTSTRUCT ps;
+ RECT r;
+ SCROLLINFO si;
t = (struct table *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
if (t == NULL) {
@@ -137,6 +199,21 @@ t->selected = 5;t->count=100;//TODO
return 0;
case WM_GETFONT:
return (LRESULT) t->font;
+ case WM_VSCROLL:
+ vscroll(t, wParam);
+ return 0;
+ case WM_SIZE:
+ if (GetClientRect(hwnd, &r) == 0)
+ abort();
+ /*TODO
+ t->pagesize = (r.bottom - r.top) / tm.tmHeight;
+ ZeroMemory(&si, sizeof (SCROLLINFO));
+ si.cbSize = sizeof (SCROLLINFO);
+ si.fMask = SIF_PAGE;
+ si.nPage = t->pagesize;
+ SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
+ */
+ return 0;
default:
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
}