source: trunk/src/user32/pmframe.cpp@ 2552

Last change on this file since 2552 was 2552, checked in by sandervl, 26 years ago

Don't call default frame handler for WM_ADJUSTWINDOWPOS

File size: 15.8 KB
Line 
1/* $Id: pmframe.cpp,v 1.41 2000-01-28 22:25:59 sandervl Exp $ */
2/*
3 * Win32 Frame Managment Code for OS/2
4 *
5 * Copyright 1999 by Christoph Bratschi (cbratschi@datacomm.ch)
6 *
7 *
8 * Project Odin Software License can be found in LICENSE.TXT
9 *
10 */
11
12#define INCL_WIN
13#define INCL_GPI
14
15#include <os2wrap.h>
16#include <stdlib.h>
17#include <string.h>
18#include "win32type.h"
19#include <misc.h>
20#include <win32wbase.h>
21#include "wprocess.h"
22#include "pmframe.h"
23#include "oslibutil.h"
24#include "oslibwin.h"
25#include "caret.h"
26#include "oslibmsg.h"
27
28#define PMFRAMELOG
29
30//******************************************************************************
31//******************************************************************************
32VOID FrameTrackFrame(Win32BaseWindow *win32wnd,DWORD flags)
33{
34 WinSendMsg(win32wnd->getOS2FrameWindowHandle(),WM_TRACKFRAME,(MPARAM)flags,(MPARAM)0);
35}
36//******************************************************************************
37//******************************************************************************
38VOID FrameUpdateChildPositions(HWND hwnd)
39{
40 HENUM henum;
41 HWND hchild;
42 RECTL rectl;
43
44 henum = WinBeginEnumWindows(hwnd);
45 while ((hchild = WinGetNextWindow(henum)) != NULLHANDLE)
46 {
47 Win32BaseWindow *child = Win32BaseWindow::GetWindowFromOS2FrameHandle(hchild);
48
49 if (child)
50 {
51 WinQueryWindowRect(child->getOS2FrameWindowHandle(),&rectl);
52 mapOS2ToWin32Rect(child->getOS2FrameWindowHandle(),OSLIB_HWND_DESKTOP,(PRECTLOS2)&rectl,child->getWindowRect());
53 FrameUpdateChildPositions(child->getOS2WindowHandle());
54 }
55 }
56 WinEndEnumWindows(henum);
57}
58//******************************************************************************
59//Win32 frame message handler
60//******************************************************************************
61MRESULT EXPENTRY Win32FrameProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
62{
63 Win32BaseWindow *win32wnd;
64 PFNWP OldFrameProc;
65 MRESULT rc;
66 THDB *thdb;
67 MSG *pWinMsg,winMsg;
68
69 SetWin32TIB();
70
71 thdb = GetThreadTHDB();
72 win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
73
74 if (!thdb || (win32wnd == NULL) || !win32wnd->getOldFrameProc())
75 {
76 dprintf(("Invalid win32wnd pointer for frame %x!!", hwnd));
77 goto RunDefWndProc;
78 }
79
80 if((thdb->msgstate & 1) == 0)
81 {//message that was sent directly to our window proc handler; translate it here
82 QMSG qmsg;
83
84 qmsg.msg = msg;
85 qmsg.hwnd = hwnd;
86 qmsg.mp1 = mp1;
87 qmsg.mp2 = mp2;
88 qmsg.time = WinQueryMsgTime(thdb->hab);
89 WinQueryMsgPos(thdb->hab, &qmsg.ptl);
90 qmsg.reserved = 0;
91
92 if(OS2ToWinMsgTranslate((PVOID)thdb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
93 {//message was not translated
94 memset(&winMsg, 0, sizeof(MSG));
95 }
96 pWinMsg = &winMsg;
97 }
98 else {
99 pWinMsg = &thdb->msg;
100 thdb->msgstate++;
101 }
102
103 OldFrameProc = (PFNWP)win32wnd->getOldFrameProc();
104
105 switch(msg)
106 {
107 case WM_FORMATFRAME:
108 break;
109
110 case WM_MINMAXFRAME:
111 {
112 PSWP swp = (PSWP)mp1;
113
114 if (!win32wnd->IsWindowCreated()) goto RunDefFrameProc;
115 dprintf(("PMFRAME: WM_MINMAXFRAME %x",hwnd));
116 if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
117 {
118 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MINIMIZE_W) | WS_MAXIMIZE_W);
119
120 RECT rect;
121
122 rect.left = rect.top = rect.right = rect.bottom = 0;
123 win32wnd->AdjustMaximizedRect(&rect);
124 swp->x += rect.left;
125 swp->cx += rect.right-rect.left;
126 swp->y -= rect.bottom;
127 swp->cy += rect.bottom-rect.top;
128 }
129 else if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
130 {
131 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
132 }
133 else if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
134 {
135 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
136 }
137 goto RunDefFrameProc;
138 }
139
140 case WM_QUERYTRACKINFO:
141 {
142 PTRACKINFO trackInfo = (PTRACKINFO)mp2;
143
144 RestoreOS2TIB();
145 OldFrameProc(hwnd,msg,mp1,mp2);
146 SetWin32TIB();
147 trackInfo->cxBorder = 0;
148 trackInfo->cyBorder = 0;
149 win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
150 RestoreOS2TIB();
151 return (MRESULT)TRUE;
152 }
153
154 case WM_QUERYBORDERSIZE:
155 {
156 PWPOINT size = (PWPOINT)mp1;
157
158 size->x = 0;
159 size->y = 0;
160 RestoreOS2TIB();
161 return (MRESULT)TRUE;
162 }
163
164 case WM_BUTTON1DOWN:
165 case WM_BUTTON1UP:
166 case WM_BUTTON1DBLCLK:
167 case WM_BUTTON2DOWN:
168 case WM_BUTTON2UP:
169 case WM_BUTTON2DBLCLK:
170 case WM_BUTTON3DOWN:
171 case WM_BUTTON3UP:
172 case WM_BUTTON3DBLCLK:
173 {
174 if (win32wnd->IsWindowCreated())
175 {
176 win32wnd->MsgButton(pWinMsg);
177 RestoreOS2TIB();
178 }
179 return (MRESULT)TRUE;
180 }
181
182 case WM_BUTTON2MOTIONSTART:
183 case WM_BUTTON2MOTIONEND:
184 case WM_BUTTON2CLICK:
185 case WM_BUTTON1MOTIONSTART:
186 case WM_BUTTON1MOTIONEND:
187 case WM_BUTTON1CLICK:
188 case WM_BUTTON3MOTIONSTART:
189 case WM_BUTTON3MOTIONEND:
190 case WM_BUTTON3CLICK:
191 RestoreOS2TIB();
192 return (MRESULT)TRUE;
193
194 case WM_MOUSEMOVE:
195 {
196 //OS/2 Window coordinates -> Win32 Window coordinates
197 if (win32wnd->IsWindowCreated())
198 win32wnd->MsgMouseMove(pWinMsg);
199 RestoreOS2TIB();
200 return (MRESULT)TRUE;
201 }
202
203 case WM_PAINT:
204 {
205 dprintf(("PMFRAME: WM_PAINT"));
206 if (win32wnd->getStyle() & WS_MINIMIZE_W)
207 goto RunDefFrameProc;
208 if (win32wnd->IsWindowCreated())
209 win32wnd->MsgNCPaint();
210 goto RunDefWndProc;
211 }
212
213 case WM_SIZE:
214 dprintf(("PMFRAME: WM_SIZE"));
215 goto RunDefFrameProc;
216
217 case WM_ADJUSTWINDOWPOS:
218 {
219 PSWP pswp = (PSWP)mp1;
220 SWP swpOld;
221 WINDOWPOS wp,wpOld;
222 HWND hParent = NULLHANDLE, hwndAfter;
223
224 dprintf(("PMFRAME: WM_ADJUSTWINDOWPOS %x %x %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
225
226 //CB: show dialog in front of owner
227 if (win32wnd->IsModalDialogOwner())
228 {
229 pswp->fl |= SWP_ZORDER;
230 pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
231 if (pswp->fl & SWP_ACTIVATE)
232 {
233 pswp->fl &= ~SWP_ACTIVATE;
234 WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
235 }
236 }
237
238 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
239 goto RunDefFrameProc;
240
241 if(!win32wnd->CanReceiveSizeMsgs())
242 break;
243
244 WinQueryWindowPos(hwnd, &swpOld);
245 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
246 if (win32wnd->isChild()) {
247 if(win32wnd->getParent()) {
248 hParent = win32wnd->getParent()->getOS2WindowHandle();
249 }
250 else goto RunDefFrameProc;
251 }
252 }
253 hwndAfter = pswp->hwndInsertBehind;
254 OSLibMapSWPtoWINDOWPOSFrame(pswp, &wp, &swpOld, hParent, hwnd);
255
256 wp.hwnd = win32wnd->getWindowHandle();
257 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
258 {
259 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
260 if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
261 }
262
263 wpOld = wp;
264 win32wnd->MsgPosChanging((LPARAM)&wp);
265
266 if ((wp.hwndInsertAfter != wpOld.hwndInsertAfter) ||
267 (wp.x != wpOld.x) || (wp.y != wpOld.y) || (wp.cx != wpOld.cx) || (wp.cy != wpOld.cy) || (wp.flags != wpOld.flags))
268 {
269 dprintf(("PMFRAME: WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
270 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
271
272 OSLibMapWINDOWPOStoSWPFrame(&wp, pswp, &swpOld, hParent, hwnd);
273 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
274 pswp->fl |= SWP_NOADJUST;
275 pswp->hwndInsertBehind = hwndAfter;
276 pswp->hwnd = hwnd;
277
278 RestoreOS2TIB();
279 return (MRESULT)0xf;
280 }
281 RestoreOS2TIB();
282 return (MRESULT)0;
283 }
284
285 case WM_WINDOWPOSCHANGED:
286 {
287 PSWP pswp = (PSWP)mp1,pswpOld = pswp+1;
288 SWP swpOld = *(pswp + 1);
289 WINDOWPOS wp;
290 HWND hParent = NULLHANDLE;
291 RECTL rect;
292 SWP swpClient = {0};
293
294 dprintf(("PMFRAME: WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
295
296 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
297 {
298 goto RunDefFrameProc;
299 }
300
301 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
302 if (win32wnd->isChild()) {
303 if(win32wnd->getParent()) {
304 hParent = win32wnd->getParent()->getOS2WindowHandle();
305 }
306 else goto PosChangedEnd; //parent has just been destroyed
307 }
308 }
309
310 OSLibMapSWPtoWINDOWPOSFrame(pswp, &wp, &swpOld, hParent, hwnd);
311
312 if(pswp->fl & SWP_ACTIVATE)
313 {
314 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)TRUE, (MPARAM)hwnd);
315 }
316
317 if((pswp->fl & (SWP_MOVE | SWP_SIZE)) && !(win32wnd->getStyle() & WS_MINIMIZE_W))
318 {
319 //Note: Also updates the new window rectangle
320 win32wnd->MsgFormatFrame(&wp);
321
322 //CB: todo: use result for WM_CALCVALIDRECTS
323 mapWin32ToOS2Rect(win32wnd->getOS2FrameWindowHandle(), win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
324
325 swpClient.hwnd = win32wnd->getOS2WindowHandle();
326 swpClient.hwndInsertBehind = 0;
327 swpClient.x = rect.xLeft;
328 swpClient.y = rect.yBottom;
329 swpClient.cx = rect.xRight-rect.xLeft;
330 swpClient.cy = rect.yTop-rect.yBottom;
331 //TODO: Get rid of SWP_SHOW; needed for winhlp32 button bar for now
332 swpClient.fl = (pswp->fl & ~SWP_ZORDER) | SWP_MOVE | SWP_SHOW;
333 WinSetMultWindowPos(thdb->hab, &swpClient, 1);
334
335 //update child positions: rectWindow is in window coordinates
336 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
337 FrameUpdateChildPositions(win32wnd->getOS2WindowHandle());
338 }
339
340 if(win32wnd->CanReceiveSizeMsgs())
341 win32wnd->MsgPosChanged((LPARAM)&wp);
342
343 if ((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
344 {
345 //redraw the frame (to prevent unnecessary client updates)
346 BOOL redrawAll = FALSE;
347
348 if (win32wnd->getWindowClass())
349 {
350 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
351
352 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
353 redrawAll = TRUE;
354 else if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
355 redrawAll = TRUE;
356 } else redrawAll = TRUE;
357
358 if (redrawAll)
359 {
360 WinInvalidateRect(hwnd,NULL,TRUE);
361 }
362 else
363 {
364 HPS hps = WinGetPS(hwnd);
365 RECTL frame,client,arcl[4];
366
367 WinQueryWindowRect(hwnd,&frame);
368 //top
369 arcl[0].xLeft = 0;
370 arcl[0].xRight = frame.xRight;
371 arcl[0].yBottom = rect.yTop;
372 arcl[0].yTop = frame.yTop;
373 //right
374 arcl[1].xLeft = rect.xRight;
375 arcl[1].xRight = frame.xRight;
376 arcl[1].yBottom = 0;
377 arcl[1].yTop = frame.yTop;
378 //left
379 arcl[2].xLeft = 0;
380 arcl[2].xRight = rect.xLeft;
381 arcl[2].yBottom = 0;
382 arcl[2].yTop = frame.yTop;
383 //bottom
384 arcl[3].xLeft = 0;
385 arcl[3].xRight = frame.xRight;
386 arcl[3].yBottom = 0;
387 arcl[3].yTop = rect.yBottom;
388
389 HRGN hrgn = GpiCreateRegion(hps,3,(PRECTL)&arcl);
390
391 WinInvalidateRegion(hwnd,hrgn,FALSE);
392 GpiDestroyRegion(hps,hrgn);
393 WinReleasePS(hps);
394 }
395 }
396 }
397 else
398 {
399 //update child positions: rectWindow is in window coordinates
400 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
401 FrameUpdateChildPositions(win32wnd->getOS2WindowHandle());
402 }
403
404 if(win32wnd->CanReceiveSizeMsgs())
405 win32wnd->MsgPosChanged((LPARAM)&wp);
406 }
407
408PosChangedEnd:
409 RestoreOS2TIB();
410 return (MRESULT)FALSE;
411 }
412
413 case WM_ERASEBACKGROUND:
414 break;
415
416 case WM_CALCVALIDRECTS:
417 {
418 //don't redraw here or PM redraw the whole frame (done in WM_WINDOWPOSCHANGED)
419 RestoreOS2TIB();
420 return (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
421 }
422
423 case WM_ACTIVATE:
424 {
425 HWND hwndTitle;
426 USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
427
428 dprintf(("PMFRAME: WM_ACTIVATE %x %x", hwnd, mp2));
429 if (win32wnd->IsWindowCreated())
430 {
431 WinSendMsg(WinWindowFromID(hwnd,FID_CLIENT),WM_ACTIVATE,mp1,mp2);
432 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
433
434 //CB: show owner behind the dialog
435 if (win32wnd->IsModalDialog())
436 {
437 Win32BaseWindow *topOwner = win32wnd->getOwner()->GetTopParent();
438
439 if (topOwner) WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
440 }
441 }
442 else
443 {
444 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
445 }
446 if(win32wnd->IsWindowCreated())
447 win32wnd->DispatchMsgA(pWinMsg);
448
449 RestoreOS2TIB();
450 return 0;
451 }
452
453 case WM_DESTROY:
454 dprintf(("PMFRAME: WM_DESTROY %x",hwnd));
455 WinSubclassWindow(hwnd,OldFrameProc);
456 win32wnd->setOldFrameProc(NULL);
457 goto RunDefFrameProc;
458
459 default:
460 RestoreOS2TIB();
461 return OldFrameProc(hwnd,msg,mp1,mp2);
462 }
463
464 RestoreOS2TIB();
465 return (MRESULT)FALSE;
466
467RunDefFrameProc:
468 RestoreOS2TIB();
469 return OldFrameProc(hwnd,msg,mp1,mp2);
470
471RunDefWndProc:
472 RestoreOS2TIB();
473 return WinDefWindowProc(hwnd,msg,mp1,mp2);
474}
475//******************************************************************************
476//******************************************************************************
477PVOID FrameSubclassFrameWindow(Win32BaseWindow *win32wnd)
478{
479 return WinSubclassWindow(win32wnd->getOS2FrameWindowHandle(),PFNWP(Win32FrameProc));
480}
481//******************************************************************************
482//******************************************************************************
483VOID FrameUpdateClient(Win32BaseWindow *win32wnd)
484{
485 RECT rectOld, rectNew;
486 RECTL rect;
487 SWP swpClient = {0};
488
489 rectOld = *win32wnd->getClientRectPtr();
490 win32wnd->MsgFormatFrame(NULL);
491 rectNew = *win32wnd->getClientRectPtr();
492 if(WinEqualRect(0, (PRECTL)&rectOld, (PRECTL)&rectNew) == 1) {
493 WinInvalidateRect(win32wnd->getOS2FrameWindowHandle(), NULL, FALSE);
494 return;
495 }
496 //CB: todo: use result for WM_CALCVALIDRECTS
497 mapWin32ToOS2Rect(win32wnd->getOS2FrameWindowHandle(), win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
498
499
500 swpClient.hwnd = win32wnd->getOS2WindowHandle();
501 swpClient.hwndInsertBehind = 0;
502 swpClient.x = rect.xLeft;
503 swpClient.y = rect.yBottom;
504 swpClient.cx = rect.xRight-rect.xLeft;
505 swpClient.cy = rect.yTop-rect.yBottom;
506 swpClient.fl = SWP_MOVE | SWP_SIZE;
507 WinSetMultWindowPos(GetThreadHAB(), &swpClient, 1);
508}
509//******************************************************************************
510//******************************************************************************
Note: See TracBrowser for help on using the repository browser.