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 */
30 /*******************************************************************************
31 * Local module support methods
34 /*FIXME: why do we need this, we should remove it, we have already FindRegRoot */
35 static void MakeFullRegPath(HWND hwndTV
, HTREEITEM hItem
, LPTSTR keyPath
, int* pPathLen
, int max
)
38 item
.mask
= TVIF_PARAM
;
40 if (TreeView_GetItem(hwndTV
, &item
)) {
41 if (item
.hItem
!= TreeView_GetRoot(hwndTV
)) {
43 MakeFullRegPath(hwndTV
, TreeView_GetParent(hwndTV
, hItem
), keyPath
, pPathLen
, max
);
44 keyPath
[*pPathLen
] = _T('\\');
47 item
.mask
= TVIF_TEXT
;
49 item
.pszText
= &keyPath
[*pPathLen
];
50 item
.cchTextMax
= max
- *pPathLen
;
51 if (TreeView_GetItem(hwndTV
, &item
)) {
52 *pPathLen
+= _tcslen(item
.pszText
);
57 static void draw_splitbar(HWND hWnd
, int x
)
60 HDC hdc
= GetDC(hWnd
);
62 GetClientRect(hWnd
, &rt
);
63 rt
.left
= x
- SPLIT_WIDTH
/2;
64 rt
.right
= x
+ SPLIT_WIDTH
/2+1;
69 static void ResizeWnd(ChildWnd
* pChildWnd
, int cx
, int cy
)
71 HDWP hdwp
= BeginDeferWindowPos(2);
72 RECT rt
= {0, 0, cx
, cy
};
74 cx
= pChildWnd
->nSplitPos
+ SPLIT_WIDTH
/2;
75 DeferWindowPos(hdwp
, pChildWnd
->hTreeWnd
, 0, rt
.left
, rt
.top
, pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2-rt
.left
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
76 DeferWindowPos(hdwp
, pChildWnd
->hListWnd
, 0, rt
.left
+cx
, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
77 EndDeferWindowPos(hdwp
);
80 static void OnPaint(HWND hWnd
)
86 GetClientRect(hWnd
, &rt
);
87 hdc
= BeginPaint(hWnd
, &ps
);
88 FillRect(ps
.hdc
, &rt
, GetSysColorBrush(COLOR_BTNFACE
));
92 /*******************************************************************************
94 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
96 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
100 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
102 switch (LOWORD(wParam
)) {
103 /* Parse the menu selections: */
104 case ID_REGISTRY_EXIT
:
107 case ID_VIEW_REFRESH
:
116 /*******************************************************************************
118 * FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
120 * PURPOSE: Processes messages for the child windows.
122 * WM_COMMAND - process the application menu
123 * WM_PAINT - Paint the main window
124 * WM_DESTROY - post a quit message and return
127 LRESULT CALLBACK
ChildWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
129 static int last_split
;
130 /* ChildWnd* pChildWnd = (ChildWnd*)GetWindowLong(hWnd, GWL_USERDATA); */
134 pChildWnd
= (ChildWnd
*)((LPCREATESTRUCT
)lParam
)->lpCreateParams
;
135 if (!pChildWnd
) return 0;
136 pChildWnd
->nSplitPos
= 250;
137 pChildWnd
->hTreeWnd
= CreateTreeView(hWnd
, pChildWnd
->szPath
, TREE_WINDOW
);
138 pChildWnd
->hListWnd
= CreateListView(hWnd
, LIST_WINDOW
/*, pChildWnd->szPath*/);
141 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
)) {
149 if (LOWORD(lParam
) == HTCLIENT
) {
152 ScreenToClient(hWnd
, &pt
);
153 if (pt
.x
>=pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && pt
.x
<pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1) {
154 SetCursor(LoadCursor(0, IDC_SIZEWE
));
162 case WM_LBUTTONDOWN
: {
164 int x
= LOWORD(lParam
);
165 GetClientRect(hWnd
, &rt
);
166 if (x
>=pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && x
<pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1) {
167 last_split
= pChildWnd
->nSplitPos
;
168 draw_splitbar(hWnd
, last_split
);
175 if (GetCapture() == hWnd
) {
177 int x
= LOWORD(lParam
);
178 draw_splitbar(hWnd
, last_split
);
180 GetClientRect(hWnd
, &rt
);
181 pChildWnd
->nSplitPos
= x
;
182 ResizeWnd(pChildWnd
, rt
.right
, rt
.bottom
);
187 case WM_CAPTURECHANGED
:
188 if (GetCapture()==hWnd
&& last_split
>=0)
189 draw_splitbar(hWnd
, last_split
);
193 if (wParam
== VK_ESCAPE
)
194 if (GetCapture() == hWnd
) {
196 draw_splitbar(hWnd
, last_split
);
197 GetClientRect(hWnd
, &rt
);
198 ResizeWnd(pChildWnd
, rt
.right
, rt
.bottom
);
201 SetCursor(LoadCursor(0, IDC_ARROW
));
206 if (GetCapture() == hWnd
) {
208 int x
= LOWORD(lParam
);
209 HDC hdc
= GetDC(hWnd
);
210 GetClientRect(hWnd
, &rt
);
211 rt
.left
= last_split
-SPLIT_WIDTH
/2;
212 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
213 InvertRect(hdc
, &rt
);
215 rt
.left
= x
-SPLIT_WIDTH
/2;
216 rt
.right
= x
+SPLIT_WIDTH
/2+1;
217 InvertRect(hdc
, &rt
);
218 ReleaseDC(hWnd
, hdc
);
223 if (pChildWnd
!= NULL
) {
224 SetFocus(pChildWnd
->nFocusPanel
? pChildWnd
->hListWnd
: pChildWnd
->hTreeWnd
);
232 if ((int)wParam
== TREE_WINDOW
) {
233 switch (((LPNMHDR
)lParam
)->code
) {
234 case TVN_ITEMEXPANDING
:
235 return !OnTreeExpanding(pChildWnd
->hTreeWnd
, (NMTREEVIEW
*)lParam
);
236 case TVN_SELCHANGED
: {
240 keyPath
[0] = _T('\0');
241 hKey
= FindRegRoot(pChildWnd
->hTreeWnd
, ((NMTREEVIEW
*)lParam
)->itemNew
.hItem
, keyPath
, &keyPathLen
, sizeof(keyPath
)/sizeof(TCHAR
));
242 RefreshListView(pChildWnd
->hListWnd
, hKey
, keyPath
);
245 keyPath
[0] = _T('\0');
246 MakeFullRegPath(pChildWnd
->hTreeWnd
, ((NMTREEVIEW
*)lParam
)->itemNew
.hItem
, keyPath
, &keyPathLen
, sizeof(keyPath
)/sizeof(TCHAR
));
247 SendMessage(hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)keyPath
);
254 if ((int)wParam
== LIST_WINDOW
) {
255 if (!SendMessage(pChildWnd
->hListWnd
, message
, wParam
, lParam
)) {
262 if (wParam
!= SIZE_MINIMIZED
&& pChildWnd
!= NULL
) {
263 ResizeWnd(pChildWnd
, LOWORD(lParam
), HIWORD(lParam
));
267 return DefWindowProc(hWnd
, message
, wParam
, lParam
);