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 static void draw_splitbar(HWND hWnd
, int x
)
55 HDC hdc
= GetDC(hWnd
);
57 GetClientRect(hWnd
, &rt
);
58 rt
.left
= x
- SPLIT_WIDTH
/2;
59 rt
.right
= x
+ SPLIT_WIDTH
/2+1;
64 static void ResizeWnd(int cx
, int cy
)
66 HDWP hdwp
= BeginDeferWindowPos(2);
67 RECT rt
= {0, 0, cx
, cy
};
69 cx
= g_pChildWnd
->nSplitPos
+ SPLIT_WIDTH
/2;
70 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
);
71 DeferWindowPos(hdwp
, g_pChildWnd
->hListWnd
, 0, rt
.left
+cx
, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
72 EndDeferWindowPos(hdwp
);
75 static void OnPaint(HWND hWnd
)
81 GetClientRect(hWnd
, &rt
);
82 hdc
= BeginPaint(hWnd
, &ps
);
83 FillRect(ps
.hdc
, &rt
, GetSysColorBrush(COLOR_BTNFACE
));
87 static LPTSTR
CombinePaths(LPCTSTR pPaths
[], int nPaths
) {
90 for (i
=0, len
=0; i
<nPaths
; i
++) {
91 if (pPaths
[i
] && *pPaths
[i
]) {
92 len
+= lstrlen(pPaths
[i
])+1;
95 combined
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(TCHAR
));
97 for (i
=0, pos
=0; i
<nPaths
; i
++) {
98 if (pPaths
[i
] && *pPaths
[i
]) {
99 int llen
= _tcslen(pPaths
[i
]);
101 _tcscpy(combined
, pPaths
[i
]);
103 combined
[pos
++] = (TCHAR
)'\\';
104 _tcscpy(combined
+pos
, pPaths
[i
]);
112 static LPTSTR
GetPathRoot(HWND hwndTV
, HTREEITEM hItem
, BOOL bFull
) {
113 LPCTSTR parts
[2] = {_T(""), _T("")};
115 HKEY hRootKey
= NULL
;
117 hItem
= TreeView_GetSelection(hwndTV
);
118 GetItemPath(hwndTV
, hItem
, &hRootKey
);
119 if (!bFull
&& !hRootKey
)
122 parts
[1] = GetRootKeyName(hRootKey
);
124 DWORD dwSize
= sizeof(text
)/sizeof(TCHAR
);
125 GetComputerName(text
, &dwSize
);
128 return CombinePaths(parts
, 2);
131 LPTSTR
GetItemFullPath(HWND hwndTV
, HTREEITEM hItem
, BOOL bFull
) {
134 HKEY hRootKey
= NULL
;
136 parts
[0] = GetPathRoot(hwndTV
, hItem
, bFull
);
137 parts
[1] = GetItemPath(hwndTV
, hItem
, &hRootKey
);
138 ret
= CombinePaths((LPCTSTR
*)parts
, 2);
139 HeapFree(GetProcessHeap(), 0, parts
[0]);
143 static LPTSTR
GetPathFullPath(HWND hwndTV
, LPTSTR path
) {
147 parts
[0] = GetPathRoot(hwndTV
, 0, TRUE
);
149 ret
= CombinePaths((LPCTSTR
*)parts
, 2);
150 HeapFree(GetProcessHeap(), 0, parts
[0]);
154 static void OnTreeSelectionChanged(HWND hwndTV
, HWND hwndLV
, HTREEITEM hItem
, BOOL bRefreshLV
)
158 HKEY hRootKey
= NULL
;
159 keyPath
= GetItemPath(hwndTV
, hItem
, &hRootKey
);
160 RefreshListView(hwndLV
, hRootKey
, keyPath
, NULL
);
165 /*******************************************************************************
166 * finish_splitbar [internal]
168 * make the splitbar invisible and resize the windows
169 * (helper for ChildWndProc)
171 static void finish_splitbar(HWND hWnd
, int x
)
175 draw_splitbar(hWnd
, last_split
);
177 GetClientRect(hWnd
, &rt
);
178 g_pChildWnd
->nSplitPos
= x
;
179 ResizeWnd(rt
.right
, rt
.bottom
);
183 /*******************************************************************************
185 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
187 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
191 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
193 switch (LOWORD(wParam
)) {
194 /* Parse the menu selections: */
195 case ID_REGISTRY_EXIT
:
198 case ID_VIEW_REFRESH
:
199 WINE_TRACE("Is this ever called or is it just dead code?\n");
202 case ID_SWITCH_PANELS
:
203 g_pChildWnd
->nFocusPanel
= !g_pChildWnd
->nFocusPanel
;
204 SetFocus(g_pChildWnd
->nFocusPanel
? g_pChildWnd
->hListWnd
: g_pChildWnd
->hTreeWnd
);
212 /*******************************************************************************
214 * FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
216 * PURPOSE: Processes messages for the child windows.
218 * WM_COMMAND - process the application menu
219 * WM_PAINT - Paint the main window
220 * WM_DESTROY - post a quit message and return
223 LRESULT CALLBACK
ChildWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
227 g_pChildWnd
= HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd
));
228 if (!g_pChildWnd
) return 0;
229 LoadString(hInst
, IDS_REGISTRY_ROOT_NAME
, g_pChildWnd
->szPath
, MAX_PATH
);
230 g_pChildWnd
->nSplitPos
= 250;
231 g_pChildWnd
->hWnd
= hWnd
;
232 g_pChildWnd
->hTreeWnd
= CreateTreeView(hWnd
, g_pChildWnd
->szPath
, TREE_WINDOW
);
233 g_pChildWnd
->hListWnd
= CreateListView(hWnd
, LIST_WINDOW
/*, g_pChildWnd->szPath*/);
234 g_pChildWnd
->nFocusPanel
= 1;
235 SetFocus(g_pChildWnd
->hTreeWnd
);
238 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
)) {
246 if (LOWORD(lParam
) == HTCLIENT
) {
249 ScreenToClient(hWnd
, &pt
);
250 if (pt
.x
>=g_pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && pt
.x
<g_pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1) {
251 SetCursor(LoadCursor(0, IDC_SIZEWE
));
257 HeapFree(GetProcessHeap(), 0, g_pChildWnd
);
261 case WM_LBUTTONDOWN
: {
263 int x
= (short)LOWORD(lParam
);
264 GetClientRect(hWnd
, &rt
);
265 if (x
>=g_pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && x
<g_pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1) {
266 last_split
= g_pChildWnd
->nSplitPos
;
267 draw_splitbar(hWnd
, last_split
);
273 /* WM_RBUTTONDOWN sets the splitbar the same way as WM_LBUTTONUP */
276 if (GetCapture() == hWnd
) {
277 finish_splitbar(hWnd
, LOWORD(lParam
));
281 case WM_CAPTURECHANGED
:
282 if (GetCapture()==hWnd
&& last_split
>=0)
283 draw_splitbar(hWnd
, last_split
);
287 if (wParam
== VK_ESCAPE
)
288 if (GetCapture() == hWnd
) {
290 draw_splitbar(hWnd
, last_split
);
291 GetClientRect(hWnd
, &rt
);
292 ResizeWnd(rt
.right
, rt
.bottom
);
295 SetCursor(LoadCursor(0, IDC_ARROW
));
300 if (GetCapture() == hWnd
) {
302 int x
= LOWORD(lParam
);
303 HDC hdc
= GetDC(hWnd
);
304 GetClientRect(hWnd
, &rt
);
305 rt
.left
= last_split
-SPLIT_WIDTH
/2;
306 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
307 InvertRect(hdc
, &rt
);
309 rt
.left
= x
-SPLIT_WIDTH
/2;
310 rt
.right
= x
+SPLIT_WIDTH
/2+1;
311 InvertRect(hdc
, &rt
);
312 ReleaseDC(hWnd
, hdc
);
317 if (g_pChildWnd
!= NULL
) {
318 SetFocus(g_pChildWnd
->nFocusPanel
? g_pChildWnd
->hListWnd
: g_pChildWnd
->hTreeWnd
);
326 if (((int)wParam
== TREE_WINDOW
) && (g_pChildWnd
!= NULL
)) {
327 switch (((LPNMHDR
)lParam
)->code
) {
328 case TVN_ITEMEXPANDING
:
329 return !OnTreeExpanding(g_pChildWnd
->hTreeWnd
, (NMTREEVIEW
*)lParam
);
331 OnTreeSelectionChanged(g_pChildWnd
->hTreeWnd
, g_pChildWnd
->hListWnd
,
332 ((NMTREEVIEW
*)lParam
)->itemNew
.hItem
, TRUE
);
335 g_pChildWnd
->nFocusPanel
= 0;
340 TrackPopupMenu(GetSubMenu(hPopupMenus
, PM_NEW
),
341 TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, hFrameWnd
, NULL
);
344 case TVN_ENDLABELEDIT
: {
346 LPNMTVDISPINFO dispInfo
= (LPNMTVDISPINFO
)lParam
;
347 LPCTSTR path
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hRootKey
);
348 BOOL res
= RenameKey(hWnd
, hRootKey
, path
, dispInfo
->item
.pszText
);
351 LPTSTR fullPath
= GetPathFullPath(g_pChildWnd
->hTreeWnd
,
352 dispInfo
->item
.pszText
);
353 item
.mask
= TVIF_HANDLE
| TVIF_TEXT
;
354 item
.hItem
= TreeView_GetSelection(g_pChildWnd
->hTreeWnd
);
355 item
.pszText
= dispInfo
->item
.pszText
;
356 SendMessage( g_pChildWnd
->hTreeWnd
, TVM_SETITEMW
, 0, (LPARAM
)&item
);
357 SendMessage(hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)fullPath
);
358 HeapFree(GetProcessHeap(), 0, fullPath
);
363 return 0; /* goto def; */
366 if (((int)wParam
== LIST_WINDOW
) && (g_pChildWnd
!= NULL
)) {
367 if (((LPNMHDR
)lParam
)->code
== NM_SETFOCUS
) {
368 g_pChildWnd
->nFocusPanel
= 1;
369 } else if (!SendMessage(g_pChildWnd
->hListWnd
, WM_NOTIFY_REFLECT
, wParam
, lParam
)) {
376 if (wParam
!= SIZE_MINIMIZED
&& g_pChildWnd
!= NULL
) {
377 ResizeWnd(LOWORD(lParam
), HIWORD(lParam
));
381 return DefWindowProc(hWnd
, message
, wParam
, lParam
);