regedit: Convert clipboard handling to unicode.

This commit is contained in:
Alexander Nicolaysen Sørnes 2008-08-10 13:52:44 +02:00 committed by Alexandre Julliard
parent 5cb8bccf46
commit 6168a7c60c
6 changed files with 168 additions and 18 deletions

View File

@ -49,6 +49,28 @@ LPCTSTR GetRootKeyName(HKEY hRootKey)
return _T("UNKNOWN HKEY, PLEASE REPORT"); return _T("UNKNOWN HKEY, PLEASE REPORT");
} }
LPCWSTR GetRootKeyNameW(HKEY hRootKey)
{
if(hRootKey == HKEY_CLASSES_ROOT)
return reg_class_namesW[INDEX_HKEY_CLASSES_ROOT];
if(hRootKey == HKEY_CURRENT_USER)
return reg_class_namesW[INDEX_HKEY_CURRENT_USER];
if(hRootKey == HKEY_LOCAL_MACHINE)
return reg_class_namesW[INDEX_HKEY_LOCAL_MACHINE];
if(hRootKey == HKEY_USERS)
return reg_class_namesW[INDEX_HKEY_USERS];
if(hRootKey == HKEY_CURRENT_CONFIG)
return reg_class_namesW[INDEX_HKEY_CURRENT_CONFIG];
if(hRootKey == HKEY_DYN_DATA)
return reg_class_namesW[INDEX_HKEY_DYN_DATA];
else
{
static const WCHAR unknown_key[] = {'U','N','K','N','O','W','N',' ','H','K','E','Y',',',' ',
'P','L','E','A','S','E',' ','R','E','P','O','R','T',0};
return unknown_key;
}
}
static void draw_splitbar(HWND hWnd, int x) static void draw_splitbar(HWND hWnd, int x)
{ {
RECT rt; RECT rt;
@ -109,6 +131,31 @@ static LPTSTR CombinePaths(LPCTSTR pPaths[], int nPaths) {
return combined; return combined;
} }
static LPWSTR CombinePathsW(LPCWSTR pPaths[], int nPaths) {
int i, len, pos;
LPWSTR combined;
for (i=0, len=0; i<nPaths; i++) {
if (pPaths[i] && *pPaths[i]) {
len += lstrlenW(pPaths[i])+1;
}
}
combined = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
*combined = '\0';
for (i=0, pos=0; i<nPaths; i++) {
if (pPaths[i] && *pPaths[i]) {
int llen = lstrlenW(pPaths[i]);
if (!*combined)
lstrcpyW(combined, pPaths[i]);
else {
combined[pos++] = (TCHAR)'\\';
lstrcpyW(combined+pos, pPaths[i]);
}
pos += llen;
}
}
return combined;
}
static LPTSTR GetPathRoot(HWND hwndTV, HTREEITEM hItem, BOOL bFull) { static LPTSTR GetPathRoot(HWND hwndTV, HTREEITEM hItem, BOOL bFull) {
LPCTSTR parts[2] = {_T(""), _T("")}; LPCTSTR parts[2] = {_T(""), _T("")};
TCHAR text[260]; TCHAR text[260];
@ -128,6 +175,25 @@ static LPTSTR GetPathRoot(HWND hwndTV, HTREEITEM hItem, BOOL bFull) {
return CombinePaths(parts, 2); return CombinePaths(parts, 2);
} }
static LPWSTR GetPathRootW(HWND hwndTV, HTREEITEM hItem, BOOL bFull) {
LPCWSTR parts[2] = {0,0};
WCHAR text[260];
HKEY hRootKey = NULL;
if (!hItem)
hItem = TreeView_GetSelection(hwndTV);
GetItemPathW(hwndTV, hItem, &hRootKey);
if (!bFull && !hRootKey)
return NULL;
if (hRootKey)
parts[1] = GetRootKeyNameW(hRootKey);
if (bFull) {
DWORD dwSize = sizeof(text)/sizeof(TCHAR);
GetComputerNameW(text, &dwSize);
parts[0] = text;
}
return CombinePathsW(parts, 2);
}
LPTSTR GetItemFullPath(HWND hwndTV, HTREEITEM hItem, BOOL bFull) { LPTSTR GetItemFullPath(HWND hwndTV, HTREEITEM hItem, BOOL bFull) {
LPTSTR parts[2]; LPTSTR parts[2];
LPTSTR ret; LPTSTR ret;
@ -140,6 +206,18 @@ LPTSTR GetItemFullPath(HWND hwndTV, HTREEITEM hItem, BOOL bFull) {
return ret; return ret;
} }
LPWSTR GetItemFullPathW(HWND hwndTV, HTREEITEM hItem, BOOL bFull) {
LPWSTR parts[2];
LPWSTR ret;
HKEY hRootKey = NULL;
parts[0] = GetPathRootW(hwndTV, hItem, bFull);
parts[1] = GetItemPathW(hwndTV, hItem, &hRootKey);
ret = CombinePathsW((LPCWSTR *)parts, 2);
HeapFree(GetProcessHeap(), 0, parts[0]);
return ret;
}
static LPTSTR GetPathFullPath(HWND hwndTV, LPTSTR path) { static LPTSTR GetPathFullPath(HWND hwndTV, LPTSTR path) {
LPTSTR parts[2]; LPTSTR parts[2];
LPTSTR ret; LPTSTR ret;

View File

@ -440,7 +440,7 @@ static BOOL PrintRegistryHive(HWND hWnd, LPCWSTR path)
return TRUE; return TRUE;
} }
static BOOL CopyKeyName(HWND hWnd, LPCTSTR keyName) static BOOL CopyKeyName(HWND hWnd, LPCWSTR keyName)
{ {
BOOL result; BOOL result;
@ -448,12 +448,12 @@ static BOOL CopyKeyName(HWND hWnd, LPCTSTR keyName)
if (result) { if (result) {
result = EmptyClipboard(); result = EmptyClipboard();
if (result) { if (result) {
int len = (_tcslen(keyName)+1)*sizeof(TCHAR); int len = (lstrlenW(keyName)+1)*sizeof(WCHAR);
HANDLE hClipData = GlobalAlloc(GHND, len); HANDLE hClipData = GlobalAlloc(GHND, len);
LPVOID pLoc = GlobalLock(hClipData); LPVOID pLoc = GlobalLock(hClipData);
_tcscpy(pLoc, keyName); lstrcpyW(pLoc, keyName);
GlobalUnlock(hClipData); GlobalUnlock(hClipData);
hClipData = SetClipboardData(CF_TEXT, hClipData); hClipData = SetClipboardData(CF_UNICODETEXT, hClipData);
} else { } else {
/* error emptying clipboard*/ /* error emptying clipboard*/
@ -753,7 +753,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
} }
case ID_EDIT_COPYKEYNAME: case ID_EDIT_COPYKEYNAME:
{ {
LPTSTR fullPath = GetItemFullPath(g_pChildWnd->hTreeWnd, NULL, FALSE); LPWSTR fullPath = GetItemFullPathW(g_pChildWnd->hTreeWnd, NULL, FALSE);
if (fullPath) { if (fullPath) {
CopyKeyName(hWnd, fullPath); CopyKeyName(hWnd, fullPath);
HeapFree(GetProcessHeap(), 0, fullPath); HeapFree(GetProcessHeap(), 0, fullPath);

View File

@ -34,6 +34,17 @@ WCHAR g_pszDefaultValueNameW[64];
BOOL ProcessCmdLine(LPSTR lpCmdLine); BOOL ProcessCmdLine(LPSTR lpCmdLine);
static const WCHAR hkey_local_machine[] = {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',0};
static const WCHAR hkey_users[] = {'H','K','E','Y','_','U','S','E','R','S',0};
static const WCHAR hkey_classes_root[] = {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T',0};
static const WCHAR hkey_current_config[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','C','O','N','F','I','G',0};
static const WCHAR hkey_current_user[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R',0};
static const WCHAR hkey_dyn_data[] = {'H','K','E','Y','_','D','Y','N','_','D','A','T','A',0};
const WCHAR *reg_class_namesW[] = {hkey_local_machine, hkey_users,
hkey_classes_root, hkey_current_config,
hkey_current_user, hkey_dyn_data
};
/******************************************************************************* /*******************************************************************************
* Global Variables: * Global Variables:

View File

@ -93,12 +93,24 @@ extern const TCHAR szChildClass[];
extern TCHAR g_pszDefaultValueName[]; extern TCHAR g_pszDefaultValueName[];
extern WCHAR g_pszDefaultValueNameW[]; extern WCHAR g_pszDefaultValueNameW[];
/* Registry class names and their indexes */
extern const WCHAR* reg_class_namesW[];
#define INDEX_HKEY_LOCAL_MACHINE 0
#define INDEX_HKEY_USERS 1
#define INDEX_HKEY_CLASSES_ROOT 2
#define INDEX_HKEY_CURRENT_CONFIG 3
#define INDEX_HKEY_CURRENT_USER 4
#define INDEX_HKEY_DYN_DATA 5
/* about.c */ /* about.c */
extern void ShowAboutBox(HWND hWnd); extern void ShowAboutBox(HWND hWnd);
/* childwnd.c */ /* childwnd.c */
extern LPCTSTR GetRootKeyName(HKEY hRootKey); extern LPCTSTR GetRootKeyName(HKEY hRootKey);
extern LPTSTR GetItemFullPath(HWND hwndTV, HTREEITEM hItem, BOOL bFull); extern LPTSTR GetItemFullPath(HWND hwndTV, HTREEITEM hItem, BOOL bFull);
extern LPWSTR GetItemFullPathW(HWND hwndTV, HTREEITEM hItem, BOOL bFull);
extern LRESULT CALLBACK ChildWndProc(HWND, UINT, WPARAM, LPARAM); extern LRESULT CALLBACK ChildWndProc(HWND, UINT, WPARAM, LPARAM);
/* framewnd.c */ /* framewnd.c */
@ -120,6 +132,7 @@ extern HWND CreateTreeView(HWND hwndParent, LPTSTR pHostName, UINT id);
extern BOOL RefreshTreeView(HWND hWndTV); extern BOOL RefreshTreeView(HWND hWndTV);
extern BOOL OnTreeExpanding(HWND hWnd, NMTREEVIEW* pnmtv); extern BOOL OnTreeExpanding(HWND hWnd, NMTREEVIEW* pnmtv);
extern LPTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey); extern LPTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey);
extern LPWSTR GetItemPathW(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey);
extern BOOL DeleteNode(HWND hwndTV, HTREEITEM hItem); extern BOOL DeleteNode(HWND hwndTV, HTREEITEM hItem);
extern HTREEITEM InsertNode(HWND hwndTV, HTREEITEM hItem, LPTSTR name); extern HTREEITEM InsertNode(HWND hwndTV, HTREEITEM hItem, LPTSTR name);
extern HWND StartKeyRename(HWND hwndTV); extern HWND StartKeyRename(HWND hwndTV);

View File

@ -40,21 +40,10 @@ static const CHAR *reg_class_names[] = {
"HKEY_CURRENT_CONFIG", "HKEY_CURRENT_USER", "HKEY_DYN_DATA" "HKEY_CURRENT_CONFIG", "HKEY_CURRENT_USER", "HKEY_DYN_DATA"
}; };
static const WCHAR hkey_local_machine[] = {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',0};
static const WCHAR hkey_users[] = {'H','K','E','Y','_','U','S','E','R','S',0};
static const WCHAR hkey_classes_root[] = {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T',0};
static const WCHAR hkey_current_config[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','C','O','N','F','I','G',0};
static const WCHAR hkey_current_user[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R',0};
static const WCHAR hkey_dyn_data[] = {'H','K','E','Y','_','D','Y','N','_','D','A','T','A',0};
static const WCHAR *reg_class_namesW[] = {hkey_local_machine, hkey_users,
hkey_classes_root, hkey_current_config,
hkey_current_user, hkey_dyn_data
};
#define REG_CLASS_NUMBER (sizeof(reg_class_names) / sizeof(reg_class_names[0])) #define REG_CLASS_NUMBER (sizeof(reg_class_names) / sizeof(reg_class_names[0]))
extern const WCHAR* reg_class_namesW[];
static HKEY reg_class_keys[REG_CLASS_NUMBER] = { static HKEY reg_class_keys[REG_CLASS_NUMBER] = {
HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CLASSES_ROOT, HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CLASSES_ROOT,
HKEY_CURRENT_CONFIG, HKEY_CURRENT_USER, HKEY_DYN_DATA HKEY_CURRENT_CONFIG, HKEY_CURRENT_USER, HKEY_DYN_DATA

View File

@ -91,6 +91,48 @@ static BOOL get_item_path(HWND hwndTV, HTREEITEM hItem, HKEY* phKey, LPTSTR* pKe
return TRUE; return TRUE;
} }
static BOOL get_item_pathW(HWND hwndTV, HTREEITEM hItem, HKEY* phKey, LPWSTR* pKeyPath, int* pPathLen, int* pMaxChars)
{
TVITEMW item;
int maxChars, chars;
LPWSTR newStr;
item.mask = TVIF_PARAM;
item.hItem = hItem;
if (!TreeView_GetItem(hwndTV, &item)) return FALSE;
if (item.lParam) {
/* found root key with valid key value */
*phKey = (HKEY)item.lParam;
return TRUE;
}
if(!get_item_pathW(hwndTV, TreeView_GetParent(hwndTV, hItem), phKey, pKeyPath, pPathLen, pMaxChars)) return FALSE;
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;
}
newStr = HeapReAlloc(GetProcessHeap(), 0, *pKeyPath, *pMaxChars * 2);
if (!newStr) return FALSE;
*pKeyPath = newStr;
*pMaxChars *= 2;
} while(TRUE);
return TRUE;
}
LPTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey) LPTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey)
{ {
int pathLen = 0, maxLen; int pathLen = 0, maxLen;
@ -107,6 +149,23 @@ LPTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey)
return pathBuffer; return pathBuffer;
} }
LPWSTR GetItemPathW(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey)
{
int pathLen = 0, maxLen;
WCHAR *pathBuffer;
pathBuffer = HeapAlloc(GetProcessHeap(), 0, 1024*sizeof(WCHAR));
if (!pathBuffer) return NULL;
*pathBuffer = 0;
maxLen = HeapSize(GetProcessHeap(), 0, pathBuffer);
if (maxLen == (SIZE_T) - 1) return NULL;
maxLen = maxLen / sizeof(WCHAR);
if (!hItem) hItem = TreeView_GetSelection(hwndTV);
if (!hItem) return NULL;
if (!get_item_pathW(hwndTV, hItem, phRootKey, &pathBuffer, &pathLen, &maxLen)) return NULL;
return pathBuffer;
}
static LPTSTR get_path_component(LPCTSTR *lplpKeyName) { static LPTSTR get_path_component(LPCTSTR *lplpKeyName) {
LPCTSTR lpPos = *lplpKeyName; LPCTSTR lpPos = *lplpKeyName;
LPTSTR lpResult = NULL; LPTSTR lpResult = NULL;