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

Last change on this file since 8266 was 8256, checked in by bird, 23 years ago

Corrected call to GetDriveType. (missing ':')

File size: 63.6 KB
Line 
1/* $Id: pmwindow.cpp,v 1.172 2002-04-13 06:19:31 bird 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 //CB: show dialog in front of owner
1012 if (win32wnd->IsModalDialogOwner())
1013 {
1014 dprintf(("win32wnd->IsModalDialogOwner %x", win32wnd->getWindowHandle()));
1015 pswp->fl |= SWP_ZORDER;
1016 pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
1017 if (pswp->fl & SWP_ACTIVATE)
1018 {
1019 pswp->fl &= ~SWP_ACTIVATE;
1020 WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
1021 }
1022 }
1023
1024 if(!win32wnd->CanReceiveSizeMsgs())
1025 break;
1026
1027 WinQueryWindowPos(hwnd, &swpOld);
1028 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
1029 if (win32wnd->isChild()) {
1030 if(win32wnd->getParent()) {
1031 hParent = win32wnd->getParent()->getOS2WindowHandle();
1032 }
1033 else goto RunDefFrameWndProc;
1034 }
1035 }
1036 hwndAfter = pswp->hwndInsertBehind;
1037 if(win32wnd->getParent()) {
1038 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(), hwnd);
1039 }
1040 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
1041
1042 wp.hwnd = win32wnd->getWindowHandle();
1043 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1044 {
1045 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1046 dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
1047 if(wndAfter) {
1048 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1049 RELEASE_WNDOBJ(wndAfter);
1050 }
1051 else wp.hwndInsertAfter = HWND_TOP_W;
1052 }
1053
1054 wpOld = wp;
1055 win32wnd->MsgPosChanging((LPARAM)&wp);
1056
1057 if(win32wnd->getOldStyle() != win32wnd->getStyle())
1058 {
1059 OSLibSetWindowStyle(win32wnd->getOS2FrameWindowHandle(), win32wnd->getOS2WindowHandle(), win32wnd->getStyle(), win32wnd->getExStyle());
1060 if(fOS2Look) {
1061 DWORD dwOldStyle = win32wnd->getOldStyle();
1062 DWORD dwStyle = win32wnd->getStyle();
1063
1064 win32wnd->setOldStyle(dwStyle);
1065 if((dwOldStyle & WS_MINIMIZE_W) && !(dwStyle & WS_MINIMIZE_W)) {
1066 //SC_RESTORE -> SC_MINIMIZE
1067 dprintf(("%x -> SC_RESTORE -> SC_MINIMIZE", win32wnd->getWindowHandle()));
1068 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), 0, SC_RESTORE, SC_MINIMIZE, hbmFrameMenu[0]);
1069 if(dwStyle & WS_MAXIMIZE_W) {
1070 //SC_MAXIMIZE -> SC_RESTORE
1071 dprintf(("%x -> SC_MAXIMIZE -> SC_RESTORE", win32wnd->getWindowHandle()));
1072 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_MAXIMIZE, SC_RESTORE, hbmFrameMenu[2]);
1073 }
1074 }
1075 else
1076 if((dwOldStyle & WS_MAXIMIZE_W) && !(dwStyle & WS_MAXIMIZE_W)) {
1077 //SC_RESTORE -> SC_MAXIMIZE
1078 dprintf(("%x -> SC_RESTORE -> SC_MAXIMIZE", win32wnd->getWindowHandle()));
1079 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_RESTORE, SC_MAXIMIZE, hbmFrameMenu[1]);
1080 }
1081 else
1082 if(!(dwOldStyle & WS_MINIMIZE_W) && (dwStyle & WS_MINIMIZE_W)) {
1083 //SC_MINIMIZE -> SC_RESTORE
1084 dprintf(("%x -> SC_MINIMIZE -> SC_RESTORE", win32wnd->getWindowHandle()));
1085 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), 0, SC_MINIMIZE, SC_RESTORE, hbmFrameMenu[2]);
1086 }
1087 else
1088 if(!(dwOldStyle & WS_MAXIMIZE_W) && (dwStyle & WS_MAXIMIZE_W)) {
1089 //SC_MAXIMIZE -> SC_RESTORE
1090 dprintf(("%x -> SC_MAXIMIZE -> SC_RESTORE", win32wnd->getWindowHandle()));
1091 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_MAXIMIZE, SC_RESTORE, hbmFrameMenu[2]);
1092 }
1093 }
1094 }
1095
1096 if ((wp.hwndInsertAfter != wpOld.hwndInsertAfter) ||
1097 (wp.x != wpOld.x) || (wp.y != wpOld.y) || (wp.cx != wpOld.cx) || (wp.cy != wpOld.cy) || (wp.flags != wpOld.flags))
1098 {
1099 ULONG flags = pswp->fl; //make a backup copy; OSLibMapWINDOWPOStoSWP will modify it
1100
1101 dprintf(("PMFRAME:WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
1102 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
1103
1104 if(win32wnd->getParent()) {
1105 OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, win32wnd->getParent()->getClientHeight(),
1106 hwnd);
1107 }
1108 else OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, OSLibQueryScreenHeight(), hwnd);
1109
1110 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
1111
1112 //OSLibMapWINDOWPOStoSWP can add flags, but we must not let it remove flags!
1113 if(pswp->fl & SWP_SIZE)
1114 flags |= SWP_SIZE;
1115
1116 if(pswp->fl & SWP_MOVE)
1117 flags |= SWP_MOVE;
1118
1119 pswp->fl = flags; //restore flags
1120
1121 pswp->fl |= SWP_NOADJUST;
1122 pswp->hwndInsertBehind = hwndAfter;
1123 pswp->hwnd = hwnd;
1124
1125 ret = 0xf;
1126 }
1127adjustend:
1128 //The next part needs to be done for top-level windows only
1129 if(!((win32wnd->getStyle() & (WS_POPUP_W|WS_CHILD_W)) == WS_CHILD_W))
1130 {
1131 //Setting these flags is necessary to avoid activation/focus problems
1132 if(ulFlags & SWP_DEACTIVATE) {
1133 ret |= AWP_DEACTIVATE;
1134 }
1135 if(ulFlags & SWP_ACTIVATE)
1136 {
1137 if(ulFlags & SWP_ZORDER) {
1138 dprintf(("Set FF_NOACTIVATESWP"));
1139 ULONG ulFrameFlags = WinQueryWindowUShort(hwnd, QWS_FLAGS);
1140 WinSetWindowUShort(hwnd, QWS_FLAGS, ulFrameFlags | FF_NOACTIVATESWP);
1141 }
1142
1143 if(!(ulFlags & SWP_SHOW))
1144 {
1145 ret |= AWP_ACTIVATE;
1146 }
1147 else
1148 {
1149 FrameSetFocus(hwnd);
1150 }
1151 }
1152 }
1153 else {
1154 if(ulFlags & (SWP_ACTIVATE|SWP_FOCUSACTIVATE))
1155 {
1156 win32wnd->MsgChildActivate(TRUE);
1157 if(fOS2Look) {
1158 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
1159 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, (MPARAM)1, 0);
1160 }
1161 }
1162 else
1163 if(ulFlags & (SWP_DEACTIVATE|SWP_FOCUSDEACTIVATE))
1164 {
1165 win32wnd->MsgChildActivate(FALSE);
1166 if(fOS2Look) {
1167 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
1168 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, 0, 0);
1169 }
1170 }
1171 }
1172 dprintf(("WM_ADJUSTWINDOWPOS ret %x flags %x", ret, WinQueryWindowUShort(hwnd, QWS_FLAGS)));
1173 rc = (MRESULT)ret;
1174 break;
1175 }
1176
1177 case WM_WINDOWPOSCHANGED:
1178 {
1179 PSWP pswp = (PSWP)mp1,pswpOld = pswp+1;
1180 SWP swpOld = *(pswp + 1);
1181 WINDOWPOS wp;
1182 ULONG flAfp = (ULONG)mp2;
1183 HWND hParent = NULLHANDLE;
1184 RECTL rect;
1185
1186 dprintf(("PMFRAME:WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
1187 if(win32wnd->IsParentChanging()) {
1188 goto PosChangedEnd;
1189 }
1190
1191 //SvL: When a window is made visible, then we don't receive a
1192 // WM_VRNENABLED message (for some weird reason)
1193 if(pswp->fl & SWP_SHOW) {
1194 win32wnd->callVisibleRgnNotifyProc(TRUE);
1195 }
1196 else
1197 if(pswp->fl & SWP_HIDE) {
1198 win32wnd->callVisibleRgnNotifyProc(FALSE);
1199 }
1200
1201 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
1202 {
1203 if(pswp->fl & SWP_RESTORE && win32wnd->getStyle() & WS_MINIMIZE_W) {
1204 dprintf(("Restoring minimized window %x", win32wnd->getWindowHandle()));
1205 win32wnd->ShowWindow(SW_RESTORE_W);
1206 }
1207 if(pswp->fl & SWP_SHOW) {
1208 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
1209 }
1210 else
1211 if(pswp->fl & SWP_HIDE) {
1212 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
1213 }
1214 //MUST call the old frame window proc!
1215 goto RunDefFrameWndProc;
1216 }
1217
1218 if(pswp->fl & (SWP_MOVE | SWP_SIZE))
1219 {
1220 if(win32wnd->isChild())
1221 {
1222 if(win32wnd->getParent()) {
1223 hParent = win32wnd->getParent()->getOS2WindowHandle();
1224 }
1225 else goto PosChangedEnd; //parent has just been destroyed
1226 }
1227 }
1228
1229
1230 if(win32wnd->getParent()) {
1231 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
1232 hwnd);
1233 }
1234 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
1235
1236 wp.hwnd = win32wnd->getWindowHandle();
1237 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1238 {
1239 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1240 dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
1241 if(wndAfter) {
1242 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1243 RELEASE_WNDOBJ(wndAfter);
1244 }
1245 else wp.hwndInsertAfter = HWND_TOP_W;
1246 }
1247
1248 if(pswp->fl & SWP_SHOW) {
1249 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
1250 }
1251 else
1252 if(pswp->fl & SWP_HIDE) {
1253 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
1254 }
1255
1256 if(flAfp & AWP_ACTIVATE)
1257 {
1258 FrameSetFocus(hwnd);
1259 }
1260
1261#ifndef USE_CALCVALIDRECT
1262 if((pswp->fl & (SWP_MOVE | SWP_SIZE)))
1263 {
1264 //CB: todo: use result for WM_CALCVALIDRECTS
1265 //Get old client rectangle (for invalidation of frame window parts later on)
1266 //Use new window height to calculate the client area
1267 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
1268
1269 //Note: Also updates the new window rectangle
1270 win32wnd->MsgFormatFrame(&wp);
1271
1272 if(win32wnd->isOwnDC()) {
1273 setPageXForm(win32wnd, (pDCData)GpiQueryDCData(win32wnd->getOwnDC()));
1274 }
1275
1276 if(win32wnd->CanReceiveSizeMsgs())
1277 win32wnd->MsgPosChanged((LPARAM)&wp);
1278
1279 if((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
1280 {
1281 //redraw the frame (to prevent unnecessary client updates)
1282 BOOL redrawAll = FALSE;
1283
1284 dprintf2(("WM_WINDOWPOSCHANGED: redraw frame"));
1285 if (win32wnd->getWindowClass())
1286 {
1287 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
1288
1289 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
1290 redrawAll = TRUE;
1291 else
1292 if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
1293 redrawAll = TRUE;
1294 }
1295 else redrawAll = TRUE;
1296
1297 if(win32wnd->IsMixMaxStateChanging()) {
1298 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
1299 redrawAll = TRUE;
1300 }
1301
1302 if (redrawAll)
1303 {
1304 //CB: redraw all children for now
1305 // -> problems with update region if we don't do it
1306 // todo: rewrite whole handling
1307 WinInvalidateRect(hwnd,NULL,TRUE);
1308 }
1309 else
1310 {
1311 HPS hps = WinGetPS(hwnd);
1312 RECTL frame,client,arcl[4];
1313
1314 WinQueryWindowRect(hwnd,&frame);
1315
1316 //top
1317 arcl[0].xLeft = 0;
1318 arcl[0].xRight = frame.xRight;
1319 arcl[0].yBottom = rect.yTop;
1320 arcl[0].yTop = frame.yTop;
1321 //right
1322 arcl[1].xLeft = rect.xRight;
1323 arcl[1].xRight = frame.xRight;
1324 arcl[1].yBottom = 0;
1325 arcl[1].yTop = frame.yTop;
1326 //left
1327 arcl[2].xLeft = 0;
1328 arcl[2].xRight = rect.xLeft;
1329 arcl[2].yBottom = 0;
1330 arcl[2].yTop = frame.yTop;
1331 //bottom
1332 arcl[3].xLeft = 0;
1333 arcl[3].xRight = frame.xRight;
1334 arcl[3].yBottom = 0;
1335 arcl[3].yTop = rect.yBottom;
1336
1337 HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
1338
1339 WinInvalidateRegion(hwnd,hrgn,FALSE);
1340 GpiDestroyRegion(hps,hrgn);
1341 WinReleasePS(hps);
1342 }
1343 }
1344 }
1345 else
1346 {
1347#endif //USE_CALCVALIDRECT
1348 if(win32wnd->CanReceiveSizeMsgs())
1349 win32wnd->MsgPosChanged((LPARAM)&wp);
1350#ifndef USE_CALCVALIDRECT
1351 }
1352#endif
1353
1354PosChangedEnd:
1355 rc = (MRESULT)FALSE;
1356 break;
1357 }
1358
1359 case WM_CALCVALIDRECTS:
1360#ifdef USE_CALCVALIDRECT
1361 {
1362 PRECTL oldRect = (PRECTL)mp1, newRect = oldRect+1;
1363 PSWP pswp = (PSWP)mp2;
1364 SWP swpOld;
1365 WINDOWPOS wp;
1366 RECTL newClientRect, oldClientRect;
1367 ULONG nccalcret;
1368// UINT res = CVR_ALIGNLEFT | CVR_ALIGNTOP;
1369 UINT res = 0;
1370
1371 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
1372
1373 //Get old position info
1374 WinQueryWindowPos(hwnd, &swpOld);
1375
1376 if(win32wnd->getParent()) {
1377 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
1378 win32wnd->getParent()->getClientRectPtr()->left,
1379 win32wnd->getParent()->getClientRectPtr()->top,
1380 hwnd);
1381 }
1382 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
1383
1384 wp.hwnd = win32wnd->getWindowHandle();
1385 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1386 {
1387 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1388 if(wndAfter) {
1389 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1390 RELEASE_WNDOBJ(wndAfter);
1391 }
1392 else wp.hwndInsertAfter = HWND_TOP_W;
1393 }
1394
1395 //Get old client rectangle
1396 mapWin32ToOS2Rect(oldRect->yTop - oldRect->yBottom, win32wnd->getClientRectPtr(), (PRECTLOS2)&oldClientRect);
1397
1398 //Note: Also updates the new window rectangle
1399 nccalcret = win32wnd->MsgFormatFrame(&wp);
1400
1401 //Get new client rectangle
1402 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&newClientRect);
1403
1404 if(nccalcret == 0) {
1405 res = CVR_ALIGNTOP | CVR_ALIGNLEFT;
1406 }
1407 else {
1408 if(nccalcret & WVR_ALIGNTOP_W) {
1409 res |= CVR_ALIGNTOP;
1410 }
1411 else
1412 if(nccalcret & WVR_ALIGNBOTTOM_W) {
1413 res |= CVR_ALIGNBOTTOM;
1414 }
1415
1416 if(nccalcret & WVR_ALIGNLEFT_W) {
1417 res |= CVR_ALIGNLEFT;
1418 }
1419 else
1420 if(nccalcret & WVR_ALIGNRIGHT_W) {
1421 res |= CVR_ALIGNRIGHT;
1422 }
1423
1424 if(nccalcret & WVR_REDRAW_W) {//WVR_REDRAW_W = (WVR_HREDRAW | WVR_VREDRAW)
1425 res |= CVR_REDRAW;
1426 }
1427 else
1428 if(nccalcret & WVR_VALIDRECTS_W) {
1429 //TODO:
1430 //res = 0;
1431 }
1432 }
1433 if(win32wnd->IsMixMaxStateChanging()) {
1434 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
1435 res |= CVR_REDRAW;
1436 }
1437 if(res == (CVR_ALIGNTOP|CVR_ALIGNLEFT)) {
1438 oldRect->xRight -= oldClientRect.xLeft;
1439 oldRect->yBottom += oldClientRect.yBottom;
1440 newRect->xRight -= newClientRect.xLeft;
1441 newRect->yBottom += newClientRect.yBottom;
1442 }
1443 rc = res;
1444 break;
1445 }
1446#else
1447 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
1448 rc = (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
1449 break;
1450#endif
1451
1452 case WM_CALCFRAMERECT:
1453 dprintf(("PMFRAME:WM_CALCFRAMERECT %x", win32wnd->getWindowHandle()));
1454 rc = (MRESULT)TRUE;
1455 break;
1456
1457 case WM_QUERYCTLTYPE:
1458 // This is a frame window
1459 dprintf(("PMFRAME:WM_QUERYCTLTYPE %x", win32wnd->getWindowHandle()));
1460 rc = (MRESULT)CCT_FRAME;
1461 break;
1462
1463#ifdef DEBUG
1464 case WM_QUERYFOCUSCHAIN:
1465 dprintf2(("PMFRAME:WM_QUERYFOCUSCHAIN %x fsCmd %x parent %x", win32wnd->getWindowHandle(), SHORT1FROMMP(mp1), (mp2) ? OS2ToWin32Handle((DWORD)mp2) : 0));
1466
1467 RestoreOS2TIB();
1468 rc = pfnFrameWndProc(hwnd, msg, mp1, mp2);
1469 SetWin32TIB();
1470 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));
1471 break;
1472// goto RunDefFrameWndProc;
1473#endif
1474
1475 case WM_FOCUSCHANGE:
1476 {
1477 HWND hwndFocus = (HWND)mp1;
1478 HWND hwndLoseFocus, hwndGainFocus;
1479 USHORT usSetFocus = SHORT1FROMMP(mp2);
1480 USHORT fsFocusChange = SHORT2FROMMP(mp2);
1481
1482 //Save window that gains focus so we can determine which
1483 //process we lose activation to
1484 hwndFocusChange = (HWND)mp1;
1485
1486 dprintf(("PMFRAME:WM_FOCUSCHANGE %x %x (%x) %x %x", win32wnd->getWindowHandle(), OS2ToWin32Handle(hwndFocus), hwndFocus, usSetFocus, fsFocusChange));
1487 goto RunDefFrameWndProc;
1488 }
1489
1490#ifdef DEBUG
1491 case WM_SETFOCUS:
1492 {
1493 dprintf(("PMFRAME: WM_SETFOCUS %x %x", win32wnd->getWindowHandle(), hwnd));
1494 goto RunDefFrameWndProc;
1495 }
1496#endif
1497
1498 case WM_ACTIVATE:
1499 {
1500 HWND hwndTitle;
1501 USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
1502
1503 dprintf(("PMFRAME: WM_ACTIVATE %x %x %x", win32wnd->getWindowHandle(), mp1, OS2ToWin32Handle((DWORD)mp2)));
1504 if (win32wnd->IsWindowCreated())
1505 {
1506 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1507 if(fOS2Look) {
1508 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
1509 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, mp1, 0);
1510 }
1511 if(SHORT1FROMMP(mp1) == 0) {
1512 //deactivate
1513 WinSendDlgItemMsg(hwnd, FID_CLIENT, WM_ACTIVATE, mp1, mp2);
1514 }
1515 PID pidThis, pidPartner, pidTemp;
1516 TID tidPartner;
1517 HENUM henum;
1518 HWND hwndEnum;
1519
1520 WinQueryWindowProcess(hwnd, &pidThis, NULL);
1521 WinQueryWindowProcess(hwndFocusChange, &pidPartner, &tidPartner);
1522
1523 if(pidThis != pidPartner) {
1524 //Gain or lose activation to window in other process
1525 //must send WM_ACTIVATEAPP to top-level windows
1526
1527 //Iterate over all child windows of the desktop
1528 henum = WinBeginEnumWindows(HWND_DESKTOP);
1529
1530 while(hwndEnum = WinGetNextWindow(henum))
1531 {
1532 WinQueryWindowProcess(hwndEnum, &pidTemp, NULL);
1533 if(pidTemp == pidThis)
1534 {
1535 SendMessageA(OS2ToWin32Handle(hwndEnum), WM_ACTIVATEAPP_W, (WPARAM)SHORT1FROMMP(mp1), (LPARAM)tidPartner);
1536 }
1537 }
1538 WinEndEnumWindows(henum);
1539 }
1540 if(SHORT1FROMMP(mp1)) {
1541 //activate
1542 WinSendDlgItemMsg(hwnd, FID_CLIENT, WM_ACTIVATE, mp1, mp2);
1543 }
1544
1545 //CB: show owner behind the dialog
1546 if (win32wnd->IsModalDialog())
1547 {
1548 if(win32wnd->getOwner()) {
1549 Win32BaseWindow *topOwner = Win32BaseWindow::GetWindowFromHandle(win32wnd->getOwner()->GetTopParent());
1550
1551 if (topOwner) {
1552 WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
1553 RELEASE_WNDOBJ(topOwner);
1554 }
1555 }
1556 }
1557 }
1558 else
1559 {
1560 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1561 }
1562 rc = 0;
1563 break;
1564 }
1565
1566 case WM_ENABLE:
1567 dprintf(("PMFRAME: WM_ENABLE %x", hwnd));
1568 win32wnd->MsgEnable(SHORT1FROMMP(mp1));
1569 break;
1570
1571 case WM_SHOW:
1572 dprintf(("PMFRAME: WM_SHOW %x %d", hwnd, mp1));
1573 //show client window
1574 WinShowWindow(win32wnd->getOS2WindowHandle(), (BOOL)mp1);
1575 break;
1576
1577 case WM_QUERYTRACKINFO:
1578 {
1579 PTRACKINFO trackInfo = (PTRACKINFO)mp2;
1580
1581 dprintf(("PMFRAME:WM_QUERYTRACKINFO %x", win32wnd->getWindowHandle()));
1582 trackInfo->cxBorder = 4;
1583 trackInfo->cyBorder = 4;
1584 win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
1585 rc = (MRESULT)TRUE;
1586 break;
1587 }
1588
1589 case WM_QUERYBORDERSIZE:
1590 {
1591 PWPOINT size = (PWPOINT)mp1;
1592
1593 dprintf(("PMFRAME:WM_QUERYBORDERSIZE %x", win32wnd->getWindowHandle()));
1594
1595 size->x = 0;
1596 size->y = 0;
1597 rc = (MRESULT)TRUE;
1598 break;
1599 }
1600
1601#ifdef DEBUG
1602 case WM_QUERYFRAMEINFO:
1603 dprintf(("PMFRAME:WM_QUERYFRAMEINFO %x", win32wnd->getWindowHandle()));
1604 goto RunDefFrameWndProc;
1605#endif
1606
1607 case WM_FORMATFRAME:
1608 dprintf(("PMFRAME:WM_FORMATFRAME %x", win32wnd->getWindowHandle()));
1609 break;
1610
1611#ifdef DEBUG
1612 case WM_ADJUSTFRAMEPOS:
1613 {
1614 PSWP pswp = (PSWP)mp1;
1615
1616 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));
1617 goto RunDefFrameWndProc;
1618 }
1619
1620 case WM_OWNERPOSCHANGE:
1621 {
1622 PSWP pswp = (PSWP)mp1;
1623
1624 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));
1625 goto RunDefFrameWndProc;
1626 }
1627#endif
1628
1629 case WM_MINMAXFRAME:
1630 {
1631 PSWP swp = (PSWP)mp1;
1632
1633 if (!win32wnd->IsWindowCreated()) goto RunDefWndProc;
1634
1635 dprintf(("PMFRAME:WM_MINMAXFRAME %x",hwnd));
1636 if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
1637 {
1638 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MINIMIZE_W) | WS_MAXIMIZE_W);
1639
1640 RECT rect;
1641
1642 rect.left = rect.top = rect.right = rect.bottom = 0;
1643 win32wnd->AdjustMaximizedRect(&rect);
1644 swp->x += rect.left;
1645 swp->cx += rect.right-rect.left;
1646 swp->y -= rect.bottom;
1647 swp->cy += rect.bottom-rect.top;
1648 }
1649 else
1650 if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
1651 {
1652 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
1653 }
1654 else
1655 if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
1656 {
1657 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
1658 }
1659 goto RunDefWndProc;
1660 }
1661
1662#ifdef DEBUG
1663 case WM_UPDATEFRAME:
1664 dprintf(("PMFRAME:WM_UPDATEFRAME %x", win32wnd->getWindowHandle()));
1665 goto RunDefFrameWndProc;
1666#endif
1667
1668 case WM_TRACKFRAME:
1669 dprintf(("PMFRAME: WM_TRACKFRAME %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
1670 if(fOS2Look) {//sent by titlebar control
1671#ifdef CUSTOM_TRACKFRAME
1672 Frame_SysCommandSizeMove(win32wnd, SC_MOVE_W+HTCAPTION_W);
1673#else
1674 FrameTrackFrame(win32wnd, TF_MOVE);
1675#endif
1676 }
1677 rc = 0;
1678 break;
1679
1680 case WM_SYSCOMMAND:
1681 dprintf(("PMFRAME: WM_SYSCOMMAND %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
1682 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
1683 RELEASE_WNDOBJ(win32wnd);
1684 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
1685 }
1686 if(win32wnd)
1687 win32wnd->DispatchMsgA(pWinMsg);
1688 break;
1689
1690#ifdef DEBUG
1691 case WM_DDE_INITIATE:
1692 case WM_DDE_INITIATEACK:
1693 case WM_DDE_REQUEST:
1694 case WM_DDE_ACK:
1695 case WM_DDE_DATA:
1696 case WM_DDE_ADVISE:
1697 case WM_DDE_UNADVISE:
1698 case WM_DDE_POKE:
1699 case WM_DDE_EXECUTE:
1700 case WM_DDE_TERMINATE:
1701 dprintf(("PMFRAME: WM_DDE %x %x", msg, win32wnd->getWindowHandle()));
1702 break;
1703#endif
1704
1705 default:
1706 goto RunDefFrameWndProc;
1707 }
1708 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1709 RestoreOS2TIB();
1710 return (MRESULT)rc;
1711
1712RunDefFrameWndProc:
1713 dprintf2(("RunDefFrameWndProc"));
1714 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1715 RestoreOS2TIB();
1716 return pfnFrameWndProc(hwnd, msg, mp1, mp2);
1717
1718RunDefWndProc:
1719 dprintf2(("RunDefWndProc"));
1720 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1721 RestoreOS2TIB();
1722 //calling WinDefWindowProc here breaks Opera hotlist window (WM_ADJUSTWINDOWPOS)
1723// return pfnFrameWndProc(hwnd, msg, mp1, mp2);
1724 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
1725}
1726//******************************************************************************
1727//******************************************************************************
1728void FrameSetFocus(HWND hwnd)
1729{
1730 HWND hwndFocusSave = WinQueryWindowULong(hwnd, QWL_HWNDFOCUSSAVE);
1731 if(!WinIsWindow(hab, hwndFocusSave)) {
1732 hwndFocusSave = WinWindowFromID(hwnd, FID_CLIENT);
1733 WinSetWindowULong(hwnd, QWL_HWNDFOCUSSAVE, hwndFocusSave);
1734 }
1735 dprintf(("FrameSetFocus: hwndFocusSave %x %x", OS2ToWin32Handle(hwndFocusSave), hwndFocusSave));
1736 WinSetFocus(HWND_DESKTOP, hwndFocusSave);
1737
1738 ULONG ulFrameFlags = WinQueryWindowUShort(hwnd, QWS_FLAGS);
1739 ulFrameFlags &= ~FF_NOACTIVATESWP;
1740 WinSetWindowUShort(hwnd, QWS_FLAGS, ulFrameFlags);
1741}
1742#ifndef CUSTOM_TRACKFRAME
1743//******************************************************************************
1744//TODO: Quickly moving a window two times doesn't force a repaint (1st time)
1745//
1746//
1747BOOL (APIENTRY *WinTrackWindow)(HWND hwndTrack, PTRACKINFO pti) = NULL;
1748//
1749//******************************************************************************
1750VOID FrameTrackFrame(Win32BaseWindow *win32wnd,DWORD flags)
1751{
1752 TRACKINFO track;
1753 RECTL rcl;
1754 PRECT pWindowRect, pClientRect;
1755 HWND hwndTracking;
1756 LONG parentHeight, parentWidth;
1757 static BOOL fInit = FALSE;
1758 APIRET rc;
1759 BOOL ret;
1760 HWND hwnd = win32wnd->getWindowHandle();
1761
1762 if(!fInit) {
1763 HMODULE hModule;
1764 char buf[CCHMAXPATH];
1765 rc = DosLoadModule(buf, sizeof(buf), "PMMERGE", &hModule);
1766 rc = DosQueryProcAddr(hModule, 5466, NULL, (PFN *)&WinTrackWindow);
1767 if(rc) WinTrackWindow = NULL;
1768 fInit = TRUE;
1769 }
1770 dprintf(("FrameTrackFrame: %x %x", hwnd, flags));
1771 track.cxBorder = 4;
1772 track.cyBorder = 4; /* 4 pel wide lines used for rectangle */
1773 track.cxGrid = 1;
1774 track.cyGrid = 1; /* smooth tracking with mouse */
1775 track.cxKeyboard = 8;
1776 track.cyKeyboard = 8; /* faster tracking using cursor keys */
1777
1778 pWindowRect = win32wnd->getWindowRect();
1779 if(win32wnd->getParent()) {
1780 parentHeight = win32wnd->getParent()->getClientHeight();
1781 parentWidth = win32wnd->getParent()->getClientWidth();
1782 hwndTracking = win32wnd->getParent()->getOS2WindowHandle();
1783 }
1784 else {
1785 parentHeight = OSLibQueryScreenHeight();
1786 parentWidth = OSLibQueryScreenWidth();
1787 hwndTracking = HWND_DESKTOP;
1788 }
1789
1790 mapWin32ToOS2Rect(parentHeight, pWindowRect, (PRECTLOS2)&track.rclTrack);
1791 rcl = track.rclTrack;
1792 WinQueryWindowRect(hwndTracking, &track.rclBoundary);
1793
1794 track.ptlMinTrackSize.x = 10;
1795 track.ptlMinTrackSize.y = 10; /* set smallest allowed size of rectangle */
1796 track.ptlMaxTrackSize.x = parentWidth;
1797 track.ptlMaxTrackSize.y = parentHeight; /* set largest allowed size of rectangle */
1798
1799 win32wnd->AdjustTrackInfo((PPOINT)&track.ptlMinTrackSize, (PPOINT)&track.ptlMaxTrackSize);
1800
1801 track.fs = flags;
1802
1803 BOOL fDynamicDrag = WinQuerySysValue(HWND_DESKTOP, SVOS_DYNAMICDRAG);
1804
1805 //TODO: send WM_QUERYDRAGICON to fetch icon (not really necessary)
1806
1807 SendMessageA( hwnd, WM_ENTERSIZEMOVE_W, 0, 0);
1808
1809 SEL sel = RestoreOS2FS();
1810 if(fDynamicDrag && WinTrackWindow) {
1811 ret = WinTrackWindow(win32wnd->getOS2FrameWindowHandle(), &track);
1812 }
1813 else ret = WinTrackRect(hwndTracking, NULL, &track);
1814 SetFS(sel);
1815
1816//TODO:
1817// if (HOOK_CallHooksA( WH_CBT_W, HCBT_MOVESIZE_W, (WPARAM)hwnd, (LPARAM)&sizingRect )) moved = FALSE;
1818
1819 SendMessageA( hwnd, WM_EXITSIZEMOVE_W, 0, 0 );
1820 SendMessageA( hwnd, WM_SETVISIBLE_W, !IsIconic(hwnd), 0L);
1821
1822 if(ret) {
1823 /* if successful copy final position back */
1824 if(!WinEqualRect(0, &rcl, &track.rclTrack)) {
1825 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));
1826 if(flags == TF_MOVE) {
1827 WinSetWindowPos(win32wnd->getOS2FrameWindowHandle(),
1828 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
1829 0, 0, SWP_MOVE);
1830 }
1831 else {
1832 WinSetWindowPos(win32wnd->getOS2FrameWindowHandle(),
1833 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
1834 track.rclTrack.xRight - track.rclTrack.xLeft,
1835 track.rclTrack.yTop - track.rclTrack.yBottom,
1836 SWP_SIZE|SWP_MOVE);
1837 }
1838 }
1839 return;
1840 }
1841 return;
1842}
1843#endif
1844//******************************************************************************
1845//******************************************************************************
1846void FrameReplaceMenuItem(HWND hwndMenu, ULONG nIndex, ULONG idOld, ULONG idNew,
1847 HBITMAP hbmNew)
1848{
1849 MENUITEM mi;
1850
1851 if (!hwndMenu)
1852 return;
1853
1854 WinEnableWindowUpdate(hwndMenu, FALSE);
1855
1856 if (WinSendMsg(hwndMenu, MM_QUERYITEM, MPFROM2SHORT(idOld, TRUE), MPFROMP(&mi)))
1857 {
1858 WinSendMsg(hwndMenu, MM_REMOVEITEM, (MPARAM)idOld, 0);
1859 mi.afStyle = MIS_BITMAP | MIS_SYSCOMMAND;
1860 mi.afAttribute = 0;
1861 mi.hwndSubMenu = 0;
1862 mi.id = idNew;
1863 mi.hItem = (ULONG)hbmNew;
1864 WinSendMsg(hwndMenu, MM_INSERTITEM, (MPARAM)&mi, 0);
1865 }
1866 WinEnableWindowUpdate(hwndMenu, TRUE);
1867
1868 WinInvalidateRect(hwndMenu, NULL, TRUE);
1869}
1870//******************************************************************************
1871//******************************************************************************
Note: See TracBrowser for help on using the repository browser.