diff options
| author | Pietro Gagliardi <[email protected]> | 2014-10-19 22:20:53 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-10-19 22:20:53 -0400 |
| commit | a3ad384a340956cc7a4b7deb692c605858ce28e6 (patch) | |
| tree | 77140c6c6c1ea2a4ff02f1dd511ecc12ab9e72e2 | |
| parent | ec22c573baa917f5572c10553a235b4dc4cbeb7f (diff) | |
Set the DC viewport properly for the purposes of scrolling.
| -rw-r--r-- | wintable/main.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/wintable/main.c b/wintable/main.c index b469ad6..5012efa 100644 --- a/wintable/main.c +++ b/wintable/main.c @@ -29,6 +29,7 @@ struct table { HFONT font; intptr_t selected; intptr_t count; + intptr_t firstVisible; }; static void drawItems(struct table *t, HDC dc, RECT cliprect) @@ -39,6 +40,7 @@ static void drawItems(struct table *t, HDC dc, RECT cliprect) intptr_t i; RECT r; intptr_t first, last; + POINT prevOrigin; // TODO eliminate the need (only use cliprect) if (GetClientRect(t->hwnd, &r) == 0) @@ -51,6 +53,14 @@ static void drawItems(struct table *t, HDC dc, RECT cliprect) if (GetTextMetricsW(dc, &tm) == 0) abort(); + // adjust the clip rect and the viewport so that (0, 0) is always the first item + if (OffsetRect(&cliprect, 0, t->firstVisible * tm.tmHeight) == 0) + abort(); + if (GetWindowOrgEx(dc, &prevOrigin) == 0) + abort(); + if (SetWindowOrgEx(dc, prevOrigin.x, prevOrigin.y + (t->firstVisible * tm.tmHeight), NULL) == 0) + abort(); + // see http://blogs.msdn.com/b/oldnewthing/archive/2003/07/29/54591.aspx and http://blogs.msdn.com/b/oldnewthing/archive/2003/07/30/54600.aspx first = cliprect.top / tm.tmHeight; if (first < 0) @@ -82,6 +92,9 @@ static void drawItems(struct table *t, HDC dc, RECT cliprect) y += tm.tmHeight; } + // reset everything + if (SetWindowOrgEx(dc, prevOrigin.x, prevOrigin.y, NULL) == 0) + abort(); if (SelectObject(dc, prevfont) != (HGDIOBJ) (thisfont)) abort(); } |
