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
;
36 /*******************************************************************************
37 * Local module support methods
40 LPCTSTR
GetRootKeyName(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 if (hRootKey
== HKEY_DYN_DATA
) return _T("HKEY_DYN_DATA");
48 return _T("UNKNOWN HKEY, PLEASE REPORT");
51 static void draw_splitbar(HWND hWnd
, int x
)
54 HDC hdc
= GetDC(hWnd
);
56 GetClientRect(hWnd
, &rt
);
57 rt
.left
= x
- SPLIT_WIDTH
/2;
58 rt
.right
= x
+ SPLIT_WIDTH
/2+1;
63 static void ResizeWnd(ChildWnd
* pChildWnd
, int cx
, int cy
)
65 HDWP hdwp
= BeginDeferWindowPos(2);
66 RECT rt
= {0, 0, cx
, cy
};
68 cx
= pChildWnd
->nSplitPos
+ SPLIT_WIDTH
/2;
69 DeferWindowPos(hdwp
, pChildWnd
->hTreeWnd
, 0, rt
.left
, rt
.top
, pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2-rt
.left
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
70 DeferWindowPos(hdwp
, pChildWnd
->hListWnd
, 0, rt
.left
+cx
, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
71 EndDeferWindowPos(hdwp
);
74 static void OnPaint(HWND hWnd
)
80 GetClientRect(hWnd
, &rt
);
81 hdc
= BeginPaint(hWnd
, &ps
);
82 FillRect(ps
.hdc
, &rt
, GetSysColorBrush(COLOR_BTNFACE
));
86 static LPTSTR
CombinePaths(LPCTSTR pPaths
[], int nPaths
) {
89 for (i
=0, len
=0; i
<nPaths
; i
++) {
90 if (pPaths
[i
] && *pPaths
[i
]) {
91 len
+= lstrlen(pPaths
[i
])+1;
94 combined
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(TCHAR
));
96 for (i
=0, pos
=0; i
<nPaths
; i
++) {
97 if (pPaths
[i
] && *pPaths
[i
]) {
98 int llen
= _tcslen(pPaths
[i
]);
100 _tcscpy(combined
, pPaths
[i
]);
102 combined
[pos
++] = (TCHAR
)'\\';
103 _tcscpy(combined
+pos
, pPaths
[i
]);
111 static LPTSTR
GetPathRoot(HWND hwndTV
, HTREEITEM hItem
, BOOL bFull
) {
112 LPCTSTR parts
[2] = {_T(""), _T("")};
114 HKEY hRootKey
= NULL
;
116 hItem
= TreeView_GetSelection(hwndTV
);
117 GetItemPath(hwndTV
, hItem
, &hRootKey
);
118 if (!bFull
&& !hRootKey
)
121 parts
[1] = GetRootKeyName(hRootKey
);
123 DWORD dwSize
= sizeof(text
)/sizeof(TCHAR
);
124 GetComputerName(text
, &dwSize
);
127 return CombinePaths(parts
, 2);
130 LPTSTR
GetItemFullPath(HWND hwndTV
, HTREEITEM hItem
, BOOL bFull
) {
133 HKEY hRootKey
= NULL
;
135 parts
[0] = GetPathRoot(hwndTV
, hItem
, bFull
);
136 parts
[1] = GetItemPath(hwndTV
, hItem
, &hRootKey
);
137 ret
= CombinePaths((LPCTSTR
*)parts
, 2);
138 HeapFree(GetProcessHeap(), 0, parts
[0]);
142 LPTSTR
GetPathFullPath(HWND hwndTV
, LPTSTR path
) {
146 parts
[0] = GetPathRoot(hwndTV
, 0, TRUE
);
148 ret
= CombinePaths((LPCTSTR
*)parts
, 2);
149 HeapFree(GetProcessHeap(), 0, parts
[0]);
153 static void OnTreeSelectionChanged(HWND hwndTV
, HWND hwndLV
, HTREEITEM hItem
, BOOL bRefreshLV
)
157 HKEY hRootKey
= NULL
;
158 keyPath
= GetItemPath(hwndTV
, hItem
, &hRootKey
);
159 RefreshListView(hwndLV
, hRootKey
, keyPath
, NULL
);
164 /*******************************************************************************
166 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
168 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
172 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
174 ChildWnd
* pChildWnd
= g_pChildWnd
;
175 switch (LOWORD(wParam
)) {
176 /* Parse the menu selections: */
177 case ID_REGISTRY_EXIT
:
180 case ID_VIEW_REFRESH
:
181 WINE_TRACE("Is this ever called or is it just dead code?\n");
184 case ID_SWITCH_PANELS
:
185 pChildWnd
->nFocusPanel
= !pChildWnd
->nFocusPanel
;
186 SetFocus(pChildWnd
->nFocusPanel
? pChildWnd
->hListWnd
: pChildWnd
->hTreeWnd
);
194 /*******************************************************************************
196 * FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
198 * PURPOSE: Processes messages for the child windows.
200 * WM_COMMAND - process the application menu
201 * WM_PAINT - Paint the main window
202 * WM_DESTROY - post a quit message and return
205 LRESULT CALLBACK
ChildWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
207 static int last_split
;
208 ChildWnd
* pChildWnd
= g_pChildWnd
;
212 g_pChildWnd
= pChildWnd
= HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd
));
213 if (!pChildWnd
) return 0;
214 LoadString(hInst
, IDS_REGISTRY_ROOT_NAME
, pChildWnd
->szPath
, MAX_PATH
);
215 pChildWnd
->nSplitPos
= 250;
216 pChildWnd
->hWnd
= hWnd
;
217 pChildWnd
->hTreeWnd
= CreateTreeView(hWnd
, pChildWnd
->szPath
, TREE_WINDOW
);
218 pChildWnd
->hListWnd
= CreateListView(hWnd
, LIST_WINDOW
/*, pChildWnd->szPath*/);
219 pChildWnd
->nFocusPanel
= 1;
220 SetFocus(pChildWnd
->hTreeWnd
);
223 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
)) {
231 if (LOWORD(lParam
) == HTCLIENT
) {
234 ScreenToClient(hWnd
, &pt
);
235 if (pt
.x
>=pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && pt
.x
<pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1) {
236 SetCursor(LoadCursor(0, IDC_SIZEWE
));
242 HeapFree(GetProcessHeap(), 0, pChildWnd
);
246 case WM_LBUTTONDOWN
: {
248 int x
= (short)LOWORD(lParam
);
249 GetClientRect(hWnd
, &rt
);
250 if (x
>=pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && x
<pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1) {
251 last_split
= pChildWnd
->nSplitPos
;
252 draw_splitbar(hWnd
, last_split
);
259 if (GetCapture() == hWnd
) {
261 int x
= LOWORD(lParam
);
262 draw_splitbar(hWnd
, last_split
);
264 GetClientRect(hWnd
, &rt
);
265 pChildWnd
->nSplitPos
= x
;
266 ResizeWnd(pChildWnd
, rt
.right
, rt
.bottom
);
271 case WM_CAPTURECHANGED
:
272 if (GetCapture()==hWnd
&& last_split
>=0)
273 draw_splitbar(hWnd
, last_split
);
277 if (wParam
== VK_ESCAPE
)
278 if (GetCapture() == hWnd
) {
280 draw_splitbar(hWnd
, last_split
);
281 GetClientRect(hWnd
, &rt
);
282 ResizeWnd(pChildWnd
, rt
.right
, rt
.bottom
);
285 SetCursor(LoadCursor(0, IDC_ARROW
));
290 if (GetCapture() == hWnd
) {
292 int x
= LOWORD(lParam
);
293 HDC hdc
= GetDC(hWnd
);
294 GetClientRect(hWnd
, &rt
);
295 rt
.left
= last_split
-SPLIT_WIDTH
/2;
296 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
297 InvertRect(hdc
, &rt
);
299 rt
.left
= x
-SPLIT_WIDTH
/2;
300 rt
.right
= x
+SPLIT_WIDTH
/2+1;
301 InvertRect(hdc
, &rt
);
302 ReleaseDC(hWnd
, hdc
);
307 if (pChildWnd
!= NULL
) {
308 SetFocus(pChildWnd
->nFocusPanel
? pChildWnd
->hListWnd
: pChildWnd
->hTreeWnd
);
316 if ((int)wParam
== TREE_WINDOW
) {
317 switch (((LPNMHDR
)lParam
)->code
) {
318 case TVN_ITEMEXPANDING
:
319 return !OnTreeExpanding(pChildWnd
->hTreeWnd
, (NMTREEVIEW
*)lParam
);
321 OnTreeSelectionChanged(pChildWnd
->hTreeWnd
, pChildWnd
->hListWnd
,
322 ((NMTREEVIEW
*)lParam
)->itemNew
.hItem
, TRUE
);
325 pChildWnd
->nFocusPanel
= 0;
330 TrackPopupMenu(GetSubMenu(hPopupMenus
, PM_NEW
),
331 TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, hFrameWnd
, NULL
);
334 case TVN_ENDLABELEDIT
: {
336 LPNMTVDISPINFO dispInfo
= (LPNMTVDISPINFO
)lParam
;
337 LPCTSTR path
= GetItemPath(pChildWnd
->hTreeWnd
, 0, &hRootKey
);
338 BOOL res
= RenameKey(hWnd
, hRootKey
, path
, dispInfo
->item
.pszText
);
341 LPTSTR fullPath
= GetPathFullPath(pChildWnd
->hTreeWnd
,
342 dispInfo
->item
.pszText
);
343 item
.mask
= TVIF_HANDLE
| TVIF_TEXT
;
344 item
.hItem
= TreeView_GetSelection(pChildWnd
->hTreeWnd
);
345 item
.pszText
= dispInfo
->item
.pszText
;
346 SendMessage( pChildWnd
->hTreeWnd
, TVM_SETITEMW
, 0, (LPARAM
)&item
);
347 SendMessage(hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)fullPath
);
348 HeapFree(GetProcessHeap(), 0, fullPath
);
353 return 0; /* goto def; */
356 if ((int)wParam
== LIST_WINDOW
) {
357 if (((LPNMHDR
)lParam
)->code
== NM_SETFOCUS
) {
358 pChildWnd
->nFocusPanel
= 1;
359 } else if (!SendMessage(pChildWnd
->hListWnd
, WM_NOTIFY_REFLECT
, wParam
, lParam
)) {
366 if (wParam
!= SIZE_MINIMIZED
&& pChildWnd
!= NULL
) {
367 ResizeWnd(pChildWnd
, LOWORD(lParam
), HIWORD(lParam
));
371 return DefWindowProc(hWnd
, message
, wParam
, lParam
);