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 switch (LOWORD(wParam
)) {
105 /* Parse the menu selections: */
106 case ID_REGISTRY_EXIT
:
109 case ID_VIEW_REFRESH
:
118 /*******************************************************************************
120 * FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
122 * PURPOSE: Processes messages for the child windows.
124 * WM_COMMAND - process the application menu
125 * WM_PAINT - Paint the main window
126 * WM_DESTROY - post a quit message and return
129 LRESULT CALLBACK
ChildWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
131 static short last_split
;
133 ChildWnd
* pChildWnd
= g_pChildWnd
;
138 TCHAR buffer
[MAX_PATH
];
139 /* load "My Computer" string */
140 LoadString(hInst
, IDS_MY_COMPUTER
, buffer
, sizeof(buffer
)/sizeof(TCHAR
));
142 g_pChildWnd
= pChildWnd
= HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd
));
143 if (!pChildWnd
) return 0;
144 _tcsncpy(pChildWnd
->szPath
, buffer
, MAX_PATH
);
145 pChildWnd
->nSplitPos
= 250;
146 pChildWnd
->hWnd
= hWnd
;
147 pChildWnd
->hTreeWnd
= CreateTreeView(hWnd
, pChildWnd
->szPath
, TREE_WINDOW
);
148 pChildWnd
->hListWnd
= CreateListView(hWnd
, LIST_WINDOW
/*, pChildWnd->szPath*/);
149 SetFocus(pChildWnd
->hTreeWnd
);
153 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
)) {
161 if (LOWORD(lParam
) == HTCLIENT
) {
164 ScreenToClient(hWnd
, &pt
);
165 if (pt
.x
>=pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && pt
.x
<pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1) {
166 SetCursor(LoadCursor(0, IDC_SIZEWE
));
172 HeapFree(GetProcessHeap(), 0, pChildWnd
);
176 case WM_LBUTTONDOWN
: {
179 pt
= MAKEPOINTS(lParam
);
180 GetClientRect(hWnd
, &rt
);
181 if (pt
.x
>=pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && pt
.x
<pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1) {
182 last_split
= pChildWnd
->nSplitPos
;
183 draw_splitbar(hWnd
, last_split
);
190 if (GetCapture() == hWnd
) {
193 pt
= MAKEPOINTS(lParam
);
194 GetClientRect(hWnd
, &rt
);
195 pt
.x
= min(max(pt
.x
, SPLIT_MIN
), rt
.right
- SPLIT_MIN
);
196 draw_splitbar(hWnd
, last_split
);
198 pChildWnd
->nSplitPos
= pt
.x
;
199 ResizeWnd(pChildWnd
, rt
.right
, rt
.bottom
);
204 case WM_CAPTURECHANGED
:
205 if (GetCapture()==hWnd
&& last_split
>=0)
206 draw_splitbar(hWnd
, last_split
);
210 if (wParam
== VK_ESCAPE
)
211 if (GetCapture() == hWnd
) {
213 draw_splitbar(hWnd
, last_split
);
214 GetClientRect(hWnd
, &rt
);
215 ResizeWnd(pChildWnd
, rt
.right
, rt
.bottom
);
218 SetCursor(LoadCursor(0, IDC_ARROW
));
223 if (GetCapture() == hWnd
) {
230 const DWORD Pattern
[4] = {0x5555AAAA, 0x5555AAAA, 0x5555AAAA, 0x5555AAAA};
231 SizingPattern
= CreateBitmap(8, 8, 1, 1, Pattern
);
235 SizingBrush
= CreatePatternBrush(SizingPattern
);
238 pt
= MAKEPOINTS(lParam
);
239 GetClientRect(hWnd
, &rt
);
240 pt
.x
= min(max(pt
.x
, SPLIT_MIN
), rt
.right
- SPLIT_MIN
);
241 if(last_split
!= pt
.x
)
243 rt
.left
= last_split
-SPLIT_WIDTH
/2;
244 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
246 OldObj
= SelectObject(hdc
, SizingBrush
);
247 PatBlt(hdc
, rt
.left
, rt
.top
, rt
.right
- rt
.left
, rt
.bottom
- rt
.top
, PATINVERT
);
249 rt
.left
= pt
.x
-SPLIT_WIDTH
/2;
250 rt
.right
= pt
.x
+SPLIT_WIDTH
/2+1;
251 PatBlt(hdc
, rt
.left
, rt
.top
, rt
.right
- rt
.left
, rt
.bottom
- rt
.top
, PATINVERT
);
252 SelectObject(hdc
, OldObj
);
253 ReleaseDC(hWnd
, hdc
);
259 if (pChildWnd
!= NULL
) {
260 SetFocus(pChildWnd
->nFocusPanel
? pChildWnd
->hListWnd
: pChildWnd
->hTreeWnd
);
268 if ((int)wParam
== TREE_WINDOW
) {
269 switch (((LPNMHDR
)lParam
)->code
) {
270 case TVN_ITEMEXPANDING
:
271 return !OnTreeExpanding(pChildWnd
->hTreeWnd
, (NMTREEVIEW
*)lParam
);
272 case TVN_SELCHANGED
: {
273 LPCTSTR keyPath
, rootName
;
277 keyPath
= GetItemPath(pChildWnd
->hTreeWnd
, ((NMTREEVIEW
*)lParam
)->itemNew
.hItem
, &hRootKey
);
280 RefreshListView(pChildWnd
->hListWnd
, 0, NULL
);
283 RefreshListView(pChildWnd
->hListWnd
, hRootKey
, keyPath
);
284 rootName
= get_root_key_name(hRootKey
);
285 fullPath
= HeapAlloc(GetProcessHeap(), 0, (_tcslen(rootName
) + 1 + _tcslen(keyPath
) + 1) * sizeof(TCHAR
));
287 _stprintf(fullPath
, _T("%s\\%s"), rootName
, keyPath
);
288 SendMessage(hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)fullPath
);
289 HeapFree(GetProcessHeap(), 0, fullPath
);
295 pChildWnd
->nFocusPanel
= 1;
302 if ((int)wParam
== LIST_WINDOW
)
304 switch (((LPNMHDR
)lParam
)->code
) {
306 pChildWnd
->nFocusPanel
= 0;
309 if(ListWndNotifyProc(pChildWnd
->hListWnd
, wParam
, lParam
, &Result
))
322 if((HWND
)wParam
== pChildWnd
->hListWnd
)
326 pt
= MAKEPOINTS(lParam
);
327 cnt
= ListView_GetSelectedCount(pChildWnd
->hListWnd
);
328 i
= ListView_GetNextItem(pChildWnd
->hListWnd
, -1, LVNI_FOCUSED
| LVNI_SELECTED
);
331 TrackPopupMenu(GetSubMenu(hPopupMenus
, PM_NEW
), TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, hFrameWnd
, NULL
);
335 HMENU mnu
= GetSubMenu(hPopupMenus
, PM_MODIFYVALUE
);
336 SetMenuDefaultItem(mnu
, ID_EDIT_MODIFY
, MF_BYCOMMAND
);
337 IsDefault
= IsDefaultValue(pChildWnd
->hListWnd
, i
);
339 EnableMenuItem(mnu
, ID_EDIT_RENAME
, MF_BYCOMMAND
| (IsDefault
? MF_DISABLED
| MF_GRAYED
: MF_ENABLED
));
341 EnableMenuItem(mnu
, ID_EDIT_RENAME
, MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
342 EnableMenuItem(mnu
, ID_EDIT_MODIFY
, MF_BYCOMMAND
| (cnt
== 1 ? MF_ENABLED
: MF_DISABLED
| MF_GRAYED
));
343 EnableMenuItem(mnu
, ID_EDIT_MODIFY_BIN
, MF_BYCOMMAND
| (cnt
== 1 ? MF_ENABLED
: MF_DISABLED
| MF_GRAYED
));
345 TrackPopupMenu(mnu
, TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, hFrameWnd
, NULL
);
352 if (wParam
!= SIZE_MINIMIZED
&& pChildWnd
!= NULL
) {
353 ResizeWnd(pChildWnd
, LOWORD(lParam
), HIWORD(lParam
));
357 return DefWindowProc(hWnd
, message
, wParam
, lParam
);