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

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

SetFocus fix

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