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

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

minimize & restore fixes

File size: 47.5 KB
Line 
1/* $Id: pmwindow.cpp,v 1.131 2001-05-22 09:33:12 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_RESTORE && win32wnd->getStyle() & WS_MINIMIZE_W) {
776 dprintf(("Restoring minimized window %x", win32wnd->getWindowHandle()));
777 win32wnd->ShowWindow(SW_RESTORE_W);
778 }
779 if(pswp->fl & SWP_SHOW) {
780 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
781 }
782 else
783 if(pswp->fl & SWP_HIDE) {
784 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
785 }
786 if(pswp->fl & SWP_ACTIVATE)
787 {
788 //Only send PM WM_ACTIVATE to top-level windows (frame windows)
789 if(!(WinQueryWindowULong(WinWindowFromID(hwnd,FID_CLIENT), OFFSET_WIN32FLAGS) & WINDOWFLAG_ACTIVE))
790 {
791 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)TRUE, (MPARAM)hwnd);
792 }
793 }
794 else
795 if(pswp->fl & SWP_DEACTIVATE)
796 {
797 //Only send PM WM_ACTIVATE to top-level windows (frame windows)
798 if(WinQueryWindowULong(WinWindowFromID(hwnd,FID_CLIENT), OFFSET_WIN32FLAGS) & WINDOWFLAG_ACTIVE)
799 {
800 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)FALSE, (MPARAM)hwnd);
801 }
802 }
803 goto RunDefWndProc;
804 }
805
806 if(pswp->fl & (SWP_MOVE | SWP_SIZE))
807 {
808 if(win32wnd->isChild())
809 {
810 if(win32wnd->getParent()) {
811 hParent = win32wnd->getParent()->getOS2WindowHandle();
812 }
813 else goto PosChangedEnd; //parent has just been destroyed
814 }
815 }
816
817
818 if(win32wnd->getParent()) {
819 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
820 hwnd);
821 }
822 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
823
824 wp.hwnd = win32wnd->getWindowHandle();
825 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
826 {
827 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
828 dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
829 if(wndAfter) {
830 wp.hwndInsertAfter = wndAfter->getWindowHandle();
831 }
832 else wp.hwndInsertAfter = HWND_TOP_W;
833 }
834
835 if(pswp->fl & SWP_SHOW) {
836 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
837 }
838 else
839 if(pswp->fl & SWP_HIDE) {
840 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
841 }
842
843#ifndef USE_CALCVALIDRECT
844 if((pswp->fl & (SWP_MOVE | SWP_SIZE)))
845 {
846 //CB: todo: use result for WM_CALCVALIDRECTS
847 //Get old client rectangle (for invalidation of frame window parts later on)
848 //Use new window height to calculate the client area
849 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
850
851 //Note: Also updates the new window rectangle
852 win32wnd->MsgFormatFrame(&wp);
853
854 if(win32wnd->isOwnDC()) {
855 setPageXForm(win32wnd, (pDCData)GpiQueryDCData(win32wnd->getOwnDC()));
856 }
857
858 if(win32wnd->CanReceiveSizeMsgs())
859 win32wnd->MsgPosChanged((LPARAM)&wp);
860
861 if((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
862 {
863 //redraw the frame (to prevent unnecessary client updates)
864 BOOL redrawAll = FALSE;
865
866 dprintf2(("WM_WINDOWPOSCHANGED: redraw frame"));
867 if (win32wnd->getWindowClass())
868 {
869 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
870
871 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
872 redrawAll = TRUE;
873 else
874 if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
875 redrawAll = TRUE;
876 }
877 else redrawAll = TRUE;
878
879 if(win32wnd->IsMixMaxStateChanging()) {
880 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
881 redrawAll = TRUE;
882 }
883
884 if (redrawAll)
885 {
886 //CB: redraw all children for now
887 // -> problems with update region if we don't do it
888 // todo: rewrite whole handling
889 WinInvalidateRect(hwnd,NULL,TRUE);
890 }
891 else
892 {
893 HPS hps = WinGetPS(hwnd);
894 RECTL frame,client,arcl[4];
895
896 WinQueryWindowRect(hwnd,&frame);
897
898 //top
899 arcl[0].xLeft = 0;
900 arcl[0].xRight = frame.xRight;
901 arcl[0].yBottom = rect.yTop;
902 arcl[0].yTop = frame.yTop;
903 //right
904 arcl[1].xLeft = rect.xRight;
905 arcl[1].xRight = frame.xRight;
906 arcl[1].yBottom = 0;
907 arcl[1].yTop = frame.yTop;
908 //left
909 arcl[2].xLeft = 0;
910 arcl[2].xRight = rect.xLeft;
911 arcl[2].yBottom = 0;
912 arcl[2].yTop = frame.yTop;
913 //bottom
914 arcl[3].xLeft = 0;
915 arcl[3].xRight = frame.xRight;
916 arcl[3].yBottom = 0;
917 arcl[3].yTop = rect.yBottom;
918
919 HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
920
921 WinInvalidateRegion(hwnd,hrgn,FALSE);
922 GpiDestroyRegion(hps,hrgn);
923 WinReleasePS(hps);
924 }
925 }
926 }
927 else
928 {
929#endif //USE_CALCVALIDRECT
930 if(win32wnd->CanReceiveSizeMsgs())
931 win32wnd->MsgPosChanged((LPARAM)&wp);
932#ifndef USE_CALCVALIDRECT
933 }
934#endif
935
936 if(pswp->fl & SWP_ACTIVATE)
937 {
938 //Only send PM WM_ACTIVATE to top-level windows (frame windows)
939 if(!(WinQueryWindowULong(WinWindowFromID(hwnd,FID_CLIENT), OFFSET_WIN32FLAGS) & WINDOWFLAG_ACTIVE))
940 {
941 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)TRUE, (MPARAM)hwnd);
942 }
943 }
944 else
945 if(pswp->fl & SWP_DEACTIVATE)
946 {
947 //Only send PM WM_ACTIVATE to top-level windows (frame windows)
948 if(WinQueryWindowULong(WinWindowFromID(hwnd,FID_CLIENT), OFFSET_WIN32FLAGS) & WINDOWFLAG_ACTIVE)
949 {
950 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)FALSE, (MPARAM)hwnd);
951 }
952 }
953
954PosChangedEnd:
955 RestoreOS2TIB();
956 return (MRESULT)FALSE;
957 }
958
959 case WM_CALCVALIDRECTS:
960#ifdef USE_CALCVALIDRECT
961 {
962 PRECTL oldRect = (PRECTL)mp1, newRect = oldRect+1;
963 PSWP pswp = (PSWP)mp2;
964 SWP swpOld;
965 WINDOWPOS wp;
966 RECTL newClientRect, oldClientRect;
967 ULONG nccalcret;
968// UINT res = CVR_ALIGNLEFT | CVR_ALIGNTOP;
969 UINT res = 0;
970
971 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
972
973 //Get old position info
974 WinQueryWindowPos(hwnd, &swpOld);
975
976 if(win32wnd->getParent()) {
977 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
978 win32wnd->getParent()->getClientRectPtr()->left,
979 win32wnd->getParent()->getClientRectPtr()->top,
980 hwnd);
981 }
982 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
983
984 wp.hwnd = win32wnd->getWindowHandle();
985 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
986 {
987 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
988 if(wndAfter) {
989 wp.hwndInsertAfter = wndAfter->getWindowHandle();
990 }
991 else wp.hwndInsertAfter = HWND_TOP_W;
992 }
993
994 //Get old client rectangle
995 mapWin32ToOS2Rect(oldRect->yTop - oldRect->yBottom, win32wnd->getClientRectPtr(), (PRECTLOS2)&oldClientRect);
996
997 //Note: Also updates the new window rectangle
998 nccalcret = win32wnd->MsgFormatFrame(&wp);
999
1000 //Get new client rectangle
1001 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&newClientRect);
1002
1003 if(nccalcret == 0) {
1004 res = CVR_ALIGNTOP | CVR_ALIGNLEFT;
1005 }
1006 else {
1007 if(nccalcret & WVR_ALIGNTOP_W) {
1008 res |= CVR_ALIGNTOP;
1009 }
1010 else
1011 if(nccalcret & WVR_ALIGNBOTTOM_W) {
1012 res |= CVR_ALIGNBOTTOM;
1013 }
1014
1015 if(nccalcret & WVR_ALIGNLEFT_W) {
1016 res |= CVR_ALIGNLEFT;
1017 }
1018 else
1019 if(nccalcret & WVR_ALIGNRIGHT_W) {
1020 res |= CVR_ALIGNRIGHT;
1021 }
1022
1023 if(nccalcret & WVR_REDRAW_W) {//WVR_REDRAW_W = (WVR_HREDRAW | WVR_VREDRAW)
1024 res |= CVR_REDRAW;
1025 }
1026 else
1027 if(nccalcret & WVR_VALIDRECTS_W) {
1028 //TODO:
1029 //res = 0;
1030 }
1031 }
1032 if(win32wnd->IsMixMaxStateChanging()) {
1033 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
1034 res |= CVR_REDRAW;
1035 }
1036 if(res == (CVR_ALIGNTOP|CVR_ALIGNLEFT)) {
1037 oldRect->xRight -= oldClientRect.xLeft;
1038 oldRect->yBottom += oldClientRect.yBottom;
1039 newRect->xRight -= newClientRect.xLeft;
1040 newRect->yBottom += newClientRect.yBottom;
1041 }
1042 RestoreOS2TIB();
1043 return (MRESULT)res;
1044 }
1045#else
1046 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
1047 RestoreOS2TIB();
1048 return (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
1049#endif
1050
1051 case WM_CALCFRAMERECT:
1052 dprintf(("PMFRAME:WM_CALCFRAMERECT %x", win32wnd->getWindowHandle()));
1053 rc = (MRESULT)TRUE;
1054 break;
1055
1056 case WM_QUERYCTLTYPE:
1057 // This is a frame window
1058 dprintf(("PMFRAME:WM_QUERYCTLTYPE %x", win32wnd->getWindowHandle()));
1059 rc = (MRESULT)CCT_FRAME;
1060 break;
1061
1062#ifdef DEBUG
1063 case WM_QUERYFOCUSCHAIN:
1064 dprintf(("PMFRAME:WM_QUERYFOCUSCHAIN %x fsCmd %x parent %x", win32wnd->getWindowHandle(), SHORT1FROMMP(mp1), mp2));
1065
1066 RestoreOS2TIB();
1067 rc = pfnFrameWndProc(hwnd, msg, mp1, mp2);
1068 SetWin32TIB();
1069 dprintf(("PMFRAME:WM_QUERYFOCUSCHAIN %x fsCmd %x parent %x returned %x", win32wnd->getWindowHandle(), SHORT1FROMMP(mp1), mp2, rc));
1070 break;
1071// goto RunDefFrameWndProc;
1072#endif
1073
1074#if 0
1075 //is sent to both windows gaining and loosing the focus
1076 case WM_FOCUSCHANGE:
1077 {
1078 HWND hwndFocus = (HWND)mp1;
1079 HWND hwndLoseFocus, hwndGainFocus;
1080 USHORT usSetFocus = SHORT1FROMMP(mp2);
1081 USHORT fsFocusChange = SHORT2FROMMP(mp2);
1082
1083 rc = 0;
1084 dprintf(("PMFRAME:WM_FOCUSCHANGE (start) %x %x %x %x", win32wnd->getWindowHandle(), hwndFocus, usSetFocus, fsFocusChange));
1085 if(usSetFocus) {
1086 hwndGainFocus = hwnd;
1087 hwndLoseFocus = hwndFocus;
1088 }
1089 else {
1090 hwndGainFocus = hwndFocus;
1091 hwndLoseFocus = hwnd;
1092 }
1093
1094 if(usSetFocus)
1095 {
1096 Win32BaseWindow *winfocus = Win32BaseWindow::GetWindowFromOS2Handle(hwndLoseFocus);
1097 if(!(fsFocusChange & FC_NOSETACTIVE))
1098 {
1099 if(!winfocus || (winfocus->GetTopParent() != win32wnd->GetTopParent()))
1100 {
1101 if(winfocus)
1102 WinSendMsg(winfocus->GetTopParent()->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)0, (MPARAM)hwndGainFocus);
1103 else
1104 WinSendMsg(hwndLoseFocus, WM_ACTIVATE, (MPARAM)0, (MPARAM)hwndGainFocus);
1105 }
1106 }
1107 //SvL: Check if window is still valid
1108 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
1109 if(win32wnd == NULL) {
1110 RestoreOS2TIB();
1111 return (MRESULT)rc;
1112 }
1113 if(!(fsFocusChange & FC_NOSETACTIVE))
1114 {
1115 Win32BaseWindow *topparent = win32wnd->GetTopParent();
1116 if(!winfocus || (winfocus->GetTopParent() != topparent))
1117 {
1118 if(!(fsFocusChange & FC_NOBRINGTOTOP))
1119 {
1120 if(topparent) {
1121 //put window at the top of z order
1122 WinSetWindowPos(topparent->getOS2WindowHandle(), HWND_TOP, 0, 0, 0, 0, SWP_ZORDER);
1123 }
1124 }
1125
1126 // PH 2000/09/01 Netscape 4.7
1127 // check if topparent is valid
1128 if (topparent)
1129 WinSendMsg(topparent->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)1, (MPARAM)hwndLoseFocus);
1130 }
1131 }
1132 //SvL: Check if window is still valid
1133 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
1134 if(win32wnd == NULL) {
1135 break;
1136 }
1137
1138 //TODO: Don't send WM_SETSELECTION to child window if frame already has selection
1139 if(!(fsFocusChange & FC_NOSETSELECTION)) {
1140 WinSendMsg(hwndGainFocus, WM_SETSELECTION, (MPARAM)1, (MPARAM)0);
1141 }
1142
1143 if(!(fsFocusChange & FC_NOSETFOCUS)) {
1144 WinSendMsg(hwndGainFocus, WM_SETFOCUS, (MPARAM)hwndLoseFocus, (MPARAM)1);
1145 }
1146 }
1147 else /* no usSetFocus */
1148 {
1149 if(!(fsFocusChange & FC_NOLOSEFOCUS)) {
1150 WinSendMsg(hwndLoseFocus, WM_SETFOCUS, (MPARAM)hwndGainFocus, (MPARAM)0);
1151 }
1152 //TODO: Don't send WM_SETSELECTION to child window if frame already has selection
1153 if(!(fsFocusChange & FC_NOLOSESELECTION)) {
1154 WinSendMsg(hwndLoseFocus, WM_SETSELECTION, (MPARAM)0, (MPARAM)0);
1155 }
1156 //SvL: Check if window is still valid
1157 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
1158 if(win32wnd == NULL) {
1159 break;
1160 }
1161
1162 Win32BaseWindow *winfocus = Win32BaseWindow::GetWindowFromOS2Handle(hwndGainFocus);
1163 if(!(fsFocusChange & FC_NOLOSEACTIVE))
1164 {
1165 Win32BaseWindow *topparent = win32wnd->GetTopParent();
1166
1167 if(!winfocus || (winfocus->GetTopParent() != topparent))
1168 {
1169 // PH 2000/09/01 Netscape 4.7
1170 // check if topparent is valid
1171 if (topparent)
1172 WinSendMsg(topparent->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)0, (MPARAM)hwndGainFocus);
1173 }
1174 }
1175 //SvL: Check if window is still valid
1176 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
1177 if(win32wnd == NULL)
1178 break;
1179
1180 if(!(fsFocusChange & FC_NOSETACTIVE))
1181 {
1182 if(!winfocus || (winfocus->GetTopParent() != win32wnd->GetTopParent()))
1183 {
1184 if(winfocus)
1185 {
1186 // PH 2000/09/01 Netscape 4.7
1187 // check if topparent is valid
1188 Win32BaseWindow *topparent = winfocus->GetTopParent();
1189 if (topparent)
1190 WinSendMsg(topparent->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)1, (MPARAM)hwndLoseFocus);
1191 }
1192 else
1193 WinSendMsg(hwndGainFocus, WM_ACTIVATE, (MPARAM)1, (MPARAM)hwndLoseFocus);
1194 }
1195 }
1196 }
1197
1198
1199#ifdef DEBUG
1200 dprintf(("PMFRAME:WM_FOCUSCHANGE (end) %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
1201#endif
1202 break;
1203 }
1204#endif
1205
1206#ifdef DEBUG
1207 case WM_FOCUSCHANGE:
1208 {
1209 HWND hwndFocus = (HWND)mp1;
1210 HWND hwndLoseFocus, hwndGainFocus;
1211 USHORT usSetFocus = SHORT1FROMMP(mp2);
1212 USHORT fsFocusChange = SHORT2FROMMP(mp2);
1213
1214 dprintf(("PMFRAME:WM_FOCUSCHANGE %x %x %x %x", win32wnd->getWindowHandle(), hwndFocus, usSetFocus, fsFocusChange));
1215 goto RunDefFrameWndProc;
1216 }
1217#endif
1218
1219 case WM_ACTIVATE:
1220 {
1221 HWND hwndTitle;
1222 USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
1223
1224 dprintf(("PMFRAME: WM_ACTIVATE %x %x %x", hwnd, mp1, mp2));
1225 if (win32wnd->IsWindowCreated())
1226 {
1227 WinSendMsg(WinWindowFromID(hwnd,FID_CLIENT),WM_ACTIVATE,mp1,mp2);
1228 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1229
1230 //CB: show owner behind the dialog
1231 if (win32wnd->IsModalDialog())
1232 {
1233 Win32BaseWindow *topOwner = win32wnd->getOwner()->GetTopParent();
1234
1235 if (topOwner) WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
1236 }
1237 }
1238 else
1239 {
1240 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1241 }
1242 rc = 0;
1243 break;
1244 }
1245
1246 case WM_ENABLE:
1247 dprintf(("PMFRAME: WM_ENABLE %x", hwnd));
1248 win32wnd->MsgEnable(SHORT1FROMMP(mp1));
1249 break;
1250
1251 case WM_SHOW:
1252 dprintf(("PMFRAME: WM_SHOW %x %d", hwnd, mp1));
1253 //show client window
1254 WinShowWindow(win32wnd->getOS2WindowHandle(), (BOOL)mp1);
1255 break;
1256
1257 case WM_SETFOCUS:
1258 {
1259 dprintf(("PMFRAME: WM_SETFOCUS %x %x", win32wnd->getWindowHandle(), hwnd));
1260 goto RunDefFrameWndProc;
1261 }
1262
1263 case WM_QUERYTRACKINFO:
1264 {
1265 PTRACKINFO trackInfo = (PTRACKINFO)mp2;
1266
1267 dprintf(("PMFRAME:WM_QUERYTRACKINFO %x", win32wnd->getWindowHandle()));
1268 trackInfo->cxBorder = 4;
1269 trackInfo->cyBorder = 4;
1270 win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
1271 rc = (MRESULT)TRUE;
1272 break;
1273 }
1274
1275 case WM_QUERYBORDERSIZE:
1276 {
1277 PWPOINT size = (PWPOINT)mp1;
1278
1279 dprintf(("PMFRAME:WM_QUERYBORDERSIZE %x", win32wnd->getWindowHandle()));
1280
1281 size->x = 0;
1282 size->y = 0;
1283 rc = (MRESULT)TRUE;
1284 break;
1285 }
1286
1287 case WM_QUERYFRAMEINFO:
1288 dprintf(("PMFRAME:WM_QUERYFRAMEINFO %x", win32wnd->getWindowHandle()));
1289 goto RunDefFrameWndProc;
1290
1291 case WM_FORMATFRAME:
1292 dprintf(("PMFRAME:WM_FORMATFRAME %x", win32wnd->getWindowHandle()));
1293 break;
1294
1295 case WM_ADJUSTFRAMEPOS:
1296 {
1297 PSWP pswp = (PSWP)mp1;
1298
1299 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));
1300 goto RunDefFrameWndProc;
1301 }
1302
1303 case WM_OWNERPOSCHANGE:
1304 {
1305 PSWP pswp = (PSWP)mp1;
1306
1307 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));
1308 goto RunDefFrameWndProc;
1309 }
1310
1311 case WM_MINMAXFRAME:
1312 {
1313 PSWP swp = (PSWP)mp1;
1314
1315 if (!win32wnd->IsWindowCreated()) goto RunDefWndProc;
1316
1317 dprintf(("PMFRAME:WM_MINMAXFRAME %x",hwnd));
1318 if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
1319 {
1320 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MINIMIZE_W) | WS_MAXIMIZE_W);
1321
1322 RECT rect;
1323
1324 rect.left = rect.top = rect.right = rect.bottom = 0;
1325 win32wnd->AdjustMaximizedRect(&rect);
1326 swp->x += rect.left;
1327 swp->cx += rect.right-rect.left;
1328 swp->y -= rect.bottom;
1329 swp->cy += rect.bottom-rect.top;
1330 }
1331 else
1332 if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
1333 {
1334 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
1335 }
1336 else
1337 if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
1338 {
1339 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
1340 }
1341 goto RunDefWndProc;
1342 }
1343
1344 case WM_UPDATEFRAME:
1345 dprintf(("PMFRAME:WM_UPDATEFRAME %x", win32wnd->getWindowHandle()));
1346 goto RunDefFrameWndProc;
1347
1348 default:
1349 goto RunDefFrameWndProc;
1350 }
1351 RestoreOS2TIB();
1352 return (MRESULT)rc;
1353
1354RunDefFrameWndProc:
1355 RestoreOS2TIB();
1356 return pfnFrameWndProc(hwnd, msg, mp1, mp2);
1357
1358RunDefWndProc:
1359 RestoreOS2TIB();
1360 //calling WinDefWindowProc here breaks Opera hotlist window (WM_ADJUSTWINDOWPOS)
1361// return pfnFrameWndProc(hwnd, msg, mp1, mp2);
1362 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
1363}
1364//******************************************************************************
1365//TODO: Quickly moving a window two times doesn't force a repaint (1st time)
1366//******************************************************************************
1367VOID FrameTrackFrame(Win32BaseWindow *win32wnd,DWORD flags)
1368{
1369 TRACKINFO track;
1370 RECTL rcl;
1371 PRECT pWindowRect, pClientRect;
1372 HWND hwndTracking;
1373 LONG parentHeight, parentWidth;
1374
1375 dprintf(("FrameTrackFrame: %x %x", win32wnd->getWindowHandle(), flags));
1376 track.cxBorder = 4;
1377 track.cyBorder = 4; /* 4 pel wide lines used for rectangle */
1378 track.cxGrid = 1;
1379 track.cyGrid = 1; /* smooth tracking with mouse */
1380 track.cxKeyboard = 8;
1381 track.cyKeyboard = 8; /* faster tracking using cursor keys */
1382
1383 pWindowRect = win32wnd->getWindowRect();
1384 if(win32wnd->getParent()) {
1385 parentHeight = win32wnd->getParent()->getClientHeight();
1386 parentWidth = win32wnd->getParent()->getClientWidth();
1387 hwndTracking = win32wnd->getParent()->getOS2WindowHandle();
1388 }
1389 else {
1390 parentHeight = OSLibQueryScreenHeight();
1391 parentWidth = OSLibQueryScreenWidth();
1392 hwndTracking = HWND_DESKTOP;
1393 }
1394
1395 mapWin32ToOS2Rect(parentHeight, pWindowRect, (PRECTLOS2)&track.rclTrack);
1396 rcl = track.rclTrack;
1397 WinQueryWindowRect(hwndTracking, &track.rclBoundary);
1398
1399 track.ptlMinTrackSize.x = 10;
1400 track.ptlMinTrackSize.y = 10; /* set smallest allowed size of rectangle */
1401 track.ptlMaxTrackSize.x = parentWidth;
1402 track.ptlMaxTrackSize.y = parentHeight; /* set largest allowed size of rectangle */
1403
1404 win32wnd->AdjustTrackInfo((PPOINT)&track.ptlMinTrackSize, (PPOINT)&track.ptlMaxTrackSize);
1405
1406 track.fs = flags;
1407
1408 if(WinTrackRect(hwndTracking, NULL, &track) )
1409 {
1410 /* if successful copy final position back */
1411 if(!WinEqualRect(0, &rcl, &track.rclTrack)) {
1412 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));
1413 if(flags == TF_MOVE) {
1414 WinSetWindowPos(win32wnd->getOS2FrameWindowHandle(),
1415 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
1416 0, 0, SWP_MOVE);
1417 }
1418 else {
1419 WinSetWindowPos(win32wnd->getOS2FrameWindowHandle(),
1420 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
1421 track.rclTrack.xRight - track.rclTrack.xLeft,
1422 track.rclTrack.yTop - track.rclTrack.yBottom,
1423 SWP_SIZE|SWP_MOVE);
1424 }
1425 }
1426 return;
1427 }
1428 return;
1429}
1430//******************************************************************************
1431//******************************************************************************
Note: See TracBrowser for help on using the repository browser.