aboutsummaryrefslogtreecommitdiff
path: root/c/listview.c
blob: 91838da08e5b8d0baa6a0c2a72e7a91ba198758b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <windows.h>
#include <commctrl.h>
#include <uxtheme.h>

#include "resource.h"
#include "defs.h"

extern HFONT HfNormal;
extern HWND HWnd;
WNDPROC LvPrevProc;
static LRESULT CALLBACK LvProc(HWND, UINT, WPARAM, LPARAM);

HWND
LvCreate(HMENU hMenu, DWORD dwStyle)
{
	HWND hLv;

	hLv = CreateWindowEx(
	    WS_EX_CLIENTEDGE,
	    WC_LISTVIEW,
	    TEXT(""),
	    dwStyle|WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP
	    |LVS_REPORT|LVS_SHOWSELALWAYS,
	    0, 0, 0, 0,
	    HWnd, hMenu, GetModuleHandle(NULL), NULL
	);

	LvPrevProc = (WNDPROC)SetWindowLongPtr(hLv,
	    GWLP_WNDPROC, (LONG_PTR)LvProc);

	ListView_SetExtendedListViewStyle(hLv, LVS_EX_FULLROWSELECT);

	SendMessage(hLv, WM_SETFONT, (WPARAM)HfNormal, MAKELPARAM(FALSE, 0));

	return hLv;
}

LRESULT CALLBACK
LvProc(HWND hLv, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg) {
	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->code) {
		case HDN_ENDTRACK:
			UpdateLayout();
			return TRUE;
		}
		break;
	case WM_GETDLGCODE:
	    {
		LRESULT lResult;
		extern HWND HElv;

		/* For the episode list view, the Enter key should not
		 * be handled by the dialog manager, but instead be sent
		 * along to the main window procedure, so that it may be
		 * handled by the NM_RETURN case in ElvHandleNotify. */

		if (hLv != HElv) break;
		lResult = CallWindowProc(LvPrevProc, hLv, uMsg, wParam, lParam);
		if (lParam && ((MSG *)lParam)->message == WM_KEYDOWN
		    && ((MSG *)lParam)->wParam == VK_RETURN)
			return DLGC_WANTMESSAGE;
		return lResult;
	    }
	}

	return CallWindowProc(LvPrevProc, hLv, uMsg, wParam, lParam);
}

/* Naively calculate height of list view. */
int
LvHeight(HWND hLv, int bHeader)
{
	int iCount;
	iCount = ListView_GetItemCount(hLv);
	return iCount? Dpi(bHeader? 27: 4)+iCount*Dpi(19): 0;
}