Synchronize with trunk revision 59636 (just before Alex's CreateProcess revamp).
[reactos.git] / base / applications / regedit / listview.c
1 /*
2 * Regedit listviews
3 *
4 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
5 *
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.
10 *
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.
15 *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "regedit.h"
22
23
24 #define CX_ICON 16
25 #define CY_ICON 16
26 #define NUM_ICONS 2
27
28 int Image_String = 0;
29 int Image_Bin = 0;
30 INT iListViewSelect = -1;
31
32 typedef struct tagLINE_INFO
33 {
34 DWORD dwValType;
35 LPWSTR name;
36 void* val;
37 size_t val_len;
38 } LINE_INFO, *PLINE_INFO;
39
40 typedef struct tagSORT_INFO
41 {
42 INT iSortingColumn;
43 BOOL bSortAscending;
44 } SORT_INFO, *PSORT_INFO;
45
46 /*******************************************************************************
47 * Global and Local Variables:
48 */
49
50 static INT g_iSortedColumn = 0;
51
52 #define MAX_LIST_COLUMNS (IDS_LIST_COLUMN_LAST - IDS_LIST_COLUMN_FIRST + 1)
53 static const int default_column_widths[MAX_LIST_COLUMNS] = { 200, 175, 400 };
54 static const int column_alignment[MAX_LIST_COLUMNS] = { LVCFMT_LEFT, LVCFMT_LEFT, LVCFMT_LEFT };
55
56 LPCWSTR GetValueName(HWND hwndLV, int iStartAt)
57 {
58 int item;
59 LVITEMW LVItem;
60 PLINE_INFO lineinfo;
61
62 /*
63 if a new item is inserted, then no allocation,
64 otherwise the heap block will be lost!
65 */
66 item = ListView_GetNextItem(hwndLV, iStartAt, LVNI_SELECTED);
67 if (item == -1) return NULL;
68
69 /*
70 Should be always TRUE anyways
71 */
72 LVItem.iItem = item;
73 LVItem.iSubItem = 0;
74 LVItem.mask = LVIF_PARAM;
75 if (ListView_GetItem(hwndLV, &LVItem) == FALSE)
76 return NULL;
77
78 lineinfo = (PLINE_INFO)LVItem.lParam;
79 if (lineinfo == NULL)
80 return NULL;
81
82 return lineinfo->name;
83 }
84
85 VOID SetValueName(HWND hwndLV, LPCWSTR pszValueName)
86 {
87 INT i, c;
88 LVFINDINFOW fi;
89
90 c = ListView_GetItemCount(hwndLV);
91 for(i = 0; i < c; i++)
92 {
93 ListView_SetItemState(hwndLV, i, 0, LVIS_FOCUSED | LVIS_SELECTED);
94 }
95 if (pszValueName == NULL)
96 i = 0;
97 else
98 {
99 fi.flags = LVFI_STRING;
100 fi.psz = pszValueName;
101 i = ListView_FindItem(hwndLV, -1, &fi);
102 }
103 ListView_SetItemState(hwndLV, i, LVIS_FOCUSED | LVIS_SELECTED,
104 LVIS_FOCUSED | LVIS_SELECTED);
105 iListViewSelect = i;
106 }
107
108 BOOL IsDefaultValue(HWND hwndLV, int i)
109 {
110 PLINE_INFO lineinfo;
111 LVITEMW Item;
112
113 Item.mask = LVIF_PARAM;
114 Item.iItem = i;
115 if(ListView_GetItem(hwndLV, &Item))
116 {
117 lineinfo = (PLINE_INFO)Item.lParam;
118 return lineinfo && (!lineinfo->name || !wcscmp(lineinfo->name, L""));
119 }
120 return FALSE;
121 }
122
123 /*******************************************************************************
124 * Local module support methods
125 */
126 static void AddEntryToList(HWND hwndLV, LPWSTR Name, DWORD dwValType, void* ValBuf, DWORD dwCount, int Position, BOOL ValExists)
127 {
128 PLINE_INFO linfo;
129 LVITEMW item;
130 int index;
131
132 linfo = (PLINE_INFO)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LINE_INFO) + dwCount);
133 linfo->dwValType = dwValType;
134 linfo->val_len = dwCount;
135 if (dwCount > 0)
136 {
137 memcpy(&linfo[1], ValBuf, dwCount);
138 linfo->val = &linfo[1];
139 }
140 linfo->name = _wcsdup(Name);
141
142 item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
143 item.iItem = (Position == -1 ? 0: Position);
144 item.iSubItem = 0;
145 item.state = 0;
146 item.stateMask = 0;
147 item.pszText = Name;
148 item.cchTextMax = (int)wcslen(item.pszText);
149 if (item.cchTextMax == 0)
150 item.pszText = LPSTR_TEXTCALLBACK;
151 item.iImage = 0;
152 item.lParam = (LPARAM)linfo;
153 switch(dwValType)
154 {
155 case REG_SZ:
156 case REG_EXPAND_SZ:
157 case REG_MULTI_SZ:
158 item.iImage = Image_String;
159 break;
160 default:
161 item.iImage = Image_Bin;
162 break;
163 }
164
165 /* item.lParam = (LPARAM)ValBuf; */
166 #if (_WIN32_IE >= 0x0300)
167 item.iIndent = 0;
168 #endif
169
170 index = ListView_InsertItem(hwndLV, &item);
171 if (index != -1)
172 {
173 switch (dwValType)
174 {
175 case REG_SZ:
176 case REG_EXPAND_SZ:
177 if(dwCount > 0)
178 {
179 ListView_SetItemText(hwndLV, index, 2, ValBuf);
180 }
181 else if(!ValExists)
182 {
183 WCHAR buffer[255];
184 /* load (value not set) string */
185 LoadStringW(hInst, IDS_VALUE_NOT_SET, buffer, COUNT_OF(buffer));
186 ListView_SetItemText(hwndLV, index, 2, buffer);
187 }
188 break;
189 case REG_MULTI_SZ:
190 {
191 LPWSTR src, str;
192 if(dwCount >= 2)
193 {
194 src = (LPWSTR)ValBuf;
195 str = HeapAlloc(GetProcessHeap(), 0, dwCount + sizeof(WCHAR));
196 if(str != NULL)
197 {
198 *str = L'\0';
199 /* concatenate all srings */
200 while(*src != L'\0')
201 {
202 wcscat(str, src);
203 wcscat(str, L" ");
204 src += wcslen(src) + 1;
205 }
206 ListView_SetItemText(hwndLV, index, 2, str);
207 HeapFree(GetProcessHeap(), 0, str);
208 }
209 else
210 ListView_SetItemText(hwndLV, index, 2, L"");
211 }
212 else
213 ListView_SetItemText(hwndLV, index, 2, L"");
214 }
215 break;
216 case REG_DWORD:
217 {
218 WCHAR buf[200];
219 if(dwCount == sizeof(DWORD))
220 {
221 wsprintf(buf, L"0x%08x (%u)", *(DWORD*)ValBuf, *(DWORD*)ValBuf);
222 }
223 else
224 {
225 LoadStringW(hInst, IDS_INVALID_DWORD, buf, COUNT_OF(buf));
226 }
227 ListView_SetItemText(hwndLV, index, 2, buf);
228 }
229 /* lpsRes = convertHexToDWORDStr(lpbData, dwLen); */
230 break;
231 default:
232 {
233 unsigned int i;
234 LPBYTE pData = (LPBYTE)ValBuf;
235 LPWSTR strBinary;
236 if(dwCount > 0)
237 {
238 strBinary = HeapAlloc(GetProcessHeap(), 0, (dwCount * sizeof(WCHAR) * 3) + sizeof(WCHAR));
239 for (i = 0; i < dwCount; i++)
240 {
241 wsprintf( strBinary + i*3, L"%02X ", pData[i] );
242 }
243 strBinary[dwCount * 3] = 0;
244 ListView_SetItemText(hwndLV, index, 2, strBinary);
245 HeapFree(GetProcessHeap(), 0, strBinary);
246 }
247 else
248 {
249 WCHAR szText[128];
250 LoadStringW(hInst, IDS_BINARY_EMPTY, szText, COUNT_OF(szText));
251 ListView_SetItemText(hwndLV, index, 2, szText);
252 }
253 }
254 break;
255 }
256 }
257 }
258
259 static BOOL CreateListColumns(HWND hWndListView)
260 {
261 WCHAR szText[50];
262 int index;
263 LVCOLUMN lvC;
264
265 /* Create columns. */
266 lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
267 lvC.pszText = szText;
268
269 /* Load the column labels from the resource file. */
270 for (index = 0; index < MAX_LIST_COLUMNS; index++)
271 {
272 lvC.iSubItem = index;
273 lvC.cx = default_column_widths[index];
274 lvC.fmt = column_alignment[index];
275 LoadStringW(hInst, IDS_LIST_COLUMN_FIRST + index, szText, COUNT_OF(szText));
276 if (ListView_InsertColumn(hWndListView, index, &lvC) == -1) return FALSE;
277 }
278 return TRUE;
279 }
280
281 static BOOL InitListViewImageLists(HWND hwndLV)
282 {
283 HIMAGELIST himl; /* handle to image list */
284 HICON hico; /* handle to icon */
285
286 /* Create the image list. */
287 if ((himl = ImageList_Create(CX_ICON, CY_ICON,
288 ILC_MASK, 0, NUM_ICONS)) == NULL)
289 {
290 return FALSE;
291 }
292
293 hico = LoadIconW(hInst, MAKEINTRESOURCEW(IDI_BIN));
294 Image_Bin = ImageList_AddIcon(himl, hico);
295
296 hico = LoadIconW(hInst, MAKEINTRESOURCEW(IDI_STRING));
297 Image_String = ImageList_AddIcon(himl, hico);
298
299 /* Fail if not all of the images were added. */
300 if (ImageList_GetImageCount(himl) < NUM_ICONS)
301 {
302 return FALSE;
303 }
304
305 /* Associate the image list with the tree view control. */
306 (void)ListView_SetImageList(hwndLV, himl, LVSIL_SMALL);
307
308 return TRUE;
309 }
310
311 /* OnGetDispInfo - processes the LVN_GETDISPINFO notification message. */
312
313 static void OnGetDispInfo(NMLVDISPINFO* plvdi)
314 {
315 static WCHAR buffer[200];
316
317 plvdi->item.pszText = NULL;
318 plvdi->item.cchTextMax = 0;
319
320 switch (plvdi->item.iSubItem)
321 {
322 case 0:
323 LoadStringW(hInst, IDS_DEFAULT_VALUE_NAME, buffer, COUNT_OF(buffer));
324 plvdi->item.pszText = buffer;
325 break;
326 case 1:
327 switch (((LINE_INFO*)plvdi->item.lParam)->dwValType)
328 {
329 case REG_NONE:
330 plvdi->item.pszText = L"REG_NONE";
331 break;
332 case REG_SZ:
333 plvdi->item.pszText = L"REG_SZ";
334 break;
335 case REG_EXPAND_SZ:
336 plvdi->item.pszText = L"REG_EXPAND_SZ";
337 break;
338 case REG_BINARY:
339 plvdi->item.pszText = L"REG_BINARY";
340 break;
341 case REG_DWORD: /* REG_DWORD_LITTLE_ENDIAN */
342 plvdi->item.pszText = L"REG_DWORD";
343 break;
344 case REG_DWORD_BIG_ENDIAN:
345 plvdi->item.pszText = L"REG_DWORD_BIG_ENDIAN";
346 break;
347 case REG_LINK:
348 plvdi->item.pszText = L"REG_LINK";
349 break;
350 case REG_MULTI_SZ:
351 plvdi->item.pszText = L"REG_MULTI_SZ";
352 break;
353 case REG_RESOURCE_LIST:
354 plvdi->item.pszText = L"REG_RESOURCE_LIST";
355 break;
356 case REG_FULL_RESOURCE_DESCRIPTOR:
357 plvdi->item.pszText = L"REG_FULL_RESOURCE_DESCRIPTOR";
358 break;
359 case REG_RESOURCE_REQUIREMENTS_LIST:
360 plvdi->item.pszText = L"REG_RESOURCE_REQUIREMENTS_LIST";
361 break;
362 case REG_QWORD: /* REG_QWORD_LITTLE_ENDIAN */
363 plvdi->item.pszText = L"REG_QWORD";
364 break;
365 default:
366 {
367 WCHAR buf2[200];
368 LoadStringW(hInst, IDS_UNKNOWN_TYPE, buf2, COUNT_OF(buf2));
369 wsprintf(buffer, buf2, ((LINE_INFO*)plvdi->item.lParam)->dwValType);
370 plvdi->item.pszText = buffer;
371 break;
372 }
373 }
374 break;
375 case 3:
376 plvdi->item.pszText = L"";
377 break;
378 }
379 }
380
381 static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
382 {
383 PSORT_INFO pSortInfo = (PSORT_INFO)lParamSort;
384 LINE_INFO *l, *r;
385 DWORD dw1, dw2;
386 DWORDLONG qw1, qw2;
387
388 l = (LINE_INFO*)lParam1;
389 r = (LINE_INFO*)lParam2;
390
391 if (pSortInfo->iSortingColumn == 1 && l->dwValType != r->dwValType)
392 {
393 /* Sort by type */
394 if (pSortInfo->bSortAscending)
395 return ((int)l->dwValType - (int)r->dwValType);
396 else
397 return ((int)r->dwValType - (int)l->dwValType);
398 }
399 if (pSortInfo->iSortingColumn == 2)
400 {
401 /* Sort by value */
402 if (l->dwValType != r->dwValType)
403 {
404 if (pSortInfo->bSortAscending)
405 return ((int)l->dwValType - (int)r->dwValType);
406 else
407 return ((int)r->dwValType - (int)l->dwValType);
408 }
409
410 if (l->val == NULL && r->val == NULL)
411 return 0;
412
413 if (pSortInfo->bSortAscending)
414 {
415 if (l->val == NULL)
416 return -1;
417 if (r->val == NULL)
418 return 1;
419 }
420 else
421 {
422 if (l->val == NULL)
423 return 1;
424 if (r->val == NULL)
425 return -1;
426 }
427
428 switch(l->dwValType)
429 {
430 case REG_DWORD:
431 {
432 dw1 = *(DWORD*)l->val;
433 dw2 = *(DWORD*)r->val;
434 if (pSortInfo->bSortAscending)
435 // return (dw1 > dw2 ? 1 : -1);
436 return ((int)dw1 - (int)dw2);
437 else
438 // return (dw1 > dw2 ? -1 : 1);
439 return ((int)dw2 - (int)dw1);
440 }
441
442 case REG_QWORD: /* REG_QWORD_LITTLE_ENDIAN */
443 {
444 qw1 = *(DWORDLONG*)l->val;
445 qw2 = *(DWORDLONG*)r->val;
446 if (pSortInfo->bSortAscending)
447 // return (qw1 > qw2 ? 1 : -1);
448 return ((int)qw1 - (int)qw2);
449 else
450 // return (qw1 > qw2 ? -1 : 1);
451 return ((int)qw2 - (int)qw1);
452 }
453
454 default:
455 {
456 INT nCompare = 0;
457
458 if (pSortInfo->bSortAscending)
459 {
460 nCompare = memcmp(l->val, r->val, min(l->val_len, r->val_len));
461 if (nCompare == 0)
462 nCompare = l->val_len - r->val_len;
463 }
464 else
465 {
466 nCompare = memcmp(r->val, l->val, min(r->val_len, l->val_len));
467 if (nCompare == 0)
468 nCompare = r->val_len - l->val_len;
469 }
470
471 return nCompare;
472 }
473 }
474 }
475
476 /* Sort by name */
477 return (pSortInfo->bSortAscending ? StrCmpLogicalW(l->name, r->name) : StrCmpLogicalW(r->name, l->name));
478 }
479
480 static BOOL ListView_Sort(HWND hListView, int iSortingColumn, int iSortedColumn)
481 {
482 if ( (GetWindowLongPtr(hListView, GWL_STYLE) & ~LVS_NOSORTHEADER) &&
483 (iSortingColumn >= 0) )
484 {
485 BOOL bSortAscending;
486 SORT_INFO SortInfo;
487
488 HWND hHeader = ListView_GetHeader(hListView);
489 HDITEM hColumn = {0};
490
491 /* If we are sorting according to another column, uninitialize the old one */
492 if ( (iSortedColumn >= 0) && (iSortingColumn != iSortedColumn) )
493 {
494 hColumn.mask = HDI_FORMAT;
495 Header_GetItem(hHeader, iSortedColumn, &hColumn);
496 hColumn.fmt &= ~(HDF_SORTUP | HDF_SORTDOWN);
497 Header_SetItem(hHeader, iSortedColumn, &hColumn);
498 }
499
500 /* Get the sorting state of the new column */
501 hColumn.mask = HDI_FORMAT;
502 Header_GetItem(hHeader, iSortingColumn, &hColumn);
503
504 /*
505 * Check whether we are sorting the list because the user clicked
506 * on a column, or because we are refreshing the list:
507 *
508 * iSortedColumn >= 0 - User clicked on a column; holds the
509 * old sorting column index.
510 * iSortedColumn < 0 - List being refreshed.
511 */
512 if (iSortedColumn >= 0)
513 {
514 /* Invert the sorting direction */
515 bSortAscending = ((hColumn.fmt & HDF_SORTUP) == 0);
516 }
517 else
518 {
519 /*
520 * If the sorting state of the column is uninitialized,
521 * initialize it by default to ascending sorting.
522 */
523 if ((hColumn.fmt & (HDF_SORTUP | HDF_SORTDOWN)) == 0)
524 hColumn.fmt |= HDF_SORTUP;
525
526 /* Keep the same sorting direction */
527 bSortAscending = ((hColumn.fmt & HDF_SORTUP) != 0);
528 }
529
530 /* Set the new column sorting state */
531 hColumn.fmt &= ~(bSortAscending ? HDF_SORTDOWN : HDF_SORTUP );
532 hColumn.fmt |= (bSortAscending ? HDF_SORTUP : HDF_SORTDOWN);
533 Header_SetItem(hHeader, iSortingColumn, &hColumn);
534
535 /* Sort the list */
536 SortInfo.iSortingColumn = iSortingColumn;
537 SortInfo.bSortAscending = bSortAscending;
538 return ListView_SortItems(hListView, CompareFunc, (LPARAM)&SortInfo);
539 }
540 else
541 return TRUE;
542 }
543
544 BOOL ListWndNotifyProc(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL *Result)
545 {
546 NMLVDISPINFO* Info;
547 int iSortingColumn;
548 UNREFERENCED_PARAMETER(wParam);
549 *Result = TRUE;
550 switch (((LPNMHDR)lParam)->code)
551 {
552 case LVN_GETDISPINFO:
553 OnGetDispInfo((NMLVDISPINFO*)lParam);
554 return TRUE;
555 case LVN_COLUMNCLICK:
556 iSortingColumn = ((LPNMLISTVIEW)lParam)->iSubItem;
557 (void)ListView_Sort(hWnd, iSortingColumn, g_iSortedColumn);
558 g_iSortedColumn = iSortingColumn;
559 return TRUE;
560 case NM_DBLCLK:
561 case NM_RETURN:
562 {
563 SendMessageW(hFrameWnd, WM_COMMAND, MAKEWPARAM(ID_EDIT_MODIFY, 0), 0);
564 }
565 return TRUE;
566 case NM_SETFOCUS:
567 g_pChildWnd->nFocusPanel = 0;
568 break;
569 case LVN_BEGINLABELEDIT:
570 Info = (NMLVDISPINFO*)lParam;
571 if(Info)
572 {
573 PLINE_INFO lineinfo = (PLINE_INFO)Info->item.lParam;
574 if(!lineinfo->name || !wcscmp(lineinfo->name, L""))
575 {
576 *Result = TRUE;
577 }
578 else
579 {
580 *Result = FALSE;
581 }
582 }
583 else
584 *Result = TRUE;
585 return TRUE;
586 case LVN_ENDLABELEDIT:
587 Info = (NMLVDISPINFO*)lParam;
588 if(Info && Info->item.pszText)
589 {
590 PLINE_INFO lineinfo = (PLINE_INFO)Info->item.lParam;
591 if(!lineinfo->name || !wcscmp(lineinfo->name, L""))
592 {
593 *Result = FALSE;
594 }
595 else
596 {
597 if(wcslen(Info->item.pszText) == 0)
598 {
599 WCHAR msg[128], caption[128];
600
601 LoadStringW(hInst, IDS_ERR_RENVAL_TOEMPTY, msg, COUNT_OF(msg));
602 LoadStringW(hInst, IDS_ERR_RENVAL_CAPTION, caption, COUNT_OF(caption));
603 MessageBoxW(0, msg, caption, 0);
604 *Result = TRUE;
605 }
606 else
607 {
608 HKEY hKeyRoot;
609 LPCWSTR keyPath;
610 LONG lResult;
611
612 keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
613 lResult = RenameValue(hKeyRoot, keyPath, Info->item.pszText, lineinfo->name);
614 lineinfo->name = realloc(lineinfo->name, (wcslen(Info->item.pszText)+1)*sizeof(WCHAR));
615 if (lineinfo->name != NULL)
616 wcscpy(lineinfo->name, Info->item.pszText);
617
618 *Result = TRUE;
619 return (lResult == ERROR_SUCCESS);
620 }
621 }
622 }
623 else
624 *Result = TRUE;
625
626 return TRUE;
627 }
628 return FALSE;
629 }
630
631 HWND CreateListView(HWND hwndParent, HMENU id)
632 {
633 RECT rcClient;
634 HWND hwndLV;
635
636 /* Get the dimensions of the parent window's client area, and create the list view control. */
637 GetClientRect(hwndParent, &rcClient);
638 hwndLV = CreateWindowExW(WS_EX_CLIENTEDGE, WC_LISTVIEW, L"List View",
639 WS_VISIBLE | WS_CHILD | WS_TABSTOP | LVS_REPORT | LVS_EDITLABELS | LVS_SHOWSELALWAYS,
640 0, 0, rcClient.right, rcClient.bottom,
641 hwndParent, id, hInst, NULL);
642 if (!hwndLV) return NULL;
643
644 /* Initialize the image list, and add items to the control. */
645 if (!CreateListColumns(hwndLV)) goto fail;
646 if (!InitListViewImageLists(hwndLV)) goto fail;
647
648 return hwndLV;
649 fail:
650 DestroyWindow(hwndLV);
651 return NULL;
652 }
653
654 void DestroyListView(HWND hwndLV)
655 {
656 INT count, i;
657 LVITEMW item;
658
659 count = ListView_GetItemCount(hwndLV);
660 for (i = 0; i < count; i++)
661 {
662 item.mask = LVIF_PARAM;
663 item.iItem = i;
664 (void)ListView_GetItem(hwndLV, &item);
665 free(((LINE_INFO*)item.lParam)->name);
666 HeapFree(GetProcessHeap(), 0, (void*)item.lParam);
667 }
668
669 }
670
671 BOOL RefreshListView(HWND hwndLV, HKEY hKey, LPCWSTR keyPath)
672 {
673 DWORD max_sub_key_len;
674 DWORD max_val_name_len;
675 DWORD max_val_size;
676 DWORD val_count;
677 HKEY hNewKey;
678 LONG errCode;
679 INT i, c;
680 BOOL AddedDefault = FALSE;
681
682 if (!hwndLV) return FALSE;
683
684 (void)ListView_EditLabel(hwndLV, -1);
685
686 SendMessageW(hwndLV, WM_SETREDRAW, FALSE, 0);
687 DestroyListView(hwndLV);
688
689 (void)ListView_DeleteAllItems(hwndLV);
690
691 if(!hKey) return FALSE;
692
693 errCode = RegOpenKeyExW(hKey, keyPath, 0, KEY_READ, &hNewKey);
694 if (errCode != ERROR_SUCCESS) return FALSE;
695
696 /* get size information and resize the buffers if necessary */
697 errCode = RegQueryInfoKeyW(hNewKey, NULL, NULL, NULL, NULL, &max_sub_key_len, NULL,
698 &val_count, &max_val_name_len, &max_val_size, NULL, NULL);
699
700 if (errCode == ERROR_SUCCESS)
701 {
702 WCHAR* ValName = HeapAlloc(GetProcessHeap(), 0, ++max_val_name_len * sizeof(WCHAR));
703 DWORD dwValNameLen = max_val_name_len;
704 BYTE* ValBuf = HeapAlloc(GetProcessHeap(), 0, max_val_size + sizeof(WCHAR));
705 DWORD dwValSize = max_val_size;
706 DWORD dwIndex = 0L;
707 DWORD dwValType;
708 /* if (RegQueryValueExW(hNewKey, NULL, NULL, &dwValType, ValBuf, &dwValSize) == ERROR_SUCCESS) { */
709 /* AddEntryToList(hwndLV, L"(Default)", dwValType, ValBuf, dwValSize); */
710 /* } */
711 /* dwValSize = max_val_size; */
712 while (RegEnumValueW(hNewKey, dwIndex, ValName, &dwValNameLen, NULL, &dwValType, ValBuf, &dwValSize) == ERROR_SUCCESS)
713 {
714 /* Add a terminating 0 character. Usually this is only necessary for strings. */
715 ValBuf[dwValSize] = ValBuf[dwValSize + 1] = 0;
716
717 AddEntryToList(hwndLV, ValName, dwValType, ValBuf, dwValSize, -1, TRUE);
718 dwValNameLen = max_val_name_len;
719 dwValSize = max_val_size;
720 dwValType = 0L;
721 ++dwIndex;
722 if(!wcscmp(ValName, L""))
723 {
724 AddedDefault = TRUE;
725 }
726 }
727 HeapFree(GetProcessHeap(), 0, ValBuf);
728 HeapFree(GetProcessHeap(), 0, ValName);
729 }
730 RegCloseKey(hNewKey);
731
732 if(!AddedDefault)
733 {
734 AddEntryToList(hwndLV, L"", REG_SZ, NULL, 0, 0, FALSE);
735 }
736 c = ListView_GetItemCount(hwndLV);
737 for(i = 0; i < c; i++)
738 {
739 ListView_SetItemState(hwndLV, i, 0, LVIS_FOCUSED | LVIS_SELECTED);
740 }
741 ListView_SetItemState(hwndLV, iListViewSelect,
742 LVIS_FOCUSED | LVIS_SELECTED,
743 LVIS_FOCUSED | LVIS_SELECTED);
744 (void)ListView_Sort(hwndLV, g_iSortedColumn, -1);
745 SendMessageW(hwndLV, WM_SETREDRAW, TRUE, 0);
746
747 return TRUE;
748 }