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

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

WM_NCHITTEST changes; no longer rely on PM

File size: 47.9 KB
Line 
1/* $Id: pmwindow.cpp,v 1.121 2001-03-30 11:14:35 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->CanReceiveSizeMsgs())
463 win32wnd->MsgPosChanged((LPARAM)&wp);
464
465 if((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
466 {
467 //redraw the frame (to prevent unnecessary client updates)
468 BOOL redrawAll = FALSE;
469
470 if (win32wnd->getWindowClass())
471 {
472 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
473
474 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
475 redrawAll = TRUE;
476 else
477 if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
478 redrawAll = TRUE;
479 }
480 else redrawAll = TRUE;
481
482 if(win32wnd->IsMixMaxStateChanging()) {
483 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
484 redrawAll = TRUE;
485 }
486
487 if (redrawAll)
488 {
489 //CB: redraw all children for now
490 // -> problems with update region if we don't do it
491 // todo: rewrite whole handling
492 WinInvalidateRect(hwnd,NULL,TRUE);
493 }
494 else
495 {
496 HPS hps = WinGetPS(hwnd);
497 RECTL frame,client,arcl[4];
498
499 WinQueryWindowRect(hwnd,&frame);
500
501 //top
502 arcl[0].xLeft = 0;
503 arcl[0].xRight = frame.xRight;
504 arcl[0].yBottom = rect.yTop;
505 arcl[0].yTop = frame.yTop;
506 //right
507 arcl[1].xLeft = rect.xRight;
508 arcl[1].xRight = frame.xRight;
509 arcl[1].yBottom = 0;
510 arcl[1].yTop = frame.yTop;
511 //left
512 arcl[2].xLeft = 0;
513 arcl[2].xRight = rect.xLeft;
514 arcl[2].yBottom = 0;
515 arcl[2].yTop = frame.yTop;
516 //bottom
517 arcl[3].xLeft = 0;
518 arcl[3].xRight = frame.xRight;
519 arcl[3].yBottom = 0;
520 arcl[3].yTop = rect.yBottom;
521
522 HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
523
524 WinInvalidateRegion(hwnd,hrgn,FALSE);
525 GpiDestroyRegion(hps,hrgn);
526 WinReleasePS(hps);
527 }
528 }
529 }
530 else
531 {
532#endif //USE_CALCVALIDRECT
533 if(win32wnd->CanReceiveSizeMsgs())
534 win32wnd->MsgPosChanged((LPARAM)&wp);
535#ifndef USE_CALCVALIDRECT
536 }
537#endif
538
539 if(pswp->fl & SWP_ACTIVATE)
540 {
541 //Only send PM WM_ACTIVATE to top-level windows (frame windows)
542 if(!(WinQueryWindowULong(hwnd, OFFSET_WIN32FLAGS) & WINDOWFLAG_ACTIVE))
543 {
544 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)TRUE, (MPARAM)hwnd);
545 }
546 }
547 else
548 if(pswp->fl & SWP_DEACTIVATE)
549 {
550 //Only send PM WM_ACTIVATE to top-level windows (frame windows)
551 if(WinQueryWindowULong(hwnd, OFFSET_WIN32FLAGS) & WINDOWFLAG_ACTIVE)
552 {
553 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)FALSE, (MPARAM)hwnd);
554 }
555 }
556
557PosChangedEnd:
558 return (MRESULT)FALSE;
559 }
560
561 case WM_ACTIVATE:
562 {
563 ULONG flags = WinQueryWindowULong(hwnd, OFFSET_WIN32FLAGS);
564
565 dprintf(("OS2: WM_ACTIVATE %x %x %x", hwnd, mp1, mp2));
566
567 WinSetWindowULong(hwnd, OFFSET_WIN32FLAGS, SHORT1FROMMP(mp1) ? (flags | WINDOWFLAG_ACTIVE):(flags & ~WINDOWFLAG_ACTIVE));
568 if(win32wnd->IsWindowCreated())
569 {
570 win32wnd->MsgActivate((LOWORD(pWinMsg->wParam) == WA_ACTIVE_W) ? 1 : 0, HIWORD(pWinMsg->wParam), pWinMsg->lParam, (HWND)mp2);
571
572 //CB: show owner behind the dialog
573 if(win32wnd->IsModalDialog())
574 {
575 Win32BaseWindow *topOwner = win32wnd->getOwner()->GetTopParent();
576
577 if(topOwner) WinSetWindowPos(topOwner->getOS2WindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
578 }
579 }
580 return 0;
581 }
582
583 case WM_SIZE:
584 {
585 dprintf(("OS2: WM_SIZE (%d,%d) (%d,%d)", SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), SHORT1FROMMP(mp1), SHORT2FROMMP(mp2)));
586 goto RunDefWndProc;
587 }
588
589 case WM_CALCVALIDRECTS:
590#ifdef USE_CALCVALIDRECT
591 {
592 PRECTL oldRect = (PRECTL)mp1, newRect = oldRect+1;
593 PSWP pswp = (PSWP)mp2;
594 SWP swpOld;
595 WINDOWPOS wp;
596 RECTL newClientRect, oldClientRect;
597 ULONG nccalcret;
598// UINT res = CVR_ALIGNLEFT | CVR_ALIGNTOP;
599 UINT res = 0;
600
601 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
602
603 //Get old position info
604 WinQueryWindowPos(hwnd, &swpOld);
605
606 if(win32wnd->getParent()) {
607 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getWindowHeight(),
608 win32wnd->getParent()->getClientRectPtr()->left,
609 win32wnd->getParent()->getClientRectPtr()->top,
610 hwnd);
611 }
612 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
613
614 wp.hwnd = win32wnd->getWindowHandle();
615 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
616 {
617 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
618 if(wndAfter) {
619 wp.hwndInsertAfter = wndAfter->getWindowHandle();
620 }
621 else wp.hwndInsertAfter = HWND_TOP_W;
622 }
623
624 //Get old client rectangle
625 mapWin32ToOS2Rect(oldRect->yTop - oldRect->yBottom, win32wnd->getClientRectPtr(), (PRECTLOS2)&oldClientRect);
626
627 //Note: Also updates the new window rectangle
628 nccalcret = win32wnd->MsgFormatFrame(&wp);
629
630 //Get new client rectangle
631 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&newClientRect);
632
633 if(nccalcret == 0) {
634 res = CVR_ALIGNTOP | CVR_ALIGNLEFT;
635 }
636 else {
637 if(nccalcret & WVR_ALIGNTOP_W) {
638 res |= CVR_ALIGNTOP;
639 }
640 else
641 if(nccalcret & WVR_ALIGNBOTTOM_W) {
642 res |= CVR_ALIGNBOTTOM;
643 }
644
645 if(nccalcret & WVR_ALIGNLEFT_W) {
646 res |= CVR_ALIGNLEFT;
647 }
648 else
649 if(nccalcret & WVR_ALIGNRIGHT_W) {
650 res |= CVR_ALIGNRIGHT;
651 }
652
653 if(nccalcret & WVR_REDRAW_W) {//WVR_REDRAW_W = (WVR_HREDRAW | WVR_VREDRAW)
654 res |= CVR_REDRAW;
655 }
656 else
657 if(nccalcret & WVR_VALIDRECTS_W) {
658 //TODO:
659 //res = 0;
660 }
661 }
662 if(win32wnd->IsMixMaxStateChanging()) {
663 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
664 res |= CVR_REDRAW;
665 }
666 if(res == (CVR_ALIGNTOP|CVR_ALIGNLEFT)) {
667 oldRect->xRight -= oldClientRect.xLeft;
668 oldRect->yBottom += oldClientRect.yBottom;
669 newRect->xRight -= newClientRect.xLeft;
670 newRect->yBottom += newClientRect.yBottom;
671 }
672
673#if 0
674 if((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
675 {
676 //redraw the frame (to prevent unnecessary client updates)
677 BOOL redrawAll = FALSE;
678
679 if (win32wnd->getWindowClass())
680 {
681 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
682
683 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
684 redrawAll = TRUE;
685 else
686 if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
687 redrawAll = TRUE;
688 }
689 else redrawAll = TRUE;
690
691 if (redrawAll)
692 {
693 //CB: redraw all children for now
694 // -> problems with update region if we don't do it
695 // todo: rewrite whole handling
696 WinInvalidateRect(hwnd,NULL,TRUE);
697 }
698 else
699 {
700 HPS hps = WinGetPS(hwnd);
701 RECTL frame,client,arcl[4];
702
703 WinQueryWindowRect(hwnd,&frame);
704
705 //top
706 arcl[0].xLeft = 0;
707 arcl[0].xRight = frame.xRight;
708 arcl[0].yBottom = rect.yTop;
709 arcl[0].yTop = frame.yTop;
710 //right
711 arcl[1].xLeft = rect.xRight;
712 arcl[1].xRight = frame.xRight;
713 arcl[1].yBottom = 0;
714 arcl[1].yTop = frame.yTop;
715 //left
716 arcl[2].xLeft = 0;
717 arcl[2].xRight = rect.xLeft;
718 arcl[2].yBottom = 0;
719 arcl[2].yTop = frame.yTop;
720 //bottom
721 arcl[3].xLeft = 0;
722 arcl[3].xRight = frame.xRight;
723 arcl[3].yBottom = 0;
724 arcl[3].yTop = rect.yBottom;
725
726 HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
727
728 WinInvalidateRegion(hwnd,hrgn,FALSE);
729 GpiDestroyRegion(hps,hrgn);
730 WinReleasePS(hps);
731 }
732 }
733
734 }
735#endif
736
737 return (MRESULT)res;
738 }
739#else
740 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
741 return (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
742#endif
743
744 case WM_VRNENABLED:
745 dprintf(("OS2: WM_VRNENABLED %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
746 if(!win32wnd->isComingToTop() && ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == WS_EX_TOPMOST_W))
747 {
748 HWND hwndrelated;
749 Win32BaseWindow *topwindow;
750
751 win32wnd->setComingToTop(TRUE);
752
753 hwndrelated = WinQueryWindow(hwnd, QW_PREV);
754 dprintf(("WM_VRNENABLED hwndrelated = %x (hwnd=%x)", hwndrelated, hwnd));
755 topwindow = Win32BaseWindow::GetWindowFromOS2Handle(hwndrelated);
756 if(topwindow == NULL || ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == 0)) {
757 //put window at the top of z order
758 WinSetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER );
759 }
760
761 win32wnd->setComingToTop(FALSE);
762 break;
763 }
764 //Restore window origin of window with CS_OWNDC style
765 //(fixes paint offset problems in Opera windows)
766 if(win32wnd->isOwnDC()) {
767 dprintfOrigin(win32wnd->getOwnDC());
768 selectClientArea(win32wnd, win32wnd->getOwnDC());
769 }
770 goto RunDefWndProc;
771
772 case WM_VRNDISABLED:
773 dprintf(("OS2: WM_VRNDISABLED %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
774 if(win32wnd->isOwnDC()) {
775 dprintfOrigin(win32wnd->getOwnDC());
776 }
777 goto RunDefWndProc;
778
779 case WM_SETFOCUS:
780 {
781 HWND hwndFocus = (HWND)mp1;
782
783 dprintf(("OS2: WM_SETFOCUS %x %x (%x) %d", win32wnd->getWindowHandle(), mp1, OS2ToWin32Handle(hwndFocus), mp2));
784
785 //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
786 //must delay this function call
787
788 teb->o.odin.fWM_SETFOCUS = TRUE;
789 teb->o.odin.hwndFocus = 0;
790 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
791 //another (non-win32) application's window
792 //set to NULL (allowed according to win32 SDK) to avoid problems
793 hwndFocus = NULL;
794 }
795 if((ULONG)mp2 == TRUE) {
796 HWND hwndFocusWin32 = OS2ToWin32Handle(hwndFocus);
797 recreateCaret (hwndFocusWin32);
798 win32wnd->MsgSetFocus(hwndFocusWin32);
799 }
800 else win32wnd->MsgKillFocus(OS2ToWin32Handle(hwndFocus));
801 teb->o.odin.fWM_SETFOCUS = FALSE;
802
803 break;
804 }
805
806#if 0
807 //is sent to both windows gaining and loosing the focus
808 case WM_FOCUSCHANGE:
809 {
810 HWND hwndFocus = (HWND)mp1;
811 HWND hwndLoseFocus, hwndGainFocus;
812 USHORT usSetFocus = SHORT1FROMMP(mp2);
813 USHORT fsFocusChange = SHORT2FROMMP(mp2);
814
815 rc = 0;
816 dprintf(("OS2: WM_FOCUSCHANGE (start) %x %x %x %x", win32wnd->getWindowHandle(), hwndFocus, usSetFocus, fsFocusChange));
817 if(usSetFocus) {
818 hwndGainFocus = hwnd;
819 hwndLoseFocus = hwndFocus;
820 }
821 else {
822 hwndGainFocus = hwndFocus;
823 hwndLoseFocus = hwnd;
824 }
825
826 if(usSetFocus)
827 {
828 Win32BaseWindow *winfocus = Win32BaseWindow::GetWindowFromOS2Handle(hwndLoseFocus);
829 if(!(fsFocusChange & FC_NOSETACTIVE))
830 {
831 if(!winfocus || (winfocus->GetTopParent() != win32wnd->GetTopParent()))
832 {
833 if(winfocus)
834 WinSendMsg(winfocus->GetTopParent()->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)0, (MPARAM)hwndGainFocus);
835 else
836 WinSendMsg(hwndLoseFocus, WM_ACTIVATE, (MPARAM)0, (MPARAM)hwndGainFocus);
837 }
838 }
839 //SvL: Check if window is still valid
840 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
841 if(win32wnd == NULL)
842 return (MRESULT)rc;
843
844 if(!(fsFocusChange & FC_NOSETACTIVE))
845 {
846 Win32BaseWindow *topparent = win32wnd->GetTopParent();
847 if(!winfocus || (winfocus->GetTopParent() != topparent))
848 {
849 if(!(fsFocusChange & FC_NOBRINGTOTOP))
850 {
851 if(topparent) {
852 //put window at the top of z order
853 WinSetWindowPos(topparent->getOS2WindowHandle(), HWND_TOP, 0, 0, 0, 0, SWP_ZORDER);
854 }
855 }
856
857 // PH 2000/09/01 Netscape 4.7
858 // check if topparent is valid
859 if (topparent)
860 WinSendMsg(topparent->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)1, (MPARAM)hwndLoseFocus);
861 }
862 }
863 //SvL: Check if window is still valid
864 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
865 if(win32wnd == NULL)
866 return (MRESULT)rc;
867
868 //TODO: Don't send WM_SETSELECTION to child window if frame already has selection
869 if(!(fsFocusChange & FC_NOSETSELECTION)) {
870 WinSendMsg(hwndGainFocus, WM_SETSELECTION, (MPARAM)1, (MPARAM)0);
871 }
872
873 if(!(fsFocusChange & FC_NOSETFOCUS)) {
874 WinSendMsg(hwndGainFocus, WM_SETFOCUS, (MPARAM)hwndLoseFocus, (MPARAM)1);
875 }
876 }
877 else /* no usSetFocus */
878 {
879 if(!(fsFocusChange & FC_NOLOSEFOCUS)) {
880 WinSendMsg(hwndLoseFocus, WM_SETFOCUS, (MPARAM)hwndGainFocus, (MPARAM)0);
881 }
882 //TODO: Don't send WM_SETSELECTION to child window if frame already has selection
883 if(!(fsFocusChange & FC_NOLOSESELECTION)) {
884 WinSendMsg(hwndLoseFocus, WM_SETSELECTION, (MPARAM)0, (MPARAM)0);
885 }
886 //SvL: Check if window is still valid
887 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
888 if(win32wnd == NULL) {
889 return (MRESULT)rc;
890 }
891
892 Win32BaseWindow *winfocus = Win32BaseWindow::GetWindowFromOS2Handle(hwndGainFocus);
893 if(!(fsFocusChange & FC_NOLOSEACTIVE))
894 {
895 Win32BaseWindow *topparent = win32wnd->GetTopParent();
896
897 if(!winfocus || (winfocus->GetTopParent() != topparent))
898 {
899 // PH 2000/09/01 Netscape 4.7
900 // check if topparent is valid
901 if (topparent)
902 WinSendMsg(topparent->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)0, (MPARAM)hwndGainFocus);
903 }
904 }
905 //SvL: Check if window is still valid
906 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
907 if(win32wnd == NULL)
908 return (MRESULT)rc;
909
910 if(!(fsFocusChange & FC_NOSETACTIVE))
911 {
912 if(!winfocus || (winfocus->GetTopParent() != win32wnd->GetTopParent()))
913 {
914 if(winfocus)
915 {
916 // PH 2000/09/01 Netscape 4.7
917 // check if topparent is valid
918 Win32BaseWindow *topparent = winfocus->GetTopParent();
919 if (topparent)
920 WinSendMsg(topparent->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)1, (MPARAM)hwndLoseFocus);
921 }
922 else
923 WinSendMsg(hwndGainFocus, WM_ACTIVATE, (MPARAM)1, (MPARAM)hwndLoseFocus);
924 }
925 }
926 }
927
928
929#ifdef DEBUG
930 SetWin32TIB();
931 dprintf(("OS2: WM_FOCUSCHANGE (end) %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
932#endif
933 return (MRESULT)rc;
934 }
935#endif
936
937 //**************************************************************************
938 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
939 //**************************************************************************
940#ifndef ODIN_HITTEST
941 case WM_HITTEST:
942 {
943 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
944 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
945 }
946 if(win32wnd && win32wnd->IsWindowCreated())
947 {
948 MRESULT rc;
949
950 rc = (MRESULT)win32wnd->MsgHitTest(pWinMsg);
951 return rc;
952 }
953 return (MRESULT)HT_NORMAL;
954 }
955#endif
956
957 case WM_BUTTON1DOWN:
958 case WM_BUTTON1UP:
959 case WM_BUTTON1DBLCLK:
960 case WM_BUTTON2DOWN:
961 case WM_BUTTON2UP:
962 case WM_BUTTON2DBLCLK:
963 case WM_BUTTON3DOWN:
964 case WM_BUTTON3UP:
965 case WM_BUTTON3DBLCLK:
966 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
967 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
968 }
969 if(win32wnd)
970 win32wnd->MsgButton(pWinMsg);
971
972 rc = (MRESULT)TRUE;
973 break;
974
975 case WM_BUTTON2MOTIONSTART:
976 case WM_BUTTON2MOTIONEND:
977 case WM_BUTTON2CLICK:
978 case WM_BUTTON1MOTIONSTART:
979 case WM_BUTTON1MOTIONEND:
980 case WM_BUTTON1CLICK:
981 case WM_BUTTON3MOTIONSTART:
982 case WM_BUTTON3MOTIONEND:
983 case WM_BUTTON3CLICK:
984 rc = (MRESULT)TRUE;
985 break;
986
987 case WM_MOUSEMOVE:
988 {
989 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
990 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
991 }
992 if(win32wnd)
993 win32wnd->MsgMouseMove(pWinMsg);
994 break;
995 }
996
997 case WM_CONTROL:
998 goto RunDefWndProc;
999
1000 case WM_COMMAND:
1001 dprintf(("OS2: WM_COMMAND %x %x %x", hwnd, mp1, mp2));
1002 win32wnd->DispatchMsgA(pWinMsg);
1003 break;
1004
1005 case WM_SYSCOMMAND:
1006 win32wnd->DispatchMsgA(pWinMsg);
1007 break;
1008
1009 case WM_RENDERFMT:
1010 case WM_RENDERALLFMTS:
1011 case WM_DESTROYCLIPBOARD:
1012 win32wnd->DispatchMsgA(pWinMsg);
1013 break;
1014
1015 case WM_CHAR:
1016 win32wnd->MsgChar(pWinMsg);
1017 break;
1018
1019 case WM_TIMER:
1020 win32wnd->DispatchMsgA(pWinMsg);
1021 goto RunDefWndProc;
1022
1023 case WM_SETWINDOWPARAMS:
1024 {
1025 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
1026
1027 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
1028 if(wndParams->fsStatus & WPM_TEXT) {
1029 win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText);
1030 }
1031 goto RunDefWndProc;
1032 }
1033
1034 case WM_QUERYWINDOWPARAMS:
1035 {
1036 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
1037 ULONG textlen;
1038 PSZ wintext;
1039
1040 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
1041 {
1042 if(wndpars->fsStatus & WPM_TEXT)
1043 win32wnd->MsgGetText(wndpars->pszText, wndpars->cchText);
1044 if(wndpars->fsStatus & WPM_CCHTEXT)
1045 wndpars->cchText = win32wnd->MsgGetTextLength();
1046
1047 wndpars->fsStatus = 0;
1048 wndpars->cbCtlData = 0;
1049 wndpars->cbPresParams = 0;
1050 return (MRESULT)TRUE;
1051 }
1052 goto RunDefWndProc;
1053 }
1054
1055 case WM_PAINT:
1056 {
1057 RECTL rectl;
1058 BOOL rc;
1059
1060 rc = WinQueryUpdateRect(hwnd, &rectl);
1061 dprintf(("OS2: WM_PAINT %x (%d,%d) (%d,%d) rc=%d", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop, rc));
1062
1063 if(rc && win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
1064 rectl.yBottom != rectl.yTop))
1065 {
1066 PRECT pClient = win32wnd->getClientRectPtr();
1067 PRECT pWindow = win32wnd->getWindowRect();
1068
1069 if(!(pClient->left == 0 && pClient->top == 0 &&
1070 win32wnd->getClientHeight() == win32wnd->getWindowHeight() &&
1071 win32wnd->getClientWidth() == win32wnd->getWindowWidth()))
1072 {
1073 win32wnd->MsgNCPaint();
1074 }
1075 win32wnd->DispatchMsgA(pWinMsg);
1076 }
1077 else goto RunDefWndProc;
1078
1079 //SvL: Not calling the default window procedure causes all sorts of
1080 // strange problems (redraw & hanging app)
1081 // -> check what WinBeginPaint does what we're forgetting in BeginPaint
1082// WinQueryUpdateRect(hwnd, &rectl);
1083// if(rectl.xLeft == 0 && rectl.yTop == 0 && rectl.xRight == 0 && rectl.yBottom == 0) {
1084// RestoreOS2TIB();
1085// return (MRESULT)FALSE;
1086// }
1087// dprintf(("Update rectangle (%d,%d)(%d,%d) not empty, msg %x", rectl.xLeft, rectl.yTop, rectl.xRight, rectl.yBottom, pWinMsg->message));
1088// goto RunDefWndProc;
1089 break;
1090 }
1091
1092 case WM_ERASEBACKGROUND:
1093 {
1094 dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
1095 return (MRESULT)FALSE;
1096 }
1097
1098#if 0
1099 case WM_CONTEXTMENU:
1100 {
1101 win32wnd->DispatchMsgA(pWinMsg);
1102
1103 return (MRESULT)TRUE;
1104 }
1105#endif
1106
1107 case WM_QUERYTRACKINFO:
1108 {
1109 PTRACKINFO trackInfo = (PTRACKINFO)mp2;
1110
1111 dprintf(("OS2: WM_QUERYTRACKINFO %x", win32wnd->getWindowHandle()));
1112 trackInfo->cxBorder = 4;
1113 trackInfo->cyBorder = 4;
1114 win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
1115 return (MRESULT)TRUE;
1116 }
1117
1118 case WM_QUERYBORDERSIZE:
1119 {
1120 PWPOINT size = (PWPOINT)mp1;
1121
1122 dprintf(("OS2: WM_QUERYBORDERSIZE %x", win32wnd->getWindowHandle()));
1123
1124 size->x = 0;
1125 size->y = 0;
1126 return (MRESULT)TRUE;
1127 }
1128
1129 case WM_REALIZEPALETTE:
1130 {
1131 dprintf(("OS2: WM_REALIZEPALETTE"));
1132 goto RunDefWndProc;
1133 }
1134
1135 case WM_OWNERPOSCHANGE:
1136 {
1137 dprintf(("OS2: WM_OWNERPOSCHANGE"));
1138 goto RunDefWndProc;
1139 }
1140
1141 case WM_INITMENU:
1142 case WM_MENUSELECT:
1143 case WM_MENUEND:
1144 case WM_NEXTMENU:
1145 case WM_SYSCOLORCHANGE:
1146 case WM_SYSVALUECHANGED:
1147 case WM_SETSELECTION:
1148 case WM_PPAINT:
1149 case WM_PSETFOCUS:
1150 case WM_PSYSCOLORCHANGE:
1151 case WM_PSIZE:
1152 case WM_PACTIVATE:
1153 case WM_PCONTROL:
1154 case WM_HELP:
1155 case WM_APPTERMINATENOTIFY:
1156 case WM_PRESPARAMCHANGED:
1157 case WM_DRAWITEM:
1158 case WM_MEASUREITEM:
1159 case WM_CONTROLPOINTER:
1160 case WM_QUERYDLGCODE:
1161 case WM_SUBSTITUTESTRING:
1162 case WM_MATCHMNEMONIC:
1163 case WM_SAVEAPPLICATION:
1164 case WM_SEMANTICEVENT:
1165 default:
1166 dprintf2(("OS2: RunDefWndProc hwnd %x msg %x mp1 %x mp2 %x", hwnd, msg, mp1, mp2));
1167 RestoreOS2TIB();
1168 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
1169 }
1170 return (MRESULT)rc;
1171
1172RunDefWndProc:
1173// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
1174 RestoreOS2TIB();
1175 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
1176} /* End of Win32WindowProc */
1177//******************************************************************************
1178//******************************************************************************
1179MRESULT EXPENTRY Win32FrameWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1180{
1181 POSTMSG_PACKET *postmsg;
1182 OSLIBPOINT point, ClientPoint;
1183 Win32BaseWindow *win32wnd;
1184 TEB *teb;
1185 MRESULT rc = 0;
1186 MSG winMsg, *pWinMsg;
1187
1188 //Restore our FS selector
1189 SetWin32TIB();
1190
1191 //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- BEGIN
1192 teb = GetThreadTEB();
1193 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
1194
1195 if(!teb || (msg != WM_CREATE && win32wnd == NULL)) {
1196 dprintf(("Invalid win32wnd pointer for window %x msg %x", hwnd, msg));
1197 goto RunDefFrameWndProc;
1198 }
1199//// if(teb->o.odin.fIgnoreMsgs) {
1200//// goto RunDefWndProc;
1201//// }
1202
1203 if((teb->o.odin.msgstate & 1) == 0)
1204 {//message that was sent directly to our window proc handler; translate it here
1205 QMSG qmsg;
1206
1207 qmsg.msg = msg;
1208 qmsg.hwnd = hwnd;
1209 qmsg.mp1 = mp1;
1210 qmsg.mp2 = mp2;
1211 qmsg.time = WinQueryMsgTime(teb->o.odin.hab);
1212 WinQueryMsgPos(teb->o.odin.hab, &qmsg.ptl);
1213 qmsg.reserved = 0;
1214
1215 if(OS2ToWinMsgTranslate((PVOID)teb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
1216 {//message was not translated
1217 memset(&winMsg, 0, sizeof(MSG));
1218 }
1219 pWinMsg = &winMsg;
1220 }
1221 else {
1222 pWinMsg = &teb->o.odin.msg;
1223 teb->o.odin.msgstate++;
1224 }
1225 //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- END
1226
1227 switch( msg )
1228 {
1229 case WM_CREATE:
1230 {
1231 RestoreOS2TIB();
1232 pfnFrameWndProc(hwnd, msg, mp1, mp2);
1233 SetWin32TIB();
1234 rc = ProcessPMMessage(hwnd, msg, mp1, mp2, win32wnd, pWinMsg, teb, TRUE);
1235 break;
1236 }
1237
1238 case WM_CALCFRAMERECT:
1239 dprintf(("OS2: WM_CALCFRAMERECT %x", win32wnd->getWindowHandle()));
1240 rc = (MRESULT)TRUE;
1241 break;
1242
1243 case WM_QUERYCTLTYPE:
1244 // This is a frame window
1245 dprintf(("OS2: WM_QUERYCTLTYPE %x", win32wnd->getWindowHandle()));
1246 rc = (MRESULT)CCT_FRAME;
1247 break;
1248
1249 case WM_QUERYFOCUSCHAIN:
1250 dprintf(("OS2: WM_QUERYFOCUSCHAIN %x", win32wnd->getWindowHandle()));
1251 goto RunDefFrameWndProc;
1252
1253 case WM_FOCUSCHANGE:
1254 {
1255 HWND hwndFocus = (HWND)mp1;
1256 HWND hwndLoseFocus, hwndGainFocus;
1257 USHORT usSetFocus = SHORT1FROMMP(mp2);
1258 USHORT fsFocusChange = SHORT2FROMMP(mp2);
1259
1260 dprintf(("OS2: WM_FOCUSCHANGE %x %x %x %x", win32wnd->getWindowHandle(), hwndFocus, usSetFocus, fsFocusChange));
1261 goto RunDefFrameWndProc;
1262 }
1263
1264 case WM_ACTIVATE:
1265 case WM_SETFOCUS:
1266 {
1267 rc = ProcessPMMessage(hwnd, msg, mp1, mp2, win32wnd, pWinMsg, teb, TRUE);
1268 goto RunDefFrameWndProc;
1269 }
1270
1271#if 0
1272//just a test
1273 case WM_ADJUSTWINDOWPOS:
1274 case WM_WINDOWPOSCHANGED:
1275 {
1276 rc = ProcessPMMessage(hwnd, msg, mp1, mp2, win32wnd, pWinMsg, teb, TRUE);
1277 goto RunDefFrameWndProc;
1278 }
1279#endif
1280
1281 case WM_QUERYFRAMEINFO:
1282 dprintf(("OS2: WM_QUERYFRAMEINFO %x", win32wnd->getWindowHandle()));
1283 goto RunDefFrameWndProc;
1284
1285 case WM_FORMATFRAME:
1286 dprintf(("OS2: WM_FORMATFRAME %x", win32wnd->getWindowHandle()));
1287 goto RunDefFrameWndProc;
1288
1289 case WM_ADJUSTFRAMEPOS:
1290 {
1291 PSWP pswp = (PSWP)mp1;
1292
1293 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));
1294 goto RunDefFrameWndProc;
1295 }
1296
1297 case WM_MINMAXFRAME:
1298 {
1299 PSWP swp = (PSWP)mp1;
1300
1301 if (!win32wnd->IsWindowCreated()) goto RunDefWndProc;
1302
1303 dprintf(("OS2: WM_MINMAXFRAME %x",hwnd));
1304 if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
1305 {
1306 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MINIMIZE_W) | WS_MAXIMIZE_W);
1307
1308 RECT rect;
1309
1310 rect.left = rect.top = rect.right = rect.bottom = 0;
1311 win32wnd->AdjustMaximizedRect(&rect);
1312 swp->x += rect.left;
1313 swp->cx += rect.right-rect.left;
1314 swp->y -= rect.bottom;
1315 swp->cy += rect.bottom-rect.top;
1316 }
1317 else
1318 if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
1319 {
1320 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
1321 }
1322 else
1323 if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
1324 {
1325 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
1326 }
1327 goto RunDefWndProc;
1328 }
1329
1330 case WM_UPDATEFRAME:
1331 dprintf(("OS2: WM_UPDATEFRAME %x", win32wnd->getWindowHandle()));
1332 goto RunDefFrameWndProc;
1333
1334 default:
1335 rc = ProcessPMMessage(hwnd, msg, mp1, mp2, win32wnd, pWinMsg, teb, TRUE);
1336 break;
1337 }
1338 RestoreOS2TIB();
1339 return (MRESULT)rc;
1340
1341RunDefFrameWndProc:
1342 RestoreOS2TIB();
1343 return pfnFrameWndProc(hwnd, msg, mp1, mp2);
1344
1345RunDefWndProc:
1346 RestoreOS2TIB();
1347 return Win32WindowProc(hwnd, msg, mp1, mp2);
1348}
1349//******************************************************************************
1350//TODO: Quickly moving a window two times doesn't force a repaint (1st time)
1351//******************************************************************************
1352VOID FrameTrackFrame(Win32BaseWindow *win32wnd,DWORD flags)
1353{
1354 TRACKINFO track;
1355 RECTL rcl;
1356 PRECT pWindowRect, pClientRect;
1357 HWND hwndTracking;
1358 HPS hpsTrack;
1359 LONG parentHeight, parentWidth;
1360
1361 dprintf(("FrameTrackFrame: %x %x", win32wnd->getWindowHandle(), flags));
1362 track.cxBorder = 4;
1363 track.cyBorder = 4; /* 4 pel wide lines used for rectangle */
1364 track.cxGrid = 1;
1365 track.cyGrid = 1; /* smooth tracking with mouse */
1366 track.cxKeyboard = 8;
1367 track.cyKeyboard = 8; /* faster tracking using cursor keys */
1368
1369 pWindowRect = win32wnd->getWindowRect();
1370 if(win32wnd->getParent()) {
1371 parentHeight = win32wnd->getParent()->getWindowHeight();
1372 parentWidth = win32wnd->getParent()->getWindowWidth();
1373 hwndTracking = win32wnd->getParent()->getOS2WindowHandle();
1374 hpsTrack = WinGetPS(hwndTracking);
1375 }
1376 else {
1377 parentHeight = OSLibQueryScreenHeight();
1378 parentWidth = OSLibQueryScreenWidth();
1379 hwndTracking = HWND_DESKTOP;
1380 hpsTrack = NULL;
1381 }
1382
1383 mapWin32ToOS2Rect(parentHeight, pWindowRect, (PRECTLOS2)&track.rclTrack);
1384 WinQueryWindowRect(hwndTracking, &track.rclBoundary);
1385
1386 track.ptlMinTrackSize.x = 10;
1387 track.ptlMinTrackSize.y = 10; /* set smallest allowed size of rectangle */
1388 track.ptlMaxTrackSize.x = parentWidth;
1389 track.ptlMaxTrackSize.y = parentHeight; /* set largest allowed size of rectangle */
1390
1391 win32wnd->AdjustTrackInfo((PPOINT)&track.ptlMinTrackSize, (PPOINT)&track.ptlMaxTrackSize);
1392
1393 track.fs = flags;
1394
1395 if(WinTrackRect(hwndTracking, NULL, &track) )
1396 {
1397 if(hpsTrack) WinReleasePS(hpsTrack);
1398
1399 /* if successful copy final position back */
1400 if(!WinEqualRect(0, &rcl, &track.rclTrack)) {
1401 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));
1402 if(flags == TF_MOVE) {
1403 WinSetWindowPos(win32wnd->getOS2WindowHandle(),
1404 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
1405 0, 0, SWP_MOVE);
1406 }
1407 else {
1408 SetWindowPos(win32wnd->getWindowHandle(), 0, track.rclTrack.xLeft,
1409 parentHeight - track.rclTrack.yTop,
1410 track.rclTrack.xRight - track.rclTrack.xLeft,
1411 track.rclTrack.yTop - track.rclTrack.yBottom,
1412 SWP_NOACTIVATE_W | SWP_NOZORDER_W | SWP_NOACTIVATE_W);
1413// WinSetWindowPos(win32wnd->getOS2WindowHandle(),
1414// 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
1415// track.rclTrack.xRight - track.rclTrack.xLeft,
1416// track.rclTrack.yTop - track.rclTrack.yBottom,
1417// SWP_SIZE|SWP_MOVE);
1418 }
1419 }
1420 return;
1421 }
1422 if(hpsTrack) WinReleasePS(hpsTrack);
1423 return;
1424}
1425//******************************************************************************
1426//******************************************************************************
Note: See TracBrowser for help on using the repository browser.