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

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

WM_WINDOWPOSCHANGED activation fix

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