2003-08-07 05:10:13 +02:00
|
|
|
/*
|
|
|
|
* Regedit treeview
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
|
2008-08-31 00:57:41 +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
|
|
|
*/
|
|
|
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
|
2003-08-08 23:03:39 +02:00
|
|
|
|
|
|
|
#define NONAMELESSUNION
|
2015-04-02 12:25:02 +02:00
|
|
|
|
2003-08-07 05:10:13 +02:00
|
|
|
#include <windows.h>
|
|
|
|
#include <commctrl.h>
|
|
|
|
#include <stdlib.h>
|
2005-01-10 17:03:22 +01:00
|
|
|
#include <wine/debug.h>
|
2005-10-26 14:07:55 +02:00
|
|
|
#include <shlwapi.h>
|
2003-08-07 05:10:13 +02:00
|
|
|
|
2018-02-07 00:20:07 +01:00
|
|
|
#include "wine/heap.h"
|
2003-08-07 05:10:13 +02:00
|
|
|
#include "main.h"
|
|
|
|
|
2005-01-10 17:03:22 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(regedit);
|
|
|
|
|
2003-08-07 05:10:13 +02:00
|
|
|
/* Global variables and constants */
|
|
|
|
/* Image_Open, Image_Closed, and Image_Root - integer variables for indexes of the images. */
|
|
|
|
/* CX_BITMAP and CY_BITMAP - width and height of an icon. */
|
|
|
|
/* NUM_BITMAPS - number of bitmaps to add to the image list. */
|
|
|
|
int Image_Open;
|
|
|
|
int Image_Closed;
|
|
|
|
int Image_Root;
|
|
|
|
|
2004-01-20 02:33:02 +01:00
|
|
|
#define NUM_ICONS 3
|
2003-08-07 05:10:13 +02:00
|
|
|
|
2005-10-26 14:07:55 +02:00
|
|
|
static BOOL UpdateExpandingTree(HWND hwndTV, HTREEITEM hItem, int state);
|
|
|
|
|
2008-08-31 00:57:41 +02:00
|
|
|
static BOOL get_item_path(HWND hwndTV, HTREEITEM hItem, HKEY* phKey, LPWSTR* pKeyPath, int* pPathLen, int* pMaxChars)
|
2008-08-10 13:52:44 +02:00
|
|
|
{
|
|
|
|
TVITEMW item;
|
|
|
|
int maxChars, chars;
|
2011-04-16 10:07:39 +02:00
|
|
|
HTREEITEM hParent;
|
2008-08-10 13:52:44 +02:00
|
|
|
|
|
|
|
item.mask = TVIF_PARAM;
|
|
|
|
item.hItem = hItem;
|
2008-10-02 10:30:22 +02:00
|
|
|
if (!TreeView_GetItemW(hwndTV, &item)) return FALSE;
|
2008-08-10 13:52:44 +02:00
|
|
|
|
|
|
|
if (item.lParam) {
|
|
|
|
/* found root key with valid key value */
|
|
|
|
*phKey = (HKEY)item.lParam;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-04-16 10:07:39 +02:00
|
|
|
hParent = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)hItem);
|
|
|
|
if(!get_item_path(hwndTV, hParent, phKey, pKeyPath, pPathLen, pMaxChars)) return FALSE;
|
2008-08-10 13:52:44 +02:00
|
|
|
if (*pPathLen) {
|
|
|
|
(*pKeyPath)[*pPathLen] = '\\';
|
|
|
|
++(*pPathLen);
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
item.mask = TVIF_TEXT;
|
|
|
|
item.hItem = hItem;
|
|
|
|
item.pszText = *pKeyPath + *pPathLen;
|
|
|
|
item.cchTextMax = maxChars = *pMaxChars - *pPathLen;
|
|
|
|
if (!TreeView_GetItemW(hwndTV, &item)) return FALSE;
|
|
|
|
chars = lstrlenW(item.pszText);
|
|
|
|
if (chars < maxChars - 1) {
|
|
|
|
*pPathLen += chars;
|
|
|
|
break;
|
|
|
|
}
|
2017-07-28 15:22:18 +02:00
|
|
|
|
2008-08-10 13:52:44 +02:00
|
|
|
*pMaxChars *= 2;
|
2017-07-28 15:22:18 +02:00
|
|
|
*pKeyPath = heap_xrealloc(*pKeyPath, *pMaxChars);
|
2008-08-10 13:52:44 +02:00
|
|
|
} while(TRUE);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-08-31 00:57:41 +02:00
|
|
|
LPWSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey)
|
2008-08-10 13:52:44 +02:00
|
|
|
{
|
2015-12-21 22:55:00 +01:00
|
|
|
int pathLen = 0, maxLen = 1024;
|
2008-08-10 13:52:44 +02:00
|
|
|
WCHAR *pathBuffer;
|
|
|
|
|
2015-12-21 22:55:00 +01:00
|
|
|
if (!hItem) {
|
|
|
|
hItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_CARET, 0);
|
|
|
|
if (!hItem) return NULL;
|
|
|
|
}
|
|
|
|
|
2017-07-28 15:22:18 +02:00
|
|
|
pathBuffer = heap_xalloc(maxLen * sizeof(WCHAR));
|
2008-08-10 13:52:44 +02:00
|
|
|
if (!pathBuffer) return NULL;
|
|
|
|
*pathBuffer = 0;
|
2008-08-31 00:57:41 +02:00
|
|
|
if (!get_item_path(hwndTV, hItem, phRootKey, &pathBuffer, &pathLen, &maxLen)) return NULL;
|
2008-08-10 13:52:44 +02:00
|
|
|
return pathBuffer;
|
|
|
|
}
|
|
|
|
|
2008-08-23 00:44:29 +02:00
|
|
|
static LPWSTR get_path_component(LPCWSTR *lplpKeyName) {
|
|
|
|
LPCWSTR lpPos = *lplpKeyName;
|
|
|
|
LPWSTR lpResult = NULL;
|
2005-09-26 11:57:56 +02:00
|
|
|
int len;
|
|
|
|
if (!lpPos)
|
|
|
|
return NULL;
|
|
|
|
while(*lpPos && *lpPos != '\\')
|
|
|
|
lpPos++;
|
|
|
|
if (*lpPos && lpPos == *lplpKeyName)
|
|
|
|
return NULL;
|
2017-07-28 15:22:18 +02:00
|
|
|
|
2008-08-23 00:44:29 +02:00
|
|
|
len = lpPos+1-(*lplpKeyName);
|
2017-07-28 15:22:18 +02:00
|
|
|
lpResult = heap_xalloc(len * sizeof(WCHAR));
|
|
|
|
|
2008-08-23 00:44:29 +02:00
|
|
|
lstrcpynW(lpResult, *lplpKeyName, len);
|
2005-09-26 11:57:56 +02:00
|
|
|
*lplpKeyName = *lpPos ? lpPos+1 : NULL;
|
|
|
|
return lpResult;
|
|
|
|
}
|
|
|
|
|
2008-08-23 00:44:29 +02:00
|
|
|
HTREEITEM FindPathInTree(HWND hwndTV, LPCWSTR lpKeyName) {
|
|
|
|
TVITEMEXW tvi;
|
|
|
|
WCHAR buf[261]; /* tree view has 260 character limitation on item name */
|
2017-04-03 21:39:46 +02:00
|
|
|
HTREEITEM hRoot, hItem, hOldItem;
|
|
|
|
BOOL valid_path;
|
2005-09-26 11:57:56 +02:00
|
|
|
|
|
|
|
buf[260] = '\0';
|
2017-04-03 21:39:46 +02:00
|
|
|
hRoot = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_ROOT, 0);
|
|
|
|
hItem = hRoot;
|
2008-08-23 00:44:29 +02:00
|
|
|
SendMessageW(hwndTV, TVM_EXPAND, TVE_EXPAND, (LPARAM)hItem );
|
2011-04-16 10:07:39 +02:00
|
|
|
hItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hItem);
|
2005-09-26 11:57:56 +02:00
|
|
|
hOldItem = hItem;
|
2017-04-03 21:39:46 +02:00
|
|
|
valid_path = FALSE;
|
2005-09-26 11:57:56 +02:00
|
|
|
while(1) {
|
2008-08-23 00:44:29 +02:00
|
|
|
LPWSTR lpItemName = get_path_component(&lpKeyName);
|
|
|
|
|
2005-09-26 11:57:56 +02:00
|
|
|
if (lpItemName) {
|
|
|
|
while(hItem) {
|
|
|
|
tvi.mask = TVIF_TEXT | TVIF_HANDLE;
|
|
|
|
tvi.hItem = hItem;
|
|
|
|
tvi.pszText = buf;
|
|
|
|
tvi.cchTextMax = 260;
|
2008-08-23 00:44:29 +02:00
|
|
|
SendMessageW(hwndTV, TVM_GETITEMW, 0, (LPARAM) &tvi);
|
|
|
|
if (!lstrcmpiW(tvi.pszText, lpItemName)) {
|
2017-04-03 21:39:46 +02:00
|
|
|
valid_path = TRUE;
|
2008-08-23 00:44:29 +02:00
|
|
|
SendMessageW(hwndTV, TVM_EXPAND, TVE_EXPAND, (LPARAM)hItem );
|
2005-09-26 11:57:56 +02:00
|
|
|
if (!lpKeyName)
|
2008-08-24 22:10:08 +02:00
|
|
|
{
|
2017-07-28 15:22:18 +02:00
|
|
|
heap_free(lpItemName);
|
2005-09-26 11:57:56 +02:00
|
|
|
return hItem;
|
2008-08-24 22:10:08 +02:00
|
|
|
}
|
2005-09-26 11:57:56 +02:00
|
|
|
hOldItem = hItem;
|
2011-04-16 10:07:39 +02:00
|
|
|
hItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hItem);
|
2005-09-26 11:57:56 +02:00
|
|
|
break;
|
|
|
|
}
|
2011-04-16 10:07:39 +02:00
|
|
|
hItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)hItem);
|
2005-09-26 11:57:56 +02:00
|
|
|
}
|
2017-07-28 15:22:18 +02:00
|
|
|
heap_free(lpItemName);
|
2005-09-26 11:57:56 +02:00
|
|
|
if (!hItem)
|
2017-04-03 21:39:46 +02:00
|
|
|
return valid_path ? hOldItem : hRoot;
|
2005-09-26 11:57:56 +02:00
|
|
|
}
|
|
|
|
else
|
2017-04-03 21:39:46 +02:00
|
|
|
return valid_path ? hItem : hRoot;
|
2005-09-26 11:57:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-15 21:19:38 +01:00
|
|
|
BOOL DeleteNode(HWND hwndTV, HTREEITEM hItem)
|
|
|
|
{
|
2011-04-16 10:07:39 +02:00
|
|
|
if (!hItem) hItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_CARET, 0);
|
2004-03-15 21:19:38 +01:00
|
|
|
if (!hItem) return FALSE;
|
2011-04-16 10:07:39 +02:00
|
|
|
return (BOOL)SendMessageW(hwndTV, TVM_DELETEITEM, 0, (LPARAM)hItem);
|
2004-03-15 21:19:38 +01:00
|
|
|
}
|
|
|
|
|
2005-01-10 17:03:22 +01:00
|
|
|
/* Add an entry to the tree. Only give hKey for root nodes (HKEY_ constants) */
|
2008-08-22 00:12:09 +02:00
|
|
|
static HTREEITEM AddEntryToTree(HWND hwndTV, HTREEITEM hParent, LPWSTR label, HKEY hKey, DWORD dwChildren)
|
2003-08-07 05:10:13 +02:00
|
|
|
{
|
2008-08-23 00:22:27 +02:00
|
|
|
TVINSERTSTRUCTW tvins;
|
2003-08-07 05:10:13 +02:00
|
|
|
|
2005-01-10 17:03:22 +01:00
|
|
|
if (hKey) {
|
2008-08-22 00:12:09 +02:00
|
|
|
if (RegQueryInfoKeyW(hKey, 0, 0, 0, &dwChildren, 0, 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS) {
|
2005-01-10 17:03:22 +01:00
|
|
|
dwChildren = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-01 12:36:05 +01:00
|
|
|
tvins.u.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
|
2008-08-23 00:22:27 +02:00
|
|
|
tvins.u.item.pszText = label;
|
|
|
|
tvins.u.item.cchTextMax = lstrlenW(label);
|
2005-12-01 12:36:05 +01:00
|
|
|
tvins.u.item.iImage = Image_Closed;
|
|
|
|
tvins.u.item.iSelectedImage = Image_Open;
|
|
|
|
tvins.u.item.cChildren = dwChildren;
|
|
|
|
tvins.u.item.lParam = (LPARAM)hKey;
|
2008-12-04 05:32:06 +01:00
|
|
|
tvins.hInsertAfter = hKey ? TVI_LAST : TVI_SORT;
|
2003-08-07 05:10:13 +02:00
|
|
|
tvins.hParent = hParent;
|
2008-08-23 00:22:27 +02:00
|
|
|
|
|
|
|
return TreeView_InsertItemW(hwndTV, &tvins);
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
|
|
|
|
2008-08-25 22:21:58 +02:00
|
|
|
static BOOL match_string(LPCWSTR sstring1, LPCWSTR sstring2, int mode)
|
2005-10-26 14:07:55 +02:00
|
|
|
{
|
|
|
|
if (mode & SEARCH_WHOLE)
|
2008-08-25 22:21:58 +02:00
|
|
|
return !lstrcmpiW(sstring1, sstring2);
|
2005-10-26 14:07:55 +02:00
|
|
|
else
|
2008-08-25 22:21:58 +02:00
|
|
|
return NULL != StrStrIW(sstring1, sstring2);
|
2005-10-26 14:07:55 +02:00
|
|
|
}
|
|
|
|
|
2008-08-25 22:21:58 +02:00
|
|
|
static BOOL match_item(HWND hwndTV, HTREEITEM hItem, LPCWSTR sstring, int mode, int *row)
|
2005-10-26 14:07:55 +02:00
|
|
|
{
|
2008-08-25 22:21:58 +02:00
|
|
|
TVITEMW item;
|
|
|
|
WCHAR keyname[KEY_MAX_LEN];
|
2005-10-26 14:07:55 +02:00
|
|
|
item.mask = TVIF_TEXT;
|
|
|
|
item.hItem = hItem;
|
|
|
|
item.pszText = keyname;
|
|
|
|
item.cchTextMax = KEY_MAX_LEN;
|
2008-10-02 10:30:22 +02:00
|
|
|
if (!TreeView_GetItemW(hwndTV, &item)) return FALSE;
|
2005-10-26 14:07:55 +02:00
|
|
|
if ((mode & SEARCH_KEYS) && match_string(keyname, sstring, mode)) {
|
|
|
|
*row = -1;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode & (SEARCH_VALUES | SEARCH_CONTENT)) {
|
|
|
|
int i, adjust;
|
2015-06-30 14:38:04 +02:00
|
|
|
WCHAR *valName, *KeyPath;
|
2005-10-26 14:07:55 +02:00
|
|
|
HKEY hKey, hRoot;
|
2015-06-30 14:38:04 +02:00
|
|
|
DWORD lenName, lenNameMax, lenValueMax;
|
|
|
|
WCHAR *buffer = NULL;
|
2005-10-26 14:07:55 +02:00
|
|
|
|
2008-08-31 00:57:41 +02:00
|
|
|
KeyPath = GetItemPath(hwndTV, hItem, &hRoot);
|
2005-10-26 14:07:55 +02:00
|
|
|
|
|
|
|
if (!KeyPath || !hRoot)
|
|
|
|
return FALSE;
|
|
|
|
|
2008-08-25 22:21:58 +02:00
|
|
|
if (RegOpenKeyExW(hRoot, KeyPath, 0, KEY_READ, &hKey) != ERROR_SUCCESS) {
|
2017-07-28 15:22:18 +02:00
|
|
|
heap_free(KeyPath);
|
2005-10-26 14:07:55 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-08-25 22:21:58 +02:00
|
|
|
|
2017-07-28 15:22:18 +02:00
|
|
|
heap_free(KeyPath);
|
2015-06-30 14:38:04 +02:00
|
|
|
|
|
|
|
if (ERROR_SUCCESS != RegQueryInfoKeyW(hKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &lenNameMax, &lenValueMax, NULL, NULL))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
lenName = ++lenNameMax;
|
2017-07-28 15:22:18 +02:00
|
|
|
valName = heap_xalloc(lenName * sizeof(WCHAR));
|
2015-06-30 14:38:04 +02:00
|
|
|
|
2005-10-26 14:07:55 +02:00
|
|
|
adjust = 0;
|
2017-07-28 15:22:18 +02:00
|
|
|
|
2005-10-26 14:07:55 +02:00
|
|
|
/* RegEnumValue won't return empty default value, so fake it when dealing with *row,
|
|
|
|
which corresponds to list view rows, not value ids */
|
2008-08-25 22:21:58 +02:00
|
|
|
if (ERROR_SUCCESS == RegEnumValueW(hKey, 0, valName, &lenName, NULL, NULL, NULL, NULL) && *valName)
|
2005-10-26 14:07:55 +02:00
|
|
|
adjust = 1;
|
|
|
|
|
|
|
|
i = (*row)-adjust;
|
|
|
|
if (i < 0) i = 0;
|
|
|
|
while(1) {
|
|
|
|
DWORD lenValue = 0, type = 0;
|
2015-06-30 14:38:04 +02:00
|
|
|
lenName = lenNameMax;
|
2005-10-26 14:07:55 +02:00
|
|
|
|
2008-08-25 22:21:58 +02:00
|
|
|
if (ERROR_SUCCESS != RegEnumValueW(hKey,
|
2015-06-30 14:38:04 +02:00
|
|
|
i, valName, &lenName, NULL, &type, NULL, NULL))
|
2005-10-26 14:07:55 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (mode & SEARCH_VALUES) {
|
|
|
|
if (match_string(valName, sstring, mode)) {
|
2017-07-28 15:22:18 +02:00
|
|
|
heap_free(valName);
|
|
|
|
heap_free(buffer);
|
2005-10-26 14:07:55 +02:00
|
|
|
RegCloseKey(hKey);
|
|
|
|
*row = i+adjust;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((mode & SEARCH_CONTENT) && (type == REG_EXPAND_SZ || type == REG_SZ)) {
|
2015-06-30 14:38:04 +02:00
|
|
|
if (!buffer)
|
2017-07-28 15:22:18 +02:00
|
|
|
buffer = heap_xalloc(lenValueMax);
|
|
|
|
|
2015-06-30 14:38:04 +02:00
|
|
|
lenName = lenNameMax;
|
|
|
|
lenValue = lenValueMax;
|
|
|
|
if (ERROR_SUCCESS != RegEnumValueW(hKey, i, valName, &lenName, NULL, &type, (LPBYTE)buffer, &lenValue))
|
2008-10-02 10:35:59 +02:00
|
|
|
break;
|
2005-10-26 14:07:55 +02:00
|
|
|
if (match_string(buffer, sstring, mode)) {
|
2017-07-28 15:22:18 +02:00
|
|
|
heap_free(valName);
|
|
|
|
heap_free(buffer);
|
2005-10-26 14:07:55 +02:00
|
|
|
RegCloseKey(hKey);
|
|
|
|
*row = i+adjust;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
2017-07-28 15:22:18 +02:00
|
|
|
heap_free(valName);
|
|
|
|
heap_free(buffer);
|
2005-10-26 14:07:55 +02:00
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-08-25 22:21:58 +02:00
|
|
|
HTREEITEM FindNext(HWND hwndTV, HTREEITEM hItem, LPCWSTR sstring, int mode, int *row)
|
2005-10-26 14:07:55 +02:00
|
|
|
{
|
|
|
|
HTREEITEM hTry, hLast;
|
|
|
|
|
|
|
|
hLast = hItem;
|
|
|
|
(*row)++;
|
|
|
|
if (match_item(hwndTV, hLast, sstring, mode & ~SEARCH_KEYS, row)) {
|
|
|
|
return hLast;
|
|
|
|
}
|
|
|
|
*row = 0;
|
|
|
|
|
|
|
|
while(hLast) {
|
|
|
|
/* first look in subtree */
|
|
|
|
/* no children? maybe we haven't loaded them yet? */
|
2011-04-16 10:07:39 +02:00
|
|
|
if (!SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hLast)) {
|
|
|
|
UINT state = (UINT)SendMessageW(hwndTV, TVM_GETITEMSTATE, (WPARAM)hLast, -1);
|
|
|
|
UpdateExpandingTree(hwndTV, hLast, state);
|
2005-10-26 14:07:55 +02:00
|
|
|
}
|
2011-04-16 10:07:39 +02:00
|
|
|
hTry = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hLast);
|
2005-10-26 14:07:55 +02:00
|
|
|
if (hTry) {
|
|
|
|
if (match_item(hwndTV, hTry, sstring, mode, row))
|
|
|
|
return hTry;
|
|
|
|
hLast = hTry;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* no more children, maybe there are any siblings? */
|
2011-04-16 10:07:39 +02:00
|
|
|
hTry = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)hLast);
|
2005-10-26 14:07:55 +02:00
|
|
|
if (hTry) {
|
|
|
|
if (match_item(hwndTV, hTry, sstring, mode, row))
|
|
|
|
return hTry;
|
|
|
|
hLast = hTry;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* no more siblings, look at the next siblings in parent(s) */
|
2011-04-16 10:07:39 +02:00
|
|
|
hLast = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)hLast);
|
2005-10-26 14:07:55 +02:00
|
|
|
if (!hLast)
|
|
|
|
return NULL;
|
2011-04-16 10:07:39 +02:00
|
|
|
while (hLast && (hTry = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)hLast)) == NULL) {
|
|
|
|
hLast = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)hLast);
|
2005-10-26 14:07:55 +02:00
|
|
|
}
|
|
|
|
if (match_item(hwndTV, hTry, sstring, mode, row))
|
|
|
|
return hTry;
|
|
|
|
hLast = hTry;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-06-04 12:01:25 +02:00
|
|
|
static BOOL RefreshTreeItem(HWND hwndTV, HTREEITEM hItem)
|
2005-01-10 17:03:22 +01:00
|
|
|
{
|
|
|
|
HKEY hRoot, hKey, hSubKey;
|
|
|
|
HTREEITEM childItem;
|
2008-08-22 00:12:09 +02:00
|
|
|
LPWSTR KeyPath;
|
2005-01-10 17:03:22 +01:00
|
|
|
DWORD dwCount, dwIndex, dwMaxSubKeyLen;
|
2008-08-22 00:12:09 +02:00
|
|
|
LPWSTR Name;
|
2008-08-23 00:22:27 +02:00
|
|
|
TVITEMW tvItem;
|
2005-01-10 17:03:22 +01:00
|
|
|
|
2005-10-26 14:07:55 +02:00
|
|
|
hRoot = NULL;
|
2008-08-31 00:57:41 +02:00
|
|
|
KeyPath = GetItemPath(hwndTV, hItem, &hRoot);
|
2005-01-10 17:03:22 +01:00
|
|
|
|
2005-10-26 14:07:55 +02:00
|
|
|
if (!KeyPath || !hRoot)
|
|
|
|
return FALSE;
|
|
|
|
|
2005-01-10 17:03:22 +01:00
|
|
|
if (*KeyPath) {
|
2008-08-22 00:12:09 +02:00
|
|
|
if (RegOpenKeyExW(hRoot, KeyPath, 0, KEY_READ, &hKey) != ERROR_SUCCESS) {
|
|
|
|
WINE_TRACE("RegOpenKeyEx failed, %s was probably removed.\n", wine_dbgstr_w(KeyPath));
|
2005-01-10 17:03:22 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
hKey = hRoot;
|
|
|
|
}
|
2017-07-28 15:22:18 +02:00
|
|
|
heap_free(KeyPath);
|
2005-01-10 17:03:22 +01:00
|
|
|
|
2008-08-22 00:12:09 +02:00
|
|
|
if (RegQueryInfoKeyW(hKey, 0, 0, 0, &dwCount, &dwMaxSubKeyLen, 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS) {
|
2005-01-10 17:03:22 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the number of children again */
|
|
|
|
tvItem.mask = TVIF_CHILDREN;
|
|
|
|
tvItem.hItem = hItem;
|
|
|
|
tvItem.cChildren = dwCount;
|
2008-08-23 00:22:27 +02:00
|
|
|
if (!TreeView_SetItemW(hwndTV, &tvItem)) {
|
2005-01-10 17:03:22 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We don't have to bother with the rest if it's not expanded. */
|
2011-04-16 10:07:39 +02:00
|
|
|
if (SendMessageW(hwndTV, TVM_GETITEMSTATE, (WPARAM)hItem, TVIS_EXPANDED) == 0) {
|
2005-01-10 17:03:22 +01:00
|
|
|
RegCloseKey(hKey);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
dwMaxSubKeyLen++; /* account for the \0 terminator */
|
2017-07-28 15:22:18 +02:00
|
|
|
Name = heap_xalloc(dwMaxSubKeyLen * sizeof(WCHAR));
|
|
|
|
|
2005-01-10 17:03:22 +01:00
|
|
|
tvItem.cchTextMax = dwMaxSubKeyLen;
|
2017-07-28 15:22:18 +02:00
|
|
|
tvItem.pszText = heap_xalloc(dwMaxSubKeyLen * sizeof(WCHAR));
|
2005-01-10 17:03:22 +01:00
|
|
|
|
|
|
|
/* Now go through all the children in the registry, and check if any have to be added. */
|
|
|
|
for (dwIndex = 0; dwIndex < dwCount; dwIndex++) {
|
|
|
|
DWORD cName = dwMaxSubKeyLen, dwSubCount;
|
|
|
|
BOOL found;
|
|
|
|
|
|
|
|
found = FALSE;
|
2008-08-22 00:12:09 +02:00
|
|
|
if (RegEnumKeyExW(hKey, dwIndex, Name, &cName, 0, 0, 0, NULL) != ERROR_SUCCESS) {
|
2005-01-10 17:03:22 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the number of children of the node. */
|
|
|
|
dwSubCount = 0;
|
2008-08-22 00:12:09 +02:00
|
|
|
if (RegOpenKeyExW(hKey, Name, 0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS) {
|
2011-04-16 10:07:39 +02:00
|
|
|
if (RegQueryInfoKeyW(hSubKey, 0, 0, 0, &dwSubCount, 0, 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS) {
|
2005-01-10 17:03:22 +01:00
|
|
|
dwSubCount = 0;
|
|
|
|
}
|
|
|
|
RegCloseKey(hSubKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the node is already in there. */
|
2011-04-16 10:07:39 +02:00
|
|
|
for (childItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hItem); childItem;
|
|
|
|
childItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)childItem)) {
|
2005-01-10 17:03:22 +01:00
|
|
|
tvItem.mask = TVIF_TEXT;
|
|
|
|
tvItem.hItem = childItem;
|
2008-08-23 00:22:27 +02:00
|
|
|
if (!TreeView_GetItemW(hwndTV, &tvItem)) {
|
2017-07-28 15:22:18 +02:00
|
|
|
heap_free(Name);
|
|
|
|
heap_free(tvItem.pszText);
|
2005-01-10 17:03:22 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-08-23 00:22:27 +02:00
|
|
|
if (!lstrcmpiW(tvItem.pszText, Name)) {
|
2005-01-10 17:03:22 +01:00
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found == FALSE) {
|
2008-08-23 00:22:27 +02:00
|
|
|
WINE_TRACE("New subkey %s\n", wine_dbgstr_w(Name));
|
2005-01-10 17:03:22 +01:00
|
|
|
AddEntryToTree(hwndTV, hItem, Name, NULL, dwSubCount);
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 15:22:18 +02:00
|
|
|
heap_free(Name);
|
|
|
|
heap_free(tvItem.pszText);
|
2005-01-10 17:03:22 +01:00
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
|
|
|
/* Now go through all the children in the tree, and check if any have to be removed. */
|
2011-04-16 10:07:39 +02:00
|
|
|
childItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hItem);
|
2005-01-10 17:03:22 +01:00
|
|
|
while (childItem) {
|
2011-04-16 10:07:39 +02:00
|
|
|
HTREEITEM nextItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)childItem);
|
2005-01-10 17:03:22 +01:00
|
|
|
if (RefreshTreeItem(hwndTV, childItem) == FALSE) {
|
2008-08-23 00:22:27 +02:00
|
|
|
SendMessageW(hwndTV, TVM_DELETEITEM, 0, (LPARAM)childItem);
|
2005-01-10 17:03:22 +01:00
|
|
|
}
|
|
|
|
childItem = nextItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-02-17 16:09:53 +01:00
|
|
|
static void treeview_sort_item(HWND hWnd, HTREEITEM item)
|
|
|
|
{
|
|
|
|
HTREEITEM child = (HTREEITEM)SendMessageW(hWnd, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)item);
|
|
|
|
|
|
|
|
while (child != NULL) {
|
|
|
|
treeview_sort_item(hWnd, child);
|
|
|
|
child = (HTREEITEM)SendMessageW(hWnd, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)child);
|
|
|
|
}
|
|
|
|
SendMessageW(hWnd, TVM_SORTCHILDREN, 0, (LPARAM)item);
|
|
|
|
}
|
|
|
|
|
2005-01-10 17:03:22 +01:00
|
|
|
BOOL RefreshTreeView(HWND hwndTV)
|
|
|
|
{
|
|
|
|
HTREEITEM hItem;
|
|
|
|
HTREEITEM hSelectedItem;
|
|
|
|
HCURSOR hcursorOld;
|
2011-04-16 10:07:39 +02:00
|
|
|
HTREEITEM hRoot;
|
2005-01-10 17:03:22 +01:00
|
|
|
|
|
|
|
WINE_TRACE("\n");
|
2011-04-16 10:07:39 +02:00
|
|
|
hSelectedItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_CARET, 0);
|
|
|
|
hcursorOld = SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_WAIT));
|
2008-08-25 23:03:17 +02:00
|
|
|
SendMessageW(hwndTV, WM_SETREDRAW, FALSE, 0);
|
2005-01-10 17:03:22 +01:00
|
|
|
|
2011-04-16 10:07:39 +02:00
|
|
|
hRoot = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_ROOT, 0);
|
|
|
|
hItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hRoot);
|
2005-01-10 17:03:22 +01:00
|
|
|
while (hItem) {
|
|
|
|
RefreshTreeItem(hwndTV, hItem);
|
2017-02-17 16:09:53 +01:00
|
|
|
treeview_sort_item(hwndTV, hItem);
|
2011-04-16 10:07:39 +02:00
|
|
|
hItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)hItem);
|
2005-01-10 17:03:22 +01:00
|
|
|
}
|
|
|
|
|
2008-08-25 23:03:17 +02:00
|
|
|
SendMessageW(hwndTV, WM_SETREDRAW, TRUE, 0);
|
2005-10-26 14:07:55 +02:00
|
|
|
InvalidateRect(hwndTV, NULL, FALSE);
|
2005-01-10 17:03:22 +01:00
|
|
|
SetCursor(hcursorOld);
|
|
|
|
|
|
|
|
/* We reselect the currently selected node, this will prompt a refresh of the listview. */
|
2008-08-25 23:03:17 +02:00
|
|
|
SendMessageW(hwndTV, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hSelectedItem);
|
2005-01-10 17:03:22 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
2003-08-07 05:10:13 +02:00
|
|
|
|
2008-08-21 23:49:34 +02:00
|
|
|
HTREEITEM InsertNode(HWND hwndTV, HTREEITEM hItem, LPWSTR name)
|
2004-03-15 21:19:38 +01:00
|
|
|
{
|
2008-08-23 00:22:27 +02:00
|
|
|
WCHAR buf[MAX_NEW_KEY_LEN];
|
2004-03-15 21:19:38 +01:00
|
|
|
HTREEITEM hNewItem = 0;
|
2008-08-23 00:22:27 +02:00
|
|
|
TVITEMEXW item;
|
2004-03-15 21:19:38 +01:00
|
|
|
|
2011-04-16 10:07:39 +02:00
|
|
|
if (!hItem) hItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_CARET, 0);
|
2004-03-15 21:19:38 +01:00
|
|
|
if (!hItem) return FALSE;
|
2012-06-02 08:46:40 +02:00
|
|
|
if (SendMessageW(hwndTV, TVM_GETITEMSTATE, (WPARAM)hItem, TVIS_EXPANDEDONCE) & TVIS_EXPANDEDONCE) {
|
2011-04-16 10:07:39 +02:00
|
|
|
hNewItem = AddEntryToTree(hwndTV, hItem, name, 0, 0);
|
2004-03-15 21:19:38 +01:00
|
|
|
} else {
|
|
|
|
item.mask = TVIF_CHILDREN | TVIF_HANDLE;
|
|
|
|
item.hItem = hItem;
|
2008-08-23 00:22:27 +02:00
|
|
|
if (!TreeView_GetItemW(hwndTV, &item)) return FALSE;
|
2004-03-15 21:19:38 +01:00
|
|
|
item.cChildren = 1;
|
2008-08-23 00:22:27 +02:00
|
|
|
if (!TreeView_SetItemW(hwndTV, &item)) return FALSE;
|
2004-03-15 21:19:38 +01:00
|
|
|
}
|
2008-08-21 23:49:34 +02:00
|
|
|
SendMessageW(hwndTV, TVM_EXPAND, TVE_EXPAND, (LPARAM)hItem );
|
2004-03-15 21:19:38 +01:00
|
|
|
if (!hNewItem) {
|
2011-04-16 10:07:39 +02:00
|
|
|
for(hNewItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hItem); hNewItem;
|
|
|
|
hNewItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)hNewItem)) {
|
|
|
|
item.mask = TVIF_HANDLE | TVIF_TEXT;
|
|
|
|
item.hItem = hNewItem;
|
|
|
|
item.pszText = buf;
|
2018-05-21 15:34:49 +02:00
|
|
|
item.cchTextMax = ARRAY_SIZE(buf);
|
2011-04-16 10:07:39 +02:00
|
|
|
if (!TreeView_GetItemW(hwndTV, &item)) continue;
|
|
|
|
if (lstrcmpW(name, item.pszText) == 0) break;
|
|
|
|
}
|
2004-03-15 21:19:38 +01:00
|
|
|
}
|
2006-03-17 10:34:05 +01:00
|
|
|
if (hNewItem)
|
2008-08-21 23:49:34 +02:00
|
|
|
SendMessageW(hwndTV, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hNewItem);
|
2004-03-15 21:19:38 +01:00
|
|
|
|
|
|
|
return hNewItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND StartKeyRename(HWND hwndTV)
|
|
|
|
{
|
|
|
|
HTREEITEM hItem;
|
|
|
|
|
2011-04-16 10:07:39 +02:00
|
|
|
if(!(hItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_CARET, 0))) return 0;
|
2017-01-03 13:33:48 +01:00
|
|
|
SetWindowLongPtrW(hwndTV, GWLP_USERDATA, 1);
|
2011-04-16 10:07:39 +02:00
|
|
|
return (HWND)SendMessageW(hwndTV, TVM_EDITLABELW, 0, (LPARAM)hItem);
|
2004-03-15 21:19:38 +01:00
|
|
|
}
|
|
|
|
|
2008-08-25 23:00:35 +02:00
|
|
|
static BOOL InitTreeViewItems(HWND hwndTV, LPWSTR pHostName)
|
2003-08-07 05:10:13 +02:00
|
|
|
{
|
2008-08-25 23:00:35 +02:00
|
|
|
TVINSERTSTRUCTW tvins;
|
2003-08-07 05:10:13 +02:00
|
|
|
HTREEITEM hRoot;
|
2022-04-14 15:01:38 +02:00
|
|
|
static WCHAR hkcr[] = L"HKEY_CLASSES_ROOT",
|
|
|
|
hkcu[] = L"HKEY_CURRENT_USER",
|
|
|
|
hklm[] = L"HKEY_LOCAL_MACHINE",
|
|
|
|
hku[] = L"HKEY_USERS",
|
|
|
|
hkcc[] = L"HKEY_CURRENT_CONFIG",
|
|
|
|
hkdd[] = L"HKEY_DYN_DATA";
|
2003-08-07 05:10:13 +02:00
|
|
|
|
2005-12-01 12:36:05 +01:00
|
|
|
tvins.u.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
|
2003-08-07 05:10:13 +02:00
|
|
|
/* Set the text of the item. */
|
2005-12-01 12:36:05 +01:00
|
|
|
tvins.u.item.pszText = pHostName;
|
2008-08-25 23:00:35 +02:00
|
|
|
tvins.u.item.cchTextMax = lstrlenW(pHostName);
|
2003-08-07 05:10:13 +02:00
|
|
|
/* Assume the item is not a parent item, so give it an image. */
|
2005-12-01 12:36:05 +01:00
|
|
|
tvins.u.item.iImage = Image_Root;
|
|
|
|
tvins.u.item.iSelectedImage = Image_Root;
|
|
|
|
tvins.u.item.cChildren = 5;
|
2003-08-07 05:10:13 +02:00
|
|
|
/* Save the heading level in the item's application-defined data area. */
|
2008-11-02 00:27:00 +01:00
|
|
|
tvins.u.item.lParam = 0;
|
2008-12-04 05:32:06 +01:00
|
|
|
tvins.hInsertAfter = TVI_FIRST;
|
2003-08-07 05:10:13 +02:00
|
|
|
tvins.hParent = TVI_ROOT;
|
|
|
|
/* Add the item to the tree view control. */
|
2008-08-25 23:00:35 +02:00
|
|
|
if (!(hRoot = TreeView_InsertItemW(hwndTV, &tvins))) return FALSE;
|
2003-08-07 05:10:13 +02:00
|
|
|
|
2006-08-10 21:29:43 +02:00
|
|
|
if (!AddEntryToTree(hwndTV, hRoot, hkcr, HKEY_CLASSES_ROOT, 1)) return FALSE;
|
|
|
|
if (!AddEntryToTree(hwndTV, hRoot, hkcu, HKEY_CURRENT_USER, 1)) return FALSE;
|
|
|
|
if (!AddEntryToTree(hwndTV, hRoot, hklm, HKEY_LOCAL_MACHINE, 1)) return FALSE;
|
|
|
|
if (!AddEntryToTree(hwndTV, hRoot, hku, HKEY_USERS, 1)) return FALSE;
|
|
|
|
if (!AddEntryToTree(hwndTV, hRoot, hkcc, HKEY_CURRENT_CONFIG, 1)) return FALSE;
|
|
|
|
if (!AddEntryToTree(hwndTV, hRoot, hkdd, HKEY_DYN_DATA, 1)) return FALSE;
|
|
|
|
|
2003-08-07 05:10:13 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-12-12 05:08:59 +01:00
|
|
|
|
2003-08-07 05:10:13 +02:00
|
|
|
/*
|
|
|
|
* InitTreeViewImageLists - creates an image list, adds three bitmaps
|
|
|
|
* to it, and associates the image list with a tree view control.
|
|
|
|
* Returns TRUE if successful, or FALSE otherwise.
|
|
|
|
* hwndTV - handle to the tree view control.
|
|
|
|
*/
|
|
|
|
static BOOL InitTreeViewImageLists(HWND hwndTV)
|
|
|
|
{
|
|
|
|
HIMAGELIST himl; /* handle to image list */
|
2004-01-20 02:33:02 +01:00
|
|
|
HICON hico; /* handle to icon */
|
2017-04-27 15:27:21 +02:00
|
|
|
INT cx = GetSystemMetrics(SM_CXSMICON);
|
|
|
|
INT cy = GetSystemMetrics(SM_CYSMICON);
|
2003-08-07 05:10:13 +02:00
|
|
|
|
|
|
|
/* Create the image list. */
|
2017-04-27 15:27:21 +02:00
|
|
|
if ((himl = ImageList_Create(cx, cy, ILC_MASK, 0, NUM_ICONS)) == NULL)
|
2003-08-07 05:10:13 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Add the open file, closed file, and document bitmaps. */
|
2008-08-25 23:00:35 +02:00
|
|
|
hico = LoadIconW(hInst, MAKEINTRESOURCEW(IDI_OPEN_FILE));
|
2004-01-20 02:33:02 +01:00
|
|
|
Image_Open = ImageList_AddIcon(himl, hico);
|
2003-08-07 05:10:13 +02:00
|
|
|
|
2008-08-25 23:00:35 +02:00
|
|
|
hico = LoadIconW(hInst, MAKEINTRESOURCEW(IDI_CLOSED_FILE));
|
2004-01-20 02:33:02 +01:00
|
|
|
Image_Closed = ImageList_AddIcon(himl, hico);
|
2003-08-07 05:10:13 +02:00
|
|
|
|
2008-08-25 23:00:35 +02:00
|
|
|
hico = LoadIconW(hInst, MAKEINTRESOURCEW(IDI_ROOT));
|
2004-01-20 02:33:02 +01:00
|
|
|
Image_Root = ImageList_AddIcon(himl, hico);
|
2003-08-07 05:10:13 +02:00
|
|
|
|
|
|
|
/* Fail if not all of the images were added. */
|
2004-01-20 02:33:02 +01:00
|
|
|
if (ImageList_GetImageCount(himl) < NUM_ICONS)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-08-07 05:10:13 +02:00
|
|
|
|
|
|
|
/* Associate the image list with the tree view control. */
|
2008-08-25 23:00:35 +02:00
|
|
|
SendMessageW(hwndTV, TVM_SETIMAGELIST, TVSIL_NORMAL, (LPARAM)himl);
|
2003-08-07 05:10:13 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-10-26 14:07:55 +02:00
|
|
|
BOOL UpdateExpandingTree(HWND hwndTV, HTREEITEM hItem, int state)
|
2003-08-07 05:10:13 +02:00
|
|
|
{
|
2003-12-12 05:08:59 +01:00
|
|
|
DWORD dwCount, dwIndex, dwMaxSubKeyLen;
|
|
|
|
HKEY hRoot, hNewKey, hKey;
|
2008-08-22 00:12:09 +02:00
|
|
|
LPWSTR keyPath;
|
|
|
|
LPWSTR Name;
|
2003-12-12 05:08:59 +01:00
|
|
|
LONG errCode;
|
2004-06-14 21:34:58 +02:00
|
|
|
HCURSOR hcursorOld;
|
2011-04-16 10:07:39 +02:00
|
|
|
TVITEMW item;
|
2003-08-07 05:10:13 +02:00
|
|
|
|
|
|
|
static int expanding;
|
|
|
|
if (expanding) return FALSE;
|
2005-10-26 14:07:55 +02:00
|
|
|
if (state & TVIS_EXPANDEDONCE ) {
|
2003-08-07 05:10:13 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
expanding = TRUE;
|
2011-04-16 10:07:39 +02:00
|
|
|
hcursorOld = SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_WAIT));
|
2008-08-22 00:12:09 +02:00
|
|
|
SendMessageW(hwndTV, WM_SETREDRAW, FALSE, 0);
|
2003-08-07 05:10:13 +02:00
|
|
|
|
2008-08-31 00:57:41 +02:00
|
|
|
keyPath = GetItemPath(hwndTV, hItem, &hRoot);
|
2003-12-12 05:08:59 +01:00
|
|
|
if (!keyPath) goto done;
|
|
|
|
|
|
|
|
if (*keyPath) {
|
2008-08-22 00:12:09 +02:00
|
|
|
errCode = RegOpenKeyExW(hRoot, keyPath, 0, KEY_READ, &hNewKey);
|
2003-12-12 05:08:59 +01:00
|
|
|
if (errCode != ERROR_SUCCESS) goto done;
|
2003-08-07 05:10:13 +02:00
|
|
|
} else {
|
2003-12-12 05:08:59 +01:00
|
|
|
hNewKey = hRoot;
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
|
|
|
|
2008-08-22 00:12:09 +02:00
|
|
|
errCode = RegQueryInfoKeyW(hNewKey, 0, 0, 0, &dwCount, &dwMaxSubKeyLen, 0, 0, 0, 0, 0, 0);
|
2003-12-12 05:08:59 +01:00
|
|
|
if (errCode != ERROR_SUCCESS) goto done;
|
|
|
|
dwMaxSubKeyLen++; /* account for the \0 terminator */
|
2017-07-28 15:22:18 +02:00
|
|
|
Name = heap_xalloc(dwMaxSubKeyLen * sizeof(WCHAR));
|
2003-12-12 05:08:59 +01:00
|
|
|
|
|
|
|
for (dwIndex = 0; dwIndex < dwCount; dwIndex++) {
|
2005-01-10 17:03:22 +01:00
|
|
|
DWORD cName = dwMaxSubKeyLen, dwSubCount;
|
|
|
|
|
2008-08-22 00:12:09 +02:00
|
|
|
errCode = RegEnumKeyExW(hNewKey, dwIndex, Name, &cName, 0, 0, 0, 0);
|
2005-01-10 17:03:22 +01:00
|
|
|
if (errCode != ERROR_SUCCESS) continue;
|
2008-08-22 00:12:09 +02:00
|
|
|
errCode = RegOpenKeyExW(hNewKey, Name, 0, KEY_QUERY_VALUE, &hKey);
|
2005-01-10 17:03:22 +01:00
|
|
|
if (errCode == ERROR_SUCCESS) {
|
2008-08-22 00:12:09 +02:00
|
|
|
errCode = RegQueryInfoKeyW(hKey, 0, 0, 0, &dwSubCount, 0, 0, 0, 0, 0, 0, 0);
|
2005-01-10 17:03:22 +01:00
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
if (errCode != ERROR_SUCCESS) dwSubCount = 0;
|
2005-10-26 14:07:55 +02:00
|
|
|
AddEntryToTree(hwndTV, hItem, Name, NULL, dwSubCount);
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
2003-12-12 05:08:59 +01:00
|
|
|
RegCloseKey(hNewKey);
|
2017-07-28 15:22:18 +02:00
|
|
|
heap_free(Name);
|
2003-12-12 05:08:59 +01:00
|
|
|
|
|
|
|
done:
|
2011-04-16 10:07:39 +02:00
|
|
|
item.mask = TVIF_STATE;
|
|
|
|
item.hItem = hItem;
|
|
|
|
item.stateMask = TVIS_EXPANDEDONCE;
|
|
|
|
item.state = TVIS_EXPANDEDONCE;
|
|
|
|
SendMessageW(hwndTV, TVM_SETITEMW, 0, (LPARAM)&item);
|
2008-08-25 23:03:17 +02:00
|
|
|
SendMessageW(hwndTV, WM_SETREDRAW, TRUE, 0);
|
2004-06-14 21:34:58 +02:00
|
|
|
SetCursor(hcursorOld);
|
2003-08-07 05:10:13 +02:00
|
|
|
expanding = FALSE;
|
2017-07-28 15:22:18 +02:00
|
|
|
heap_free(keyPath);
|
2003-12-12 05:08:59 +01:00
|
|
|
|
2003-08-07 05:10:13 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-04-16 10:07:03 +02:00
|
|
|
BOOL OnTreeExpanding(HWND hwndTV, NMTREEVIEWW* pnmtv)
|
2005-10-26 14:07:55 +02:00
|
|
|
{
|
|
|
|
return UpdateExpandingTree(hwndTV, pnmtv->itemNew.hItem, pnmtv->itemNew.state);
|
|
|
|
}
|
|
|
|
|
2003-12-12 05:08:59 +01:00
|
|
|
|
2003-08-07 05:10:13 +02:00
|
|
|
/*
|
|
|
|
* CreateTreeView - creates a tree view control.
|
|
|
|
* Returns the handle to the new control if successful, or NULL otherwise.
|
|
|
|
* hwndParent - handle to the control's parent window.
|
|
|
|
*/
|
2008-08-25 23:00:35 +02:00
|
|
|
HWND CreateTreeView(HWND hwndParent, LPWSTR pHostName, UINT id)
|
2003-08-07 05:10:13 +02:00
|
|
|
{
|
|
|
|
RECT rcClient;
|
|
|
|
HWND hwndTV;
|
|
|
|
|
|
|
|
/* Get the dimensions of the parent window's client area, and create the tree view control. */
|
|
|
|
GetClientRect(hwndParent, &rcClient);
|
2022-04-14 15:01:38 +02:00
|
|
|
hwndTV = CreateWindowExW(WS_EX_CLIENTEDGE, WC_TREEVIEWW, L"Tree View",
|
2017-01-28 14:37:51 +01:00
|
|
|
WS_VISIBLE | WS_CHILD | WS_TABSTOP | TVS_HASLINES | TVS_HASBUTTONS |
|
|
|
|
TVS_LINESATROOT | TVS_EDITLABELS | TVS_SHOWSELALWAYS,
|
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);
|
2008-08-31 17:16:21 +02:00
|
|
|
SendMessageW(hwndTV, TVM_SETUNICODEFORMAT, TRUE, 0);
|
2003-08-07 05:10:13 +02:00
|
|
|
/* Initialize the image list, and add items to the control. */
|
|
|
|
if (!InitTreeViewImageLists(hwndTV) || !InitTreeViewItems(hwndTV, pHostName)) {
|
|
|
|
DestroyWindow(hwndTV);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return hwndTV;
|
|
|
|
}
|