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]);
221 static LPTSTR
GetPathFullPath(HWND hwndTV
, LPTSTR path
) {
225 parts
[0] = GetPathRoot(hwndTV
, 0, TRUE
);
227 ret
= CombinePaths((LPCTSTR
*)parts
, 2);
228 HeapFree(GetProcessHeap(), 0, parts
[0]);
232 static void OnTreeSelectionChanged(HWND hwndTV
, HWND hwndLV
, HTREEITEM hItem
, BOOL bRefreshLV
)
236 HKEY hRootKey
= NULL
;
237 keyPath
= GetItemPath(hwndTV
, hItem
, &hRootKey
);
238 RefreshListView(hwndLV
, hRootKey
, keyPath
, NULL
);
243 /*******************************************************************************
244 * finish_splitbar [internal]
246 * make the splitbar invisible and resize the windows
247 * (helper for ChildWndProc)
249 static void finish_splitbar(HWND hWnd
, int x
)
253 draw_splitbar(hWnd
, last_split
);
255 GetClientRect(hWnd
, &rt
);
256 g_pChildWnd
->nSplitPos
= x
;
257 ResizeWnd(rt
.right
, rt
.bottom
);
261 /*******************************************************************************
263 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
265 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
269 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
271 switch (LOWORD(wParam
)) {
272 /* Parse the menu selections: */
273 case ID_REGISTRY_EXIT
:
276 case ID_VIEW_REFRESH
:
277 WINE_TRACE("Is this ever called or is it just dead code?\n");
280 case ID_SWITCH_PANELS
:
281 g_pChildWnd
->nFocusPanel
= !g_pChildWnd
->nFocusPanel
;
282 SetFocus(g_pChildWnd
->nFocusPanel
? g_pChildWnd
->hListWnd
: g_pChildWnd
->hTreeWnd
);
290 /*******************************************************************************
292 * FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
294 * PURPOSE: Processes messages for the child windows.
296 * WM_COMMAND - process the application menu
297 * WM_PAINT - Paint the main window
298 * WM_DESTROY - post a quit message and return
301 LRESULT CALLBACK
ChildWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
305 g_pChildWnd
= HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd
));
306 if (!g_pChildWnd
) return 0;
307 LoadString(hInst
, IDS_REGISTRY_ROOT_NAME
, g_pChildWnd
->szPath
, MAX_PATH
);
308 g_pChildWnd
->nSplitPos
= 250;
309 g_pChildWnd
->hWnd
= hWnd
;
310 g_pChildWnd
->hTreeWnd
= CreateTreeView(hWnd
, g_pChildWnd
->szPath
, TREE_WINDOW
);
311 g_pChildWnd
->hListWnd
= CreateListView(hWnd
, LIST_WINDOW
/*, g_pChildWnd->szPath*/);
312 g_pChildWnd
->nFocusPanel
= 1;
313 SetFocus(g_pChildWnd
->hTreeWnd
);
316 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
)) {
324 if (LOWORD(lParam
) == HTCLIENT
) {
327 ScreenToClient(hWnd
, &pt
);
328 if (pt
.x
>=g_pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && pt
.x
<g_pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1) {
329 SetCursor(LoadCursor(0, IDC_SIZEWE
));
335 HeapFree(GetProcessHeap(), 0, g_pChildWnd
);
339 case WM_LBUTTONDOWN
: {
341 int x
= (short)LOWORD(lParam
);
342 GetClientRect(hWnd
, &rt
);
343 if (x
>=g_pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && x
<g_pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1) {
344 last_split
= g_pChildWnd
->nSplitPos
;
345 draw_splitbar(hWnd
, last_split
);
351 /* WM_RBUTTONDOWN sets the splitbar the same way as WM_LBUTTONUP */
354 if (GetCapture() == hWnd
) {
355 finish_splitbar(hWnd
, LOWORD(lParam
));
359 case WM_CAPTURECHANGED
:
360 if (GetCapture()==hWnd
&& last_split
>=0)
361 draw_splitbar(hWnd
, last_split
);
365 if (wParam
== VK_ESCAPE
)
366 if (GetCapture() == hWnd
) {
368 draw_splitbar(hWnd
, last_split
);
369 GetClientRect(hWnd
, &rt
);
370 ResizeWnd(rt
.right
, rt
.bottom
);
373 SetCursor(LoadCursor(0, IDC_ARROW
));
378 if (GetCapture() == hWnd
) {
380 int x
= LOWORD(lParam
);
381 HDC hdc
= GetDC(hWnd
);
382 GetClientRect(hWnd
, &rt
);
383 rt
.left
= last_split
-SPLIT_WIDTH
/2;
384 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
385 InvertRect(hdc
, &rt
);
387 rt
.left
= x
-SPLIT_WIDTH
/2;
388 rt
.right
= x
+SPLIT_WIDTH
/2+1;
389 InvertRect(hdc
, &rt
);
390 ReleaseDC(hWnd
, hdc
);
395 if (g_pChildWnd
!= NULL
) {
396 SetFocus(g_pChildWnd
->nFocusPanel
? g_pChildWnd
->hListWnd
: g_pChildWnd
->hTreeWnd
);
404 if (((int)wParam
== TREE_WINDOW
) && (g_pChildWnd
!= NULL
)) {
405 switch (((LPNMHDR
)lParam
)->code
) {
406 case TVN_ITEMEXPANDING
:
407 return !OnTreeExpanding(g_pChildWnd
->hTreeWnd
, (NMTREEVIEW
*)lParam
);
409 OnTreeSelectionChanged(g_pChildWnd
->hTreeWnd
, g_pChildWnd
->hListWnd
,
410 ((NMTREEVIEW
*)lParam
)->itemNew
.hItem
, TRUE
);
413 g_pChildWnd
->nFocusPanel
= 0;
418 TrackPopupMenu(GetSubMenu(hPopupMenus
, PM_NEW
),
419 TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, hFrameWnd
, NULL
);
422 case TVN_ENDLABELEDIT
: {
424 LPNMTVDISPINFO dispInfo
= (LPNMTVDISPINFO
)lParam
;
425 LPCTSTR path
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hRootKey
);
426 BOOL res
= RenameKey(hWnd
, hRootKey
, path
, dispInfo
->item
.pszText
);
429 LPTSTR fullPath
= GetPathFullPath(g_pChildWnd
->hTreeWnd
,
430 dispInfo
->item
.pszText
);
431 item
.mask
= TVIF_HANDLE
| TVIF_TEXT
;
432 item
.hItem
= TreeView_GetSelection(g_pChildWnd
->hTreeWnd
);
433 item
.pszText
= dispInfo
->item
.pszText
;
434 SendMessage( g_pChildWnd
->hTreeWnd
, TVM_SETITEMW
, 0, (LPARAM
)&item
);
435 SendMessage(hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)fullPath
);
436 HeapFree(GetProcessHeap(), 0, fullPath
);
441 return 0; /* goto def; */
444 if (((int)wParam
== LIST_WINDOW
) && (g_pChildWnd
!= NULL
)) {
445 if (((LPNMHDR
)lParam
)->code
== NM_SETFOCUS
) {
446 g_pChildWnd
->nFocusPanel
= 1;
447 } else if (!SendMessage(g_pChildWnd
->hListWnd
, WM_NOTIFY_REFLECT
, wParam
, lParam
)) {
454 if (wParam
!= SIZE_MINIMIZED
&& g_pChildWnd
!= NULL
) {
455 ResizeWnd(LOWORD(lParam
), HIWORD(lParam
));
459 return DefWindowProc(hWnd
, message
, wParam
, lParam
);