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

Last change on this file since 10240 was 10240, checked in by sandervl, 22 years ago

Ignore messages sent or posted to the desktop window; Post/SendMessage: use shared or local memory depending

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