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

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

Visible & Clip region changes

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