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

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

removed previous WM_ADJUSTFRAMEPOS fix; has bad side effects

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