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

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

MDI + SetParent + activation fixes

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