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

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

Use WC_FRAME for the Odin frame window and subclass it; Updates for new keyboard hook

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