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

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

Notify visible region callback when WM_SHOW arrives

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