Commit e26b563e authored by Alexander Nicolaysen Sørnes's avatar Alexander Nicolaysen Sørnes Committed by Alexandre Julliard

regedit: Remove some ANSI functions.

parent 6b7ebf08
......@@ -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; i<nPaths; i++) {
if (pPaths[i] && *pPaths[i]) {
len += lstrlen(pPaths[i])+1;
}
}
combined = HeapAlloc(GetProcessHeap(), 0, len * sizeof(TCHAR));
*combined = '\0';
for (i=0, pos=0; i<nPaths; i++) {
if (pPaths[i] && *pPaths[i]) {
int llen = _tcslen(pPaths[i]);
if (!*combined)
_tcscpy(combined, pPaths[i]);
else {
combined[pos++] = (TCHAR)'\\';
_tcscpy(combined+pos, pPaths[i]);
}
pos += llen;
}
}
return combined;
}
static LPWSTR CombinePathsW(LPCWSTR pPaths[], int nPaths) {
static LPWSTR CombinePaths(LPCWSTR pPaths[], int nPaths) {
int i, len, pos;
LPWSTR combined;
for (i=0, len=0; i<nPaths; i++) {
......@@ -157,32 +132,13 @@ static LPWSTR CombinePathsW(LPCWSTR pPaths[], int nPaths) {
return combined;
}
static LPTSTR GetPathRoot(HWND hwndTV, HTREEITEM hItem, BOOL bFull) {
LPCTSTR parts[2] = {_T(""), _T("")};
TCHAR text[260];
HKEY hRootKey = NULL;
if (!hItem)
hItem = TreeView_GetSelection(hwndTV);
GetItemPath(hwndTV, hItem, &hRootKey);
if (!bFull && !hRootKey)
return NULL;
if (hRootKey)
parts[1] = GetRootKeyName(hRootKey);
if (bFull) {
DWORD dwSize = sizeof(text)/sizeof(TCHAR);
GetComputerName(text, &dwSize);
parts[0] = text;
}
return CombinePaths(parts, 2);
}
static LPWSTR GetPathRootW(HWND hwndTV, HTREEITEM hItem, BOOL bFull) {
static LPWSTR GetPathRoot(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);
GetItemPath(hwndTV, hItem, &hRootKey);
if (!bFull && !hRootKey)
return NULL;
if (hRootKey)
......@@ -192,29 +148,17 @@ static LPWSTR GetPathRootW(HWND hwndTV, HTREEITEM hItem, BOOL bFull) {
GetComputerNameW(text, &dwSize);
parts[0] = text;
}
return CombinePathsW(parts, 2);
}
LPTSTR GetItemFullPath(HWND hwndTV, HTREEITEM hItem, BOOL bFull) {
LPTSTR parts[2];
LPTSTR ret;
HKEY hRootKey = NULL;
parts[0] = GetPathRoot(hwndTV, hItem, bFull);
parts[1] = GetItemPath(hwndTV, hItem, &hRootKey);
ret = CombinePaths((LPCTSTR *)parts, 2);
HeapFree(GetProcessHeap(), 0, parts[0]);
return ret;
return CombinePaths(parts, 2);
}
LPWSTR GetItemFullPathW(HWND hwndTV, HTREEITEM hItem, BOOL bFull) {
LPWSTR GetItemFullPath(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);
parts[0] = GetPathRoot(hwndTV, hItem, bFull);
parts[1] = GetItemPath(hwndTV, hItem, &hRootKey);
ret = CombinePaths((LPCWSTR *)parts, 2);
HeapFree(GetProcessHeap(), 0, parts[0]);
HeapFree(GetProcessHeap(), 0, parts[1]);
return ret;
......@@ -224,9 +168,9 @@ static LPWSTR GetPathFullPath(HWND hwndTV, LPWSTR path) {
LPWSTR parts[2];
LPWSTR ret;
parts[0] = GetPathRootW(hwndTV, 0, TRUE);
parts[0] = GetPathRoot(hwndTV, 0, TRUE);
parts[1] = path;
ret = CombinePathsW((LPCWSTR*)parts, 2);
ret = CombinePaths((LPCWSTR*)parts, 2);
HeapFree(GetProcessHeap(), 0, parts[0]);
return ret;
}
......@@ -236,7 +180,7 @@ static void OnTreeSelectionChanged(HWND hwndTV, HWND hwndLV, HTREEITEM hItem, BO
if (bRefreshLV) {
LPWSTR keyPath;
HKEY hRootKey = NULL;
keyPath = GetItemPathW(hwndTV, hItem, &hRootKey);
keyPath = GetItemPath(hwndTV, hItem, &hRootKey);
RefreshListView(hwndLV, hRootKey, keyPath, NULL);
HeapFree(GetProcessHeap(), 0, keyPath);
}
......@@ -426,7 +370,7 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
HKEY hRootKey;
LPNMTVDISPINFO dispInfo = (LPNMTVDISPINFO)lParam;
WCHAR* itemText = GetWideString(dispInfo->item.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;
......
......@@ -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);
......
......@@ -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);
......
......@@ -2,6 +2,7 @@
* Regedit treeview
*
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
* Copyright (C) 2008 Alexander N. Sørnes <alex@thehandofagony.com>
*
* 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 <windows.h>
#include <commctrl.h>
#include <stdlib.h>
#include <tchar.h>
#include <stdio.h>
#include <wine/debug.h>
#include <shlwapi.h>
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment