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

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

SPI_GETNONCLIENTMETRICS size check extended & Fixed RMB on icon of minimized mdi window

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