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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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;
36 /*******************************************************************************
37 * Local module support methods
40 static LPCTSTR get_root_key_name(HKEY hRootKey)
42 if (hRootKey == HKEY_CLASSES_ROOT) return _T("HKEY_CLASSES_ROOT");
43 if (hRootKey == HKEY_CURRENT_USER) return _T("HKEY_CURRENT_USER");
44 if (hRootKey == HKEY_LOCAL_MACHINE) return _T("HKEY_LOCAL_MACHINE");
45 if (hRootKey == HKEY_USERS) return _T("HKEY_USERS");
46 if (hRootKey == HKEY_CURRENT_CONFIG) return _T("HKEY_CURRENT_CONFIG");
47 return _T("UKNOWN HKEY, PLEASE REPORT");
50 static void draw_splitbar(HWND hWnd, int x)
53 HDC hdc = GetDC(hWnd);
55 GetClientRect(hWnd, &rt);
56 rt.left = x - SPLIT_WIDTH/2;
57 rt.right = x + SPLIT_WIDTH/2+1;
62 static void ResizeWnd(ChildWnd* pChildWnd, int cx, int cy)
64 HDWP hdwp = BeginDeferWindowPos(2);
65 RECT rt = {0, 0, cx, cy};
67 cx = pChildWnd->nSplitPos + SPLIT_WIDTH/2;
68 DeferWindowPos(hdwp, pChildWnd->hTreeWnd, 0, rt.left, rt.top, pChildWnd->nSplitPos-SPLIT_WIDTH/2-rt.left, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
69 DeferWindowPos(hdwp, pChildWnd->hListWnd, 0, rt.left+cx , rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
70 EndDeferWindowPos(hdwp);
73 static void OnPaint(HWND hWnd)
79 GetClientRect(hWnd, &rt);
80 hdc = BeginPaint(hWnd, &ps);
81 FillRect(ps.hdc, &rt, GetSysColorBrush(COLOR_BTNFACE));
85 /*******************************************************************************
87 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
89 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
93 static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
95 ChildWnd* pChildWnd = g_pChildWnd;
96 switch (LOWORD(wParam)) {
97 /* Parse the menu selections: */
98 case ID_REGISTRY_EXIT:
101 case ID_VIEW_REFRESH:
104 case ID_SWITCH_PANELS:
105 pChildWnd->nFocusPanel = !pChildWnd->nFocusPanel;
106 SetFocus(pChildWnd->nFocusPanel? pChildWnd->hListWnd: pChildWnd->hTreeWnd);
114 /*******************************************************************************
116 * FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
118 * PURPOSE: Processes messages for the child windows.
120 * WM_COMMAND - process the application menu
121 * WM_PAINT - Paint the main window
122 * WM_DESTROY - post a quit message and return
125 LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
127 static int last_split;
128 ChildWnd* pChildWnd = g_pChildWnd;
132 g_pChildWnd = pChildWnd = HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd));
133 if (!pChildWnd) return 0;
134 _tcsncpy(pChildWnd->szPath, _T("My Computer"), MAX_PATH);
135 pChildWnd->nSplitPos = 250;
136 pChildWnd->hWnd = hWnd;
137 pChildWnd->hTreeWnd = CreateTreeView(hWnd, pChildWnd->szPath, TREE_WINDOW);
138 pChildWnd->hListWnd = CreateListView(hWnd, LIST_WINDOW/*, pChildWnd->szPath*/);
139 SetFocus(pChildWnd->hTreeWnd);
142 if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
150 if (LOWORD(lParam) == HTCLIENT) {
153 ScreenToClient(hWnd, &pt);
154 if (pt.x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && pt.x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
155 SetCursor(LoadCursor(0, IDC_SIZEWE));
161 HeapFree(GetProcessHeap(), 0, pChildWnd);
165 case WM_LBUTTONDOWN: {
167 int x = LOWORD(lParam);
168 GetClientRect(hWnd, &rt);
169 if (x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
170 last_split = pChildWnd->nSplitPos;
171 draw_splitbar(hWnd, last_split);
178 if (GetCapture() == hWnd) {
180 int x = LOWORD(lParam);
181 draw_splitbar(hWnd, last_split);
183 GetClientRect(hWnd, &rt);
184 pChildWnd->nSplitPos = x;
185 ResizeWnd(pChildWnd, rt.right, rt.bottom);
190 case WM_CAPTURECHANGED:
191 if (GetCapture()==hWnd && last_split>=0)
192 draw_splitbar(hWnd, last_split);
196 if (wParam == VK_ESCAPE)
197 if (GetCapture() == hWnd) {
199 draw_splitbar(hWnd, last_split);
200 GetClientRect(hWnd, &rt);
201 ResizeWnd(pChildWnd, rt.right, rt.bottom);
204 SetCursor(LoadCursor(0, IDC_ARROW));
209 if (GetCapture() == hWnd) {
211 int x = LOWORD(lParam);
212 HDC hdc = GetDC(hWnd);
213 GetClientRect(hWnd, &rt);
214 rt.left = last_split-SPLIT_WIDTH/2;
215 rt.right = last_split+SPLIT_WIDTH/2+1;
216 InvertRect(hdc, &rt);
218 rt.left = x-SPLIT_WIDTH/2;
219 rt.right = x+SPLIT_WIDTH/2+1;
220 InvertRect(hdc, &rt);
221 ReleaseDC(hWnd, hdc);
226 if (pChildWnd != NULL) {
227 SetFocus(pChildWnd->nFocusPanel? pChildWnd->hListWnd: pChildWnd->hTreeWnd);
235 if ((int)wParam == TREE_WINDOW) {
236 switch (((LPNMHDR)lParam)->code) {
237 case TVN_ITEMEXPANDING:
238 return !OnTreeExpanding(pChildWnd->hTreeWnd, (NMTREEVIEW*)lParam);
239 case TVN_SELCHANGED: {
240 LPCTSTR keyPath, rootName;
244 keyPath = GetItemPath(pChildWnd->hTreeWnd, ((NMTREEVIEW*)lParam)->itemNew.hItem, &hRootKey);
246 RefreshListView(pChildWnd->hListWnd, hRootKey, keyPath, NULL);
247 rootName = get_root_key_name(hRootKey);
248 fullPath = HeapAlloc(GetProcessHeap(), 0, (lstrlen(rootName) + 1 + lstrlen(keyPath) + 1) * sizeof(TCHAR));
250 _stprintf(fullPath, "%s\\%s", rootName, keyPath);
251 SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)fullPath);
252 HeapFree(GetProcessHeap(), 0, fullPath);
258 pChildWnd->nFocusPanel = 0;
263 TrackPopupMenu(GetSubMenu(hPopupMenus, PM_NEW),
264 TPM_RIGHTBUTTON, pt.x, pt.y, 0, hFrameWnd, NULL);
267 case TVN_ENDLABELEDIT: {
269 LPNMTVDISPINFO dispInfo = (LPNMTVDISPINFO)lParam;
270 LPCTSTR path = GetItemPath(pChildWnd->hTreeWnd, 0, &hRootKey);
271 BOOL res = RenameKey(hWnd, hRootKey, path, dispInfo->item.pszText);
274 item.mask = TVIF_HANDLE | TVIF_TEXT;
275 item.hItem = TreeView_GetSelection(pChildWnd->hTreeWnd);
276 item.pszText = dispInfo->item.pszText;
277 TreeView_SetItem(pChildWnd->hTreeWnd, &item);
282 return 0; /* goto def; */
285 if ((int)wParam == LIST_WINDOW) {
286 if (((LPNMHDR)lParam)->code == NM_SETFOCUS) {
287 pChildWnd->nFocusPanel = 1;
288 } else if (!SendMessage(pChildWnd->hListWnd, WM_NOTIFY_REFLECT, wParam, lParam)) {
295 if (wParam != SIZE_MINIMIZED && pChildWnd != NULL) {
296 ResizeWnd(pChildWnd, LOWORD(lParam), HIWORD(lParam));
300 return DefWindowProc(hWnd, message, wParam, lParam);