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

Last change on this file since 5655 was 5655, checked in by sandervl, 24 years ago

FrameTrackFrame & nccalcsize bugfixes

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