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

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

Post(Thread)/SendMessage updates & fixes

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