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

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

added custom function to force color to mono cursor conversion

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