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

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

fix for excessive redrawing in Notes

File size: 29.3 KB
Line 
1/* $Id: pmwindow.cpp,v 1.95 2000-06-14 14:25:57 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 RestoreOS2TIB();
203 PMFrameWindowProc(hwnd, msg, mp1, mp2);
204 SetWin32TIB();
205
206 if(thdb->newWindow == 0)
207 goto createfail;
208
209 //Processing is done in after WinCreateWindow returns
210 dprintf(("OS2: WM_CREATE %x", hwnd));
211 win32wnd = (Win32BaseWindow *)thdb->newWindow;
212 thdb->newWindow = 0;
213 if(win32wnd->MsgCreate(hwnd) == FALSE)
214 {
215 RestoreOS2TIB();
216 return (MRESULT)TRUE; //discontinue window creation
217 }
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 RunDefFrameProc;
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 WinSetWindowUShort(hwnd,QWS_FLAGS, SHORT1FROMMP(mp1) ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
453 if(win32wnd->IsWindowCreated())
454 {
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 RestoreOS2TIB();
466 return 0;
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 goto RunDefWndProc;
473 }
474
475 case WM_MINMAXFRAME:
476 {
477 PSWP swp = (PSWP)mp1;
478
479 if (!win32wnd->IsWindowCreated()) goto RunDefFrameProc;
480 dprintf(("OS2: WM_MINMAXFRAME %x",hwnd));
481 if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
482 {
483 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MINIMIZE_W) | WS_MAXIMIZE_W);
484
485 RECT rect;
486
487 rect.left = rect.top = rect.right = rect.bottom = 0;
488 win32wnd->AdjustMaximizedRect(&rect);
489 swp->x += rect.left;
490 swp->cx += rect.right-rect.left;
491 swp->y -= rect.bottom;
492 swp->cy += rect.bottom-rect.top;
493 }
494 else if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
495 {
496 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
497 }
498 else if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
499 {
500 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
501 }
502 goto RunDefFrameProc;
503 }
504
505 case WM_OWNERPOSCHANGE:
506 {
507 dprintf(("OS2: WM_OWNERPOSCHANGE"));
508 goto RunDefWndProc;
509 }
510
511 case WM_CALCVALIDRECTS:
512#if 0
513 {
514 PRECTL oldRect = (PRECTL)mp1,newRect = oldRect+1;
515 UINT res = CVR_ALIGNLEFT | CVR_ALIGNTOP;
516
517//CB: todo: use WM_NCCALCSIZE result
518 if (win32wnd->getWindowClass())
519 {
520 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
521
522 if ((dwStyle & CS_HREDRAW_W) && (newRect->xRight-newRect->xLeft != oldRect->xRight-oldRect->xLeft))
523 res |= CVR_REDRAW;
524 else if ((dwStyle & CS_VREDRAW_W) && (newRect->yTop-newRect->yBottom != oldRect->yTop-oldRect->yBottom))
525 res |= CVR_REDRAW;
526 } else res |= CVR_REDRAW;
527
528 RestoreOS2TIB();
529 return (MRESULT)res;
530 }
531#else
532 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
533 RestoreOS2TIB();
534 return (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
535#endif
536
537 case WM_VRNENABLED:
538 if(!win32wnd->isComingToTop() && ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == WS_EX_TOPMOST_W))
539 {
540 HWND hwndrelated;
541 Win32BaseWindow *topwindow;
542
543 win32wnd->setComingToTop(TRUE);
544
545 hwndrelated = WinQueryWindow(hwnd, QW_PREV);
546 dprintf(("WM_VRNENABLED hwndrelated = %x (hwnd=%x)", hwndrelated, hwnd));
547 topwindow = Win32BaseWindow::GetWindowFromOS2Handle(hwndrelated);
548 if(topwindow == NULL || ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == 0)) {
549 //put window at the top of z order
550 WinSetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER );
551 }
552
553 win32wnd->setComingToTop(FALSE);
554 break;
555 }
556 goto RunDefWndProc;
557
558 case WM_SETFOCUS:
559 {
560 HWND hwndFocus = (HWND)mp1;
561
562 dprintf(("OS2: WM_SETFOCUS %x %x %d", win32wnd->getWindowHandle(), mp1, mp2));
563 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
564 //another (non-win32) application's window
565 //set to NULL (allowed according to win32 SDK) to avoid problems
566 hwndFocus = NULL;
567 }
568 if((ULONG)mp2 == TRUE) {
569 HWND hwndFocusWin32 = Win32BaseWindow::OS2ToWin32Handle(hwndFocus);
570 recreateCaret (hwndFocusWin32);
571 win32wnd->MsgSetFocus(hwndFocusWin32);
572 }
573 else win32wnd->MsgKillFocus(Win32BaseWindow::OS2ToWin32Handle(hwndFocus));
574 break;
575 }
576
577 //**************************************************************************
578 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
579 //**************************************************************************
580 case WM_HITTEST:
581 {
582 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
583 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
584 }
585 if(win32wnd && win32wnd->IsWindowCreated())
586 {
587 MRESULT rc;
588
589 rc = (MRESULT)win32wnd->MsgHitTest(pWinMsg);
590 RestoreOS2TIB();
591 return rc;
592 }
593 return (MRESULT)HT_NORMAL;
594 }
595
596 case WM_BUTTON1DOWN:
597 case WM_BUTTON1UP:
598 case WM_BUTTON1DBLCLK:
599 case WM_BUTTON2DOWN:
600 case WM_BUTTON2UP:
601 case WM_BUTTON2DBLCLK:
602 case WM_BUTTON3DOWN:
603 case WM_BUTTON3UP:
604 case WM_BUTTON3DBLCLK:
605 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
606 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
607 }
608 if(win32wnd)
609 win32wnd->MsgButton(pWinMsg);
610 rc = TRUE;
611 break;
612
613 case WM_BUTTON2MOTIONSTART:
614 case WM_BUTTON2MOTIONEND:
615 case WM_BUTTON2CLICK:
616 case WM_BUTTON1MOTIONSTART:
617 case WM_BUTTON1MOTIONEND:
618 case WM_BUTTON1CLICK:
619 case WM_BUTTON3MOTIONSTART:
620 case WM_BUTTON3MOTIONEND:
621 case WM_BUTTON3CLICK:
622 rc = TRUE;
623 break;
624
625 case WM_MOUSEMOVE:
626 {
627 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
628 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
629 }
630 if(win32wnd)
631 win32wnd->MsgMouseMove(pWinMsg);
632 break;
633 }
634
635 case WM_CONTROL:
636 goto RunDefWndProc;
637
638 case WM_COMMAND:
639 dprintf(("OS2: WM_COMMAND %x %x %x", hwnd, mp1, mp2));
640 win32wnd->DispatchMsgA(pWinMsg);
641 break;
642
643 case WM_SYSCOMMAND:
644 win32wnd->DispatchMsgA(pWinMsg);
645 break;
646
647 case WM_CHAR:
648 win32wnd->MsgChar(pWinMsg);
649 break;
650
651 case WM_TIMER:
652 win32wnd->DispatchMsgA(pWinMsg);
653 goto RunDefWndProc;
654
655 case WM_SETWINDOWPARAMS:
656 {
657 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
658
659 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
660 if(wndParams->fsStatus & WPM_TEXT) {
661 win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText);
662 }
663 goto RunDefWndProc;
664 }
665
666 case WM_QUERYWINDOWPARAMS:
667 {
668 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
669 ULONG textlen;
670 PSZ wintext;
671
672 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
673 {
674 if(wndpars->fsStatus & WPM_TEXT)
675 win32wnd->MsgGetText(wndpars->pszText, wndpars->cchText);
676 if(wndpars->fsStatus & WPM_CCHTEXT)
677 wndpars->cchText = win32wnd->MsgGetTextLength();
678
679 wndpars->fsStatus = 0;
680 wndpars->cbCtlData = 0;
681 wndpars->cbPresParams = 0;
682 RestoreOS2TIB();
683 return (MRESULT)TRUE;
684 }
685 goto RunDefWndProc;
686 }
687
688 case WM_PAINT:
689 {
690 RECTL rectl;
691 BOOL rc;
692
693 rc = WinQueryUpdateRect(hwnd, &rectl);
694 dprintf(("OS2: WM_PAINT (%d,%d) (%d,%d)", rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop));
695 if(rc && win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
696 rectl.yBottom != rectl.yTop))
697 {
698 PRECT pClient = win32wnd->getClientRectPtr();
699 PRECT pWindow = win32wnd->getWindowRect();
700
701 if(!(pClient->left == 0 && pClient->top == 0 &&
702 win32wnd->getClientHeight() == win32wnd->getWindowHeight() &&
703 win32wnd->getClientWidth() == win32wnd->getWindowWidth()))
704 {
705 win32wnd->MsgNCPaint();
706 }
707 win32wnd->DispatchMsgA(pWinMsg);
708 }
709 else goto RunDefWndProc;
710
711 //SvL: Not calling the default window procedure causes all sorts of
712 // strange problems (redraw & hanging app)
713 // -> check what WinBeginPaint does what we're forgetting in BeginPaint
714// WinQueryUpdateRect(hwnd, &rectl);
715// if(rectl.xLeft == 0 && rectl.yTop == 0 && rectl.xRight == 0 && rectl.yBottom == 0) {
716// RestoreOS2TIB();
717// return (MRESULT)FALSE;
718// }
719// dprintf(("Update rectangle (%d,%d)(%d,%d) not empty, msg %x", rectl.xLeft, rectl.yTop, rectl.xRight, rectl.yBottom, pWinMsg->message));
720// goto RunDefWndProc;
721 break;
722 }
723
724 case WM_ERASEBACKGROUND:
725 {
726 dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
727 RestoreOS2TIB();
728 return (MRESULT)FALSE;
729 }
730
731#if 0
732 case WM_CONTEXTMENU:
733 {
734 win32wnd->DispatchMsgA(pWinMsg);
735
736 RestoreOS2TIB();
737 return (MRESULT)TRUE;
738 }
739#endif
740
741 case WM_FOCUSCHANGE:
742 dprintf(("OS2: WM_FOCUSCHANGE %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
743 goto RunDefFrameProc; //partly responsible for activation of frame windows
744
745 case WM_QUERYTRACKINFO:
746 {
747 PTRACKINFO trackInfo = (PTRACKINFO)mp2;
748
749 dprintf(("OS2: WM_QUERYTRACKINFO %x", win32wnd->getWindowHandle()));
750 RestoreOS2TIB();
751 PMFrameWindowProc(hwnd,msg,mp1,mp2);
752 SetWin32TIB();
753 trackInfo->cxBorder = 4;
754 trackInfo->cyBorder = 4;
755 win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
756 RestoreOS2TIB();
757 return (MRESULT)TRUE;
758 }
759
760 case WM_QUERYBORDERSIZE:
761 {
762 PWPOINT size = (PWPOINT)mp1;
763
764 dprintf(("OS2: WM_QUERYBORDERSIZE %x", win32wnd->getWindowHandle()));
765
766 size->x = 0;
767 size->y = 0;
768 RestoreOS2TIB();
769 return (MRESULT)TRUE;
770 }
771
772 case WM_FORMATFRAME:
773 dprintf(("OS2: WM_FORMATFRAME %x", win32wnd->getWindowHandle()));
774 break;
775
776#if 0
777 case WM_ADJUSTFRAMEPOS:
778 dprintf(("OS2: WM_ADJUSTFRAMEPOS %x", win32wnd->getWindowHandle()));
779 break;
780
781 case WM_QUERYFRAMEINFO:
782 dprintf(("OS2: WM_QUERYFRAMEINFO %x", win32wnd->getWindowHandle()));
783 return (MRESULT)(FI_FRAME|FI_ACTIVATEOK);
784
785 case WM_QUERYFOCUSCHAIN:
786 {
787 USHORT fsCmd = SHORT1FROMMP(mp1);
788
789 dprintf(("OS2: WM_QUERYFOCUSCHAIN %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
790 switch(fsCmd) {
791 case QFC_NEXTINCHAIN:
792 break;
793 case QFC_ACTIVE:
794 case QFC_FRAME:
795 if(win32wnd->GetTopParent()) {
796 dprintf(("Frame = %x", win32wnd->GetTopParent()->getOS2WindowHandle()));
797 return (MRESULT)win32wnd->GetTopParent()->getOS2WindowHandle();
798 }
799 break;
800 case QFC_SELECTACTIVE:
801 break;
802 case QFC_PARTOFCHAIN:
803 return (MRESULT)TRUE;
804 }
805 break;
806 }
807#endif
808
809 case WM_INITMENU:
810 case WM_MENUSELECT:
811 case WM_MENUEND:
812 case WM_NEXTMENU:
813 case WM_SYSCOLORCHANGE:
814 case WM_SYSVALUECHANGED:
815 case WM_SETSELECTION:
816 case WM_PPAINT:
817 case WM_PSETFOCUS:
818 case WM_PSYSCOLORCHANGE:
819 case WM_PSIZE:
820 case WM_PACTIVATE:
821 case WM_PCONTROL:
822 case WM_HELP:
823 case WM_APPTERMINATENOTIFY:
824 case WM_PRESPARAMCHANGED:
825 case WM_DRAWITEM:
826 case WM_MEASUREITEM:
827 case WM_CONTROLPOINTER:
828 case WM_QUERYDLGCODE:
829 case WM_SUBSTITUTESTRING:
830 case WM_MATCHMNEMONIC:
831 case WM_SAVEAPPLICATION:
832 case WM_SEMANTICEVENT:
833 default:
834// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
835 RestoreOS2TIB();
836 return PMFrameWindowProc(hwnd, msg, mp1, mp2);
837// return WinDefWindowProc( hwnd, msg, mp1, mp2 );
838 }
839 RestoreOS2TIB();
840 return (MRESULT)rc;
841
842RunDefFrameProc:
843 RestoreOS2TIB();
844 return PMFrameWindowProc(hwnd, msg, mp1, mp2);
845
846RunDefWndProc:
847// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
848 RestoreOS2TIB();
849 return PMFrameWindowProc(hwnd, msg, mp1, mp2);
850// return WinDefWindowProc( hwnd, msg, mp1, mp2 );
851} /* End of Win32WindowProc */
852//******************************************************************************
853//TODO: Quickly moving a window two times doesn't force a repaint (1st time)
854//******************************************************************************
855VOID FrameTrackFrame(Win32BaseWindow *win32wnd,DWORD flags)
856{
857 TRACKINFO track;
858 RECTL rcl;
859 PRECT pWindowRect;
860 HWND hwndTracking;
861 HPS hpsTrack;
862 LONG parentHeight, parentWidth;
863
864 track.cxBorder = 4;
865 track.cyBorder = 4; /* 4 pel wide lines used for rectangle */
866 track.cxGrid = 1;
867 track.cyGrid = 1; /* smooth tracking with mouse */
868 track.cxKeyboard = 8;
869 track.cyKeyboard = 8; /* faster tracking using cursor keys */
870
871 pWindowRect = win32wnd->getWindowRect();
872 if(win32wnd->getParent()) {
873 parentHeight = win32wnd->getParent()->getWindowHeight();
874 parentWidth = win32wnd->getParent()->getWindowWidth();
875 hwndTracking = win32wnd->getParent()->getOS2WindowHandle();
876 hpsTrack = WinGetPS(hwndTracking);
877 }
878 else {
879 parentHeight = OSLibQueryScreenHeight();
880 parentWidth = OSLibQueryScreenWidth();
881 hwndTracking = HWND_DESKTOP;
882 hpsTrack = NULL;
883 }
884
885 rcl.xLeft = pWindowRect->left;
886 rcl.yTop = OSLibQueryScreenHeight() - pWindowRect->top;
887 rcl.xRight = pWindowRect->right;
888 rcl.yBottom = OSLibQueryScreenHeight() - pWindowRect->bottom;
889 if(hwndTracking != HWND_DESKTOP) {
890 WinMapWindowPoints(win32wnd->getOS2WindowHandle(), HWND_DESKTOP, (PPOINTL)&rcl, 2);
891 }
892 WinCopyRect(hab, &track.rclTrack, &rcl); /* starting point */
893
894 WinSetRect(hab, &track.rclBoundary, 0, 0, parentWidth, parentHeight); /* bounding rectangle */
895
896 track.ptlMinTrackSize.x = 10;
897 track.ptlMinTrackSize.y = 10; /* set smallest allowed size of rectangle */
898 track.ptlMaxTrackSize.x = parentWidth;
899 track.ptlMaxTrackSize.y = parentHeight; /* set largest allowed size of rectangle */
900
901 win32wnd->AdjustTrackInfo((PPOINT)&track.ptlMinTrackSize, (PPOINT)&track.ptlMaxTrackSize);
902
903 track.fs = flags;
904
905 if(WinTrackRect(HWND_DESKTOP, NULL, &track) )
906 {
907 if(hpsTrack) WinReleasePS(hpsTrack);
908
909 /* if successful copy final position back */
910 if(!WinEqualRect(0, &rcl, &track.rclTrack)) {
911 if(flags == TF_MOVE) {
912 WinSetWindowPos(win32wnd->getOS2WindowHandle(),
913 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
914 0, 0, SWP_MOVE);
915 }
916 else {
917 WinSetWindowPos(win32wnd->getOS2WindowHandle(),
918 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
919 track.rclTrack.xRight - track.rclTrack.xLeft,
920 track.rclTrack.yTop - track.rclTrack.yBottom,
921 SWP_SIZE|SWP_MOVE);
922 }
923 }
924 return;
925 }
926 if(hpsTrack) WinReleasePS(hpsTrack);
927 return;
928}
929//******************************************************************************
930//******************************************************************************
Note: See TracBrowser for help on using the repository browser.