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 */
30 #include "wine/debug.h"
31 #include "wine/unicode.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(regedit
);
35 ChildWnd
* g_pChildWnd
;
36 static int last_split
;
38 /*******************************************************************************
39 * Local module support methods
42 LPCTSTR
GetRootKeyName(HKEY hRootKey
)
44 if (hRootKey
== HKEY_CLASSES_ROOT
) return _T("HKEY_CLASSES_ROOT");
45 if (hRootKey
== HKEY_CURRENT_USER
) return _T("HKEY_CURRENT_USER");
46 if (hRootKey
== HKEY_LOCAL_MACHINE
) return _T("HKEY_LOCAL_MACHINE");
47 if (hRootKey
== HKEY_USERS
) return _T("HKEY_USERS");
48 if (hRootKey
== HKEY_CURRENT_CONFIG
) return _T("HKEY_CURRENT_CONFIG");
49 if (hRootKey
== HKEY_DYN_DATA
) return _T("HKEY_DYN_DATA");
50 return _T("UNKNOWN HKEY, PLEASE REPORT");
53 LPCWSTR
GetRootKeyNameW(HKEY hRootKey
)
55 if(hRootKey
== HKEY_CLASSES_ROOT
)
56 return reg_class_namesW
[INDEX_HKEY_CLASSES_ROOT
];
57 if(hRootKey
== HKEY_CURRENT_USER
)
58 return reg_class_namesW
[INDEX_HKEY_CURRENT_USER
];
59 if(hRootKey
== HKEY_LOCAL_MACHINE
)
60 return reg_class_namesW
[INDEX_HKEY_LOCAL_MACHINE
];
61 if(hRootKey
== HKEY_USERS
)
62 return reg_class_namesW
[INDEX_HKEY_USERS
];
63 if(hRootKey
== HKEY_CURRENT_CONFIG
)
64 return reg_class_namesW
[INDEX_HKEY_CURRENT_CONFIG
];
65 if(hRootKey
== HKEY_DYN_DATA
)
66 return reg_class_namesW
[INDEX_HKEY_DYN_DATA
];
69 static const WCHAR unknown_key
[] = {'U','N','K','N','O','W','N',' ','H','K','E','Y',',',' ',
70 'P','L','E','A','S','E',' ','R','E','P','O','R','T',0};
75 static void draw_splitbar(HWND hWnd
, int x
)
78 HDC hdc
= GetDC(hWnd
);
80 GetClientRect(hWnd
, &rt
);
81 rt
.left
= x
- SPLIT_WIDTH
/2;
82 rt
.right
= x
+ SPLIT_WIDTH
/2+1;
87 static void ResizeWnd(int cx
, int cy
)
89 HDWP hdwp
= BeginDeferWindowPos(2);
90 RECT rt
= {0, 0, cx
, cy
};
92 cx
= g_pChildWnd
->nSplitPos
+ SPLIT_WIDTH
/2;
93 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
);
94 DeferWindowPos(hdwp
, g_pChildWnd
->hListWnd
, 0, rt
.left
+cx
, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
95 EndDeferWindowPos(hdwp
);
98 static void OnPaint(HWND hWnd
)
104 GetClientRect(hWnd
, &rt
);
105 hdc
= BeginPaint(hWnd
, &ps
);
106 FillRect(ps
.hdc
, &rt
, GetSysColorBrush(COLOR_BTNFACE
));
110 static LPWSTR
CombinePaths(LPCWSTR pPaths
[], int nPaths
) {
113 for (i
=0, len
=0; i
<nPaths
; i
++) {
114 if (pPaths
[i
] && *pPaths
[i
]) {
115 len
+= lstrlenW(pPaths
[i
])+1;
118 combined
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
120 for (i
=0, pos
=0; i
<nPaths
; i
++) {
121 if (pPaths
[i
] && *pPaths
[i
]) {
122 int llen
= lstrlenW(pPaths
[i
]);
124 lstrcpyW(combined
, pPaths
[i
]);
126 combined
[pos
++] = (TCHAR
)'\\';
127 lstrcpyW(combined
+pos
, pPaths
[i
]);
135 static LPWSTR
GetPathRoot(HWND hwndTV
, HTREEITEM hItem
, BOOL bFull
) {
136 LPCWSTR parts
[2] = {0,0};
138 HKEY hRootKey
= NULL
;
140 hItem
= TreeView_GetSelection(hwndTV
);
141 HeapFree(GetProcessHeap(), 0, GetItemPath(hwndTV
, hItem
, &hRootKey
));
142 if (!bFull
&& !hRootKey
)
145 parts
[1] = GetRootKeyNameW(hRootKey
);
147 DWORD dwSize
= sizeof(text
)/sizeof(TCHAR
);
148 GetComputerNameW(text
, &dwSize
);
151 return CombinePaths(parts
, 2);
154 LPWSTR
GetItemFullPath(HWND hwndTV
, HTREEITEM hItem
, BOOL bFull
) {
157 HKEY hRootKey
= NULL
;
159 parts
[0] = GetPathRoot(hwndTV
, hItem
, bFull
);
160 parts
[1] = GetItemPath(hwndTV
, hItem
, &hRootKey
);
161 ret
= CombinePaths((LPCWSTR
*)parts
, 2);
162 HeapFree(GetProcessHeap(), 0, parts
[0]);
163 HeapFree(GetProcessHeap(), 0, parts
[1]);
167 static LPWSTR
GetPathFullPath(HWND hwndTV
, LPWSTR path
) {
171 parts
[0] = GetPathRoot(hwndTV
, 0, TRUE
);
173 ret
= CombinePaths((LPCWSTR
*)parts
, 2);
174 HeapFree(GetProcessHeap(), 0, parts
[0]);
178 static void OnTreeSelectionChanged(HWND hwndTV
, HWND hwndLV
, HTREEITEM hItem
, BOOL bRefreshLV
)
182 HKEY hRootKey
= NULL
;
183 keyPath
= GetItemPath(hwndTV
, hItem
, &hRootKey
);
184 RefreshListView(hwndLV
, hRootKey
, keyPath
, NULL
);
185 HeapFree(GetProcessHeap(), 0, keyPath
);
190 /*******************************************************************************
191 * finish_splitbar [internal]
193 * make the splitbar invisible and resize the windows
194 * (helper for ChildWndProc)
196 static void finish_splitbar(HWND hWnd
, int x
)
200 draw_splitbar(hWnd
, last_split
);
202 GetClientRect(hWnd
, &rt
);
203 g_pChildWnd
->nSplitPos
= x
;
204 ResizeWnd(rt
.right
, rt
.bottom
);
208 /*******************************************************************************
210 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
212 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
216 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
218 switch (LOWORD(wParam
)) {
219 /* Parse the menu selections: */
220 case ID_REGISTRY_EXIT
:
223 case ID_VIEW_REFRESH
:
224 WINE_TRACE("Is this ever called or is it just dead code?\n");
227 case ID_SWITCH_PANELS
:
228 g_pChildWnd
->nFocusPanel
= !g_pChildWnd
->nFocusPanel
;
229 SetFocus(g_pChildWnd
->nFocusPanel
? g_pChildWnd
->hListWnd
: g_pChildWnd
->hTreeWnd
);
237 /*******************************************************************************
239 * FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
241 * PURPOSE: Processes messages for the child windows.
243 * WM_COMMAND - process the application menu
244 * WM_PAINT - Paint the main window
245 * WM_DESTROY - post a quit message and return
248 LRESULT CALLBACK
ChildWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
252 g_pChildWnd
= HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd
));
253 if (!g_pChildWnd
) return 0;
254 LoadStringW(hInst
, IDS_REGISTRY_ROOT_NAME
, g_pChildWnd
->szPath
, MAX_PATH
);
255 g_pChildWnd
->nSplitPos
= 250;
256 g_pChildWnd
->hWnd
= hWnd
;
257 g_pChildWnd
->hTreeWnd
= CreateTreeView(hWnd
, g_pChildWnd
->szPath
, TREE_WINDOW
);
258 g_pChildWnd
->hListWnd
= CreateListView(hWnd
, LIST_WINDOW
/*, g_pChildWnd->szPath*/);
259 g_pChildWnd
->nFocusPanel
= 1;
260 SetFocus(g_pChildWnd
->hTreeWnd
);
263 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
)) {
271 if (LOWORD(lParam
) == HTCLIENT
) {
274 ScreenToClient(hWnd
, &pt
);
275 if (pt
.x
>=g_pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && pt
.x
<g_pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1) {
276 SetCursor(LoadCursor(0, IDC_SIZEWE
));
282 HeapFree(GetProcessHeap(), 0, g_pChildWnd
);
286 case WM_LBUTTONDOWN
: {
288 int x
= (short)LOWORD(lParam
);
289 GetClientRect(hWnd
, &rt
);
290 if (x
>=g_pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && x
<g_pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1) {
291 last_split
= g_pChildWnd
->nSplitPos
;
292 draw_splitbar(hWnd
, last_split
);
298 /* WM_RBUTTONDOWN sets the splitbar the same way as WM_LBUTTONUP */
301 if (GetCapture() == hWnd
) {
302 finish_splitbar(hWnd
, LOWORD(lParam
));
306 case WM_CAPTURECHANGED
:
307 if (GetCapture()==hWnd
&& last_split
>=0)
308 draw_splitbar(hWnd
, last_split
);
312 if (wParam
== VK_ESCAPE
)
313 if (GetCapture() == hWnd
) {
315 draw_splitbar(hWnd
, last_split
);
316 GetClientRect(hWnd
, &rt
);
317 ResizeWnd(rt
.right
, rt
.bottom
);
320 SetCursor(LoadCursor(0, IDC_ARROW
));
325 if (GetCapture() == hWnd
) {
327 int x
= LOWORD(lParam
);
328 HDC hdc
= GetDC(hWnd
);
329 GetClientRect(hWnd
, &rt
);
330 rt
.left
= last_split
-SPLIT_WIDTH
/2;
331 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
332 InvertRect(hdc
, &rt
);
334 rt
.left
= x
-SPLIT_WIDTH
/2;
335 rt
.right
= x
+SPLIT_WIDTH
/2+1;
336 InvertRect(hdc
, &rt
);
337 ReleaseDC(hWnd
, hdc
);
342 if (g_pChildWnd
!= NULL
) {
343 SetFocus(g_pChildWnd
->nFocusPanel
? g_pChildWnd
->hListWnd
: g_pChildWnd
->hTreeWnd
);
351 if (((int)wParam
== TREE_WINDOW
) && (g_pChildWnd
!= NULL
)) {
352 switch (((LPNMHDR
)lParam
)->code
) {
353 case TVN_ITEMEXPANDINGW
:
354 return !OnTreeExpanding(g_pChildWnd
->hTreeWnd
, (NMTREEVIEW
*)lParam
);
355 case TVN_SELCHANGEDW
:
356 OnTreeSelectionChanged(g_pChildWnd
->hTreeWnd
, g_pChildWnd
->hListWnd
,
357 ((NMTREEVIEWW
*)lParam
)->itemNew
.hItem
, TRUE
);
360 g_pChildWnd
->nFocusPanel
= 0;
365 TrackPopupMenu(GetSubMenu(hPopupMenus
, PM_NEW
),
366 TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, hFrameWnd
, NULL
);
369 case TVN_ENDLABELEDITW
: {
371 LPNMTVDISPINFOW dispInfo
= (LPNMTVDISPINFOW
)lParam
;
372 LPWSTR path
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hRootKey
);
373 BOOL res
= RenameKey(hWnd
, hRootKey
, path
, dispInfo
->item
.pszText
);
376 LPWSTR fullPath
= GetPathFullPath(g_pChildWnd
->hTreeWnd
,
377 dispInfo
->item
.pszText
);
378 item
.mask
= TVIF_HANDLE
| TVIF_TEXT
;
379 item
.hItem
= TreeView_GetSelection(g_pChildWnd
->hTreeWnd
);
380 item
.pszText
= dispInfo
->item
.pszText
;
381 SendMessageW( g_pChildWnd
->hTreeWnd
, TVM_SETITEMW
, 0, (LPARAM
)&item
);
382 SendMessageW(hStatusBar
, SB_SETTEXTW
, 0, (LPARAM
)fullPath
);
383 HeapFree(GetProcessHeap(), 0, fullPath
);
385 HeapFree(GetProcessHeap(), 0, path
);
389 return 0; /* goto def; */
392 if (((int)wParam
== LIST_WINDOW
) && (g_pChildWnd
!= NULL
)) {
393 if (((LPNMHDR
)lParam
)->code
== NM_SETFOCUS
) {
394 g_pChildWnd
->nFocusPanel
= 1;
395 } else if (!SendMessage(g_pChildWnd
->hListWnd
, WM_NOTIFY_REFLECT
, wParam
, lParam
)) {
402 if (wParam
!= SIZE_MINIMIZED
&& g_pChildWnd
!= NULL
) {
403 ResizeWnd(LOWORD(lParam
), HIWORD(lParam
));
407 return DefWindowProc(hWnd
, message
, wParam
, lParam
);