From 6168a7c60c69d1f7e46838680ef185183b0f475b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexander=20Nicolaysen=20S=C3=B8rnes?= Date: Sun, 10 Aug 2008 13:52:44 +0200 Subject: [PATCH] regedit: Convert clipboard handling to unicode. --- programs/regedit/childwnd.c | 78 +++++++++++++++++++++++++++++++++++++++++++++ programs/regedit/framewnd.c | 10 +++--- programs/regedit/main.c | 11 +++++++ programs/regedit/main.h | 13 ++++++++ programs/regedit/regproc.c | 15 ++------- programs/regedit/treeview.c | 59 ++++++++++++++++++++++++++++++++++ 6 files changed, 168 insertions(+), 18 deletions(-) diff --git a/programs/regedit/childwnd.c b/programs/regedit/childwnd.c index 23eca7fd1c8..42fefca5422 100644 --- a/programs/regedit/childwnd.c +++ b/programs/regedit/childwnd.c @@ -49,6 +49,28 @@ LPCTSTR GetRootKeyName(HKEY hRootKey) 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) { RECT rt; @@ -109,6 +131,31 @@ static LPTSTR CombinePaths(LPCTSTR pPaths[], int nPaths) { return combined; } +static LPWSTR CombinePathsW(LPCWSTR pPaths[], int nPaths) { + int i, len, pos; + LPWSTR combined; + for (i=0, len=0; ihTreeWnd, NULL, FALSE); + LPWSTR fullPath = GetItemFullPathW(g_pChildWnd->hTreeWnd, NULL, FALSE); if (fullPath) { CopyKeyName(hWnd, fullPath); HeapFree(GetProcessHeap(), 0, fullPath); diff --git a/programs/regedit/main.c b/programs/regedit/main.c index 2b37565246d..5661b263412 100644 --- a/programs/regedit/main.c +++ b/programs/regedit/main.c @@ -34,6 +34,17 @@ WCHAR g_pszDefaultValueNameW[64]; 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: diff --git a/programs/regedit/main.h b/programs/regedit/main.h index f0f0c645ae5..6b5a098e203 100644 --- a/programs/regedit/main.h +++ b/programs/regedit/main.h @@ -93,12 +93,24 @@ extern const TCHAR szChildClass[]; extern TCHAR g_pszDefaultValueName[]; 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 */ extern void ShowAboutBox(HWND hWnd); /* childwnd.c */ extern LPCTSTR GetRootKeyName(HKEY hRootKey); 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); /* framewnd.c */ @@ -120,6 +132,7 @@ extern HWND CreateTreeView(HWND hwndParent, LPTSTR pHostName, UINT id); extern BOOL RefreshTreeView(HWND hWndTV); extern BOOL OnTreeExpanding(HWND hWnd, NMTREEVIEW* pnmtv); 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 HTREEITEM InsertNode(HWND hwndTV, HTREEITEM hItem, LPTSTR name); extern HWND StartKeyRename(HWND hwndTV); diff --git a/programs/regedit/regproc.c b/programs/regedit/regproc.c index 13bfc17c90c..8f05a2d6e45 100644 --- a/programs/regedit/regproc.c +++ b/programs/regedit/regproc.c @@ -40,21 +40,10 @@ static const CHAR *reg_class_names[] = { "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])) +extern const WCHAR* reg_class_namesW[]; + static HKEY reg_class_keys[REG_CLASS_NUMBER] = { HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CLASSES_ROOT, HKEY_CURRENT_CONFIG, HKEY_CURRENT_USER, HKEY_DYN_DATA diff --git a/programs/regedit/treeview.c b/programs/regedit/treeview.c index bfce4aa5bcf..3261a66517c 100644 --- a/programs/regedit/treeview.c +++ b/programs/regedit/treeview.c @@ -91,6 +91,48 @@ static BOOL get_item_path(HWND hwndTV, HTREEITEM hItem, HKEY* phKey, LPTSTR* pKe 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) { int pathLen = 0, maxLen; @@ -107,6 +149,23 @@ LPTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey) 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) { LPCTSTR lpPos = *lplpKeyName; LPTSTR lpResult = NULL; -- 2.11.4.GIT