2003-08-07 05:10:13 +02:00
|
|
|
/*
|
|
|
|
* Regedit listviews
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <windows.h>
|
2003-12-12 05:08:59 +01:00
|
|
|
#include <windowsx.h>
|
2003-08-07 05:10:13 +02:00
|
|
|
#include <commctrl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <tchar.h>
|
|
|
|
#include <process.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
|
2004-05-04 04:55:28 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(regedit);
|
|
|
|
|
2003-12-10 03:10:52 +01:00
|
|
|
typedef struct tagLINE_INFO
|
|
|
|
{
|
|
|
|
DWORD dwValType;
|
|
|
|
LPTSTR name;
|
|
|
|
void* val;
|
|
|
|
size_t val_len;
|
|
|
|
} LINE_INFO;
|
2003-08-07 05:10:13 +02:00
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* Global and Local Variables:
|
|
|
|
*/
|
|
|
|
|
|
|
|
static WNDPROC g_orgListWndProc;
|
2003-12-10 03:10:52 +01:00
|
|
|
static DWORD g_columnToSort = ~0UL;
|
|
|
|
static BOOL g_invertSort = FALSE;
|
2003-12-12 05:08:59 +01:00
|
|
|
static LPTSTR g_valueName;
|
2004-01-14 00:18:12 +01:00
|
|
|
static LPTSTR g_currentPath;
|
|
|
|
static HKEY g_currentRootKey;
|
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 };
|
|
|
|
|
2004-01-17 00:02:44 +01:00
|
|
|
LPTSTR get_item_text(HWND hwndLV, int item)
|
|
|
|
{
|
|
|
|
LPTSTR newStr, curStr;
|
|
|
|
int maxLen = 128;
|
|
|
|
|
|
|
|
curStr = HeapAlloc(GetProcessHeap(), 0, maxLen);
|
|
|
|
if (!curStr) return NULL;
|
2004-05-04 04:55:28 +02:00
|
|
|
if (item == 0) return NULL; /* first item is ALWAYS a default */
|
2004-01-17 00:02:44 +01:00
|
|
|
do {
|
|
|
|
ListView_GetItemText(hwndLV, item, 0, curStr, maxLen);
|
|
|
|
if (_tcslen(curStr) < maxLen - 1) return curStr;
|
|
|
|
newStr = HeapReAlloc(GetProcessHeap(), 0, curStr, maxLen * 2);
|
|
|
|
if (!newStr) break;
|
|
|
|
curStr = newStr;
|
|
|
|
maxLen *= 2;
|
|
|
|
} while (TRUE);
|
|
|
|
HeapFree(GetProcessHeap(), 0, curStr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-12-12 05:08:59 +01:00
|
|
|
LPCTSTR GetValueName(HWND hwndLV)
|
|
|
|
{
|
2004-01-17 00:02:44 +01:00
|
|
|
INT item;
|
2003-12-12 05:08:59 +01:00
|
|
|
|
2004-05-04 04:55:28 +02:00
|
|
|
if (g_valueName && g_valueName != LPSTR_TEXTCALLBACK)
|
|
|
|
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
|
|
|
|
|
|
|
g_valueName = get_item_text(hwndLV, item);
|
2003-12-12 05:08:59 +01:00
|
|
|
|
|
|
|
return g_valueName;
|
|
|
|
}
|
2003-08-07 05:10:13 +02:00
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* Local module support methods
|
|
|
|
*/
|
2004-05-04 04:55:28 +02:00
|
|
|
static void AddEntryToList(HWND hwndLV, LPTSTR Name, DWORD dwValType,
|
|
|
|
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;
|
2003-08-07 05:10:13 +02:00
|
|
|
LVITEM item;
|
|
|
|
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;
|
|
|
|
memcpy(&linfo[1], ValBuf, dwCount);
|
2004-05-04 04:55:28 +02:00
|
|
|
|
|
|
|
if (Name)
|
|
|
|
linfo->name = _tcsdup(Name);
|
|
|
|
else
|
|
|
|
linfo->name = NULL;
|
2003-12-10 03:10:52 +01:00
|
|
|
|
2004-05-04 04:55:28 +02:00
|
|
|
item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
|
|
|
|
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;
|
|
|
|
item.pszText = Name ? Name : LPSTR_TEXTCALLBACK;
|
|
|
|
item.cchTextMax = Name ? _tcslen(item.pszText) : 0;
|
|
|
|
if (bHighlight) {
|
|
|
|
item.stateMask = item.state = LVIS_FOCUSED | LVIS_SELECTED;
|
|
|
|
}
|
2003-08-07 05:10:13 +02:00
|
|
|
item.iImage = 0;
|
2003-12-10 03:10:52 +01:00
|
|
|
item.lParam = (LPARAM)linfo;
|
|
|
|
|
2003-12-08 23:48:07 +01:00
|
|
|
/* item.lParam = (LPARAM)ValBuf; */
|
2003-08-07 05:10:13 +02:00
|
|
|
#if (_WIN32_IE >= 0x0300)
|
|
|
|
item.iIndent = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
index = ListView_InsertItem(hwndLV, &item);
|
|
|
|
if (index != -1) {
|
2003-12-08 23:48:07 +01:00
|
|
|
/* LPTSTR pszText = NULL; */
|
2003-08-07 05:10:13 +02:00
|
|
|
LPTSTR pszText = _T("value");
|
|
|
|
switch (dwValType) {
|
|
|
|
case REG_SZ:
|
|
|
|
case REG_EXPAND_SZ:
|
2004-05-04 04:55:28 +02:00
|
|
|
if (ValBuf) {
|
|
|
|
ListView_SetItemText(hwndLV, index, 2, ValBuf);
|
|
|
|
} else {
|
|
|
|
ListView_SetItemText(hwndLV, index, 2, "(not set)");
|
|
|
|
}
|
2003-08-07 05:10:13 +02:00
|
|
|
break;
|
2003-12-08 23:48:07 +01:00
|
|
|
case REG_DWORD: {
|
2003-08-07 05:10:13 +02:00
|
|
|
TCHAR buf[64];
|
|
|
|
wsprintf(buf, _T("0x%08X (%d)"), *(DWORD*)ValBuf, *(DWORD*)ValBuf);
|
|
|
|
ListView_SetItemText(hwndLV, index, 2, buf);
|
|
|
|
}
|
2003-12-08 23:48:07 +01:00
|
|
|
/* lpsRes = convertHexToDWORDStr(lpbData, dwLen); */
|
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;
|
|
|
|
LPBYTE pData = (LPBYTE)ValBuf;
|
|
|
|
LPTSTR strBinary = HeapAlloc(GetProcessHeap(), 0, dwCount * sizeof(TCHAR) * 3 + 1);
|
|
|
|
for (i = 0; i < dwCount; i++)
|
|
|
|
wsprintf( strBinary + i*3, _T("%02X "), pData[i] );
|
|
|
|
strBinary[dwCount * 3] = 0;
|
|
|
|
ListView_SetItemText(hwndLV, index, 2, strBinary);
|
|
|
|
HeapFree(GetProcessHeap(), 0, strBinary);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2003-12-08 23:48:07 +01:00
|
|
|
/* lpsRes = convertHexToHexCSV(lpbData, dwLen); */
|
2003-08-07 05:10:13 +02:00
|
|
|
ListView_SetItemText(hwndLV, index, 2, pszText);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-12 05:08:59 +01:00
|
|
|
static BOOL CreateListColumns(HWND hWndListView)
|
2003-08-07 05:10:13 +02:00
|
|
|
{
|
|
|
|
TCHAR szText[50];
|
|
|
|
int index;
|
|
|
|
LV_COLUMN lvC;
|
|
|
|
|
|
|
|
/* 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];
|
|
|
|
LoadString(hInst, IDS_LIST_COLUMN_FIRST + index, szText, sizeof(szText)/sizeof(TCHAR));
|
2003-12-12 05:08:59 +01:00
|
|
|
if (ListView_InsertColumn(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. */
|
|
|
|
|
|
|
|
static void OnGetDispInfo(NMLVDISPINFO* plvdi)
|
|
|
|
{
|
|
|
|
static TCHAR buffer[200];
|
|
|
|
|
|
|
|
plvdi->item.pszText = NULL;
|
|
|
|
plvdi->item.cchTextMax = 0;
|
|
|
|
|
|
|
|
switch (plvdi->item.iSubItem) {
|
|
|
|
case 0:
|
2004-05-04 04:55:28 +02:00
|
|
|
plvdi->item.pszText = (LPSTR)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:
|
|
|
|
plvdi->item.pszText = _T("REG_SZ");
|
|
|
|
break;
|
|
|
|
case REG_EXPAND_SZ:
|
|
|
|
plvdi->item.pszText = _T("REG_EXPAND_SZ");
|
|
|
|
break;
|
|
|
|
case REG_BINARY:
|
|
|
|
plvdi->item.pszText = _T("REG_BINARY");
|
|
|
|
break;
|
|
|
|
case REG_DWORD:
|
|
|
|
plvdi->item.pszText = _T("REG_DWORD");
|
|
|
|
break;
|
|
|
|
case REG_DWORD_BIG_ENDIAN:
|
|
|
|
plvdi->item.pszText = _T("REG_DWORD_BIG_ENDIAN");
|
|
|
|
break;
|
|
|
|
case REG_MULTI_SZ:
|
|
|
|
plvdi->item.pszText = _T("REG_MULTI_SZ");
|
|
|
|
break;
|
|
|
|
case REG_LINK:
|
|
|
|
plvdi->item.pszText = _T("REG_LINK");
|
|
|
|
break;
|
|
|
|
case REG_RESOURCE_LIST:
|
|
|
|
plvdi->item.pszText = _T("REG_RESOURCE_LIST");
|
|
|
|
break;
|
|
|
|
case REG_NONE:
|
|
|
|
plvdi->item.pszText = _T("REG_NONE");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
wsprintf(buffer, _T("unknown(%d)"), plvdi->item.lParam);
|
|
|
|
plvdi->item.pszText = buffer;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
plvdi->item.pszText = _T("(value not set)");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
plvdi->item.pszText = _T("");
|
|
|
|
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
|
|
|
|
|
|
|
if (g_columnToSort == ~0UL)
|
|
|
|
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 */
|
|
|
|
}
|
|
|
|
return g_invertSort ? _tcscmp(r->name, l->name) : _tcscmp(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
|
|
|
|
|
|
|
case LVN_BEGINLABELEDIT:
|
|
|
|
if (!((NMLVDISPINFO *)lParam)->item.iItem)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
2003-08-07 05:10:13 +02:00
|
|
|
case LVN_GETDISPINFO:
|
|
|
|
OnGetDispInfo((NMLVDISPINFO*)lParam);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
ListView_SortItems(hWnd, CompareFunc, hWnd);
|
|
|
|
break;
|
2004-01-17 00:02:44 +01:00
|
|
|
case LVN_ENDLABELEDIT: {
|
|
|
|
LPNMLVDISPINFO dispInfo = (LPNMLVDISPINFO)lParam;
|
|
|
|
LPTSTR valueName = get_item_text(hWnd, dispInfo->item.iItem);
|
2004-05-04 04:55:28 +02:00
|
|
|
LONG ret;
|
|
|
|
if (!valueName) return -1; /* cannot rename a default value */
|
|
|
|
ret = RenameValue(hWnd, g_currentRootKey, g_currentPath, valueName, dispInfo->item.pszText);
|
|
|
|
if (ret)
|
|
|
|
RefreshListView(hWnd, g_currentRootKey, g_currentPath, dispInfo->item.pszText);
|
2004-01-17 00:02:44 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, valueName);
|
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)
|
|
|
|
SendMessage(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);
|
|
|
|
SendMessage(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: {
|
|
|
|
POINTS pt = MAKEPOINTS(lParam);
|
2004-05-04 04:55:28 +02:00
|
|
|
int cnt = ListView_GetNextItem(hWnd, -1, LVNI_SELECTED);
|
2004-01-16 03:14:19 +01:00
|
|
|
TrackPopupMenu(GetSubMenu(hPopupMenus, cnt == -1 ? PM_NEW : PM_MODIFYVALUE),
|
|
|
|
TPM_RIGHTBUTTON, pt.x, pt.y, 0, hFrameWnd, NULL);
|
|
|
|
break;
|
|
|
|
}
|
2003-08-07 05:10:13 +02:00
|
|
|
default:
|
|
|
|
return CallWindowProc(g_orgListWndProc, hWnd, message, wParam, lParam);
|
|
|
|
break;
|
2003-12-08 23:48:07 +01:00
|
|
|
}
|
|
|
|
return 0;
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HWND CreateListView(HWND hwndParent, int id)
|
|
|
|
{
|
|
|
|
RECT rcClient;
|
|
|
|
HWND hwndLV;
|
|
|
|
|
|
|
|
/* Get the dimensions of the parent window's client area, and create the list view control. */
|
|
|
|
GetClientRect(hwndParent, &rcClient);
|
|
|
|
hwndLV = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, _T("List View"),
|
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,
|
|
|
|
hwndParent, (HMENU)id, hInst, NULL);
|
2003-12-12 05:08:59 +01:00
|
|
|
if (!hwndLV) return NULL;
|
2003-08-07 05:10:13 +02:00
|
|
|
ListView_SetExtendedListViewStyle(hwndLV, LVS_EX_FULLROWSELECT);
|
|
|
|
|
|
|
|
/* Initialize the image list, and add items to the control. */
|
2003-12-08 23:48:07 +01:00
|
|
|
/*
|
2003-12-12 05:08:59 +01:00
|
|
|
if (!InitListViewImageLists(hwndLV)) goto fail;
|
|
|
|
if (!InitListViewItems(hwndLV, szName)) goto fail;
|
|
|
|
*/
|
|
|
|
if (!CreateListColumns(hwndLV)) goto fail;
|
2003-12-08 23:48:07 +01:00
|
|
|
g_orgListWndProc = SubclassWindow(hwndLV, 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
|
|
|
}
|
|
|
|
|
2004-05-04 04:55:28 +02:00
|
|
|
BOOL RefreshListView(HWND hwndLV, HKEY hKeyRoot, LPCTSTR keyPath, LPCTSTR 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;
|
|
|
|
TCHAR* valName = 0;
|
|
|
|
BYTE* valBuf = 0;
|
|
|
|
HKEY hKey = 0;
|
2003-12-12 05:08:59 +01:00
|
|
|
LONG errCode;
|
|
|
|
INT count, i;
|
|
|
|
LVITEM item;
|
2003-08-07 05:10:13 +02:00
|
|
|
|
2003-12-12 05:08:59 +01:00
|
|
|
if (!hwndLV) return FALSE;
|
|
|
|
|
|
|
|
SendMessage(hwndLV, WM_SETREDRAW, FALSE, 0);
|
2004-01-17 00:02:44 +01:00
|
|
|
|
|
|
|
errCode = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_READ, &hKey);
|
|
|
|
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;
|
|
|
|
ListView_GetItem(hwndLV, &item);
|
|
|
|
free(((LINE_INFO*)item.lParam)->name);
|
|
|
|
HeapFree(GetProcessHeap(), 0, (void*)item.lParam);
|
|
|
|
}
|
|
|
|
g_columnToSort = ~0UL;
|
|
|
|
ListView_DeleteAllItems(hwndLV);
|
|
|
|
|
|
|
|
/* get size information and resize the buffers if necessary */
|
2004-01-17 00:02:44 +01:00
|
|
|
errCode = RegQueryInfoKey(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++;
|
|
|
|
|
|
|
|
valName = HeapAlloc(GetProcessHeap(), 0, max_val_name_len * sizeof(TCHAR));
|
|
|
|
valBuf = HeapAlloc(GetProcessHeap(), 0, max_val_size);
|
2004-05-04 04:55:28 +02:00
|
|
|
if (RegQueryValueEx(hKey, NULL, NULL, &valType, valBuf, &valSize) == ERROR_FILE_NOT_FOUND) {
|
|
|
|
AddEntryToList(hwndLV, NULL, REG_SZ, NULL, 0, !highlightValue);
|
|
|
|
}
|
2004-01-17 00:02:44 +01:00
|
|
|
/*dwValSize = max_val_size; */
|
|
|
|
for(index = 0; index < val_count; index++) {
|
2004-05-04 04:55:28 +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;
|
|
|
|
errCode = RegEnumValue(hKey, index, valName, &valNameLen, NULL, &valType, valBuf, &valSize);
|
|
|
|
if (errCode != ERROR_SUCCESS) goto done;
|
|
|
|
valBuf[valSize] = 0;
|
2004-05-04 04:55:28 +02:00
|
|
|
if (valName && highlightValue && !_tcscmp(valName, highlightValue))
|
|
|
|
bSelected = TRUE;
|
|
|
|
AddEntryToList(hwndLV, valName[0] ? valName : NULL, valType, valBuf, valSize, bSelected);
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
2004-05-04 04:55:28 +02:00
|
|
|
ListView_SortItems(hwndLV, CompareFunc, hwndLV);
|
2004-01-17 00:02:44 +01:00
|
|
|
|
|
|
|
g_currentRootKey = hKeyRoot;
|
|
|
|
if (keyPath != g_currentPath) {
|
|
|
|
HeapFree(GetProcessHeap(), 0, g_currentPath);
|
|
|
|
g_currentPath = HeapAlloc(GetProcessHeap(), 0, (lstrlen(keyPath) + 1) * sizeof(TCHAR));
|
|
|
|
if (!g_currentPath) goto done;
|
|
|
|
lstrcpy(g_currentPath, keyPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = TRUE;
|
|
|
|
|
|
|
|
done:
|
|
|
|
HeapFree(GetProcessHeap(), 0, valBuf);
|
|
|
|
HeapFree(GetProcessHeap(), 0, valName);
|
2003-12-12 05:08:59 +01:00
|
|
|
SendMessage(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
|
|
|
}
|