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

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

more logging

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