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

Last change on this file since 2521 was 2521, checked in by cbratschi, 26 years ago

refixed WM_WINDOWPOS*

File size: 15.8 KB
Line 
1/* $Id: pmframe.cpp,v 1.39 2000-01-26 18:02:35 cbratschi 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 <os2.h> /* PM header file */
16#include <os2wrap.h>
17#include <stdlib.h>
18#include <string.h>
19#include "win32type.h"
20#include <misc.h>
21#include <win32wbase.h>
22#include "wprocess.h"
23#include "pmframe.h"
24#include "oslibutil.h"
25#include "oslibwin.h"
26#include "caret.h"
27#include "oslibmsg.h"
28
29#define PMFRAMELOG
30
31//******************************************************************************
32//******************************************************************************
33VOID FrameTrackFrame(Win32BaseWindow *win32wnd,DWORD flags)
34{
35 WinSendMsg(win32wnd->getOS2FrameWindowHandle(),WM_TRACKFRAME,(MPARAM)flags,(MPARAM)0);
36}
37//******************************************************************************
38//******************************************************************************
39VOID FrameUpdateChildPositions(HWND hwnd)
40{
41 HENUM henum;
42 HWND hchild;
43 RECTL rectl;
44
45 henum = WinBeginEnumWindows(hwnd);
46 while ((hchild = WinGetNextWindow(henum)) != NULLHANDLE)
47 {
48 Win32BaseWindow *child = Win32BaseWindow::GetWindowFromOS2FrameHandle(hchild);
49
50 if (child)
51 {
52 WinQueryWindowRect(child->getOS2FrameWindowHandle(),&rectl);
53 mapOS2ToWin32Rect(child->getOS2FrameWindowHandle(),OSLIB_HWND_DESKTOP,(PRECTLOS2)&rectl,child->getWindowRect());
54 FrameUpdateChildPositions(child->getOS2WindowHandle());
55 }
56 }
57 WinEndEnumWindows(henum);
58}
59//******************************************************************************
60//Win32 frame message handler
61//******************************************************************************
62MRESULT EXPENTRY Win32FrameProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
63{
64 Win32BaseWindow *win32wnd;
65 PFNWP OldFrameProc;
66 MRESULT rc;
67 THDB *thdb;
68 MSG *pWinMsg,winMsg;
69
70 SetWin32TIB();
71
72 thdb = GetThreadTHDB();
73 win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
74
75 if (!thdb || (win32wnd == NULL) || !win32wnd->getOldFrameProc())
76 {
77 dprintf(("Invalid win32wnd pointer for frame %x!!", hwnd));
78 goto RunDefWndProc;
79 }
80
81 if((thdb->msgstate & 1) == 0)
82 {//message that was sent directly to our window proc handler; translate it here
83 QMSG qmsg;
84
85 qmsg.msg = msg;
86 qmsg.hwnd = hwnd;
87 qmsg.mp1 = mp1;
88 qmsg.mp2 = mp2;
89 qmsg.time = WinQueryMsgTime(thdb->hab);
90 WinQueryMsgPos(thdb->hab, &qmsg.ptl);
91 qmsg.reserved = 0;
92
93 if(OS2ToWinMsgTranslate((PVOID)thdb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
94 {//message was not translated
95 memset(&winMsg, 0, sizeof(MSG));
96 }
97 pWinMsg = &winMsg;
98 }
99 else {
100 pWinMsg = &thdb->msg;
101 thdb->msgstate++;
102 }
103
104 OldFrameProc = (PFNWP)win32wnd->getOldFrameProc();
105
106 switch(msg)
107 {
108 case WM_FORMATFRAME:
109 break;
110
111 case WM_MINMAXFRAME:
112 {
113 PSWP swp = (PSWP)mp1;
114
115 if (!win32wnd->IsWindowCreated()) goto RunDefFrameProc;
116 dprintf(("PMFRAME: WM_MINMAXFRAME %x",hwnd));
117 if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
118 {
119 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MINIMIZE_W) | WS_MAXIMIZE_W);
120
121 RECT rect;
122
123 rect.left = rect.top = rect.right = rect.bottom = 0;
124 win32wnd->AdjustMaximizedRect(&rect);
125 swp->x += rect.left;
126 swp->cx += rect.right-rect.left;
127 swp->y -= rect.bottom;
128 swp->cy += rect.bottom-rect.top;
129 }
130 else if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
131 {
132 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
133 }
134 else if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
135 {
136 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
137 }
138 goto RunDefFrameProc;
139 }
140
141 case WM_QUERYTRACKINFO:
142 {
143 PTRACKINFO trackInfo = (PTRACKINFO)mp2;
144
145 RestoreOS2TIB();
146 OldFrameProc(hwnd,msg,mp1,mp2);
147 SetWin32TIB();
148 trackInfo->cxBorder = 0;
149 trackInfo->cyBorder = 0;
150 win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
151 RestoreOS2TIB();
152 return (MRESULT)TRUE;
153 }
154
155 case WM_QUERYBORDERSIZE:
156 {
157 PWPOINT size = (PWPOINT)mp1;
158
159 size->x = 0;
160 size->y = 0;
161 RestoreOS2TIB();
162 return (MRESULT)TRUE;
163 }
164
165 case WM_BUTTON1DOWN:
166 case WM_BUTTON1UP:
167 case WM_BUTTON1DBLCLK:
168 case WM_BUTTON2DOWN:
169 case WM_BUTTON2UP:
170 case WM_BUTTON2DBLCLK:
171 case WM_BUTTON3DOWN:
172 case WM_BUTTON3UP:
173 case WM_BUTTON3DBLCLK:
174 {
175 if (win32wnd->IsWindowCreated())
176 {
177 win32wnd->MsgButton(pWinMsg);
178 RestoreOS2TIB();
179 }
180 return (MRESULT)TRUE;
181 }
182
183 case WM_BUTTON2MOTIONSTART:
184 case WM_BUTTON2MOTIONEND:
185 case WM_BUTTON2CLICK:
186 case WM_BUTTON1MOTIONSTART:
187 case WM_BUTTON1MOTIONEND:
188 case WM_BUTTON1CLICK:
189 case WM_BUTTON3MOTIONSTART:
190 case WM_BUTTON3MOTIONEND:
191 case WM_BUTTON3CLICK:
192 RestoreOS2TIB();
193 return (MRESULT)TRUE;
194
195 case WM_MOUSEMOVE:
196 {
197 //OS/2 Window coordinates -> Win32 Window coordinates
198 if (win32wnd->IsWindowCreated())
199 win32wnd->MsgMouseMove(pWinMsg);
200 RestoreOS2TIB();
201 return (MRESULT)TRUE;
202 }
203
204 case WM_PAINT:
205 {
206 dprintf(("PMFRAME: WM_PAINT"));
207 if (win32wnd->getStyle() & WS_MINIMIZE_W)
208 goto RunDefFrameProc;
209 if (win32wnd->IsWindowCreated())
210 win32wnd->MsgNCPaint();
211 goto RunDefWndProc;
212 }
213
214 case WM_SIZE:
215 dprintf(("PMFRAME: WM_SIZE"));
216 goto RunDefFrameProc;
217
218 case WM_ADJUSTWINDOWPOS:
219 {
220 PSWP pswp = (PSWP)mp1;
221 SWP swpOld;
222 WINDOWPOS wp,wpOld;
223 HWND hParent = NULLHANDLE, hwndAfter;
224
225 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));
226
227 //CB: show dialog in front of owner
228 if (win32wnd->IsModalDialogOwner())
229 {
230 pswp->fl |= SWP_ZORDER;
231 pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
232 if (pswp->fl & SWP_ACTIVATE)
233 {
234 pswp->fl &= ~SWP_ACTIVATE;
235 WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
236 }
237 }
238
239 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
240 goto RunDefFrameProc;
241
242 if(!win32wnd->CanReceiveSizeMsgs())
243 break;
244
245 WinQueryWindowPos(hwnd, &swpOld);
246 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
247 if (win32wnd->isChild()) {
248 if(win32wnd->getParent()) {
249 hParent = win32wnd->getParent()->getOS2WindowHandle();
250 }
251 else goto RunDefFrameProc;
252 }
253 }
254 hwndAfter = pswp->hwndInsertBehind;
255 OSLibMapSWPtoWINDOWPOSFrame(pswp, &wp, &swpOld, hParent, hwnd);
256
257 wp.hwnd = win32wnd->getWindowHandle();
258 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
259 {
260 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
261 if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
262 }
263
264 wpOld = wp;
265 win32wnd->MsgPosChanging((LPARAM)&wp);
266
267 if ((wp.hwndInsertAfter != wpOld.hwndInsertAfter) ||
268 (wp.x != wpOld.x) || (wp.y != wpOld.y) || (wp.cx != wpOld.cx) || (wp.cy != wpOld.cy) || (wp.flags != wpOld.flags))
269 {
270 dprintf(("PMFRAME: WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
271 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
272
273 OSLibMapWINDOWPOStoSWPFrame(&wp, pswp, &swpOld, hParent, hwnd);
274 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
275 pswp->fl |= SWP_NOADJUST;
276 pswp->hwndInsertBehind = hwndAfter;
277 pswp->hwnd = hwnd;
278
279 RestoreOS2TIB();
280 return (MRESULT)0xf;
281 }
282 goto RunDefFrameProc;
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.