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

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

SetParent bugfix

File size: 49.7 KB
Line 
1/* $Id: pmwindow.cpp,v 1.138 2001-07-04 09:29:51 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 dprintf(("WM_TIMER %x %x time %x", win32wnd->getWindowHandle(), pWinMsg->wParam, GetTickCount()));
497 win32wnd->DispatchMsgA(pWinMsg);
498 goto RunDefWndProc;
499
500 case WM_SETWINDOWPARAMS:
501 {
502 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
503
504 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
505 if(wndParams->fsStatus & WPM_TEXT) {
506 win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText);
507 }
508 goto RunDefWndProc;
509 }
510
511 case WM_QUERYWINDOWPARAMS:
512 {
513 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
514 ULONG textlen;
515 PSZ wintext;
516
517 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
518 {
519 if(wndpars->fsStatus & WPM_TEXT)
520 win32wnd->MsgGetText(wndpars->pszText, wndpars->cchText);
521 if(wndpars->fsStatus & WPM_CCHTEXT)
522 wndpars->cchText = win32wnd->MsgGetTextLength();
523
524 wndpars->fsStatus = 0;
525 wndpars->cbCtlData = 0;
526 wndpars->cbPresParams = 0;
527 rc = (MRESULT)TRUE;
528 break;
529 }
530 goto RunDefWndProc;
531 }
532
533 case WM_PAINT:
534 {
535 RECTL rectl;
536 BOOL rc;
537
538 rc = WinQueryUpdateRect(hwnd, &rectl);
539 dprintf(("OS2: WM_PAINT %x (%d,%d) (%d,%d) rc=%d", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop, rc));
540
541 if(rc && win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
542 rectl.yBottom != rectl.yTop))
543 {
544 win32wnd->DispatchMsgA(pWinMsg);
545 }
546 else goto RunDefWndProc;
547 break;
548 }
549
550 case WM_ERASEBACKGROUND:
551 {
552 dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
553 rc = (MRESULT)FALSE;
554 break;
555 }
556
557 case WM_CALCVALIDRECTS:
558 dprintf(("OS2: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
559 rc = (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
560 break;
561
562 case WM_REALIZEPALETTE:
563 {
564 dprintf(("OS2: WM_REALIZEPALETTE"));
565 goto RunDefWndProc;
566 }
567
568 case WM_INITMENU:
569 case WM_MENUSELECT:
570 case WM_MENUEND:
571 case WM_NEXTMENU:
572 case WM_SYSCOLORCHANGE:
573 case WM_SYSVALUECHANGED:
574 case WM_SETSELECTION:
575 case WM_PPAINT:
576 case WM_PSETFOCUS:
577 case WM_PSYSCOLORCHANGE:
578 case WM_PSIZE:
579 case WM_PACTIVATE:
580 case WM_PCONTROL:
581 case WM_HELP:
582 case WM_APPTERMINATENOTIFY:
583 case WM_PRESPARAMCHANGED:
584 case WM_DRAWITEM:
585 case WM_MEASUREITEM:
586 case WM_CONTROLPOINTER:
587 case WM_QUERYDLGCODE:
588 case WM_SUBSTITUTESTRING:
589 case WM_MATCHMNEMONIC:
590 case WM_SAVEAPPLICATION:
591 case WM_SEMANTICEVENT:
592 default:
593 dprintf2(("OS2: RunDefWndProc hwnd %x msg %x mp1 %x mp2 %x", hwnd, msg, mp1, mp2));
594 goto RunDefWndProc;
595 }
596 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
597 RestoreOS2TIB();
598 return (MRESULT)rc;
599
600RunDefWndProc:
601// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
602 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
603 RestoreOS2TIB();
604 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
605} /* End of Win32WindowProc */
606//******************************************************************************
607//******************************************************************************
608MRESULT EXPENTRY Win32FrameWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
609{
610 POSTMSG_PACKET *postmsg;
611 OSLIBPOINT point, ClientPoint;
612 Win32BaseWindow *win32wnd;
613 TEB *teb;
614 MRESULT rc = 0;
615 MSG winMsg, *pWinMsg;
616
617 //Restore our FS selector
618 SetWin32TIB();
619
620 //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- BEGIN
621 teb = GetThreadTEB();
622 win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
623
624 if(!teb || (msg != WM_CREATE && win32wnd == NULL)) {
625 dprintf(("PMFRAME: Invalid win32wnd pointer for window %x msg %x", hwnd, msg));
626 goto RunDefFrameWndProc;
627 }
628//// if(teb->o.odin.fIgnoreMsgs) {
629//// goto RunDefWndProc;
630//// }
631
632 if((teb->o.odin.msgstate & 1) == 0)
633 {//message that was sent directly to our window proc handler; translate it here
634 QMSG qmsg;
635
636 qmsg.msg = msg;
637 qmsg.hwnd = hwnd;
638 qmsg.mp1 = mp1;
639 qmsg.mp2 = mp2;
640 qmsg.time = WinQueryMsgTime(teb->o.odin.hab);
641 WinQueryMsgPos(teb->o.odin.hab, &qmsg.ptl);
642 qmsg.reserved = 0;
643
644 if(OS2ToWinMsgTranslate((PVOID)teb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
645 {//message was not translated
646 memset(&winMsg, 0, sizeof(MSG));
647 }
648 pWinMsg = &winMsg;
649 }
650 else {
651 pWinMsg = &teb->o.odin.msg;
652 teb->o.odin.msgstate++;
653 }
654 //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- END
655
656 switch( msg )
657 {
658 case WM_CREATE:
659 {
660 //WM_CREATE handled during client window creation
661 dprintf(("PMFRAME: WM_CREATE %x"));
662 goto RunDefFrameWndProc;
663 }
664
665 case WM_PAINT:
666 {
667 RECTL rectl;
668
669 HPS hps = WinBeginPaint(hwnd, NULL, &rectl);
670 dprintf(("PMFRAME: WM_PAINT %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop));
671
672 if(win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
673 rectl.yBottom != rectl.yTop))
674 {
675 PRECT pClient = win32wnd->getClientRectPtr();
676 PRECT pWindow = win32wnd->getWindowRect();
677
678 if(!(pClient->left == 0 && pClient->top == 0 &&
679 win32wnd->getClientHeight() == win32wnd->getWindowHeight() &&
680 win32wnd->getClientWidth() == win32wnd->getWindowWidth()))
681 {
682 RECT rectUpdate;
683
684 mapOS2ToWin32Rect(win32wnd->getWindowHeight(), (PRECTLOS2)&rectl, &rectUpdate);
685 win32wnd->MsgNCPaint(&rectUpdate);
686 }
687 }
688 WinEndPaint(hps);
689 break;
690 }
691
692 case WM_ERASEBACKGROUND:
693 {
694 dprintf(("PMFRAME:WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
695 rc = (MRESULT)FALSE;
696 break;
697 }
698
699 //**************************************************************************
700 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
701 //**************************************************************************
702
703 case WM_BUTTON1DOWN:
704 case WM_BUTTON1UP:
705 case WM_BUTTON1DBLCLK:
706 case WM_BUTTON2DOWN:
707 case WM_BUTTON2UP:
708 case WM_BUTTON2DBLCLK:
709 case WM_BUTTON3DOWN:
710 case WM_BUTTON3UP:
711 case WM_BUTTON3DBLCLK:
712 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
713 RELEASE_WNDOBJ(win32wnd);
714 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
715 }
716 if(win32wnd)
717 win32wnd->MsgButton(pWinMsg);
718
719 rc = (MRESULT)TRUE;
720 break;
721
722 case WM_BUTTON2MOTIONSTART:
723 case WM_BUTTON2MOTIONEND:
724 case WM_BUTTON2CLICK:
725 case WM_BUTTON1MOTIONSTART:
726 case WM_BUTTON1MOTIONEND:
727 case WM_BUTTON1CLICK:
728 case WM_BUTTON3MOTIONSTART:
729 case WM_BUTTON3MOTIONEND:
730 case WM_BUTTON3CLICK:
731 rc = (MRESULT)TRUE;
732 break;
733
734 case WM_MOUSEMOVE:
735 {
736 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
737 RELEASE_WNDOBJ(win32wnd);
738 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
739 }
740 if(win32wnd)
741 win32wnd->MsgMouseMove(pWinMsg);
742 break;
743 }
744
745 case WM_ADJUSTWINDOWPOS:
746 {
747 PSWP pswp = (PSWP)mp1;
748 SWP swpOld;
749 WINDOWPOS wp,wpOld;
750 HWND hParent = NULLHANDLE, hwndAfter;
751
752 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));
753
754 if(win32wnd->IsParentChanging()) {
755 rc = 0;
756 break;
757 }
758
759 if(pswp->fl & SWP_NOADJUST) {
760 //ignore weird messages (TODO: why are they sent?)
761 break;
762 }
763 //CB: show dialog in front of owner
764 if (win32wnd->IsModalDialogOwner())
765 {
766 dprintf(("win32wnd->IsModalDialogOwner %x", win32wnd->getWindowHandle()));
767 pswp->fl |= SWP_ZORDER;
768 pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
769 if (pswp->fl & SWP_ACTIVATE)
770 {
771 pswp->fl &= ~SWP_ACTIVATE;
772 WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
773 }
774 }
775
776 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
777 goto RunDefWndProc;
778
779 if(!win32wnd->CanReceiveSizeMsgs())
780 break;
781
782 WinQueryWindowPos(hwnd, &swpOld);
783 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
784 if (win32wnd->isChild()) {
785 if(win32wnd->getParent()) {
786 hParent = win32wnd->getParent()->getOS2WindowHandle();
787 }
788 else goto RunDefWndProc;
789 }
790 }
791 hwndAfter = pswp->hwndInsertBehind;
792 if(win32wnd->getParent()) {
793 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(), hwnd);
794 }
795 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
796
797 wp.hwnd = win32wnd->getWindowHandle();
798 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
799 {
800 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
801 dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
802 if(wndAfter) {
803 wp.hwndInsertAfter = wndAfter->getWindowHandle();
804 RELEASE_WNDOBJ(wndAfter);
805 }
806 else wp.hwndInsertAfter = HWND_TOP_W;
807 }
808
809 wpOld = wp;
810 win32wnd->MsgPosChanging((LPARAM)&wp);
811
812 if(win32wnd->getOldStyle() != win32wnd->getStyle()) {
813 OSLibSetWindowStyle(win32wnd->getOS2FrameWindowHandle(), win32wnd->getOS2WindowHandle(), win32wnd->getStyle(), win32wnd->getExStyle());
814 if(fOS2Look) {
815 DWORD dwOldStyle = win32wnd->getOldStyle();
816 DWORD dwStyle = win32wnd->getStyle();
817
818 if((dwOldStyle & WS_MINIMIZE_W) && !(dwStyle & WS_MINIMIZE_W)) {
819 //SC_RESTORE -> SC_MINIMIZE
820 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), 0, SC_RESTORE, SC_MINIMIZE, hbmFrameMenu[0]);
821 }
822 else
823 if((dwOldStyle & WS_MAXIMIZE_W) && !(dwStyle & WS_MAXIMIZE_W)) {
824 //SC_RESTORE -> SC_MAXIMIZE
825 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_RESTORE, SC_MAXIMIZE, hbmFrameMenu[1]);
826 }
827 else
828 if(!(dwOldStyle & WS_MINIMIZE_W) && (dwStyle & WS_MINIMIZE_W)) {
829 //SC_MINIMIZE -> SC_RESTORE
830 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), 0, SC_MINIMIZE, SC_RESTORE, hbmFrameMenu[2]);
831 }
832 else
833 if(!(dwOldStyle & WS_MAXIMIZE_W) && (dwStyle & WS_MAXIMIZE_W)) {
834 //SC_MAXIMIZE -> SC_RESTORE
835 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_MAXIMIZE, SC_RESTORE, hbmFrameMenu[2]);
836 }
837 }
838 }
839
840 if ((wp.hwndInsertAfter != wpOld.hwndInsertAfter) ||
841 (wp.x != wpOld.x) || (wp.y != wpOld.y) || (wp.cx != wpOld.cx) || (wp.cy != wpOld.cy) || (wp.flags != wpOld.flags))
842 {
843 ULONG flags = pswp->fl; //make a backup copy; OSLibMapWINDOWPOStoSWP will modify it
844
845 dprintf(("PMFRAME:WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
846 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
847
848 if(win32wnd->getParent()) {
849 OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, win32wnd->getParent()->getClientHeight(),
850 hwnd);
851 }
852 else OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, OSLibQueryScreenHeight(), hwnd);
853
854 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
855
856 //OSLibMapWINDOWPOStoSWP can add flags, but we must not let it remove flags!
857 if(pswp->fl & SWP_SIZE)
858 flags |= SWP_SIZE;
859
860 if(pswp->fl & SWP_MOVE)
861 flags |= SWP_MOVE;
862
863 pswp->fl = flags; //restore flags
864
865 pswp->fl |= SWP_NOADJUST;
866 pswp->hwndInsertBehind = hwndAfter;
867 pswp->hwnd = hwnd;
868
869 rc = (MRESULT)0xf;
870 break;
871 }
872 rc = 0;
873 break;
874 }
875
876 case WM_WINDOWPOSCHANGED:
877 {
878 PSWP pswp = (PSWP)mp1,pswpOld = pswp+1;
879 SWP swpOld = *(pswp + 1);
880 WINDOWPOS wp;
881 HWND hParent = NULLHANDLE;
882 RECTL rect;
883
884 dprintf(("PMFRAME:WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
885 if(win32wnd->IsParentChanging()) {
886 goto PosChangedEnd;
887 }
888
889 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
890 {
891 if(pswp->fl & SWP_RESTORE && win32wnd->getStyle() & WS_MINIMIZE_W) {
892 dprintf(("Restoring minimized window %x", win32wnd->getWindowHandle()));
893 win32wnd->ShowWindow(SW_RESTORE_W);
894 }
895 if(pswp->fl & SWP_SHOW) {
896 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
897 }
898 else
899 if(pswp->fl & SWP_HIDE) {
900 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
901 }
902 if(pswp->fl & SWP_ACTIVATE)
903 {
904 //Only send PM WM_ACTIVATE to top-level windows (frame windows)
905 if(!(WinQueryWindowULong(WinWindowFromID(hwnd,FID_CLIENT), OFFSET_WIN32FLAGS) & WINDOWFLAG_ACTIVE))
906 {
907 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)TRUE, (MPARAM)hwnd);
908 if(fOS2Look) {
909 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, MPFROMSHORT(TRUE), 0);
910 }
911 }
912 }
913 else
914 if(pswp->fl & SWP_DEACTIVATE)
915 {
916 //Only send PM WM_ACTIVATE to top-level windows (frame windows)
917 if(WinQueryWindowULong(WinWindowFromID(hwnd,FID_CLIENT), OFFSET_WIN32FLAGS) & WINDOWFLAG_ACTIVE)
918 {
919 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)FALSE, (MPARAM)hwnd);
920 if(fOS2Look) {
921 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, MPFROMSHORT(FALSE), 0);
922 }
923 }
924 }
925 goto RunDefWndProc;
926 }
927
928 if(pswp->fl & (SWP_MOVE | SWP_SIZE))
929 {
930 if(win32wnd->isChild())
931 {
932 if(win32wnd->getParent()) {
933 hParent = win32wnd->getParent()->getOS2WindowHandle();
934 }
935 else goto PosChangedEnd; //parent has just been destroyed
936 }
937 }
938
939
940 if(win32wnd->getParent()) {
941 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
942 hwnd);
943 }
944 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
945
946 wp.hwnd = win32wnd->getWindowHandle();
947 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
948 {
949 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
950 dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
951 if(wndAfter) {
952 wp.hwndInsertAfter = wndAfter->getWindowHandle();
953 RELEASE_WNDOBJ(wndAfter);
954 }
955 else wp.hwndInsertAfter = HWND_TOP_W;
956 }
957
958 if(pswp->fl & SWP_SHOW) {
959 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
960 }
961 else
962 if(pswp->fl & SWP_HIDE) {
963 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
964 }
965
966#ifndef USE_CALCVALIDRECT
967 if((pswp->fl & (SWP_MOVE | SWP_SIZE)))
968 {
969 //CB: todo: use result for WM_CALCVALIDRECTS
970 //Get old client rectangle (for invalidation of frame window parts later on)
971 //Use new window height to calculate the client area
972 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
973
974 //Note: Also updates the new window rectangle
975 win32wnd->MsgFormatFrame(&wp);
976
977 if(win32wnd->isOwnDC()) {
978 setPageXForm(win32wnd, (pDCData)GpiQueryDCData(win32wnd->getOwnDC()));
979 }
980
981 if(win32wnd->CanReceiveSizeMsgs())
982 win32wnd->MsgPosChanged((LPARAM)&wp);
983
984 if((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
985 {
986 //redraw the frame (to prevent unnecessary client updates)
987 BOOL redrawAll = FALSE;
988
989 dprintf2(("WM_WINDOWPOSCHANGED: redraw frame"));
990 if (win32wnd->getWindowClass())
991 {
992 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
993
994 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
995 redrawAll = TRUE;
996 else
997 if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
998 redrawAll = TRUE;
999 }
1000 else redrawAll = TRUE;
1001
1002 if(win32wnd->IsMixMaxStateChanging()) {
1003 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
1004 redrawAll = TRUE;
1005 }
1006
1007 if (redrawAll)
1008 {
1009 //CB: redraw all children for now
1010 // -> problems with update region if we don't do it
1011 // todo: rewrite whole handling
1012 WinInvalidateRect(hwnd,NULL,TRUE);
1013 }
1014 else
1015 {
1016 HPS hps = WinGetPS(hwnd);
1017 RECTL frame,client,arcl[4];
1018
1019 WinQueryWindowRect(hwnd,&frame);
1020
1021 //top
1022 arcl[0].xLeft = 0;
1023 arcl[0].xRight = frame.xRight;
1024 arcl[0].yBottom = rect.yTop;
1025 arcl[0].yTop = frame.yTop;
1026 //right
1027 arcl[1].xLeft = rect.xRight;
1028 arcl[1].xRight = frame.xRight;
1029 arcl[1].yBottom = 0;
1030 arcl[1].yTop = frame.yTop;
1031 //left
1032 arcl[2].xLeft = 0;
1033 arcl[2].xRight = rect.xLeft;
1034 arcl[2].yBottom = 0;
1035 arcl[2].yTop = frame.yTop;
1036 //bottom
1037 arcl[3].xLeft = 0;
1038 arcl[3].xRight = frame.xRight;
1039 arcl[3].yBottom = 0;
1040 arcl[3].yTop = rect.yBottom;
1041
1042 HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
1043
1044 WinInvalidateRegion(hwnd,hrgn,FALSE);
1045 GpiDestroyRegion(hps,hrgn);
1046 WinReleasePS(hps);
1047 }
1048 }
1049 }
1050 else
1051 {
1052#endif //USE_CALCVALIDRECT
1053 if(win32wnd->CanReceiveSizeMsgs())
1054 win32wnd->MsgPosChanged((LPARAM)&wp);
1055#ifndef USE_CALCVALIDRECT
1056 }
1057#endif
1058
1059 if(pswp->fl & SWP_ACTIVATE)
1060 {
1061 //Only send PM WM_ACTIVATE to top-level windows (frame windows)
1062 if(!(WinQueryWindowULong(WinWindowFromID(hwnd,FID_CLIENT), OFFSET_WIN32FLAGS) & WINDOWFLAG_ACTIVE))
1063 {
1064 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)TRUE, (MPARAM)hwnd);
1065 if(fOS2Look) {
1066 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, MPFROMSHORT(TRUE), 0);
1067 }
1068 }
1069 }
1070 else
1071 if(pswp->fl & SWP_DEACTIVATE)
1072 {
1073 //Only send PM WM_ACTIVATE to top-level windows (frame windows)
1074 if(WinQueryWindowULong(WinWindowFromID(hwnd,FID_CLIENT), OFFSET_WIN32FLAGS) & WINDOWFLAG_ACTIVE)
1075 {
1076 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)FALSE, (MPARAM)hwnd);
1077 if(fOS2Look) {
1078 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, MPFROMSHORT(FALSE), 0);
1079 }
1080 }
1081 }
1082
1083PosChangedEnd:
1084 rc = (MRESULT)FALSE;
1085 break;
1086 }
1087
1088 case WM_CALCVALIDRECTS:
1089#ifdef USE_CALCVALIDRECT
1090 {
1091 PRECTL oldRect = (PRECTL)mp1, newRect = oldRect+1;
1092 PSWP pswp = (PSWP)mp2;
1093 SWP swpOld;
1094 WINDOWPOS wp;
1095 RECTL newClientRect, oldClientRect;
1096 ULONG nccalcret;
1097// UINT res = CVR_ALIGNLEFT | CVR_ALIGNTOP;
1098 UINT res = 0;
1099
1100 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
1101
1102 //Get old position info
1103 WinQueryWindowPos(hwnd, &swpOld);
1104
1105 if(win32wnd->getParent()) {
1106 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
1107 win32wnd->getParent()->getClientRectPtr()->left,
1108 win32wnd->getParent()->getClientRectPtr()->top,
1109 hwnd);
1110 }
1111 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
1112
1113 wp.hwnd = win32wnd->getWindowHandle();
1114 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1115 {
1116 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1117 if(wndAfter) {
1118 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1119 RELEASE_WNDOBJ(wndAfter);
1120 }
1121 else wp.hwndInsertAfter = HWND_TOP_W;
1122 }
1123
1124 //Get old client rectangle
1125 mapWin32ToOS2Rect(oldRect->yTop - oldRect->yBottom, win32wnd->getClientRectPtr(), (PRECTLOS2)&oldClientRect);
1126
1127 //Note: Also updates the new window rectangle
1128 nccalcret = win32wnd->MsgFormatFrame(&wp);
1129
1130 //Get new client rectangle
1131 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&newClientRect);
1132
1133 if(nccalcret == 0) {
1134 res = CVR_ALIGNTOP | CVR_ALIGNLEFT;
1135 }
1136 else {
1137 if(nccalcret & WVR_ALIGNTOP_W) {
1138 res |= CVR_ALIGNTOP;
1139 }
1140 else
1141 if(nccalcret & WVR_ALIGNBOTTOM_W) {
1142 res |= CVR_ALIGNBOTTOM;
1143 }
1144
1145 if(nccalcret & WVR_ALIGNLEFT_W) {
1146 res |= CVR_ALIGNLEFT;
1147 }
1148 else
1149 if(nccalcret & WVR_ALIGNRIGHT_W) {
1150 res |= CVR_ALIGNRIGHT;
1151 }
1152
1153 if(nccalcret & WVR_REDRAW_W) {//WVR_REDRAW_W = (WVR_HREDRAW | WVR_VREDRAW)
1154 res |= CVR_REDRAW;
1155 }
1156 else
1157 if(nccalcret & WVR_VALIDRECTS_W) {
1158 //TODO:
1159 //res = 0;
1160 }
1161 }
1162 if(win32wnd->IsMixMaxStateChanging()) {
1163 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
1164 res |= CVR_REDRAW;
1165 }
1166 if(res == (CVR_ALIGNTOP|CVR_ALIGNLEFT)) {
1167 oldRect->xRight -= oldClientRect.xLeft;
1168 oldRect->yBottom += oldClientRect.yBottom;
1169 newRect->xRight -= newClientRect.xLeft;
1170 newRect->yBottom += newClientRect.yBottom;
1171 }
1172 rc = res;
1173 break;
1174 }
1175#else
1176 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
1177 rc = (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
1178 break;
1179#endif
1180
1181 case WM_CALCFRAMERECT:
1182 dprintf(("PMFRAME:WM_CALCFRAMERECT %x", win32wnd->getWindowHandle()));
1183 rc = (MRESULT)TRUE;
1184 break;
1185
1186 case WM_QUERYCTLTYPE:
1187 // This is a frame window
1188 dprintf(("PMFRAME:WM_QUERYCTLTYPE %x", win32wnd->getWindowHandle()));
1189 rc = (MRESULT)CCT_FRAME;
1190 break;
1191
1192#ifdef DEBUG
1193 case WM_QUERYFOCUSCHAIN:
1194 dprintf2(("PMFRAME:WM_QUERYFOCUSCHAIN %x fsCmd %x parent %x", win32wnd->getWindowHandle(), SHORT1FROMMP(mp1), mp2));
1195
1196 RestoreOS2TIB();
1197 rc = pfnFrameWndProc(hwnd, msg, mp1, mp2);
1198 SetWin32TIB();
1199 dprintf2(("PMFRAME:WM_QUERYFOCUSCHAIN %x fsCmd %x parent %x returned %x", win32wnd->getWindowHandle(), SHORT1FROMMP(mp1), mp2, rc));
1200 break;
1201// goto RunDefFrameWndProc;
1202#endif
1203
1204#ifdef DEBUG
1205 case WM_FOCUSCHANGE:
1206 {
1207 HWND hwndFocus = (HWND)mp1;
1208 HWND hwndLoseFocus, hwndGainFocus;
1209 USHORT usSetFocus = SHORT1FROMMP(mp2);
1210 USHORT fsFocusChange = SHORT2FROMMP(mp2);
1211
1212 dprintf(("PMFRAME:WM_FOCUSCHANGE %x %x %x %x", win32wnd->getWindowHandle(), hwndFocus, usSetFocus, fsFocusChange));
1213 goto RunDefFrameWndProc;
1214 }
1215#endif
1216
1217 case WM_ACTIVATE:
1218 {
1219 HWND hwndTitle;
1220 USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
1221
1222 dprintf(("PMFRAME: WM_ACTIVATE %x %x %x", hwnd, mp1, mp2));
1223 if (win32wnd->IsWindowCreated())
1224 {
1225 WinSendMsg(WinWindowFromID(hwnd,FID_CLIENT),WM_ACTIVATE,mp1,mp2);
1226 if(fOS2Look) {
1227 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, mp1, 0);
1228 }
1229 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1230
1231 //CB: show owner behind the dialog
1232 if (win32wnd->IsModalDialog())
1233 {
1234 if(win32wnd->getOwner()) {
1235 Win32BaseWindow *topOwner = Win32BaseWindow::GetWindowFromHandle(win32wnd->getOwner()->GetTopParent());
1236
1237 if (topOwner) {
1238 WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
1239 RELEASE_WNDOBJ(topOwner);
1240 }
1241 }
1242 }
1243 }
1244 else
1245 {
1246 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1247 }
1248 rc = 0;
1249 break;
1250 }
1251
1252 case WM_ENABLE:
1253 dprintf(("PMFRAME: WM_ENABLE %x", hwnd));
1254 win32wnd->MsgEnable(SHORT1FROMMP(mp1));
1255 break;
1256
1257 case WM_SHOW:
1258 dprintf(("PMFRAME: WM_SHOW %x %d", hwnd, mp1));
1259 //show client window
1260 WinShowWindow(win32wnd->getOS2WindowHandle(), (BOOL)mp1);
1261 break;
1262
1263 case WM_SETFOCUS:
1264 {
1265 dprintf(("PMFRAME: WM_SETFOCUS %x %x", win32wnd->getWindowHandle(), hwnd));
1266 goto RunDefFrameWndProc;
1267 }
1268
1269 case WM_QUERYTRACKINFO:
1270 {
1271 PTRACKINFO trackInfo = (PTRACKINFO)mp2;
1272
1273 dprintf(("PMFRAME:WM_QUERYTRACKINFO %x", win32wnd->getWindowHandle()));
1274 trackInfo->cxBorder = 4;
1275 trackInfo->cyBorder = 4;
1276 win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
1277 rc = (MRESULT)TRUE;
1278 break;
1279 }
1280
1281 case WM_QUERYBORDERSIZE:
1282 {
1283 PWPOINT size = (PWPOINT)mp1;
1284
1285 dprintf(("PMFRAME:WM_QUERYBORDERSIZE %x", win32wnd->getWindowHandle()));
1286
1287 size->x = 0;
1288 size->y = 0;
1289 rc = (MRESULT)TRUE;
1290 break;
1291 }
1292
1293 case WM_QUERYFRAMEINFO:
1294 dprintf(("PMFRAME:WM_QUERYFRAMEINFO %x", win32wnd->getWindowHandle()));
1295 goto RunDefFrameWndProc;
1296
1297 case WM_FORMATFRAME:
1298 dprintf(("PMFRAME:WM_FORMATFRAME %x", win32wnd->getWindowHandle()));
1299 break;
1300
1301 case WM_ADJUSTFRAMEPOS:
1302 {
1303 PSWP pswp = (PSWP)mp1;
1304
1305 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));
1306 goto RunDefFrameWndProc;
1307 }
1308
1309 case WM_OWNERPOSCHANGE:
1310 {
1311 PSWP pswp = (PSWP)mp1;
1312
1313 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));
1314 goto RunDefFrameWndProc;
1315 }
1316
1317 case WM_MINMAXFRAME:
1318 {
1319 PSWP swp = (PSWP)mp1;
1320
1321 if (!win32wnd->IsWindowCreated()) goto RunDefWndProc;
1322
1323 dprintf(("PMFRAME:WM_MINMAXFRAME %x",hwnd));
1324 if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
1325 {
1326 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MINIMIZE_W) | WS_MAXIMIZE_W);
1327
1328 RECT rect;
1329
1330 rect.left = rect.top = rect.right = rect.bottom = 0;
1331 win32wnd->AdjustMaximizedRect(&rect);
1332 swp->x += rect.left;
1333 swp->cx += rect.right-rect.left;
1334 swp->y -= rect.bottom;
1335 swp->cy += rect.bottom-rect.top;
1336 }
1337 else
1338 if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
1339 {
1340 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
1341 }
1342 else
1343 if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
1344 {
1345 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
1346 }
1347 goto RunDefWndProc;
1348 }
1349
1350 case WM_UPDATEFRAME:
1351 dprintf(("PMFRAME:WM_UPDATEFRAME %x", win32wnd->getWindowHandle()));
1352 goto RunDefFrameWndProc;
1353
1354 case WM_TRACKFRAME:
1355 if(fOS2Look) {//sent by titlebar control
1356 FrameTrackFrame(win32wnd, TF_MOVE);
1357 }
1358 rc = 0;
1359 break;
1360
1361 case WM_SYSCOMMAND:
1362 dprintf(("PMFRAME: WM_SYSCOMMAND %x", win32wnd->getWindowHandle()));
1363 win32wnd->DispatchMsgA(pWinMsg);
1364 break;
1365
1366 default:
1367 goto RunDefFrameWndProc;
1368 }
1369 RestoreOS2TIB();
1370 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1371 return (MRESULT)rc;
1372
1373RunDefFrameWndProc:
1374 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1375 RestoreOS2TIB();
1376 return pfnFrameWndProc(hwnd, msg, mp1, mp2);
1377
1378RunDefWndProc:
1379 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1380 RestoreOS2TIB();
1381 //calling WinDefWindowProc here breaks Opera hotlist window (WM_ADJUSTWINDOWPOS)
1382// return pfnFrameWndProc(hwnd, msg, mp1, mp2);
1383 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
1384}
1385//******************************************************************************
1386//TODO: Quickly moving a window two times doesn't force a repaint (1st time)
1387//******************************************************************************
1388VOID FrameTrackFrame(Win32BaseWindow *win32wnd,DWORD flags)
1389{
1390 TRACKINFO track;
1391 RECTL rcl;
1392 PRECT pWindowRect, pClientRect;
1393 HWND hwndTracking;
1394 LONG parentHeight, parentWidth;
1395
1396 dprintf(("FrameTrackFrame: %x %x", win32wnd->getWindowHandle(), flags));
1397 track.cxBorder = 4;
1398 track.cyBorder = 4; /* 4 pel wide lines used for rectangle */
1399 track.cxGrid = 1;
1400 track.cyGrid = 1; /* smooth tracking with mouse */
1401 track.cxKeyboard = 8;
1402 track.cyKeyboard = 8; /* faster tracking using cursor keys */
1403
1404 pWindowRect = win32wnd->getWindowRect();
1405 if(win32wnd->getParent()) {
1406 parentHeight = win32wnd->getParent()->getClientHeight();
1407 parentWidth = win32wnd->getParent()->getClientWidth();
1408 hwndTracking = win32wnd->getParent()->getOS2WindowHandle();
1409 }
1410 else {
1411 parentHeight = OSLibQueryScreenHeight();
1412 parentWidth = OSLibQueryScreenWidth();
1413 hwndTracking = HWND_DESKTOP;
1414 }
1415
1416 mapWin32ToOS2Rect(parentHeight, pWindowRect, (PRECTLOS2)&track.rclTrack);
1417 rcl = track.rclTrack;
1418 WinQueryWindowRect(hwndTracking, &track.rclBoundary);
1419
1420 track.ptlMinTrackSize.x = 10;
1421 track.ptlMinTrackSize.y = 10; /* set smallest allowed size of rectangle */
1422 track.ptlMaxTrackSize.x = parentWidth;
1423 track.ptlMaxTrackSize.y = parentHeight; /* set largest allowed size of rectangle */
1424
1425 win32wnd->AdjustTrackInfo((PPOINT)&track.ptlMinTrackSize, (PPOINT)&track.ptlMaxTrackSize);
1426
1427 track.fs = flags;
1428
1429 if(WinTrackRect(hwndTracking, NULL, &track) )
1430 {
1431 /* if successful copy final position back */
1432 if(!WinEqualRect(0, &rcl, &track.rclTrack)) {
1433 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));
1434 if(flags == TF_MOVE) {
1435 WinSetWindowPos(win32wnd->getOS2FrameWindowHandle(),
1436 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
1437 0, 0, SWP_MOVE);
1438 }
1439 else {
1440 WinSetWindowPos(win32wnd->getOS2FrameWindowHandle(),
1441 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
1442 track.rclTrack.xRight - track.rclTrack.xLeft,
1443 track.rclTrack.yTop - track.rclTrack.yBottom,
1444 SWP_SIZE|SWP_MOVE);
1445 }
1446 }
1447 return;
1448 }
1449 return;
1450}
1451//******************************************************************************
1452//******************************************************************************
1453void FrameReplaceMenuItem(HWND hwndMenu, ULONG nIndex, ULONG idOld, ULONG idNew,
1454 HBITMAP hbmNew)
1455{
1456 MENUITEM mi;
1457
1458 if (!hwndMenu)
1459 return;
1460
1461 WinEnableWindowUpdate(hwndMenu, FALSE);
1462
1463 if (WinSendMsg(hwndMenu, MM_QUERYITEM, MPFROM2SHORT(idOld, TRUE), MPFROMP(&mi)))
1464 {
1465 WinSendMsg(hwndMenu, MM_REMOVEITEM, (MPARAM)idOld, 0);
1466 mi.afStyle = MIS_BITMAP | MIS_SYSCOMMAND;
1467 mi.afAttribute = 0;
1468 mi.hwndSubMenu = 0;
1469 mi.id = idNew;
1470 mi.hItem = (ULONG)hbmNew;
1471 WinSendMsg(hwndMenu, MM_INSERTITEM, (MPARAM)&mi, 0);
1472 }
1473 WinEnableWindowUpdate(hwndMenu, TRUE);
1474
1475 WinInvalidateRect(hwndMenu, NULL, TRUE);
1476}
1477//******************************************************************************
1478//******************************************************************************
Note: See TracBrowser for help on using the repository browser.