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

Last change on this file since 4140 was 4140, checked in by phaller, 25 years ago

.

File size: 34.3 KB
Line 
1/* $Id: pmwindow.cpp,v 1.102 2000-09-01 01:36:15 phaller 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_ACTIVATE)
380 {
381 if(!(WinQueryWindowUShort(hwnd,QWS_FLAGS) & FF_ACTIVE)) {
382 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)TRUE, (MPARAM)hwnd);
383 }
384 }
385
386 if((pswp->fl & (SWP_MOVE | SWP_SIZE)) && !(win32wnd->getStyle() & WS_MINIMIZE_W))
387 {
388 //Note: Also updates the new window rectangle
389 win32wnd->MsgFormatFrame(&wp);
390
391 //CB: todo: use result for WM_CALCVALIDRECTS
392 mapWin32ToOS2RectFrame(win32wnd, win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
393
394 if(win32wnd->CanReceiveSizeMsgs())
395 win32wnd->MsgPosChanged((LPARAM)&wp);
396
397 if((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
398 {
399 //redraw the frame (to prevent unnecessary client updates)
400 BOOL redrawAll = FALSE;
401
402 if (win32wnd->getWindowClass())
403 {
404 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
405
406 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
407 redrawAll = TRUE;
408 else if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
409 redrawAll = TRUE;
410 } else redrawAll = TRUE;
411
412 if (redrawAll)
413 {
414 //CB: redraw all children for now
415 // -> problems with update region if we don't do it
416 // todo: rewrite whole handling
417 WinInvalidateRect(hwnd,NULL,TRUE);
418 }
419 else
420 {
421 HPS hps = WinGetPS(hwnd);
422 RECTL frame,client,arcl[4];
423
424 WinQueryWindowRect(hwnd,&frame);
425 //top
426 arcl[0].xLeft = 0;
427 arcl[0].xRight = frame.xRight;
428 arcl[0].yBottom = rect.yTop;
429 arcl[0].yTop = frame.yTop;
430 //right
431 arcl[1].xLeft = rect.xRight;
432 arcl[1].xRight = frame.xRight;
433 arcl[1].yBottom = 0;
434 arcl[1].yTop = frame.yTop;
435 //left
436 arcl[2].xLeft = 0;
437 arcl[2].xRight = rect.xLeft;
438 arcl[2].yBottom = 0;
439 arcl[2].yTop = frame.yTop;
440 //bottom
441 arcl[3].xLeft = 0;
442 arcl[3].xRight = frame.xRight;
443 arcl[3].yBottom = 0;
444 arcl[3].yTop = rect.yBottom;
445
446 HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
447
448 WinInvalidateRegion(hwnd,hrgn,FALSE);
449 GpiDestroyRegion(hps,hrgn);
450 WinReleasePS(hps);
451 }
452 }
453 }
454 else
455 {
456 if(win32wnd->CanReceiveSizeMsgs())
457 win32wnd->MsgPosChanged((LPARAM)&wp);
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 //**************************************************************************
593 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
594 //**************************************************************************
595 case WM_HITTEST:
596 {
597 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
598 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
599 }
600 if(win32wnd && win32wnd->IsWindowCreated())
601 {
602 MRESULT rc;
603
604 rc = (MRESULT)win32wnd->MsgHitTest(pWinMsg);
605 RestoreOS2TIB();
606 return rc;
607 }
608 return (MRESULT)HT_NORMAL;
609 }
610
611 case WM_BUTTON1DOWN:
612 case WM_BUTTON1UP:
613 case WM_BUTTON1DBLCLK:
614 case WM_BUTTON2DOWN:
615 case WM_BUTTON2UP:
616 case WM_BUTTON2DBLCLK:
617 case WM_BUTTON3DOWN:
618 case WM_BUTTON3UP:
619 case WM_BUTTON3DBLCLK:
620 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
621 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
622 }
623 if(win32wnd)
624 win32wnd->MsgButton(pWinMsg);
625 rc = TRUE;
626 break;
627
628 case WM_BUTTON2MOTIONSTART:
629 case WM_BUTTON2MOTIONEND:
630 case WM_BUTTON2CLICK:
631 case WM_BUTTON1MOTIONSTART:
632 case WM_BUTTON1MOTIONEND:
633 case WM_BUTTON1CLICK:
634 case WM_BUTTON3MOTIONSTART:
635 case WM_BUTTON3MOTIONEND:
636 case WM_BUTTON3CLICK:
637 rc = TRUE;
638 break;
639
640 case WM_MOUSEMOVE:
641 {
642 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
643 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
644 }
645 if(win32wnd)
646 win32wnd->MsgMouseMove(pWinMsg);
647 break;
648 }
649
650 case WM_CONTROL:
651 goto RunDefWndProc;
652
653 case WM_COMMAND:
654 dprintf(("OS2: WM_COMMAND %x %x %x", hwnd, mp1, mp2));
655 win32wnd->DispatchMsgA(pWinMsg);
656 break;
657
658 case WM_SYSCOMMAND:
659 win32wnd->DispatchMsgA(pWinMsg);
660 break;
661
662 case WM_CHAR:
663 win32wnd->MsgChar(pWinMsg);
664 break;
665
666 case WM_TIMER:
667 win32wnd->DispatchMsgA(pWinMsg);
668 goto RunDefWndProc;
669
670 case WM_SETWINDOWPARAMS:
671 {
672 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
673
674 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
675 if(wndParams->fsStatus & WPM_TEXT) {
676 win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText);
677 }
678 goto RunDefWndProc;
679 }
680
681 case WM_QUERYWINDOWPARAMS:
682 {
683 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
684 ULONG textlen;
685 PSZ wintext;
686
687 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
688 {
689 if(wndpars->fsStatus & WPM_TEXT)
690 win32wnd->MsgGetText(wndpars->pszText, wndpars->cchText);
691 if(wndpars->fsStatus & WPM_CCHTEXT)
692 wndpars->cchText = win32wnd->MsgGetTextLength();
693
694 wndpars->fsStatus = 0;
695 wndpars->cbCtlData = 0;
696 wndpars->cbPresParams = 0;
697 RestoreOS2TIB();
698 return (MRESULT)TRUE;
699 }
700 goto RunDefWndProc;
701 }
702
703 case WM_PAINT:
704 {
705 RECTL rectl;
706 BOOL rc;
707
708 rc = WinQueryUpdateRect(hwnd, &rectl);
709 dprintf(("OS2: WM_PAINT %x (%d,%d) (%d,%d) rc=%d", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop, rc));
710 if(rc && win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
711 rectl.yBottom != rectl.yTop))
712 {
713 PRECT pClient = win32wnd->getClientRectPtr();
714 PRECT pWindow = win32wnd->getWindowRect();
715
716 if(!(pClient->left == 0 && pClient->top == 0 &&
717 win32wnd->getClientHeight() == win32wnd->getWindowHeight() &&
718 win32wnd->getClientWidth() == win32wnd->getWindowWidth()))
719 {
720 win32wnd->MsgNCPaint();
721 }
722 win32wnd->DispatchMsgA(pWinMsg);
723 }
724 else goto RunDefWndProc;
725
726 //SvL: Not calling the default window procedure causes all sorts of
727 // strange problems (redraw & hanging app)
728 // -> check what WinBeginPaint does what we're forgetting in BeginPaint
729// WinQueryUpdateRect(hwnd, &rectl);
730// if(rectl.xLeft == 0 && rectl.yTop == 0 && rectl.xRight == 0 && rectl.yBottom == 0) {
731// RestoreOS2TIB();
732// return (MRESULT)FALSE;
733// }
734// dprintf(("Update rectangle (%d,%d)(%d,%d) not empty, msg %x", rectl.xLeft, rectl.yTop, rectl.xRight, rectl.yBottom, pWinMsg->message));
735// goto RunDefWndProc;
736 break;
737 }
738
739 case WM_ERASEBACKGROUND:
740 {
741 dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
742 RestoreOS2TIB();
743 return (MRESULT)FALSE;
744 }
745
746#if 0
747 case WM_CONTEXTMENU:
748 {
749 win32wnd->DispatchMsgA(pWinMsg);
750
751 RestoreOS2TIB();
752 return (MRESULT)TRUE;
753 }
754#endif
755
756 case WM_FOCUSCHANGE:
757 {
758 HWND hwndFocus = (HWND)mp1;
759 HWND hwndLoseFocus, hwndGainFocus;
760 USHORT usSetFocus = SHORT1FROMMP(mp2);
761 USHORT fsFocusChange = SHORT2FROMMP(mp2);
762
763 dprintf(("OS2: WM_FOCUSCHANGE (start) %x %x %x %x", win32wnd->getWindowHandle(), hwndFocus, usSetFocus, fsFocusChange));
764 RestoreOS2TIB();
765 if(usSetFocus) {
766 hwndGainFocus = hwnd;
767 hwndLoseFocus = hwndFocus;
768 }
769 else {
770 hwndGainFocus = hwndFocus;
771 hwndLoseFocus = hwnd;
772 }
773 if(!(fsFocusChange & FC_NOLOSEFOCUS)) {
774 WinSendMsg(hwndLoseFocus, WM_SETFOCUS, (MPARAM)hwndGainFocus, (MPARAM)0);
775 }
776 //TODO: Don't send WM_SETSELECTION to child window if frame already has selection
777 if(!(fsFocusChange & FC_NOLOSESELECTION)) {
778 WinSendMsg(hwndLoseFocus, WM_SETSELECTION, (MPARAM)0, (MPARAM)0);
779 }
780 //SvL: Check if window is still valid
781 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
782 if(win32wnd == NULL) {
783 return (MRESULT)rc;
784 }
785
786
787 if(usSetFocus)
788 {
789 Win32BaseWindow *winfocus = Win32BaseWindow::GetWindowFromOS2Handle(hwndLoseFocus);
790 if(!(fsFocusChange & FC_NOLOSEACTIVE))
791 {
792 if(!winfocus || (winfocus->GetTopParent() != win32wnd->GetTopParent()))
793 {
794 if(winfocus)
795 WinSendMsg(winfocus->GetTopParent()->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)0, (MPARAM)hwndGainFocus);
796 else
797 WinSendMsg(hwndLoseFocus, WM_ACTIVATE, (MPARAM)0, (MPARAM)hwndGainFocus);
798 }
799 }
800 //SvL: Check if window is still valid
801 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
802 if(win32wnd == NULL)
803 return (MRESULT)rc;
804
805 if(!(fsFocusChange & FC_NOSETACTIVE))
806 {
807 Win32BaseWindow *topparent = win32wnd->GetTopParent();
808 if(!winfocus || (winfocus->GetTopParent() != topparent))
809 {
810 if(!(fsFocusChange & FC_NOBRINGTOTOP))
811 {
812 if(topparent) {
813 //put window at the top of z order
814 WinSetWindowPos(topparent->getOS2WindowHandle(), HWND_TOP, 0, 0, 0, 0, SWP_ZORDER);
815 }
816 }
817
818 // PH 2000/09/01 Netscape 4.7
819 // check if topparent is valid
820 if (topparent)
821 WinSendMsg(topparent->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)1, (MPARAM)hwndLoseFocus);
822 }
823 }
824 }
825 else /* no usSetFocus */
826 {
827 Win32BaseWindow *winfocus = Win32BaseWindow::GetWindowFromOS2Handle(hwndGainFocus);
828 if(!(fsFocusChange & FC_NOLOSEACTIVE))
829 {
830 Win32BaseWindow *topparent = win32wnd->GetTopParent();
831
832 if(!winfocus || (winfocus->GetTopParent() != topparent))
833 {
834 // PH 2000/09/01 Netscape 4.7
835 // check if topparent is valid
836 if (topparent)
837 WinSendMsg(topparent->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)0, (MPARAM)hwndGainFocus);
838 }
839 }
840 //SvL: Check if window is still valid
841 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
842 if(win32wnd == NULL)
843 return (MRESULT)rc;
844
845 if(!(fsFocusChange & FC_NOSETACTIVE))
846 {
847 if(!winfocus || (winfocus->GetTopParent() != win32wnd->GetTopParent()))
848 {
849 if(winfocus)
850 {
851 // PH 2000/09/01 Netscape 4.7
852 // check if topparent is valid
853 Win32BaseWindow *topparent = winfocus->GetTopParent();
854 if (topparent)
855 WinSendMsg(topparent->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)1, (MPARAM)hwndLoseFocus);
856 }
857 else
858 WinSendMsg(hwndGainFocus, WM_ACTIVATE, (MPARAM)1, (MPARAM)hwndLoseFocus);
859 }
860 }
861 }
862
863
864 //TODO: Don't send WM_SETSELECTION to child window if frame already has selection
865 if(!(fsFocusChange & FC_NOSETSELECTION)) {
866 WinSendMsg(hwndGainFocus, WM_SETSELECTION, (MPARAM)1, (MPARAM)0);
867 }
868
869 if(!(fsFocusChange & FC_NOSETFOCUS)) {
870 WinSendMsg(hwndGainFocus, WM_SETFOCUS, (MPARAM)hwndLoseFocus, (MPARAM)1);
871 }
872#ifdef DEBUG
873 SetWin32TIB();
874 dprintf(("OS2: WM_FOCUSCHANGE (end) %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
875 RestoreOS2TIB();
876#endif
877 return (MRESULT)rc;
878 }
879
880 case WM_QUERYTRACKINFO:
881 {
882 PTRACKINFO trackInfo = (PTRACKINFO)mp2;
883
884 dprintf(("OS2: WM_QUERYTRACKINFO %x", win32wnd->getWindowHandle()));
885 trackInfo->cxBorder = 4;
886 trackInfo->cyBorder = 4;
887 win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
888 RestoreOS2TIB();
889 return (MRESULT)TRUE;
890 }
891
892 case WM_QUERYBORDERSIZE:
893 {
894 PWPOINT size = (PWPOINT)mp1;
895
896 dprintf(("OS2: WM_QUERYBORDERSIZE %x", win32wnd->getWindowHandle()));
897
898 size->x = 0;
899 size->y = 0;
900 RestoreOS2TIB();
901 return (MRESULT)TRUE;
902 }
903
904 case WM_REALIZEPALETTE:
905 {
906 dprintf(("OS2: WM_REALIZEPALETTE"));
907 goto RunDefWndProc;
908 }
909
910 case WM_OWNERPOSCHANGE:
911 {
912 dprintf(("OS2: WM_OWNERPOSCHANGE"));
913 goto RunDefWndProc;
914 }
915
916 case WM_FORMATFRAME:
917 dprintf(("OS2: WM_FORMATFRAME %x", win32wnd->getWindowHandle()));
918// goto RunDefWndProc;
919 break;
920
921 case WM_ADJUSTFRAMEPOS:
922 {
923 PSWP pswp = (PSWP)mp1;
924
925 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));
926 break;
927 }
928
929 case WM_QUERYFRAMEINFO:
930 dprintf(("OS2: WM_QUERYFRAMEINFO %x", win32wnd->getWindowHandle()));
931 return (MRESULT)(FI_FRAME|FI_ACTIVATEOK);
932
933 case WM_QUERYFOCUSCHAIN:
934 {
935 USHORT fsCmd = SHORT1FROMMP(mp1);
936
937 dprintf(("OS2: WM_QUERYFOCUSCHAIN %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
938#if 1
939 goto RunDefWndProc;
940#else
941 switch(fsCmd) {
942 case QFC_NEXTINCHAIN:
943 break;
944 case QFC_ACTIVE:
945 case QFC_FRAME:
946 if(win32wnd->GetTopParent()) {
947 dprintf(("Frame = %x", win32wnd->GetTopParent()->getOS2WindowHandle()));
948 return (MRESULT)win32wnd->GetTopParent()->getOS2WindowHandle();
949 }
950 break;
951 case QFC_SELECTACTIVE:
952 break;
953 case QFC_PARTOFCHAIN:
954 return (MRESULT)TRUE;
955 }
956 break;
957#endif
958 }
959
960 case WM_INITMENU:
961 case WM_MENUSELECT:
962 case WM_MENUEND:
963 case WM_NEXTMENU:
964 case WM_SYSCOLORCHANGE:
965 case WM_SYSVALUECHANGED:
966 case WM_SETSELECTION:
967 case WM_PPAINT:
968 case WM_PSETFOCUS:
969 case WM_PSYSCOLORCHANGE:
970 case WM_PSIZE:
971 case WM_PACTIVATE:
972 case WM_PCONTROL:
973 case WM_HELP:
974 case WM_APPTERMINATENOTIFY:
975 case WM_PRESPARAMCHANGED:
976 case WM_DRAWITEM:
977 case WM_MEASUREITEM:
978 case WM_CONTROLPOINTER:
979 case WM_QUERYDLGCODE:
980 case WM_SUBSTITUTESTRING:
981 case WM_MATCHMNEMONIC:
982 case WM_SAVEAPPLICATION:
983 case WM_SEMANTICEVENT:
984 default:
985// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
986 RestoreOS2TIB();
987 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
988 }
989 RestoreOS2TIB();
990 return (MRESULT)rc;
991
992RunDefWndProc:
993// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
994 RestoreOS2TIB();
995 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
996} /* End of Win32WindowProc */
997//******************************************************************************
998//TODO: Quickly moving a window two times doesn't force a repaint (1st time)
999//******************************************************************************
1000VOID FrameTrackFrame(Win32BaseWindow *win32wnd,DWORD flags)
1001{
1002 TRACKINFO track;
1003 RECTL rcl;
1004 PRECT pWindowRect;
1005 HWND hwndTracking;
1006 HPS hpsTrack;
1007 LONG parentHeight, parentWidth;
1008
1009 dprintf(("FrameTrackFrame: %x %x", win32wnd->getWindowHandle(), flags));
1010 track.cxBorder = 4;
1011 track.cyBorder = 4; /* 4 pel wide lines used for rectangle */
1012 track.cxGrid = 1;
1013 track.cyGrid = 1; /* smooth tracking with mouse */
1014 track.cxKeyboard = 8;
1015 track.cyKeyboard = 8; /* faster tracking using cursor keys */
1016
1017 pWindowRect = win32wnd->getWindowRect();
1018 if(win32wnd->getParent()) {
1019 parentHeight = win32wnd->getParent()->getWindowHeight();
1020 parentWidth = win32wnd->getParent()->getWindowWidth();
1021 hwndTracking = win32wnd->getParent()->getOS2WindowHandle();
1022 hpsTrack = WinGetPS(hwndTracking);
1023 }
1024 else {
1025 parentHeight = OSLibQueryScreenHeight();
1026 parentWidth = OSLibQueryScreenWidth();
1027 hwndTracking = HWND_DESKTOP;
1028 hpsTrack = NULL;
1029 }
1030
1031 rcl.xLeft = pWindowRect->left;
1032 rcl.yTop = OSLibQueryScreenHeight() - pWindowRect->top;
1033 rcl.xRight = pWindowRect->right;
1034 rcl.yBottom = OSLibQueryScreenHeight() - pWindowRect->bottom;
1035 if(hwndTracking != HWND_DESKTOP) {
1036 WinMapWindowPoints(win32wnd->getOS2WindowHandle(), HWND_DESKTOP, (PPOINTL)&rcl, 2);
1037 }
1038 WinCopyRect(hab, &track.rclTrack, &rcl); /* starting point */
1039
1040 WinSetRect(hab, &track.rclBoundary, 0, 0, parentWidth, parentHeight); /* bounding rectangle */
1041
1042 track.ptlMinTrackSize.x = 10;
1043 track.ptlMinTrackSize.y = 10; /* set smallest allowed size of rectangle */
1044 track.ptlMaxTrackSize.x = parentWidth;
1045 track.ptlMaxTrackSize.y = parentHeight; /* set largest allowed size of rectangle */
1046
1047 win32wnd->AdjustTrackInfo((PPOINT)&track.ptlMinTrackSize, (PPOINT)&track.ptlMaxTrackSize);
1048
1049 track.fs = flags;
1050
1051 if(WinTrackRect(HWND_DESKTOP, NULL, &track) )
1052 {
1053 if(hpsTrack) WinReleasePS(hpsTrack);
1054
1055 /* if successful copy final position back */
1056 if(!WinEqualRect(0, &rcl, &track.rclTrack)) {
1057 if(flags == TF_MOVE) {
1058 WinSetWindowPos(win32wnd->getOS2WindowHandle(),
1059 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
1060 0, 0, SWP_MOVE);
1061 }
1062 else {
1063 WinSetWindowPos(win32wnd->getOS2WindowHandle(),
1064 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
1065 track.rclTrack.xRight - track.rclTrack.xLeft,
1066 track.rclTrack.yTop - track.rclTrack.yBottom,
1067 SWP_SIZE|SWP_MOVE);
1068 }
1069 }
1070 return;
1071 }
1072 if(hpsTrack) WinReleasePS(hpsTrack);
1073 return;
1074}
1075//******************************************************************************
1076//******************************************************************************
Note: See TracBrowser for help on using the repository browser.