Set the DC viewport properly for the purposes of scrolling.

This commit is contained in:
Pietro Gagliardi 2014-10-19 22:20:53 -04:00
parent ec22c573ba
commit a3ad384a34
1 changed files with 13 additions and 0 deletions

View File

@ -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();
}