2002-07-14 17:59:36 +00:00
|
|
|
/*
|
|
|
|
* ReactOS regedit
|
|
|
|
*
|
|
|
|
* listview.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
|
|
|
#include <windows.h>
|
|
|
|
#include <commctrl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <memory.h>
|
|
|
|
#include <tchar.h>
|
|
|
|
#include <process.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <windowsx.h>
|
|
|
|
#include "main.h"
|
|
|
|
#include "listview.h"
|
2002-08-29 18:42:38 +00:00
|
|
|
#include "hex_str.h"
|
2002-07-14 17:59:36 +00:00
|
|
|
|
2002-07-18 20:27:52 +00:00
|
|
|
|
2002-07-14 17:59:36 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2002-07-20 16:29:26 +00:00
|
|
|
// Global and Local Variables:
|
2002-07-14 17:59:36 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
static WNDPROC g_orgListWndProc;
|
|
|
|
|
2002-07-20 16:29:26 +00: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 };
|
|
|
|
|
2002-07-14 17:59:36 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Local module support methods
|
|
|
|
//
|
2002-07-22 14:41:40 +00:00
|
|
|
extern unsigned char AsciiTable[256][3];
|
2002-07-14 17:59:36 +00:00
|
|
|
|
2002-07-18 20:27:52 +00:00
|
|
|
static void AddEntryToList(HWND hwndLV, LPTSTR Name, DWORD dwValType, void* ValBuf, DWORD dwCount)
|
2002-07-16 22:18:29 +00:00
|
|
|
{
|
|
|
|
LVITEM item;
|
2002-07-22 14:41:40 +00:00
|
|
|
int index;
|
2002-07-16 22:18:29 +00:00
|
|
|
|
|
|
|
item.mask = LVIF_TEXT | LVIF_PARAM;
|
|
|
|
item.iItem = 0;//idx;
|
|
|
|
item.iSubItem = 0;
|
|
|
|
item.state = 0;
|
|
|
|
item.stateMask = 0;
|
2002-07-18 20:27:52 +00:00
|
|
|
item.pszText = Name;
|
|
|
|
item.cchTextMax = _tcslen(item.pszText);
|
2002-07-22 14:41:40 +00:00
|
|
|
if (item.cchTextMax == 0)
|
|
|
|
item.pszText = LPSTR_TEXTCALLBACK;
|
2002-07-16 22:18:29 +00:00
|
|
|
item.iImage = 0;
|
2002-07-18 20:27:52 +00:00
|
|
|
item.lParam = (LPARAM)dwValType;
|
|
|
|
// item.lParam = (LPARAM)ValBuf;
|
2002-07-16 22:18:29 +00:00
|
|
|
#if (_WIN32_IE >= 0x0300)
|
|
|
|
item.iIndent = 0;
|
|
|
|
#endif
|
2002-07-22 14:41:40 +00:00
|
|
|
|
|
|
|
index = ListView_InsertItem(hwndLV, &item);
|
|
|
|
if (index != -1) {
|
|
|
|
// LPTSTR pszText = NULL;
|
|
|
|
LPTSTR pszText = _T("value");
|
|
|
|
switch (dwValType) {
|
|
|
|
case REG_SZ:
|
|
|
|
case REG_EXPAND_SZ:
|
|
|
|
ListView_SetItemText(hwndLV, index, 2, ValBuf);
|
|
|
|
break;
|
|
|
|
case REG_DWORD:
|
|
|
|
{
|
|
|
|
TCHAR buf[64];
|
2002-08-29 18:42:38 +00:00
|
|
|
wsprintf(buf, _T("0x%08X (%d)"), *(DWORD*)ValBuf, *(DWORD*)ValBuf);
|
2002-07-22 14:41:40 +00:00
|
|
|
ListView_SetItemText(hwndLV, index, 2, buf);
|
|
|
|
}
|
|
|
|
// lpsRes = convertHexToDWORDStr(lpbData, dwLen);
|
|
|
|
break;
|
|
|
|
case REG_BINARY:
|
|
|
|
{
|
2002-08-29 18:42:38 +00:00
|
|
|
unsigned int i;
|
2002-07-22 14:41:40 +00:00
|
|
|
LPTSTR pData = (LPTSTR)ValBuf;
|
|
|
|
LPTSTR strBinary = malloc(dwCount * sizeof(TCHAR) * 3 + 1);
|
|
|
|
memset(strBinary, _T(' '), dwCount * sizeof(TCHAR) * 3);
|
|
|
|
strBinary[dwCount * sizeof(TCHAR) * 3] = _T('\0');
|
|
|
|
for (i = 0; i < dwCount; i++) {
|
|
|
|
unsigned short* pShort;
|
2002-08-29 18:42:38 +00:00
|
|
|
pShort = (unsigned short*)&(strBinary[i*3]);
|
2002-07-22 14:41:40 +00:00
|
|
|
// strBinary[i*3] = Byte2Hex((LPTSTR)ValBuf+i);
|
|
|
|
// *pShort++ = Byte2Hex(*(pData+i));
|
|
|
|
*pShort = Byte2Hex(*(pData+i));
|
|
|
|
}
|
|
|
|
ListView_SetItemText(hwndLV, index, 2, strBinary);
|
|
|
|
free(strBinary);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// lpsRes = convertHexToHexCSV(lpbData, dwLen);
|
|
|
|
ListView_SetItemText(hwndLV, index, 2, pszText);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-07-16 22:18:29 +00:00
|
|
|
}
|
|
|
|
|
2002-07-14 17:59:36 +00:00
|
|
|
static void CreateListColumns(HWND hWndListView)
|
|
|
|
{
|
|
|
|
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];
|
2002-07-22 21:12:26 +00:00
|
|
|
LoadString(hInst, IDS_LIST_COLUMN_FIRST + index, szText, sizeof(szText)/sizeof(TCHAR));
|
2002-07-14 17:59:36 +00:00
|
|
|
if (ListView_InsertColumn(hWndListView, index, &lvC) == -1) {
|
|
|
|
// TODO: handle failure condition...
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-20 16:29:26 +00:00
|
|
|
// OnGetDispInfo - processes the LVN_GETDISPINFO notification message.
|
2002-07-14 17:59:36 +00:00
|
|
|
|
|
|
|
static void OnGetDispInfo(NMLVDISPINFO* plvdi)
|
|
|
|
{
|
2002-07-18 20:27:52 +00:00
|
|
|
static TCHAR buffer[200];
|
2002-07-16 22:18:29 +00:00
|
|
|
|
2002-07-14 17:59:36 +00:00
|
|
|
plvdi->item.pszText = NULL;
|
2002-07-16 22:18:29 +00:00
|
|
|
plvdi->item.cchTextMax = 0;
|
2002-07-14 17:59:36 +00:00
|
|
|
|
|
|
|
switch (plvdi->item.iSubItem) {
|
|
|
|
case 0:
|
2002-07-20 16:29:26 +00:00
|
|
|
plvdi->item.pszText = _T("(Default)");
|
2002-07-14 17:59:36 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2002-07-18 20:27:52 +00:00
|
|
|
switch (plvdi->item.lParam) {
|
|
|
|
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_LITTLE_ENDIAN:
|
|
|
|
// plvdi->item.pszText = _T("REG_DWORD_LITTLE_ENDIAN");
|
|
|
|
// 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:
|
2002-07-20 16:29:26 +00:00
|
|
|
wsprintf(buffer, _T("unknown(%d)"), plvdi->item.lParam);
|
2002-07-18 20:27:52 +00:00
|
|
|
plvdi->item.pszText = buffer;
|
|
|
|
break;
|
|
|
|
}
|
2002-07-14 17:59:36 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2002-07-16 22:18:29 +00:00
|
|
|
plvdi->item.pszText = _T("(value not set)");
|
2002-07-14 17:59:36 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2002-07-16 22:18:29 +00:00
|
|
|
plvdi->item.pszText = _T("");
|
2002-07-14 17:59:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-07-18 20:27:52 +00:00
|
|
|
|
2002-08-29 18:42:38 +00:00
|
|
|
#if 0
|
2002-07-20 16:29:26 +00:00
|
|
|
static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
|
|
|
|
{
|
|
|
|
TCHAR buf1[1000];
|
|
|
|
TCHAR buf2[1000];
|
|
|
|
|
|
|
|
ListView_GetItemText((HWND)lParamSort, lParam1, 0, buf1, sizeof(buf1));
|
|
|
|
ListView_GetItemText((HWND)lParamSort, lParam2, 0, buf2, sizeof(buf2));
|
|
|
|
return _tcscmp(buf1, buf2);
|
|
|
|
}
|
2002-08-29 18:42:38 +00:00
|
|
|
#endif
|
2002-07-20 16:29:26 +00:00
|
|
|
|
|
|
|
static void ListViewPopUpMenu(HWND hWnd, POINT pt)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-07-14 17:59:36 +00:00
|
|
|
static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch (LOWORD(wParam)) {
|
|
|
|
// case ID_FILE_OPEN:
|
|
|
|
// break;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT CALLBACK ListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch (message) {
|
|
|
|
case WM_COMMAND:
|
|
|
|
if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
|
|
|
|
return CallWindowProc(g_orgListWndProc, hWnd, message, wParam, lParam);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_NOTIFY:
|
|
|
|
switch (((LPNMHDR)lParam)->code) {
|
|
|
|
case LVN_GETDISPINFO:
|
|
|
|
OnGetDispInfo((NMLVDISPINFO*)lParam);
|
|
|
|
break;
|
|
|
|
case NM_DBLCLK:
|
|
|
|
{
|
|
|
|
NMITEMACTIVATE* nmitem = (LPNMITEMACTIVATE)lParam;
|
|
|
|
LVHITTESTINFO info;
|
|
|
|
|
|
|
|
if (nmitem->hdr.hwndFrom != hWnd) break;
|
|
|
|
// if (nmitem->hdr.idFrom != IDW_LISTVIEW) break;
|
|
|
|
// if (nmitem->hdr.code != ???) break;
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
info.pt.x = nmitem->ptAction.x;
|
|
|
|
info.pt.y = nmitem->ptAction.y;
|
|
|
|
if (ListView_HitTest(hWnd, &info) != -1) {
|
|
|
|
LVITEM item;
|
|
|
|
item.mask = LVIF_PARAM;
|
|
|
|
item.iItem = info.iItem;
|
|
|
|
if (ListView_GetItem(hWnd, &item)) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-07-16 22:18:29 +00:00
|
|
|
case NM_RCLICK:
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
LV_HITTESTINFO lvH;
|
2002-07-20 16:29:26 +00:00
|
|
|
NM_LISTVIEW* pNm = (NM_LISTVIEW*)lParam;
|
2002-07-16 22:18:29 +00:00
|
|
|
lvH.pt.x = pNm->ptAction.x;
|
|
|
|
lvH.pt.y = pNm->ptAction.y;
|
|
|
|
idx = ListView_HitTest(hWnd, &lvH);
|
|
|
|
if (idx != -1) {
|
|
|
|
POINT pt;
|
|
|
|
GetCursorPos(&pt);
|
|
|
|
ListViewPopUpMenu(hWnd, pt);
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-07-14 17:59:36 +00:00
|
|
|
default:
|
|
|
|
return CallWindowProc(g_orgListWndProc, hWnd, message, wParam, lParam);
|
|
|
|
}
|
|
|
|
break;
|
2002-07-16 22:18:29 +00:00
|
|
|
case WM_KEYDOWN:
|
|
|
|
if (wParam == VK_TAB) {
|
|
|
|
//TODO: SetFocus(Globals.hDriveBar)
|
|
|
|
//SetFocus(child->nFocusPanel? child->left.hWnd: child->right.hWnd);
|
|
|
|
}
|
2002-07-20 16:29:26 +00:00
|
|
|
// fall thru...
|
2002-07-16 22:18:29 +00:00
|
|
|
default:
|
|
|
|
return CallWindowProc(g_orgListWndProc, hWnd, message, wParam, lParam);
|
|
|
|
break;
|
2002-07-14 17:59:36 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-18 18:16:42 +00:00
|
|
|
HWND CreateListView(HWND hwndParent, int id)
|
2002-07-14 17:59:36 +00:00
|
|
|
{
|
2002-07-20 16:29:26 +00:00
|
|
|
RECT rcClient;
|
|
|
|
HWND hwndLV;
|
2002-07-14 17:59:36 +00:00
|
|
|
|
|
|
|
// Get the dimensions of the parent window's client area, and create the list view control.
|
|
|
|
GetClientRect(hwndParent, &rcClient);
|
2002-07-21 22:57:06 +00:00
|
|
|
hwndLV = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, _T("List View"),
|
|
|
|
WS_VISIBLE | WS_CHILD | LVS_REPORT,
|
2002-07-14 17:59:36 +00:00
|
|
|
0, 0, rcClient.right, rcClient.bottom,
|
|
|
|
hwndParent, (HMENU)id, hInst, NULL);
|
2002-07-18 18:16:42 +00:00
|
|
|
ListView_SetExtendedListViewStyle(hwndLV, LVS_EX_FULLROWSELECT);
|
2002-07-14 17:59:36 +00:00
|
|
|
|
|
|
|
// Initialize the image list, and add items to the control.
|
|
|
|
/*
|
|
|
|
if (!InitListViewImageLists(hwndLV) ||
|
2002-07-20 16:29:26 +00:00
|
|
|
!InitListViewItems(hwndLV, szName)) {
|
2002-07-14 17:59:36 +00:00
|
|
|
DestroyWindow(hwndLV);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
CreateListColumns(hwndLV);
|
|
|
|
g_orgListWndProc = SubclassWindow(hwndLV, ListWndProc);
|
|
|
|
return hwndLV;
|
|
|
|
}
|
|
|
|
|
2002-07-18 20:27:52 +00:00
|
|
|
BOOL RefreshListView(HWND hwndLV, HKEY hKey, LPTSTR keyPath)
|
|
|
|
{
|
2002-07-22 14:41:40 +00:00
|
|
|
if (hwndLV != NULL) {
|
|
|
|
ListView_DeleteAllItems(hwndLV);
|
|
|
|
}
|
2002-07-18 20:27:52 +00:00
|
|
|
|
|
|
|
if (hKey != NULL) {
|
|
|
|
HKEY hNewKey;
|
2002-07-22 14:41:40 +00:00
|
|
|
LONG errCode = RegOpenKeyEx(hKey, keyPath, 0, KEY_READ, &hNewKey);
|
2002-07-18 20:27:52 +00:00
|
|
|
if (errCode == ERROR_SUCCESS) {
|
|
|
|
DWORD max_sub_key_len;
|
|
|
|
DWORD max_val_name_len;
|
|
|
|
DWORD max_val_size;
|
|
|
|
DWORD val_count;
|
|
|
|
ShowWindow(hwndLV, SW_HIDE);
|
|
|
|
/* get size information and resize the buffers if necessary */
|
|
|
|
errCode = RegQueryInfoKey(hNewKey, NULL, NULL, NULL, NULL,
|
|
|
|
&max_sub_key_len, NULL, &val_count, &max_val_name_len, &max_val_size, NULL, NULL);
|
|
|
|
if (errCode == ERROR_SUCCESS) {
|
|
|
|
TCHAR* ValName = malloc(++max_val_name_len * sizeof(TCHAR));
|
|
|
|
DWORD dwValNameLen = max_val_name_len;
|
2002-07-20 16:29:26 +00:00
|
|
|
BYTE* ValBuf = malloc(++max_val_size);
|
2002-07-18 20:27:52 +00:00
|
|
|
DWORD dwValSize = max_val_size;
|
|
|
|
DWORD dwIndex = 0L;
|
|
|
|
DWORD dwValType;
|
2002-07-22 14:41:40 +00:00
|
|
|
// if (RegQueryValueEx(hNewKey, NULL, NULL, &dwValType, ValBuf, &dwValSize) == ERROR_SUCCESS) {
|
|
|
|
// AddEntryToList(hwndLV, _T("(Default)"), dwValType, ValBuf, dwValSize);
|
|
|
|
// }
|
|
|
|
// dwValSize = max_val_size;
|
2002-07-20 16:29:26 +00:00
|
|
|
while (RegEnumValue(hNewKey, dwIndex, ValName, &dwValNameLen, NULL, &dwValType, ValBuf, &dwValSize) == ERROR_SUCCESS) {
|
2002-08-29 18:42:38 +00:00
|
|
|
ValBuf[dwValSize] = 0;
|
2002-07-22 14:41:40 +00:00
|
|
|
AddEntryToList(hwndLV, ValName, dwValType, ValBuf, dwValSize);
|
2002-07-18 20:27:52 +00:00
|
|
|
dwValNameLen = max_val_name_len;
|
|
|
|
dwValSize = max_val_size;
|
|
|
|
dwValType = 0L;
|
|
|
|
++dwIndex;
|
|
|
|
}
|
|
|
|
free(ValBuf);
|
|
|
|
free(ValName);
|
|
|
|
}
|
|
|
|
//ListView_SortItemsEx(hwndLV, CompareFunc, hwndLV);
|
|
|
|
// SendMessage(hwndLV, LVM_SORTITEMSEX, (WPARAM)CompareFunc, (LPARAM)hwndLV);
|
|
|
|
ShowWindow(hwndLV, SW_SHOW);
|
|
|
|
RegCloseKey(hNewKey);
|
|
|
|
}
|
2002-07-14 17:59:36 +00:00
|
|
|
}
|
2002-07-18 20:27:52 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2002-07-14 17:59:36 +00:00
|
|
|
|