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

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

Rewrote Set/GetViewportExtEx, Set/GetMapMode & moved them from gdi32 to user32 + titlebar fix

File size: 32.3 KB
Line 
1/* $Id: pmwindow.cpp,v 1.98 2000-07-04 08:42:06 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) wp.hwndInsertAfter = wndAfter->getWindowHandle();
296 }
297
298 wpOld = wp;
299 win32wnd->MsgPosChanging((LPARAM)&wp);
300
301 if ((wp.hwndInsertAfter != wpOld.hwndInsertAfter) ||
302 (wp.x != wpOld.x) || (wp.y != wpOld.y) || (wp.cx != wpOld.cx) || (wp.cy != wpOld.cy) || (wp.flags != wpOld.flags))
303 {
304 dprintf(("OS2: WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
305 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
306
307 if(win32wnd->getParent()) {
308 OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, win32wnd->getParent()->getWindowHeight(),
309 win32wnd->getParent()->getClientRectPtr()->left,
310 win32wnd->getParent()->getClientRectPtr()->top,
311 hwnd);
312 }
313 else OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
314
315 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
316 pswp->fl |= SWP_NOADJUST;
317 pswp->hwndInsertBehind = hwndAfter;
318 pswp->hwnd = hwnd;
319
320 RestoreOS2TIB();
321 return (MRESULT)0xf;
322 }
323 RestoreOS2TIB();
324 return (MRESULT)0;
325 }
326
327 case WM_WINDOWPOSCHANGED:
328 {
329 PSWP pswp = (PSWP)mp1,pswpOld = pswp+1;
330 SWP swpOld = *(pswp + 1);
331 WINDOWPOS wp;
332 HWND hParent = NULLHANDLE;
333 RECTL rect;
334
335 dprintf(("OS2: WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
336
337 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
338 {
339 if(pswp->fl & SWP_ACTIVATE)
340 {
341 if(!(WinQueryWindowUShort(hwnd,QWS_FLAGS) & FF_ACTIVE)) {
342 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)TRUE, (MPARAM)hwnd);
343 }
344 }
345 goto RunDefWndProc;
346 }
347
348 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
349 if(win32wnd->isChild()) {
350 if(win32wnd->getParent()) {
351 hParent = win32wnd->getParent()->getOS2WindowHandle();
352 }
353 else goto PosChangedEnd; //parent has just been destroyed
354 }
355 }
356
357
358 if(win32wnd->getParent()) {
359 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getWindowHeight(),
360 win32wnd->getParent()->getClientRectPtr()->left,
361 win32wnd->getParent()->getClientRectPtr()->top,
362 hwnd);
363 }
364 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
365
366 if(pswp->fl & SWP_ACTIVATE)
367 {
368 if(!(WinQueryWindowUShort(hwnd,QWS_FLAGS) & FF_ACTIVE)) {
369 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)TRUE, (MPARAM)hwnd);
370 }
371 }
372
373 if((pswp->fl & (SWP_MOVE | SWP_SIZE)) && !(win32wnd->getStyle() & WS_MINIMIZE_W))
374 {
375 //Note: Also updates the new window rectangle
376 win32wnd->MsgFormatFrame(&wp);
377
378 //CB: todo: use result for WM_CALCVALIDRECTS
379 mapWin32ToOS2RectFrame(win32wnd, win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
380
381 if(win32wnd->CanReceiveSizeMsgs())
382 win32wnd->MsgPosChanged((LPARAM)&wp);
383
384 if((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
385 {
386 //redraw the frame (to prevent unnecessary client updates)
387 BOOL redrawAll = FALSE;
388
389 if (win32wnd->getWindowClass())
390 {
391 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
392
393 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
394 redrawAll = TRUE;
395 else if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
396 redrawAll = TRUE;
397 } else redrawAll = TRUE;
398
399 if (redrawAll)
400 {
401 //CB: redraw all children for now
402 // -> problems with update region if we don't do it
403 // todo: rewrite whole handling
404 WinInvalidateRect(hwnd,NULL,TRUE);
405 }
406 else
407 {
408 HPS hps = WinGetPS(hwnd);
409 RECTL frame,client,arcl[4];
410
411 WinQueryWindowRect(hwnd,&frame);
412 //top
413 arcl[0].xLeft = 0;
414 arcl[0].xRight = frame.xRight;
415 arcl[0].yBottom = rect.yTop;
416 arcl[0].yTop = frame.yTop;
417 //right
418 arcl[1].xLeft = rect.xRight;
419 arcl[1].xRight = frame.xRight;
420 arcl[1].yBottom = 0;
421 arcl[1].yTop = frame.yTop;
422 //left
423 arcl[2].xLeft = 0;
424 arcl[2].xRight = rect.xLeft;
425 arcl[2].yBottom = 0;
426 arcl[2].yTop = frame.yTop;
427 //bottom
428 arcl[3].xLeft = 0;
429 arcl[3].xRight = frame.xRight;
430 arcl[3].yBottom = 0;
431 arcl[3].yTop = rect.yBottom;
432
433 HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
434
435 WinInvalidateRegion(hwnd,hrgn,FALSE);
436 GpiDestroyRegion(hps,hrgn);
437 WinReleasePS(hps);
438 }
439 }
440 }
441 else
442 {
443 if(win32wnd->CanReceiveSizeMsgs())
444 win32wnd->MsgPosChanged((LPARAM)&wp);
445 }
446
447PosChangedEnd:
448 RestoreOS2TIB();
449 return (MRESULT)FALSE;
450 }
451
452 case WM_ACTIVATE:
453 {
454 USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
455
456 dprintf(("OS2: WM_ACTIVATE %x %x %x", hwnd, mp1, mp2));
457
458 WinSetWindowUShort(hwnd,QWS_FLAGS, SHORT1FROMMP(mp1) ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
459 if(win32wnd->IsWindowCreated())
460 {
461 win32wnd->MsgActivate((LOWORD(pWinMsg->wParam) == WA_ACTIVE_W) ? 1 : 0, HIWORD(pWinMsg->wParam), pWinMsg->lParam, (HWND)mp2);
462
463 //CB: show owner behind the dialog
464 if(win32wnd->IsModalDialog())
465 {
466 Win32BaseWindow *topOwner = win32wnd->getOwner()->GetTopParent();
467
468 if(topOwner) WinSetWindowPos(topOwner->getOS2WindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
469 }
470 }
471 RestoreOS2TIB();
472 return 0;
473 }
474
475 case WM_SIZE:
476 {
477 dprintf(("OS2: WM_SIZE (%d,%d) (%d,%d)", SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), SHORT1FROMMP(mp1), SHORT2FROMMP(mp2)));
478 goto RunDefWndProc;
479 }
480
481 case WM_MINMAXFRAME:
482 {
483 PSWP swp = (PSWP)mp1;
484
485 if (!win32wnd->IsWindowCreated()) goto RunDefWndProc;
486
487 dprintf(("OS2: WM_MINMAXFRAME %x",hwnd));
488 if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
489 {
490 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MINIMIZE_W) | WS_MAXIMIZE_W);
491
492 RECT rect;
493
494 rect.left = rect.top = rect.right = rect.bottom = 0;
495 win32wnd->AdjustMaximizedRect(&rect);
496 swp->x += rect.left;
497 swp->cx += rect.right-rect.left;
498 swp->y -= rect.bottom;
499 swp->cy += rect.bottom-rect.top;
500 }
501 else if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
502 {
503 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
504 }
505 else if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
506 {
507 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
508 }
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 dprintf(("OS2: WM_VRNENABLED %x", win32wnd->getWindowHandle()));
540 if(!win32wnd->isComingToTop() && ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == WS_EX_TOPMOST_W))
541 {
542 HWND hwndrelated;
543 Win32BaseWindow *topwindow;
544
545 win32wnd->setComingToTop(TRUE);
546
547 hwndrelated = WinQueryWindow(hwnd, QW_PREV);
548 dprintf(("WM_VRNENABLED hwndrelated = %x (hwnd=%x)", hwndrelated, hwnd));
549 topwindow = Win32BaseWindow::GetWindowFromOS2Handle(hwndrelated);
550 if(topwindow == NULL || ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == 0)) {
551 //put window at the top of z order
552 WinSetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER );
553 }
554
555 win32wnd->setComingToTop(FALSE);
556 break;
557 }
558 goto RunDefWndProc;
559
560 case WM_SETFOCUS:
561 {
562 HWND hwndFocus = (HWND)mp1;
563
564 dprintf(("OS2: WM_SETFOCUS %x %x %d", win32wnd->getWindowHandle(), mp1, mp2));
565 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
566 //another (non-win32) application's window
567 //set to NULL (allowed according to win32 SDK) to avoid problems
568 hwndFocus = NULL;
569 }
570 if((ULONG)mp2 == TRUE) {
571 HWND hwndFocusWin32 = Win32BaseWindow::OS2ToWin32Handle(hwndFocus);
572 recreateCaret (hwndFocusWin32);
573 win32wnd->MsgSetFocus(hwndFocusWin32);
574 }
575 else win32wnd->MsgKillFocus(Win32BaseWindow::OS2ToWin32Handle(hwndFocus));
576 break;
577 }
578
579 //**************************************************************************
580 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
581 //**************************************************************************
582 case WM_HITTEST:
583 {
584 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
585 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
586 }
587 if(win32wnd && win32wnd->IsWindowCreated())
588 {
589 MRESULT rc;
590
591 rc = (MRESULT)win32wnd->MsgHitTest(pWinMsg);
592 RestoreOS2TIB();
593 return rc;
594 }
595 return (MRESULT)HT_NORMAL;
596 }
597
598 case WM_BUTTON1DOWN:
599 case WM_BUTTON1UP:
600 case WM_BUTTON1DBLCLK:
601 case WM_BUTTON2DOWN:
602 case WM_BUTTON2UP:
603 case WM_BUTTON2DBLCLK:
604 case WM_BUTTON3DOWN:
605 case WM_BUTTON3UP:
606 case WM_BUTTON3DBLCLK:
607 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
608 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
609 }
610 if(win32wnd)
611 win32wnd->MsgButton(pWinMsg);
612 rc = TRUE;
613 break;
614
615 case WM_BUTTON2MOTIONSTART:
616 case WM_BUTTON2MOTIONEND:
617 case WM_BUTTON2CLICK:
618 case WM_BUTTON1MOTIONSTART:
619 case WM_BUTTON1MOTIONEND:
620 case WM_BUTTON1CLICK:
621 case WM_BUTTON3MOTIONSTART:
622 case WM_BUTTON3MOTIONEND:
623 case WM_BUTTON3CLICK:
624 rc = TRUE;
625 break;
626
627 case WM_MOUSEMOVE:
628 {
629 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
630 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
631 }
632 if(win32wnd)
633 win32wnd->MsgMouseMove(pWinMsg);
634 break;
635 }
636
637 case WM_CONTROL:
638 goto RunDefWndProc;
639
640 case WM_COMMAND:
641 dprintf(("OS2: WM_COMMAND %x %x %x", hwnd, mp1, mp2));
642 win32wnd->DispatchMsgA(pWinMsg);
643 break;
644
645 case WM_SYSCOMMAND:
646 win32wnd->DispatchMsgA(pWinMsg);
647 break;
648
649 case WM_CHAR:
650 win32wnd->MsgChar(pWinMsg);
651 break;
652
653 case WM_TIMER:
654 win32wnd->DispatchMsgA(pWinMsg);
655 goto RunDefWndProc;
656
657 case WM_SETWINDOWPARAMS:
658 {
659 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
660
661 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
662 if(wndParams->fsStatus & WPM_TEXT) {
663 win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText);
664 }
665 goto RunDefWndProc;
666 }
667
668 case WM_QUERYWINDOWPARAMS:
669 {
670 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
671 ULONG textlen;
672 PSZ wintext;
673
674 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
675 {
676 if(wndpars->fsStatus & WPM_TEXT)
677 win32wnd->MsgGetText(wndpars->pszText, wndpars->cchText);
678 if(wndpars->fsStatus & WPM_CCHTEXT)
679 wndpars->cchText = win32wnd->MsgGetTextLength();
680
681 wndpars->fsStatus = 0;
682 wndpars->cbCtlData = 0;
683 wndpars->cbPresParams = 0;
684 RestoreOS2TIB();
685 return (MRESULT)TRUE;
686 }
687 goto RunDefWndProc;
688 }
689
690 case WM_PAINT:
691 {
692 RECTL rectl;
693 BOOL rc;
694
695 rc = WinQueryUpdateRect(hwnd, &rectl);
696 dprintf(("OS2: WM_PAINT %x (%d,%d) (%d,%d) rc=%d", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop, rc));
697 if(rc && win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
698 rectl.yBottom != rectl.yTop))
699 {
700 PRECT pClient = win32wnd->getClientRectPtr();
701 PRECT pWindow = win32wnd->getWindowRect();
702
703 if(!(pClient->left == 0 && pClient->top == 0 &&
704 win32wnd->getClientHeight() == win32wnd->getWindowHeight() &&
705 win32wnd->getClientWidth() == win32wnd->getWindowWidth()))
706 {
707 win32wnd->MsgNCPaint();
708 }
709 win32wnd->DispatchMsgA(pWinMsg);
710 }
711 else goto RunDefWndProc;
712
713 //SvL: Not calling the default window procedure causes all sorts of
714 // strange problems (redraw & hanging app)
715 // -> check what WinBeginPaint does what we're forgetting in BeginPaint
716// WinQueryUpdateRect(hwnd, &rectl);
717// if(rectl.xLeft == 0 && rectl.yTop == 0 && rectl.xRight == 0 && rectl.yBottom == 0) {
718// RestoreOS2TIB();
719// return (MRESULT)FALSE;
720// }
721// dprintf(("Update rectangle (%d,%d)(%d,%d) not empty, msg %x", rectl.xLeft, rectl.yTop, rectl.xRight, rectl.yBottom, pWinMsg->message));
722// goto RunDefWndProc;
723 break;
724 }
725
726 case WM_ERASEBACKGROUND:
727 {
728 dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
729 RestoreOS2TIB();
730 return (MRESULT)FALSE;
731 }
732
733#if 0
734 case WM_CONTEXTMENU:
735 {
736 win32wnd->DispatchMsgA(pWinMsg);
737
738 RestoreOS2TIB();
739 return (MRESULT)TRUE;
740 }
741#endif
742
743 case WM_FOCUSCHANGE:
744 {
745 HWND hwndFocus = (HWND)mp1;
746 HWND hwndLoseFocus, hwndGainFocus;
747 USHORT usSetFocus = SHORT1FROMMP(mp2);
748 USHORT fsFocusChange = SHORT2FROMMP(mp2);
749
750 dprintf(("OS2: WM_FOCUSCHANGE (start) %x %x %x %x", win32wnd->getWindowHandle(), hwndFocus, usSetFocus, fsFocusChange));
751 RestoreOS2TIB();
752 if(usSetFocus) {
753 hwndGainFocus = hwnd;
754 hwndLoseFocus = hwndFocus;
755 }
756 else {
757 hwndGainFocus = hwndFocus;
758 hwndLoseFocus = hwnd;
759 }
760 if(!(fsFocusChange & FC_NOLOSEFOCUS)) {
761 WinSendMsg(hwndLoseFocus, WM_SETFOCUS, (MPARAM)hwndGainFocus, (MPARAM)0);
762 }
763 //TODO: Don't send WM_SETSELECTION to child window if frame already has selection
764 if(!(fsFocusChange & FC_NOLOSESELECTION)) {
765 WinSendMsg(hwndLoseFocus, WM_SETSELECTION, (MPARAM)0, (MPARAM)0);
766 }
767 if(usSetFocus)
768 {
769 Win32BaseWindow *winfocus = Win32BaseWindow::GetWindowFromOS2Handle(hwndLoseFocus);
770 if(!(fsFocusChange & FC_NOLOSEACTIVE)) {
771 if(!winfocus || (winfocus->GetTopParent() != win32wnd->GetTopParent())) {
772 if(winfocus) {
773 WinSendMsg(winfocus->GetTopParent()->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)0, (MPARAM)hwndGainFocus);
774 }
775 else WinSendMsg(hwndLoseFocus, WM_ACTIVATE, (MPARAM)0, (MPARAM)hwndGainFocus);
776 }
777 }
778 if(!(fsFocusChange & FC_NOSETACTIVE))
779 {
780 Win32BaseWindow *topparent = win32wnd->GetTopParent();
781 if(!winfocus || (winfocus->GetTopParent() != topparent))
782 {
783 if(!(fsFocusChange & FC_NOBRINGTOTOP))
784 {
785 if(topparent) {
786 //put window at the top of z order
787 WinSetWindowPos(topparent->getOS2WindowHandle(), HWND_TOP, 0, 0, 0, 0, SWP_ZORDER);
788 }
789 }
790 WinSendMsg(topparent->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)1, (MPARAM)hwndLoseFocus);
791 }
792 }
793 }
794 else
795 {
796 Win32BaseWindow *winfocus = Win32BaseWindow::GetWindowFromOS2Handle(hwndGainFocus);
797 if(!(fsFocusChange & FC_NOLOSEACTIVE)) {
798 if(!winfocus || (winfocus->GetTopParent() != win32wnd->GetTopParent())) {
799 WinSendMsg(win32wnd->GetTopParent()->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)0, (MPARAM)hwndGainFocus);
800 }
801 }
802 if(!(fsFocusChange & FC_NOSETACTIVE)) {
803 if(!winfocus || (winfocus->GetTopParent() != win32wnd->GetTopParent())) {
804 if(winfocus) {
805 WinSendMsg(winfocus->GetTopParent()->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)1, (MPARAM)hwndLoseFocus);
806 }
807 else WinSendMsg(hwndGainFocus, WM_ACTIVATE, (MPARAM)1, (MPARAM)hwndLoseFocus);
808 }
809 }
810 }
811 //TODO: Don't send WM_SETSELECTION to child window if frame already has selection
812 if(!(fsFocusChange & FC_NOSETSELECTION)) {
813 WinSendMsg(hwndGainFocus, WM_SETSELECTION, (MPARAM)1, (MPARAM)0);
814 }
815
816 if(!(fsFocusChange & FC_NOSETFOCUS)) {
817 WinSendMsg(hwndGainFocus, WM_SETFOCUS, (MPARAM)hwndLoseFocus, (MPARAM)1);
818 }
819#ifdef DEBUG
820 SetWin32TIB();
821 dprintf(("OS2: WM_FOCUSCHANGE (end) %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
822 RestoreOS2TIB();
823#endif
824 return (MRESULT)rc;
825 }
826
827 case WM_QUERYTRACKINFO:
828 {
829 PTRACKINFO trackInfo = (PTRACKINFO)mp2;
830
831 dprintf(("OS2: WM_QUERYTRACKINFO %x", win32wnd->getWindowHandle()));
832 trackInfo->cxBorder = 4;
833 trackInfo->cyBorder = 4;
834 win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
835 RestoreOS2TIB();
836 return (MRESULT)TRUE;
837 }
838
839 case WM_QUERYBORDERSIZE:
840 {
841 PWPOINT size = (PWPOINT)mp1;
842
843 dprintf(("OS2: WM_QUERYBORDERSIZE %x", win32wnd->getWindowHandle()));
844
845 size->x = 0;
846 size->y = 0;
847 RestoreOS2TIB();
848 return (MRESULT)TRUE;
849 }
850
851 case WM_OWNERPOSCHANGE:
852 {
853 dprintf(("OS2: WM_OWNERPOSCHANGE"));
854 goto RunDefWndProc;
855 }
856
857 case WM_FORMATFRAME:
858 dprintf(("OS2: WM_FORMATFRAME %x", win32wnd->getWindowHandle()));
859// goto RunDefWndProc;
860 break;
861
862 case WM_ADJUSTFRAMEPOS:
863 {
864 PSWP pswp = (PSWP)mp1;
865
866 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));
867 break;
868 }
869
870 case WM_QUERYFRAMEINFO:
871 dprintf(("OS2: WM_QUERYFRAMEINFO %x", win32wnd->getWindowHandle()));
872 return (MRESULT)(FI_FRAME|FI_ACTIVATEOK);
873
874 case WM_QUERYFOCUSCHAIN:
875 {
876 USHORT fsCmd = SHORT1FROMMP(mp1);
877
878 dprintf(("OS2: WM_QUERYFOCUSCHAIN %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
879#if 1
880 goto RunDefWndProc;
881#else
882 switch(fsCmd) {
883 case QFC_NEXTINCHAIN:
884 break;
885 case QFC_ACTIVE:
886 case QFC_FRAME:
887 if(win32wnd->GetTopParent()) {
888 dprintf(("Frame = %x", win32wnd->GetTopParent()->getOS2WindowHandle()));
889 return (MRESULT)win32wnd->GetTopParent()->getOS2WindowHandle();
890 }
891 break;
892 case QFC_SELECTACTIVE:
893 break;
894 case QFC_PARTOFCHAIN:
895 return (MRESULT)TRUE;
896 }
897 break;
898#endif
899 }
900
901 case WM_INITMENU:
902 case WM_MENUSELECT:
903 case WM_MENUEND:
904 case WM_NEXTMENU:
905 case WM_SYSCOLORCHANGE:
906 case WM_SYSVALUECHANGED:
907 case WM_SETSELECTION:
908 case WM_PPAINT:
909 case WM_PSETFOCUS:
910 case WM_PSYSCOLORCHANGE:
911 case WM_PSIZE:
912 case WM_PACTIVATE:
913 case WM_PCONTROL:
914 case WM_HELP:
915 case WM_APPTERMINATENOTIFY:
916 case WM_PRESPARAMCHANGED:
917 case WM_DRAWITEM:
918 case WM_MEASUREITEM:
919 case WM_CONTROLPOINTER:
920 case WM_QUERYDLGCODE:
921 case WM_SUBSTITUTESTRING:
922 case WM_MATCHMNEMONIC:
923 case WM_SAVEAPPLICATION:
924 case WM_SEMANTICEVENT:
925 default:
926// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
927 RestoreOS2TIB();
928 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
929 }
930 RestoreOS2TIB();
931 return (MRESULT)rc;
932
933RunDefWndProc:
934// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
935 RestoreOS2TIB();
936 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
937} /* End of Win32WindowProc */
938//******************************************************************************
939//TODO: Quickly moving a window two times doesn't force a repaint (1st time)
940//******************************************************************************
941VOID FrameTrackFrame(Win32BaseWindow *win32wnd,DWORD flags)
942{
943 TRACKINFO track;
944 RECTL rcl;
945 PRECT pWindowRect;
946 HWND hwndTracking;
947 HPS hpsTrack;
948 LONG parentHeight, parentWidth;
949
950 track.cxBorder = 4;
951 track.cyBorder = 4; /* 4 pel wide lines used for rectangle */
952 track.cxGrid = 1;
953 track.cyGrid = 1; /* smooth tracking with mouse */
954 track.cxKeyboard = 8;
955 track.cyKeyboard = 8; /* faster tracking using cursor keys */
956
957 pWindowRect = win32wnd->getWindowRect();
958 if(win32wnd->getParent()) {
959 parentHeight = win32wnd->getParent()->getWindowHeight();
960 parentWidth = win32wnd->getParent()->getWindowWidth();
961 hwndTracking = win32wnd->getParent()->getOS2WindowHandle();
962 hpsTrack = WinGetPS(hwndTracking);
963 }
964 else {
965 parentHeight = OSLibQueryScreenHeight();
966 parentWidth = OSLibQueryScreenWidth();
967 hwndTracking = HWND_DESKTOP;
968 hpsTrack = NULL;
969 }
970
971 rcl.xLeft = pWindowRect->left;
972 rcl.yTop = OSLibQueryScreenHeight() - pWindowRect->top;
973 rcl.xRight = pWindowRect->right;
974 rcl.yBottom = OSLibQueryScreenHeight() - pWindowRect->bottom;
975 if(hwndTracking != HWND_DESKTOP) {
976 WinMapWindowPoints(win32wnd->getOS2WindowHandle(), HWND_DESKTOP, (PPOINTL)&rcl, 2);
977 }
978 WinCopyRect(hab, &track.rclTrack, &rcl); /* starting point */
979
980 WinSetRect(hab, &track.rclBoundary, 0, 0, parentWidth, parentHeight); /* bounding rectangle */
981
982 track.ptlMinTrackSize.x = 10;
983 track.ptlMinTrackSize.y = 10; /* set smallest allowed size of rectangle */
984 track.ptlMaxTrackSize.x = parentWidth;
985 track.ptlMaxTrackSize.y = parentHeight; /* set largest allowed size of rectangle */
986
987 win32wnd->AdjustTrackInfo((PPOINT)&track.ptlMinTrackSize, (PPOINT)&track.ptlMaxTrackSize);
988
989 track.fs = flags;
990
991 if(WinTrackRect(HWND_DESKTOP, NULL, &track) )
992 {
993 if(hpsTrack) WinReleasePS(hpsTrack);
994
995 /* if successful copy final position back */
996 if(!WinEqualRect(0, &rcl, &track.rclTrack)) {
997 if(flags == TF_MOVE) {
998 WinSetWindowPos(win32wnd->getOS2WindowHandle(),
999 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
1000 0, 0, SWP_MOVE);
1001 }
1002 else {
1003 WinSetWindowPos(win32wnd->getOS2WindowHandle(),
1004 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
1005 track.rclTrack.xRight - track.rclTrack.xLeft,
1006 track.rclTrack.yTop - track.rclTrack.yBottom,
1007 SWP_SIZE|SWP_MOVE);
1008 }
1009 }
1010 return;
1011 }
1012 if(hpsTrack) WinReleasePS(hpsTrack);
1013 return;
1014}
1015//******************************************************************************
1016//******************************************************************************
Note: See TracBrowser for help on using the repository browser.