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

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

dispatch untranslated msgs + frame control button changes (manually change restore/min/max)

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