source: trunk/src/user32/pmwindow.cpp@ 5280

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

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

File size: 47.7 KB
Line 
1/* $Id: pmwindow.cpp,v 1.120 2001-02-23 14:52:41 sandervl Exp $ */
2/*
3 * Win32 Window Managment Code for OS/2
4 *
5 * Copyright 1998-2000 Sander van Leeuwen (sandervl@xs4all.nl)
6 * Copyright 1999 Daniela Engert (dani@ngrt.de)
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12#define INCL_WIN
13#define INCL_GPI
14#define INCL_DEV /* Device Function definitions */
15#define INCL_GPICONTROL /* GPI control Functions */
16#define INCL_DOSPROCESS
17#define INCL_WINTRACKRECT
18
19#include <os2wrap.h>
20#include <stdlib.h>
21#include <string.h>
22#include <win32type.h>
23#include <win32api.h>
24#include <winconst.h>
25#include <winuser32.h>
26#include <wprocess.h>
27#include <misc.h>
28#include <win32wbase.h>
29#include <win32dlg.h>
30#include "win32wdesktop.h"
31#include "pmwindow.h"
32#include "oslibwin.h"
33#include "oslibutil.h"
34#include "oslibgdi.h"
35#include "oslibmsg.h"
36#include "dc.h"
37#include <thread.h>
38#include <wprocess.h>
39#include "caret.h"
40#include "timer.h"
41#include <codepage.h>
42
43#define DBG_LOCALLOG DBG_pmwindow
44#include "dbglocal.h"
45
46//define this to use the new code for WM_CALCVALIDRECT handling
47//#define USE_CALCVALIDRECT
48
49HMQ hmq = 0; /* Message queue handle */
50HAB hab = 0;
51
52RECTL desktopRectl = {0};
53ULONG ScreenWidth = 0;
54ULONG ScreenHeight = 0;
55ULONG ScreenBitsPerPel = 0;
56
57static PFNWP pfnFrameWndProc = NULL;
58
59MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
60MRESULT EXPENTRY Win32FrameWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
61MRESULT ProcessPMMessage(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2, Win32BaseWindow *win32wnd,
62 MSG *pWinMsg, TEB *teb, BOOL isFrame);
63
64//******************************************************************************
65//Initialize PM; create hab, message queue and register special Win32 window classes
66//******************************************************************************
67BOOL InitPM()
68{
69
70 hab = WinInitialize(0);
71 dprintf(("Winitialize returned %x", hab));
72 hmq = WinCreateMsgQueue(hab, 0);
73
74 if(!hab || !hmq)
75 {
76 UINT error;
77 //CB: only fail on real error
78 error = WinGetLastError(hab) & 0xFFFF; //error code
79 if (!hab || (error != PMERR_MSG_QUEUE_ALREADY_EXISTS))
80 {
81 dprintf(("WinInitialize or WinCreateMsgQueue failed %x %x", hab, hmq));
82 dprintf((" Error = %x",error));
83 return(FALSE);
84 }
85 else
86 {
87 if(!hab) {
88 hab = WinQueryAnchorBlock(HWND_DESKTOP);
89 dprintf(("WinQueryAnchorBlock returned %x", hab));
90 }
91 if(!hmq) {
92 hmq = HMQ_CURRENT;
93 }
94 }
95 }
96 SetThreadHAB(hab);
97 dprintf(("InitPM: hmq = %x", hmq));
98 SetThreadMessageQueue(hmq);
99
100 BOOL rc = WinSetCp(hmq, GetDisplayCodepage());
101 dprintf(("InitPM: WinSetCP was %sOK", rc ? "" : "not "));
102
103 if(!WinRegisterClass( /* Register window class */
104 hab, /* Anchor block handle */
105 (PSZ)WIN32_STDCLASS, /* Window class name */
106 (PFNWP)Win32WindowProc, /* Address of window procedure */
107 CS_HITTEST,
108 NROF_WIN32WNDBYTES))
109 {
110 dprintf(("WinRegisterClass Win32BaseWindow failed"));
111 return(FALSE);
112 }
113
114 CLASSINFO FrameClassInfo;
115 if(!WinQueryClassInfo (hab, WC_FRAME, &FrameClassInfo)) {
116 dprintf (("WinQueryClassInfo WC_FRAME failed"));
117 return (FALSE);
118 }
119 pfnFrameWndProc = FrameClassInfo.pfnWindowProc;
120
121 dprintf(("WC_FRAME style %x", FrameClassInfo.flClassStyle));
122
123 if(!WinRegisterClass( /* Register window class */
124 hab, /* Anchor block handle */
125 (PSZ)WIN32_STDFRAMECLASS, /* Window class name */
126 (PFNWP)Win32FrameWindowProc, /* Address of window procedure */
127 CS_HITTEST | CS_FRAME,
128 FrameClassInfo.cbWindowData+NROF_WIN32WNDBYTES))
129 {
130 dprintf(("WinRegisterClass Win32BaseWindow failed %x", WinGetLastError(hab)));
131 return(FALSE);
132 }
133
134 WinQueryWindowRect(HWND_DESKTOP, &desktopRectl);
135 ScreenWidth = desktopRectl.xRight;
136 ScreenHeight = desktopRectl.yTop;
137
138 HDC hdc; /* Device-context handle */
139 /* context data structure */
140 DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL,
141 NULL, NULL, NULL};
142
143 /* create memory device context */
144 hdc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
145 DevQueryCaps(hdc, CAPS_COLOR_BITCOUNT, 1, (PLONG)&ScreenBitsPerPel);
146 DevCloseDC(hdc);
147
148 dprintf(("InitPM: Desktop (%d,%d)", ScreenWidth, ScreenHeight));
149 return TRUE;
150} /* End of main */
151//******************************************************************************
152//Win32 window message handler
153//******************************************************************************
154MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
155{
156 Win32BaseWindow *win32wnd;
157 TEB *teb;
158 MSG winMsg, *pWinMsg;
159 MRESULT rc = 0;
160
161 //Restore our FS selector
162 SetWin32TIB();
163
164 //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- BEGIN
165 teb = GetThreadTEB();
166 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
167
168 if(!teb || (msg != WM_CREATE && win32wnd == NULL)) {
169 dprintf(("Invalid win32wnd pointer for window %x msg %x", hwnd, msg));
170 goto RunDefWndProc;
171 }
172//// if(teb->o.odin.fIgnoreMsgs) {
173//// goto RunDefWndProc;
174//// }
175
176 if((teb->o.odin.msgstate & 1) == 0)
177 {//message that was sent directly to our window proc handler; translate it here
178 QMSG qmsg;
179
180 qmsg.msg = msg;
181 qmsg.hwnd = hwnd;
182 qmsg.mp1 = mp1;
183 qmsg.mp2 = mp2;
184 qmsg.time = WinQueryMsgTime(teb->o.odin.hab);
185 WinQueryMsgPos(teb->o.odin.hab, &qmsg.ptl);
186 qmsg.reserved = 0;
187
188 if(OS2ToWinMsgTranslate((PVOID)teb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
189 {//message was not translated
190 memset(&winMsg, 0, sizeof(MSG));
191 }
192 pWinMsg = &winMsg;
193 }
194 else {
195 pWinMsg = &teb->o.odin.msg;
196 teb->o.odin.msgstate++;
197 }
198 //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- END
199 rc = ProcessPMMessage(hwnd, msg, mp1, mp2, win32wnd, pWinMsg, teb, FALSE);
200 RestoreOS2TIB();
201 return rc;
202
203RunDefWndProc:
204 RestoreOS2TIB();
205 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
206}
207//******************************************************************************
208//******************************************************************************
209MRESULT ProcessPMMessage(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2, Win32BaseWindow *win32wnd, MSG *pWinMsg, TEB *teb, BOOL isFrame)
210{
211 POSTMSG_PACKET *postmsg;
212 OSLIBPOINT point, ClientPoint;
213 MRESULT rc = 0;
214
215 if(msg == WIN32APP_POSTMSG) {
216 //probably win32 app user message
217 if((ULONG)mp1 == WIN32MSG_MAGICA) {
218 return (MRESULT)win32wnd->DispatchMsgA(pWinMsg);
219 }
220 else
221 if((ULONG)mp1 == WIN32MSG_MAGICW) {
222 return (MRESULT)win32wnd->DispatchMsgW(pWinMsg);
223 }
224 }
225 else
226 if(msg == WIN32APP_SETFOCUSMSG) {
227 //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
228 //must delay this function call
229 //mp1 = win32 window handle
230 //mp2 = activate flag
231 dprintf(("USER32: Delayed SetFocus %x call!", mp1));
232 teb->o.odin.hwndFocus = 0;
233 WinFocusChange(HWND_DESKTOP, hwnd, mp2 ? FC_NOLOSEACTIVE : 0);
234 }
235
236 switch( msg )
237 {
238 //OS/2 msgs
239 case WM_CREATE:
240 {
241 if(teb->o.odin.newWindow == 0)
242 goto createfail;
243
244 //Processing is done in after WinCreateWindow returns
245 dprintf(("OS2: WM_CREATE %x", hwnd));
246 win32wnd = (Win32BaseWindow *)teb->o.odin.newWindow;
247 teb->o.odin.newWindow = 0;
248 if(win32wnd->MsgCreate(hwnd) == FALSE)
249 {
250 return (MRESULT)TRUE; //discontinue window creation
251 }
252 createfail:
253 return (MRESULT)FALSE;
254 }
255
256 case WM_QUIT:
257 dprintf(("OS2: WM_QUIT %x", hwnd));
258 win32wnd->MsgQuit();
259 break;
260
261 case WM_CLOSE:
262 dprintf(("OS2: WM_CLOSE %x", hwnd));
263 win32wnd->MsgClose();
264 break;
265
266 case WM_DESTROY:
267 dprintf(("OS2: WM_DESTROY %x", hwnd));
268 win32wnd->MsgDestroy();
269 WinSetVisibleRegionNotify(hwnd, FALSE);
270 goto RunDefWndProc;
271
272 case WM_ENABLE:
273 dprintf(("OS2: WM_ENABLE %x", hwnd));
274 win32wnd->MsgEnable(SHORT1FROMMP(mp1));
275 break;
276
277 case WM_SHOW:
278 dprintf(("OS2: WM_SHOW %x %d", hwnd, mp1));
279 win32wnd->MsgShow((ULONG)mp1);
280 break;
281
282 case WM_ADJUSTWINDOWPOS:
283 {
284 PSWP pswp = (PSWP)mp1;
285 SWP swpOld;
286 WINDOWPOS wp,wpOld;
287 HWND hParent = NULLHANDLE, hwndAfter;
288
289 dprintf(("OS2: WM_ADJUSTWINDOWPOS %x %x %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
290
291 if(pswp->fl & SWP_NOADJUST) {
292 //ignore weird messages (TODO: why are they sent?)
293 break;
294 }
295 //CB: show dialog in front of owner
296 if (win32wnd->IsModalDialogOwner())
297 {
298 dprintf(("win32wnd->IsModalDialogOwner %x", win32wnd->getWindowHandle()));
299 pswp->fl |= SWP_ZORDER;
300 pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
301 if (pswp->fl & SWP_ACTIVATE)
302 {
303 pswp->fl &= ~SWP_ACTIVATE;
304 WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
305 }
306 }
307
308 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
309 goto RunDefWndProc;
310
311 if(!win32wnd->CanReceiveSizeMsgs())
312 break;
313
314 WinQueryWindowPos(hwnd, &swpOld);
315 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
316 if (win32wnd->isChild()) {
317 if(win32wnd->getParent()) {
318 hParent = win32wnd->getParent()->getOS2WindowHandle();
319 }
320 else goto RunDefWndProc;
321 }
322 }
323 hwndAfter = pswp->hwndInsertBehind;
324 if(win32wnd->getParent()) {
325 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getWindowHeight(),
326 win32wnd->getParent()->getClientRectPtr()->left,
327 win32wnd->getParent()->getClientRectPtr()->top,
328 hwnd);
329 }
330 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
331
332 wp.hwnd = win32wnd->getWindowHandle();
333 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
334 {
335 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
336 if(wndAfter) {
337 wp.hwndInsertAfter = wndAfter->getWindowHandle();
338 }
339 else wp.hwndInsertAfter = HWND_TOP_W;
340 }
341
342 wpOld = wp;
343 win32wnd->MsgPosChanging((LPARAM)&wp);
344
345 if ((wp.hwndInsertAfter != wpOld.hwndInsertAfter) ||
346 (wp.x != wpOld.x) || (wp.y != wpOld.y) || (wp.cx != wpOld.cx) || (wp.cy != wpOld.cy) || (wp.flags != wpOld.flags))
347 {
348 ULONG flags = pswp->fl; //make a backup copy; OSLibMapWINDOWPOStoSWP will modify it
349
350 dprintf(("OS2: WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
351 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
352
353 if(win32wnd->getParent()) {
354 OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, win32wnd->getParent()->getWindowHeight(),
355 win32wnd->getParent()->getClientRectPtr()->left,
356 win32wnd->getParent()->getClientRectPtr()->top,
357 hwnd);
358 }
359 else OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
360
361 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
362
363 //OSLibMapWINDOWPOStoSWP can add flags, but we must not let it remove flags!
364 if(pswp->fl & SWP_SIZE)
365 flags |= SWP_SIZE;
366
367 if(pswp->fl & SWP_MOVE)
368 flags |= SWP_MOVE;
369
370 pswp->fl = flags; //restore flags
371
372 pswp->fl |= SWP_NOADJUST;
373 pswp->hwndInsertBehind = hwndAfter;
374 pswp->hwnd = hwnd;
375
376 return (MRESULT)0xf;
377 }
378 return (MRESULT)0;
379 }
380
381 case WM_WINDOWPOSCHANGED:
382 {
383 PSWP pswp = (PSWP)mp1,pswpOld = pswp+1;
384 SWP swpOld = *(pswp + 1);
385 WINDOWPOS wp;
386 HWND hParent = NULLHANDLE;
387 RECTL rect;
388
389 dprintf(("OS2: WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
390
391 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
392 {
393 if(pswp->fl & SWP_ACTIVATE)
394 {
395 //Only send PM WM_ACTIVATE to top-level windows (frame windows)
396 if(!(WinQueryWindowULong(hwnd, OFFSET_WIN32FLAGS) & WINDOWFLAG_ACTIVE))
397 {
398 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)TRUE, (MPARAM)hwnd);
399 }
400 }
401 else
402 if(pswp->fl & SWP_DEACTIVATE)
403 {
404 //Only send PM WM_ACTIVATE to top-level windows (frame windows)
405 if(WinQueryWindowULong(hwnd, OFFSET_WIN32FLAGS) & WINDOWFLAG_ACTIVE)
406 {
407 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)FALSE, (MPARAM)hwnd);
408 }
409 }
410 goto RunDefWndProc;
411 }
412
413 if(pswp->fl & (SWP_MOVE | SWP_SIZE))
414 {
415 if(win32wnd->isChild())
416 {
417 if(win32wnd->getParent()) {
418 hParent = win32wnd->getParent()->getOS2WindowHandle();
419 }
420 else goto PosChangedEnd; //parent has just been destroyed
421 }
422 }
423
424
425 if(win32wnd->getParent()) {
426 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getWindowHeight(),
427 win32wnd->getParent()->getClientRectPtr()->left,
428 win32wnd->getParent()->getClientRectPtr()->top,
429 hwnd);
430 }
431 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
432
433 wp.hwnd = win32wnd->getWindowHandle();
434 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
435 {
436 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
437 if(wndAfter) {
438 wp.hwndInsertAfter = wndAfter->getWindowHandle();
439 }
440 else wp.hwndInsertAfter = HWND_TOP_W;
441 }
442
443#ifndef USE_CALCVALIDRECT
444 if((pswp->fl & (SWP_MOVE | SWP_SIZE)))
445 {
446 //CB: todo: use result for WM_CALCVALIDRECTS
447 //Get old client rectangle (for invalidation of frame window parts later on)
448 //Use new window height to calculate the client area
449 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
450
451 //Note: Also updates the new window rectangle
452 win32wnd->MsgFormatFrame(&wp);
453
454 if(win32wnd->CanReceiveSizeMsgs())
455 win32wnd->MsgPosChanged((LPARAM)&wp);
456
457 if((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
458 {
459 //redraw the frame (to prevent unnecessary client updates)
460 BOOL redrawAll = FALSE;
461
462 if (win32wnd->getWindowClass())
463 {
464 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
465
466 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
467 redrawAll = TRUE;
468 else
469 if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
470 redrawAll = TRUE;
471 }
472 else redrawAll = TRUE;
473
474 if(win32wnd->IsMixMaxStateChanging()) {
475 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
476 redrawAll = TRUE;
477 }
478
479 if (redrawAll)
480 {
481 //CB: redraw all children for now
482 // -> problems with update region if we don't do it
483 // todo: rewrite whole handling
484 WinInvalidateRect(hwnd,NULL,TRUE);
485 }
486 else
487 {
488 HPS hps = WinGetPS(hwnd);
489 RECTL frame,client,arcl[4];
490
491 WinQueryWindowRect(hwnd,&frame);
492
493 //top
494 arcl[0].xLeft = 0;
495 arcl[0].xRight = frame.xRight;
496 arcl[0].yBottom = rect.yTop;
497 arcl[0].yTop = frame.yTop;
498 //right
499 arcl[1].xLeft = rect.xRight;
500 arcl[1].xRight = frame.xRight;
501 arcl[1].yBottom = 0;
502 arcl[1].yTop = frame.yTop;
503 //left
504 arcl[2].xLeft = 0;
505 arcl[2].xRight = rect.xLeft;
506 arcl[2].yBottom = 0;
507 arcl[2].yTop = frame.yTop;
508 //bottom
509 arcl[3].xLeft = 0;
510 arcl[3].xRight = frame.xRight;
511 arcl[3].yBottom = 0;
512 arcl[3].yTop = rect.yBottom;
513
514 HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
515
516 WinInvalidateRegion(hwnd,hrgn,FALSE);
517 GpiDestroyRegion(hps,hrgn);
518 WinReleasePS(hps);
519 }
520 }
521 }
522 else
523 {
524#endif //USE_CALCVALIDRECT
525 if(win32wnd->CanReceiveSizeMsgs())
526 win32wnd->MsgPosChanged((LPARAM)&wp);
527#ifndef USE_CALCVALIDRECT
528 }
529#endif
530
531 if(pswp->fl & SWP_ACTIVATE)
532 {
533 //Only send PM WM_ACTIVATE to top-level windows (frame windows)
534 if(!(WinQueryWindowULong(hwnd, OFFSET_WIN32FLAGS) & WINDOWFLAG_ACTIVE))
535 {
536 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)TRUE, (MPARAM)hwnd);
537 }
538 }
539 else
540 if(pswp->fl & SWP_DEACTIVATE)
541 {
542 //Only send PM WM_ACTIVATE to top-level windows (frame windows)
543 if(WinQueryWindowULong(hwnd, OFFSET_WIN32FLAGS) & WINDOWFLAG_ACTIVE)
544 {
545 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)FALSE, (MPARAM)hwnd);
546 }
547 }
548
549PosChangedEnd:
550 return (MRESULT)FALSE;
551 }
552
553 case WM_ACTIVATE:
554 {
555 ULONG flags = WinQueryWindowULong(hwnd, OFFSET_WIN32FLAGS);
556
557 dprintf(("OS2: WM_ACTIVATE %x %x %x", hwnd, mp1, mp2));
558
559 WinSetWindowULong(hwnd, OFFSET_WIN32FLAGS, SHORT1FROMMP(mp1) ? (flags | WINDOWFLAG_ACTIVE):(flags & ~WINDOWFLAG_ACTIVE));
560 if(win32wnd->IsWindowCreated())
561 {
562 win32wnd->MsgActivate((LOWORD(pWinMsg->wParam) == WA_ACTIVE_W) ? 1 : 0, HIWORD(pWinMsg->wParam), pWinMsg->lParam, (HWND)mp2);
563
564 //CB: show owner behind the dialog
565 if(win32wnd->IsModalDialog())
566 {
567 Win32BaseWindow *topOwner = win32wnd->getOwner()->GetTopParent();
568
569 if(topOwner) WinSetWindowPos(topOwner->getOS2WindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
570 }
571 }
572 return 0;
573 }
574
575 case WM_SIZE:
576 {
577 dprintf(("OS2: WM_SIZE (%d,%d) (%d,%d)", SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), SHORT1FROMMP(mp1), SHORT2FROMMP(mp2)));
578 goto RunDefWndProc;
579 }
580
581 case WM_CALCVALIDRECTS:
582#ifdef USE_CALCVALIDRECT
583 {
584 PRECTL oldRect = (PRECTL)mp1, newRect = oldRect+1;
585 PSWP pswp = (PSWP)mp2;
586 SWP swpOld;
587 WINDOWPOS wp;
588 RECTL newClientRect, oldClientRect;
589 ULONG nccalcret;
590// UINT res = CVR_ALIGNLEFT | CVR_ALIGNTOP;
591 UINT res = 0;
592
593 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
594
595 //Get old position info
596 WinQueryWindowPos(hwnd, &swpOld);
597
598 if(win32wnd->getParent()) {
599 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getWindowHeight(),
600 win32wnd->getParent()->getClientRectPtr()->left,
601 win32wnd->getParent()->getClientRectPtr()->top,
602 hwnd);
603 }
604 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
605
606 wp.hwnd = win32wnd->getWindowHandle();
607 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
608 {
609 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
610 if(wndAfter) {
611 wp.hwndInsertAfter = wndAfter->getWindowHandle();
612 }
613 else wp.hwndInsertAfter = HWND_TOP_W;
614 }
615
616 //Get old client rectangle
617 mapWin32ToOS2Rect(oldRect->yTop - oldRect->yBottom, win32wnd->getClientRectPtr(), (PRECTLOS2)&oldClientRect);
618
619 //Note: Also updates the new window rectangle
620 nccalcret = win32wnd->MsgFormatFrame(&wp);
621
622 //Get new client rectangle
623 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&newClientRect);
624
625 if(nccalcret == 0) {
626 res = CVR_ALIGNTOP | CVR_ALIGNLEFT;
627 }
628 else {
629 if(nccalcret & WVR_ALIGNTOP_W) {
630 res |= CVR_ALIGNTOP;
631 }
632 else
633 if(nccalcret & WVR_ALIGNBOTTOM_W) {
634 res |= CVR_ALIGNBOTTOM;
635 }
636
637 if(nccalcret & WVR_ALIGNLEFT_W) {
638 res |= CVR_ALIGNLEFT;
639 }
640 else
641 if(nccalcret & WVR_ALIGNRIGHT_W) {
642 res |= CVR_ALIGNRIGHT;
643 }
644
645 if(nccalcret & WVR_REDRAW_W) {//WVR_REDRAW_W = (WVR_HREDRAW | WVR_VREDRAW)
646 res |= CVR_REDRAW;
647 }
648 else
649 if(nccalcret & WVR_VALIDRECTS_W) {
650 //TODO:
651 //res = 0;
652 }
653 }
654 if(win32wnd->IsMixMaxStateChanging()) {
655 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
656 res |= CVR_REDRAW;
657 }
658 if(res == (CVR_ALIGNTOP|CVR_ALIGNLEFT)) {
659 oldRect->xRight -= oldClientRect.xLeft;
660 oldRect->yBottom += oldClientRect.yBottom;
661 newRect->xRight -= newClientRect.xLeft;
662 newRect->yBottom += newClientRect.yBottom;
663 }
664
665#if 0
666 if((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
667 {
668 //redraw the frame (to prevent unnecessary client updates)
669 BOOL redrawAll = FALSE;
670
671 if (win32wnd->getWindowClass())
672 {
673 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
674
675 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
676 redrawAll = TRUE;
677 else
678 if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
679 redrawAll = TRUE;
680 }
681 else redrawAll = TRUE;
682
683 if (redrawAll)
684 {
685 //CB: redraw all children for now
686 // -> problems with update region if we don't do it
687 // todo: rewrite whole handling
688 WinInvalidateRect(hwnd,NULL,TRUE);
689 }
690 else
691 {
692 HPS hps = WinGetPS(hwnd);
693 RECTL frame,client,arcl[4];
694
695 WinQueryWindowRect(hwnd,&frame);
696
697 //top
698 arcl[0].xLeft = 0;
699 arcl[0].xRight = frame.xRight;
700 arcl[0].yBottom = rect.yTop;
701 arcl[0].yTop = frame.yTop;
702 //right
703 arcl[1].xLeft = rect.xRight;
704 arcl[1].xRight = frame.xRight;
705 arcl[1].yBottom = 0;
706 arcl[1].yTop = frame.yTop;
707 //left
708 arcl[2].xLeft = 0;
709 arcl[2].xRight = rect.xLeft;
710 arcl[2].yBottom = 0;
711 arcl[2].yTop = frame.yTop;
712 //bottom
713 arcl[3].xLeft = 0;
714 arcl[3].xRight = frame.xRight;
715 arcl[3].yBottom = 0;
716 arcl[3].yTop = rect.yBottom;
717
718 HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
719
720 WinInvalidateRegion(hwnd,hrgn,FALSE);
721 GpiDestroyRegion(hps,hrgn);
722 WinReleasePS(hps);
723 }
724 }
725
726 }
727#endif
728
729 return (MRESULT)res;
730 }
731#else
732 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
733 return (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
734#endif
735
736 case WM_VRNENABLED:
737 dprintf(("OS2: WM_VRNENABLED %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
738 if(!win32wnd->isComingToTop() && ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == WS_EX_TOPMOST_W))
739 {
740 HWND hwndrelated;
741 Win32BaseWindow *topwindow;
742
743 win32wnd->setComingToTop(TRUE);
744
745 hwndrelated = WinQueryWindow(hwnd, QW_PREV);
746 dprintf(("WM_VRNENABLED hwndrelated = %x (hwnd=%x)", hwndrelated, hwnd));
747 topwindow = Win32BaseWindow::GetWindowFromOS2Handle(hwndrelated);
748 if(topwindow == NULL || ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == 0)) {
749 //put window at the top of z order
750 WinSetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER );
751 }
752
753 win32wnd->setComingToTop(FALSE);
754 break;
755 }
756 //Restore window origin of window with CS_OWNDC style
757 //(fixes paint offset problems in Opera windows)
758 if(win32wnd->isOwnDC()) {
759 dprintfOrigin(win32wnd->getOwnDC());
760 selectClientArea(win32wnd, win32wnd->getOwnDC());
761 }
762 goto RunDefWndProc;
763
764 case WM_VRNDISABLED:
765 dprintf(("OS2: WM_VRNDISABLED %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
766 if(win32wnd->isOwnDC()) {
767 dprintfOrigin(win32wnd->getOwnDC());
768 }
769 goto RunDefWndProc;
770
771 case WM_SETFOCUS:
772 {
773 HWND hwndFocus = (HWND)mp1;
774
775 dprintf(("OS2: WM_SETFOCUS %x %x (%x) %d", win32wnd->getWindowHandle(), mp1, OS2ToWin32Handle(hwndFocus), mp2));
776
777 //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
778 //must delay this function call
779
780 teb->o.odin.fWM_SETFOCUS = TRUE;
781 teb->o.odin.hwndFocus = 0;
782 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
783 //another (non-win32) application's window
784 //set to NULL (allowed according to win32 SDK) to avoid problems
785 hwndFocus = NULL;
786 }
787 if((ULONG)mp2 == TRUE) {
788 HWND hwndFocusWin32 = OS2ToWin32Handle(hwndFocus);
789 recreateCaret (hwndFocusWin32);
790 win32wnd->MsgSetFocus(hwndFocusWin32);
791 }
792 else win32wnd->MsgKillFocus(OS2ToWin32Handle(hwndFocus));
793 teb->o.odin.fWM_SETFOCUS = FALSE;
794
795 break;
796 }
797
798#if 0
799 //is sent to both windows gaining and loosing the focus
800 case WM_FOCUSCHANGE:
801 {
802 HWND hwndFocus = (HWND)mp1;
803 HWND hwndLoseFocus, hwndGainFocus;
804 USHORT usSetFocus = SHORT1FROMMP(mp2);
805 USHORT fsFocusChange = SHORT2FROMMP(mp2);
806
807 rc = 0;
808 dprintf(("OS2: WM_FOCUSCHANGE (start) %x %x %x %x", win32wnd->getWindowHandle(), hwndFocus, usSetFocus, fsFocusChange));
809 if(usSetFocus) {
810 hwndGainFocus = hwnd;
811 hwndLoseFocus = hwndFocus;
812 }
813 else {
814 hwndGainFocus = hwndFocus;
815 hwndLoseFocus = hwnd;
816 }
817
818 if(usSetFocus)
819 {
820 Win32BaseWindow *winfocus = Win32BaseWindow::GetWindowFromOS2Handle(hwndLoseFocus);
821 if(!(fsFocusChange & FC_NOSETACTIVE))
822 {
823 if(!winfocus || (winfocus->GetTopParent() != win32wnd->GetTopParent()))
824 {
825 if(winfocus)
826 WinSendMsg(winfocus->GetTopParent()->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)0, (MPARAM)hwndGainFocus);
827 else
828 WinSendMsg(hwndLoseFocus, WM_ACTIVATE, (MPARAM)0, (MPARAM)hwndGainFocus);
829 }
830 }
831 //SvL: Check if window is still valid
832 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
833 if(win32wnd == NULL)
834 return (MRESULT)rc;
835
836 if(!(fsFocusChange & FC_NOSETACTIVE))
837 {
838 Win32BaseWindow *topparent = win32wnd->GetTopParent();
839 if(!winfocus || (winfocus->GetTopParent() != topparent))
840 {
841 if(!(fsFocusChange & FC_NOBRINGTOTOP))
842 {
843 if(topparent) {
844 //put window at the top of z order
845 WinSetWindowPos(topparent->getOS2WindowHandle(), HWND_TOP, 0, 0, 0, 0, SWP_ZORDER);
846 }
847 }
848
849 // PH 2000/09/01 Netscape 4.7
850 // check if topparent is valid
851 if (topparent)
852 WinSendMsg(topparent->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)1, (MPARAM)hwndLoseFocus);
853 }
854 }
855 //SvL: Check if window is still valid
856 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
857 if(win32wnd == NULL)
858 return (MRESULT)rc;
859
860 //TODO: Don't send WM_SETSELECTION to child window if frame already has selection
861 if(!(fsFocusChange & FC_NOSETSELECTION)) {
862 WinSendMsg(hwndGainFocus, WM_SETSELECTION, (MPARAM)1, (MPARAM)0);
863 }
864
865 if(!(fsFocusChange & FC_NOSETFOCUS)) {
866 WinSendMsg(hwndGainFocus, WM_SETFOCUS, (MPARAM)hwndLoseFocus, (MPARAM)1);
867 }
868 }
869 else /* no usSetFocus */
870 {
871 if(!(fsFocusChange & FC_NOLOSEFOCUS)) {
872 WinSendMsg(hwndLoseFocus, WM_SETFOCUS, (MPARAM)hwndGainFocus, (MPARAM)0);
873 }
874 //TODO: Don't send WM_SETSELECTION to child window if frame already has selection
875 if(!(fsFocusChange & FC_NOLOSESELECTION)) {
876 WinSendMsg(hwndLoseFocus, WM_SETSELECTION, (MPARAM)0, (MPARAM)0);
877 }
878 //SvL: Check if window is still valid
879 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
880 if(win32wnd == NULL) {
881 return (MRESULT)rc;
882 }
883
884 Win32BaseWindow *winfocus = Win32BaseWindow::GetWindowFromOS2Handle(hwndGainFocus);
885 if(!(fsFocusChange & FC_NOLOSEACTIVE))
886 {
887 Win32BaseWindow *topparent = win32wnd->GetTopParent();
888
889 if(!winfocus || (winfocus->GetTopParent() != topparent))
890 {
891 // PH 2000/09/01 Netscape 4.7
892 // check if topparent is valid
893 if (topparent)
894 WinSendMsg(topparent->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)0, (MPARAM)hwndGainFocus);
895 }
896 }
897 //SvL: Check if window is still valid
898 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
899 if(win32wnd == NULL)
900 return (MRESULT)rc;
901
902 if(!(fsFocusChange & FC_NOSETACTIVE))
903 {
904 if(!winfocus || (winfocus->GetTopParent() != win32wnd->GetTopParent()))
905 {
906 if(winfocus)
907 {
908 // PH 2000/09/01 Netscape 4.7
909 // check if topparent is valid
910 Win32BaseWindow *topparent = winfocus->GetTopParent();
911 if (topparent)
912 WinSendMsg(topparent->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)1, (MPARAM)hwndLoseFocus);
913 }
914 else
915 WinSendMsg(hwndGainFocus, WM_ACTIVATE, (MPARAM)1, (MPARAM)hwndLoseFocus);
916 }
917 }
918 }
919
920
921#ifdef DEBUG
922 SetWin32TIB();
923 dprintf(("OS2: WM_FOCUSCHANGE (end) %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
924#endif
925 return (MRESULT)rc;
926 }
927#endif
928
929 //**************************************************************************
930 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
931 //**************************************************************************
932 case WM_HITTEST:
933 {
934 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
935 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
936 }
937 if(win32wnd && win32wnd->IsWindowCreated())
938 {
939 MRESULT rc;
940
941 rc = (MRESULT)win32wnd->MsgHitTest(pWinMsg);
942 return rc;
943 }
944 return (MRESULT)HT_NORMAL;
945 }
946
947 case WM_BUTTON1DOWN:
948 case WM_BUTTON1UP:
949 case WM_BUTTON1DBLCLK:
950 case WM_BUTTON2DOWN:
951 case WM_BUTTON2UP:
952 case WM_BUTTON2DBLCLK:
953 case WM_BUTTON3DOWN:
954 case WM_BUTTON3UP:
955 case WM_BUTTON3DBLCLK:
956 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
957 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
958 }
959 if(win32wnd)
960 win32wnd->MsgButton(pWinMsg);
961
962 rc = (MRESULT)TRUE;
963 break;
964
965 case WM_BUTTON2MOTIONSTART:
966 case WM_BUTTON2MOTIONEND:
967 case WM_BUTTON2CLICK:
968 case WM_BUTTON1MOTIONSTART:
969 case WM_BUTTON1MOTIONEND:
970 case WM_BUTTON1CLICK:
971 case WM_BUTTON3MOTIONSTART:
972 case WM_BUTTON3MOTIONEND:
973 case WM_BUTTON3CLICK:
974 rc = (MRESULT)TRUE;
975 break;
976
977 case WM_MOUSEMOVE:
978 {
979 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
980 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
981 }
982 if(win32wnd)
983 win32wnd->MsgMouseMove(pWinMsg);
984 break;
985 }
986
987 case WM_CONTROL:
988 goto RunDefWndProc;
989
990 case WM_COMMAND:
991 dprintf(("OS2: WM_COMMAND %x %x %x", hwnd, mp1, mp2));
992 win32wnd->DispatchMsgA(pWinMsg);
993 break;
994
995 case WM_SYSCOMMAND:
996 win32wnd->DispatchMsgA(pWinMsg);
997 break;
998
999 case WM_RENDERFMT:
1000 case WM_RENDERALLFMTS:
1001 case WM_DESTROYCLIPBOARD:
1002 win32wnd->DispatchMsgA(pWinMsg);
1003 break;
1004
1005 case WM_CHAR:
1006 win32wnd->MsgChar(pWinMsg);
1007 break;
1008
1009 case WM_TIMER:
1010 win32wnd->DispatchMsgA(pWinMsg);
1011 goto RunDefWndProc;
1012
1013 case WM_SETWINDOWPARAMS:
1014 {
1015 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
1016
1017 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
1018 if(wndParams->fsStatus & WPM_TEXT) {
1019 win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText);
1020 }
1021 goto RunDefWndProc;
1022 }
1023
1024 case WM_QUERYWINDOWPARAMS:
1025 {
1026 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
1027 ULONG textlen;
1028 PSZ wintext;
1029
1030 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
1031 {
1032 if(wndpars->fsStatus & WPM_TEXT)
1033 win32wnd->MsgGetText(wndpars->pszText, wndpars->cchText);
1034 if(wndpars->fsStatus & WPM_CCHTEXT)
1035 wndpars->cchText = win32wnd->MsgGetTextLength();
1036
1037 wndpars->fsStatus = 0;
1038 wndpars->cbCtlData = 0;
1039 wndpars->cbPresParams = 0;
1040 return (MRESULT)TRUE;
1041 }
1042 goto RunDefWndProc;
1043 }
1044
1045 case WM_PAINT:
1046 {
1047 RECTL rectl;
1048 BOOL rc;
1049
1050 rc = WinQueryUpdateRect(hwnd, &rectl);
1051 dprintf(("OS2: WM_PAINT %x (%d,%d) (%d,%d) rc=%d", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop, rc));
1052
1053 if(rc && win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
1054 rectl.yBottom != rectl.yTop))
1055 {
1056 PRECT pClient = win32wnd->getClientRectPtr();
1057 PRECT pWindow = win32wnd->getWindowRect();
1058
1059 if(!(pClient->left == 0 && pClient->top == 0 &&
1060 win32wnd->getClientHeight() == win32wnd->getWindowHeight() &&
1061 win32wnd->getClientWidth() == win32wnd->getWindowWidth()))
1062 {
1063 win32wnd->MsgNCPaint();
1064 }
1065 win32wnd->DispatchMsgA(pWinMsg);
1066 }
1067 else goto RunDefWndProc;
1068
1069 //SvL: Not calling the default window procedure causes all sorts of
1070 // strange problems (redraw & hanging app)
1071 // -> check what WinBeginPaint does what we're forgetting in BeginPaint
1072// WinQueryUpdateRect(hwnd, &rectl);
1073// if(rectl.xLeft == 0 && rectl.yTop == 0 && rectl.xRight == 0 && rectl.yBottom == 0) {
1074// RestoreOS2TIB();
1075// return (MRESULT)FALSE;
1076// }
1077// dprintf(("Update rectangle (%d,%d)(%d,%d) not empty, msg %x", rectl.xLeft, rectl.yTop, rectl.xRight, rectl.yBottom, pWinMsg->message));
1078// goto RunDefWndProc;
1079 break;
1080 }
1081
1082 case WM_ERASEBACKGROUND:
1083 {
1084 dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
1085 return (MRESULT)FALSE;
1086 }
1087
1088#if 0
1089 case WM_CONTEXTMENU:
1090 {
1091 win32wnd->DispatchMsgA(pWinMsg);
1092
1093 return (MRESULT)TRUE;
1094 }
1095#endif
1096
1097 case WM_QUERYTRACKINFO:
1098 {
1099 PTRACKINFO trackInfo = (PTRACKINFO)mp2;
1100
1101 dprintf(("OS2: WM_QUERYTRACKINFO %x", win32wnd->getWindowHandle()));
1102 trackInfo->cxBorder = 4;
1103 trackInfo->cyBorder = 4;
1104 win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
1105 return (MRESULT)TRUE;
1106 }
1107
1108 case WM_QUERYBORDERSIZE:
1109 {
1110 PWPOINT size = (PWPOINT)mp1;
1111
1112 dprintf(("OS2: WM_QUERYBORDERSIZE %x", win32wnd->getWindowHandle()));
1113
1114 size->x = 0;
1115 size->y = 0;
1116 return (MRESULT)TRUE;
1117 }
1118
1119 case WM_REALIZEPALETTE:
1120 {
1121 dprintf(("OS2: WM_REALIZEPALETTE"));
1122 goto RunDefWndProc;
1123 }
1124
1125 case WM_OWNERPOSCHANGE:
1126 {
1127 dprintf(("OS2: WM_OWNERPOSCHANGE"));
1128 goto RunDefWndProc;
1129 }
1130
1131 case WM_INITMENU:
1132 case WM_MENUSELECT:
1133 case WM_MENUEND:
1134 case WM_NEXTMENU:
1135 case WM_SYSCOLORCHANGE:
1136 case WM_SYSVALUECHANGED:
1137 case WM_SETSELECTION:
1138 case WM_PPAINT:
1139 case WM_PSETFOCUS:
1140 case WM_PSYSCOLORCHANGE:
1141 case WM_PSIZE:
1142 case WM_PACTIVATE:
1143 case WM_PCONTROL:
1144 case WM_HELP:
1145 case WM_APPTERMINATENOTIFY:
1146 case WM_PRESPARAMCHANGED:
1147 case WM_DRAWITEM:
1148 case WM_MEASUREITEM:
1149 case WM_CONTROLPOINTER:
1150 case WM_QUERYDLGCODE:
1151 case WM_SUBSTITUTESTRING:
1152 case WM_MATCHMNEMONIC:
1153 case WM_SAVEAPPLICATION:
1154 case WM_SEMANTICEVENT:
1155 default:
1156 dprintf2(("OS2: RunDefWndProc hwnd %x msg %x mp1 %x mp2 %x", hwnd, msg, mp1, mp2));
1157 RestoreOS2TIB();
1158 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
1159 }
1160 return (MRESULT)rc;
1161
1162RunDefWndProc:
1163// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
1164 RestoreOS2TIB();
1165 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
1166} /* End of Win32WindowProc */
1167//******************************************************************************
1168//******************************************************************************
1169MRESULT EXPENTRY Win32FrameWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1170{
1171 POSTMSG_PACKET *postmsg;
1172 OSLIBPOINT point, ClientPoint;
1173 Win32BaseWindow *win32wnd;
1174 TEB *teb;
1175 MRESULT rc = 0;
1176 MSG winMsg, *pWinMsg;
1177
1178 //Restore our FS selector
1179 SetWin32TIB();
1180
1181 //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- BEGIN
1182 teb = GetThreadTEB();
1183 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
1184
1185 if(!teb || (msg != WM_CREATE && win32wnd == NULL)) {
1186 dprintf(("Invalid win32wnd pointer for window %x msg %x", hwnd, msg));
1187 goto RunDefFrameWndProc;
1188 }
1189//// if(teb->o.odin.fIgnoreMsgs) {
1190//// goto RunDefWndProc;
1191//// }
1192
1193 if((teb->o.odin.msgstate & 1) == 0)
1194 {//message that was sent directly to our window proc handler; translate it here
1195 QMSG qmsg;
1196
1197 qmsg.msg = msg;
1198 qmsg.hwnd = hwnd;
1199 qmsg.mp1 = mp1;
1200 qmsg.mp2 = mp2;
1201 qmsg.time = WinQueryMsgTime(teb->o.odin.hab);
1202 WinQueryMsgPos(teb->o.odin.hab, &qmsg.ptl);
1203 qmsg.reserved = 0;
1204
1205 if(OS2ToWinMsgTranslate((PVOID)teb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
1206 {//message was not translated
1207 memset(&winMsg, 0, sizeof(MSG));
1208 }
1209 pWinMsg = &winMsg;
1210 }
1211 else {
1212 pWinMsg = &teb->o.odin.msg;
1213 teb->o.odin.msgstate++;
1214 }
1215 //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- END
1216
1217 switch( msg )
1218 {
1219 case WM_CREATE:
1220 {
1221 RestoreOS2TIB();
1222 pfnFrameWndProc(hwnd, msg, mp1, mp2);
1223 SetWin32TIB();
1224 rc = ProcessPMMessage(hwnd, msg, mp1, mp2, win32wnd, pWinMsg, teb, TRUE);
1225 break;
1226 }
1227
1228 case WM_CALCFRAMERECT:
1229 dprintf(("OS2: WM_CALCFRAMERECT %x", win32wnd->getWindowHandle()));
1230 rc = (MRESULT)TRUE;
1231 break;
1232
1233 case WM_QUERYCTLTYPE:
1234 // This is a frame window
1235 dprintf(("OS2: WM_QUERYCTLTYPE %x", win32wnd->getWindowHandle()));
1236 rc = (MRESULT)CCT_FRAME;
1237 break;
1238
1239 case WM_QUERYFOCUSCHAIN:
1240 dprintf(("OS2: WM_QUERYFOCUSCHAIN %x", win32wnd->getWindowHandle()));
1241 goto RunDefFrameWndProc;
1242
1243 case WM_FOCUSCHANGE:
1244 {
1245 HWND hwndFocus = (HWND)mp1;
1246 HWND hwndLoseFocus, hwndGainFocus;
1247 USHORT usSetFocus = SHORT1FROMMP(mp2);
1248 USHORT fsFocusChange = SHORT2FROMMP(mp2);
1249
1250 dprintf(("OS2: WM_FOCUSCHANGE %x %x %x %x", win32wnd->getWindowHandle(), hwndFocus, usSetFocus, fsFocusChange));
1251 goto RunDefFrameWndProc;
1252 }
1253
1254 case WM_ACTIVATE:
1255 case WM_SETFOCUS:
1256 {
1257 rc = ProcessPMMessage(hwnd, msg, mp1, mp2, win32wnd, pWinMsg, teb, TRUE);
1258 goto RunDefFrameWndProc;
1259 }
1260
1261#if 0
1262//just a test
1263 case WM_ADJUSTWINDOWPOS:
1264 case WM_WINDOWPOSCHANGED:
1265 {
1266 rc = ProcessPMMessage(hwnd, msg, mp1, mp2, win32wnd, pWinMsg, teb, TRUE);
1267 goto RunDefFrameWndProc;
1268 }
1269#endif
1270
1271 case WM_QUERYFRAMEINFO:
1272 dprintf(("OS2: WM_QUERYFRAMEINFO %x", win32wnd->getWindowHandle()));
1273 goto RunDefFrameWndProc;
1274
1275 case WM_FORMATFRAME:
1276 dprintf(("OS2: WM_FORMATFRAME %x", win32wnd->getWindowHandle()));
1277 goto RunDefFrameWndProc;
1278
1279 case WM_ADJUSTFRAMEPOS:
1280 {
1281 PSWP pswp = (PSWP)mp1;
1282
1283 dprintf(("OS2: WM_ADJUSTFRAMEPOS %x %x %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
1284 goto RunDefFrameWndProc;
1285 }
1286
1287 case WM_MINMAXFRAME:
1288 {
1289 PSWP swp = (PSWP)mp1;
1290
1291 if (!win32wnd->IsWindowCreated()) goto RunDefWndProc;
1292
1293 dprintf(("OS2: WM_MINMAXFRAME %x",hwnd));
1294 if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
1295 {
1296 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MINIMIZE_W) | WS_MAXIMIZE_W);
1297
1298 RECT rect;
1299
1300 rect.left = rect.top = rect.right = rect.bottom = 0;
1301 win32wnd->AdjustMaximizedRect(&rect);
1302 swp->x += rect.left;
1303 swp->cx += rect.right-rect.left;
1304 swp->y -= rect.bottom;
1305 swp->cy += rect.bottom-rect.top;
1306 }
1307 else
1308 if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
1309 {
1310 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
1311 }
1312 else
1313 if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
1314 {
1315 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
1316 }
1317 goto RunDefWndProc;
1318 }
1319
1320 case WM_UPDATEFRAME:
1321 dprintf(("OS2: WM_UPDATEFRAME %x", win32wnd->getWindowHandle()));
1322 goto RunDefFrameWndProc;
1323
1324 default:
1325 rc = ProcessPMMessage(hwnd, msg, mp1, mp2, win32wnd, pWinMsg, teb, TRUE);
1326 break;
1327 }
1328 RestoreOS2TIB();
1329 return (MRESULT)rc;
1330
1331RunDefFrameWndProc:
1332 RestoreOS2TIB();
1333 return pfnFrameWndProc(hwnd, msg, mp1, mp2);
1334
1335RunDefWndProc:
1336 RestoreOS2TIB();
1337 return Win32WindowProc(hwnd, msg, mp1, mp2);
1338}
1339//******************************************************************************
1340//TODO: Quickly moving a window two times doesn't force a repaint (1st time)
1341//******************************************************************************
1342VOID FrameTrackFrame(Win32BaseWindow *win32wnd,DWORD flags)
1343{
1344 TRACKINFO track;
1345 RECTL rcl;
1346 PRECT pWindowRect, pClientRect;
1347 HWND hwndTracking;
1348 HPS hpsTrack;
1349 LONG parentHeight, parentWidth;
1350
1351 dprintf(("FrameTrackFrame: %x %x", win32wnd->getWindowHandle(), flags));
1352 track.cxBorder = 4;
1353 track.cyBorder = 4; /* 4 pel wide lines used for rectangle */
1354 track.cxGrid = 1;
1355 track.cyGrid = 1; /* smooth tracking with mouse */
1356 track.cxKeyboard = 8;
1357 track.cyKeyboard = 8; /* faster tracking using cursor keys */
1358
1359 pWindowRect = win32wnd->getWindowRect();
1360 if(win32wnd->getParent()) {
1361 parentHeight = win32wnd->getParent()->getWindowHeight();
1362 parentWidth = win32wnd->getParent()->getWindowWidth();
1363 hwndTracking = win32wnd->getParent()->getOS2WindowHandle();
1364 hpsTrack = WinGetPS(hwndTracking);
1365 }
1366 else {
1367 parentHeight = OSLibQueryScreenHeight();
1368 parentWidth = OSLibQueryScreenWidth();
1369 hwndTracking = HWND_DESKTOP;
1370 hpsTrack = NULL;
1371 }
1372
1373 mapWin32ToOS2Rect(parentHeight, pWindowRect, (PRECTLOS2)&track.rclTrack);
1374 WinQueryWindowRect(hwndTracking, &track.rclBoundary);
1375
1376 track.ptlMinTrackSize.x = 10;
1377 track.ptlMinTrackSize.y = 10; /* set smallest allowed size of rectangle */
1378 track.ptlMaxTrackSize.x = parentWidth;
1379 track.ptlMaxTrackSize.y = parentHeight; /* set largest allowed size of rectangle */
1380
1381 win32wnd->AdjustTrackInfo((PPOINT)&track.ptlMinTrackSize, (PPOINT)&track.ptlMaxTrackSize);
1382
1383 track.fs = flags;
1384
1385 if(WinTrackRect(hwndTracking, NULL, &track) )
1386 {
1387 if(hpsTrack) WinReleasePS(hpsTrack);
1388
1389 /* if successful copy final position back */
1390 if(!WinEqualRect(0, &rcl, &track.rclTrack)) {
1391 dprintf(("FrameTrackFrame: new (os/2) window rect: (%d,%d)(%d,%d)", track.rclTrack.xLeft, track.rclTrack.yBottom, track.rclTrack.xRight - track.rclTrack.xLeft, track.rclTrack.yTop - track.rclTrack.yBottom));
1392 if(flags == TF_MOVE) {
1393 WinSetWindowPos(win32wnd->getOS2WindowHandle(),
1394 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
1395 0, 0, SWP_MOVE);
1396 }
1397 else {
1398 SetWindowPos(win32wnd->getWindowHandle(), 0, track.rclTrack.xLeft,
1399 parentHeight - track.rclTrack.yTop,
1400 track.rclTrack.xRight - track.rclTrack.xLeft,
1401 track.rclTrack.yTop - track.rclTrack.yBottom,
1402 SWP_NOACTIVATE_W | SWP_NOZORDER_W | SWP_NOACTIVATE_W);
1403// WinSetWindowPos(win32wnd->getOS2WindowHandle(),
1404// 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
1405// track.rclTrack.xRight - track.rclTrack.xLeft,
1406// track.rclTrack.yTop - track.rclTrack.yBottom,
1407// SWP_SIZE|SWP_MOVE);
1408 }
1409 }
1410 return;
1411 }
1412 if(hpsTrack) WinReleasePS(hpsTrack);
1413 return;
1414}
1415//******************************************************************************
1416//******************************************************************************
Note: See TracBrowser for help on using the repository browser.