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

Last change on this file since 5229 was 5217, checked in by sandervl, 25 years ago

MDI activation fixes

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