From e26b563ee1e27e18b19844044ab014eb65730cb8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexander=20Nicolaysen=20S=C3=B8rnes?= Date: Sun, 31 Aug 2008 00:57:41 +0200 Subject: [PATCH] regedit: Remove some ANSI functions. --- programs/regedit/childwnd.c | 80 +++++++-------------------------------------- programs/regedit/framewnd.c | 37 +++++++++++---------- programs/regedit/main.h | 6 ++-- programs/regedit/treeview.c | 74 +++++------------------------------------ 4 files changed, 42 insertions(+), 155 deletions(-) diff --git a/programs/regedit/childwnd.c b/programs/regedit/childwnd.c index a80235ae757..bb8cf6f2461 100644 --- a/programs/regedit/childwnd.c +++ b/programs/regedit/childwnd.c @@ -107,32 +107,7 @@ static void OnPaint(HWND hWnd) EndPaint(hWnd, &ps); } -static LPTSTR CombinePaths(LPCTSTR pPaths[], int nPaths) { - int i, len, pos; - LPTSTR combined; - for (i=0, len=0; iitem.pszText); - LPWSTR path = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hRootKey); + LPWSTR path = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey); BOOL res = RenameKey(hWnd, hRootKey, path, itemText); if (res) { TVITEMEXW item; diff --git a/programs/regedit/framewnd.c b/programs/regedit/framewnd.c index c083f06c923..b0631b7f985 100644 --- a/programs/regedit/framewnd.c +++ b/programs/regedit/framewnd.c @@ -105,7 +105,7 @@ static void UpdateMenuItems(HMENU hMenu) { BOOL bAllowEdit = FALSE; HKEY hRootKey = NULL; LPWSTR keyName; - keyName = GetItemPathW(hwndTV, TreeView_GetSelection(hwndTV), &hRootKey); + keyName = GetItemPath(hwndTV, TreeView_GetSelection(hwndTV), &hRootKey); if (GetFocus() != hwndTV || (keyName && *keyName)) { /* can't modify root keys, but allow for their values */ bAllowEdit = TRUE; } @@ -192,7 +192,7 @@ void SetupStatusBar(HWND hWnd, BOOL bResize) void UpdateStatusBar(void) { - LPWSTR fullPath = GetItemFullPathW(g_pChildWnd->hTreeWnd, NULL, TRUE); + LPWSTR fullPath = GetItemFullPath(g_pChildWnd->hTreeWnd, NULL, TRUE); SendMessageW(hStatusBar, SB_SETTEXTW, 0, (LPARAM)fullPath); HeapFree(GetProcessHeap(), 0, fullPath); } @@ -263,7 +263,6 @@ static UINT CALLBACK ExportRegistryFile_OFNHookProc(HWND hdlg, UINT uiMsg, WPARA { static OPENFILENAME* pOpenFileName; OFNOTIFY *pOfNotify; - LPTSTR path; switch (uiMsg) { case WM_INITDIALOG: @@ -278,11 +277,15 @@ static UINT CALLBACK ExportRegistryFile_OFNHookProc(HWND hdlg, UINT uiMsg, WPARA switch (pOfNotify->hdr.code) { case CDN_INITDONE: - path = GetItemFullPath(g_pChildWnd->hTreeWnd, NULL, FALSE); - SendDlgItemMessage(hdlg, IDC_EXPORT_PATH, WM_SETTEXT, 0, (LPARAM)path); - HeapFree(GetProcessHeap(), 0, path); + { + WCHAR* pathW = GetItemFullPath(g_pChildWnd->hTreeWnd, NULL, FALSE); + CHAR* pathA = GetMultiByteString(pathW); + SendDlgItemMessage(hdlg, IDC_EXPORT_PATH, WM_SETTEXT, 0, (LPARAM)pathA); + HeapFree(GetProcessHeap(), 0, pathW); + HeapFree(GetProcessHeap(), 0, pathA); CheckRadioButton(hdlg, IDC_EXPORT_ALL, IDC_EXPORT_SELECTED, pOpenFileName->lCustData ? IDC_EXPORT_SELECTED : IDC_EXPORT_ALL); break; + } case CDN_FILEOK: ExportRegistryFile_StoreSelection(hdlg, pOpenFileName); break; @@ -528,10 +531,10 @@ static INT_PTR CALLBACK addtofavorites_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM w case WM_INITDIALOG: { HKEY hKeyRoot = NULL; - LPWSTR ItemPath = GetItemPathW(g_pChildWnd->hTreeWnd, NULL, &hKeyRoot); + LPWSTR ItemPath = GetItemPath(g_pChildWnd->hTreeWnd, NULL, &hKeyRoot); if(!ItemPath || !*ItemPath) - ItemPath = GetItemFullPathW(g_pChildWnd->hTreeWnd, NULL, FALSE); + ItemPath = GetItemFullPath(g_pChildWnd->hTreeWnd, NULL, FALSE); EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE); SetWindowTextW(hwndValue, ItemPath); SendMessageW(hwndValue, EM_SETLIMITTEXT, 127, 0); @@ -679,7 +682,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } case ID_EDIT_DELETE: if (GetFocus() == g_pChildWnd->hTreeWnd) { - WCHAR* keyPath = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); + WCHAR* keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); if (keyPath == 0 || *keyPath == 0) { MessageBeep(MB_ICONHAND); } else if (DeleteKey(hWnd, hKeyRoot, keyPath)) { @@ -687,7 +690,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } HeapFree(GetProcessHeap(), 0, keyPath); } else if (GetFocus() == g_pChildWnd->hListWnd) { - WCHAR* keyPath = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); + WCHAR* keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); curIndex = ListView_GetNextItem(g_pChildWnd->hListWnd, -1, LVNI_SELECTED); while(curIndex != -1) { WCHAR* valueNameW; @@ -716,7 +719,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case ID_EDIT_MODIFY: { LPCWSTR valueName = GetValueName(g_pChildWnd->hListWnd); - WCHAR* keyPath = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); + WCHAR* keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); if (ModifyValue(hWnd, hKeyRoot, keyPath, valueName)) RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, valueName); HeapFree(GetProcessHeap(), 0, keyPath); @@ -758,7 +761,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } case ID_EDIT_COPYKEYNAME: { - LPWSTR fullPath = GetItemFullPathW(g_pChildWnd->hTreeWnd, NULL, FALSE); + LPWSTR fullPath = GetItemFullPath(g_pChildWnd->hTreeWnd, NULL, FALSE); if (fullPath) { CopyKeyName(hWnd, fullPath); HeapFree(GetProcessHeap(), 0, fullPath); @@ -768,7 +771,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case ID_EDIT_NEW_KEY: { WCHAR newKeyW[MAX_NEW_KEY_LEN]; - WCHAR* keyPath = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); + WCHAR* keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); if (CreateKey(hWnd, hKeyRoot, keyPath, newKeyW)) { if (InsertNode(g_pChildWnd->hTreeWnd, 0, newKeyW)) StartKeyRename(g_pChildWnd->hTreeWnd); @@ -790,7 +793,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) /* fall through */ create_value: { - WCHAR* keyPath = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); + WCHAR* keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); WCHAR newKey[MAX_NEW_KEY_LEN]; if (CreateValue(hWnd, hKeyRoot, keyPath, valueType, newKey)) { RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, newKey); @@ -801,7 +804,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) break; case ID_EDIT_RENAME: { - WCHAR* keyPath = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); + WCHAR* keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); if (keyPath == 0 || *keyPath == 0) { MessageBeep(MB_ICONHAND); } else if (GetFocus() == g_pChildWnd->hTreeWnd) { @@ -826,7 +829,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case ID_FAVORITES_ADDTOFAVORITES: { HKEY hKey; - LPWSTR lpKeyPath = GetItemFullPathW(g_pChildWnd->hTreeWnd, NULL, FALSE); + LPWSTR lpKeyPath = GetItemFullPath(g_pChildWnd->hTreeWnd, NULL, FALSE); if (lpKeyPath) { if (DialogBox(0, MAKEINTRESOURCE(IDD_ADDFAVORITE), hWnd, addtofavorites_dlgproc) == IDOK) { if (RegCreateKeyExW(HKEY_CURRENT_USER, favoritesKey, @@ -854,7 +857,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } case ID_VIEW_REFRESH: { - WCHAR* keyPath = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); + WCHAR* keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); RefreshTreeView(g_pChildWnd->hTreeWnd); RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, NULL); HeapFree(GetProcessHeap(), 0, keyPath); diff --git a/programs/regedit/main.h b/programs/regedit/main.h index aec4d2f27fc..84a712ccff7 100644 --- a/programs/regedit/main.h +++ b/programs/regedit/main.h @@ -109,8 +109,7 @@ 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 LPWSTR GetItemFullPath(HWND hwndTV, HTREEITEM hItem, BOOL bFull); extern LRESULT CALLBACK ChildWndProc(HWND, UINT, WPARAM, LPARAM); /* framewnd.c */ @@ -131,8 +130,7 @@ extern BOOL IsDefaultValue(HWND hwndLV, int i); extern HWND CreateTreeView(HWND hwndParent, LPWSTR 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 LPWSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey); extern BOOL DeleteNode(HWND hwndTV, HTREEITEM hItem); extern HTREEITEM InsertNode(HWND hwndTV, HTREEITEM hItem, LPWSTR name); extern HWND StartKeyRename(HWND hwndTV); diff --git a/programs/regedit/treeview.c b/programs/regedit/treeview.c index 12dd87a91e5..6e4131cea1d 100644 --- a/programs/regedit/treeview.c +++ b/programs/regedit/treeview.c @@ -2,6 +2,7 @@ * Regedit treeview * * Copyright (C) 2002 Robert Dickenson + * Copyright (C) 2008 Alexander N. Sørnes * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -25,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -49,49 +49,7 @@ int Image_Root; static BOOL UpdateExpandingTree(HWND hwndTV, HTREEITEM hItem, int state); -static BOOL get_item_path(HWND hwndTV, HTREEITEM hItem, HKEY* phKey, LPTSTR* pKeyPath, int* pPathLen, int* pMaxLen) -{ - TVITEM item; - int maxLen, len; - LPTSTR 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_path(hwndTV, TreeView_GetParent(hwndTV, hItem), phKey, pKeyPath, pPathLen, pMaxLen)) return FALSE; - if (*pPathLen) { - (*pKeyPath)[*pPathLen] = _T('\\'); - ++(*pPathLen); - } - - do { - item.mask = TVIF_TEXT; - item.hItem = hItem; - item.pszText = *pKeyPath + *pPathLen; - item.cchTextMax = maxLen = *pMaxLen - *pPathLen; - if (!TreeView_GetItem(hwndTV, &item)) return FALSE; - len = _tcslen(item.pszText); - if (len < maxLen - 1) { - *pPathLen += len; - break; - } - newStr = HeapReAlloc(GetProcessHeap(), 0, *pKeyPath, *pMaxLen * 2); - if (!newStr) return FALSE; - *pKeyPath = newStr; - *pMaxLen *= 2; - } while(TRUE); - - return TRUE; -} - -static BOOL get_item_pathW(HWND hwndTV, HTREEITEM hItem, HKEY* phKey, LPWSTR* pKeyPath, int* pPathLen, int* pMaxChars) +static BOOL get_item_path(HWND hwndTV, HTREEITEM hItem, HKEY* phKey, LPWSTR* pKeyPath, int* pPathLen, int* pMaxChars) { TVITEMW item; int maxChars, chars; @@ -107,7 +65,7 @@ static BOOL get_item_pathW(HWND hwndTV, HTREEITEM hItem, HKEY* phKey, LPWSTR* pK return TRUE; } - if(!get_item_pathW(hwndTV, TreeView_GetParent(hwndTV, hItem), phKey, pKeyPath, pPathLen, pMaxChars)) return FALSE; + if(!get_item_path(hwndTV, TreeView_GetParent(hwndTV, hItem), phKey, pKeyPath, pPathLen, pMaxChars)) return FALSE; if (*pPathLen) { (*pKeyPath)[*pPathLen] = '\\'; ++(*pPathLen); @@ -133,23 +91,7 @@ static BOOL get_item_pathW(HWND hwndTV, HTREEITEM hItem, HKEY* phKey, LPWSTR* pK return TRUE; } -LPTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey) -{ - int pathLen = 0, maxLen; - TCHAR *pathBuffer; - - pathBuffer = HeapAlloc(GetProcessHeap(), 0, 1024); - if (!pathBuffer) return NULL; - *pathBuffer = 0; - maxLen = HeapSize(GetProcessHeap(), 0, pathBuffer); - if (maxLen == (SIZE_T) - 1) return NULL; - if (!hItem) hItem = TreeView_GetSelection(hwndTV); - if (!hItem) return NULL; - if (!get_item_path(hwndTV, hItem, phRootKey, &pathBuffer, &pathLen, &maxLen)) return NULL; - return pathBuffer; -} - -LPWSTR GetItemPathW(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey) +LPWSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey) { int pathLen = 0, maxLen; WCHAR *pathBuffer; @@ -162,7 +104,7 @@ LPWSTR GetItemPathW(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey) 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; + if (!get_item_path(hwndTV, hItem, phRootKey, &pathBuffer, &pathLen, &maxLen)) return NULL; return pathBuffer; } @@ -286,7 +228,7 @@ static BOOL match_item(HWND hwndTV, HTREEITEM hItem, LPCWSTR sstring, int mode, HKEY hKey, hRoot; DWORD lenName; - KeyPath = GetItemPathW(hwndTV, hItem, &hRoot); + KeyPath = GetItemPath(hwndTV, hItem, &hRoot); if (!KeyPath || !hRoot) return FALSE; @@ -398,7 +340,7 @@ static BOOL RefreshTreeItem(HWND hwndTV, HTREEITEM hItem) TVITEMW tvItem; hRoot = NULL; - KeyPath = GetItemPathW(hwndTV, hItem, &hRoot); + KeyPath = GetItemPath(hwndTV, hItem, &hRoot); if (!KeyPath || !hRoot) return FALSE; @@ -663,7 +605,7 @@ BOOL UpdateExpandingTree(HWND hwndTV, HTREEITEM hItem, int state) hcursorOld = SetCursor(LoadCursor(NULL, IDC_WAIT)); SendMessageW(hwndTV, WM_SETREDRAW, FALSE, 0); - keyPath = GetItemPathW(hwndTV, hItem, &hRoot); + keyPath = GetItemPath(hwndTV, hItem, &hRoot); if (!keyPath) goto done; if (*keyPath) { -- 2.11.4.GIT