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
CreateEx(DWORD exStyle,DWORD style,int x,int y,int width,int height,HWND parentWindow,HMENU idOrHMenu,HINSTANCE instance,LPVOID createParam)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 /* note: LVITEM and LVCOLUMN structures contain optional fields
24 depending from preprocessor macros:
25 #if (_WIN32_IE >= 0x0300)
26 #if (_WIN32_WINNT >= 0x0501)
27 #if (_WIN32_WINNT >= 0x0600)
28 */
29
GetItemParam(unsigned index,LPARAM & param) const30 bool CListView::GetItemParam(unsigned index, LPARAM ¶m) const
31 {
32 LVITEM item;
33 item.iItem = (int)index;
34 item.iSubItem = 0;
35 item.mask = LVIF_PARAM;
36 const bool res = GetItem(&item);
37 param = item.lParam;
38 return res;
39 }
40
InsertColumn(unsigned columnIndex,LPCTSTR text,int width)41 int CListView::InsertColumn(unsigned columnIndex, LPCTSTR text, int width)
42 {
43 LVCOLUMN ci;
44 ci.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
45 ci.pszText = (LPTSTR)(void *)text;
46 ci.iSubItem = (int)columnIndex;
47 ci.cx = width;
48 return InsertColumn(columnIndex, &ci);
49 }
50
InsertItem(unsigned index,LPCTSTR text)51 int CListView::InsertItem(unsigned index, LPCTSTR text)
52 {
53 LVITEM item;
54 item.mask = LVIF_TEXT | LVIF_PARAM;
55 item.iItem = (int)index;
56 item.lParam = (LPARAM)index;
57 item.pszText = (LPTSTR)(void *)text;
58 item.iSubItem = 0;
59 return InsertItem(&item);
60 }
61
SetSubItem(unsigned index,unsigned subIndex,LPCTSTR text)62 int CListView::SetSubItem(unsigned index, unsigned subIndex, LPCTSTR text)
63 {
64 LVITEM item;
65 item.mask = LVIF_TEXT;
66 item.iItem = (int)index;
67 item.pszText = (LPTSTR)(void *)text;
68 item.iSubItem = (int)subIndex;
69 return SetItem(&item);
70 }
71
72 #ifndef _UNICODE
73
InsertColumn(unsigned columnIndex,LPCWSTR text,int width)74 int CListView::InsertColumn(unsigned columnIndex, LPCWSTR text, int width)
75 {
76 LVCOLUMNW ci;
77 ci.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
78 ci.pszText = (LPWSTR)(void *)text;
79 ci.iSubItem = (int)columnIndex;
80 ci.cx = width;
81 return InsertColumn(columnIndex, &ci);
82 }
83
InsertItem(unsigned index,LPCWSTR text)84 int CListView::InsertItem(unsigned index, LPCWSTR text)
85 {
86 LVITEMW item;
87 item.mask = LVIF_TEXT | LVIF_PARAM;
88 item.iItem = (int)index;
89 item.lParam = (LPARAM)index;
90 item.pszText = (LPWSTR)(void *)text;
91 item.iSubItem = 0;
92 return InsertItem(&item);
93 }
94
SetSubItem(unsigned index,unsigned subIndex,LPCWSTR text)95 int CListView::SetSubItem(unsigned index, unsigned subIndex, LPCWSTR text)
96 {
97 LVITEMW item;
98 item.mask = LVIF_TEXT;
99 item.iItem = (int)index;
100 item.pszText = (LPWSTR)(void *)text;
101 item.iSubItem = (int)subIndex;
102 return SetItem(&item);
103 }
104
105 #endif
106
ListViewSubclassProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)107 static LRESULT APIENTRY ListViewSubclassProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
108 {
109 CWindow window(hwnd);
110 CListView2 *w = (CListView2 *)(window.GetUserDataLongPtr());
111 if (w == NULL)
112 return 0;
113 return w->OnMessage(message, wParam, lParam);
114 }
115
OnMessage(UINT message,WPARAM wParam,LPARAM lParam)116 LRESULT CListView2::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
117 {
118 #ifndef _UNICODE
119 if (g_IsNT)
120 return CallWindowProcW(_origWindowProc, *this, message, wParam, lParam);
121 else
122 #endif
123 return CallWindowProc(_origWindowProc, *this, message, wParam, lParam);
124 }
125
SetWindowProc()126 void CListView2::SetWindowProc()
127 {
128 SetUserDataLongPtr((LONG_PTR)this);
129 #ifndef _UNICODE
130 if (g_IsNT)
131 _origWindowProc = (WNDPROC)SetLongPtrW(GWLP_WNDPROC, (LONG_PTR)ListViewSubclassProc);
132 else
133 #endif
134 _origWindowProc = (WNDPROC)SetLongPtr(GWLP_WNDPROC, (LONG_PTR)ListViewSubclassProc);
135 }
136
137 /*
138 LRESULT CListView3::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
139 {
140 LRESULT res = CListView2::OnMessage(message, wParam, lParam);
141 if (message == WM_GETDLGCODE)
142 {
143 // when user presses RETURN, windows sends default (first) button command to parent dialog.
144 // we disable this:
145 MSG *msg = (MSG *)lParam;
146 WPARAM key = wParam;
147 bool change = false;
148 if (msg)
149 {
150 if (msg->message == WM_KEYDOWN && msg->wParam == VK_RETURN)
151 change = true;
152 }
153 else if (wParam == VK_RETURN)
154 change = true;
155 if (change)
156 res |= DLGC_WANTALLKEYS;
157 }
158 return res;
159 }
160 */
161
162 }}
163