| 1 | /* $Id: pmwindow.cpp,v 1.45 1999-10-25 20:17:20 sandervl Exp $ */ | 
|---|
| 2 | /* | 
|---|
| 3 | * Win32 Window Managment Code for OS/2 | 
|---|
| 4 | * | 
|---|
| 5 | * Copyright 1998-1999 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 |  | 
|---|
| 15 | #include <os2.h>                        /* PM header file               */ | 
|---|
| 16 | #include <os2wrap.h> | 
|---|
| 17 | #include <stdlib.h> | 
|---|
| 18 | #include "win32type.h" | 
|---|
| 19 | #include <winconst.h> | 
|---|
| 20 | #include <wprocess.h> | 
|---|
| 21 | #include <misc.h> | 
|---|
| 22 | #include <win32wbase.h> | 
|---|
| 23 | #include <win32dlg.h> | 
|---|
| 24 | #include "win32wdesktop.h" | 
|---|
| 25 | #include "pmwindow.h" | 
|---|
| 26 | #include "oslibwin.h" | 
|---|
| 27 | #include "oslibutil.h" | 
|---|
| 28 | #include "oslibgdi.h" | 
|---|
| 29 | #include "oslibmsg.h" | 
|---|
| 30 | #include "dc.h" | 
|---|
| 31 | #include <thread.h> | 
|---|
| 32 | #include <wprocess.h> | 
|---|
| 33 | #include "caret.h" | 
|---|
| 34 | #include "timer.h" | 
|---|
| 35 |  | 
|---|
| 36 | HMQ  hmq = 0;                             /* Message queue handle         */ | 
|---|
| 37 | HAB  hab = 0; | 
|---|
| 38 |  | 
|---|
| 39 | RECTL desktopRectl = {0}; | 
|---|
| 40 | ULONG ScreenWidth  = 0; | 
|---|
| 41 | ULONG ScreenHeight = 0; | 
|---|
| 42 |  | 
|---|
| 43 | //Used for key translation while processing WM_CHAR message | 
|---|
| 44 | USHORT virtualKeyTable [66] = { | 
|---|
| 45 | 0x00,    //   OS/2 VK         Win32 VK,    Entry 0 is not used | 
|---|
| 46 | 0x01,    // VK_BUTTON1       VK_LBUTTON | 
|---|
| 47 | 0x02,    // VK_BUTTON2       VK_RBUTTON | 
|---|
| 48 | 0x04,    // VK_BUTTON3       VK_MBUTTON | 
|---|
| 49 | 0x03,    // VK_BREAK         VK_CANCEL | 
|---|
| 50 | 0x08,    // VK_BACKSPACE     VK_BACK | 
|---|
| 51 | 0x09,    // VK_TAB           VK_TAB | 
|---|
| 52 | 0x00,    // VK_BACKTAB       No equivalent! | 
|---|
| 53 | 0x0A,    // VK_NEWLINE       0x0A (no VK_* def) | 
|---|
| 54 | 0x10,    // VK_SHIFT         VK_SHIFT | 
|---|
| 55 | 0x11,    // VK_CTRL          VK_CONTROL | 
|---|
| 56 | 0x12,    // VK_ALT           VK_MENU, best match I guess | 
|---|
| 57 | 0x12,    // VK_ALTGRAF       VK_MENU, best match I guess | 
|---|
| 58 | 0x13,    // VK_PAUSE         VK_PAUSE | 
|---|
| 59 | 0x14,    // VK_CAPSLOCK      VK_CAPITAL | 
|---|
| 60 | 0x1B,    // VK_ESC           VK_ESCAPE | 
|---|
| 61 | 0x20,    // VK_SPACE         VK_SPACE | 
|---|
| 62 | 0x21,    // VK_PAGEUP        VK_PRIOR | 
|---|
| 63 | 0x22,    // VK_PAGEDOWN      VK_NEXT | 
|---|
| 64 | 0x23,    // VK_END           VK_END | 
|---|
| 65 | 0x24,    // VK_HOME          VK_HOME | 
|---|
| 66 | 0x25,    // VK_LEFT          VK_LEFT | 
|---|
| 67 | 0x26,    // VK_UP            VK_UP | 
|---|
| 68 | 0x27,    // VK_RIGHT         VK_RIGHT | 
|---|
| 69 | 0x28,    // VK_DOWN          VK_DOWN | 
|---|
| 70 | 0x2C,    // VK_PRINTSCRN     VK_SNAPSHOT | 
|---|
| 71 | 0x2D,    // VK_INSERT        VK_INSERT | 
|---|
| 72 | 0x2E,    // VK_DELETE        VK_DELETE | 
|---|
| 73 | 0x91,    // VK_SCRLLOCK      VK_SCROLL | 
|---|
| 74 | 0x90,    // VK_NUMLOCK       VK_NUMLOCK | 
|---|
| 75 | 0x0D,    // VK_ENTER         VK_RETURN | 
|---|
| 76 | 0x00,    // VK_SYSRQ         No equivalent! | 
|---|
| 77 | 0x70,    // VK_F1            VK_F1 | 
|---|
| 78 | 0x71,    // VK_F2            VK_F2 | 
|---|
| 79 | 0x72,    // VK_F3            VK_F3 | 
|---|
| 80 | 0x73,    // VK_F4            VK_F4 | 
|---|
| 81 | 0x74,    // VK_F5            VK_F5 | 
|---|
| 82 | 0x75,    // VK_F6            VK_F6 | 
|---|
| 83 | 0x76,    // VK_F7            VK_F7 | 
|---|
| 84 | 0x77,    // VK_F8            VK_F8 | 
|---|
| 85 | 0x78,    // VK_F9            VK_F9 | 
|---|
| 86 | 0x79,    // VK_F10           VK_F10 | 
|---|
| 87 | 0x7A,    // VK_F11           VK_F11 | 
|---|
| 88 | 0x7B,    // VK_F12           VK_F12 | 
|---|
| 89 | 0x7C,    // VK_F13           VK_F13 | 
|---|
| 90 | 0x7D,    // VK_F14           VK_F14 | 
|---|
| 91 | 0x7E,    // VK_F15           VK_F15 | 
|---|
| 92 | 0x7F,    // VK_F16           VK_F16 | 
|---|
| 93 | 0x80,    // VK_F17           VK_F17 | 
|---|
| 94 | 0x81,    // VK_F18           VK_F18 | 
|---|
| 95 | 0x82,    // VK_F19           VK_F19 | 
|---|
| 96 | 0x83,    // VK_F20           VK_F20 | 
|---|
| 97 | 0x84,    // VK_F21           VK_F21 | 
|---|
| 98 | 0x85,    // VK_F22           VK_F22 | 
|---|
| 99 | 0x86,    // VK_F23           VK_F23 | 
|---|
| 100 | 0x87,    // VK_F24           VK_F24 | 
|---|
| 101 | 0x00,    // VK_ENDDRAG       No equivalent! | 
|---|
| 102 | 0x0C,    // VK_CLEAR         VK_CLEAR | 
|---|
| 103 | 0xF9,    // VK_EREOF         VK_EREOF | 
|---|
| 104 | 0xFD,    // VK_PA1           VK_PA1 | 
|---|
| 105 | 0xF6,    // VK_ATTN          VK_ATTN | 
|---|
| 106 | 0xF7,    // VK_CRSEL         VK_CRSEL | 
|---|
| 107 | 0xF8,    // VK_EXSEL         VK_EXSEL | 
|---|
| 108 | 0x00,    // VK_COPY          No equivalent! | 
|---|
| 109 | 0x00,    // VK_BLK1          No equivalent! | 
|---|
| 110 | 0x00};   // VK_BLK2          No equivalent! | 
|---|
| 111 |  | 
|---|
| 112 | MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2); | 
|---|
| 113 |  | 
|---|
| 114 | //****************************************************************************** | 
|---|
| 115 | //Initialize PM; create hab, message queue and register special Win32 window classes | 
|---|
| 116 | //****************************************************************************** | 
|---|
| 117 | BOOL InitPM() | 
|---|
| 118 | { | 
|---|
| 119 | hab = WinInitialize(0); | 
|---|
| 120 | dprintf(("Winitialize returned %x", hab)); | 
|---|
| 121 | hmq = WinCreateMsgQueue(hab, 0); | 
|---|
| 122 |  | 
|---|
| 123 | if(!hab || !hmq) | 
|---|
| 124 | { | 
|---|
| 125 | UINT error; | 
|---|
| 126 | //CB: only fail on real error | 
|---|
| 127 | error = WinGetLastError(hab) & 0xFFFF; //error code | 
|---|
| 128 | if (!hab || error != PMERR_MSG_QUEUE_ALREADY_EXISTS) | 
|---|
| 129 | { | 
|---|
| 130 | dprintf(("WinInitialize or WinCreateMsgQueue failed %x %x", hab, hmq)); | 
|---|
| 131 | dprintf((" Error = %x",error)); | 
|---|
| 132 | return(FALSE); | 
|---|
| 133 | } | 
|---|
| 134 | else | 
|---|
| 135 | { | 
|---|
| 136 | if(!hab) { | 
|---|
| 137 | hab = WinQueryAnchorBlock(HWND_DESKTOP); | 
|---|
| 138 | dprintf(("WinQueryAnchorBlock returned %x", hab)); | 
|---|
| 139 | } | 
|---|
| 140 | if(!hmq) { | 
|---|
| 141 | hmq = HMQ_CURRENT; | 
|---|
| 142 | } | 
|---|
| 143 | } | 
|---|
| 144 | } | 
|---|
| 145 | SetThreadHAB(hab); | 
|---|
| 146 | dprintf(("InitPM: hmq = %x", hmq)); | 
|---|
| 147 | SetThreadMessageQueue(hmq); | 
|---|
| 148 |  | 
|---|
| 149 | if(!WinRegisterClass(                 /* Register window class        */ | 
|---|
| 150 | hab,                               /* Anchor block handle          */ | 
|---|
| 151 | (PSZ)WIN32_STDCLASS,               /* Window class name            */ | 
|---|
| 152 | (PFNWP)Win32WindowProc,            /* Address of window procedure  */ | 
|---|
| 153 | //     CS_SIZEREDRAW | CS_HITTEST | CS_MOVENOTIFY, | 
|---|
| 154 | CS_SIZEREDRAW | CS_HITTEST, | 
|---|
| 155 | NROF_WIN32WNDBYTES)) { | 
|---|
| 156 | dprintf(("WinRegisterClass Win32BaseWindow failed")); | 
|---|
| 157 | return(FALSE); | 
|---|
| 158 | } | 
|---|
| 159 |  | 
|---|
| 160 | WinQueryWindowRect(HWND_DESKTOP, &desktopRectl); | 
|---|
| 161 | ScreenWidth  = desktopRectl.xRight; | 
|---|
| 162 | ScreenHeight = desktopRectl.yTop; | 
|---|
| 163 |  | 
|---|
| 164 | dprintf(("InitPM: Desktop (%d,%d)", ScreenWidth, ScreenHeight)); | 
|---|
| 165 | return OSLibInitMsgQueue(); | 
|---|
| 166 | } /* End of main */ | 
|---|
| 167 | //****************************************************************************** | 
|---|
| 168 | //Win32 window message handler | 
|---|
| 169 | //****************************************************************************** | 
|---|
| 170 | MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) | 
|---|
| 171 | { | 
|---|
| 172 | POSTMSG_PACKET  *postmsg; | 
|---|
| 173 | OSLIBPOINT       point, ClientPoint; | 
|---|
| 174 | Win32BaseWindow *win32wnd; | 
|---|
| 175 | APIRET           rc; | 
|---|
| 176 |  | 
|---|
| 177 | //Restore our FS selector | 
|---|
| 178 | SetWin32TIB(); | 
|---|
| 179 |  | 
|---|
| 180 | win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd); | 
|---|
| 181 |  | 
|---|
| 182 | if(msg != WM_CREATE && win32wnd == NULL) { | 
|---|
| 183 | dprintf(("Invalid win32wnd pointer for window %x!!", hwnd)); | 
|---|
| 184 | goto RunDefWndProc; | 
|---|
| 185 | } | 
|---|
| 186 | if(msg > WIN32APP_USERMSGBASE) { | 
|---|
| 187 | //win32 app user message | 
|---|
| 188 | return (MRESULT)win32wnd->SendMessageA((ULONG)msg-WIN32APP_USERMSGBASE, (ULONG)mp1, (ULONG)mp2); | 
|---|
| 189 | } | 
|---|
| 190 | switch( msg ) | 
|---|
| 191 | { | 
|---|
| 192 | //OS/2 msgs | 
|---|
| 193 | case WM_CREATE: | 
|---|
| 194 | { | 
|---|
| 195 | THDB *thdb = GetThreadTHDB(); | 
|---|
| 196 |  | 
|---|
| 197 | if(thdb == NULL || thdb->newWindow == 0) | 
|---|
| 198 | goto createfail; | 
|---|
| 199 |  | 
|---|
| 200 | //Processing is done in after WinCreateWindow returns | 
|---|
| 201 | dprintf(("OS2: WM_CREATE %x", hwnd)); | 
|---|
| 202 | win32wnd = (Win32BaseWindow *)thdb->newWindow; | 
|---|
| 203 |  | 
|---|
| 204 | if(win32wnd->MsgCreate(WinQueryWindow(hwnd, QW_PARENT), hwnd) == FALSE) | 
|---|
| 205 | { | 
|---|
| 206 | RestoreOS2TIB(); | 
|---|
| 207 | return (MRESULT)TRUE; //discontinue window creation | 
|---|
| 208 | } | 
|---|
| 209 | createfail: | 
|---|
| 210 | RestoreOS2TIB(); | 
|---|
| 211 | return (MRESULT)FALSE; | 
|---|
| 212 | } | 
|---|
| 213 |  | 
|---|
| 214 | case WM_QUIT: | 
|---|
| 215 | dprintf(("OS2: WM_QUIT %x", hwnd)); | 
|---|
| 216 | if(win32wnd->MsgQuit()) { | 
|---|
| 217 | goto RunDefWndProc; | 
|---|
| 218 | } | 
|---|
| 219 | break; | 
|---|
| 220 |  | 
|---|
| 221 | case WM_CLOSE: | 
|---|
| 222 | dprintf(("OS2: WM_CLOSE %x", hwnd)); | 
|---|
| 223 | //        win32wnd->RemoveFakeOpen32(); | 
|---|
| 224 | if(win32wnd->MsgClose()) { | 
|---|
| 225 | goto RunDefWndProc; | 
|---|
| 226 | } | 
|---|
| 227 | break; | 
|---|
| 228 |  | 
|---|
| 229 | case WM_DESTROY: | 
|---|
| 230 | dprintf(("OS2: WM_DESTROY %x", hwnd)); | 
|---|
| 231 | if(win32wnd->MsgDestroy()) { | 
|---|
| 232 | goto RunDefWndProc; | 
|---|
| 233 | } | 
|---|
| 234 | break; | 
|---|
| 235 |  | 
|---|
| 236 | case WM_ENABLE: | 
|---|
| 237 | dprintf(("OS2: WM_ENABLE %x", hwnd)); | 
|---|
| 238 | if(win32wnd->MsgEnable(SHORT1FROMMP(mp1))) { | 
|---|
| 239 | goto RunDefWndProc; | 
|---|
| 240 | } | 
|---|
| 241 | break; | 
|---|
| 242 |  | 
|---|
| 243 | case WM_SHOW: | 
|---|
| 244 | dprintf(("OS2: WM_SHOW %x %d", hwnd, mp1)); | 
|---|
| 245 | if(win32wnd->MsgShow((ULONG)mp1)) { | 
|---|
| 246 | goto RunDefWndProc; | 
|---|
| 247 | } | 
|---|
| 248 | break; | 
|---|
| 249 |  | 
|---|
| 250 | #if 0 | 
|---|
| 251 | case WM_ADJUSTWINDOWPOS: | 
|---|
| 252 | { | 
|---|
| 253 | PSWP     pswp = (PSWP)mp1; | 
|---|
| 254 | SWP      swpOld, swpNew; | 
|---|
| 255 | WINDOWPOS wp; | 
|---|
| 256 | ULONG     parentHeight = 0; | 
|---|
| 257 | HWND      hParent = NULLHANDLE, hFrame = NULLHANDLE, hwndAfter; | 
|---|
| 258 |  | 
|---|
| 259 | dprintf(("OS2: WM_ADJUSTWINDOWPOS %x %x %x (%d,%d) (%d,%d)", hwnd, pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy)); | 
|---|
| 260 |  | 
|---|
| 261 | if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) goto RunDefWndProc;; | 
|---|
| 262 |  | 
|---|
| 263 | //SvL: TODO: Workaround. Why is this happening? | 
|---|
| 264 | //     When this flag is set the coordinates are 0, even though SWP_SIZE & SWP_MOVE are set. | 
|---|
| 265 | //        if ((pswp->fl & SWP_NOADJUST)) goto RunDefWndProc; | 
|---|
| 266 |  | 
|---|
| 267 | if(!win32wnd->CanReceiveSizeMsgs()) goto RunDefWndProc;; | 
|---|
| 268 |  | 
|---|
| 269 | WinQueryWindowPos(hwnd, &swpOld); | 
|---|
| 270 |  | 
|---|
| 271 | if(pswp->fl & (SWP_MOVE | SWP_SIZE)) { | 
|---|
| 272 | if (win32wnd->isChild()) { | 
|---|
| 273 | if(win32wnd->getParent()) { | 
|---|
| 274 | hParent = win32wnd->getParent()->getOS2WindowHandle(); | 
|---|
| 275 | } | 
|---|
| 276 | else    goto RunDefWndProc;; | 
|---|
| 277 | } | 
|---|
| 278 | } | 
|---|
| 279 | hwndAfter = pswp->hwndInsertBehind; | 
|---|
| 280 | hFrame = win32wnd->getOS2FrameWindowHandle(); | 
|---|
| 281 | OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, hParent, hFrame); | 
|---|
| 282 |  | 
|---|
| 283 | wp.hwnd = win32wnd->getWindowHandle(); | 
|---|
| 284 | if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM)) | 
|---|
| 285 | { | 
|---|
| 286 | Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind); | 
|---|
| 287 | if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle(); | 
|---|
| 288 | } | 
|---|
| 289 | if(win32wnd->MsgPosChanging((LPARAM)&wp) == 0) | 
|---|
| 290 | {//app or default window handler changed wp | 
|---|
| 291 | dprintf(("OS2: WM_ADJUSTWINDOWPOS, app changed windowpos struct")); | 
|---|
| 292 | dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy)); | 
|---|
| 293 | OSLibMapWINDOWPOStoSWP(&wp, &swpNew, &swpOld, hParent, hFrame); | 
|---|
| 294 | dprintf(("%x (%d,%d), (%d,%d)", swpNew.fl, swpNew.x, swpNew.y, swpNew.cx, swpNew.cy)); | 
|---|
| 295 | swpNew.fl |= SWP_NOADJUST; | 
|---|
| 296 | swpNew.hwndInsertBehind = hwndAfter; | 
|---|
| 297 | swpNew.hwnd = hFrame; | 
|---|
| 298 |  | 
|---|
| 299 | WinSetMultWindowPos(GetThreadHAB(), &swpNew, 1); | 
|---|
| 300 | return (MRESULT)0; | 
|---|
| 301 | } | 
|---|
| 302 | break; | 
|---|
| 303 | } | 
|---|
| 304 |  | 
|---|
| 305 | case WM_WINDOWPOSCHANGED: | 
|---|
| 306 | { | 
|---|
| 307 | PSWP      pswp  = (PSWP)mp1; | 
|---|
| 308 | SWP       swpOld = *(pswp + 1); | 
|---|
| 309 | WINDOWPOS wp; | 
|---|
| 310 | HWND      hParent = NULLHANDLE; | 
|---|
| 311 | LONG      yDelta = pswp->cy - swpOld.cy; | 
|---|
| 312 | LONG      xDelta = pswp->cx - swpOld.cx; | 
|---|
| 313 |  | 
|---|
| 314 | dprintf(("OS2: WM_WINDOWPOSCHANGED %x %x (%d,%d) (%d,%d)", hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy)); | 
|---|
| 315 |  | 
|---|
| 316 | if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) break; | 
|---|
| 317 |  | 
|---|
| 318 | if(pswp->fl & (SWP_MOVE | SWP_SIZE)) { | 
|---|
| 319 | if (win32wnd->isChild()) { | 
|---|
| 320 | if(win32wnd->getParent()) { | 
|---|
| 321 | hParent = win32wnd->getParent()->getOS2WindowHandle(); | 
|---|
| 322 | } | 
|---|
| 323 | else    goto RunDefWndProc; //parent has just been destroyed | 
|---|
| 324 | } | 
|---|
| 325 | } | 
|---|
| 326 | OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, hParent, win32wnd->getOS2FrameWindowHandle()); | 
|---|
| 327 |  | 
|---|
| 328 | if (!win32wnd->CanReceiveSizeMsgs())    break; | 
|---|
| 329 |  | 
|---|
| 330 | win32wnd->setWindowRect(wp.x, wp.y, wp.x+wp.cx, wp.y+wp.cy); | 
|---|
| 331 | win32wnd->setClientRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy); | 
|---|
| 332 |  | 
|---|
| 333 | wp.hwnd = win32wnd->getWindowHandle(); | 
|---|
| 334 | if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM)) | 
|---|
| 335 | { | 
|---|
| 336 | Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind); | 
|---|
| 337 | wp.hwndInsertAfter = wndAfter->getWindowHandle(); | 
|---|
| 338 | } | 
|---|
| 339 |  | 
|---|
| 340 | if (yDelta != 0 || xDelta != 0) | 
|---|
| 341 | { | 
|---|
| 342 | HENUM henum = WinBeginEnumWindows(pswp->hwnd); | 
|---|
| 343 | SWP swp[10]; | 
|---|
| 344 | int i = 0; | 
|---|
| 345 | HWND hwnd; | 
|---|
| 346 |  | 
|---|
| 347 | while ((hwnd = WinGetNextWindow(henum)) != NULLHANDLE) | 
|---|
| 348 | { | 
|---|
| 349 | #if 0 | 
|---|
| 350 | if (mdiClient ) | 
|---|
| 351 | { | 
|---|
| 352 | continue; | 
|---|
| 353 | } | 
|---|
| 354 | #endif | 
|---|
| 355 | WinQueryWindowPos(hwnd, &(swp[i])); | 
|---|
| 356 |  | 
|---|
| 357 | #ifdef DEBUG | 
|---|
| 358 | Win32BaseWindow *window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd); | 
|---|
| 359 | dprintf(("ENUMERATE %x delta %d (%d,%d) (%d,%d) %x", (window) ? window->getWindowHandle() : hwnd, | 
|---|
| 360 | yDelta, swp[i].x, swp[i].y, swp[i].cx, swp[i].cy, swp[i].fl)); | 
|---|
| 361 | #endif | 
|---|
| 362 |  | 
|---|
| 363 | if(swp[i].y != 0) { | 
|---|
| 364 | //child window at offset <> 0 from client area -> offset now changes | 
|---|
| 365 | swp[i].y  += yDelta; | 
|---|
| 366 | swp[i].fl &= ~(SWP_NOREDRAW); | 
|---|
| 367 | } | 
|---|
| 368 | //else child window with the same start coorindates as the client area | 
|---|
| 369 | //The app should resize it. | 
|---|
| 370 |  | 
|---|
| 371 | if (i == 9) | 
|---|
| 372 | { | 
|---|
| 373 | WinSetMultWindowPos(GetThreadHAB(), swp, 10); | 
|---|
| 374 | i = 0; | 
|---|
| 375 | } | 
|---|
| 376 | else | 
|---|
| 377 | { | 
|---|
| 378 | i++; | 
|---|
| 379 | } | 
|---|
| 380 | } | 
|---|
| 381 |  | 
|---|
| 382 | WinEndEnumWindows(henum); | 
|---|
| 383 |  | 
|---|
| 384 | if (i) | 
|---|
| 385 | WinSetMultWindowPos(GetThreadHAB(), swp, i); | 
|---|
| 386 | } | 
|---|
| 387 | if (yDelta != 0) | 
|---|
| 388 | { | 
|---|
| 389 | POINT pt; | 
|---|
| 390 | if(GetCaretPos (&pt) == TRUE) | 
|---|
| 391 | { | 
|---|
| 392 | pt.y -= yDelta; | 
|---|
| 393 | SetCaretPos (pt.x, pt.y); | 
|---|
| 394 | } | 
|---|
| 395 | } | 
|---|
| 396 | win32wnd->MsgPosChanged((LPARAM)&wp); | 
|---|
| 397 |  | 
|---|
| 398 | goto RunDefWndProc; | 
|---|
| 399 | } | 
|---|
| 400 | #endif | 
|---|
| 401 |  | 
|---|
| 402 | case WM_ACTIVATE: | 
|---|
| 403 | { | 
|---|
| 404 | HWND hwndActivate = (HWND)mp2; | 
|---|
| 405 | BOOL fMinimized = FALSE; | 
|---|
| 406 |  | 
|---|
| 407 | dprintf(("OS2: WM_ACTIVATE %x %x", hwnd, hwndActivate)); | 
|---|
| 408 | if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) { | 
|---|
| 409 | //another (non-win32) application's window | 
|---|
| 410 | //set to NULL (allowed according to win32 SDK) to avoid problems | 
|---|
| 411 | hwndActivate = NULL; | 
|---|
| 412 | } | 
|---|
| 413 | if(WinQueryWindowULong(hwnd, QWL_STYLE) & WS_MINIMIZED) | 
|---|
| 414 | { | 
|---|
| 415 | fMinimized = TRUE; | 
|---|
| 416 | } | 
|---|
| 417 |  | 
|---|
| 418 | if(win32wnd->MsgActivate(SHORT1FROMMP(mp1), fMinimized, Win32BaseWindow::OS2ToWin32Handle(hwndActivate))) { | 
|---|
| 419 | goto RunDefWndProc; | 
|---|
| 420 | } | 
|---|
| 421 | break; | 
|---|
| 422 | } | 
|---|
| 423 |  | 
|---|
| 424 | case WM_SIZE: | 
|---|
| 425 | { | 
|---|
| 426 | dprintf(("OS2: WM_SIZE (%d,%d) (%d,%d)", SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), SHORT1FROMMP(mp1), SHORT2FROMMP(mp2))); | 
|---|
| 427 | break; | 
|---|
| 428 | } | 
|---|
| 429 |  | 
|---|
| 430 | case WM_OWNERPOSCHANGE: | 
|---|
| 431 | { | 
|---|
| 432 | dprintf(("OS2: WM_OWNERPOSCHANGE")); | 
|---|
| 433 | goto RunDefWndProc; | 
|---|
| 434 | } | 
|---|
| 435 |  | 
|---|
| 436 | case WM_CALCVALIDRECTS: | 
|---|
| 437 | { | 
|---|
| 438 | dprintf(("OS2: WM_CALCVALIDRECTS")); | 
|---|
| 439 | goto RunDefWndProc; | 
|---|
| 440 | } | 
|---|
| 441 |  | 
|---|
| 442 | case WM_FOCUSCHANGE: | 
|---|
| 443 | dprintf(("OS2: WM_FOCUSCHANGE %x", win32wnd->getWindowHandle())); | 
|---|
| 444 | goto RunDefWndProc; | 
|---|
| 445 |  | 
|---|
| 446 | case WM_SETFOCUS: | 
|---|
| 447 | { | 
|---|
| 448 | HWND hwndFocus = (HWND)mp1; | 
|---|
| 449 |  | 
|---|
| 450 | dprintf(("OS2: WM_SETFOCUS %x %x %d", win32wnd->getWindowHandle(), mp1, mp2)); | 
|---|
| 451 | if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) { | 
|---|
| 452 | //another (non-win32) application's window | 
|---|
| 453 | //set to NULL (allowed according to win32 SDK) to avoid problems | 
|---|
| 454 | hwndFocus = NULL; | 
|---|
| 455 | } | 
|---|
| 456 | if((ULONG)mp2 == TRUE) { | 
|---|
| 457 | HWND hwndFocusWin32 = Win32BaseWindow::OS2ToWin32Handle(hwndFocus); | 
|---|
| 458 | recreateCaret (hwndFocusWin32); | 
|---|
| 459 | rc = win32wnd->MsgSetFocus(hwndFocusWin32); | 
|---|
| 460 | } | 
|---|
| 461 | else    rc = win32wnd->MsgKillFocus(Win32BaseWindow::OS2ToWin32Handle(hwndFocus)); | 
|---|
| 462 | if(rc) { | 
|---|
| 463 | goto RunDefWndProc; | 
|---|
| 464 | } | 
|---|
| 465 | break; | 
|---|
| 466 | } | 
|---|
| 467 |  | 
|---|
| 468 | //************************************************************************** | 
|---|
| 469 | //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen | 
|---|
| 470 | //************************************************************************** | 
|---|
| 471 | case WM_BUTTON1DOWN: | 
|---|
| 472 | dprintf(("OS2: WM_BUTTON1DOWN %x", hwnd)); | 
|---|
| 473 | point.x = (*(POINTS *)&mp1).x; | 
|---|
| 474 | point.y = (*(POINTS *)&mp1).y; | 
|---|
| 475 | ClientPoint.x = point.x; | 
|---|
| 476 | ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y); | 
|---|
| 477 | MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point); | 
|---|
| 478 | if(win32wnd->MsgButton(BUTTON_LEFTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) { | 
|---|
| 479 | goto RunDefWndProc; | 
|---|
| 480 | } | 
|---|
| 481 | break; | 
|---|
| 482 |  | 
|---|
| 483 | case WM_BUTTON1UP: | 
|---|
| 484 | dprintf(("OS2: WM_BUTTON1UP %x", hwnd)); | 
|---|
| 485 | point.x = (*(POINTS *)&mp1).x; | 
|---|
| 486 | point.y = (*(POINTS *)&mp1).y; | 
|---|
| 487 | ClientPoint.x = point.x; | 
|---|
| 488 | ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y); | 
|---|
| 489 | MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point); | 
|---|
| 490 | if(win32wnd->MsgButton(BUTTON_LEFTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) { | 
|---|
| 491 | goto RunDefWndProc; | 
|---|
| 492 | } | 
|---|
| 493 | break; | 
|---|
| 494 | case WM_BUTTON1DBLCLK: | 
|---|
| 495 | point.x = (*(POINTS *)&mp1).x; | 
|---|
| 496 | point.y = (*(POINTS *)&mp1).y; | 
|---|
| 497 | ClientPoint.x = point.x; | 
|---|
| 498 | ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y); | 
|---|
| 499 | MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point); | 
|---|
| 500 | if(win32wnd->MsgButton(BUTTON_LEFTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) { | 
|---|
| 501 | goto RunDefWndProc; | 
|---|
| 502 | } | 
|---|
| 503 | break; | 
|---|
| 504 | case WM_BUTTON2DOWN: | 
|---|
| 505 | point.x = (*(POINTS *)&mp1).x; | 
|---|
| 506 | point.y = (*(POINTS *)&mp1).y; | 
|---|
| 507 | ClientPoint.x = point.x; | 
|---|
| 508 | ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y); | 
|---|
| 509 | MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point); | 
|---|
| 510 | if(win32wnd->MsgButton(BUTTON_RIGHTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) { | 
|---|
| 511 | goto RunDefWndProc; | 
|---|
| 512 | } | 
|---|
| 513 | break; | 
|---|
| 514 | case WM_BUTTON2UP: | 
|---|
| 515 | point.x = (*(POINTS *)&mp1).x; | 
|---|
| 516 | point.y = (*(POINTS *)&mp1).y; | 
|---|
| 517 | ClientPoint.x = point.x; | 
|---|
| 518 | ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y); | 
|---|
| 519 | MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point); | 
|---|
| 520 | if(win32wnd->MsgButton(BUTTON_RIGHTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) { | 
|---|
| 521 | goto RunDefWndProc; | 
|---|
| 522 | } | 
|---|
| 523 | break; | 
|---|
| 524 | case WM_BUTTON2DBLCLK: | 
|---|
| 525 | point.x = (*(POINTS *)&mp1).x; | 
|---|
| 526 | point.y = (*(POINTS *)&mp1).y; | 
|---|
| 527 | ClientPoint.x = point.x; | 
|---|
| 528 | ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y); | 
|---|
| 529 | MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point); | 
|---|
| 530 | if(win32wnd->MsgButton(BUTTON_RIGHTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) { | 
|---|
| 531 | goto RunDefWndProc; | 
|---|
| 532 | } | 
|---|
| 533 | break; | 
|---|
| 534 | case WM_BUTTON3DOWN: | 
|---|
| 535 | point.x = (*(POINTS *)&mp1).x; | 
|---|
| 536 | point.y = (*(POINTS *)&mp1).y; | 
|---|
| 537 | ClientPoint.x = point.x; | 
|---|
| 538 | ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y); | 
|---|
| 539 | MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point); | 
|---|
| 540 | if(win32wnd->MsgButton(BUTTON_MIDDLEDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) { | 
|---|
| 541 | goto RunDefWndProc; | 
|---|
| 542 | } | 
|---|
| 543 | break; | 
|---|
| 544 | case WM_BUTTON3UP: | 
|---|
| 545 | point.x = (*(POINTS *)&mp1).x; | 
|---|
| 546 | point.y = (*(POINTS *)&mp1).y; | 
|---|
| 547 | ClientPoint.x = point.x; | 
|---|
| 548 | ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y); | 
|---|
| 549 | MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point); | 
|---|
| 550 | if(win32wnd->MsgButton(BUTTON_MIDDLEUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) { | 
|---|
| 551 | goto RunDefWndProc; | 
|---|
| 552 | } | 
|---|
| 553 | break; | 
|---|
| 554 | case WM_BUTTON3DBLCLK: | 
|---|
| 555 | point.x = (*(POINTS *)&mp1).x; | 
|---|
| 556 | point.y = (*(POINTS *)&mp1).y; | 
|---|
| 557 | ClientPoint.x = point.x; | 
|---|
| 558 | ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y); | 
|---|
| 559 | MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point); | 
|---|
| 560 | if(win32wnd->MsgButton(BUTTON_MIDDLEDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) { | 
|---|
| 561 | goto RunDefWndProc; | 
|---|
| 562 | } | 
|---|
| 563 | break; | 
|---|
| 564 |  | 
|---|
| 565 | case WM_BUTTON2MOTIONSTART: | 
|---|
| 566 | case WM_BUTTON2MOTIONEND: | 
|---|
| 567 | case WM_BUTTON2CLICK: | 
|---|
| 568 | case WM_BUTTON1MOTIONSTART: | 
|---|
| 569 | case WM_BUTTON1MOTIONEND: | 
|---|
| 570 | case WM_BUTTON1CLICK: | 
|---|
| 571 | case WM_BUTTON3MOTIONSTART: | 
|---|
| 572 | case WM_BUTTON3MOTIONEND: | 
|---|
| 573 | case WM_BUTTON3CLICK: | 
|---|
| 574 | goto RunDefWndProc; | 
|---|
| 575 |  | 
|---|
| 576 | case WM_MOUSEMOVE: | 
|---|
| 577 | { | 
|---|
| 578 | ULONG keystate = 0; | 
|---|
| 579 | if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1)) | 
|---|
| 580 | keystate |= WMMOVE_LBUTTON; | 
|---|
| 581 | if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2)) | 
|---|
| 582 | keystate |= WMMOVE_MBUTTON; | 
|---|
| 583 | if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3)) | 
|---|
| 584 | keystate |= WMMOVE_RBUTTON; | 
|---|
| 585 | if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT)) | 
|---|
| 586 | keystate |= WMMOVE_SHIFT; | 
|---|
| 587 | if(WinGetKeyState(HWND_DESKTOP, VK_CTRL)) | 
|---|
| 588 | keystate |= WMMOVE_CTRL; | 
|---|
| 589 |  | 
|---|
| 590 | //OS/2 Window coordinates -> Win32 Window coordinates | 
|---|
| 591 | if(win32wnd->MsgMouseMove(keystate, SHORT1FROMMP(mp1), MapOS2ToWin32Y(win32wnd, SHORT2FROMMP(mp1)))) | 
|---|
| 592 | { | 
|---|
| 593 | //Changes mouse cursor to default | 
|---|
| 594 | goto RunDefWndProc; | 
|---|
| 595 | } | 
|---|
| 596 | break; | 
|---|
| 597 | } | 
|---|
| 598 |  | 
|---|
| 599 | case WM_CONTROL: | 
|---|
| 600 |  | 
|---|
| 601 | case WM_COMMAND: | 
|---|
| 602 | if(SHORT1FROMMP(mp2) == CMDSRC_MENU) { | 
|---|
| 603 | win32wnd->MsgCommand(CMD_MENU, SHORT1FROMMP(mp1), 0); | 
|---|
| 604 | } | 
|---|
| 605 | if(SHORT1FROMMP(mp2) == CMDSRC_ACCELERATOR) { | 
|---|
| 606 | win32wnd->MsgCommand(CMD_ACCELERATOR, SHORT1FROMMP(mp1), 0); | 
|---|
| 607 | } | 
|---|
| 608 | //todo controls + accelerators | 
|---|
| 609 | break; | 
|---|
| 610 |  | 
|---|
| 611 | case WM_SYSCOMMAND: | 
|---|
| 612 | { | 
|---|
| 613 | ULONG x = 0, y = 0; | 
|---|
| 614 | ULONG win32sc; | 
|---|
| 615 |  | 
|---|
| 616 | if(SHORT2FROMMP(mp2) == TRUE) {//syscommand caused by mouse action | 
|---|
| 617 | POINTL pointl; | 
|---|
| 618 | WinQueryPointerPos(HWND_DESKTOP, &pointl); | 
|---|
| 619 | x = pointl.x; | 
|---|
| 620 | y = ScreenHeight - y; | 
|---|
| 621 | } | 
|---|
| 622 | switch(SHORT1FROMMP(mp1)) { | 
|---|
| 623 | case SC_MOVE: | 
|---|
| 624 | win32sc = SC_MOVE_W; | 
|---|
| 625 | break; | 
|---|
| 626 | case SC_CLOSE: | 
|---|
| 627 | win32sc = SC_CLOSE_W; | 
|---|
| 628 | break; | 
|---|
| 629 | case SC_MAXIMIZE: | 
|---|
| 630 | win32sc = SC_MAXIMIZE_W; | 
|---|
| 631 | break; | 
|---|
| 632 | case SC_MINIMIZE: | 
|---|
| 633 | win32sc = SC_MINIMIZE_W; | 
|---|
| 634 | break; | 
|---|
| 635 | case SC_NEXTFRAME: | 
|---|
| 636 | case SC_NEXTWINDOW: | 
|---|
| 637 | win32sc = SC_NEXTWINDOW_W; | 
|---|
| 638 | break; | 
|---|
| 639 | case SC_RESTORE: | 
|---|
| 640 | win32sc = SC_RESTORE_W; | 
|---|
| 641 | break; | 
|---|
| 642 | case SC_TASKMANAGER: | 
|---|
| 643 | win32sc = SC_TASKLIST_W; | 
|---|
| 644 | break; | 
|---|
| 645 | default: | 
|---|
| 646 | goto RunDefWndProc; | 
|---|
| 647 | } | 
|---|
| 648 | dprintf(("WM_SYSCOMMAND %x %x (%d,%d)", hwnd, win32sc, x, y)); | 
|---|
| 649 | if(win32wnd->MsgSysCommand(win32sc, x, y)) { | 
|---|
| 650 | goto RunDefWndProc; | 
|---|
| 651 | } | 
|---|
| 652 | break; | 
|---|
| 653 | } | 
|---|
| 654 | case WM_CHAR: | 
|---|
| 655 | { | 
|---|
| 656 | THDB *thdb; | 
|---|
| 657 | ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0; | 
|---|
| 658 | ULONG flags = SHORT1FROMMP(mp1); | 
|---|
| 659 | BOOL keyWasPressed, fTranslated = FALSE, fRunDefWndProc = FALSE; | 
|---|
| 660 | char c; | 
|---|
| 661 |  | 
|---|
| 662 | repeatCount = CHAR3FROMMP(mp1); | 
|---|
| 663 | scanCode = CHAR4FROMMP(mp1); | 
|---|
| 664 | keyWasPressed = ((SHORT1FROMMP (mp1) & KC_PREVDOWN) == KC_PREVDOWN); | 
|---|
| 665 |  | 
|---|
| 666 | dprintf(("PM: WM_CHAR: %x %x %d %x", SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), repeatCount, scanCode)); | 
|---|
| 667 | // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key | 
|---|
| 668 | // given the OS/2 virtual key and OS/2 character | 
|---|
| 669 |  | 
|---|
| 670 | if (((SHORT1FROMMP (mp1) & KC_CHAR) == KC_CHAR) || | 
|---|
| 671 | ((SHORT1FROMMP (mp1) & KC_LONEKEY) == KC_LONEKEY)) | 
|---|
| 672 | { | 
|---|
| 673 | c = SHORT1FROMMP (mp2); | 
|---|
| 674 | if ((c >= 'A') && (c <= 'Z')) { | 
|---|
| 675 | virtualKey = c; | 
|---|
| 676 | goto VirtualKeyFound; | 
|---|
| 677 | } | 
|---|
| 678 | if ((c >='a') && (c <= 'z')) { | 
|---|
| 679 | virtualKey = c - 32;   // make it uppercase | 
|---|
| 680 | goto VirtualKeyFound; | 
|---|
| 681 | } | 
|---|
| 682 | if ((c >= '0') && (c <= '9')) { | 
|---|
| 683 | virtualKey = c; | 
|---|
| 684 | goto VirtualKeyFound; | 
|---|
| 685 | } | 
|---|
| 686 | } | 
|---|
| 687 |  | 
|---|
| 688 | // convert OS/2 virtual keys to Win32 virtual key | 
|---|
| 689 | if (SHORT2FROMMP (mp2) <= VK_BLK2) | 
|---|
| 690 | virtualKey = virtualKeyTable [SHORT2FROMMP (mp2)]; | 
|---|
| 691 |  | 
|---|
| 692 | VirtualKeyFound: | 
|---|
| 693 |  | 
|---|
| 694 | if(!(SHORT1FROMMP(mp1) & KC_ALT)) | 
|---|
| 695 | { | 
|---|
| 696 | // | 
|---|
| 697 | // the Alt key is not pressed | 
|---|
| 698 | // | 
|---|
| 699 | if ((flags & KC_KEYUP) == KC_KEYUP) { | 
|---|
| 700 | // send WM_KEYUP message | 
|---|
| 701 |  | 
|---|
| 702 | if(win32wnd->MsgKeyUp (repeatCount, scanCode, virtualKey)) { | 
|---|
| 703 | fRunDefWndProc = TRUE; | 
|---|
| 704 | } | 
|---|
| 705 | } | 
|---|
| 706 | else { | 
|---|
| 707 | // send WM_KEYDOWN message | 
|---|
| 708 | if (win32wnd->MsgKeyDown (repeatCount, scanCode, virtualKey, keyWasPressed)) | 
|---|
| 709 | fRunDefWndProc = TRUE; | 
|---|
| 710 | } | 
|---|
| 711 | } | 
|---|
| 712 | else { | 
|---|
| 713 | // | 
|---|
| 714 | // the Alt key is pressed | 
|---|
| 715 | // | 
|---|
| 716 | if ((flags & KC_KEYUP) == KC_KEYUP) { | 
|---|
| 717 | // send WM_SYSKEYUP message | 
|---|
| 718 |  | 
|---|
| 719 | if(win32wnd->MsgSysKeyUp (repeatCount, scanCode, virtualKey)) { | 
|---|
| 720 | fRunDefWndProc = TRUE; | 
|---|
| 721 | } | 
|---|
| 722 | } | 
|---|
| 723 | else { | 
|---|
| 724 | // send WM_SYSKEYDOWN message | 
|---|
| 725 | if (win32wnd->MsgSysKeyDown (repeatCount, scanCode, virtualKey, keyWasPressed)) | 
|---|
| 726 | fRunDefWndProc = TRUE; | 
|---|
| 727 | } | 
|---|
| 728 | } | 
|---|
| 729 |  | 
|---|
| 730 | thdb = GetThreadTHDB(); | 
|---|
| 731 | if(thdb) { | 
|---|
| 732 | fTranslated = thdb->fMsgTranslated; | 
|---|
| 733 | thdb->fMsgTranslated = FALSE;  //reset flag | 
|---|
| 734 | } | 
|---|
| 735 | //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains | 
|---|
| 736 | //      the newly generated WM_CHAR message. | 
|---|
| 737 | if(fTranslated && !((flags & KC_KEYUP) == KC_KEYUP)) {//TranslatedMessage was called before DispatchMessage, so send WM_CHAR messages | 
|---|
| 738 | ULONG keyflags = 0, vkey = 0; | 
|---|
| 739 | ULONG fl = SHORT1FROMMP(mp1); | 
|---|
| 740 | ULONG chCode = SHORT1FROMMP(mp2); | 
|---|
| 741 |  | 
|---|
| 742 | if(!(fl & KC_CHAR)) { | 
|---|
| 743 | //SvL: Test | 
|---|
| 744 | break; | 
|---|
| 745 | //                goto RunDefWndProc; | 
|---|
| 746 | } | 
|---|
| 747 | if(fl & KC_VIRTUALKEY) { | 
|---|
| 748 | if(virtualKey) | 
|---|
| 749 | vkey = virtualKey; | 
|---|
| 750 | else    vkey = SHORT2FROMMP(mp2); | 
|---|
| 751 | chCode = vkey; | 
|---|
| 752 | } | 
|---|
| 753 | if(fl & KC_KEYUP) { | 
|---|
| 754 | keyflags |= KEY_UP; | 
|---|
| 755 | } | 
|---|
| 756 | if(fl & KC_ALT) { | 
|---|
| 757 | keyflags |= KEY_ALTDOWN; | 
|---|
| 758 | } | 
|---|
| 759 | if(fl & KC_PREVDOWN) { | 
|---|
| 760 | keyflags |= KEY_PREVDOWN; | 
|---|
| 761 | } | 
|---|
| 762 | if(fl & KC_DEADKEY) { | 
|---|
| 763 | keyflags |= KEY_DEADKEY; | 
|---|
| 764 | } | 
|---|
| 765 | if(win32wnd->MsgChar(chCode, CHAR3FROMMP(mp1), CHAR4FROMMP(mp1), virtualKey, keyflags)) { | 
|---|
| 766 | //SvL: Test | 
|---|
| 767 | //                goto RunDefWndProc; | 
|---|
| 768 |  | 
|---|
| 769 | } | 
|---|
| 770 | } | 
|---|
| 771 | //SvL: Test | 
|---|
| 772 | //        if(fRunDefWndProc) goto RunDefWndProc; | 
|---|
| 773 | break; | 
|---|
| 774 | } | 
|---|
| 775 |  | 
|---|
| 776 | case WM_INITMENU: | 
|---|
| 777 | case WM_MENUSELECT: | 
|---|
| 778 | case WM_MENUEND: | 
|---|
| 779 | case WM_NEXTMENU: | 
|---|
| 780 | goto RunDefWndProc; | 
|---|
| 781 |  | 
|---|
| 782 | case WM_TIMER: | 
|---|
| 783 | if (mp2) | 
|---|
| 784 | { | 
|---|
| 785 | BOOL sys; | 
|---|
| 786 | ULONG id; | 
|---|
| 787 |  | 
|---|
| 788 | if (TIMER_GetTimerInfo(hwnd,(ULONG)mp1,&sys,&id)) | 
|---|
| 789 | { | 
|---|
| 790 | if (sys) | 
|---|
| 791 | win32wnd->MsgSysTimer(id); | 
|---|
| 792 | else | 
|---|
| 793 | win32wnd->MsgTimer(id); | 
|---|
| 794 | } | 
|---|
| 795 | } | 
|---|
| 796 | goto RunDefWndProc; | 
|---|
| 797 |  | 
|---|
| 798 | case WM_SETWINDOWPARAMS: | 
|---|
| 799 | { | 
|---|
| 800 | WNDPARAMS *wndParams = (WNDPARAMS *)mp1; | 
|---|
| 801 |  | 
|---|
| 802 | dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd)); | 
|---|
| 803 | if(wndParams->fsStatus & WPM_TEXT) { | 
|---|
| 804 | if(win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText)) { | 
|---|
| 805 | goto RunDefWndProc; | 
|---|
| 806 | } | 
|---|
| 807 | } | 
|---|
| 808 | goto RunDefWndProc; | 
|---|
| 809 | } | 
|---|
| 810 |  | 
|---|
| 811 | case WM_QUERYWINDOWPARAMS: | 
|---|
| 812 | { | 
|---|
| 813 | PWNDPARAMS wndpars = (PWNDPARAMS)mp1; | 
|---|
| 814 | ULONG textlen; | 
|---|
| 815 | PSZ   wintext; | 
|---|
| 816 |  | 
|---|
| 817 | if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT)) | 
|---|
| 818 | { | 
|---|
| 819 | if(wndpars->fsStatus & WPM_CCHTEXT) | 
|---|
| 820 | wndpars->cchText = win32wnd->MsgGetTextLength(); | 
|---|
| 821 | if(wndpars->fsStatus & WPM_TEXT) | 
|---|
| 822 | wndpars->pszText = win32wnd->MsgGetText(); | 
|---|
| 823 |  | 
|---|
| 824 | wndpars->fsStatus = 0; | 
|---|
| 825 | wndpars->cbCtlData = 0; | 
|---|
| 826 | wndpars->cbPresParams = 0; | 
|---|
| 827 | RestoreOS2TIB(); | 
|---|
| 828 | return (MRESULT)TRUE; | 
|---|
| 829 | } | 
|---|
| 830 | goto RunDefWndProc; | 
|---|
| 831 | } | 
|---|
| 832 |  | 
|---|
| 833 | case WM_ERASEBACKGROUND: | 
|---|
| 834 | { | 
|---|
| 835 | dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle())); | 
|---|
| 836 | if (WinQueryUpdateRect (hwnd, NULL) && !win32wnd->isSupressErase()) { | 
|---|
| 837 | BOOL erased = sendEraseBkgnd (win32wnd); | 
|---|
| 838 | win32wnd->setEraseBkgnd (!erased, !erased); | 
|---|
| 839 | } | 
|---|
| 840 | break; | 
|---|
| 841 | } | 
|---|
| 842 |  | 
|---|
| 843 | case WM_PAINT: | 
|---|
| 844 | dprintf(("OS2: WM_PAINT %x", hwnd)); | 
|---|
| 845 |  | 
|---|
| 846 | if (WinQueryUpdateRect (hwnd, NULL)) { | 
|---|
| 847 | if (!win32wnd->isSupressErase()) { | 
|---|
| 848 | BOOL erased = sendEraseBkgnd (win32wnd); | 
|---|
| 849 | win32wnd->setEraseBkgnd (!erased, !erased); | 
|---|
| 850 | } | 
|---|
| 851 | } | 
|---|
| 852 | win32wnd->setSupressErase (FALSE); | 
|---|
| 853 |  | 
|---|
| 854 | if(win32wnd->MsgPaint(0, 0)) { | 
|---|
| 855 | goto RunDefWndProc; | 
|---|
| 856 | } | 
|---|
| 857 | break; | 
|---|
| 858 |  | 
|---|
| 859 | case WM_HITTEST: | 
|---|
| 860 | // Only send this message if the window is enabled | 
|---|
| 861 | if (WinIsWindowEnabled(hwnd)) | 
|---|
| 862 | { | 
|---|
| 863 | if(win32wnd->MsgHitTest((*(POINTS *)&mp1).x, MapOS2ToWin32Y(OSLIB_HWND_DESKTOP, hwnd, (*(POINTS *)&mp1).y))) { | 
|---|
| 864 | goto RunDefWndProc; | 
|---|
| 865 | } | 
|---|
| 866 | } | 
|---|
| 867 | else    goto RunDefWndProc; | 
|---|
| 868 | break; | 
|---|
| 869 |  | 
|---|
| 870 | case WM_SYSCOLORCHANGE: | 
|---|
| 871 | case WM_SYSVALUECHANGED: | 
|---|
| 872 | case WM_SETSELECTION: | 
|---|
| 873 | case WM_PPAINT: | 
|---|
| 874 | case WM_PSETFOCUS: | 
|---|
| 875 | case WM_PSYSCOLORCHANGE: | 
|---|
| 876 | case WM_PSIZE: | 
|---|
| 877 | case WM_PACTIVATE: | 
|---|
| 878 | case WM_PCONTROL: | 
|---|
| 879 | case WM_HELP: | 
|---|
| 880 | case WM_APPTERMINATENOTIFY: | 
|---|
| 881 | case WM_PRESPARAMCHANGED: | 
|---|
| 882 | case WM_DRAWITEM: | 
|---|
| 883 | case WM_MEASUREITEM: | 
|---|
| 884 | case WM_CONTROLPOINTER: | 
|---|
| 885 | case WM_QUERYDLGCODE: | 
|---|
| 886 | case WM_SUBSTITUTESTRING: | 
|---|
| 887 | case WM_MATCHMNEMONIC: | 
|---|
| 888 | case WM_SAVEAPPLICATION: | 
|---|
| 889 | case WM_SEMANTICEVENT: | 
|---|
| 890 | default: | 
|---|
| 891 | //        dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd)); | 
|---|
| 892 | RestoreOS2TIB(); | 
|---|
| 893 | return WinDefWindowProc( hwnd, msg, mp1, mp2 ); | 
|---|
| 894 | } | 
|---|
| 895 | RestoreOS2TIB(); | 
|---|
| 896 | return (MRESULT)FALSE; | 
|---|
| 897 |  | 
|---|
| 898 | RunDefWndProc: | 
|---|
| 899 | //  dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd)); | 
|---|
| 900 | RestoreOS2TIB(); | 
|---|
| 901 | return WinDefWindowProc( hwnd, msg, mp1, mp2 ); | 
|---|
| 902 | } /* End of Win32WindowProc */ | 
|---|
| 903 | //****************************************************************************** | 
|---|
| 904 | //****************************************************************************** | 
|---|
| 905 | MRESULT EXPENTRY Win32SubclassWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) | 
|---|
| 906 | { | 
|---|
| 907 | Win32BaseWindow* win32wnd; | 
|---|
| 908 |  | 
|---|
| 909 | //Restore our FS selector | 
|---|
| 910 | SetWin32TIB(); | 
|---|
| 911 |  | 
|---|
| 912 | win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd); | 
|---|
| 913 |  | 
|---|
| 914 | if (!win32wnd) | 
|---|
| 915 | { | 
|---|
| 916 | dprintf(("Invalid win32wnd pointer for subclassed window %x!!", hwnd)); | 
|---|
| 917 | goto RunDefWndProc; | 
|---|
| 918 | } | 
|---|
| 919 |  | 
|---|
| 920 | switch (msg) | 
|---|
| 921 | { | 
|---|
| 922 | case WM_WINDOWPOSCHANGED: | 
|---|
| 923 | { | 
|---|
| 924 | PSWP      pswp  = (PSWP)mp1; | 
|---|
| 925 | SWP       swpOld = *(pswp + 1); | 
|---|
| 926 | WINDOWPOS wp; | 
|---|
| 927 | HWND      hParent = NULLHANDLE, hFrame = NULLHANDLE; | 
|---|
| 928 |  | 
|---|
| 929 | dprintf(("OS2Subclass: WM_WINDOWPOSCHANGED %x %x (%d,%d) (%d,%d)", hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy)); | 
|---|
| 930 | if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) break; | 
|---|
| 931 |  | 
|---|
| 932 | hParent = hFrame = WinQueryWindow(hwnd, QW_PARENT); | 
|---|
| 933 |  | 
|---|
| 934 | OSLibMapSWPtoWINDOWPOS(pswp,&wp, &swpOld,hParent,hFrame); | 
|---|
| 935 |  | 
|---|
| 936 | win32wnd->setWindowRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy); | 
|---|
| 937 | win32wnd->setClientRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy); | 
|---|
| 938 | wp.x = swpOld.x; | 
|---|
| 939 | wp.y = swpOld.y; | 
|---|
| 940 | wp.cx = swpOld.cx; | 
|---|
| 941 | wp.cy = swpOld.cy; | 
|---|
| 942 |  | 
|---|
| 943 | wp.hwnd = win32wnd->getWindowHandle(); | 
|---|
| 944 |  | 
|---|
| 945 | win32wnd->MsgPosChanged((LPARAM)&wp); | 
|---|
| 946 |  | 
|---|
| 947 | goto RunOldWndProc; | 
|---|
| 948 | } | 
|---|
| 949 |  | 
|---|
| 950 | default: | 
|---|
| 951 | goto RunDefHandler; | 
|---|
| 952 | } | 
|---|
| 953 |  | 
|---|
| 954 | RunDefWndProc: | 
|---|
| 955 | RestoreOS2TIB(); | 
|---|
| 956 | return WinDefWindowProc(hwnd,msg,mp1,mp2); | 
|---|
| 957 |  | 
|---|
| 958 | RunOldWndProc: | 
|---|
| 959 | RestoreOS2TIB(); | 
|---|
| 960 | return ((PFNWP)win32wnd->getOldWndProc())(hwnd,msg,mp1,mp2); | 
|---|
| 961 |  | 
|---|
| 962 | RunDefHandler: | 
|---|
| 963 | RestoreOS2TIB(); | 
|---|
| 964 | return Win32WindowProc(hwnd,msg,mp1,mp2); | 
|---|
| 965 | } | 
|---|
| 966 |  | 
|---|
| 967 | PVOID SubclassWithDefHandler(HWND hwnd) | 
|---|
| 968 | { | 
|---|
| 969 | return WinSubclassWindow(hwnd,Win32SubclassWindowProc); | 
|---|
| 970 | } | 
|---|