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

Last change on this file since 5258 was 5258, checked in by sandervl, 25 years ago

mdi, setcursor, min/max/restore, dlglist changes

File size: 12.5 KB
Line 
1/* $Id: win32wbasepos.cpp,v 1.22 2001-02-23 14:52:42 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(getOS2WindowHandle(), &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 if((winpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
156 {
157 params.rgrc[0] = *newWindowRect;
158 if(calcValidRect)
159 {
160 winposCopy = *winpos;
161 params.rgrc[1] = *oldWindowRect;
162 params.rgrc[2] = *oldClientRect;
163 //client rectangel must be in parent coordinates
164 OffsetRect(&params.rgrc[2], rectWindow.left, rectWindow.top);
165
166 params.lppos = &winposCopy;
167 }
168 result = SendInternalMessageA(WM_NCCALCSIZE, calcValidRect, (LPARAM)&params );
169
170 /* If the application send back garbage, ignore it */
171 if(params.rgrc[0].left <= params.rgrc[0].right && params.rgrc[0].top <= params.rgrc[0].bottom)
172 {
173 *newClientRect = params.rgrc[0];
174 //client rectangle now in parent coordinates; convert to 'frame' coordinates
175 OffsetRect(newClientRect, -rectWindow.left, -rectWindow.top);
176 }
177
178 /* FIXME: WVR_ALIGNxxx */
179 if(newClientRect->left != rectClient.left || newClientRect->top != rectClient.top)
180 winpos->flags &= ~SWP_NOCLIENTMOVE;
181
182 if((newClientRect->right - newClientRect->left != rectClient.right - rectClient.left) ||
183 (newClientRect->bottom - newClientRect->top != rectClient.bottom - rectClient.top))
184 winpos->flags &= ~SWP_NOCLIENTSIZE;
185
186 }
187 else
188 if(!(winpos->flags & SWP_NOMOVE) &&
189 (newClientRect->left != rectClient.left || newClientRect->top != rectClient.top)) {
190 winpos->flags &= ~SWP_NOCLIENTMOVE;
191 }
192 return result;
193}
194/***********************************************************************
195 * WINPOS_HandleWindowPosChanging
196 *
197 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
198 */
199LONG Win32BaseWindow::HandleWindowPosChanging(WINDOWPOS *winpos)
200{
201 POINT maxSize;
202 if (winpos->flags & SWP_NOSIZE) return 0;
203
204 if ((dwStyle & WS_THICKFRAME) ||
205 ((dwStyle & (WS_POPUP | WS_CHILD)) == 0))
206 {
207 GetMinMaxInfo( &maxSize, NULL, NULL, NULL );
208 winpos->cx = MIN( winpos->cx, maxSize.x );
209 winpos->cy = MIN( winpos->cy, maxSize.y );
210 }
211 return 0;
212}
213/***********************************************************************
214 * WINPOS_FindIconPos
215 *
216 * Find a suitable place for an iconic window.
217 */
218static void WINPOS_FindIconPos( HWND hwnd, POINT &pt )
219{
220 RECT rectParent;
221 int x, y, xspacing, yspacing;
222 HWND hwndChild, hwndParent;
223
224 hwndParent = GetParent(hwnd);
225 if(hwndParent == 0) {
226 dprintf(("WINPOS_FindIconPos: no parent found for window %x", hwnd));
227 return;
228 }
229
230 GetClientRect(hwndParent, &rectParent );
231 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
232 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
233 return; /* The icon already has a suitable position */
234
235 xspacing = GetSystemMetrics(SM_CXICONSPACING);
236 yspacing = GetSystemMetrics(SM_CYICONSPACING);
237
238 y = rectParent.bottom;
239 for (;;)
240 {
241 x = rectParent.left;
242 do
243 {
244 /* Check if another icon already occupies this spot */
245 hwndChild = GetWindow(hwndParent, GW_CHILD);
246
247 while(hwndChild)
248 {
249 Win32BaseWindow *child = NULL;
250 RECT *pRectWindow;
251
252 child = Win32BaseWindow::GetWindowFromHandle(hwndChild);
253 if(!child) {
254 dprintf(("ERROR: WINPOS_FindIconPos, child %x not found", hwndChild));
255 return;
256 }
257 if ((child->getStyle() & WS_MINIMIZE) && (child->getWindowHandle() != hwnd))
258 {
259 pRectWindow = child->getWindowRect();
260 if ((pRectWindow->left < x + xspacing) &&
261 (pRectWindow->right >= x) &&
262 (pRectWindow->top <= y) &&
263 (pRectWindow->bottom > y - yspacing))
264 break; /* There's a window in there */
265 }
266 hwndChild = GetWindow(hwndChild, GW_HWNDNEXT);
267 }
268
269 if (!hwndChild) /* No window was found, so it's OK for us */
270 {
271 pt.x = x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
272 pt.y = y - (yspacing + GetSystemMetrics(SM_CYICON)) / 2;
273 return;
274 }
275 x += xspacing;
276 } while(x <= rectParent.right-xspacing);
277
278 y -= yspacing;
279 }
280}
281/******************************************************************************
282 * WINPOS_MinMaximize
283 *
284 * Fill in lpRect and return additional flags to be used with SetWindowPos().
285 * This function assumes that 'cmd' is different from the current window
286 * state.
287 */
288UINT Win32BaseWindow::MinMaximize(UINT cmd, LPRECT lpRect)
289{
290 UINT swpFlags = 0;
291 POINT size, iconPos;
292
293 size.x = rectWindow.left;
294 size.y = rectWindow.top;
295
296 if(IsRectEmpty(&windowpos.rcNormalPosition)) {
297 CopyRect(&windowpos.rcNormalPosition, &rectWindow);
298 }
299 if(!HOOK_CallHooksA(WH_CBT, HCBT_MINMAX, getWindowHandle(), cmd))
300 {
301 if(getStyle() & WS_MINIMIZE )
302 {
303 if(!SendInternalMessageA(WM_QUERYOPEN, 0, 0L))
304 return (SWP_NOSIZE | SWP_NOMOVE);
305 }
306 switch( cmd )
307 {
308 case SW_MINIMIZE:
309 if( getStyle() & WS_MAXIMIZE)
310 {
311 setFlags(getFlags() | WIN_RESTORE_MAX);
312 setStyle(getStyle() & ~WS_MAXIMIZE);
313 }
314 else setFlags(getFlags() & ~WIN_RESTORE_MAX);
315
316 setStyle(getStyle() | WS_MINIMIZE);
317
318 iconPos.x = windowpos.ptMinPosition.x;
319 iconPos.y = windowpos.ptMinPosition.y;
320 WINPOS_FindIconPos(getWindowHandle(), iconPos);
321 SetRect(lpRect, iconPos.x, iconPos.y, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
322 break;
323
324 case SW_MAXIMIZE:
325 GetMinMaxInfo(&size, &windowpos.ptMaxPosition, NULL, NULL );
326
327 if(getStyle() & WS_MINIMIZE )
328 {
329 setStyle(getStyle() & ~WS_MINIMIZE);
330 }
331 setStyle(getStyle() | WS_MAXIMIZE);
332
333 SetRect(lpRect, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y,
334 size.x, size.y );
335 break;
336
337 case SW_RESTORE:
338 if(getStyle() & WS_MINIMIZE)
339 {
340 setStyle(getStyle() & ~WS_MINIMIZE);
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.