source: trunk/src/user32/pmwindow.cpp

Last change on this file was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

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