1 | /* $Id: win32wbasepos.cpp,v 1.20 2001-02-21 20:51:07 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 | */
|
---|
49 | void 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 | */
|
---|
145 | LONG 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(¶ms.rgrc[2], rectWindow.left, rectWindow.top);
|
---|
165 |
|
---|
166 | params.lppos = &winposCopy;
|
---|
167 | }
|
---|
168 | result = SendInternalMessageA(WM_NCCALCSIZE, calcValidRect, (LPARAM)¶ms );
|
---|
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 | */
|
---|
199 | LONG 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_MinMaximize
|
---|
215 | *
|
---|
216 | * Fill in lpRect and return additional flags to be used with SetWindowPos().
|
---|
217 | * This function assumes that 'cmd' is different from the current window
|
---|
218 | * state.
|
---|
219 | */
|
---|
220 | UINT Win32BaseWindow::MinMaximize(UINT cmd, LPRECT lpRect)
|
---|
221 | {
|
---|
222 | UINT swpFlags = 0;
|
---|
223 | POINT size;
|
---|
224 |
|
---|
225 | size.x = rectWindow.left;
|
---|
226 | size.y = rectWindow.top;
|
---|
227 |
|
---|
228 | if(IsRectEmpty(&windowpos.rcNormalPosition)) {
|
---|
229 | CopyRect(&windowpos.rcNormalPosition, &rectWindow);
|
---|
230 | }
|
---|
231 | if(!HOOK_CallHooksA(WH_CBT, HCBT_MINMAX, getWindowHandle(), cmd))
|
---|
232 | {
|
---|
233 | if(getStyle() & WS_MINIMIZE )
|
---|
234 | {
|
---|
235 | if(!SendInternalMessageA(WM_QUERYOPEN, 0, 0L))
|
---|
236 | return (SWP_NOSIZE | SWP_NOMOVE);
|
---|
237 | }
|
---|
238 | switch( cmd )
|
---|
239 | {
|
---|
240 | case SW_MINIMIZE:
|
---|
241 | if( getStyle() & WS_MAXIMIZE)
|
---|
242 | {
|
---|
243 | setFlags(getFlags() | WIN_RESTORE_MAX);
|
---|
244 | setStyle(getStyle() & ~WS_MAXIMIZE);
|
---|
245 | }
|
---|
246 | else setFlags(getFlags() & ~WIN_RESTORE_MAX);
|
---|
247 |
|
---|
248 | setStyle(getStyle() | WS_MINIMIZE);
|
---|
249 |
|
---|
250 | SetRect(lpRect, windowpos.ptMinPosition.x, windowpos.ptMinPosition.y,
|
---|
251 | GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
|
---|
252 | break;
|
---|
253 |
|
---|
254 | case SW_MAXIMIZE:
|
---|
255 | GetMinMaxInfo(&size, &windowpos.ptMaxPosition, NULL, NULL );
|
---|
256 |
|
---|
257 | if(getStyle() & WS_MINIMIZE )
|
---|
258 | {
|
---|
259 | setStyle(getStyle() & ~WS_MINIMIZE);
|
---|
260 | }
|
---|
261 | setStyle(getStyle() | WS_MAXIMIZE);
|
---|
262 |
|
---|
263 | SetRect(lpRect, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y,
|
---|
264 | size.x, size.y );
|
---|
265 | break;
|
---|
266 |
|
---|
267 | case SW_RESTORE:
|
---|
268 | if(getStyle() & WS_MINIMIZE)
|
---|
269 | {
|
---|
270 | setStyle(getStyle() & ~WS_MINIMIZE);
|
---|
271 |
|
---|
272 | if( getFlags() & WIN_RESTORE_MAX)
|
---|
273 | {
|
---|
274 | /* Restore to maximized position */
|
---|
275 | GetMinMaxInfo(&size, &windowpos.ptMaxPosition, NULL, NULL);
|
---|
276 | setStyle(getStyle() | WS_MAXIMIZE);
|
---|
277 | SetRect(lpRect, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y, size.x, size.y);
|
---|
278 | break;
|
---|
279 | }
|
---|
280 | }
|
---|
281 | else
|
---|
282 | if( !(getStyle() & WS_MAXIMIZE) )
|
---|
283 | return 0;
|
---|
284 | else setStyle(getStyle() & ~WS_MAXIMIZE);
|
---|
285 |
|
---|
286 | /* Restore to normal position */
|
---|
287 | *lpRect = windowpos.rcNormalPosition;
|
---|
288 | lpRect->right -= lpRect->left;
|
---|
289 | lpRect->bottom -= lpRect->top;
|
---|
290 | break;
|
---|
291 | }
|
---|
292 | }
|
---|
293 | else swpFlags |= SWP_NOSIZE | SWP_NOMOVE;
|
---|
294 |
|
---|
295 | return swpFlags;
|
---|
296 | }
|
---|
297 | //******************************************************************************
|
---|
298 | //******************************************************************************
|
---|