Started writing the new Table's header.

This commit is contained in:
Pietro Gagliardi 2014-10-20 13:40:57 -04:00
parent 47e2b2cb51
commit f6aeaf29aa
1 changed files with 57 additions and 12 deletions

View File

@ -19,7 +19,7 @@
#include <vsstyle.h> #include <vsstyle.h>
#include <vssym32.h> #include <vssym32.h>
// #qo LIBS: user32 kernel32 gdi32 // #qo LIBS: user32 kernel32 gdi32 comctl32
// TODO // TODO
// - http://blogs.msdn.com/b/oldnewthing/archive/2003/09/09/54826.aspx (relies on the integrality parts? IDK) // - http://blogs.msdn.com/b/oldnewthing/archive/2003/09/09/54826.aspx (relies on the integrality parts? IDK)
@ -36,6 +36,8 @@ struct table {
intptr_t firstVisible; intptr_t firstVisible;
intptr_t pagesize; // in rows intptr_t pagesize; // in rows
int wheelCarry; int wheelCarry;
HWND header;
int headerHeight;
}; };
static LONG rowHeight(struct table *t) static LONG rowHeight(struct table *t)
@ -220,6 +222,8 @@ static void resize(struct table *t)
{ {
RECT r; RECT r;
SCROLLINFO si; SCROLLINFO si;
HDLAYOUT headerlayout;
WINDOWPOS headerpos;
if (GetClientRect(t->hwnd, &r) == 0) if (GetClientRect(t->hwnd, &r) == 0)
abort(); abort();
@ -231,6 +235,13 @@ static void resize(struct table *t)
si.nMax = t->count - 1; si.nMax = t->count - 1;
si.nPage = t->pagesize; si.nPage = t->pagesize;
SetScrollInfo(t->hwnd, SB_VERT, &si, TRUE); SetScrollInfo(t->hwnd, SB_VERT, &si, TRUE);
headerlayout.prc = &r;
headerlayout.pwpos = &headerpos;
if (SendMessageW(t->header, HDM_LAYOUT, 0, (LPARAM) (&headerlayout)) == FALSE)
abort();
if (SetWindowPos(t->header, headerpos.hwndInsertAfter, headerpos.x, headerpos.y, headerpos.cx, headerpos.cy, headerpos.flags | SWP_SHOWWINDOW) == 0)
abort();
t->headerHeight = headerpos.cy;
} }
static void drawItems(struct table *t, HDC dc, RECT cliprect) static void drawItems(struct table *t, HDC dc, RECT cliprect)
@ -317,6 +328,11 @@ static LRESULT CALLBACK tableWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
t = (struct table *) GetWindowLongPtrW(hwnd, GWLP_USERDATA); t = (struct table *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
if (t == NULL) { if (t == NULL) {
// we have to do things this way because creating the header control will fail mysteriously if we create it first thing
// (which is fine; we can get the parent hInstance this way too)
if (uMsg == WM_NCCREATE) {
CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam;
t = (struct table *) malloc(sizeof (struct table)); t = (struct table *) malloc(sizeof (struct table));
if (t == NULL) if (t == NULL)
abort(); abort();
@ -328,8 +344,27 @@ static LRESULT CALLBACK tableWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
abort(); abort();
t->font = t->defaultFont; t->font = t->defaultFont;
t->selected = 5;t->count=100;//TODO t->selected = 5;t->count=100;//TODO
t->header = CreateWindowExW(0,
WC_HEADERW, L"",
// TODO is HOTTRACK needed?
WS_CHILD | HDS_FULLDRAG | HDS_HORZ | HDS_HOTTRACK,
0, 0, 0, 0,
t->hwnd, (HMENU) 100, cs->hInstance, NULL);
if (t->header == NULL)
abort();
{HDITEMW item;
ZeroMemory(&item, sizeof (HDITEMW));
item.mask = HDI_WIDTH | HDI_TEXT | HDI_FORMAT;
item.cxy = 200;
item.pszText = L"Column";
item.fmt = HDF_LEFT | HDF_STRING;
if (SendMessage(t->header, HDM_INSERTITEM, 0, (LPARAM) (&item)) == (LRESULT) (-1))
abort();}
SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) t); SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) t);
} }
// even if we did the above, fall through
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
}
switch (uMsg) { switch (uMsg) {
case WM_PAINT: case WM_PAINT:
dc = BeginPaint(hwnd, &ps); dc = BeginPaint(hwnd, &ps);
@ -342,8 +377,12 @@ t->selected = 5;t->count=100;//TODO
t->font = (HFONT) wParam; t->font = (HFONT) wParam;
if (t->font == NULL) if (t->font == NULL)
t->font = t->defaultFont; t->font = t->defaultFont;
// also set the header font
SendMessageW(t->header, WM_SETFONT, wParam, lParam);
if (LOWORD(lParam) != FALSE) { if (LOWORD(lParam) != FALSE) {
// the scrollbar page size will change so redraw that too // the scrollbar page size will change so redraw that too
// also recalculate the header height
// TODO do that when this is FALSE too somehow
resize(t); resize(t);
redrawAll(t); redrawAll(t);
} }
@ -399,7 +438,13 @@ int main(void)
{ {
HWND mainwin; HWND mainwin;
MSG msg; MSG msg;
INITCOMMONCONTROLSEX icc;
ZeroMemory(&icc, sizeof (INITCOMMONCONTROLSEX));
icc.dwSize = sizeof (INITCOMMONCONTROLSEX);
icc.dwICC = ICC_LISTVIEW_CLASSES;
if (InitCommonControlsEx(&icc) == 0)
abort();
makeTableWindowClass(); makeTableWindowClass();
mainwin = CreateWindowExW(0, mainwin = CreateWindowExW(0,
tableWindowClass, L"Main Window", tableWindowClass, L"Main Window",