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
);
80 wsprintf(buf
, _T("0x%08X (%d)"), *(DWORD
*)ValBuf
, *(DWORD
*)ValBuf
);
81 ListView_SetItemText(hwndLV
, index
, 2, buf
);
83 /* lpsRes = convertHexToDWORDStr(lpbData, dwLen); */
87 LPBYTE pData
= (LPBYTE
)ValBuf
;
88 LPTSTR strBinary
= HeapAlloc(GetProcessHeap(), 0, dwCount
* sizeof(TCHAR
) * 3 + 1);
89 for (i
= 0; i
< dwCount
; i
++)
90 wsprintf( strBinary
+ i
*3, _T("%02X "), pData
[i
] );
91 strBinary
[dwCount
* 3] = 0;
92 ListView_SetItemText(hwndLV
, index
, 2, strBinary
);
93 HeapFree(GetProcessHeap(), 0, strBinary
);
97 /* lpsRes = convertHexToHexCSV(lpbData, dwLen); */
98 ListView_SetItemText(hwndLV
, index
, 2, pszText
);
104 static void CreateListColumns(HWND hWndListView
)
110 /* Create columns. */
111 lvC
.mask
= LVCF_FMT
| LVCF_WIDTH
| LVCF_TEXT
| LVCF_SUBITEM
;
112 lvC
.pszText
= szText
;
114 /* Load the column labels from the resource file. */
115 for (index
= 0; index
< MAX_LIST_COLUMNS
; index
++) {
116 lvC
.iSubItem
= index
;
117 lvC
.cx
= default_column_widths
[index
];
118 lvC
.fmt
= column_alignment
[index
];
119 LoadString(hInst
, IDS_LIST_COLUMN_FIRST
+ index
, szText
, sizeof(szText
)/sizeof(TCHAR
));
120 if (ListView_InsertColumn(hWndListView
, index
, &lvC
) == -1) {
121 /* TODO: handle failure condition... */
127 /* OnGetDispInfo - processes the LVN_GETDISPINFO notification message. */
129 static void OnGetDispInfo(NMLVDISPINFO
* plvdi
)
131 static TCHAR buffer
[200];
133 plvdi
->item
.pszText
= NULL
;
134 plvdi
->item
.cchTextMax
= 0;
136 switch (plvdi
->item
.iSubItem
) {
138 plvdi
->item
.pszText
= _T("(Default)");
141 switch (plvdi
->item
.lParam
) {
143 plvdi
->item
.pszText
= _T("REG_SZ");
146 plvdi
->item
.pszText
= _T("REG_EXPAND_SZ");
149 plvdi
->item
.pszText
= _T("REG_BINARY");
152 plvdi
->item
.pszText
= _T("REG_DWORD");
154 /* case REG_DWORD_LITTLE_ENDIAN: */
155 /* plvdi->item.pszText = _T("REG_DWORD_LITTLE_ENDIAN"); */
157 case REG_DWORD_BIG_ENDIAN
:
158 plvdi
->item
.pszText
= _T("REG_DWORD_BIG_ENDIAN");
161 plvdi
->item
.pszText
= _T("REG_MULTI_SZ");
164 plvdi
->item
.pszText
= _T("REG_LINK");
166 case REG_RESOURCE_LIST
:
167 plvdi
->item
.pszText
= _T("REG_RESOURCE_LIST");
170 plvdi
->item
.pszText
= _T("REG_NONE");
173 wsprintf(buffer
, _T("unknown(%d)"), plvdi
->item
.lParam
);
174 plvdi
->item
.pszText
= buffer
;
179 plvdi
->item
.pszText
= _T("(value not set)");
182 plvdi
->item
.pszText
= _T("");
188 static int CALLBACK
CompareFunc(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
193 ListView_GetItemText((HWND
)lParamSort
, lParam1
, 0, buf1
, sizeof(buf1
));
194 ListView_GetItemText((HWND
)lParamSort
, lParam2
, 0, buf2
, sizeof(buf2
));
195 return _tcscmp(buf1
, buf2
);
199 static void ListViewPopUpMenu(HWND hWnd
, POINT pt
)
202 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
204 switch (LOWORD(wParam
)) {
205 /* case ID_FILE_OPEN: */
213 static LRESULT CALLBACK
ListWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
217 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
)) {
218 return CallWindowProc(g_orgListWndProc
, hWnd
, message
, wParam
, lParam
);
222 switch (((LPNMHDR
)lParam
)->code
) {
223 case LVN_GETDISPINFO
:
224 OnGetDispInfo((NMLVDISPINFO
*)lParam
);
227 NMITEMACTIVATE
* nmitem
= (LPNMITEMACTIVATE
)lParam
;
230 if (nmitem
->hdr
.hwndFrom
!= hWnd
) break;
231 /* if (nmitem->hdr.idFrom != IDW_LISTVIEW) break; */
232 /* if (nmitem->hdr.code != ???) break; */
234 switch (nmitem
->uKeyFlags
) {
235 case LVKF_ALT
: /* The ALT key is pressed. */
236 /* properties dialog box ? */
238 case LVKF_CONTROL
: /* The CTRL key is pressed. */
239 /* run dialog box for providing parameters... */
241 case LVKF_SHIFT
: /* The SHIFT key is pressed. */
245 info
.pt
.x
= nmitem
->ptAction
.x
;
246 info
.pt
.y
= nmitem
->ptAction
.y
;
247 if (ListView_HitTest(hWnd
, &info
) != -1) {
249 item
.mask
= LVIF_PARAM
;
250 item
.iItem
= info
.iItem
;
251 if (ListView_GetItem(hWnd
, &item
)) {}
259 NM_LISTVIEW
* pNm
= (NM_LISTVIEW
*)lParam
;
260 lvH
.pt
.x
= pNm
->ptAction
.x
;
261 lvH
.pt
.y
= pNm
->ptAction
.y
;
262 idx
= ListView_HitTest(hWnd
, &lvH
);
266 ListViewPopUpMenu(hWnd
, pt
);
273 return CallWindowProc(g_orgListWndProc
, hWnd
, message
, wParam
, lParam
);
277 if (wParam
== VK_TAB
) {
278 /*TODO: SetFocus(Globals.hDriveBar) */
279 /*SetFocus(child->nFocusPanel? child->left.hWnd: child->right.hWnd); */
283 return CallWindowProc(g_orgListWndProc
, hWnd
, message
, wParam
, lParam
);
290 HWND
CreateListView(HWND hwndParent
, int id
)
295 /* Get the dimensions of the parent window's client area, and create the list view control. */
296 GetClientRect(hwndParent
, &rcClient
);
297 hwndLV
= CreateWindowEx(WS_EX_CLIENTEDGE
, WC_LISTVIEW
, _T("List View"),
298 WS_VISIBLE
| WS_CHILD
| LVS_REPORT
,
299 0, 0, rcClient
.right
, rcClient
.bottom
,
300 hwndParent
, (HMENU
)id
, hInst
, NULL
);
301 ListView_SetExtendedListViewStyle(hwndLV
, LVS_EX_FULLROWSELECT
);
303 /* Initialize the image list, and add items to the control. */
305 if (!InitListViewImageLists(hwndLV) ||
306 !InitListViewItems(hwndLV, szName)) {
307 DestroyWindow(hwndLV);
311 CreateListColumns(hwndLV
);
312 g_orgListWndProc
= SubclassWindow(hwndLV
, ListWndProc
);
316 BOOL
RefreshListView(HWND hwndLV
, HKEY hKey
, LPTSTR keyPath
)
318 if (hwndLV
!= NULL
) {
319 ListView_DeleteAllItems(hwndLV
);
324 LONG errCode
= RegOpenKeyEx(hKey
, keyPath
, 0, KEY_READ
, &hNewKey
);
325 if (errCode
== ERROR_SUCCESS
) {
326 DWORD max_sub_key_len
;
327 DWORD max_val_name_len
;
330 ShowWindow(hwndLV
, SW_HIDE
);
331 /* get size information and resize the buffers if necessary */
332 errCode
= RegQueryInfoKey(hNewKey
, NULL
, NULL
, NULL
, NULL
,
333 &max_sub_key_len
, NULL
, &val_count
, &max_val_name_len
, &max_val_size
, NULL
, NULL
);
335 #define BUF_HEAD_SPACE 2 /* TODO: check why this is required with ROS ??? */
337 if (errCode
== ERROR_SUCCESS
) {
338 TCHAR
* ValName
= HeapAlloc(GetProcessHeap(), 0, ++max_val_name_len
* sizeof(TCHAR
) + BUF_HEAD_SPACE
);
339 DWORD dwValNameLen
= max_val_name_len
;
340 BYTE
* ValBuf
= HeapAlloc(GetProcessHeap(), 0, ++max_val_size
/* + BUF_HEAD_SPACE*/);
341 DWORD dwValSize
= max_val_size
;
344 /* if (RegQueryValueEx(hNewKey, NULL, NULL, &dwValType, ValBuf, &dwValSize) == ERROR_SUCCESS) { */
345 /* AddEntryToList(hwndLV, _T("(Default)"), dwValType, ValBuf, dwValSize); */
347 /* dwValSize = max_val_size; */
348 while (RegEnumValue(hNewKey
, dwIndex
, ValName
, &dwValNameLen
, NULL
, &dwValType
, ValBuf
, &dwValSize
) == ERROR_SUCCESS
) {
349 ValBuf
[dwValSize
] = 0;
350 AddEntryToList(hwndLV
, ValName
, dwValType
, ValBuf
, dwValSize
);
351 dwValNameLen
= max_val_name_len
;
352 dwValSize
= max_val_size
;
356 HeapFree(GetProcessHeap(), 0, ValBuf
);
357 HeapFree(GetProcessHeap(), 0, ValName
);
359 /*ListView_SortItemsEx(hwndLV, CompareFunc, hwndLV); */
360 /* SendMessage(hwndLV, LVM_SORTITEMSEX, (WPARAM)CompareFunc, (LPARAM)hwndLV); */
361 ShowWindow(hwndLV
, SW_SHOW
);
362 RegCloseKey(hNewKey
);