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

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

Win32ToOS2Handle & OS2ToWin32Handle exported with stdcall calling convention

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