diff options
Diffstat (limited to 'CPP/Windows/Control/ListView.cpp')
-rw-r--r-- | CPP/Windows/Control/ListView.cpp | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/CPP/Windows/Control/ListView.cpp b/CPP/Windows/Control/ListView.cpp new file mode 100644 index 0000000..16cfd39 --- /dev/null +++ b/CPP/Windows/Control/ListView.cpp | |||
@@ -0,0 +1,155 @@ | |||
1 | // Windows/Control/ListView.cpp | ||
2 | |||
3 | #include "StdAfx.h" | ||
4 | |||
5 | #include "ListView.h" | ||
6 | |||
7 | #ifndef _UNICODE | ||
8 | extern bool g_IsNT; | ||
9 | #endif | ||
10 | |||
11 | namespace NWindows { | ||
12 | namespace NControl { | ||
13 | |||
14 | bool CListView::CreateEx(DWORD exStyle, DWORD style, | ||
15 | int x, int y, int width, int height, | ||
16 | HWND parentWindow, HMENU idOrHMenu, | ||
17 | HINSTANCE instance, LPVOID createParam) | ||
18 | { | ||
19 | return CWindow::CreateEx(exStyle, WC_LISTVIEW, TEXT(""), style, x, y, width, | ||
20 | height, parentWindow, idOrHMenu, instance, createParam); | ||
21 | } | ||
22 | |||
23 | bool CListView::GetItemParam(int index, LPARAM ¶m) const | ||
24 | { | ||
25 | LVITEM item; | ||
26 | item.iItem = index; | ||
27 | item.iSubItem = 0; | ||
28 | item.mask = LVIF_PARAM; | ||
29 | bool aResult = GetItem(&item); | ||
30 | param = item.lParam; | ||
31 | return aResult; | ||
32 | } | ||
33 | |||
34 | int CListView::InsertColumn(int columnIndex, LPCTSTR text, int width) | ||
35 | { | ||
36 | LVCOLUMN ci; | ||
37 | ci.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; | ||
38 | ci.pszText = (LPTSTR)(void *)text; | ||
39 | ci.iSubItem = columnIndex; | ||
40 | ci.cx = width; | ||
41 | return InsertColumn(columnIndex, &ci); | ||
42 | } | ||
43 | |||
44 | int CListView::InsertItem(int index, LPCTSTR text) | ||
45 | { | ||
46 | LVITEM item; | ||
47 | item.mask = LVIF_TEXT | LVIF_PARAM; | ||
48 | item.iItem = index; | ||
49 | item.lParam = index; | ||
50 | item.pszText = (LPTSTR)(void *)text; | ||
51 | item.iSubItem = 0; | ||
52 | return InsertItem(&item); | ||
53 | } | ||
54 | |||
55 | int CListView::SetSubItem(int index, int subIndex, LPCTSTR text) | ||
56 | { | ||
57 | LVITEM item; | ||
58 | item.mask = LVIF_TEXT; | ||
59 | item.iItem = index; | ||
60 | item.pszText = (LPTSTR)(void *)text; | ||
61 | item.iSubItem = subIndex; | ||
62 | return SetItem(&item); | ||
63 | } | ||
64 | |||
65 | #ifndef _UNICODE | ||
66 | |||
67 | int CListView::InsertColumn(int columnIndex, LPCWSTR text, int width) | ||
68 | { | ||
69 | LVCOLUMNW ci; | ||
70 | ci.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; | ||
71 | ci.pszText = (LPWSTR)(void *)text; | ||
72 | ci.iSubItem = columnIndex; | ||
73 | ci.cx = width; | ||
74 | return InsertColumn(columnIndex, &ci); | ||
75 | } | ||
76 | |||
77 | int CListView::InsertItem(int index, LPCWSTR text) | ||
78 | { | ||
79 | LVITEMW item; | ||
80 | item.mask = LVIF_TEXT | LVIF_PARAM; | ||
81 | item.iItem = index; | ||
82 | item.lParam = index; | ||
83 | item.pszText = (LPWSTR)(void *)text; | ||
84 | item.iSubItem = 0; | ||
85 | return InsertItem(&item); | ||
86 | } | ||
87 | |||
88 | int CListView::SetSubItem(int index, int subIndex, LPCWSTR text) | ||
89 | { | ||
90 | LVITEMW item; | ||
91 | item.mask = LVIF_TEXT; | ||
92 | item.iItem = index; | ||
93 | item.pszText = (LPWSTR)(void *)text; | ||
94 | item.iSubItem = subIndex; | ||
95 | return SetItem(&item); | ||
96 | } | ||
97 | |||
98 | #endif | ||
99 | |||
100 | static LRESULT APIENTRY ListViewSubclassProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) | ||
101 | { | ||
102 | CWindow window(hwnd); | ||
103 | CListView2 *w = (CListView2 *)(window.GetUserDataLongPtr()); | ||
104 | if (w == NULL) | ||
105 | return 0; | ||
106 | return w->OnMessage(message, wParam, lParam); | ||
107 | } | ||
108 | |||
109 | LRESULT CListView2::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) | ||
110 | { | ||
111 | #ifndef _UNICODE | ||
112 | if (g_IsNT) | ||
113 | return CallWindowProcW(_origWindowProc, *this, message, wParam, lParam); | ||
114 | else | ||
115 | #endif | ||
116 | return CallWindowProc(_origWindowProc, *this, message, wParam, lParam); | ||
117 | } | ||
118 | |||
119 | void CListView2::SetWindowProc() | ||
120 | { | ||
121 | SetUserDataLongPtr((LONG_PTR)this); | ||
122 | #ifndef _UNICODE | ||
123 | if (g_IsNT) | ||
124 | _origWindowProc = (WNDPROC)SetLongPtrW(GWLP_WNDPROC, (LONG_PTR)ListViewSubclassProc); | ||
125 | else | ||
126 | #endif | ||
127 | _origWindowProc = (WNDPROC)SetLongPtr(GWLP_WNDPROC, (LONG_PTR)ListViewSubclassProc); | ||
128 | } | ||
129 | |||
130 | /* | ||
131 | LRESULT CListView3::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) | ||
132 | { | ||
133 | LRESULT res = CListView2::OnMessage(message, wParam, lParam); | ||
134 | if (message == WM_GETDLGCODE) | ||
135 | { | ||
136 | // when user presses RETURN, windows sends default (first) button command to parent dialog. | ||
137 | // we disable this: | ||
138 | MSG *msg = (MSG *)lParam; | ||
139 | WPARAM key = wParam; | ||
140 | bool change = false; | ||
141 | if (msg) | ||
142 | { | ||
143 | if (msg->message == WM_KEYDOWN && msg->wParam == VK_RETURN) | ||
144 | change = true; | ||
145 | } | ||
146 | else if (wParam == VK_RETURN) | ||
147 | change = true; | ||
148 | if (change) | ||
149 | res |= DLGC_WANTALLKEYS; | ||
150 | } | ||
151 | return res; | ||
152 | } | ||
153 | */ | ||
154 | |||
155 | }} | ||