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

Last change on this file since 8406 was 8406, checked in by sandervl, 23 years ago

PF: Don't send WM_WINDOWPOSCHANGING message when PM sends SWP_FOCUS(DE)ACTIVATE message.

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