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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
29 ChildWnd
* g_pChildWnd
;
30 HBITMAP SizingPattern
= 0;
31 HBRUSH SizingBrush
= 0;
33 /*******************************************************************************
34 * Local module support methods
37 static LPCTSTR
get_root_key_name(HKEY hRootKey
)
39 if (hRootKey
== HKEY_CLASSES_ROOT
) return _T("HKEY_CLASSES_ROOT");
40 if (hRootKey
== HKEY_CURRENT_USER
) return _T("HKEY_CURRENT_USER");
41 if (hRootKey
== HKEY_LOCAL_MACHINE
) return _T("HKEY_LOCAL_MACHINE");
42 if (hRootKey
== HKEY_USERS
) return _T("HKEY_USERS");
43 if (hRootKey
== HKEY_CURRENT_CONFIG
) return _T("HKEY_CURRENT_CONFIG");
44 return _T("UKNOWN HKEY, PLEASE REPORT");
47 static void draw_splitbar(HWND hWnd
, int x
)
51 HDC hdc
= GetDC(hWnd
);
55 const DWORD Pattern
[4] = {0x5555AAAA, 0x5555AAAA, 0x5555AAAA, 0x5555AAAA};
56 SizingPattern
= CreateBitmap(8, 8, 1, 1, Pattern
);
60 SizingBrush
= CreatePatternBrush(SizingPattern
);
62 GetClientRect(hWnd
, &rt
);
63 rt
.left
= x
- SPLIT_WIDTH
/2;
64 rt
.right
= x
+ SPLIT_WIDTH
/2+1;
65 OldObj
= SelectObject(hdc
, SizingBrush
);
66 PatBlt(hdc
, rt
.left
, rt
.top
, rt
.right
- rt
.left
, rt
.bottom
- rt
.top
, PATINVERT
);
67 SelectObject(hdc
, OldObj
);
71 static void ResizeWnd(ChildWnd
* pChildWnd
, int cx
, int cy
)
73 HDWP hdwp
= BeginDeferWindowPos(2);
74 RECT rt
= {0, 0, cx
, cy
};
76 cx
= pChildWnd
->nSplitPos
+ SPLIT_WIDTH
/2;
77 DeferWindowPos(hdwp
, pChildWnd
->hTreeWnd
, 0, rt
.left
, rt
.top
, pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2-rt
.left
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
78 DeferWindowPos(hdwp
, pChildWnd
->hListWnd
, 0, rt
.left
+cx
, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
79 EndDeferWindowPos(hdwp
);
82 static void OnPaint(HWND hWnd
)
88 GetClientRect(hWnd
, &rt
);
89 hdc
= BeginPaint(hWnd
, &ps
);
90 FillRect(ps
.hdc
, &rt
, GetSysColorBrush(COLOR_BTNFACE
));
94 /*******************************************************************************
96 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
98 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
102 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
104 ChildWnd
* pChildWnd
= g_pChildWnd
;
105 switch (LOWORD(wParam
)) {
106 /* Parse the menu selections: */
107 case ID_REGISTRY_EXIT
:
110 case ID_VIEW_REFRESH
:
113 case ID_SWITCH_PANELS
:
114 pChildWnd
->nFocusPanel
= !pChildWnd
->nFocusPanel
;
115 SetFocus(pChildWnd
->nFocusPanel
? pChildWnd
->hListWnd
: pChildWnd
->hTreeWnd
);
123 /*******************************************************************************
125 * FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
127 * PURPOSE: Processes messages for the child windows.
129 * WM_COMMAND - process the application menu
130 * WM_PAINT - Paint the main window
131 * WM_DESTROY - post a quit message and return
135 ChildWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
137 static short last_split
;
139 ChildWnd
* pChildWnd
= g_pChildWnd
;
144 TCHAR buffer
[MAX_PATH
];
145 /* load "My Computer" string */
146 LoadString(hInst
, IDS_MY_COMPUTER
, buffer
, sizeof(buffer
)/sizeof(TCHAR
));
148 g_pChildWnd
= pChildWnd
= HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd
));
149 if (!pChildWnd
) return 0;
150 _tcsncpy(pChildWnd
->szPath
, buffer
, MAX_PATH
);
151 pChildWnd
->nSplitPos
= 250;
152 pChildWnd
->hWnd
= hWnd
;
153 pChildWnd
->hTreeWnd
= CreateTreeView(hWnd
, pChildWnd
->szPath
, TREE_WINDOW
);
154 pChildWnd
->hListWnd
= CreateListView(hWnd
, LIST_WINDOW
/*, pChildWnd->szPath*/);
155 SetFocus(pChildWnd
->hTreeWnd
);
159 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
)) {
167 if (LOWORD(lParam
) == HTCLIENT
) {
170 ScreenToClient(hWnd
, &pt
);
171 if (pt
.x
>=pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && pt
.x
<pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1) {
172 SetCursor(LoadCursor(0, IDC_SIZEWE
));
178 HeapFree(GetProcessHeap(), 0, pChildWnd
);
182 case WM_LBUTTONDOWN
: {
185 pt
= MAKEPOINTS(lParam
);
186 GetClientRect(hWnd
, &rt
);
187 if (pt
.x
>=pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && pt
.x
<pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1) {
188 last_split
= pChildWnd
->nSplitPos
;
189 draw_splitbar(hWnd
, last_split
);
196 if (GetCapture() == hWnd
) {
199 pt
= MAKEPOINTS(lParam
);
200 GetClientRect(hWnd
, &rt
);
201 pt
.x
= min(max(pt
.x
, SPLIT_MIN
), rt
.right
- SPLIT_MIN
);
202 draw_splitbar(hWnd
, last_split
);
204 pChildWnd
->nSplitPos
= pt
.x
;
205 ResizeWnd(pChildWnd
, rt
.right
, rt
.bottom
);
210 case WM_CAPTURECHANGED
:
211 if (GetCapture()==hWnd
&& last_split
>=0)
212 draw_splitbar(hWnd
, last_split
);
216 if (wParam
== VK_ESCAPE
)
217 if (GetCapture() == hWnd
) {
219 draw_splitbar(hWnd
, last_split
);
220 GetClientRect(hWnd
, &rt
);
221 ResizeWnd(pChildWnd
, rt
.right
, rt
.bottom
);
224 SetCursor(LoadCursor(0, IDC_ARROW
));
229 if (GetCapture() == hWnd
) {
236 const DWORD Pattern
[4] = {0x5555AAAA, 0x5555AAAA, 0x5555AAAA, 0x5555AAAA};
237 SizingPattern
= CreateBitmap(8, 8, 1, 1, Pattern
);
241 SizingBrush
= CreatePatternBrush(SizingPattern
);
244 pt
= MAKEPOINTS(lParam
);
245 GetClientRect(hWnd
, &rt
);
246 pt
.x
= min(max(pt
.x
, SPLIT_MIN
), rt
.right
- SPLIT_MIN
);
247 if(last_split
!= pt
.x
)
249 rt
.left
= last_split
-SPLIT_WIDTH
/2;
250 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
252 OldObj
= SelectObject(hdc
, SizingBrush
);
253 PatBlt(hdc
, rt
.left
, rt
.top
, rt
.right
- rt
.left
, rt
.bottom
- rt
.top
, PATINVERT
);
255 rt
.left
= pt
.x
-SPLIT_WIDTH
/2;
256 rt
.right
= pt
.x
+SPLIT_WIDTH
/2+1;
257 PatBlt(hdc
, rt
.left
, rt
.top
, rt
.right
- rt
.left
, rt
.bottom
- rt
.top
, PATINVERT
);
258 SelectObject(hdc
, OldObj
);
259 ReleaseDC(hWnd
, hdc
);
265 if (pChildWnd
!= NULL
) {
266 SetFocus(pChildWnd
->nFocusPanel
? pChildWnd
->hListWnd
: pChildWnd
->hTreeWnd
);
274 if ((int)wParam
== TREE_WINDOW
) {
275 switch (((LPNMHDR
)lParam
)->code
) {
276 case TVN_ITEMEXPANDING
:
277 return !OnTreeExpanding(pChildWnd
->hTreeWnd
, (NMTREEVIEW
*)lParam
);
278 case TVN_SELCHANGED
: {
279 LPCTSTR keyPath
, rootName
;
283 keyPath
= GetItemPath(pChildWnd
->hTreeWnd
, ((NMTREEVIEW
*)lParam
)->itemNew
.hItem
, &hRootKey
);
285 RefreshListView(pChildWnd
->hListWnd
, hRootKey
, keyPath
);
286 rootName
= get_root_key_name(hRootKey
);
287 fullPath
= HeapAlloc(GetProcessHeap(), 0, (_tcslen(rootName
) + 1 + _tcslen(keyPath
) + 1) * sizeof(TCHAR
));
289 _stprintf(fullPath
, _T("%s\\%s"), rootName
, keyPath
);
290 SendMessage(hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)fullPath
);
291 HeapFree(GetProcessHeap(), 0, fullPath
);
297 pChildWnd
->nFocusPanel
= 0;
304 if ((int)wParam
== LIST_WINDOW
)
306 switch (((LPNMHDR
)lParam
)->code
) {
308 pChildWnd
->nFocusPanel
= 1;
311 if(!ListWndNotifyProc(pChildWnd
->hListWnd
, wParam
, lParam
, &Result
))
324 if((HWND
)wParam
== pChildWnd
->hListWnd
)
328 pt
= MAKEPOINTS(lParam
);
329 cnt
= ListView_GetSelectedCount(pChildWnd
->hListWnd
);
330 i
= ListView_GetNextItem(pChildWnd
->hListWnd
, -1, LVNI_FOCUSED
| LVNI_SELECTED
);
333 TrackPopupMenu(GetSubMenu(hPopupMenus
, PM_NEW
), TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, hFrameWnd
, NULL
);
337 HMENU mnu
= GetSubMenu(hPopupMenus
, PM_MODIFYVALUE
);
338 SetMenuDefaultItem(mnu
, ID_EDIT_MODIFY
, MF_BYCOMMAND
);
339 IsDefault
= IsDefaultValue(pChildWnd
->hListWnd
, i
);
341 EnableMenuItem(mnu
, ID_EDIT_RENAME
, MF_BYCOMMAND
| (IsDefault
? MF_DISABLED
| MF_GRAYED
: MF_ENABLED
));
343 EnableMenuItem(mnu
, ID_EDIT_RENAME
, MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
344 EnableMenuItem(mnu
, ID_EDIT_MODIFY
, MF_BYCOMMAND
| (cnt
== 1 ? MF_ENABLED
: MF_DISABLED
| MF_GRAYED
));
345 EnableMenuItem(mnu
, ID_EDIT_MODIFY_BIN
, MF_BYCOMMAND
| (cnt
== 1 ? MF_ENABLED
: MF_DISABLED
| MF_GRAYED
));
347 TrackPopupMenu(mnu
, TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, hFrameWnd
, NULL
);
354 if (wParam
!= SIZE_MINIMIZED
&& pChildWnd
!= NULL
) {
355 ResizeWnd(pChildWnd
, LOWORD(lParam
), HIWORD(lParam
));
359 return DefWindowProc(hWnd
, message
, wParam
, lParam
);