Added a second column, drew stuff in it, and assorted other changes.
This commit is contained in:
parent
9d951dc732
commit
2fb6254420
|
@ -39,6 +39,7 @@ struct table {
|
||||||
int wheelCarry;
|
int wheelCarry;
|
||||||
HWND header;
|
HWND header;
|
||||||
int headerHeight;
|
int headerHeight;
|
||||||
|
intptr_t nColumns;
|
||||||
};
|
};
|
||||||
|
|
||||||
static LONG rowHeight(struct table *t)
|
static LONG rowHeight(struct table *t)
|
||||||
|
@ -81,9 +82,20 @@ static RECT realClientRect(struct table *t)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void finishSelect(struct table *t)
|
||||||
|
{
|
||||||
|
if (t->selected < 0)
|
||||||
|
t->selected = 0;
|
||||||
|
if (t->selected >= t->count)
|
||||||
|
t->selected = t->count - 1;
|
||||||
|
// TODO update only the old and new selected items
|
||||||
|
redrawAll(t);
|
||||||
|
// TODO scroll to the selected item if it's not entirely visible
|
||||||
|
}
|
||||||
|
|
||||||
static void keySelect(struct table *t, WPARAM wParam, LPARAM lParam)
|
static void keySelect(struct table *t, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
// TODO what happens if up/page up is pressed with nothing selected?
|
// TODO figure out correct behavior with nothing selected
|
||||||
if (t->count == 0) // don't try to do anything if there's nothing to do
|
if (t->count == 0) // don't try to do anything if there's nothing to do
|
||||||
return;
|
return;
|
||||||
switch (wParam) {
|
switch (wParam) {
|
||||||
|
@ -109,13 +121,7 @@ static void keySelect(struct table *t, WPARAM wParam, LPARAM lParam)
|
||||||
// don't touch anything
|
// don't touch anything
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (t->selected < 0)
|
finishSelect(t);
|
||||||
t->selected = 0;
|
|
||||||
if (t->selected >= t->count)
|
|
||||||
t->selected = t->count - 1;
|
|
||||||
// TODO update only the old and new selected items
|
|
||||||
redrawAll(t);
|
|
||||||
// TODO scroll to the selected item if it's not entirely visible
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void selectItem(struct table *t, WPARAM wParam, LPARAM lParam)
|
static void selectItem(struct table *t, WPARAM wParam, LPARAM lParam)
|
||||||
|
@ -132,9 +138,7 @@ static void selectItem(struct table *t, WPARAM wParam, LPARAM lParam)
|
||||||
t->selected = y;
|
t->selected = y;
|
||||||
if (t->selected >= t->count)
|
if (t->selected >= t->count)
|
||||||
t->selected = -1;
|
t->selected = -1;
|
||||||
// TODO update only the old and new selected items
|
finishSelect(t);
|
||||||
redrawAll(t);
|
|
||||||
// TODO scroll to the selected item if it's not entirely visible
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO on initial show the items are not arranged properly
|
// TODO on initial show the items are not arranged properly
|
||||||
|
@ -272,12 +276,11 @@ static void drawItems(struct table *t, HDC dc, RECT cliprect)
|
||||||
TEXTMETRICW tm;
|
TEXTMETRICW tm;
|
||||||
LONG y;
|
LONG y;
|
||||||
intptr_t i;
|
intptr_t i;
|
||||||
RECT r;
|
RECT controlSize; // for filling the entire selected row
|
||||||
intptr_t first, last;
|
intptr_t first, last;
|
||||||
POINT prevOrigin, prevViewportOrigin;
|
POINT prevOrigin, prevViewportOrigin;
|
||||||
|
|
||||||
// TODO eliminate the need (only use cliprect)
|
if (GetClientRect(t->hwnd, &controlSize) == 0)
|
||||||
if (GetClientRect(t->hwnd, &r) == 0)
|
|
||||||
abort();
|
abort();
|
||||||
|
|
||||||
thisfont = t->font; // in case WM_SETFONT happens before we return
|
thisfont = t->font; // in case WM_SETFONT happens before we return
|
||||||
|
@ -313,12 +316,8 @@ static void drawItems(struct table *t, HDC dc, RECT cliprect)
|
||||||
int textColor;
|
int textColor;
|
||||||
WCHAR msg[100];
|
WCHAR msg[100];
|
||||||
RECT headeritem;
|
RECT headeritem;
|
||||||
|
intptr_t j;
|
||||||
|
|
||||||
// TODO check errors
|
|
||||||
rsel.left = r.left;
|
|
||||||
rsel.top = y;
|
|
||||||
rsel.right = r.right - r.left;
|
|
||||||
rsel.bottom = y + tm.tmHeight;
|
|
||||||
// TODO verify these two
|
// TODO verify these two
|
||||||
background = (HBRUSH) (COLOR_WINDOW + 1);
|
background = (HBRUSH) (COLOR_WINDOW + 1);
|
||||||
textColor = COLOR_WINDOWTEXT;
|
textColor = COLOR_WINDOWTEXT;
|
||||||
|
@ -332,16 +331,30 @@ static void drawItems(struct table *t, HDC dc, RECT cliprect)
|
||||||
textColor = COLOR_BTNTEXT;
|
textColor = COLOR_BTNTEXT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SetTextColor(dc, GetSysColor(textColor));
|
|
||||||
FillRect(dc, &rsel, background);
|
// first fill the selection rect
|
||||||
SetBkMode(dc, TRANSPARENT);
|
rsel.left = controlSize.left;
|
||||||
if (SendMessageW(t->header, HDM_GETITEMRECT, 0, (LPARAM) (&headeritem)) == 0)
|
rsel.top = y;
|
||||||
|
rsel.right = controlSize.right - controlSize.left;
|
||||||
|
rsel.bottom = y + tm.tmHeight;
|
||||||
|
if (FillRect(dc, &rsel, background) == 0)
|
||||||
|
abort();
|
||||||
|
|
||||||
|
// now draw the cells
|
||||||
|
if (SetTextColor(dc, GetSysColor(textColor)) == CLR_INVALID)
|
||||||
|
abort();
|
||||||
|
if (SetBkMode(dc, TRANSPARENT) == 0)
|
||||||
|
abort();
|
||||||
|
for (j = 0; j < t->nColumns; j++) {
|
||||||
|
if (SendMessageW(t->header, HDM_GETITEMRECT, (WPARAM) j, (LPARAM) (&headeritem)) == 0)
|
||||||
abort();
|
abort();
|
||||||
rsel.left = headeritem.left + SendMessageW(t->header, HDM_GETBITMAPMARGIN, 0, 0);
|
rsel.left = headeritem.left + SendMessageW(t->header, HDM_GETBITMAPMARGIN, 0, 0);
|
||||||
rsel.top = y;
|
rsel.top = y;
|
||||||
rsel.right = headeritem.right;
|
rsel.right = headeritem.right;
|
||||||
rsel.bottom = y + tm.tmHeight;
|
rsel.bottom = y + tm.tmHeight;
|
||||||
DrawTextExW(dc, msg, wsprintf(msg, L"Item %d", i), &rsel, DT_END_ELLIPSIS | DT_LEFT | DT_NOPREFIX | DT_SINGLELINE, NULL);
|
if (DrawTextExW(dc, msg, wsprintf(msg, L"Item %d", i), &rsel, DT_END_ELLIPSIS | DT_LEFT | DT_NOPREFIX | DT_SINGLELINE, NULL) == 0)
|
||||||
|
abort();
|
||||||
|
}
|
||||||
y += tm.tmHeight;
|
y += tm.tmHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,7 +408,15 @@ item.cxy = 200;
|
||||||
item.pszText = L"Column";
|
item.pszText = L"Column";
|
||||||
item.fmt = HDF_LEFT | HDF_STRING;
|
item.fmt = HDF_LEFT | HDF_STRING;
|
||||||
if (SendMessage(t->header, HDM_INSERTITEM, 0, (LPARAM) (&item)) == (LRESULT) (-1))
|
if (SendMessage(t->header, HDM_INSERTITEM, 0, (LPARAM) (&item)) == (LRESULT) (-1))
|
||||||
abort();}
|
abort();
|
||||||
|
ZeroMemory(&item, sizeof (HDITEMW));
|
||||||
|
item.mask = HDI_WIDTH | HDI_TEXT | HDI_FORMAT;
|
||||||
|
item.cxy = 150;
|
||||||
|
item.pszText = L"Column 2";
|
||||||
|
item.fmt = HDF_LEFT | HDF_STRING;
|
||||||
|
if (SendMessage(t->header, HDM_INSERTITEM, 1, (LPARAM) (&item)) == (LRESULT) (-1))
|
||||||
|
abort();
|
||||||
|
t->nColumns=2;}
|
||||||
SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) t);
|
SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) t);
|
||||||
}
|
}
|
||||||
// even if we did the above, fall through
|
// even if we did the above, fall through
|
||||||
|
|
Loading…
Reference in New Issue