4 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 /*******************************************************************************
35 * Global and Local Variables:
38 static WNDPROC g_orgListWndProc;
40 #define MAX_LIST_COLUMNS (IDS_LIST_COLUMN_LAST - IDS_LIST_COLUMN_FIRST + 1)
41 static int default_column_widths[MAX_LIST_COLUMNS] = { 200, 175, 400 };
42 static int column_alignment[MAX_LIST_COLUMNS] = { LVCFMT_LEFT, LVCFMT_LEFT, LVCFMT_LEFT };
45 /*******************************************************************************
46 * Local module support methods
48 static void AddEntryToList(HWND hwndLV, LPTSTR Name, DWORD dwValType, void* ValBuf, DWORD dwCount)
53 item.mask = LVIF_TEXT | LVIF_PARAM;
54 item.iItem = 0;/*idx; */
59 item.cchTextMax = _tcslen(item.pszText);
60 if (item.cchTextMax == 0)
61 item.pszText = LPSTR_TEXTCALLBACK;
63 item.lParam = (LPARAM)dwValType;
64 /* item.lParam = (LPARAM)ValBuf; */
65 #if (_WIN32_IE >= 0x0300)
69 index = ListView_InsertItem(hwndLV, &item);
71 /* LPTSTR pszText = NULL; */
72 LPTSTR pszText = _T("value");
76 ListView_SetItemText(hwndLV, index, 2, ValBuf);
81 wsprintf(buf, _T("0x%08X (%d)"), *(DWORD*)ValBuf, *(DWORD*)ValBuf);
82 ListView_SetItemText(hwndLV, index, 2, buf);
84 /* lpsRes = convertHexToDWORDStr(lpbData, dwLen); */
89 LPBYTE pData = (LPBYTE)ValBuf;
90 LPTSTR strBinary = HeapAlloc(GetProcessHeap(), 0, dwCount * sizeof(TCHAR) * 3 + 1);
91 for (i = 0; i < dwCount; i++)
92 wsprintf( strBinary + i*3, _T("%02X "), pData[i] );
93 strBinary[dwCount * 3] = 0;
94 ListView_SetItemText(hwndLV, index, 2, strBinary);
95 HeapFree(GetProcessHeap(), 0, strBinary);
99 /* lpsRes = convertHexToHexCSV(lpbData, dwLen); */
100 ListView_SetItemText(hwndLV, index, 2, pszText);
106 static void CreateListColumns(HWND hWndListView)
112 /* Create columns. */
113 lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
114 lvC.pszText = szText;
116 /* Load the column labels from the resource file. */
117 for (index = 0; index < MAX_LIST_COLUMNS; index++) {
118 lvC.iSubItem = index;
119 lvC.cx = default_column_widths[index];
120 lvC.fmt = column_alignment[index];
121 LoadString(hInst, IDS_LIST_COLUMN_FIRST + index, szText, sizeof(szText)/sizeof(TCHAR));
122 if (ListView_InsertColumn(hWndListView, index, &lvC) == -1) {
123 /* TODO: handle failure condition... */
129 /* OnGetDispInfo - processes the LVN_GETDISPINFO notification message. */
131 static void OnGetDispInfo(NMLVDISPINFO* plvdi)
133 static TCHAR buffer[200];
135 plvdi->item.pszText = NULL;
136 plvdi->item.cchTextMax = 0;
138 switch (plvdi->item.iSubItem) {
140 plvdi->item.pszText = _T("(Default)");
143 switch (plvdi->item.lParam) {
145 plvdi->item.pszText = _T("REG_SZ");
148 plvdi->item.pszText = _T("REG_EXPAND_SZ");
151 plvdi->item.pszText = _T("REG_BINARY");
154 plvdi->item.pszText = _T("REG_DWORD");
156 /* case REG_DWORD_LITTLE_ENDIAN: */
157 /* plvdi->item.pszText = _T("REG_DWORD_LITTLE_ENDIAN"); */
159 case REG_DWORD_BIG_ENDIAN:
160 plvdi->item.pszText = _T("REG_DWORD_BIG_ENDIAN");
163 plvdi->item.pszText = _T("REG_MULTI_SZ");
166 plvdi->item.pszText = _T("REG_LINK");
168 case REG_RESOURCE_LIST:
169 plvdi->item.pszText = _T("REG_RESOURCE_LIST");
172 plvdi->item.pszText = _T("REG_NONE");
175 wsprintf(buffer, _T("unknown(%d)"), plvdi->item.lParam);
176 plvdi->item.pszText = buffer;
181 plvdi->item.pszText = _T("(value not set)");
184 plvdi->item.pszText = _T("");
190 static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
195 ListView_GetItemText((HWND)lParamSort, lParam1, 0, buf1, sizeof(buf1));
196 ListView_GetItemText((HWND)lParamSort, lParam2, 0, buf2, sizeof(buf2));
197 return _tcscmp(buf1, buf2);
201 static void ListViewPopUpMenu(HWND hWnd, POINT pt)
205 static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
207 switch (LOWORD(wParam)) {
208 /* case ID_FILE_OPEN: */
216 static LRESULT CALLBACK ListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
220 if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
221 return CallWindowProc(g_orgListWndProc, hWnd, message, wParam, lParam);
225 switch (((LPNMHDR)lParam)->code) {
226 case LVN_GETDISPINFO:
227 OnGetDispInfo((NMLVDISPINFO*)lParam);
231 NMITEMACTIVATE* nmitem = (LPNMITEMACTIVATE)lParam;
234 if (nmitem->hdr.hwndFrom != hWnd) break;
235 /* if (nmitem->hdr.idFrom != IDW_LISTVIEW) break; */
236 /* if (nmitem->hdr.code != ???) break; */
238 switch (nmitem->uKeyFlags) {
239 case LVKF_ALT: /* The ALT key is pressed. */
240 /* properties dialog box ? */
242 case LVKF_CONTROL: /* The CTRL key is pressed. */
243 /* run dialog box for providing parameters... */
245 case LVKF_SHIFT: /* The SHIFT key is pressed. */
249 info.pt.x = nmitem->ptAction.x;
250 info.pt.y = nmitem->ptAction.y;
251 if (ListView_HitTest(hWnd, &info) != -1) {
253 item.mask = LVIF_PARAM;
254 item.iItem = info.iItem;
255 if (ListView_GetItem(hWnd, &item)) {
265 NM_LISTVIEW* pNm = (NM_LISTVIEW*)lParam;
266 lvH.pt.x = pNm->ptAction.x;
267 lvH.pt.y = pNm->ptAction.y;
268 idx = ListView_HitTest(hWnd, &lvH);
272 ListViewPopUpMenu(hWnd, pt);
279 return CallWindowProc(g_orgListWndProc, hWnd, message, wParam, lParam);
283 if (wParam == VK_TAB) {
284 /*TODO: SetFocus(Globals.hDriveBar) */
285 /*SetFocus(child->nFocusPanel? child->left.hWnd: child->right.hWnd); */
289 return CallWindowProc(g_orgListWndProc, hWnd, message, wParam, lParam);
296 HWND CreateListView(HWND hwndParent, int id)
301 /* Get the dimensions of the parent window's client area, and create the list view control. */
302 GetClientRect(hwndParent, &rcClient);
303 hwndLV = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, _T("List View"),
304 WS_VISIBLE | WS_CHILD | LVS_REPORT,
305 0, 0, rcClient.right, rcClient.bottom,
306 hwndParent, (HMENU)id, hInst, NULL);
307 ListView_SetExtendedListViewStyle(hwndLV, LVS_EX_FULLROWSELECT);
309 /* Initialize the image list, and add items to the control. */
311 if (!InitListViewImageLists(hwndLV) ||
312 !InitListViewItems(hwndLV, szName)) {
313 DestroyWindow(hwndLV);
317 CreateListColumns(hwndLV);
318 g_orgListWndProc = SubclassWindow(hwndLV, ListWndProc);
322 BOOL RefreshListView(HWND hwndLV, HKEY hKey, LPTSTR keyPath)
324 if (hwndLV != NULL) {
325 ListView_DeleteAllItems(hwndLV);
330 LONG errCode = RegOpenKeyEx(hKey, keyPath, 0, KEY_READ, &hNewKey);
331 if (errCode == ERROR_SUCCESS) {
332 DWORD max_sub_key_len;
333 DWORD max_val_name_len;
336 ShowWindow(hwndLV, SW_HIDE);
337 /* get size information and resize the buffers if necessary */
338 errCode = RegQueryInfoKey(hNewKey, NULL, NULL, NULL, NULL,
339 &max_sub_key_len, NULL, &val_count, &max_val_name_len, &max_val_size, NULL, NULL);
341 #define BUF_HEAD_SPACE 2 /* TODO: check why this is required with ROS ??? */
343 if (errCode == ERROR_SUCCESS) {
344 TCHAR* ValName = HeapAlloc(GetProcessHeap(), 0, ++max_val_name_len * sizeof(TCHAR) + BUF_HEAD_SPACE);
345 DWORD dwValNameLen = max_val_name_len;
346 BYTE* ValBuf = HeapAlloc(GetProcessHeap(), 0, ++max_val_size/* + BUF_HEAD_SPACE*/);
347 DWORD dwValSize = max_val_size;
350 /* if (RegQueryValueEx(hNewKey, NULL, NULL, &dwValType, ValBuf, &dwValSize) == ERROR_SUCCESS) { */
351 /* AddEntryToList(hwndLV, _T("(Default)"), dwValType, ValBuf, dwValSize); */
353 /* dwValSize = max_val_size; */
354 while (RegEnumValue(hNewKey, dwIndex, ValName, &dwValNameLen, NULL, &dwValType, ValBuf, &dwValSize) == ERROR_SUCCESS) {
355 ValBuf[dwValSize] = 0;
356 AddEntryToList(hwndLV, ValName, dwValType, ValBuf, dwValSize);
357 dwValNameLen = max_val_name_len;
358 dwValSize = max_val_size;
362 HeapFree(GetProcessHeap(), 0, ValBuf);
363 HeapFree(GetProcessHeap(), 0, ValName);
365 /*ListView_SortItemsEx(hwndLV, CompareFunc, hwndLV); */
366 /* SendMessage(hwndLV, LVM_SORTITEMSEX, (WPARAM)CompareFunc, (LPARAM)hwndLV); */
367 ShowWindow(hwndLV, SW_SHOW);
368 RegCloseKey(hNewKey);