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 */
28 #include "wine/debug.h"
29 #include "wine/unicode.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(regedit
);
33 ChildWnd
* g_pChildWnd
;
34 static int last_split
;
36 /*******************************************************************************
37 * Local module support methods
40 LPCWSTR
GetRootKeyName(HKEY hRootKey
)
42 if(hRootKey
== HKEY_CLASSES_ROOT
)
43 return reg_class_namesW
[INDEX_HKEY_CLASSES_ROOT
];
44 if(hRootKey
== HKEY_CURRENT_USER
)
45 return reg_class_namesW
[INDEX_HKEY_CURRENT_USER
];
46 if(hRootKey
== HKEY_LOCAL_MACHINE
)
47 return reg_class_namesW
[INDEX_HKEY_LOCAL_MACHINE
];
48 if(hRootKey
== HKEY_USERS
)
49 return reg_class_namesW
[INDEX_HKEY_USERS
];
50 if(hRootKey
== HKEY_CURRENT_CONFIG
)
51 return reg_class_namesW
[INDEX_HKEY_CURRENT_CONFIG
];
52 if(hRootKey
== HKEY_DYN_DATA
)
53 return reg_class_namesW
[INDEX_HKEY_DYN_DATA
];
56 static const WCHAR unknown_key
[] = {'U','N','K','N','O','W','N',' ','H','K','E','Y',',',' ',
57 'P','L','E','A','S','E',' ','R','E','P','O','R','T',0};
62 static void draw_splitbar(HWND hWnd
, int x
)
65 HDC hdc
= GetDC(hWnd
);
67 GetClientRect(hWnd
, &rt
);
68 rt
.left
= x
- SPLIT_WIDTH
/2;
69 rt
.right
= x
+ SPLIT_WIDTH
/2+1;
74 static void ResizeWnd(int cx
, int cy
)
76 HDWP hdwp
= BeginDeferWindowPos(2);
77 RECT rt
= {0, 0, cx
, cy
};
79 cx
= g_pChildWnd
->nSplitPos
+ SPLIT_WIDTH
/2;
80 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
);
81 DeferWindowPos(hdwp
, g_pChildWnd
->hListWnd
, 0, rt
.left
+cx
, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
82 EndDeferWindowPos(hdwp
);
85 static void OnPaint(HWND hWnd
)
91 GetClientRect(hWnd
, &rt
);
92 hdc
= BeginPaint(hWnd
, &ps
);
93 FillRect(ps
.hdc
, &rt
, GetSysColorBrush(COLOR_BTNFACE
));
97 static LPWSTR
CombinePaths(LPCWSTR pPaths
[], int nPaths
) {
100 for (i
=0, len
=0; i
<nPaths
; i
++) {
101 if (pPaths
[i
] && *pPaths
[i
]) {
102 len
+= lstrlenW(pPaths
[i
])+1;
105 combined
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
107 for (i
=0, pos
=0; i
<nPaths
; i
++) {
108 if (pPaths
[i
] && *pPaths
[i
]) {
109 int llen
= lstrlenW(pPaths
[i
]);
111 lstrcpyW(combined
, pPaths
[i
]);
113 combined
[pos
++] = '\\';
114 lstrcpyW(combined
+pos
, pPaths
[i
]);
122 static LPWSTR
GetPathRoot(HWND hwndTV
, HTREEITEM hItem
, BOOL bFull
) {
123 LPCWSTR parts
[2] = {0,0};
125 HKEY hRootKey
= NULL
;
127 hItem
= TreeView_GetSelection(hwndTV
);
128 HeapFree(GetProcessHeap(), 0, GetItemPath(hwndTV
, hItem
, &hRootKey
));
129 if (!bFull
&& !hRootKey
)
132 parts
[1] = GetRootKeyName(hRootKey
);
134 DWORD dwSize
= sizeof(text
)/sizeof(WCHAR
);
135 GetComputerNameW(text
, &dwSize
);
138 return CombinePaths(parts
, 2);
141 LPWSTR
GetItemFullPath(HWND hwndTV
, HTREEITEM hItem
, BOOL bFull
) {
144 HKEY hRootKey
= NULL
;
146 parts
[0] = GetPathRoot(hwndTV
, hItem
, bFull
);
147 parts
[1] = GetItemPath(hwndTV
, hItem
, &hRootKey
);
148 ret
= CombinePaths((LPCWSTR
*)parts
, 2);
149 HeapFree(GetProcessHeap(), 0, parts
[0]);
150 HeapFree(GetProcessHeap(), 0, parts
[1]);
154 static LPWSTR
GetPathFullPath(HWND hwndTV
, LPWSTR path
) {
158 parts
[0] = GetPathRoot(hwndTV
, 0, TRUE
);
160 ret
= CombinePaths((LPCWSTR
*)parts
, 2);
161 HeapFree(GetProcessHeap(), 0, parts
[0]);
165 static void OnTreeSelectionChanged(HWND hwndTV
, HWND hwndLV
, HTREEITEM hItem
, BOOL bRefreshLV
)
169 HKEY hRootKey
= NULL
;
170 keyPath
= GetItemPath(hwndTV
, hItem
, &hRootKey
);
171 RefreshListView(hwndLV
, hRootKey
, keyPath
, NULL
);
172 HeapFree(GetProcessHeap(), 0, keyPath
);
177 /*******************************************************************************
178 * finish_splitbar [internal]
180 * make the splitbar invisible and resize the windows
181 * (helper for ChildWndProc)
183 static void finish_splitbar(HWND hWnd
, int x
)
187 draw_splitbar(hWnd
, last_split
);
189 GetClientRect(hWnd
, &rt
);
190 g_pChildWnd
->nSplitPos
= x
;
191 ResizeWnd(rt
.right
, rt
.bottom
);
195 /*******************************************************************************
197 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
199 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
203 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
205 switch (LOWORD(wParam
)) {
206 /* Parse the menu selections: */
207 case ID_REGISTRY_EXIT
:
210 case ID_VIEW_REFRESH
:
211 WINE_TRACE("Is this ever called or is it just dead code?\n");
214 case ID_SWITCH_PANELS
:
215 g_pChildWnd
->nFocusPanel
= !g_pChildWnd
->nFocusPanel
;
216 SetFocus(g_pChildWnd
->nFocusPanel
? g_pChildWnd
->hListWnd
: g_pChildWnd
->hTreeWnd
);
224 /*******************************************************************************
226 * FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
228 * PURPOSE: Processes messages for the child windows.
230 * WM_COMMAND - process the application menu
231 * WM_PAINT - Paint the main window
232 * WM_DESTROY - post a quit message and return
235 LRESULT CALLBACK
ChildWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
239 g_pChildWnd
= HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd
));
240 if (!g_pChildWnd
) return 0;
241 LoadStringW(hInst
, IDS_REGISTRY_ROOT_NAME
, g_pChildWnd
->szPath
, MAX_PATH
);
242 g_pChildWnd
->nSplitPos
= 250;
243 g_pChildWnd
->hWnd
= hWnd
;
244 g_pChildWnd
->hTreeWnd
= CreateTreeView(hWnd
, g_pChildWnd
->szPath
, TREE_WINDOW
);
245 g_pChildWnd
->hListWnd
= CreateListView(hWnd
, LIST_WINDOW
/*, g_pChildWnd->szPath*/);
246 g_pChildWnd
->nFocusPanel
= 1;
247 SetFocus(g_pChildWnd
->hTreeWnd
);
250 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
)) {
258 if (LOWORD(lParam
) == HTCLIENT
) {
261 ScreenToClient(hWnd
, &pt
);
262 if (pt
.x
>=g_pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && pt
.x
<g_pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1) {
263 SetCursor(LoadCursor(0, IDC_SIZEWE
));
269 HeapFree(GetProcessHeap(), 0, g_pChildWnd
);
273 case WM_LBUTTONDOWN
: {
275 int x
= (short)LOWORD(lParam
);
276 GetClientRect(hWnd
, &rt
);
277 if (x
>=g_pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && x
<g_pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1) {
278 last_split
= g_pChildWnd
->nSplitPos
;
279 draw_splitbar(hWnd
, last_split
);
285 /* WM_RBUTTONDOWN sets the splitbar the same way as WM_LBUTTONUP */
288 if (GetCapture() == hWnd
) {
289 finish_splitbar(hWnd
, LOWORD(lParam
));
293 case WM_CAPTURECHANGED
:
294 if (GetCapture()==hWnd
&& last_split
>=0)
295 draw_splitbar(hWnd
, last_split
);
299 if (wParam
== VK_ESCAPE
)
300 if (GetCapture() == hWnd
) {
302 draw_splitbar(hWnd
, last_split
);
303 GetClientRect(hWnd
, &rt
);
304 ResizeWnd(rt
.right
, rt
.bottom
);
307 SetCursor(LoadCursor(0, IDC_ARROW
));
312 if (GetCapture() == hWnd
) {
314 int x
= LOWORD(lParam
);
315 HDC hdc
= GetDC(hWnd
);
316 GetClientRect(hWnd
, &rt
);
317 rt
.left
= last_split
-SPLIT_WIDTH
/2;
318 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
319 InvertRect(hdc
, &rt
);
321 rt
.left
= x
-SPLIT_WIDTH
/2;
322 rt
.right
= x
+SPLIT_WIDTH
/2+1;
323 InvertRect(hdc
, &rt
);
324 ReleaseDC(hWnd
, hdc
);
329 if (g_pChildWnd
!= NULL
) {
330 SetFocus(g_pChildWnd
->nFocusPanel
? g_pChildWnd
->hListWnd
: g_pChildWnd
->hTreeWnd
);
338 if (((int)wParam
== TREE_WINDOW
) && (g_pChildWnd
!= NULL
)) {
339 switch (((LPNMHDR
)lParam
)->code
) {
340 case TVN_ITEMEXPANDINGW
:
341 return !OnTreeExpanding(g_pChildWnd
->hTreeWnd
, (NMTREEVIEW
*)lParam
);
342 case TVN_SELCHANGEDW
:
343 OnTreeSelectionChanged(g_pChildWnd
->hTreeWnd
, g_pChildWnd
->hListWnd
,
344 ((NMTREEVIEWW
*)lParam
)->itemNew
.hItem
, TRUE
);
347 g_pChildWnd
->nFocusPanel
= 0;
352 TrackPopupMenu(GetSubMenu(hPopupMenus
, PM_NEW
),
353 TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, hFrameWnd
, NULL
);
356 case TVN_ENDLABELEDITW
: {
358 LPNMTVDISPINFOW dispInfo
= (LPNMTVDISPINFOW
)lParam
;
359 LPWSTR path
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hRootKey
);
360 BOOL res
= RenameKey(hWnd
, hRootKey
, path
, dispInfo
->item
.pszText
);
363 LPWSTR fullPath
= GetPathFullPath(g_pChildWnd
->hTreeWnd
,
364 dispInfo
->item
.pszText
);
365 item
.mask
= TVIF_HANDLE
| TVIF_TEXT
;
366 item
.hItem
= TreeView_GetSelection(g_pChildWnd
->hTreeWnd
);
367 item
.pszText
= dispInfo
->item
.pszText
;
368 SendMessageW( g_pChildWnd
->hTreeWnd
, TVM_SETITEMW
, 0, (LPARAM
)&item
);
369 SendMessageW(hStatusBar
, SB_SETTEXTW
, 0, (LPARAM
)fullPath
);
370 HeapFree(GetProcessHeap(), 0, fullPath
);
372 HeapFree(GetProcessHeap(), 0, path
);
376 return 0; /* goto def; */
379 if (((int)wParam
== LIST_WINDOW
) && (g_pChildWnd
!= NULL
)) {
380 if (((LPNMHDR
)lParam
)->code
== NM_SETFOCUS
) {
381 g_pChildWnd
->nFocusPanel
= 1;
382 } else if (!SendMessage(g_pChildWnd
->hListWnd
, WM_NOTIFY_REFLECT
, wParam
, lParam
)) {
389 if (wParam
!= SIZE_MINIMIZED
&& g_pChildWnd
!= NULL
) {
390 ResizeWnd(LOWORD(lParam
), HIWORD(lParam
));
394 return DefWindowProc(hWnd
, message
, wParam
, lParam
);