Numbered each of the sample items.
This commit is contained in:
parent
3aa4fb3183
commit
42ca7ced99
|
@ -38,14 +38,12 @@ struct table {
|
||||||
int wheelCarry;
|
int wheelCarry;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void vscrollto(struct table *t, intptr_t newpos)
|
static LONG rowHeight(struct table *t)
|
||||||
{
|
{
|
||||||
HFONT thisfont, prevfont;
|
HFONT thisfont, prevfont;
|
||||||
TEXTMETRICW tm;
|
TEXTMETRICW tm;
|
||||||
HDC dc;
|
HDC dc;
|
||||||
SCROLLINFO si;
|
|
||||||
|
|
||||||
// TODO split into a function
|
|
||||||
dc = GetDC(t->hwnd);
|
dc = GetDC(t->hwnd);
|
||||||
if (dc == NULL)
|
if (dc == NULL)
|
||||||
abort();
|
abort();
|
||||||
|
@ -59,6 +57,12 @@ static void vscrollto(struct table *t, intptr_t newpos)
|
||||||
abort();
|
abort();
|
||||||
if (ReleaseDC(t->hwnd, dc) == 0)
|
if (ReleaseDC(t->hwnd, dc) == 0)
|
||||||
abort();
|
abort();
|
||||||
|
return tm.tmHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vscrollto(struct table *t, intptr_t newpos)
|
||||||
|
{
|
||||||
|
SCROLLINFO si;
|
||||||
|
|
||||||
if (newpos < 0)
|
if (newpos < 0)
|
||||||
newpos = 0;
|
newpos = 0;
|
||||||
|
@ -66,7 +70,7 @@ static void vscrollto(struct table *t, intptr_t newpos)
|
||||||
newpos = (t->count - t->pagesize);
|
newpos = (t->count - t->pagesize);
|
||||||
|
|
||||||
// negative because ScrollWindowEx() is "backwards"
|
// 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,
|
NULL, NULL, NULL, NULL,
|
||||||
SW_ERASE | SW_INVALIDATE) == ERROR)
|
SW_ERASE | SW_INVALIDATE) == ERROR)
|
||||||
abort();
|
abort();
|
||||||
|
@ -151,28 +155,12 @@ static void vscroll(struct table *t, WPARAM wParam)
|
||||||
|
|
||||||
static void resize(struct table *t)
|
static void resize(struct table *t)
|
||||||
{
|
{
|
||||||
HFONT thisfont, prevfont;
|
|
||||||
TEXTMETRICW tm;
|
|
||||||
HDC dc;
|
|
||||||
RECT r;
|
RECT r;
|
||||||
SCROLLINFO si;
|
SCROLLINFO si;
|
||||||
|
|
||||||
if (GetClientRect(t->hwnd, &r) == 0)
|
if (GetClientRect(t->hwnd, &r) == 0)
|
||||||
abort();
|
abort();
|
||||||
dc = GetDC(t->hwnd);
|
t->pagesize = (r.bottom - r.top) / rowHeight(t);
|
||||||
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;
|
|
||||||
ZeroMemory(&si, sizeof (SCROLLINFO));
|
ZeroMemory(&si, sizeof (SCROLLINFO));
|
||||||
si.cbSize = sizeof (SCROLLINFO);
|
si.cbSize = sizeof (SCROLLINFO);
|
||||||
si.fMask = SIF_RANGE | SIF_PAGE;
|
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++) {
|
for (i = first; i < last; i++) {
|
||||||
RECT rsel;
|
RECT rsel;
|
||||||
HBRUSH background;
|
HBRUSH background;
|
||||||
|
WCHAR msg[100];
|
||||||
|
|
||||||
// TODO check errors
|
// TODO check errors
|
||||||
// TODO verify correct colors
|
// TODO verify correct colors
|
||||||
|
@ -238,7 +227,7 @@ static void drawItems(struct table *t, HDC dc, RECT cliprect)
|
||||||
SetTextColor(dc, GetSysColor(COLOR_WINDOWTEXT));
|
SetTextColor(dc, GetSysColor(COLOR_WINDOWTEXT));
|
||||||
FillRect(dc, &rsel, background);
|
FillRect(dc, &rsel, background);
|
||||||
SetBkMode(dc, TRANSPARENT);
|
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;
|
y += tm.tmHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue