4 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
29 #include "wine/debug.h"
30 #include "wine/unicode.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(regedit);
34 ChildWnd* g_pChildWnd;
35 static int last_split;
37 /*******************************************************************************
38 * Local module support methods
41 LPCTSTR GetRootKeyName(HKEY hRootKey)
43 if (hRootKey == HKEY_CLASSES_ROOT) return _T("HKEY_CLASSES_ROOT");
44 if (hRootKey == HKEY_CURRENT_USER) return _T("HKEY_CURRENT_USER");
45 if (hRootKey == HKEY_LOCAL_MACHINE) return _T("HKEY_LOCAL_MACHINE");
46 if (hRootKey == HKEY_USERS) return _T("HKEY_USERS");
47 if (hRootKey == HKEY_CURRENT_CONFIG) return _T("HKEY_CURRENT_CONFIG");
48 if (hRootKey == HKEY_DYN_DATA) return _T("HKEY_DYN_DATA");
49 return _T("UNKNOWN HKEY, PLEASE REPORT");
52 LPCWSTR GetRootKeyNameW(HKEY hRootKey)
54 if(hRootKey == HKEY_CLASSES_ROOT)
55 return reg_class_namesW[INDEX_HKEY_CLASSES_ROOT];
56 if(hRootKey == HKEY_CURRENT_USER)
57 return reg_class_namesW[INDEX_HKEY_CURRENT_USER];
58 if(hRootKey == HKEY_LOCAL_MACHINE)
59 return reg_class_namesW[INDEX_HKEY_LOCAL_MACHINE];
60 if(hRootKey == HKEY_USERS)
61 return reg_class_namesW[INDEX_HKEY_USERS];
62 if(hRootKey == HKEY_CURRENT_CONFIG)
63 return reg_class_namesW[INDEX_HKEY_CURRENT_CONFIG];
64 if(hRootKey == HKEY_DYN_DATA)
65 return reg_class_namesW[INDEX_HKEY_DYN_DATA];
68 static const WCHAR unknown_key[] = {'U','N','K','N','O','W','N',' ','H','K','E','Y',',',' ',
69 'P','L','E','A','S','E',' ','R','E','P','O','R','T',0};
74 static void draw_splitbar(HWND hWnd, int x)
77 HDC hdc = GetDC(hWnd);
79 GetClientRect(hWnd, &rt);
80 rt.left = x - SPLIT_WIDTH/2;
81 rt.right = x + SPLIT_WIDTH/2+1;
86 static void ResizeWnd(int cx, int cy)
88 HDWP hdwp = BeginDeferWindowPos(2);
89 RECT rt = {0, 0, cx, cy};
91 cx = g_pChildWnd->nSplitPos + SPLIT_WIDTH/2;
92 DeferWindowPos(hdwp, g_pChildWnd->hTreeWnd, 0, rt.left, rt.top, g_pChildWnd->nSplitPos-SPLIT_WIDTH/2-rt.left, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
93 DeferWindowPos(hdwp, g_pChildWnd->hListWnd, 0, rt.left+cx , rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
94 EndDeferWindowPos(hdwp);
97 static void OnPaint(HWND hWnd)
103 GetClientRect(hWnd, &rt);
104 hdc = BeginPaint(hWnd, &ps);
105 FillRect(ps.hdc, &rt, GetSysColorBrush(COLOR_BTNFACE));
109 static LPTSTR CombinePaths(LPCTSTR pPaths[], int nPaths) {
112 for (i=0, len=0; i<nPaths; i++) {
113 if (pPaths[i] && *pPaths[i]) {
114 len += lstrlen(pPaths[i])+1;
117 combined = HeapAlloc(GetProcessHeap(), 0, len * sizeof(TCHAR));
119 for (i=0, pos=0; i<nPaths; i++) {
120 if (pPaths[i] && *pPaths[i]) {
121 int llen = _tcslen(pPaths[i]);
123 _tcscpy(combined, pPaths[i]);
125 combined[pos++] = (TCHAR)'\\';
126 _tcscpy(combined+pos, pPaths[i]);
134 static LPWSTR CombinePathsW(LPCWSTR pPaths[], int nPaths) {
137 for (i=0, len=0; i<nPaths; i++) {
138 if (pPaths[i] && *pPaths[i]) {
139 len += lstrlenW(pPaths[i])+1;
142 combined = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
144 for (i=0, pos=0; i<nPaths; i++) {
145 if (pPaths[i] && *pPaths[i]) {
146 int llen = lstrlenW(pPaths[i]);
148 lstrcpyW(combined, pPaths[i]);
150 combined[pos++] = (TCHAR)'\\';
151 lstrcpyW(combined+pos, pPaths[i]);
159 static LPTSTR GetPathRoot(HWND hwndTV, HTREEITEM hItem, BOOL bFull) {
160 LPCTSTR parts[2] = {_T(""), _T("")};
162 HKEY hRootKey = NULL;
164 hItem = TreeView_GetSelection(hwndTV);
165 GetItemPath(hwndTV, hItem, &hRootKey);
166 if (!bFull && !hRootKey)
169 parts[1] = GetRootKeyName(hRootKey);
171 DWORD dwSize = sizeof(text)/sizeof(TCHAR);
172 GetComputerName(text, &dwSize);
175 return CombinePaths(parts, 2);
178 static LPWSTR GetPathRootW(HWND hwndTV, HTREEITEM hItem, BOOL bFull) {
179 LPCWSTR parts[2] = {0,0};
181 HKEY hRootKey = NULL;
183 hItem = TreeView_GetSelection(hwndTV);
184 GetItemPathW(hwndTV, hItem, &hRootKey);
185 if (!bFull && !hRootKey)
188 parts[1] = GetRootKeyNameW(hRootKey);
190 DWORD dwSize = sizeof(text)/sizeof(TCHAR);
191 GetComputerNameW(text, &dwSize);
194 return CombinePathsW(parts, 2);
197 LPTSTR GetItemFullPath(HWND hwndTV, HTREEITEM hItem, BOOL bFull) {
200 HKEY hRootKey = NULL;
202 parts[0] = GetPathRoot(hwndTV, hItem, bFull);
203 parts[1] = GetItemPath(hwndTV, hItem, &hRootKey);
204 ret = CombinePaths((LPCTSTR *)parts, 2);
205 HeapFree(GetProcessHeap(), 0, parts[0]);
209 LPWSTR GetItemFullPathW(HWND hwndTV, HTREEITEM hItem, BOOL bFull) {
212 HKEY hRootKey = NULL;
214 parts[0] = GetPathRootW(hwndTV, hItem, bFull);
215 parts[1] = GetItemPathW(hwndTV, hItem, &hRootKey);
216 ret = CombinePathsW((LPCWSTR *)parts, 2);
217 HeapFree(GetProcessHeap(), 0, parts[0]);
218 HeapFree(GetProcessHeap(), 0, parts[1]);
222 static LPTSTR GetPathFullPath(HWND hwndTV, LPTSTR path) {
226 parts[0] = GetPathRoot(hwndTV, 0, TRUE);
228 ret = CombinePaths((LPCTSTR *)parts, 2);
229 HeapFree(GetProcessHeap(), 0, parts[0]);
233 static void OnTreeSelectionChanged(HWND hwndTV, HWND hwndLV, HTREEITEM hItem, BOOL bRefreshLV)
237 HKEY hRootKey = NULL;
238 keyPath = GetItemPath(hwndTV, hItem, &hRootKey);
239 RefreshListView(hwndLV, hRootKey, keyPath, NULL);
244 /*******************************************************************************
245 * finish_splitbar [internal]
247 * make the splitbar invisible and resize the windows
248 * (helper for ChildWndProc)
250 static void finish_splitbar(HWND hWnd, int x)
254 draw_splitbar(hWnd, last_split);
256 GetClientRect(hWnd, &rt);
257 g_pChildWnd->nSplitPos = x;
258 ResizeWnd(rt.right, rt.bottom);
262 /*******************************************************************************
264 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
266 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
270 static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
272 switch (LOWORD(wParam)) {
273 /* Parse the menu selections: */
274 case ID_REGISTRY_EXIT:
277 case ID_VIEW_REFRESH:
278 WINE_TRACE("Is this ever called or is it just dead code?\n");
281 case ID_SWITCH_PANELS:
282 g_pChildWnd->nFocusPanel = !g_pChildWnd->nFocusPanel;
283 SetFocus(g_pChildWnd->nFocusPanel? g_pChildWnd->hListWnd: g_pChildWnd->hTreeWnd);
291 /*******************************************************************************
293 * FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
295 * PURPOSE: Processes messages for the child windows.
297 * WM_COMMAND - process the application menu
298 * WM_PAINT - Paint the main window
299 * WM_DESTROY - post a quit message and return
302 LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
306 g_pChildWnd = HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd));
307 if (!g_pChildWnd) return 0;
308 LoadStringW(hInst, IDS_REGISTRY_ROOT_NAME, g_pChildWnd->szPath, MAX_PATH);
309 g_pChildWnd->nSplitPos = 250;
310 g_pChildWnd->hWnd = hWnd;
311 g_pChildWnd->hTreeWnd = CreateTreeView(hWnd, g_pChildWnd->szPath, TREE_WINDOW);
312 g_pChildWnd->hListWnd = CreateListView(hWnd, LIST_WINDOW/*, g_pChildWnd->szPath*/);
313 g_pChildWnd->nFocusPanel = 1;
314 SetFocus(g_pChildWnd->hTreeWnd);
317 if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
325 if (LOWORD(lParam) == HTCLIENT) {
328 ScreenToClient(hWnd, &pt);
329 if (pt.x>=g_pChildWnd->nSplitPos-SPLIT_WIDTH/2 && pt.x<g_pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
330 SetCursor(LoadCursor(0, IDC_SIZEWE));
336 HeapFree(GetProcessHeap(), 0, g_pChildWnd);
340 case WM_LBUTTONDOWN: {
342 int x = (short)LOWORD(lParam);
343 GetClientRect(hWnd, &rt);
344 if (x>=g_pChildWnd->nSplitPos-SPLIT_WIDTH/2 && x<g_pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
345 last_split = g_pChildWnd->nSplitPos;
346 draw_splitbar(hWnd, last_split);
352 /* WM_RBUTTONDOWN sets the splitbar the same way as WM_LBUTTONUP */
355 if (GetCapture() == hWnd) {
356 finish_splitbar(hWnd, LOWORD(lParam));
360 case WM_CAPTURECHANGED:
361 if (GetCapture()==hWnd && last_split>=0)
362 draw_splitbar(hWnd, last_split);
366 if (wParam == VK_ESCAPE)
367 if (GetCapture() == hWnd) {
369 draw_splitbar(hWnd, last_split);
370 GetClientRect(hWnd, &rt);
371 ResizeWnd(rt.right, rt.bottom);
374 SetCursor(LoadCursor(0, IDC_ARROW));
379 if (GetCapture() == hWnd) {
381 int x = LOWORD(lParam);
382 HDC hdc = GetDC(hWnd);
383 GetClientRect(hWnd, &rt);
384 rt.left = last_split-SPLIT_WIDTH/2;
385 rt.right = last_split+SPLIT_WIDTH/2+1;
386 InvertRect(hdc, &rt);
388 rt.left = x-SPLIT_WIDTH/2;
389 rt.right = x+SPLIT_WIDTH/2+1;
390 InvertRect(hdc, &rt);
391 ReleaseDC(hWnd, hdc);
396 if (g_pChildWnd != NULL) {
397 SetFocus(g_pChildWnd->nFocusPanel? g_pChildWnd->hListWnd: g_pChildWnd->hTreeWnd);
405 if (((int)wParam == TREE_WINDOW) && (g_pChildWnd != NULL)) {
406 switch (((LPNMHDR)lParam)->code) {
407 case TVN_ITEMEXPANDING:
408 return !OnTreeExpanding(g_pChildWnd->hTreeWnd, (NMTREEVIEW*)lParam);
410 OnTreeSelectionChanged(g_pChildWnd->hTreeWnd, g_pChildWnd->hListWnd,
411 ((NMTREEVIEW *)lParam)->itemNew.hItem, TRUE);
414 g_pChildWnd->nFocusPanel = 0;
419 TrackPopupMenu(GetSubMenu(hPopupMenus, PM_NEW),
420 TPM_RIGHTBUTTON, pt.x, pt.y, 0, hFrameWnd, NULL);
423 case TVN_ENDLABELEDIT: {
425 LPNMTVDISPINFO dispInfo = (LPNMTVDISPINFO)lParam;
426 LPCTSTR path = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
427 BOOL res = RenameKey(hWnd, hRootKey, path, dispInfo->item.pszText);
430 LPTSTR fullPath = GetPathFullPath(g_pChildWnd->hTreeWnd,
431 dispInfo->item.pszText);
432 item.mask = TVIF_HANDLE | TVIF_TEXT;
433 item.hItem = TreeView_GetSelection(g_pChildWnd->hTreeWnd);
434 item.pszText = dispInfo->item.pszText;
435 SendMessage( g_pChildWnd->hTreeWnd, TVM_SETITEMW, 0, (LPARAM)&item );
436 SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)fullPath);
437 HeapFree(GetProcessHeap(), 0, fullPath);
442 return 0; /* goto def; */
445 if (((int)wParam == LIST_WINDOW) && (g_pChildWnd != NULL)) {
446 if (((LPNMHDR)lParam)->code == NM_SETFOCUS) {
447 g_pChildWnd->nFocusPanel = 1;
448 } else if (!SendMessage(g_pChildWnd->hListWnd, WM_NOTIFY_REFLECT, wParam, lParam)) {
455 if (wParam != SIZE_MINIMIZED && g_pChildWnd != NULL) {
456 ResizeWnd(LOWORD(lParam), HIWORD(lParam));
460 return DefWindowProc(hWnd, message, wParam, lParam);