3e3bec8434fa301a10737c1a5a2d6aea84e1c7ad
6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
42 ////////////////////////////////////////////////////////////////////////////////
43 // Global and Local Variables:
46 static WNDPROC g_orgListWndProc
;
48 #define MAX_LIST_COLUMNS (IDS_LIST_COLUMN_LAST - IDS_LIST_COLUMN_FIRST + 1)
49 static int default_column_widths
[MAX_LIST_COLUMNS
] = { 200, 175, 400 };
50 static int column_alignment
[MAX_LIST_COLUMNS
] = { LVCFMT_LEFT
, LVCFMT_LEFT
, LVCFMT_LEFT
};
53 ////////////////////////////////////////////////////////////////////////////////
54 // Local module support methods
57 static void AddEntryToList(HWND hwndLV
, LPTSTR Name
, DWORD dwValType
, void* ValBuf
, DWORD dwCount
)
61 item
.mask
= LVIF_TEXT
| LVIF_PARAM
;
67 item
.cchTextMax
= _tcslen(item
.pszText
);
70 item
.lParam
= (LPARAM
)dwValType
;
71 // item.lParam = (LPARAM)ValBuf;
72 #if (_WIN32_IE >= 0x0300)
75 ListView_InsertItem(hwndLV
, &item
);
78 static void CreateListColumns(HWND hWndListView
)
85 lvC
.mask
= LVCF_FMT
| LVCF_WIDTH
| LVCF_TEXT
| LVCF_SUBITEM
;
88 // Load the column labels from the resource file.
89 for (index
= 0; index
< MAX_LIST_COLUMNS
; index
++) {
91 lvC
.cx
= default_column_widths
[index
];
92 lvC
.fmt
= column_alignment
[index
];
93 LoadString(hInst
, IDS_LIST_COLUMN_FIRST
+ index
, szText
, sizeof(szText
));
94 if (ListView_InsertColumn(hWndListView
, index
, &lvC
) == -1) {
95 // TODO: handle failure condition...
101 // OnGetDispInfo - processes the LVN_GETDISPINFO notification message.
103 static void OnGetDispInfo(NMLVDISPINFO
* plvdi
)
105 static TCHAR buffer
[200];
107 plvdi
->item
.pszText
= NULL
;
108 plvdi
->item
.cchTextMax
= 0;
110 switch (plvdi
->item
.iSubItem
) {
112 plvdi
->item
.pszText
= _T("(Default)");
115 switch (plvdi
->item
.lParam
) {
117 plvdi
->item
.pszText
= _T("REG_SZ");
120 plvdi
->item
.pszText
= _T("REG_EXPAND_SZ");
123 plvdi
->item
.pszText
= _T("REG_BINARY");
126 plvdi
->item
.pszText
= _T("REG_DWORD");
128 // case REG_DWORD_LITTLE_ENDIAN:
129 // plvdi->item.pszText = _T("REG_DWORD_LITTLE_ENDIAN");
131 case REG_DWORD_BIG_ENDIAN
:
132 plvdi
->item
.pszText
= _T("REG_DWORD_BIG_ENDIAN");
135 plvdi
->item
.pszText
= _T("REG_MULTI_SZ");
138 plvdi
->item
.pszText
= _T("REG_LINK");
140 case REG_RESOURCE_LIST
:
141 plvdi
->item
.pszText
= _T("REG_RESOURCE_LIST");
144 plvdi
->item
.pszText
= _T("REG_NONE");
147 wsprintf(buffer
, _T("unknown(%d)"), plvdi
->item
.lParam
);
148 plvdi
->item
.pszText
= buffer
;
153 plvdi
->item
.pszText
= _T("(value not set)");
156 plvdi
->item
.pszText
= _T("");
161 static int CALLBACK
CompareFunc(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
166 ListView_GetItemText((HWND
)lParamSort
, lParam1
, 0, buf1
, sizeof(buf1
));
167 ListView_GetItemText((HWND
)lParamSort
, lParam2
, 0, buf2
, sizeof(buf2
));
168 return _tcscmp(buf1
, buf2
);
171 static void ListViewPopUpMenu(HWND hWnd
, POINT pt
)
175 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
177 switch (LOWORD(wParam
)) {
178 // case ID_FILE_OPEN:
186 static LRESULT CALLBACK
ListWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
190 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
)) {
191 return CallWindowProc(g_orgListWndProc
, hWnd
, message
, wParam
, lParam
);
195 switch (((LPNMHDR
)lParam
)->code
) {
196 case LVN_GETDISPINFO
:
197 OnGetDispInfo((NMLVDISPINFO
*)lParam
);
201 NMITEMACTIVATE
* nmitem
= (LPNMITEMACTIVATE
)lParam
;
204 if (nmitem
->hdr
.hwndFrom
!= hWnd
) break;
205 // if (nmitem->hdr.idFrom != IDW_LISTVIEW) break;
206 // if (nmitem->hdr.code != ???) break;
208 switch (nmitem
->uKeyFlags
) {
209 case LVKF_ALT
: // The ALT key is pressed.
210 // properties dialog box ?
212 case LVKF_CONTROL
: // The CTRL key is pressed.
213 // run dialog box for providing parameters...
215 case LVKF_SHIFT
: // The SHIFT key is pressed.
219 info
.pt
.x
= nmitem
->ptAction
.x
;
220 info
.pt
.y
= nmitem
->ptAction
.y
;
221 if (ListView_HitTest(hWnd
, &info
) != -1) {
223 item
.mask
= LVIF_PARAM
;
224 item
.iItem
= info
.iItem
;
225 if (ListView_GetItem(hWnd
, &item
)) {
235 NM_LISTVIEW
* pNm
= (NM_LISTVIEW
*)lParam
;
236 lvH
.pt
.x
= pNm
->ptAction
.x
;
237 lvH
.pt
.y
= pNm
->ptAction
.y
;
238 idx
= ListView_HitTest(hWnd
, &lvH
);
242 ListViewPopUpMenu(hWnd
, pt
);
249 return CallWindowProc(g_orgListWndProc
, hWnd
, message
, wParam
, lParam
);
253 if (wParam
== VK_TAB
) {
254 //TODO: SetFocus(Globals.hDriveBar)
255 //SetFocus(child->nFocusPanel? child->left.hWnd: child->right.hWnd);
259 return CallWindowProc(g_orgListWndProc
, hWnd
, message
, wParam
, lParam
);
266 HWND
CreateListView(HWND hwndParent
)
271 // Get the dimensions of the parent window's client area, and create the list view control.
272 GetClientRect(hwndParent
, &rcClient
);
273 hwndLV
= CreateWindowEx(0, WC_LISTVIEW
, _T("List View"),
274 WS_VISIBLE
| WS_CHILD
| WS_EX_CLIENTEDGE
| LVS_REPORT
,
275 0, 0, rcClient
.right
, rcClient
.bottom
,
276 hwndParent
, (HMENU
)LIST_WINDOW
, hInst
, NULL
);
277 ListView_SetExtendedListViewStyle(hwndLV
, LVS_EX_FULLROWSELECT
);
279 // Initialize the image list, and add items to the control.
281 if (!InitListViewImageLists(hwndLV) ||
282 !InitListViewItems(hwndLV, szName)) {
283 DestroyWindow(hwndLV);
287 CreateListColumns(hwndLV
);
288 g_orgListWndProc
= SubclassWindow(hwndLV
, ListWndProc
);
292 BOOL
RefreshListView(HWND hwndLV
, HKEY hKey
, LPTSTR keyPath
)
294 if (hwndLV
!= NULL
) {
295 ListView_DeleteAllItems(hwndLV
);
303 DWORD max_sub_key_len
;
304 DWORD max_val_name_len
;
307 errCode
= RegQueryInfoKey(hKey
, NULL
, NULL
, NULL
, NULL
,
308 &max_sub_key_len
, NULL
, &val_count
, &max_val_name_len
, &max_val_size
, NULL
, NULL
);
309 if (errCode
== ERROR_SUCCESS
) {
310 TCHAR
* ValName
= malloc(++max_val_name_len
* sizeof(TCHAR
));
311 DWORD dwValNameLen
= max_val_name_len
;
312 BYTE
* ValBuf
= malloc(++max_val_size
);
313 DWORD dwValSize
= max_val_size
;
316 while (RegEnumValue(hKey
, dwIndex
, ValName
, &dwValNameLen
, NULL
, &dwValType
, ValBuf
, &dwValSize
) == ERROR_SUCCESS
) {
317 AddEntryToList(hwndLV
, ValName
, dwValType
, ValBuf
, dwIndex
);
318 dwValNameLen
= max_val_name_len
;
319 dwValSize
= max_val_size
;
328 errCode
= RegOpenKeyEx(hKey
, keyPath
, 0, KEY_READ
, &hNewKey
);
329 if (errCode
== ERROR_SUCCESS
) {
330 DWORD max_sub_key_len
;
331 DWORD max_val_name_len
;
334 ShowWindow(hwndLV
, SW_HIDE
);
335 /* get size information and resize the buffers if necessary */
336 errCode
= RegQueryInfoKey(hNewKey
, NULL
, NULL
, NULL
, NULL
,
337 &max_sub_key_len
, NULL
, &val_count
, &max_val_name_len
, &max_val_size
, NULL
, NULL
);
338 if (errCode
== ERROR_SUCCESS
) {
339 TCHAR
* ValName
= malloc(++max_val_name_len
* sizeof(TCHAR
));
340 DWORD dwValNameLen
= max_val_name_len
;
341 BYTE
* ValBuf
= malloc(++max_val_size
);
342 DWORD dwValSize
= max_val_size
;
345 while (RegEnumValue(hNewKey
, dwIndex
, ValName
, &dwValNameLen
, NULL
, &dwValType
, ValBuf
, &dwValSize
) == ERROR_SUCCESS
) {
346 //while (RegEnumValue(hNewKey, dwIndex, ValName, &dwValNameLen, NULL, &dwValType, NULL, NULL) == ERROR_SUCCESS) {
347 AddEntryToList(hwndLV
, ValName
, dwValType
, ValBuf
, dwIndex
);
348 dwValNameLen
= max_val_name_len
;
349 dwValSize
= max_val_size
;
356 //ListView_SortItemsEx(hwndLV, CompareFunc, hwndLV);
357 // SendMessage(hwndLV, LVM_SORTITEMSEX, (WPARAM)CompareFunc, (LPARAM)hwndLV);
358 ShowWindow(hwndLV
, SW_SHOW
);
359 RegCloseKey(hNewKey
);