2003-08-07 05:10:13 +02:00
|
|
|
/*
|
|
|
|
* Regedit listviews
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
|
2008-08-31 16:49:43 +02:00
|
|
|
* Copyright (C) 2008 Alexander N. Sørnes <alex@thehandofagony.com>
|
2003-08-07 05:10:13 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-08-07 05:10:13 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <commctrl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
|
2004-05-04 04:55:28 +02:00
|
|
|
#include "wine/unicode.h"
|
2005-03-21 11:29:32 +01:00
|
|
|
static INT Image_String;
|
|
|
|
static INT Image_Binary;
|
|
|
|
|
2003-12-10 03:10:52 +01:00
|
|
|
typedef struct tagLINE_INFO
|
|
|
|
{
|
|
|
|
DWORD dwValType;
|
2008-08-26 20:57:23 +02:00
|
|
|
LPWSTR name;
|
2003-12-10 03:10:52 +01:00
|
|
|
void* val;
|
|
|
|
size_t val_len;
|
|
|
|
} LINE_INFO;
|
2003-08-07 05:10:13 +02:00
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* Global and Local Variables:
|
|
|
|
*/
|
|
|
|
|
|
|
|
static WNDPROC g_orgListWndProc;
|
2008-04-09 14:22:42 +02:00
|
|
|
static DWORD g_columnToSort = ~0U;
|
2003-12-10 03:10:52 +01:00
|
|
|
static BOOL g_invertSort = FALSE;
|
2008-08-27 20:40:31 +02:00
|
|
|
static LPWSTR g_valueName;
|
|
|
|
static LPWSTR g_currentPath;
|
2004-01-14 00:18:12 +01:00
|
|
|
static HKEY g_currentRootKey;
|
2008-08-31 16:49:43 +02:00
|
|
|
static WCHAR g_szValueNotSet[64];
|
2003-08-07 05:10:13 +02:00
|
|
|
|
|
|
|
#define MAX_LIST_COLUMNS (IDS_LIST_COLUMN_LAST - IDS_LIST_COLUMN_FIRST + 1)
|
|
|
|
static int default_column_widths[MAX_LIST_COLUMNS] = { 200, 175, 400 };
|
|
|
|
static int column_alignment[MAX_LIST_COLUMNS] = { LVCFMT_LEFT, LVCFMT_LEFT, LVCFMT_LEFT };
|
|
|
|
|
2008-08-31 16:58:27 +02:00
|
|
|
LPWSTR GetItemText(HWND hwndLV, UINT item)
|
2008-08-27 20:40:31 +02:00
|
|
|
{
|
|
|
|
LPWSTR newStr, curStr;
|
|
|
|
unsigned int maxLen = 128;
|
|
|
|
|
|
|
|
curStr = HeapAlloc(GetProcessHeap(), 0, maxLen * sizeof(WCHAR));
|
|
|
|
if (!curStr) return NULL;
|
|
|
|
if (item == 0) { /* first item is ALWAYS a default */
|
|
|
|
HeapFree(GetProcessHeap(), 0, curStr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
ListView_GetItemTextW(hwndLV, item, 0, curStr, maxLen * sizeof(WCHAR));
|
|
|
|
if (lstrlenW(curStr) < maxLen - 1) return curStr;
|
|
|
|
newStr = HeapReAlloc(GetProcessHeap(), 0, curStr, maxLen * 2 * sizeof(WCHAR));
|
|
|
|
if (!newStr) break;
|
|
|
|
curStr = newStr;
|
|
|
|
maxLen *= 2;
|
|
|
|
} while (TRUE);
|
|
|
|
HeapFree(GetProcessHeap(), 0, curStr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
LPCWSTR GetValueName(HWND hwndLV)
|
2003-12-12 05:08:59 +01:00
|
|
|
{
|
2004-01-17 00:02:44 +01:00
|
|
|
INT item;
|
2003-12-12 05:08:59 +01:00
|
|
|
|
2008-08-27 20:40:31 +02:00
|
|
|
if (g_valueName != LPSTR_TEXTCALLBACKW)
|
2004-05-04 04:55:28 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, g_valueName);
|
2004-01-17 00:02:44 +01:00
|
|
|
g_valueName = NULL;
|
2003-12-12 05:08:59 +01:00
|
|
|
|
|
|
|
item = ListView_GetNextItem(hwndLV, -1, LVNI_FOCUSED);
|
|
|
|
if (item == -1) return NULL;
|
2004-01-17 00:02:44 +01:00
|
|
|
|
2008-08-31 16:58:27 +02:00
|
|
|
g_valueName = GetItemText(hwndLV, item);
|
2003-12-12 05:08:59 +01:00
|
|
|
|
|
|
|
return g_valueName;
|
|
|
|
}
|
2003-08-07 05:10:13 +02:00
|
|
|
|
2005-03-21 11:29:32 +01:00
|
|
|
/* convert '\0' separated string list into ',' separated string list */
|
2008-08-26 20:57:23 +02:00
|
|
|
static void MakeMULTISZDisplayable(LPWSTR multi)
|
2005-03-21 11:29:32 +01:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
for (; *multi; multi++)
|
|
|
|
;
|
|
|
|
if (*(multi+1))
|
|
|
|
{
|
|
|
|
*multi = ',';
|
|
|
|
multi++;
|
|
|
|
}
|
|
|
|
} while (*multi);
|
|
|
|
}
|
|
|
|
|
2003-08-07 05:10:13 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* Local module support methods
|
|
|
|
*/
|
2008-08-26 20:57:23 +02:00
|
|
|
static void AddEntryToList(HWND hwndLV, LPWSTR Name, DWORD dwValType,
|
2004-05-04 04:55:28 +02:00
|
|
|
void* ValBuf, DWORD dwCount, BOOL bHighlight)
|
2003-08-07 05:10:13 +02:00
|
|
|
{
|
2003-12-10 03:10:52 +01:00
|
|
|
LINE_INFO* linfo;
|
2008-08-26 20:57:23 +02:00
|
|
|
LVITEMW item;
|
2003-08-07 05:10:13 +02:00
|
|
|
int index;
|
|
|
|
|
2003-12-10 03:10:52 +01:00
|
|
|
linfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LINE_INFO) + dwCount);
|
|
|
|
linfo->dwValType = dwValType;
|
|
|
|
linfo->val_len = dwCount;
|
2008-08-26 20:57:23 +02:00
|
|
|
CopyMemory(&linfo[1], ValBuf, dwCount);
|
2004-05-04 04:55:28 +02:00
|
|
|
|
|
|
|
if (Name)
|
2008-08-26 20:57:23 +02:00
|
|
|
{
|
|
|
|
linfo->name = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(Name) + 1) * sizeof(WCHAR));
|
|
|
|
lstrcpyW(linfo->name, Name);
|
|
|
|
} else
|
|
|
|
{
|
2004-05-04 04:55:28 +02:00
|
|
|
linfo->name = NULL;
|
2008-08-26 20:57:23 +02:00
|
|
|
}
|
2003-12-10 03:10:52 +01:00
|
|
|
|
2005-03-21 11:29:32 +01:00
|
|
|
item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE | LVIF_IMAGE;
|
2004-05-04 04:55:28 +02:00
|
|
|
item.iItem = ListView_GetItemCount(hwndLV);/*idx; */
|
2003-08-07 05:10:13 +02:00
|
|
|
item.iSubItem = 0;
|
|
|
|
item.state = 0;
|
2004-05-04 04:55:28 +02:00
|
|
|
item.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
|
2008-08-26 20:57:23 +02:00
|
|
|
item.pszText = Name ? Name : LPSTR_TEXTCALLBACKW;
|
|
|
|
item.cchTextMax = Name ? lstrlenW(item.pszText) : 0;
|
2004-05-04 04:55:28 +02:00
|
|
|
if (bHighlight) {
|
|
|
|
item.stateMask = item.state = LVIS_FOCUSED | LVIS_SELECTED;
|
|
|
|
}
|
2005-03-21 11:29:32 +01:00
|
|
|
switch (dwValType)
|
|
|
|
{
|
|
|
|
case REG_SZ:
|
|
|
|
case REG_EXPAND_SZ:
|
|
|
|
case REG_MULTI_SZ:
|
|
|
|
item.iImage = Image_String;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
item.iImage = Image_Binary;
|
|
|
|
break;
|
|
|
|
}
|
2003-12-10 03:10:52 +01:00
|
|
|
item.lParam = (LPARAM)linfo;
|
|
|
|
|
2003-08-07 05:10:13 +02:00
|
|
|
#if (_WIN32_IE >= 0x0300)
|
|
|
|
item.iIndent = 0;
|
|
|
|
#endif
|
|
|
|
|
2008-08-26 20:57:23 +02:00
|
|
|
index = ListView_InsertItemW(hwndLV, &item);
|
2003-08-07 05:10:13 +02:00
|
|
|
if (index != -1) {
|
|
|
|
switch (dwValType) {
|
|
|
|
case REG_SZ:
|
|
|
|
case REG_EXPAND_SZ:
|
2004-05-04 04:55:28 +02:00
|
|
|
if (ValBuf) {
|
2008-08-26 20:57:23 +02:00
|
|
|
ListView_SetItemTextW(hwndLV, index, 2, ValBuf);
|
2004-05-04 04:55:28 +02:00
|
|
|
} else {
|
2008-08-31 16:49:43 +02:00
|
|
|
ListView_SetItemTextW(hwndLV, index, 2, g_szValueNotSet);
|
2004-05-04 04:55:28 +02:00
|
|
|
}
|
2003-08-07 05:10:13 +02:00
|
|
|
break;
|
2003-12-08 23:48:07 +01:00
|
|
|
case REG_DWORD: {
|
2008-08-26 20:57:23 +02:00
|
|
|
WCHAR buf[64];
|
|
|
|
WCHAR format[] = {'0','x','%','0','8','x',' ','(','%','u',')',0};
|
|
|
|
wsprintfW(buf, format, *(DWORD*)ValBuf, *(DWORD*)ValBuf);
|
|
|
|
ListView_SetItemTextW(hwndLV, index, 2, buf);
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
|
|
|
break;
|
2003-12-08 23:48:07 +01:00
|
|
|
case REG_BINARY: {
|
2003-08-07 05:10:13 +02:00
|
|
|
unsigned int i;
|
2009-01-15 09:47:14 +01:00
|
|
|
LPBYTE pData = ValBuf;
|
2008-08-26 20:57:23 +02:00
|
|
|
LPWSTR strBinary = HeapAlloc(GetProcessHeap(), 0, dwCount * sizeof(WCHAR) * 3 + sizeof(WCHAR));
|
|
|
|
WCHAR format[] = {'%','0','2','X',' ',0};
|
2003-08-07 05:10:13 +02:00
|
|
|
for (i = 0; i < dwCount; i++)
|
2008-08-26 20:57:23 +02:00
|
|
|
wsprintfW( strBinary + i*3, format, pData[i] );
|
2003-08-07 05:10:13 +02:00
|
|
|
strBinary[dwCount * 3] = 0;
|
2008-08-26 20:57:23 +02:00
|
|
|
ListView_SetItemTextW(hwndLV, index, 2, strBinary);
|
2003-08-07 05:10:13 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, strBinary);
|
|
|
|
}
|
|
|
|
break;
|
2005-03-21 11:29:32 +01:00
|
|
|
case REG_MULTI_SZ:
|
|
|
|
MakeMULTISZDisplayable(ValBuf);
|
2008-08-26 20:57:23 +02:00
|
|
|
ListView_SetItemTextW(hwndLV, index, 2, ValBuf);
|
2005-03-21 11:29:32 +01:00
|
|
|
break;
|
2003-08-07 05:10:13 +02:00
|
|
|
default:
|
2006-08-23 14:11:39 +02:00
|
|
|
{
|
2008-08-26 20:57:23 +02:00
|
|
|
WCHAR szText[128];
|
|
|
|
LoadStringW(hInst, IDS_REGISTRY_VALUE_CANT_DISPLAY, szText, COUNT_OF(szText));
|
|
|
|
ListView_SetItemTextW(hwndLV, index, 2, szText);
|
2003-08-07 05:10:13 +02:00
|
|
|
break;
|
2006-08-23 14:11:39 +02:00
|
|
|
}
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-21 11:29:32 +01:00
|
|
|
static BOOL InitListViewImageList(HWND hWndListView)
|
|
|
|
{
|
|
|
|
HIMAGELIST himl;
|
|
|
|
HICON hicon;
|
|
|
|
INT cx = GetSystemMetrics(SM_CXSMICON);
|
|
|
|
INT cy = GetSystemMetrics(SM_CYSMICON);
|
|
|
|
|
|
|
|
himl = ImageList_Create(cx, cy, ILC_MASK, 0, 2);
|
|
|
|
if (!himl)
|
|
|
|
return FALSE;
|
|
|
|
|
2008-08-31 14:53:30 +02:00
|
|
|
hicon = LoadImageW(hInst, MAKEINTRESOURCEW(IDI_STRING),
|
2005-03-21 11:29:32 +01:00
|
|
|
IMAGE_ICON, cx, cy, LR_DEFAULTCOLOR);
|
|
|
|
Image_String = ImageList_AddIcon(himl, hicon);
|
|
|
|
|
2008-08-31 14:53:30 +02:00
|
|
|
hicon = LoadImageW(hInst, MAKEINTRESOURCEW(IDI_BIN),
|
2005-03-21 11:29:32 +01:00
|
|
|
IMAGE_ICON, cx, cy, LR_DEFAULTCOLOR);
|
|
|
|
Image_Binary = ImageList_AddIcon(himl, hicon);
|
|
|
|
|
2008-08-31 14:53:30 +02:00
|
|
|
SendMessageW( hWndListView, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM) himl );
|
2005-03-21 11:29:32 +01:00
|
|
|
|
|
|
|
/* fail if some of the icons failed to load */
|
|
|
|
if (ImageList_GetImageCount(himl) < 2)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-12-12 05:08:59 +01:00
|
|
|
static BOOL CreateListColumns(HWND hWndListView)
|
2003-08-07 05:10:13 +02:00
|
|
|
{
|
2008-08-31 14:53:30 +02:00
|
|
|
WCHAR szText[50];
|
2003-08-07 05:10:13 +02:00
|
|
|
int index;
|
2008-08-31 14:53:30 +02:00
|
|
|
LVCOLUMNW lvC;
|
2003-08-07 05:10:13 +02:00
|
|
|
|
|
|
|
/* Create columns. */
|
|
|
|
lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
|
|
|
|
lvC.pszText = szText;
|
|
|
|
|
|
|
|
/* Load the column labels from the resource file. */
|
|
|
|
for (index = 0; index < MAX_LIST_COLUMNS; index++) {
|
|
|
|
lvC.iSubItem = index;
|
|
|
|
lvC.cx = default_column_widths[index];
|
|
|
|
lvC.fmt = column_alignment[index];
|
2008-08-31 14:53:30 +02:00
|
|
|
LoadStringW(hInst, IDS_LIST_COLUMN_FIRST + index, szText, sizeof(szText)/sizeof(WCHAR));
|
|
|
|
if (ListView_InsertColumnW(hWndListView, index, &lvC) == -1) return FALSE;
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
2003-12-12 05:08:59 +01:00
|
|
|
return TRUE;
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* OnGetDispInfo - processes the LVN_GETDISPINFO notification message. */
|
|
|
|
|
2008-08-31 16:49:43 +02:00
|
|
|
static void OnGetDispInfo(NMLVDISPINFOW* plvdi)
|
2003-08-07 05:10:13 +02:00
|
|
|
{
|
2008-08-31 16:49:43 +02:00
|
|
|
static WCHAR buffer[200];
|
|
|
|
static WCHAR reg_szT[] = {'R','E','G','_','S','Z',0},
|
2006-06-30 00:18:08 +02:00
|
|
|
reg_expand_szT[] = {'R','E','G','_','E','X','P','A','N','D','_','S','Z',0},
|
|
|
|
reg_binaryT[] = {'R','E','G','_','B','I','N','A','R','Y',0},
|
|
|
|
reg_dwordT[] = {'R','E','G','_','D','W','O','R','D',0},
|
|
|
|
reg_dword_big_endianT[] = {'R','E','G','_','D','W','O','R','D','_',
|
|
|
|
'B','I','G','_','E','N','D','I','A','N',0},
|
|
|
|
reg_multi_szT[] = {'R','E','G','_','M','U','L','T','I','_','S','Z',0},
|
|
|
|
reg_linkT[] = {'R','E','G','_','L','I','N','K',0},
|
|
|
|
reg_resource_listT[] = {'R','E','G','_','R','E','S','O','U','R','C','E','_','L','I','S','T',0},
|
|
|
|
reg_noneT[] = {'R','E','G','_','N','O','N','E',0},
|
|
|
|
emptyT[] = {0};
|
2003-08-07 05:10:13 +02:00
|
|
|
|
|
|
|
plvdi->item.pszText = NULL;
|
|
|
|
plvdi->item.cchTextMax = 0;
|
|
|
|
|
|
|
|
switch (plvdi->item.iSubItem) {
|
|
|
|
case 0:
|
2008-08-31 16:49:43 +02:00
|
|
|
plvdi->item.pszText = g_pszDefaultValueName;
|
2003-08-07 05:10:13 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
2003-12-10 03:10:52 +01:00
|
|
|
switch (((LINE_INFO*)plvdi->item.lParam)->dwValType) {
|
2003-08-07 05:10:13 +02:00
|
|
|
case REG_SZ:
|
2006-06-30 00:18:08 +02:00
|
|
|
plvdi->item.pszText = reg_szT;
|
2003-08-07 05:10:13 +02:00
|
|
|
break;
|
|
|
|
case REG_EXPAND_SZ:
|
2006-06-30 00:18:08 +02:00
|
|
|
plvdi->item.pszText = reg_expand_szT;
|
2003-08-07 05:10:13 +02:00
|
|
|
break;
|
|
|
|
case REG_BINARY:
|
2006-06-30 00:18:08 +02:00
|
|
|
plvdi->item.pszText = reg_binaryT;
|
2003-08-07 05:10:13 +02:00
|
|
|
break;
|
|
|
|
case REG_DWORD:
|
2006-06-30 00:18:08 +02:00
|
|
|
plvdi->item.pszText = reg_dwordT;
|
2003-08-07 05:10:13 +02:00
|
|
|
break;
|
|
|
|
case REG_DWORD_BIG_ENDIAN:
|
2006-06-30 00:18:08 +02:00
|
|
|
plvdi->item.pszText = reg_dword_big_endianT;
|
2003-08-07 05:10:13 +02:00
|
|
|
break;
|
|
|
|
case REG_MULTI_SZ:
|
2006-06-30 00:18:08 +02:00
|
|
|
plvdi->item.pszText = reg_multi_szT;
|
2003-08-07 05:10:13 +02:00
|
|
|
break;
|
|
|
|
case REG_LINK:
|
2006-06-30 00:18:08 +02:00
|
|
|
plvdi->item.pszText = reg_linkT;
|
2003-08-07 05:10:13 +02:00
|
|
|
break;
|
|
|
|
case REG_RESOURCE_LIST:
|
2006-06-30 00:18:08 +02:00
|
|
|
plvdi->item.pszText = reg_resource_listT;
|
2003-08-07 05:10:13 +02:00
|
|
|
break;
|
|
|
|
case REG_NONE:
|
2006-06-30 00:18:08 +02:00
|
|
|
plvdi->item.pszText = reg_noneT;
|
2003-08-07 05:10:13 +02:00
|
|
|
break;
|
|
|
|
default:
|
2006-08-23 14:11:39 +02:00
|
|
|
{
|
2008-08-31 16:49:43 +02:00
|
|
|
WCHAR szUnknownFmt[64];
|
|
|
|
LoadStringW(hInst, IDS_REGISTRY_UNKNOWN_TYPE, szUnknownFmt, COUNT_OF(szUnknownFmt));
|
|
|
|
wsprintfW(buffer, szUnknownFmt, plvdi->item.lParam);
|
2003-08-07 05:10:13 +02:00
|
|
|
plvdi->item.pszText = buffer;
|
|
|
|
break;
|
2006-08-23 14:11:39 +02:00
|
|
|
}
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
2006-08-23 14:11:39 +02:00
|
|
|
plvdi->item.pszText = g_szValueNotSet;
|
2003-08-07 05:10:13 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
2006-06-30 00:18:08 +02:00
|
|
|
plvdi->item.pszText = emptyT;
|
2003-08-07 05:10:13 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
|
|
|
|
{
|
2003-12-10 03:10:52 +01:00
|
|
|
LINE_INFO*l, *r;
|
|
|
|
l = (LINE_INFO*)lParam1;
|
|
|
|
r = (LINE_INFO*)lParam2;
|
2004-05-04 04:55:28 +02:00
|
|
|
if (!l->name) return -1;
|
|
|
|
if (!r->name) return +1;
|
2003-12-10 03:10:52 +01:00
|
|
|
|
2008-04-09 14:22:42 +02:00
|
|
|
if (g_columnToSort == ~0U)
|
2003-12-10 03:10:52 +01:00
|
|
|
g_columnToSort = 0;
|
|
|
|
|
|
|
|
if (g_columnToSort == 1 && l->dwValType != r->dwValType)
|
|
|
|
return g_invertSort ? (int)r->dwValType - (int)l->dwValType : (int)l->dwValType - (int)r->dwValType;
|
2003-12-12 05:08:59 +01:00
|
|
|
if (g_columnToSort == 2) {
|
2003-12-10 03:10:52 +01:00
|
|
|
/* FIXME: Sort on value */
|
|
|
|
}
|
2008-08-26 22:52:09 +02:00
|
|
|
return g_invertSort ? lstrcmpiW(r->name, l->name) : lstrcmpiW(l->name, r->name);
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
|
|
|
|
2004-03-15 21:19:38 +01:00
|
|
|
HWND StartValueRename(HWND hwndLV)
|
2004-01-14 00:18:12 +01:00
|
|
|
{
|
|
|
|
int item;
|
|
|
|
|
2004-01-17 00:02:44 +01:00
|
|
|
item = ListView_GetNextItem(hwndLV, -1, LVNI_FOCUSED | LVNI_SELECTED);
|
2004-05-04 04:55:28 +02:00
|
|
|
if (item < 1) { /* cannot rename default key */
|
|
|
|
MessageBeep(MB_ICONHAND);
|
|
|
|
return 0;
|
|
|
|
}
|
2004-03-15 21:19:38 +01:00
|
|
|
return ListView_EditLabel(hwndLV, item);
|
2004-01-14 00:18:12 +01:00
|
|
|
}
|
2003-08-07 05:10:13 +02:00
|
|
|
|
|
|
|
static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2003-12-08 23:48:07 +01:00
|
|
|
switch (LOWORD(wParam)) {
|
|
|
|
/* case ID_FILE_OPEN: */
|
|
|
|
/* break; */
|
|
|
|
default:
|
2003-08-07 05:10:13 +02:00
|
|
|
return FALSE;
|
2003-12-08 23:48:07 +01:00
|
|
|
}
|
|
|
|
return TRUE;
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT CALLBACK ListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2003-12-08 23:48:07 +01:00
|
|
|
switch (message) {
|
|
|
|
case WM_COMMAND:
|
2003-08-07 05:10:13 +02:00
|
|
|
if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
|
|
|
|
return CallWindowProc(g_orgListWndProc, hWnd, message, wParam, lParam);
|
|
|
|
}
|
2003-12-08 23:48:07 +01:00
|
|
|
break;
|
2004-05-04 04:55:28 +02:00
|
|
|
case WM_NOTIFY_REFLECT:
|
2003-08-07 05:10:13 +02:00
|
|
|
switch (((LPNMHDR)lParam)->code) {
|
2004-05-04 04:55:28 +02:00
|
|
|
|
2008-08-31 16:49:43 +02:00
|
|
|
case LVN_BEGINLABELEDITW:
|
|
|
|
if (!((NMLVDISPINFOW *)lParam)->item.iItem)
|
2004-05-04 04:55:28 +02:00
|
|
|
return 1;
|
|
|
|
return 0;
|
2008-08-31 16:49:43 +02:00
|
|
|
case LVN_GETDISPINFOW:
|
|
|
|
OnGetDispInfo((NMLVDISPINFOW*)lParam);
|
2003-08-07 05:10:13 +02:00
|
|
|
break;
|
2003-12-10 03:10:52 +01:00
|
|
|
case LVN_COLUMNCLICK:
|
|
|
|
if (g_columnToSort == ((LPNMLISTVIEW)lParam)->iSubItem)
|
|
|
|
g_invertSort = !g_invertSort;
|
2003-12-12 05:08:59 +01:00
|
|
|
else {
|
2003-12-10 03:10:52 +01:00
|
|
|
g_columnToSort = ((LPNMLISTVIEW)lParam)->iSubItem;
|
|
|
|
g_invertSort = FALSE;
|
|
|
|
}
|
|
|
|
|
2008-08-31 16:49:43 +02:00
|
|
|
SendMessageW(hWnd, LVM_SORTITEMS, (WPARAM)hWnd, (LPARAM)CompareFunc);
|
2003-12-10 03:10:52 +01:00
|
|
|
break;
|
2008-08-31 16:49:43 +02:00
|
|
|
case LVN_ENDLABELEDITW: {
|
|
|
|
LPNMLVDISPINFOW dispInfo = (LPNMLVDISPINFOW)lParam;
|
2008-08-31 16:58:27 +02:00
|
|
|
LPWSTR oldName = GetItemText(hWnd, dispInfo->item.iItem);
|
2004-05-04 04:55:28 +02:00
|
|
|
LONG ret;
|
2008-08-29 22:20:26 +02:00
|
|
|
if (!oldName) return -1; /* cannot rename a default value */
|
2008-08-31 16:49:43 +02:00
|
|
|
ret = RenameValue(hWnd, g_currentRootKey, g_currentPath, oldName, dispInfo->item.pszText);
|
2004-05-04 04:55:28 +02:00
|
|
|
if (ret)
|
2008-08-27 20:40:31 +02:00
|
|
|
{
|
2008-08-31 16:49:43 +02:00
|
|
|
RefreshListView(hWnd, g_currentRootKey, g_currentPath, dispInfo->item.pszText);
|
2008-08-27 20:40:31 +02:00
|
|
|
}
|
2008-08-29 22:20:26 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, oldName);
|
2004-05-04 04:55:28 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case NM_RETURN: {
|
|
|
|
int cnt = ListView_GetNextItem(hWnd, -1, LVNI_FOCUSED | LVNI_SELECTED);
|
|
|
|
if (cnt != -1)
|
2008-09-02 19:26:44 +02:00
|
|
|
SendMessageW(hFrameWnd, WM_COMMAND, ID_EDIT_MODIFY, 0);
|
2004-01-17 00:02:44 +01:00
|
|
|
}
|
2004-05-04 04:55:28 +02:00
|
|
|
break;
|
2003-12-08 23:48:07 +01:00
|
|
|
case NM_DBLCLK: {
|
|
|
|
NMITEMACTIVATE* nmitem = (LPNMITEMACTIVATE)lParam;
|
|
|
|
LVHITTESTINFO info;
|
|
|
|
|
2004-05-04 04:55:28 +02:00
|
|
|
/* if (nmitem->hdr.hwndFrom != hWnd) break; unnecessary because of WM_NOTIFY_REFLECT */
|
2003-12-08 23:48:07 +01:00
|
|
|
/* if (nmitem->hdr.idFrom != IDW_LISTVIEW) break; */
|
|
|
|
/* if (nmitem->hdr.code != ???) break; */
|
2003-08-07 05:10:13 +02:00
|
|
|
#ifdef _MSC_VER
|
2003-12-08 23:48:07 +01:00
|
|
|
switch (nmitem->uKeyFlags) {
|
|
|
|
case LVKF_ALT: /* The ALT key is pressed. */
|
|
|
|
/* properties dialog box ? */
|
|
|
|
break;
|
|
|
|
case LVKF_CONTROL: /* The CTRL key is pressed. */
|
|
|
|
/* run dialog box for providing parameters... */
|
|
|
|
break;
|
|
|
|
case LVKF_SHIFT: /* The SHIFT key is pressed. */
|
|
|
|
break;
|
|
|
|
}
|
2003-08-07 05:10:13 +02:00
|
|
|
#endif
|
2003-12-08 23:48:07 +01:00
|
|
|
info.pt.x = nmitem->ptAction.x;
|
|
|
|
info.pt.y = nmitem->ptAction.y;
|
|
|
|
if (ListView_HitTest(hWnd, &info) != -1) {
|
2004-05-04 04:55:28 +02:00
|
|
|
ListView_SetItemState(hWnd, -1, 0, LVIS_FOCUSED|LVIS_SELECTED);
|
|
|
|
ListView_SetItemState(hWnd, info.iItem, LVIS_FOCUSED|LVIS_SELECTED,
|
|
|
|
LVIS_FOCUSED|LVIS_SELECTED);
|
2008-09-02 19:26:44 +02:00
|
|
|
SendMessageW(hFrameWnd, WM_COMMAND, ID_EDIT_MODIFY, 0);
|
2003-12-08 23:48:07 +01:00
|
|
|
}
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2004-05-04 04:55:28 +02:00
|
|
|
return 0; /* shouldn't call default ! */
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
2003-12-08 23:48:07 +01:00
|
|
|
break;
|
2004-01-16 03:14:19 +01:00
|
|
|
case WM_CONTEXTMENU: {
|
2004-05-04 04:55:28 +02:00
|
|
|
int cnt = ListView_GetNextItem(hWnd, -1, LVNI_SELECTED);
|
2004-11-24 19:28:31 +01:00
|
|
|
TrackPopupMenu(GetSubMenu(hPopupMenus, cnt == -1 ? PM_NEW : PM_MODIFYVALUE),
|
|
|
|
TPM_RIGHTBUTTON, (short)LOWORD(lParam), (short)HIWORD(lParam),
|
|
|
|
0, hFrameWnd, NULL);
|
2004-01-16 03:14:19 +01:00
|
|
|
break;
|
|
|
|
}
|
2003-08-07 05:10:13 +02:00
|
|
|
default:
|
|
|
|
return CallWindowProc(g_orgListWndProc, hWnd, message, wParam, lParam);
|
2003-12-08 23:48:07 +01:00
|
|
|
}
|
|
|
|
return 0;
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-09 14:22:42 +02:00
|
|
|
HWND CreateListView(HWND hwndParent, UINT id)
|
2003-08-07 05:10:13 +02:00
|
|
|
{
|
|
|
|
RECT rcClient;
|
|
|
|
HWND hwndLV;
|
2008-08-31 14:53:30 +02:00
|
|
|
WCHAR ListView[] = {'L','i','s','t',' ','V','i','e','w',0};
|
2003-08-07 05:10:13 +02:00
|
|
|
|
2006-08-23 14:11:39 +02:00
|
|
|
/* prepare strings */
|
2008-08-31 16:49:43 +02:00
|
|
|
LoadStringW(hInst, IDS_REGISTRY_VALUE_NOT_SET, g_szValueNotSet, COUNT_OF(g_szValueNotSet));
|
2006-08-23 14:11:39 +02:00
|
|
|
|
2003-08-07 05:10:13 +02:00
|
|
|
/* Get the dimensions of the parent window's client area, and create the list view control. */
|
|
|
|
GetClientRect(hwndParent, &rcClient);
|
2008-08-31 14:53:30 +02:00
|
|
|
hwndLV = CreateWindowExW(WS_EX_CLIENTEDGE, WC_LISTVIEWW, ListView,
|
2004-01-16 22:20:54 +01:00
|
|
|
WS_VISIBLE | WS_CHILD | WS_TABSTOP | LVS_REPORT | LVS_EDITLABELS,
|
2003-12-08 23:48:07 +01:00
|
|
|
0, 0, rcClient.right, rcClient.bottom,
|
2009-01-15 09:47:14 +01:00
|
|
|
hwndParent, ULongToHandle(id), hInst, NULL);
|
2003-12-12 05:08:59 +01:00
|
|
|
if (!hwndLV) return NULL;
|
2008-08-31 16:49:43 +02:00
|
|
|
SendMessageW(hwndLV, LVM_SETUNICODEFORMAT, TRUE, 0);
|
2008-08-31 14:53:30 +02:00
|
|
|
SendMessageW(hwndLV, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
|
2003-08-07 05:10:13 +02:00
|
|
|
|
2005-03-21 11:29:32 +01:00
|
|
|
/* Initialize the image list */
|
|
|
|
if (!InitListViewImageList(hwndLV)) goto fail;
|
2003-12-12 05:08:59 +01:00
|
|
|
if (!CreateListColumns(hwndLV)) goto fail;
|
2008-08-31 14:53:30 +02:00
|
|
|
g_orgListWndProc = (WNDPROC) SetWindowLongPtrW(hwndLV, GWLP_WNDPROC, (LPARAM)ListWndProc);
|
2003-08-07 05:10:13 +02:00
|
|
|
return hwndLV;
|
2003-12-12 05:08:59 +01:00
|
|
|
fail:
|
|
|
|
DestroyWindow(hwndLV);
|
|
|
|
return NULL;
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
|
|
|
|
2008-08-27 20:40:31 +02:00
|
|
|
BOOL RefreshListView(HWND hwndLV, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR highlightValue)
|
2003-08-07 05:10:13 +02:00
|
|
|
{
|
2004-01-17 00:02:44 +01:00
|
|
|
BOOL result = FALSE;
|
2003-12-12 05:08:59 +01:00
|
|
|
DWORD max_sub_key_len;
|
2004-01-17 00:02:44 +01:00
|
|
|
DWORD max_val_name_len, valNameLen;
|
|
|
|
DWORD max_val_size, valSize;
|
|
|
|
DWORD val_count, index, valType;
|
2008-08-26 20:57:23 +02:00
|
|
|
WCHAR* valName = 0;
|
2004-01-17 00:02:44 +01:00
|
|
|
BYTE* valBuf = 0;
|
|
|
|
HKEY hKey = 0;
|
2003-12-12 05:08:59 +01:00
|
|
|
LONG errCode;
|
|
|
|
INT count, i;
|
2008-08-26 20:57:23 +02:00
|
|
|
LVITEMW item;
|
2003-08-07 05:10:13 +02:00
|
|
|
|
2003-12-12 05:08:59 +01:00
|
|
|
if (!hwndLV) return FALSE;
|
|
|
|
|
2008-08-26 20:57:23 +02:00
|
|
|
SendMessageW(hwndLV, WM_SETREDRAW, FALSE, 0);
|
|
|
|
|
2008-08-27 20:40:31 +02:00
|
|
|
errCode = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_READ, &hKey);
|
2004-01-17 00:02:44 +01:00
|
|
|
if (errCode != ERROR_SUCCESS) goto done;
|
|
|
|
|
2003-12-12 05:08:59 +01:00
|
|
|
count = ListView_GetItemCount(hwndLV);
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
item.mask = LVIF_PARAM;
|
|
|
|
item.iItem = i;
|
2008-08-26 20:57:23 +02:00
|
|
|
SendMessageW( hwndLV, LVM_GETITEM, 0, (LPARAM)&item );
|
|
|
|
HeapFree(GetProcessHeap(), 0, ((LINE_INFO*)item.lParam)->name);
|
2003-12-12 05:08:59 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, (void*)item.lParam);
|
|
|
|
}
|
2008-04-09 14:22:42 +02:00
|
|
|
g_columnToSort = ~0U;
|
2008-08-26 20:57:23 +02:00
|
|
|
SendMessageW( hwndLV, LVM_DELETEALLITEMS, 0, 0L );
|
2003-12-12 05:08:59 +01:00
|
|
|
|
|
|
|
/* get size information and resize the buffers if necessary */
|
2008-08-26 20:57:23 +02:00
|
|
|
errCode = RegQueryInfoKeyW(hKey, NULL, NULL, NULL, NULL, &max_sub_key_len, NULL,
|
2003-12-12 05:08:59 +01:00
|
|
|
&val_count, &max_val_name_len, &max_val_size, NULL, NULL);
|
2004-01-17 00:02:44 +01:00
|
|
|
if (errCode != ERROR_SUCCESS) goto done;
|
|
|
|
|
|
|
|
/* account for the terminator char */
|
|
|
|
max_val_name_len++;
|
|
|
|
max_val_size++;
|
|
|
|
|
2008-08-26 20:57:23 +02:00
|
|
|
valName = HeapAlloc(GetProcessHeap(), 0, max_val_name_len * sizeof(WCHAR));
|
2009-01-29 08:47:42 +01:00
|
|
|
if (!valName)
|
|
|
|
goto done;
|
2004-01-17 00:02:44 +01:00
|
|
|
valBuf = HeapAlloc(GetProcessHeap(), 0, max_val_size);
|
2009-01-29 08:47:42 +01:00
|
|
|
if (!valBuf)
|
|
|
|
goto done;
|
|
|
|
|
2008-08-26 20:57:23 +02:00
|
|
|
if (RegQueryValueExW(hKey, NULL, NULL, &valType, valBuf, &valSize) == ERROR_FILE_NOT_FOUND) {
|
2004-05-04 04:55:28 +02:00
|
|
|
AddEntryToList(hwndLV, NULL, REG_SZ, NULL, 0, !highlightValue);
|
|
|
|
}
|
2004-01-17 00:02:44 +01:00
|
|
|
for(index = 0; index < val_count; index++) {
|
2008-08-27 20:40:31 +02:00
|
|
|
BOOL bSelected = (valName == highlightValue); /* NOT a bug, we check for double NULL here */
|
2004-01-17 00:02:44 +01:00
|
|
|
valNameLen = max_val_name_len;
|
|
|
|
valSize = max_val_size;
|
|
|
|
valType = 0;
|
2008-08-26 20:57:23 +02:00
|
|
|
errCode = RegEnumValueW(hKey, index, valName, &valNameLen, NULL, &valType, valBuf, &valSize);
|
2004-01-17 00:02:44 +01:00
|
|
|
if (errCode != ERROR_SUCCESS) goto done;
|
|
|
|
valBuf[valSize] = 0;
|
2009-01-29 08:47:42 +01:00
|
|
|
if (highlightValue && !lstrcmpW(valName, highlightValue))
|
2004-05-04 04:55:28 +02:00
|
|
|
bSelected = TRUE;
|
|
|
|
AddEntryToList(hwndLV, valName[0] ? valName : NULL, valType, valBuf, valSize, bSelected);
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
2008-08-26 20:57:23 +02:00
|
|
|
SendMessageW(hwndLV, LVM_SORTITEMS, (WPARAM)hwndLV, (LPARAM)CompareFunc);
|
2004-01-17 00:02:44 +01:00
|
|
|
|
|
|
|
g_currentRootKey = hKeyRoot;
|
|
|
|
if (keyPath != g_currentPath) {
|
|
|
|
HeapFree(GetProcessHeap(), 0, g_currentPath);
|
2008-08-27 20:40:31 +02:00
|
|
|
g_currentPath = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(keyPath) + 1) * sizeof(WCHAR));
|
2004-01-17 00:02:44 +01:00
|
|
|
if (!g_currentPath) goto done;
|
2008-08-27 20:40:31 +02:00
|
|
|
lstrcpyW(g_currentPath, keyPath);
|
2004-01-17 00:02:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
result = TRUE;
|
|
|
|
|
|
|
|
done:
|
|
|
|
HeapFree(GetProcessHeap(), 0, valBuf);
|
|
|
|
HeapFree(GetProcessHeap(), 0, valName);
|
2008-08-26 20:57:23 +02:00
|
|
|
SendMessageW(hwndLV, WM_SETREDRAW, TRUE, 0);
|
2004-01-17 00:02:44 +01:00
|
|
|
if (hKey) RegCloseKey(hKey);
|
2003-12-12 05:08:59 +01:00
|
|
|
|
2004-01-17 00:02:44 +01:00
|
|
|
return result;
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|