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

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

Changes & fixes for minimized windows

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