#include #include #include #include "common.h" #include "listview.h" #include "main.h" extern HFONT g_hfNormal; static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); ListView::ListView(const HWND hWndParent, const HMENU hMenu, const DWORD dwStyle) { m_hWndParent = hWndParent; m_bHeader = !(dwStyle & LVS_NOCOLUMNHEADER); hWnd = CreateWindowEx( WS_EX_CLIENTEDGE, WC_LISTVIEW, TEXT(""), dwStyle|WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP|LVS_REPORT|LVS_SHOWSELALWAYS, 0, 0, 0, 0, m_hWndParent, hMenu, GetModuleHandle(NULL), this ); if (SetProp(hWnd, TEXT("this"), (HANDLE)this)) m_prevProc = (WNDPROC)SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)::WndProc); ListView_SetExtendedListViewStyle(hWnd, LVS_EX_FULLROWSELECT); SendMessage(hWnd, WM_SETFONT, (WPARAM)g_hfNormal, MAKELPARAM(FALSE, 0)); } /* Naively calculate height of list view. */ int ListView::Height(int bHeader) { if (bHeader == -1) bHeader = m_bHeader; const int iCount = ListView_GetItemCount(hWnd); return iCount? Dpi(bHeader? 27: 4)+iCount*Dpi(19): 0; } void ListView::UpdateTheme(const BOOL bThemeActive) { DWORD dwStyle; const TCHAR* tszTheme; WORD wAction; extern int g_bThemes; if (!g_bThemes) return; if (bThemeActive) { dwStyle = LVS_EX_DOUBLEBUFFER; tszTheme = TEXT("Explorer"); wAction = UIS_SET; } else { dwStyle = 0; tszTheme = NULL; wAction = UIS_CLEAR; } /* Use modern "Explorer" theme. */ SetWindowTheme(hWnd, tszTheme, NULL); /* The modern theme requires double buffering. */ ListView_SetExtendedListViewStyleEx(hWnd, LVS_EX_DOUBLEBUFFER, dwStyle); /* Hide focus rectangles. */ SendMessage(hWnd, WM_UPDATEUISTATE, MAKEWPARAM(wAction, UISF_HIDEFOCUS), 0); } LRESULT CALLBACK ListView::WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam, const LPARAM lParam) { switch (uMsg) { case WM_NOTIFY: switch (((NMHDR*)lParam)->code) { case HDN_ENDTRACK: UpdateLayout(); return TRUE; } break; } return CallWindowProc(m_prevProc, hWnd, uMsg, wParam, lParam); } LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam, const LPARAM lParam) { ListView* const pLv = (ListView*)GetProp(hWnd, TEXT("this")); if (uMsg == WM_DESTROY) RemoveProp(hWnd, TEXT("this")); return pLv? pLv->WndProc(hWnd, uMsg, wParam, lParam): FALSE; }