501393e43557fb031a80ff2b21a1d457a4c96126
[reactos.git] / rosapps / templates / mdi / childwnd.c
1 /*
2 * ReactOS Application MDI Child Window
3 *
4 * childwnd.c
5 *
6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #ifdef _MSC_VER
24 #include "stdafx.h"
25 #else
26 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
27 #include <windows.h>
28 #include <commctrl.h>
29 #include <stdlib.h>
30 #include <malloc.h>
31 #include <memory.h>
32 #include <tchar.h>
33 #include <process.h>
34 #include <stdio.h>
35 #endif
36
37 #include <assert.h>
38 #define ASSERT assert
39
40 #include "main.h"
41 #include "childwnd.h"
42
43 ////////////////////////////////////////////////////////////////////////////////
44
45 static void draw_splitbar(HWND hWnd, int x)
46 {
47 RECT rt;
48 HDC hdc = GetDC(hWnd);
49
50 GetClientRect(hWnd, &rt);
51 rt.left = x - SPLIT_WIDTH/2;
52 rt.right = x + SPLIT_WIDTH/2+1;
53 InvertRect(hdc, &rt);
54 ReleaseDC(hWnd, hdc);
55 }
56
57 static void OnPaint(HWND hWnd, ChildWnd* pChildWnd)
58 {
59 PAINTSTRUCT ps;
60 RECT rt;
61 GetClientRect(hWnd, &rt);
62 BeginPaint(hWnd, &ps);
63
64 // lastBrush = SelectObject(ps.hdc, (HBRUSH)GetStockObject(WHITE_BRUSH));
65 // Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
66 // SelectObject(ps.hdc, lastBrush);
67 // rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL);
68 FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH));
69 /*
70 rt.left = pChildWnd->nSplitPos-SPLIT_WIDTH/2;
71 rt.right = pChildWnd->nSplitPos+SPLIT_WIDTH/2+1;
72 lastBrush = SelectBrush(ps.hdc, (HBRUSH)GetStockObject(COLOR_SPLITBAR));
73 Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
74 SelectObject(ps.hdc, lastBrush);
75 #ifdef _NO_EXTENSIONS
76 rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL);
77 FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH));
78 #endif
79 */
80 EndPaint(hWnd, &ps);
81 }
82
83
84 static void OnSize(ChildWnd* pChildWnd, WPARAM wParam, LPARAM lParam)
85 {
86 if (wParam != SIZE_MINIMIZED) {
87 //resize_tree(pChildWnd, LOWORD(lParam), HIWORD(lParam));
88 }
89 }
90
91 //
92 // FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
93 //
94 // PURPOSE: Processes messages for the child windows.
95 //
96 // WM_COMMAND - process the application menu
97 // WM_PAINT - Paint the main window
98 // WM_DESTROY - post a quit message and return
99 //
100 //
101 LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
102 {
103 static int last_split;
104 // Pane* pane;
105 ChildWnd* pChildWnd = (ChildWnd*)GetWindowLong(hWnd, GWL_USERDATA);
106 // ChildWnd* new_child;
107 ASSERT(pChildWnd);
108
109 if (1) {
110 switch(message) {
111 case WM_CREATE:
112 return 0;
113
114 case WM_MDIACTIVATE: // set an alternate menu here
115 if (lParam == (LPARAM)hWnd) {
116 } else {
117 }
118 DrawMenuBar(hFrameWnd);
119 // return 0;
120 break;
121
122 case WM_PAINT:
123 OnPaint(hWnd, pChildWnd);
124 return 0;
125
126 case WM_NCDESTROY:
127 //SetWindowLong(hWnd, GWL_USERDATA, 0);
128 break;
129
130 case WM_SETCURSOR:
131 if (LOWORD(lParam) == HTCLIENT) {
132 POINT pt;
133 GetCursorPos(&pt);
134 ScreenToClient(hWnd, &pt);
135
136 if (pt.x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && pt.x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
137 SetCursor(LoadCursor(0, IDC_SIZEWE));
138 return TRUE;
139 }
140 }
141 //goto def;
142 break;
143
144 case WM_LBUTTONDOWN: {
145 RECT rt;
146 int x = LOWORD(lParam);
147
148 GetClientRect(hWnd, &rt);
149
150 if (x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
151 last_split = pChildWnd->nSplitPos;
152 #ifdef _NO_EXTENSIONS
153 draw_splitbar(hWnd, last_split);
154 #endif
155 SetCapture(hWnd);
156 }
157
158 break;}
159
160 case WM_LBUTTONUP:
161 if (GetCapture() == hWnd) {
162 #ifdef _NO_EXTENSIONS
163 RECT rt;
164 int x = LOWORD(lParam);
165 draw_splitbar(hWnd, last_split);
166 last_split = -1;
167 GetClientRect(hWnd, &rt);
168 pChildWnd->nSplitPos = x;
169 //resize_tree(pChildWnd, rt.right, rt.bottom);
170 #endif
171 ReleaseCapture();
172 }
173 break;
174
175 #ifdef _NO_EXTENSIONS
176 case WM_CAPTURECHANGED:
177 if (GetCapture()==hWnd && last_split>=0)
178 draw_splitbar(hWnd, last_split);
179 break;
180 #endif
181
182 case WM_KEYDOWN:
183 if (wParam == VK_ESCAPE)
184 if (GetCapture() == hWnd) {
185 RECT rt;
186 #ifdef _NO_EXTENSIONS
187 draw_splitbar(hWnd, last_split);
188 #else
189 pChildWnd->nSplitPos = last_split;
190 #endif
191 GetClientRect(hWnd, &rt);
192 //resize_tree(pChildWnd, rt.right, rt.bottom);
193 last_split = -1;
194 ReleaseCapture();
195 SetCursor(LoadCursor(0, IDC_ARROW));
196 }
197 break;
198
199 case WM_MOUSEMOVE:
200 if (GetCapture() == hWnd) {
201 RECT rt;
202 int x = LOWORD(lParam);
203
204 #ifdef _NO_EXTENSIONS
205 HDC hdc = GetDC(hWnd);
206 GetClientRect(hWnd, &rt);
207
208 rt.left = last_split-SPLIT_WIDTH/2;
209 rt.right = last_split+SPLIT_WIDTH/2+1;
210 InvertRect(hdc, &rt);
211
212 last_split = x;
213 rt.left = x-SPLIT_WIDTH/2;
214 rt.right = x+SPLIT_WIDTH/2+1;
215 InvertRect(hdc, &rt);
216
217 ReleaseDC(hWnd, hdc);
218 #else
219 GetClientRect(hWnd, &rt);
220
221 if (x>=0 && x<rt.right) {
222 pChildWnd->nSplitPos = x;
223 resize_tree(pChildWnd, rt.right, rt.bottom);
224 rt.left = x-SPLIT_WIDTH/2;
225 rt.right = x+SPLIT_WIDTH/2+1;
226 InvalidateRect(hWnd, &rt, FALSE);
227 UpdateWindow(pChildWnd->left.hWnd);
228 UpdateWindow(hWnd);
229 UpdateWindow(pChildWnd->right.hWnd);
230 }
231 #endif
232 }
233 break;
234
235 #ifndef _NO_EXTENSIONS
236 case WM_GETMINMAXINFO:
237 DefMDIChildProc(hWnd, message, wParam, lParam);
238
239 {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lParam;
240
241 lpmmi->ptMaxTrackSize.x <<= 1;//2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN
242 lpmmi->ptMaxTrackSize.y <<= 1;//2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN
243 break;}
244 #endif
245
246 case WM_SETFOCUS:
247 SetCurrentDirectory(pChildWnd->szPath);
248 SetFocus(pChildWnd->nFocusPanel? pChildWnd->hRightWnd: pChildWnd->hLeftWnd);
249 break;
250 /*
251 case WM_COMMAND:
252 pane = GetFocus()==pChildWnd->left.hWnd? &pChildWnd->left: &pChildWnd->right;
253 switch(LOWORD(wParam)) {
254 case ID_WINDOW_NEW_WINDOW:
255 return 0;
256 default:
257 return pane_command(pane, LOWORD(wParam));
258 break;
259 }
260 break;
261 */
262 case WM_SIZE:
263 if (wParam != SIZE_MINIMIZED) {
264 OnSize(pChildWnd, wParam, lParam);
265 }
266 // fall through
267 default: def:
268 return DefMDIChildProc(hWnd, message, wParam, lParam);
269 }
270 }
271 return DefMDIChildProc(hWnd, message, wParam, lParam);
272 }