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

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

lots of fixes + changes (see ChangeLog)

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