Fixed the Windows Table reimplementation's redraw issues. Thanks again to Jonathan Potter (http://stackoverflow.com/a/26747199/3408572).

This commit is contained in:
Pietro Gagliardi 2014-11-06 19:47:38 -05:00
parent 0b36a87713
commit 130e139806
1 changed files with 14 additions and 18 deletions

View File

@ -392,7 +392,6 @@ static void drawItems(struct table *t, HDC dc, RECT cliprect)
intptr_t i; intptr_t i;
RECT controlSize; // for filling the entire selected row RECT controlSize; // for filling the entire selected row
intptr_t first, last; intptr_t first, last;
POINT prevOrigin, prevViewportOrigin;
if (GetClientRect(t->hwnd, &controlSize) == 0) if (GetClientRect(t->hwnd, &controlSize) == 0)
abort(); abort();
@ -404,36 +403,33 @@ static void drawItems(struct table *t, HDC dc, RECT cliprect)
if (prevfont == NULL) if (prevfont == NULL)
abort(); abort();
// adjust the clip rect and the window so that (0, 0) is always the first item // ignore anything beneath the header
// adjust the viewport so that everything is shifted down t->headerHeight pixels if (cliprect.top < t->headerHeight)
if (OffsetRect(&cliprect, 0, t->firstVisible * height) == 0) cliprect.top = t->headerHeight;
abort(); // now let's pretend the header isn't there
if (GetWindowOrgEx(dc, &prevOrigin) == 0) // we only need it in (or rather, before) the drawItem() calls below
abort(); cliprect.top -= t->headerHeight;
if (SetWindowOrgEx(dc, prevOrigin.x, prevOrigin.y + (t->firstVisible * height), NULL) == 0) cliprect.bottom -= t->headerHeight;
abort();
if (SetViewportOrgEx(dc, 0, t->headerHeight, &prevViewportOrigin) == 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 // 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 / height; // we need to add t->firstVisible here because cliprect is relative to the visible area
first = (cliprect.top / height) + t->firstVisible;
if (first < 0) if (first < 0)
first = 0; first = 0;
last = (cliprect.bottom + height - 1) / height; last = ((cliprect.bottom + height - 1) / height) + t->firstVisible;
if (last >= t->count) if (last >= t->count)
last = t->count; last = t->count;
y = first * height; // now for the first y, discount firstVisible
y = (first - t->firstVisible) * height;
// and offset by the header height
y += t->headerHeight;
for (i = first; i < last; i++) { for (i = first; i < last; i++) {
drawItem(t, dc, i, y, height, controlSize); drawItem(t, dc, i, y, height, controlSize);
y += height; y += height;
} }
// reset everything // reset everything
if (SetViewportOrgEx(dc, prevViewportOrigin.x, prevViewportOrigin.y, NULL) == 0)
abort();
if (SetWindowOrgEx(dc, prevOrigin.x, prevOrigin.y, NULL) == 0)
abort();
if (SelectObject(dc, prevfont) != (HGDIOBJ) (thisfont)) if (SelectObject(dc, prevfont) != (HGDIOBJ) (thisfont))
abort(); abort();
} }