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