source: trunk/src/user32/win32wbasepos.cpp@ 5777

Last change on this file since 5777 was 5777, checked in by sandervl, 24 years ago

minimize & restore fixes

File size: 12.7 KB
Line 
1/* $Id: win32wbasepos.cpp,v 1.25 2001-05-22 09:33:16 sandervl Exp $ */
2/*
3 * Win32 Window Base Class for OS/2 (nonclient/position methods)
4 *
5 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
6 * Copyright 1999 Daniela Engert (dani@ngrt.de)
7 *
8 * Parts based on Wine Windows code (windows\win.c, windows\nonclient.c)
9 *
10 * Copyright 1993, 1994 Alexandre Julliard
11 *
12 * TODO: Not thread/process safe
13 *
14 * Wine code based on build 990815
15 *
16 * Project Odin Software License can be found in LICENSE.TXT
17 *
18 */
19#include <os2win.h>
20#include <win.h>
21#include <stdlib.h>
22#include <string.h>
23#include <stdarg.h>
24#include <assert.h>
25#include <misc.h>
26#include <win32wbase.h>
27#include <spy.h>
28#include "wndmsg.h"
29#include "oslibwin.h"
30#include "oslibutil.h"
31#include "oslibgdi.h"
32#include "oslibres.h"
33#include "oslibdos.h"
34#include "syscolor.h"
35#include "win32wndhandle.h"
36#include "dc.h"
37#include "pmframe.h"
38#include "win32wdesktop.h"
39#include <win\hook.h>
40
41#define DBG_LOCALLOG DBG_win32wbasepos
42#include "dbglocal.h"
43
44/*******************************************************************
45 * GetMinMaxInfo
46 *
47 * Get the minimized and maximized information for a window.
48 */
49void Win32BaseWindow::GetMinMaxInfo(POINT *maxSize, POINT *maxPos,
50 POINT *minTrack, POINT *maxTrack )
51{
52 MINMAXINFO MinMax;
53 INT xinc, yinc;
54
55 /* Compute default values */
56 MinMax.ptMaxPosition.x = 0;
57 MinMax.ptMaxPosition.y = 0;
58
59 if(!(getStyle() & (WS_POPUP | WS_CHILD))) {
60 RECT rect;
61 OSLibWinGetMaxPosition(getOS2FrameWindowHandle(), &rect);
62 MinMax.ptMaxPosition.x = rect.left;
63 MinMax.ptMaxPosition.y = rect.top;
64
65 MinMax.ptMaxSize.x = rect.right - rect.left;
66 MinMax.ptMaxSize.y = rect.bottom - rect.top;
67 MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
68 MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
69 MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXSCREEN);
70 MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN);
71 }
72 else {
73 MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
74 MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
75 MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
76 MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
77 MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXSCREEN);
78 MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN);
79 }
80
81 if (HAS_DLGFRAME( dwStyle, dwExStyle ))
82 {
83 xinc = GetSystemMetrics(SM_CXDLGFRAME);
84 yinc = GetSystemMetrics(SM_CYDLGFRAME);
85 }
86 else
87 {
88 xinc = yinc = 0;
89 if (HAS_THICKFRAME(dwStyle, dwExStyle))
90 {
91 xinc += GetSystemMetrics(SM_CXFRAME);
92 yinc += GetSystemMetrics(SM_CYFRAME);
93 }
94 //SvL: Wine has no 'else', but I'm seeing different behaviour in NT
95 // and it doesn't make much sense either as a window can have
96 // only one kind of border (see drawing code)
97 else
98 if (dwStyle & WS_BORDER)
99 {
100 xinc += GetSystemMetrics(SM_CXBORDER);
101 yinc += GetSystemMetrics(SM_CYBORDER);
102 }
103 }
104 MinMax.ptMaxSize.x += 2 * xinc;
105 MinMax.ptMaxSize.y += 2 * yinc;
106
107#if 0
108 lpPos = (LPINTERNALPOS)GetPropA( hwndSelf, atomInternalPos );
109 if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
110 CONV_POINT16TO32( &lpPos->ptMaxPos, &MinMax.ptMaxPosition );
111 else
112 {
113#endif
114 MinMax.ptMaxPosition.x -= xinc;
115 MinMax.ptMaxPosition.y -= yinc;
116// }
117
118 SendInternalMessageA(WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
119
120 /* Some sanity checks */
121
122 dprintf(("GetMinMaxInfo: %ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
123 MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
124 MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
125 MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
126 MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y));
127 MinMax.ptMaxTrackSize.x = MAX( MinMax.ptMaxTrackSize.x,
128 MinMax.ptMinTrackSize.x );
129 MinMax.ptMaxTrackSize.y = MAX( MinMax.ptMaxTrackSize.y,
130 MinMax.ptMinTrackSize.y );
131
132 if (maxSize) *maxSize = MinMax.ptMaxSize;
133 if (maxPos) *maxPos = MinMax.ptMaxPosition;
134 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
135 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
136}
137/***********************************************************************
138 * WINPOS_SendNCCalcSize
139 *
140 * Send a WM_NCCALCSIZE message to a window.
141 * All parameters are read-only except newClientRect.
142 * oldWindowRect, oldClientRect and winpos must be non-NULL only
143 * when calcValidRect is TRUE.
144 */
145LONG Win32BaseWindow::SendNCCalcSize(BOOL calcValidRect, RECT *newWindowRect,
146 RECT *oldWindowRect,
147 RECT *oldClientRect, WINDOWPOS *winpos,
148 RECT *newClientRect )
149{
150 NCCALCSIZE_PARAMS params;
151 WINDOWPOS winposCopy;
152 LONG result = 0;
153
154 /* Send WM_NCCALCSIZE message to get new client area */
155 params.rgrc[0] = *newWindowRect;
156 if(calcValidRect)
157 {
158 winposCopy = *winpos;
159 params.rgrc[1] = *oldWindowRect;
160 params.rgrc[2] = *oldClientRect;
161 //client rectangel must be in parent coordinates
162 OffsetRect(&params.rgrc[2], rectWindow.left, rectWindow.top);
163
164 params.lppos = &winposCopy;
165 }
166 result = SendInternalMessageA(WM_NCCALCSIZE, calcValidRect, (LPARAM)&params );
167
168 /* If the application send back garbage, ignore it */
169 if(params.rgrc[0].left <= params.rgrc[0].right && params.rgrc[0].top <= params.rgrc[0].bottom)
170 {
171 *newClientRect = params.rgrc[0];
172 //client rectangle now in parent coordinates; convert to 'frame' coordinates
173 OffsetRect(newClientRect, -rectWindow.left, -rectWindow.top);
174 }
175
176 /* FIXME: WVR_ALIGNxxx */
177 if(newClientRect->left != rectClient.left || newClientRect->top != rectClient.top)
178 winpos->flags &= ~SWP_NOCLIENTMOVE;
179
180 if((newClientRect->right - newClientRect->left != rectClient.right - rectClient.left) ||
181 (newClientRect->bottom - newClientRect->top != rectClient.bottom - rectClient.top))
182 winpos->flags &= ~SWP_NOCLIENTSIZE;
183
184 return result;
185}
186/***********************************************************************
187 * WINPOS_HandleWindowPosChanging
188 *
189 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
190 */
191LONG Win32BaseWindow::HandleWindowPosChanging(WINDOWPOS *winpos)
192{
193 POINT maxSize;
194 if (winpos->flags & SWP_NOSIZE) return 0;
195
196 if ((dwStyle & WS_THICKFRAME) ||
197 ((dwStyle & (WS_POPUP | WS_CHILD)) == 0))
198 {
199 GetMinMaxInfo( &maxSize, NULL, NULL, NULL );
200 winpos->cx = MIN( winpos->cx, maxSize.x );
201 winpos->cy = MIN( winpos->cy, maxSize.y );
202 }
203 return 0;
204}
205/***********************************************************************
206 * WINPOS_FindIconPos
207 *
208 * Find a suitable place for an iconic window.
209 */
210static void WINPOS_FindIconPos( HWND hwnd, POINT &pt )
211{
212 RECT rectParent;
213 int x, y, xspacing, yspacing;
214 HWND hwndChild, hwndParent;
215
216 hwndParent = GetParent(hwnd);
217 if(hwndParent == 0) {
218 dprintf(("WINPOS_FindIconPos: no parent found for window %x", hwnd));
219 return;
220 }
221
222 GetClientRect(hwndParent, &rectParent );
223 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
224 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
225 return; /* The icon already has a suitable position */
226
227 xspacing = GetSystemMetrics(SM_CXICONSPACING);
228 yspacing = GetSystemMetrics(SM_CYICONSPACING);
229
230 y = rectParent.bottom;
231 for (;;)
232 {
233 x = rectParent.left;
234 do
235 {
236 /* Check if another icon already occupies this spot */
237 hwndChild = GetWindow(hwndParent, GW_CHILD);
238
239 while(hwndChild)
240 {
241 Win32BaseWindow *child = NULL;
242 RECT *pRectWindow;
243
244 child = Win32BaseWindow::GetWindowFromHandle(hwndChild);
245 if(!child) {
246 dprintf(("ERROR: WINPOS_FindIconPos, child %x not found", hwndChild));
247 return;
248 }
249 if ((child->getStyle() & WS_MINIMIZE) && (child->getWindowHandle() != hwnd))
250 {
251 pRectWindow = child->getWindowRect();
252 if ((pRectWindow->left < x + xspacing) &&
253 (pRectWindow->right >= x) &&
254 (pRectWindow->top <= y) &&
255 (pRectWindow->bottom > y - yspacing))
256 break; /* There's a window in there */
257 }
258 hwndChild = GetWindow(hwndChild, GW_HWNDNEXT);
259 }
260
261 if (!hwndChild) /* No window was found, so it's OK for us */
262 {
263 pt.x = x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
264 pt.y = y - (yspacing + GetSystemMetrics(SM_CYICON)) / 2;
265 return;
266 }
267 x += xspacing;
268 } while(x <= rectParent.right-xspacing);
269
270 y -= yspacing;
271 }
272}
273/******************************************************************************
274 * WINPOS_MinMaximize
275 *
276 * Fill in lpRect and return additional flags to be used with SetWindowPos().
277 * This function assumes that 'cmd' is different from the current window
278 * state.
279 */
280UINT Win32BaseWindow::MinMaximize(UINT cmd, LPRECT lpRect)
281{
282 UINT swpFlags = 0;
283 POINT size, iconPos;
284
285 size.x = rectWindow.left;
286 size.y = rectWindow.top;
287
288 if(IsRectEmpty(&windowpos.rcNormalPosition)) {
289 CopyRect(&windowpos.rcNormalPosition, &rectWindow);
290 }
291 if(!HOOK_CallHooksA(WH_CBT, HCBT_MINMAX, getWindowHandle(), cmd))
292 {
293 if(getStyle() & WS_MINIMIZE )
294 {
295 if(!SendInternalMessageA(WM_QUERYOPEN, 0, 0L))
296 return (SWP_NOSIZE | SWP_NOMOVE);
297 }
298 switch( cmd )
299 {
300 case SW_MINIMIZE:
301 if( getStyle() & WS_MAXIMIZE)
302 {
303 setFlags(getFlags() | WIN_RESTORE_MAX);
304 setStyle(getStyle() & ~WS_MAXIMIZE);
305 }
306 else setFlags(getFlags() & ~WIN_RESTORE_MAX);
307
308 setStyle(getStyle() | WS_MINIMIZE);
309
310 if(getParent() == NULL) {
311 SetRect(lpRect, -32000, -32000, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON));
312 OSLibSetWindowStyle(getOS2FrameWindowHandle(), getOS2WindowHandle(), getStyle(), getExStyle());
313 }
314 else {
315 iconPos.x = windowpos.ptMinPosition.x;
316 iconPos.y = windowpos.ptMinPosition.y;
317 WINPOS_FindIconPos(getWindowHandle(), iconPos);
318 SetRect(lpRect, iconPos.x, iconPos.y, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
319 }
320 break;
321
322 case SW_MAXIMIZE:
323 GetMinMaxInfo(&size, &windowpos.ptMaxPosition, NULL, NULL );
324
325 if(getStyle() & WS_MINIMIZE )
326 {
327 setStyle(getStyle() & ~WS_MINIMIZE);
328 OSLibSetWindowStyle(getOS2FrameWindowHandle(), getOS2WindowHandle(), getStyle(), getExStyle());
329 }
330 setStyle(getStyle() | WS_MAXIMIZE);
331
332 SetRect(lpRect, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y,
333 size.x, size.y );
334 break;
335
336 case SW_RESTORE:
337 if(getStyle() & WS_MINIMIZE)
338 {
339 setStyle(getStyle() & ~WS_MINIMIZE);
340 OSLibSetWindowStyle(getOS2FrameWindowHandle(), getOS2WindowHandle(), getStyle(), getExStyle());
341
342 if( getFlags() & WIN_RESTORE_MAX)
343 {
344 /* Restore to maximized position */
345 GetMinMaxInfo(&size, &windowpos.ptMaxPosition, NULL, NULL);
346 setStyle(getStyle() | WS_MAXIMIZE);
347 SetRect(lpRect, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y, size.x, size.y);
348 break;
349 }
350 }
351 else
352 if( !(getStyle() & WS_MAXIMIZE) )
353 return 0;
354 else setStyle(getStyle() & ~WS_MAXIMIZE);
355
356 /* Restore to normal position */
357 *lpRect = windowpos.rcNormalPosition;
358 lpRect->right -= lpRect->left;
359 lpRect->bottom -= lpRect->top;
360 break;
361 }
362 }
363 else swpFlags |= SWP_NOSIZE | SWP_NOMOVE;
364
365 return swpFlags;
366}
367//******************************************************************************
368//******************************************************************************
Note: See TracBrowser for help on using the repository browser.