summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-10-20 11:19:35 -0400
committerPietro Gagliardi <[email protected]>2014-10-20 11:19:35 -0400
commit42ca7ced998a6f0e575e49f17f86ded6358b63c0 (patch)
treee44168a55d02f274c756007cc72c01cfd8360d7f
parent3aa4fb31832e9e4bd45a59e40735dcf62175e815 (diff)
Numbered each of the sample items.
-rw-r--r--wintable/main.c33
1 files changed, 11 insertions, 22 deletions
diff --git a/wintable/main.c b/wintable/main.c
index 6b7ca33..a221459 100644
--- a/wintable/main.c
+++ b/wintable/main.c
@@ -38,14 +38,12 @@ struct table {
int wheelCarry;
};
-static void vscrollto(struct table *t, intptr_t newpos)
+static LONG rowHeight(struct table *t)
{
HFONT thisfont, prevfont;
TEXTMETRICW tm;
HDC dc;
- SCROLLINFO si;
- // TODO split into a function
dc = GetDC(t->hwnd);
if (dc == NULL)
abort();
@@ -59,6 +57,12 @@ static void vscrollto(struct table *t, intptr_t newpos)
abort();
if (ReleaseDC(t->hwnd, dc) == 0)
abort();
+ return tm.tmHeight;
+}
+
+static void vscrollto(struct table *t, intptr_t newpos)
+{
+ SCROLLINFO si;
if (newpos < 0)
newpos = 0;
@@ -66,7 +70,7 @@ static void vscrollto(struct table *t, intptr_t newpos)
newpos = (t->count - t->pagesize);
// negative because ScrollWindowEx() is "backwards"
- if (ScrollWindowEx(t->hwnd, 0, (-(newpos - t->firstVisible)) * tm.tmHeight,
+ if (ScrollWindowEx(t->hwnd, 0, (-(newpos - t->firstVisible)) * rowHeight(t),
NULL, NULL, NULL, NULL,
SW_ERASE | SW_INVALIDATE) == ERROR)
abort();
@@ -151,28 +155,12 @@ static void vscroll(struct table *t, WPARAM wParam)
static void resize(struct table *t)
{
- HFONT thisfont, prevfont;
- TEXTMETRICW tm;
- HDC dc;
RECT r;
SCROLLINFO si;
if (GetClientRect(t->hwnd, &r) == 0)
abort();
- dc = GetDC(t->hwnd);
- if (dc == NULL)
- abort();
- thisfont = t->font; // in case WM_SETFONT happens before we return
- prevfont = (HFONT) SelectObject(dc, thisfont);
- if (prevfont == NULL)
- abort();
- if (GetTextMetricsW(dc, &tm) == 0)
- abort();
- if (SelectObject(dc, prevfont) != (HGDIOBJ) (thisfont))
- abort();
- if (ReleaseDC(t->hwnd, dc) == 0)
- abort();
- t->pagesize = (r.bottom - r.top) / tm.tmHeight;
+ t->pagesize = (r.bottom - r.top) / rowHeight(t);
ZeroMemory(&si, sizeof (SCROLLINFO));
si.cbSize = sizeof (SCROLLINFO);
si.fMask = SIF_RANGE | SIF_PAGE;
@@ -223,6 +211,7 @@ static void drawItems(struct table *t, HDC dc, RECT cliprect)
for (i = first; i < last; i++) {
RECT rsel;
HBRUSH background;
+ WCHAR msg[100];
// TODO check errors
// TODO verify correct colors
@@ -238,7 +227,7 @@ static void drawItems(struct table *t, HDC dc, RECT cliprect)
SetTextColor(dc, GetSysColor(COLOR_WINDOWTEXT));
FillRect(dc, &rsel, background);
SetBkMode(dc, TRANSPARENT);
- TextOutW(dc, r.left, y, L"Item", 4);
+ TextOutW(dc, r.left, y, msg, wsprintf(msg, L"Item %d", i));
y += tm.tmHeight;
}