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

Last change on this file since 5247 was 5246, checked in by sandervl, 25 years ago

minimize updates + update region fix in NotifyFrameChanged

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