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

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

bugfixes + os/2 look support added

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