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

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

focus/activation fixes

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