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;
31 /*******************************************************************************
32 * Local module support methods
35 static LPCTSTR get_root_key_name(HKEY hRootKey)
37 if (hRootKey == HKEY_CLASSES_ROOT) return _T("HKEY_CLASSES_ROOT");
38 if (hRootKey == HKEY_CURRENT_USER) return _T("HKEY_CURRENT_USER");
39 if (hRootKey == HKEY_LOCAL_MACHINE) return _T("HKEY_LOCAL_MACHINE");
40 if (hRootKey == HKEY_USERS) return _T("HKEY_USERS");
41 if (hRootKey == HKEY_CURRENT_CONFIG) return _T("HKEY_CURRENT_CONFIG");
42 return _T("UKNOWN HKEY, PLEASE REPORT");
45 static void draw_splitbar(HWND hWnd, int x)
48 HDC hdc = GetDC(hWnd);
50 GetClientRect(hWnd, &rt);
51 rt.left = x - SPLIT_WIDTH/2;
52 rt.right = x + SPLIT_WIDTH/2+1;
57 static void ResizeWnd(ChildWnd* pChildWnd, int cx, int cy)
59 HDWP hdwp = BeginDeferWindowPos(2);
60 RECT rt = {0, 0, cx, cy};
62 cx = pChildWnd->nSplitPos + SPLIT_WIDTH/2;
63 DeferWindowPos(hdwp, pChildWnd->hTreeWnd, 0, rt.left, rt.top, pChildWnd->nSplitPos-SPLIT_WIDTH/2-rt.left, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
64 DeferWindowPos(hdwp, pChildWnd->hListWnd, 0, rt.left+cx , rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
65 EndDeferWindowPos(hdwp);
68 static void OnPaint(HWND hWnd)
74 GetClientRect(hWnd, &rt);
75 hdc = BeginPaint(hWnd, &ps);
76 FillRect(ps.hdc, &rt, GetSysColorBrush(COLOR_BTNFACE));
80 /*******************************************************************************
82 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
84 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
88 static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
90 switch (LOWORD(wParam)) {
91 /* Parse the menu selections: */
92 case ID_REGISTRY_EXIT:
104 /*******************************************************************************
106 * FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
108 * PURPOSE: Processes messages for the child windows.
110 * WM_COMMAND - process the application menu
111 * WM_PAINT - Paint the main window
112 * WM_DESTROY - post a quit message and return
115 LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
117 static int last_split;
118 ChildWnd* pChildWnd = g_pChildWnd;
122 g_pChildWnd = pChildWnd = HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd));
123 if (!pChildWnd) return 0;
124 _tcsncpy(pChildWnd->szPath, _T("My Computer"), MAX_PATH);
125 pChildWnd->nSplitPos = 250;
126 pChildWnd->hWnd = hWnd;
127 pChildWnd->hTreeWnd = CreateTreeView(hWnd, pChildWnd->szPath, TREE_WINDOW);
128 pChildWnd->hListWnd = CreateListView(hWnd, LIST_WINDOW/*, pChildWnd->szPath*/);
129 SetFocus(pChildWnd->hTreeWnd);
132 if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
140 if (LOWORD(lParam) == HTCLIENT) {
143 ScreenToClient(hWnd, &pt);
144 if (pt.x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && pt.x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
145 SetCursor(LoadCursor(0, IDC_SIZEWE));
151 HeapFree(GetProcessHeap(), 0, pChildWnd);
155 case WM_LBUTTONDOWN: {
157 int x = LOWORD(lParam);
158 GetClientRect(hWnd, &rt);
159 if (x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
160 last_split = pChildWnd->nSplitPos;
161 draw_splitbar(hWnd, last_split);
168 if (GetCapture() == hWnd) {
170 int x = LOWORD(lParam);
171 draw_splitbar(hWnd, last_split);
173 GetClientRect(hWnd, &rt);
174 pChildWnd->nSplitPos = x;
175 ResizeWnd(pChildWnd, rt.right, rt.bottom);
180 case WM_CAPTURECHANGED:
181 if (GetCapture()==hWnd && last_split>=0)
182 draw_splitbar(hWnd, last_split);
186 if (wParam == VK_ESCAPE)
187 if (GetCapture() == hWnd) {
189 draw_splitbar(hWnd, last_split);
190 GetClientRect(hWnd, &rt);
191 ResizeWnd(pChildWnd, rt.right, rt.bottom);
194 SetCursor(LoadCursor(0, IDC_ARROW));
199 if (GetCapture() == hWnd) {
201 int x = LOWORD(lParam);
202 HDC hdc = GetDC(hWnd);
203 GetClientRect(hWnd, &rt);
204 rt.left = last_split-SPLIT_WIDTH/2;
205 rt.right = last_split+SPLIT_WIDTH/2+1;
206 InvertRect(hdc, &rt);
208 rt.left = x-SPLIT_WIDTH/2;
209 rt.right = x+SPLIT_WIDTH/2+1;
210 InvertRect(hdc, &rt);
211 ReleaseDC(hWnd, hdc);
216 if (pChildWnd != NULL) {
217 SetFocus(pChildWnd->nFocusPanel? pChildWnd->hListWnd: pChildWnd->hTreeWnd);
225 if ((int)wParam == TREE_WINDOW) {
226 switch (((LPNMHDR)lParam)->code) {
227 case TVN_ITEMEXPANDING:
228 return !OnTreeExpanding(pChildWnd->hTreeWnd, (NMTREEVIEW*)lParam);
229 case TVN_SELCHANGED: {
230 LPCTSTR keyPath, rootName;
234 keyPath = GetItemPath(pChildWnd->hTreeWnd, ((NMTREEVIEW*)lParam)->itemNew.hItem, &hRootKey);
236 RefreshListView(pChildWnd->hListWnd, hRootKey, keyPath);
237 rootName = get_root_key_name(hRootKey);
238 fullPath = HeapAlloc(GetProcessHeap(), 0, (lstrlen(rootName) + 1 + lstrlen(keyPath) + 1) * sizeof(TCHAR));
240 _stprintf(fullPath, "%s\\%s", rootName, keyPath);
241 SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)fullPath);
242 HeapFree(GetProcessHeap(), 0, fullPath);
248 pChildWnd->nFocusPanel = 1;
254 if ((int)wParam == LIST_WINDOW) {
255 if (((LPNMHDR)lParam)->code == NM_SETFOCUS) {
256 pChildWnd->nFocusPanel = 0;
257 } else if (!SendMessage(pChildWnd->hListWnd, message, wParam, lParam)) {
264 if (wParam != SIZE_MINIMIZED && pChildWnd != NULL) {
265 ResizeWnd(pChildWnd, LOWORD(lParam), HIWORD(lParam));
269 return DefWindowProc(hWnd, message, wParam, lParam);