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

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

destroy cd notification window during dll unload

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