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