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

Last change on this file since 5993 was 5993, checked in by sandervl, 24 years ago

OS/2 looks changes + fixes

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