From 9142f7730bd433b5d4a0259eda38f8d115d8f3d3 Mon Sep 17 00:00:00 2001 From: "Dimitrie O. Paun" Date: Wed, 3 Dec 2003 20:25:24 +0000 Subject: [PATCH] Added support for editing strings. --- programs/regedit/En.rc | 22 ++++++ programs/regedit/Makefile.in | 1 + programs/regedit/childwnd.c | 7 +- programs/regedit/edit.c | 136 +++++++++++++++++++++++++++++++++++ programs/regedit/framewnd.c | 25 ++++++- programs/regedit/main.c | 4 ++ programs/regedit/main.h | 13 ++++ programs/regedit/resource.h | 9 +++ programs/regedit/treeview.c | 3 + 9 files changed, 213 insertions(+), 7 deletions(-) create mode 100644 programs/regedit/edit.c diff --git a/programs/regedit/En.rc b/programs/regedit/En.rc index f1db366b8a4..6d113ed093a 100644 --- a/programs/regedit/En.rc +++ b/programs/regedit/En.rc @@ -119,6 +119,20 @@ BEGIN DEFPUSHBUTTON "OK",IDOK,195,6,30,11,WS_GROUP END +IDD_EDIT_STRING DIALOG DISCARDABLE 22, 17, 210, 75 +STYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENU +CAPTION "Edit String" +FONT 8, "System" +BEGIN + LTEXT "Value name:",IDC_STATIC,5,5,119,8 + EDITTEXT IDC_VALUE_NAME,5,15,200,12, WS_BORDER | WS_TABSTOP | WS_DISABLED + LTEXT "Value data:",IDC_STATIC,5,30,119,8 + EDITTEXT IDC_VALUE_DATA,5,40,200,12, WS_BORDER | WS_TABSTOP + DEFPUSHBUTTON "OK",IDOK,140,60,30,11,WS_GROUP + DEFPUSHBUTTON "Cancel",IDCANCEL,175,60,30,11,WS_GROUP +END + + /* * String Table */ @@ -181,6 +195,14 @@ BEGIN ID_EDIT_FINDNEXT "Finds next occurrence of text specified in previous search" END +STRINGTABLE DISCARDABLE +BEGIN + IDS_ERROR "Error" + IDS_BAD_VALUE "Can't query value '%s'" + IDS_UNSUPPORTED_TYPE "Can't edit keys of this type (%ld)" + IDS_TOO_BIG_VALUE "Value is too big (%ld)" +END + /*****************************************************************/ diff --git a/programs/regedit/Makefile.in b/programs/regedit/Makefile.in index e86ff3ca2c7..e6bb7b38ccb 100644 --- a/programs/regedit/Makefile.in +++ b/programs/regedit/Makefile.in @@ -11,6 +11,7 @@ EXTRADEFS = -DNO_LIBWINE_PORT C_SRCS = \ about.c \ childwnd.c \ + edit.c \ framewnd.c \ listview.c \ main.c \ diff --git a/programs/regedit/childwnd.c b/programs/regedit/childwnd.c index d0315428777..c3835f8a5bc 100644 --- a/programs/regedit/childwnd.c +++ b/programs/regedit/childwnd.c @@ -22,16 +22,16 @@ #include #include #include -#include -#define ASSERT assert #include "main.h" +ChildWnd* pChildWnd; /******************************************************************************* * Local module support methods */ +/*FIXME: why do we need this, we should remove it, we have already FindRegRoot */ static void MakeFullRegPath(HWND hwndTV, HTREEITEM hItem, LPTSTR keyPath, int* pPathLen, int max) { TVITEM item; @@ -128,12 +128,11 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa { static int last_split; /* ChildWnd* pChildWnd = (ChildWnd*)GetWindowLong(hWnd, GWL_USERDATA); */ - static ChildWnd* pChildWnd; switch (message) { case WM_CREATE: pChildWnd = (ChildWnd*)((LPCREATESTRUCT)lParam)->lpCreateParams; - ASSERT(pChildWnd); + if (!pChildWnd) return 0; pChildWnd->nSplitPos = 250; pChildWnd->hTreeWnd = CreateTreeView(hWnd, pChildWnd->szPath, TREE_WINDOW); pChildWnd->hListWnd = CreateListView(hWnd, LIST_WINDOW/*, pChildWnd->szPath*/); diff --git a/programs/regedit/edit.c b/programs/regedit/edit.c new file mode 100644 index 00000000000..41c4532470b --- /dev/null +++ b/programs/regedit/edit.c @@ -0,0 +1,136 @@ +/* + * Registry editing UI functions. + * + * Copyright (C) 2003 Dimitrie O. Paun + * + * 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 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "main.h" +#include "regproc.h" +#include "resource.h" + +static TCHAR* editValueName; +static TCHAR* stringValueData; + +void error(HWND hwnd, INT resId, ...) +{ + va_list ap; + TCHAR title[256]; + TCHAR errfmt[1024]; + TCHAR errstr[1024]; + HINSTANCE hInstance; + + hInstance = GetModuleHandle(0); + + if (!LoadString(hInstance, IDS_ERROR, title, COUNT_OF(title))) + lstrcpy(title, "Error"); + + if (!LoadString(hInstance, resId, errfmt, COUNT_OF(errfmt))) + lstrcpy(errfmt, "Unknown error string!"); + + va_start(ap, resId); + _vsntprintf(errstr, COUNT_OF(errstr), errfmt, ap); + va_end(ap); + + MessageBox(hwnd, errstr, title, MB_OK | MB_ICONERROR); +} + +INT_PTR CALLBACK modify_string_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + TCHAR* valueData; + HWND hwndValue; + int len; + + switch(uMsg) { + case WM_INITDIALOG: + SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName); + SetDlgItemText(hwndDlg, IDC_VALUE_DATA, stringValueData); + return TRUE; + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDOK: + if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) { + if ((len = GetWindowTextLength(hwndValue))) { + if ((valueData = HeapReAlloc(GetProcessHeap(), 0, stringValueData, (len + 1) * sizeof(TCHAR)))) { + stringValueData = valueData; + if (!GetWindowText(hwndValue, stringValueData, len + 1)) + *stringValueData = 0; + } + } + } + /* Fall through */ + case IDCANCEL: + EndDialog(hwndDlg, wParam); + return TRUE; + } + } + return FALSE; +} + +BOOL ModifyValue(HWND hwnd, HKEY hKey, LPTSTR valueName) +{ + DWORD valueDataLen; + DWORD type; + LONG lRet; + BOOL result = FALSE; + + if (!hKey || !valueName) return FALSE; + + editValueName = valueName; + + lRet = RegQueryValueEx(hKey, valueName, 0, &type, 0, &valueDataLen); + if (lRet != ERROR_SUCCESS) { + error(hwnd, IDS_BAD_VALUE, valueName); + goto done; + } + + if ( (type == REG_SZ) || (type == REG_EXPAND_SZ) ) { + if (!(stringValueData = HeapAlloc(GetProcessHeap(), 0, valueDataLen))) { + error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen); + goto done; + } + lRet = RegQueryValueEx(hKey, valueName, 0, 0, stringValueData, &valueDataLen); + if (lRet != ERROR_SUCCESS) { + error(hwnd, IDS_BAD_VALUE, valueName); + goto done; + } + if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_STRING), hwnd, modify_string_dlgproc) == IDOK) { + lRet = RegSetValueEx(hKey, valueName, 0, type, stringValueData, lstrlen(stringValueData) + 1); + if (lRet == ERROR_SUCCESS) result = TRUE; + } + } else if ( type == REG_DWORD ) { + MessageBox(hwnd, "Can't edit dwords for now", "Error", MB_OK | MB_ICONERROR); + } else { + error(hwnd, IDS_UNSUPPORTED_TYPE, type); + } + +done: + HeapFree(GetProcessHeap(), 0, stringValueData); + stringValueData = NULL; + + return result; +} diff --git a/programs/regedit/framewnd.c b/programs/regedit/framewnd.c index 832f3410de2..c4121b19b9e 100644 --- a/programs/regedit/framewnd.c +++ b/programs/regedit/framewnd.c @@ -436,6 +436,19 @@ BOOL RefreshView(HWND hWnd) */ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { + HKEY hKeyRoot, hKey; + TCHAR keyPath[1000] = { 0 }; + TCHAR valueName[255] = { 0 }; + int keyPathLen = 0, item; + BOOL result = TRUE; + LONG lRet; + + hKeyRoot = FindRegRoot(pChildWnd->hTreeWnd, 0, keyPath, &keyPathLen, sizeof(keyPath)/sizeof(TCHAR)); + lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_READ, &hKey); + if (lRet != ERROR_SUCCESS) hKey = 0; + item = ListView_GetNextItem(pChildWnd->hListWnd, -1, LVNI_FOCUSED); + if (item != -1) ListView_GetItemText(pChildWnd->hListWnd, item, 0, valueName, sizeof(valueName)/sizeof(TCHAR)); + switch (LOWORD(wParam)) { /* Parse the menu selections:*/ case ID_REGISTRY_IMPORTREGISTRYFILE: @@ -451,6 +464,10 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case ID_REGISTRY_PRINT: PrintRegistryHive(hWnd, _T("")); break; + case ID_EDIT_MODIFY: + if (ModifyValue(hWnd, hKey, valueName)) + RefreshListView(pChildWnd->hListWnd, hKeyRoot, keyPath); + break; case ID_EDIT_COPYKEYNAME: CopyKeyName(hWnd, _T("")); break; @@ -486,9 +503,11 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) #endif break; default: - return FALSE; - } - return TRUE; + result = FALSE; + } + + RegCloseKey(hKey); + return result; } /******************************************************************************** diff --git a/programs/regedit/main.c b/programs/regedit/main.c index d28965de307..06d76581b75 100644 --- a/programs/regedit/main.c +++ b/programs/regedit/main.c @@ -100,6 +100,8 @@ static BOOL DynamicBind( void ) d(GetMessageA) d(GetSubMenu) d(GetSystemMetrics) + d(GetWindowTextA) + d(GetWindowTextLengthA) d(InvertRect) d(IsWindowVisible) d(LoadAcceleratorsA) @@ -110,6 +112,7 @@ static BOOL DynamicBind( void ) d(LoadMenuA) d(LoadStringA) d(MessageBeep) + d(MessageBoxA) d(MoveWindow) d(OpenClipboard) d(PostQuitMessage) @@ -121,6 +124,7 @@ static BOOL DynamicBind( void ) d(SendMessageA) d(SetCapture) d(SetCursor) + d(SetDlgItemTextA) d(SetFocus) d(SetWindowLongA) d(SetWindowTextA) diff --git a/programs/regedit/main.h b/programs/regedit/main.h index 6131834925d..6f130c926f7 100644 --- a/programs/regedit/main.h +++ b/programs/regedit/main.h @@ -37,6 +37,7 @@ extern "C" { #define SPLIT_WIDTH 5 #define MAX_NAME_LEN 500 +#define COUNT_OF(a) (sizeof(a)/sizeof(a[0])) /******************************************************************************/ @@ -59,6 +60,7 @@ typedef struct { WINDOWPLACEMENT pos; TCHAR szPath[MAX_PATH]; } ChildWnd; +extern ChildWnd* pChildWnd; /******************************************************************************* * Global Variables: @@ -126,6 +128,8 @@ d(GetSaveFileNameA) d(GetStockObject) d(GetSubMenu) d(GetSystemMetrics) +d(GetWindowTextA) +d(GetWindowTextLengthA) d(ImageList_Add) d(ImageList_Create) d(ImageList_GetImageCount) @@ -140,6 +144,7 @@ d(LoadImageA) d(LoadMenuA) d(LoadStringA) d(MessageBeep) +d(MessageBoxA) d(MoveWindow) d(OpenClipboard) d(PostQuitMessage) @@ -152,6 +157,7 @@ d(ScreenToClient) d(SendMessageA) d(SetCapture) d(SetCursor) +d(SetDlgItemTextA) d(SetFocus) d(SetWindowLongA) d(SetWindowTextA) @@ -197,6 +203,8 @@ d(wsprintfA) #define GetStockObject pGetStockObject #define GetSubMenu pGetSubMenu #define GetSystemMetrics pGetSystemMetrics +#define GetWindowTextA pGetWindowTextA +#define GetWindowTextLengthA pGetWindowTextLengthA #define ImageList_Add pImageList_Add #define ImageList_Create pImageList_Create #define ImageList_GetImageCount pImageList_GetImageCount @@ -211,6 +219,7 @@ d(wsprintfA) #define LoadMenuA pLoadMenuA #define LoadStringA pLoadStringA #define MessageBeep pMessageBeep +#define MessageBoxA pMessageBoxA #define MoveWindow pMoveWindow #define OpenClipboard pOpenClipboard #define PostQuitMessage pPostQuitMessage @@ -223,6 +232,7 @@ d(wsprintfA) #define SendMessageA pSendMessageA #define SetCapture pSetCapture #define SetCursor pSetCursor +#define SetDlgItemTextA pSetDlgItemTextA #define SetFocus pSetFocus #define SetWindowLongA pSetWindowLongA #define SetWindowTextA pSetWindowTextA @@ -257,4 +267,7 @@ extern HWND CreateTreeView(HWND hwndParent, LPTSTR pHostName, int id); extern BOOL OnTreeExpanding(HWND hWnd, NMTREEVIEW* pnmtv); extern HKEY FindRegRoot(HWND hwndTV, HTREEITEM hItem, LPTSTR keyPath, int* pPathLen, int max); +/* edit.c */ +BOOL ModifyValue(HWND hwnd, HKEY hKey, LPTSTR valueName); + #endif /* __MAIN_H__ */ diff --git a/programs/regedit/resource.h b/programs/regedit/resource.h index f266d4075bd..06b2de88289 100644 --- a/programs/regedit/resource.h +++ b/programs/regedit/resource.h @@ -102,4 +102,13 @@ #define ID_REGISTRY_PRINTERSETUP 32833 #define ID_REGISTRY_SAVESUBTREEAS 32834 #define IDS_LICENSE 32835 +#define IDS_ERROR 32836 +#define IDS_BAD_VALUE 32837 +#define IDS_UNSUPPORTED_TYPE 32838 +#define IDS_TOO_BIG_VALUE 32839 + +#define IDD_EDIT_STRING 2000 +#define IDC_VALUE_NAME 2001 +#define IDC_VALUE_DATA 2002 + #define IDC_STATIC -1 diff --git a/programs/regedit/treeview.c b/programs/regedit/treeview.c index 3643c4f51a1..b947825679a 100644 --- a/programs/regedit/treeview.c +++ b/programs/regedit/treeview.c @@ -48,6 +48,9 @@ HKEY FindRegRoot(HWND hwndTV, HTREEITEM hItem, LPTSTR keyPath, int* pPathLen, in { HKEY hKey = NULL; TVITEM item; + + if (!hItem) hItem = TreeView_GetSelection(hwndTV); + item.mask = TVIF_PARAM; item.hItem = TreeView_GetParent(hwndTV, hItem);