| 1 | /* $Id: oslibmsgtranslate.cpp,v 1.95 2002-09-18 10:56:49 sandervl Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | * Window message translation functions for OS/2
|
|---|
| 4 | *
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
|
|---|
| 7 | * Copyright 1999 Daniela Engert (dani@ngrt.de)
|
|---|
| 8 | * Copyright 1999 Rene Pronk (R.Pronk@twi.tudelft.nl)
|
|---|
| 9 | *
|
|---|
| 10 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 11 | *
|
|---|
| 12 | * TODO: Extra msgs: which messages must be put into the queue and which can be sent directly?
|
|---|
| 13 | * (According to the docs TranslateMessage really inserts a msg in the queue)
|
|---|
| 14 | * TODO: Filter translation isn't correct for posted messages
|
|---|
| 15 | *
|
|---|
| 16 | */
|
|---|
| 17 | #define INCL_WIN
|
|---|
| 18 | #define INCL_PM
|
|---|
| 19 | #define INCL_DOSPROCESS
|
|---|
| 20 | #include <os2wrap.h>
|
|---|
| 21 | #include <string.h>
|
|---|
| 22 | #include <misc.h>
|
|---|
| 23 | #include <winconst.h>
|
|---|
| 24 | #include <win32api.h>
|
|---|
| 25 | #include "oslibmsg.h"
|
|---|
| 26 | #include <winuser32.h>
|
|---|
| 27 | #include "win32wdesktop.h"
|
|---|
| 28 | #include "oslibutil.h"
|
|---|
| 29 | #include "timer.h"
|
|---|
| 30 | #include <thread.h>
|
|---|
| 31 | #include <wprocess.h>
|
|---|
| 32 | #include "pmwindow.h"
|
|---|
| 33 | #include "oslibwin.h"
|
|---|
| 34 | #include "winmouse.h"
|
|---|
| 35 | #include <pmkbdhk.h>
|
|---|
| 36 | #include <pmscan.h>
|
|---|
| 37 | #include <winscan.h>
|
|---|
| 38 | #include <winkeyboard.h>
|
|---|
| 39 | #include "hook.h"
|
|---|
| 40 |
|
|---|
| 41 | #define DBG_LOCALLOG DBG_oslibmsgtranslate
|
|---|
| 42 | #include "dbglocal.h"
|
|---|
| 43 |
|
|---|
| 44 | static BOOL fGenerateDoubleClick = FALSE;
|
|---|
| 45 | static MSG doubleClickMsg = {0};
|
|---|
| 46 |
|
|---|
| 47 | //For wheel mouse translation
|
|---|
| 48 | #define WHEEL_DELTA 120
|
|---|
| 49 | #define OS2_WHEEL_CORRECTION 1
|
|---|
| 50 | //PF Correction is different for different mouse drivers. For now no correction
|
|---|
| 51 | //is ok because lots of Odin controls rely on minimum delta. However in future
|
|---|
| 52 | //we will possibly detect mouse driver and use correction if speed will be
|
|---|
| 53 | //too high or too low.
|
|---|
| 54 |
|
|---|
| 55 | //******************************************************************************
|
|---|
| 56 | //******************************************************************************
|
|---|
| 57 | BOOL setThreadQueueExtraCharMessage(TEB* teb, MSG* pExtraMsg)
|
|---|
| 58 | {
|
|---|
| 59 | // check if the single slot is occupied already
|
|---|
| 60 | if (teb->o.odin.fTranslated == TRUE)
|
|---|
| 61 | // there's still an already translated message to be processed
|
|---|
| 62 | return FALSE;
|
|---|
| 63 | teb->o.odin.fTranslated = TRUE;
|
|---|
| 64 | memcpy(&teb->o.odin.msgWCHAR, pExtraMsg, sizeof(MSG));
|
|---|
| 65 | return TRUE;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | //******************************************************************************
|
|---|
| 69 | //******************************************************************************
|
|---|
| 70 | ULONG GetMouseKeyState()
|
|---|
| 71 | {
|
|---|
| 72 | ULONG keystate = 0;
|
|---|
| 73 |
|
|---|
| 74 | if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) & 0x8000)
|
|---|
| 75 | keystate |= MK_LBUTTON_W;
|
|---|
| 76 | if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2) & 0x8000)
|
|---|
| 77 | keystate |= MK_RBUTTON_W;
|
|---|
| 78 | if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3) & 0x8000)
|
|---|
| 79 | keystate |= MK_MBUTTON_W;
|
|---|
| 80 | if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT) & 0x8000)
|
|---|
| 81 | keystate |= MK_SHIFT_W;
|
|---|
| 82 | if(WinGetKeyState(HWND_DESKTOP, VK_CTRL) & 0x8000)
|
|---|
| 83 | keystate |= MK_CONTROL_W;
|
|---|
| 84 |
|
|---|
| 85 | return keystate;
|
|---|
| 86 | }
|
|---|
| 87 | //******************************************************************************
|
|---|
| 88 | //******************************************************************************
|
|---|
| 89 | LONG IsNCMouseMsg(Win32BaseWindow *win32wnd)
|
|---|
| 90 | {
|
|---|
| 91 | return ((win32wnd->getLastHitTestVal() != HTCLIENT_W) && (WinQueryCapture(HWND_DESKTOP) != win32wnd->getOS2WindowHandle()));
|
|---|
| 92 | }
|
|---|
| 93 | //******************************************************************************
|
|---|
| 94 | //******************************************************************************
|
|---|
| 95 | void SetMenuDoubleClick(BOOL fSet)
|
|---|
| 96 | {
|
|---|
| 97 | fGenerateDoubleClick = fSet;
|
|---|
| 98 | }
|
|---|
| 99 | //******************************************************************************
|
|---|
| 100 | //******************************************************************************
|
|---|
| 101 | BOOL OS2ToWinMsgTranslate(void *pTeb, QMSG *os2Msg, MSG *winMsg, BOOL isUnicode, BOOL fMsgRemoved)
|
|---|
| 102 | {
|
|---|
| 103 | Win32BaseWindow *win32wnd = 0;
|
|---|
| 104 | OSLIBPOINT point, ClientPoint;
|
|---|
| 105 | POSTMSG_PACKET *packet;
|
|---|
| 106 | TEB *teb = (TEB *)pTeb;
|
|---|
| 107 | BOOL fWasDisabled = FALSE;
|
|---|
| 108 | BOOL fIsFrame = FALSE;
|
|---|
| 109 | int i;
|
|---|
| 110 |
|
|---|
| 111 | memset(winMsg, 0, sizeof(MSG));
|
|---|
| 112 | win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(os2Msg->hwnd);
|
|---|
| 113 | if(!win32wnd) {
|
|---|
| 114 | win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(os2Msg->hwnd);
|
|---|
| 115 | if(win32wnd) {
|
|---|
| 116 | fIsFrame = TRUE;
|
|---|
| 117 | }
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | //PostThreadMessage posts WIN32APP_POSTMSG msg without window handle
|
|---|
| 121 | //Realplayer starts a timer with hwnd 0 & proc 0; check this here
|
|---|
| 122 | if(win32wnd == 0 && (os2Msg->msg != WM_CREATE && os2Msg->msg != WM_QUIT && os2Msg->msg != WM_TIMER && os2Msg->msg < WIN32APP_POSTMSG))
|
|---|
| 123 | {
|
|---|
| 124 | goto dummymessage; //not a win32 client window
|
|---|
| 125 | }
|
|---|
| 126 | winMsg->time = os2Msg->time;
|
|---|
| 127 | //CB: PM bug or undocumented feature? ptl.x highword is set!
|
|---|
| 128 | winMsg->pt.x = os2Msg->ptl.x & 0xFFFF;
|
|---|
| 129 | winMsg->pt.y = mapScreenY(os2Msg->ptl.y);
|
|---|
| 130 |
|
|---|
| 131 | if(win32wnd) //==0 for WM_CREATE/WM_QUIT
|
|---|
| 132 | winMsg->hwnd = win32wnd->getWindowHandle();
|
|---|
| 133 |
|
|---|
| 134 | if(os2Msg->msg >= WIN32APP_POSTMSG) {
|
|---|
| 135 | packet = (POSTMSG_PACKET *)os2Msg->mp2;
|
|---|
| 136 | if(packet && ((ULONG)os2Msg->mp1 == WIN32MSG_MAGICA || (ULONG)os2Msg->mp1 == WIN32MSG_MAGICW)) {
|
|---|
| 137 | winMsg->message = os2Msg->msg - WIN32APP_POSTMSG;
|
|---|
| 138 | winMsg->wParam = packet->wParam;
|
|---|
| 139 | winMsg->lParam = packet->lParam;
|
|---|
| 140 | if(fMsgRemoved == MSG_REMOVE) free(packet); //free the shared memory here
|
|---|
| 141 | if(win32wnd) RELEASE_WNDOBJ(win32wnd);
|
|---|
| 142 | return TRUE;
|
|---|
| 143 | }
|
|---|
| 144 | else {//broadcasted message (no packet present)
|
|---|
| 145 | winMsg->message = os2Msg->msg - WIN32APP_POSTMSG;
|
|---|
| 146 | winMsg->wParam = (UINT)os2Msg->mp1;
|
|---|
| 147 | winMsg->lParam = (DWORD)os2Msg->mp2;
|
|---|
| 148 | if(win32wnd) RELEASE_WNDOBJ(win32wnd);
|
|---|
| 149 | return TRUE;
|
|---|
| 150 | }
|
|---|
| 151 | goto dummymessage;
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | switch(os2Msg->msg)
|
|---|
| 155 | {
|
|---|
| 156 | //OS/2 msgs
|
|---|
| 157 | case WM_CREATE:
|
|---|
| 158 | {
|
|---|
| 159 | if(teb->o.odin.newWindow == 0) {
|
|---|
| 160 | DebugInt3();
|
|---|
| 161 | goto dummymessage;
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | win32wnd = (Win32BaseWindow *)teb->o.odin.newWindow;
|
|---|
| 165 | win32wnd->addRef();
|
|---|
| 166 |
|
|---|
| 167 | winMsg->message = WINWM_CREATE;
|
|---|
| 168 | winMsg->hwnd = win32wnd->getWindowHandle();
|
|---|
| 169 | winMsg->wParam = 0;
|
|---|
| 170 | winMsg->lParam = (LPARAM)win32wnd->tmpcs;
|
|---|
| 171 | break;
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | case WM_QUIT:
|
|---|
| 175 | winMsg->message = WINWM_QUIT;
|
|---|
| 176 | if (fMsgRemoved && win32wnd && (ULONG)os2Msg->mp2 != 0) {
|
|---|
| 177 | // mp2 != 0 -> sent by window list; be nice and close
|
|---|
| 178 | // the window first
|
|---|
| 179 | win32wnd->MsgClose();
|
|---|
| 180 | }
|
|---|
| 181 | break;
|
|---|
| 182 |
|
|---|
| 183 | case WM_CLOSE:
|
|---|
| 184 | winMsg->message = WINWM_CLOSE;
|
|---|
| 185 | break;
|
|---|
| 186 |
|
|---|
| 187 | case WM_DESTROY:
|
|---|
| 188 | winMsg->message = WINWM_DESTROY;
|
|---|
| 189 | break;
|
|---|
| 190 |
|
|---|
| 191 | case WM_ENABLE:
|
|---|
| 192 | winMsg->message = WINWM_ENABLE;
|
|---|
| 193 | winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
|
|---|
| 194 | break;
|
|---|
| 195 |
|
|---|
| 196 | case WM_SHOW:
|
|---|
| 197 | winMsg->message = WINWM_SHOWWINDOW;
|
|---|
| 198 | winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
|
|---|
| 199 | break;
|
|---|
| 200 |
|
|---|
| 201 | case WM_WINDOWPOSCHANGED:
|
|---|
| 202 | {
|
|---|
| 203 | PSWP pswp = (PSWP)os2Msg->mp1;
|
|---|
| 204 | SWP swpOld = *(pswp + 1);
|
|---|
| 205 | HWND hParent = NULLHANDLE;
|
|---|
| 206 | LONG yDelta = pswp->cy - swpOld.cy;
|
|---|
| 207 | LONG xDelta = pswp->cx - swpOld.cx;
|
|---|
| 208 |
|
|---|
| 209 | if(!fIsFrame) goto dummymessage;
|
|---|
| 210 |
|
|---|
| 211 | if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) goto dummymessage;
|
|---|
| 212 |
|
|---|
| 213 | if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
|
|---|
| 214 | if (win32wnd->isChild()) {
|
|---|
| 215 | if(win32wnd->getParent()) {
|
|---|
| 216 | hParent = win32wnd->getParent()->getOS2WindowHandle();
|
|---|
| 217 | }
|
|---|
| 218 | else goto dummymessage; //parent has just been destroyed
|
|---|
| 219 | }
|
|---|
| 220 | }
|
|---|
| 221 | if(win32wnd->getParent()) {
|
|---|
| 222 | OSLibMapSWPtoWINDOWPOS(pswp, &teb->o.odin.wp, &swpOld, win32wnd->getParent()->getClientHeight(),
|
|---|
| 223 | win32wnd->getOS2WindowHandle());
|
|---|
| 224 | }
|
|---|
| 225 | else OSLibMapSWPtoWINDOWPOS(pswp, &teb->o.odin.wp, &swpOld, OSLibQueryScreenHeight(), win32wnd->getOS2WindowHandle());
|
|---|
| 226 |
|
|---|
| 227 | if (!win32wnd->CanReceiveSizeMsgs()) goto dummymessage;
|
|---|
| 228 |
|
|---|
| 229 | if(pswp->fl & (SWP_MOVE | SWP_SIZE))
|
|---|
| 230 | {
|
|---|
| 231 | teb->o.odin.wp.hwnd = win32wnd->getWindowHandle();
|
|---|
| 232 | if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
|
|---|
| 233 | {
|
|---|
| 234 | Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
|
|---|
| 235 | if(wndAfter) {
|
|---|
| 236 | teb->o.odin.wp.hwndInsertAfter = wndAfter->getWindowHandle();
|
|---|
| 237 | RELEASE_WNDOBJ(wndAfter);
|
|---|
| 238 | }
|
|---|
| 239 | else teb->o.odin.wp.hwndInsertAfter = HWND_TOP_W;
|
|---|
| 240 | }
|
|---|
| 241 | }
|
|---|
| 242 | winMsg->message = WINWM_WINDOWPOSCHANGED;
|
|---|
| 243 | winMsg->lParam = (LPARAM)&teb->o.odin.wp;
|
|---|
| 244 | break;
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | case WM_ACTIVATE:
|
|---|
| 248 | {
|
|---|
| 249 | HWND hwndActivate = (HWND)os2Msg->mp2;
|
|---|
| 250 | BOOL fMinimized = FALSE;
|
|---|
| 251 |
|
|---|
| 252 | hwndActivate = OS2ToWin32Handle(hwndActivate);
|
|---|
| 253 | if(hwndActivate == 0) {
|
|---|
| 254 | //another (non-win32) application's window
|
|---|
| 255 | //set to desktop window handle
|
|---|
| 256 | hwndActivate = windowDesktop->getWindowHandle();
|
|---|
| 257 | }
|
|---|
| 258 |
|
|---|
| 259 | if(win32wnd->getStyle() & WS_MINIMIZE_W)
|
|---|
| 260 | {
|
|---|
| 261 | fMinimized = TRUE;
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 | winMsg->message = WINWM_ACTIVATE;
|
|---|
| 265 | winMsg->wParam = MAKELONG((SHORT1FROMMP(os2Msg->mp1)) ? WA_ACTIVE_W : WA_INACTIVE_W, fMinimized);
|
|---|
| 266 | winMsg->lParam = (LPARAM)hwndActivate;
|
|---|
| 267 | break;
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | case WM_SETFOCUS:
|
|---|
| 271 | {
|
|---|
| 272 | HWND hwndFocus = (HWND)os2Msg->mp1;
|
|---|
| 273 |
|
|---|
| 274 | if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
|
|---|
| 275 | //another (non-win32) application's window
|
|---|
| 276 | //set to NULL (allowed according to win32 SDK) to avoid problems
|
|---|
| 277 | hwndFocus = NULL;
|
|---|
| 278 | }
|
|---|
| 279 | else hwndFocus = OS2ToWin32Handle(hwndFocus);
|
|---|
| 280 |
|
|---|
| 281 | if((ULONG)os2Msg->mp2 == TRUE) {
|
|---|
| 282 | winMsg->message = WINWM_SETFOCUS;
|
|---|
| 283 | winMsg->wParam = (WPARAM)hwndFocus;
|
|---|
| 284 | }
|
|---|
| 285 | else {
|
|---|
| 286 | winMsg->message = WINWM_KILLFOCUS;
|
|---|
| 287 | winMsg->wParam = (WPARAM)hwndFocus;
|
|---|
| 288 | }
|
|---|
| 289 | break;
|
|---|
| 290 | }
|
|---|
| 291 |
|
|---|
| 292 | //**************************************************************************
|
|---|
| 293 | //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
|
|---|
| 294 | //**************************************************************************
|
|---|
| 295 | case WM_BUTTON1DOWN:
|
|---|
| 296 | case WM_BUTTON1UP:
|
|---|
| 297 | case WM_BUTTON1DBLCLK:
|
|---|
| 298 | case WM_BUTTON2DOWN:
|
|---|
| 299 | case WM_BUTTON2UP:
|
|---|
| 300 | case WM_BUTTON2DBLCLK:
|
|---|
| 301 | case WM_BUTTON3DOWN:
|
|---|
| 302 | case WM_BUTTON3UP:
|
|---|
| 303 | case WM_BUTTON3DBLCLK:
|
|---|
| 304 | {
|
|---|
| 305 | //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
|
|---|
| 306 |
|
|---|
| 307 | dprintf(("MsgButton %x (%x) %d at (%d,%d) time %x", winMsg->hwnd, os2Msg->hwnd, WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN), winMsg->pt.x, winMsg->pt.y, winMsg->time));
|
|---|
| 308 |
|
|---|
| 309 | HWND hwnd;
|
|---|
| 310 |
|
|---|
| 311 | DisableLogging();
|
|---|
| 312 | if(GetCapture() != winMsg->hwnd)
|
|---|
| 313 | {
|
|---|
| 314 | hwnd = WindowFromPoint(winMsg->pt);
|
|---|
| 315 | if(win32wnd->getWindowHandle() != hwnd) {
|
|---|
| 316 | RELEASE_WNDOBJ(win32wnd);
|
|---|
| 317 | win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 318 | if(win32wnd == NULL) {
|
|---|
| 319 | DebugInt3();
|
|---|
| 320 | EnableLogging();
|
|---|
| 321 | goto dummymessage;
|
|---|
| 322 | }
|
|---|
| 323 | winMsg->hwnd = hwnd;
|
|---|
| 324 | }
|
|---|
| 325 | }
|
|---|
| 326 |
|
|---|
| 327 | //if a window is disabled, its parent receives the mouse messages
|
|---|
| 328 | if(!IsWindowEnabled(win32wnd->getWindowHandle())) {
|
|---|
| 329 | if(win32wnd->getParent()) {
|
|---|
| 330 | Win32BaseWindow *parent = win32wnd->getParent();;
|
|---|
| 331 | if(parent) parent->addRef();
|
|---|
| 332 | RELEASE_WNDOBJ(win32wnd);
|
|---|
| 333 | win32wnd = parent;
|
|---|
| 334 | }
|
|---|
| 335 | fWasDisabled = TRUE;
|
|---|
| 336 | }
|
|---|
| 337 |
|
|---|
| 338 | if(IsNCMouseMsg(win32wnd)) {
|
|---|
| 339 | winMsg->message = WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
|
|---|
| 340 | winMsg->wParam = win32wnd->getLastHitTestVal();
|
|---|
| 341 | winMsg->lParam = MAKELONG(winMsg->pt.x, winMsg->pt.y); //screen coordinates
|
|---|
| 342 | }
|
|---|
| 343 | else {
|
|---|
| 344 | ClientPoint.x = winMsg->pt.x;
|
|---|
| 345 | ClientPoint.y = winMsg->pt.y;
|
|---|
| 346 | MapWindowPoints(0, win32wnd->getWindowHandle(), (LPPOINT)&ClientPoint, 1);
|
|---|
| 347 | winMsg->message = WINWM_LBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
|
|---|
| 348 | winMsg->wParam = GetMouseKeyState();
|
|---|
| 349 | winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
|
|---|
| 350 | }
|
|---|
| 351 | EnableLogging();
|
|---|
| 352 |
|
|---|
| 353 | if(fWasDisabled) {
|
|---|
| 354 | if(win32wnd) {
|
|---|
| 355 | winMsg->hwnd = win32wnd->getWindowHandle();
|
|---|
| 356 | }
|
|---|
| 357 | else goto dummymessage; //don't send mouse messages to disabled windows
|
|---|
| 358 | }
|
|---|
| 359 |
|
|---|
| 360 | DisableLogging();
|
|---|
| 361 | if ((winMsg->message == WINWM_LBUTTONDOWN) ||
|
|---|
| 362 | (winMsg->message == WINWM_RBUTTONDOWN) ||
|
|---|
| 363 | (winMsg->message == WINWM_MBUTTONDOWN) ||
|
|---|
| 364 | (winMsg->message == WINWM_NCLBUTTONDOWN) ||
|
|---|
| 365 | (winMsg->message == WINWM_NCRBUTTONDOWN) ||
|
|---|
| 366 | (winMsg->message == WINWM_NCMBUTTONDOWN))
|
|---|
| 367 | {
|
|---|
| 368 | if(fGenerateDoubleClick && doubleClickMsg.message == winMsg->message &&
|
|---|
| 369 | winMsg->time - doubleClickMsg.time < GetDoubleClickTime() &&
|
|---|
| 370 | (abs(winMsg->pt.x - doubleClickMsg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK_W)/2) &&
|
|---|
| 371 | (abs(winMsg->pt.y - doubleClickMsg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK_W)/2))
|
|---|
| 372 | {
|
|---|
| 373 | dprintf(("single -> double click"));
|
|---|
| 374 | if(winMsg->message >= WINWM_LBUTTONDOWN) {
|
|---|
| 375 | winMsg->message += (WINWM_LBUTTONDBLCLK - WINWM_LBUTTONDOWN);
|
|---|
| 376 | }
|
|---|
| 377 | else winMsg->message += (WINWM_LBUTTONDBLCLK - WINWM_NCLBUTTONDOWN);
|
|---|
| 378 | doubleClickMsg.message = 0;
|
|---|
| 379 | }
|
|---|
| 380 | else {
|
|---|
| 381 | dprintf(("save for double click"));
|
|---|
| 382 | doubleClickMsg = *winMsg;
|
|---|
| 383 | if(doubleClickMsg.message >= WINWM_NCLBUTTONDOWN && doubleClickMsg.message <= WINWM_NCMBUTTONDOWN) {
|
|---|
| 384 | doubleClickMsg.message += (WINWM_LBUTTONDOWN - WINWM_NCLBUTTONDOWN);
|
|---|
| 385 | }
|
|---|
| 386 | }
|
|---|
| 387 | }
|
|---|
| 388 | EnableLogging();
|
|---|
| 389 |
|
|---|
| 390 | if(fMsgRemoved == MSG_REMOVE)
|
|---|
| 391 | {
|
|---|
| 392 | MSLLHOOKSTRUCT hook;
|
|---|
| 393 | ULONG msg;
|
|---|
| 394 |
|
|---|
| 395 | if(winMsg->message >= WINWM_NCLBUTTONDOWN && winMsg->message <= WINWM_NCMBUTTONDBLCLK) {
|
|---|
| 396 | msg = winMsg->message - WINWM_NCLBUTTONDOWN + WINWM_LBUTTONDOWN;
|
|---|
| 397 | }
|
|---|
| 398 | else msg = winMsg->message;
|
|---|
| 399 |
|
|---|
| 400 | if(msg == WINWM_LBUTTONDBLCLK) {
|
|---|
| 401 | msg = WINWM_LBUTTONDOWN;
|
|---|
| 402 | }
|
|---|
| 403 | else
|
|---|
| 404 | if(msg == WINWM_RBUTTONDBLCLK) {
|
|---|
| 405 | msg = WINWM_RBUTTONDOWN;
|
|---|
| 406 | }
|
|---|
| 407 | else
|
|---|
| 408 | if(msg == WINWM_MBUTTONDBLCLK) {
|
|---|
| 409 | msg = WINWM_MBUTTONDOWN;
|
|---|
| 410 | }
|
|---|
| 411 |
|
|---|
| 412 | hook.pt.x = os2Msg->ptl.x & 0xFFFF;
|
|---|
| 413 | hook.pt.y = mapScreenY(os2Msg->ptl.y);
|
|---|
| 414 | hook.mouseData = 0; //todo: XBUTTON1/2 (XP feature) or wheel data
|
|---|
| 415 | hook.flags = 0; //todo: injected (LLMHF_INJECTED)
|
|---|
| 416 | hook.time = winMsg->time;
|
|---|
| 417 | hook.dwExtraInfo = 0;
|
|---|
| 418 |
|
|---|
| 419 | if(HOOK_CallHooksW( WH_MOUSE_LL, HC_ACTION, msg, (LPARAM)&hook)) {
|
|---|
| 420 | goto dummymessage; //hook swallowed message
|
|---|
| 421 | }
|
|---|
| 422 | }
|
|---|
| 423 | break;
|
|---|
| 424 | }
|
|---|
| 425 |
|
|---|
| 426 | case WM_BUTTON2CLICK:
|
|---|
| 427 | case WM_BUTTON1CLICK:
|
|---|
| 428 | case WM_BUTTON3CLICK:
|
|---|
| 429 | goto dummymessage;
|
|---|
| 430 |
|
|---|
| 431 | case WM_BUTTON2MOTIONSTART:
|
|---|
| 432 | case WM_BUTTON2MOTIONEND:
|
|---|
| 433 | case WM_BUTTON1MOTIONSTART:
|
|---|
| 434 | case WM_BUTTON1MOTIONEND:
|
|---|
| 435 | case WM_BUTTON3MOTIONSTART:
|
|---|
| 436 | case WM_BUTTON3MOTIONEND:
|
|---|
| 437 | //no break; translate to WM_MOUSEMOVE
|
|---|
| 438 | //Some applications (e.g. Unreal) retrieve all mouse messages
|
|---|
| 439 | //when a mouse button is pressed and don't expect WM_NULL
|
|---|
| 440 |
|
|---|
| 441 | case WM_MOUSEMOVE:
|
|---|
| 442 | {
|
|---|
| 443 | //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
|
|---|
| 444 |
|
|---|
| 445 | HWND hwnd;
|
|---|
| 446 |
|
|---|
| 447 | dprintf2(("WM_MOUSEMOVE (%d,%d)", winMsg->pt.x, winMsg->pt.y));
|
|---|
| 448 | DisableLogging();
|
|---|
| 449 | if(GetCapture() != winMsg->hwnd)
|
|---|
| 450 | {
|
|---|
| 451 | hwnd = WindowFromPoint(winMsg->pt);
|
|---|
| 452 | if(win32wnd->getWindowHandle() != hwnd) {
|
|---|
| 453 | RELEASE_WNDOBJ(win32wnd);
|
|---|
| 454 | win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 455 | if(win32wnd == NULL) {
|
|---|
| 456 | DebugInt3();
|
|---|
| 457 | EnableLogging();
|
|---|
| 458 | goto dummymessage;
|
|---|
| 459 | }
|
|---|
| 460 | winMsg->hwnd = hwnd;
|
|---|
| 461 | }
|
|---|
| 462 | }
|
|---|
| 463 |
|
|---|
| 464 | //if a window is disabled, its parent receives the mouse messages
|
|---|
| 465 | if(!IsWindowEnabled(win32wnd->getWindowHandle())) {
|
|---|
| 466 | if(win32wnd->getParent()) {
|
|---|
| 467 | Win32BaseWindow *parent = win32wnd->getParent();;
|
|---|
| 468 | if(parent) parent->addRef();
|
|---|
| 469 | RELEASE_WNDOBJ(win32wnd);
|
|---|
| 470 | win32wnd = parent;
|
|---|
| 471 | }
|
|---|
| 472 | fWasDisabled = TRUE;
|
|---|
| 473 | }
|
|---|
| 474 | if(IsNCMouseMsg(win32wnd))
|
|---|
| 475 | {
|
|---|
| 476 | winMsg->message = WINWM_NCMOUSEMOVE;
|
|---|
| 477 | winMsg->wParam = (WPARAM)win32wnd->getLastHitTestVal();
|
|---|
| 478 | winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
|
|---|
| 479 | }
|
|---|
| 480 | else
|
|---|
| 481 | {
|
|---|
| 482 | ClientPoint.x = winMsg->pt.x;
|
|---|
| 483 | ClientPoint.y = winMsg->pt.y;
|
|---|
| 484 | MapWindowPoints(0, win32wnd->getWindowHandle(), (LPPOINT)&ClientPoint, 1);
|
|---|
| 485 |
|
|---|
| 486 | winMsg->message = WINWM_MOUSEMOVE;
|
|---|
| 487 | winMsg->wParam = GetMouseKeyState();
|
|---|
| 488 | winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
|
|---|
| 489 | }
|
|---|
| 490 | EnableLogging();
|
|---|
| 491 | if(fWasDisabled) {
|
|---|
| 492 | if(win32wnd) {
|
|---|
| 493 | winMsg->hwnd = win32wnd->getWindowHandle();
|
|---|
| 494 | }
|
|---|
| 495 | else {
|
|---|
| 496 | goto dummymessage; //don't send mouse messages to disabled windows
|
|---|
| 497 | }
|
|---|
| 498 | }
|
|---|
| 499 | if(fMsgRemoved == MSG_REMOVE)
|
|---|
| 500 | {
|
|---|
| 501 | MSLLHOOKSTRUCT hook;
|
|---|
| 502 |
|
|---|
| 503 | hook.pt.x = os2Msg->ptl.x & 0xFFFF;
|
|---|
| 504 | hook.pt.y = mapScreenY(os2Msg->ptl.y);
|
|---|
| 505 | hook.mouseData = 0;
|
|---|
| 506 | hook.flags = 0; //todo: injected (LLMHF_INJECTED)
|
|---|
| 507 | hook.time = winMsg->time;
|
|---|
| 508 | hook.dwExtraInfo = 0;
|
|---|
| 509 |
|
|---|
| 510 | if(HOOK_CallHooksW( WH_MOUSE_LL, HC_ACTION, winMsg->message, (LPARAM)&hook)) {
|
|---|
| 511 | goto dummymessage; //hook swallowed message
|
|---|
| 512 | }
|
|---|
| 513 | }
|
|---|
| 514 | break;
|
|---|
| 515 | }
|
|---|
| 516 |
|
|---|
| 517 | case WM_CONTROL:
|
|---|
| 518 | goto dummymessage;
|
|---|
| 519 |
|
|---|
| 520 | case WM_COMMAND:
|
|---|
| 521 | if(SHORT1FROMMP(os2Msg->mp2) == CMDSRC_MENU) {
|
|---|
| 522 | winMsg->message = WINWM_COMMAND;
|
|---|
| 523 | winMsg->wParam = (WPARAM)SHORT1FROMMP(os2Msg->mp1); //id
|
|---|
| 524 | break;
|
|---|
| 525 | }
|
|---|
| 526 | //todo controls
|
|---|
| 527 | goto dummymessage;
|
|---|
| 528 |
|
|---|
| 529 | case WM_SYSCOMMAND:
|
|---|
| 530 | {
|
|---|
| 531 | ULONG x = 0, y = 0;
|
|---|
| 532 | ULONG win32sc;
|
|---|
| 533 |
|
|---|
| 534 | if(SHORT2FROMMP(os2Msg->mp2) == TRUE) {//syscommand caused by mouse action
|
|---|
| 535 | POINTL pointl;
|
|---|
| 536 | WinQueryPointerPos(HWND_DESKTOP, &pointl);
|
|---|
| 537 | x = pointl.x;
|
|---|
| 538 | y = mapScreenY(y);
|
|---|
| 539 | }
|
|---|
| 540 | switch(SHORT1FROMMP(os2Msg->mp1)) {
|
|---|
| 541 | case SC_MOVE:
|
|---|
| 542 | win32sc = SC_MOVE_W;
|
|---|
| 543 | break;
|
|---|
| 544 | case SC_CLOSE:
|
|---|
| 545 | {
|
|---|
| 546 | //FALSE -> keyboard operation = user pressed Alt-F4 -> close app
|
|---|
| 547 | //TRUE -> user clicked on close button -> close window
|
|---|
| 548 | if(SHORT2FROMMP(os2Msg->mp2) == FALSE)
|
|---|
| 549 | {
|
|---|
| 550 | HWND hwnd = win32wnd->GetTopParent();
|
|---|
| 551 | if(win32wnd->getWindowHandle() != hwnd) {
|
|---|
| 552 | RELEASE_WNDOBJ(win32wnd);
|
|---|
| 553 | win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 554 | if(win32wnd == NULL) {
|
|---|
| 555 | DebugInt3();
|
|---|
| 556 | goto dummymessage;
|
|---|
| 557 | }
|
|---|
| 558 | winMsg->hwnd = hwnd;
|
|---|
| 559 | }
|
|---|
| 560 | }
|
|---|
| 561 | win32sc = SC_CLOSE_W;
|
|---|
| 562 | break;
|
|---|
| 563 | }
|
|---|
| 564 | case SC_MAXIMIZE:
|
|---|
| 565 | win32sc = SC_MAXIMIZE_W;
|
|---|
| 566 | break;
|
|---|
| 567 | case SC_MINIMIZE:
|
|---|
| 568 | win32sc = SC_MINIMIZE_W;
|
|---|
| 569 | break;
|
|---|
| 570 | case SC_NEXTFRAME:
|
|---|
| 571 | case SC_NEXTWINDOW:
|
|---|
| 572 | win32sc = SC_NEXTWINDOW_W;
|
|---|
| 573 | break;
|
|---|
| 574 | case SC_RESTORE:
|
|---|
| 575 | win32sc = SC_RESTORE_W;
|
|---|
| 576 | break;
|
|---|
| 577 | case SC_TASKMANAGER:
|
|---|
| 578 | win32sc = SC_TASKLIST_W;
|
|---|
| 579 | break;
|
|---|
| 580 | default:
|
|---|
| 581 | dprintf(("Unknown/unsupported SC command %d", SHORT1FROMMP(os2Msg->mp1)));
|
|---|
| 582 | goto dummymessage;
|
|---|
| 583 | }
|
|---|
| 584 | winMsg->message= WINWM_SYSCOMMAND;
|
|---|
| 585 | winMsg->wParam = (WPARAM)win32sc;
|
|---|
| 586 | winMsg->lParam = MAKELONG((USHORT)x, (USHORT)y);
|
|---|
| 587 | break;
|
|---|
| 588 | }
|
|---|
| 589 |
|
|---|
| 590 | case WM_CHAR_SPECIAL:
|
|---|
| 591 | {
|
|---|
| 592 | // @@@PH
|
|---|
| 593 | // special char message from the keyboard hook
|
|---|
| 594 | dprintf(("PM: WM_CHAR_SPECIAL\n"));
|
|---|
| 595 |
|
|---|
| 596 | // NO BREAK! FALLTHRU CASE!
|
|---|
| 597 | }
|
|---|
| 598 |
|
|---|
| 599 | case WM_CHAR:
|
|---|
| 600 | {
|
|---|
| 601 | ULONG repeatCount=0;
|
|---|
| 602 | ULONG virtualKey=0;
|
|---|
| 603 | ULONG keyFlags=0;
|
|---|
| 604 | USHORT scanCode=0;
|
|---|
| 605 | ULONG flags = SHORT1FROMMP(os2Msg->mp1);
|
|---|
| 606 | BOOL keyWasPressed;
|
|---|
| 607 | char c;
|
|---|
| 608 | USHORT usPMScanCode = CHAR4FROMMP(os2Msg->mp1);
|
|---|
| 609 |
|
|---|
| 610 | teb->o.odin.fTranslated = FALSE;
|
|---|
| 611 | repeatCount = CHAR3FROMMP(os2Msg->mp1);
|
|---|
| 612 | scanCode = CHAR4FROMMP(os2Msg->mp1);
|
|---|
| 613 | keyWasPressed = ((SHORT1FROMMP (os2Msg->mp1) & KC_PREVDOWN) == KC_PREVDOWN);
|
|---|
| 614 |
|
|---|
| 615 | dprintf(("PM: WM_CHAR: %x %x rep=%d scancode=%x", SHORT1FROMMP(os2Msg->mp2), SHORT2FROMMP(os2Msg->mp2), repeatCount, scanCode));
|
|---|
| 616 | dprintf(("PM: WM_CHAR: hwnd %x flags %x mp1 %x, mp2 %x, time=%08xh", win32wnd->getWindowHandle(), flags, os2Msg->mp1, os2Msg->mp2, os2Msg->time));
|
|---|
| 617 |
|
|---|
| 618 | BOOL fWinExtended;
|
|---|
| 619 | BYTE bWinVKey;
|
|---|
| 620 | WORD wWinScan;
|
|---|
| 621 |
|
|---|
| 622 | if (scanCode==0) goto dummymessage;
|
|---|
| 623 |
|
|---|
| 624 | // Note: Numlock-state currently ignored, see below
|
|---|
| 625 | KeyTranslatePMScanToWinVKey(usPMScanCode,
|
|---|
| 626 | FALSE,
|
|---|
| 627 | &bWinVKey,
|
|---|
| 628 | &wWinScan,
|
|---|
| 629 | &fWinExtended);
|
|---|
| 630 | winMsg->wParam = bWinVKey;
|
|---|
| 631 | winMsg->lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
|
|---|
| 632 | winMsg->lParam |= (wWinScan & 0x1FF) << 16; // bit 16-23, scancode + bit 15 extended
|
|---|
| 633 |
|
|---|
| 634 | // Set the extended bit when appropriate
|
|---|
| 635 | if (fWinExtended)
|
|---|
| 636 | winMsg->lParam = winMsg->lParam | WIN_KEY_EXTENDED;
|
|---|
| 637 |
|
|---|
| 638 | #if 0
|
|---|
| 639 | //TODO
|
|---|
| 640 | // Adjust VKEY value for pad digits if NumLock is on
|
|---|
| 641 | if ((scanCode >= 0x47) && (scanCode <= 0x53) &&
|
|---|
| 642 | (virtualKey >= 0x30) && (virtualKey >= 39))
|
|---|
| 643 | winMsg->wParam = virtualKey + 0x30;
|
|---|
| 644 | #endif
|
|---|
| 645 |
|
|---|
| 646 | #ifdef ALTGR_HACK
|
|---|
| 647 |
|
|---|
| 648 |
|
|---|
| 649 | if (usPMScanCode == PMSCAN_ALTRIGHT)
|
|---|
| 650 | {
|
|---|
| 651 | // Turn message into CTRL-event
|
|---|
| 652 | // The original PM message is still saved inside
|
|---|
| 653 | // the TEB, the next call to TranslateMessage()
|
|---|
| 654 | // will then generate the required additional message
|
|---|
| 655 | // for the ALTGR-event.
|
|---|
| 656 | winMsg->wParam = VK_LCONTROL_W;
|
|---|
| 657 | winMsg->lParam = repeatCount & 0x0FFFF;
|
|---|
| 658 | winMsg->lParam |= WINSCAN_CTRLLEFT << 16
|
|---|
| 659 | | WIN_KEY_DONTCARE;
|
|---|
| 660 |
|
|---|
| 661 | if (flags & KC_KEYUP)
|
|---|
| 662 | {
|
|---|
| 663 | winMsg->message = WINWM_SYSKEYUP;
|
|---|
| 664 | winMsg->lParam |= WIN_KEY_ALTHELD; // bit 29, alt was pressed
|
|---|
| 665 | winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, always 1 for a WM_KEYUP message
|
|---|
| 666 | winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
|
|---|
| 667 |
|
|---|
| 668 | // Note: altgr affects the alt-key state in windows!
|
|---|
| 669 | // The overlay causes GetKeyState/GetAsyncKeyState to return
|
|---|
| 670 | // the correct states
|
|---|
| 671 | KeySetOverlayKeyState(VK_LCONTROL_W, KEYOVERLAYSTATE_DONTCARE);
|
|---|
| 672 | KeySetOverlayKeyState(VK_CONTROL_W, KEYOVERLAYSTATE_DONTCARE);
|
|---|
| 673 | }
|
|---|
| 674 | else
|
|---|
| 675 | {
|
|---|
| 676 | winMsg->lParam |= WIN_KEY_ALTHELD;
|
|---|
| 677 | if (keyWasPressed)
|
|---|
| 678 | winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, 1 means key was pressed
|
|---|
| 679 | winMsg->message = WINWM_KEYDOWN;
|
|---|
| 680 |
|
|---|
| 681 | // Note: altgr affects the alt-key state in windows!
|
|---|
| 682 | // The overlay causes GetKeyState/GetAsyncKeyState to return
|
|---|
| 683 | // the correct states
|
|---|
| 684 | KeySetOverlayKeyState(VK_LCONTROL_W, KEYOVERLAYSTATE_DOWN);
|
|---|
| 685 | KeySetOverlayKeyState(VK_CONTROL_W, KEYOVERLAYSTATE_DOWN);
|
|---|
| 686 | KeySetOverlayKeyState(VK_RMENU_W, KEYOVERLAYSTATE_DOWN);
|
|---|
| 687 | KeySetOverlayKeyState(VK_MENU_W, KEYOVERLAYSTATE_DOWN);
|
|---|
| 688 |
|
|---|
| 689 | // Note: when CTRL comes up, windows keeps ALTGR still down!
|
|---|
| 690 | // KeySetOverlayKeyState(VK_RMENU_W, KEYOVERLAYSTATE_DOWN);
|
|---|
| 691 | }
|
|---|
| 692 | }
|
|---|
| 693 | #endif
|
|---|
| 694 |
|
|---|
| 695 | //@PF This looks ugly but this is just what we have in win32 both in win98/win2k
|
|---|
| 696 | //what happens is that lParam is tweaked in win32 to contain some illegal codes
|
|---|
| 697 | //I simply reproduce here all situation. Absolute values can be kept because
|
|---|
| 698 | //Break scancode can be acheived only by pressing Ctrl-Break combination
|
|---|
| 699 | if ((usPMScanCode == PMSCAN_BREAK) && !(flags & KC_KEYUP) && (flags & KC_CTRL)
|
|---|
| 700 | && (fMsgRemoved && !(teb->o.odin.fTranslated)))
|
|---|
| 701 | {
|
|---|
| 702 | MSG extramsg;
|
|---|
| 703 | memcpy(&extramsg, winMsg, sizeof(MSG));
|
|---|
| 704 | // adjust our WM_CHAR code
|
|---|
| 705 | extramsg.lParam = 0x01460001;
|
|---|
| 706 | extramsg.message = WINWM_CHAR;
|
|---|
| 707 | setThreadQueueExtraCharMessage(teb, &extramsg);
|
|---|
| 708 | // and finally adjust our WM_KEYDOWN code
|
|---|
| 709 | winMsg->lParam = 0x01460001;
|
|---|
| 710 | }
|
|---|
| 711 |
|
|---|
| 712 | if (!(flags & KC_ALT))
|
|---|
| 713 | {
|
|---|
| 714 | //
|
|---|
| 715 | // the Alt key is not pressed
|
|---|
| 716 | // or no more pressed
|
|---|
| 717 | //
|
|---|
| 718 | if (flags & KC_KEYUP)
|
|---|
| 719 | {
|
|---|
| 720 | // check for a lonesome ALT key ...
|
|---|
| 721 | if ( (flags & KC_LONEKEY) &&
|
|---|
| 722 | ((winMsg->wParam == VK_LMENU_W) || (winMsg->wParam == VK_RMENU_W)) )
|
|---|
| 723 | {
|
|---|
| 724 | winMsg->message = WINWM_SYSKEYUP;
|
|---|
| 725 | // held ALT-key when current key is released
|
|---|
| 726 | // generates additional flag 0x2000000
|
|---|
| 727 | // Note: PM seems to do this differently,
|
|---|
| 728 | // KC_ALT is already reset
|
|---|
| 729 | }
|
|---|
| 730 | else
|
|---|
| 731 | {
|
|---|
| 732 | // send WM_KEYUP message
|
|---|
| 733 | winMsg->message = WINWM_KEYUP;
|
|---|
| 734 | }
|
|---|
| 735 | winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, always 1 for a WM_KEYUP message
|
|---|
| 736 | winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
|
|---|
| 737 | }
|
|---|
| 738 | else
|
|---|
| 739 | { // send WM_KEYDOWN message
|
|---|
| 740 | winMsg->message = WINWM_KEYDOWN;
|
|---|
| 741 |
|
|---|
| 742 | if (keyWasPressed)
|
|---|
| 743 | winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, 1 means key was pressed
|
|---|
| 744 |
|
|---|
| 745 | //Shift-Enter and possibly others need to have special handling
|
|---|
| 746 | if (flags & KC_SHIFT)
|
|---|
| 747 | {
|
|---|
| 748 | if(fMsgRemoved && !(teb->o.odin.fTranslated))
|
|---|
| 749 | {
|
|---|
| 750 | dprintf(("PM: KC_SHIFT: %x",winMsg->wParam));
|
|---|
| 751 | if (winMsg->wParam == VK_RETURN_W)
|
|---|
| 752 | {
|
|---|
| 753 | MSG extramsg;
|
|---|
| 754 | memcpy(&extramsg, winMsg, sizeof(MSG));
|
|---|
| 755 |
|
|---|
| 756 | extramsg.message = WINWM_CHAR;
|
|---|
| 757 |
|
|---|
| 758 | // insert message into the queue
|
|---|
| 759 | setThreadQueueExtraCharMessage(teb, &extramsg);
|
|---|
| 760 | winMsg->lParam &= 0x3FFFFFFF;
|
|---|
| 761 | }
|
|---|
| 762 | } // else ???
|
|---|
| 763 | } // KC_SHIFT
|
|---|
| 764 | else
|
|---|
| 765 | {
|
|---|
| 766 | // in case we handle Enter directly through PMKBDHOOK
|
|---|
| 767 | if ((os2Msg->msg == WM_CHAR_SPECIAL) && (winMsg->wParam == VK_RETURN_W)
|
|---|
| 768 | && (fMsgRemoved && !(teb->o.odin.fTranslated)))
|
|---|
| 769 | {
|
|---|
| 770 | MSG extramsg;
|
|---|
| 771 | memcpy(&extramsg, winMsg, sizeof(MSG));
|
|---|
| 772 |
|
|---|
| 773 | extramsg.message = WINWM_CHAR;
|
|---|
| 774 |
|
|---|
| 775 | // insert message into the queue
|
|---|
| 776 | setThreadQueueExtraCharMessage(teb, &extramsg);
|
|---|
| 777 | }
|
|---|
| 778 | }
|
|---|
| 779 | }
|
|---|
| 780 | // if right alt is down, then we need to set the alt down bit too
|
|---|
| 781 | if (WinGetKeyState(HWND_DESKTOP, VK_ALTGRAF) & 0x8000) {
|
|---|
| 782 | winMsg->lParam |= WIN_KEY_ALTHELD;
|
|---|
| 783 | }
|
|---|
| 784 | }
|
|---|
| 785 | else
|
|---|
| 786 | {
|
|---|
| 787 | //
|
|---|
| 788 | // the Alt key is pressed
|
|---|
| 789 | //
|
|---|
| 790 | if (flags & KC_KEYUP)
|
|---|
| 791 | {
|
|---|
| 792 | //@@PF Note that without pmkbdhook there will not be correct message for Alt-Enter
|
|---|
| 793 | winMsg->message = WINWM_SYSKEYUP;
|
|---|
| 794 | winMsg->lParam |= WIN_KEY_PREVSTATE;
|
|---|
| 795 | // No ALTHELD for Alt itself ;)
|
|---|
| 796 | winMsg->lParam |= WIN_KEY_ALTHELD;
|
|---|
| 797 | winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
|
|---|
| 798 | }
|
|---|
| 799 | else
|
|---|
| 800 | {
|
|---|
| 801 | // send WM_SYSKEYDOWN message
|
|---|
| 802 | winMsg->message = WINWM_SYSKEYDOWN;
|
|---|
| 803 | if (keyWasPressed)
|
|---|
| 804 | winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, 1 means key was pressed
|
|---|
| 805 |
|
|---|
| 806 | // pressed ALT-key generates additional flag 0x2000000
|
|---|
| 807 | // if the current window has keyboard focus
|
|---|
| 808 | winMsg->lParam |= WIN_KEY_ALTHELD;
|
|---|
| 809 | }
|
|---|
| 810 | }
|
|---|
| 811 |
|
|---|
| 812 | #ifdef ALTGR_HACK
|
|---|
| 813 | // it's a PMSCAN_ALTRIGHT WM_CHAR message?
|
|---|
| 814 | // and not previously translated?
|
|---|
| 815 | if(fMsgRemoved && usPMScanCode == PMSCAN_ALTRIGHT && !(teb->o.odin.fTranslated))
|
|---|
| 816 | {
|
|---|
| 817 | dprintf(("Queue ALTRIGHT message"));
|
|---|
| 818 | // special ALTRIGHT treatment:
|
|---|
| 819 | // we try to insert another WM_KEYDOWN or WM_KEYUP instead of
|
|---|
| 820 | // the usual WM_CHAR which is expected here.
|
|---|
| 821 | // -> experimental
|
|---|
| 822 | // it's really an OS/2-style WM_CHAR message?
|
|---|
| 823 | MSG extramsg;
|
|---|
| 824 | memcpy(&extramsg, winMsg, sizeof(MSG));
|
|---|
| 825 |
|
|---|
| 826 | // AltGr is not released with WINWM_SYSKEYUP, but WINWM_KEYUP
|
|---|
| 827 | if(flags & KC_KEYUP)
|
|---|
| 828 | {
|
|---|
| 829 | extramsg.message = WINWM_KEYUP;
|
|---|
| 830 | }
|
|---|
| 831 | extramsg.wParam = VK_RMENU_W;
|
|---|
| 832 |
|
|---|
| 833 | // mask out message bits and scan code
|
|---|
| 834 | extramsg.lParam &= (0xDC00FFFF);
|
|---|
| 835 | extramsg.lParam |= (WINSCAN_ALTRIGHT & 0x1FF) << 16;
|
|---|
| 836 | //// extramsg.lParam |= WIN_KEY_EXTENDED;
|
|---|
| 837 | if (!(flags & KC_KEYUP))
|
|---|
| 838 | extramsg.lParam |= WIN_KEY_ALTHELD;
|
|---|
| 839 |
|
|---|
| 840 | // insert message into the queue
|
|---|
| 841 | setThreadQueueExtraCharMessage(teb, &extramsg);
|
|---|
| 842 | }
|
|---|
| 843 | #endif
|
|---|
| 844 | break;
|
|---|
| 845 | }
|
|---|
| 846 |
|
|---|
| 847 | case WM_TIMER:
|
|---|
| 848 | //Why was this check here????
|
|---|
| 849 | // if (os2Msg->mp2)
|
|---|
| 850 | // {
|
|---|
| 851 | BOOL sys;
|
|---|
| 852 | ULONG id;
|
|---|
| 853 |
|
|---|
| 854 | if (TIMER_GetTimerInfo(os2Msg->hwnd,(ULONG)os2Msg->mp1,&sys,&id))
|
|---|
| 855 | {
|
|---|
| 856 | winMsg->wParam = (WPARAM)id;
|
|---|
| 857 | winMsg->message= (sys) ? WINWM_SYSTIMER : WINWM_TIMER;
|
|---|
| 858 | break;
|
|---|
| 859 | }
|
|---|
| 860 | // }
|
|---|
| 861 | goto dummymessage; //for caret blinking
|
|---|
| 862 |
|
|---|
| 863 | case WM_SETWINDOWPARAMS:
|
|---|
| 864 | {
|
|---|
| 865 | WNDPARAMS *wndParams = (WNDPARAMS *)os2Msg->mp1;
|
|---|
| 866 |
|
|---|
| 867 | if(wndParams->fsStatus & WPM_TEXT) {
|
|---|
| 868 | winMsg->message = WINWM_SETTEXT;
|
|---|
| 869 | winMsg->lParam = (LPARAM)wndParams->pszText;
|
|---|
| 870 | break;
|
|---|
| 871 | }
|
|---|
| 872 | goto dummymessage;
|
|---|
| 873 | }
|
|---|
| 874 |
|
|---|
| 875 | #if 0
|
|---|
| 876 | case WM_QUERYWINDOWPARAMS:
|
|---|
| 877 | {
|
|---|
| 878 | PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
|
|---|
| 879 | ULONG textlen;
|
|---|
| 880 | PSZ wintext;
|
|---|
| 881 |
|
|---|
| 882 | if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
|
|---|
| 883 | {
|
|---|
| 884 | if(wndpars->fsStatus & WPM_CCHTEXT)
|
|---|
| 885 | wndpars->cchText = win32wnd->MsgGetTextLength();
|
|---|
| 886 | if(wndpars->fsStatus & WPM_TEXT)
|
|---|
| 887 | wndpars->pszText = win32wnd->MsgGetText();
|
|---|
| 888 |
|
|---|
| 889 | wndpars->fsStatus = 0;
|
|---|
| 890 | wndpars->cbCtlData = 0;
|
|---|
| 891 | wndpars->cbPresParams = 0;
|
|---|
| 892 | goto dummymessage;
|
|---|
| 893 | }
|
|---|
| 894 | }
|
|---|
| 895 | #endif
|
|---|
| 896 |
|
|---|
| 897 | case WM_PAINT:
|
|---|
| 898 | {
|
|---|
| 899 | if(win32wnd->IsWindowIconic()) {
|
|---|
| 900 | winMsg->message = WINWM_PAINTICON;
|
|---|
| 901 | }
|
|---|
| 902 | else winMsg->message = WINWM_PAINT;
|
|---|
| 903 | break;
|
|---|
| 904 | }
|
|---|
| 905 |
|
|---|
| 906 | case WM_CONTEXTMENU:
|
|---|
| 907 | winMsg->message = WINWM_CONTEXTMENU;
|
|---|
| 908 | winMsg->wParam = win32wnd->getWindowHandle();
|
|---|
| 909 | winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
|
|---|
| 910 | break;
|
|---|
| 911 |
|
|---|
| 912 | case WM_RENDERFMT:
|
|---|
| 913 | winMsg->message = WINWM_RENDERFORMAT;
|
|---|
| 914 | winMsg->wParam = (UINT) os2Msg->mp1;
|
|---|
| 915 | break;
|
|---|
| 916 |
|
|---|
| 917 | case WM_RENDERALLFMTS:
|
|---|
| 918 | winMsg->message = WINWM_RENDERALLFORMATS;
|
|---|
| 919 | break;
|
|---|
| 920 |
|
|---|
| 921 | case WM_DESTROYCLIPBOARD:
|
|---|
| 922 | winMsg->message = WINWM_DESTROYCLIPBOARD;
|
|---|
| 923 | break;
|
|---|
| 924 |
|
|---|
| 925 | case WM_DRAWCLIPBOARD:
|
|---|
| 926 | winMsg->message = WINWM_DRAWCLIPBOARD;
|
|---|
| 927 | break;
|
|---|
| 928 |
|
|---|
| 929 | case WM_HSCROLL:
|
|---|
| 930 | case WM_VSCROLL:
|
|---|
| 931 | //PF For win32 we support only vertical scrolling for WM_MOUSEWHEEL
|
|---|
| 932 | if (os2Msg->msg == WM_VSCROLL)
|
|---|
| 933 | {
|
|---|
| 934 | POINT CursorPoint;
|
|---|
| 935 | winMsg->message = WINWM_MOUSEWHEEL;
|
|---|
| 936 | if (OSLibWinQueryPointerPos(&CursorPoint))
|
|---|
| 937 | mapScreenPoint((OSLIBPOINT*)&CursorPoint);
|
|---|
| 938 |
|
|---|
| 939 | if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEDOWN)
|
|---|
| 940 | winMsg->wParam = MAKELONG(GetMouseKeyState(), -WHEEL_DELTA/OS2_WHEEL_CORRECTION);
|
|---|
| 941 | else
|
|---|
| 942 | if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEUP)
|
|---|
| 943 | winMsg->wParam = MAKELONG(GetMouseKeyState(), WHEEL_DELTA/OS2_WHEEL_CORRECTION);
|
|---|
| 944 | else
|
|---|
| 945 | winMsg->wParam = MAKELONG(GetMouseKeyState(), 0);
|
|---|
| 946 |
|
|---|
| 947 | winMsg->lParam = MAKELONG(CursorPoint.x, CursorPoint.y);
|
|---|
| 948 |
|
|---|
| 949 | dprintf(("WM_MOUSEWHEEL message delta %d at (%d,%d)",HIWORD(winMsg->wParam),CursorPoint.x, CursorPoint.y));
|
|---|
| 950 | if (fMsgRemoved == MSG_REMOVE)
|
|---|
| 951 | {
|
|---|
| 952 | MSLLHOOKSTRUCT hook;
|
|---|
| 953 |
|
|---|
| 954 | hook.pt.x = os2Msg->ptl.x & 0xFFFF;
|
|---|
| 955 | hook.pt.y = mapScreenY(os2Msg->ptl.y);
|
|---|
| 956 | if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEDOWN)
|
|---|
| 957 | hook.mouseData = MAKELONG(GetMouseKeyState(), -WHEEL_DELTA/OS2_WHEEL_CORRECTION);
|
|---|
| 958 | else
|
|---|
| 959 | if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEUP)
|
|---|
| 960 | hook.mouseData = MAKELONG(GetMouseKeyState(), WHEEL_DELTA/OS2_WHEEL_CORRECTION);
|
|---|
| 961 | else goto dummymessage; // IBM driver produces other messages as well sometimes
|
|---|
| 962 |
|
|---|
| 963 | hook.flags = LLMHF_INJECTED;
|
|---|
| 964 | hook.time = winMsg->time;
|
|---|
| 965 | hook.dwExtraInfo = 0;
|
|---|
| 966 | if(HOOK_CallHooksW( WH_MOUSE_LL, HC_ACTION, WINWM_MOUSEWHEEL, (LPARAM)&hook))
|
|---|
| 967 | goto dummymessage; //hook swallowed message
|
|---|
| 968 | }
|
|---|
| 969 | break;
|
|---|
| 970 | }
|
|---|
| 971 | goto dummymessage; //eat this message
|
|---|
| 972 | break;
|
|---|
| 973 |
|
|---|
| 974 | case WM_INITMENU:
|
|---|
| 975 | case WM_MENUSELECT:
|
|---|
| 976 | case WM_MENUEND:
|
|---|
| 977 | case WM_NEXTMENU:
|
|---|
| 978 | case WM_SYSCOLORCHANGE:
|
|---|
| 979 | case WM_SYSVALUECHANGED:
|
|---|
| 980 | case WM_SETSELECTION:
|
|---|
| 981 | case WM_PPAINT:
|
|---|
| 982 | case WM_PSETFOCUS:
|
|---|
| 983 | case WM_PSYSCOLORCHANGE:
|
|---|
| 984 | case WM_PSIZE:
|
|---|
| 985 | case WM_PACTIVATE:
|
|---|
| 986 | case WM_PCONTROL:
|
|---|
| 987 | case WM_HELP:
|
|---|
| 988 | case WM_APPTERMINATENOTIFY:
|
|---|
| 989 | case WM_PRESPARAMCHANGED:
|
|---|
| 990 | case WM_DRAWITEM:
|
|---|
| 991 | case WM_MEASUREITEM:
|
|---|
| 992 | case WM_CONTROLPOINTER:
|
|---|
| 993 | case WM_QUERYDLGCODE:
|
|---|
| 994 | case WM_SUBSTITUTESTRING:
|
|---|
| 995 | case WM_MATCHMNEMONIC:
|
|---|
| 996 | case WM_SAVEAPPLICATION:
|
|---|
| 997 | case WM_SEMANTICEVENT:
|
|---|
| 998 | default:
|
|---|
| 999 | dummymessage:
|
|---|
| 1000 | dprintf2(("dummy message %x %x %x %x", os2Msg->hwnd, os2Msg->msg, os2Msg->mp1, os2Msg->mp2));
|
|---|
| 1001 | winMsg->message = 0;
|
|---|
| 1002 | winMsg->wParam = 0;
|
|---|
| 1003 | winMsg->lParam = 0;
|
|---|
| 1004 | if(win32wnd) RELEASE_WNDOBJ(win32wnd);
|
|---|
| 1005 | return FALSE;
|
|---|
| 1006 | }
|
|---|
| 1007 | if(win32wnd) RELEASE_WNDOBJ(win32wnd);
|
|---|
| 1008 | return TRUE;
|
|---|
| 1009 | }
|
|---|
| 1010 | //******************************************************************************
|
|---|
| 1011 | //******************************************************************************
|
|---|
| 1012 | BOOL OSLibWinTranslateMessage(MSG *msg)
|
|---|
| 1013 | {
|
|---|
| 1014 | TEB *teb;
|
|---|
| 1015 | MSG extramsg;
|
|---|
| 1016 |
|
|---|
| 1017 | teb = GetThreadTEB();
|
|---|
| 1018 | if(!teb)
|
|---|
| 1019 | return FALSE;
|
|---|
| 1020 |
|
|---|
| 1021 | UCHAR ucPMScanCode = CHAR4FROMMP(teb->o.odin.os2msg.mp1);
|
|---|
| 1022 | ULONG fl = SHORT1FROMMP(teb->o.odin.os2msg.mp1);
|
|---|
| 1023 |
|
|---|
| 1024 |
|
|---|
| 1025 | //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
|
|---|
| 1026 | // the newly generated WM_CHAR message.
|
|---|
| 1027 | if(!teb->o.odin.fTranslated &&
|
|---|
| 1028 | teb->o.odin.os2msg.msg == WM_CHAR &&
|
|---|
| 1029 | !((SHORT1FROMMP(teb->o.odin.os2msg.mp1) & KC_KEYUP) == KC_KEYUP))
|
|---|
| 1030 | {
|
|---|
| 1031 | //TranslatedMessage was called before DispatchMessage, so queue WM_CHAR message
|
|---|
| 1032 | memcpy(&extramsg, msg, sizeof(MSG));
|
|---|
| 1033 | extramsg.wParam = SHORT1FROMMP(teb->o.odin.os2msg.mp2);
|
|---|
| 1034 | extramsg.lParam = 0;
|
|---|
| 1035 |
|
|---|
| 1036 | // ESCAPE generates a WM_CHAR under windows, so take
|
|---|
| 1037 | // special care for this here.
|
|---|
| 1038 | switch (ucPMScanCode)
|
|---|
| 1039 | {
|
|---|
| 1040 | case PMSCAN_ESC:
|
|---|
| 1041 | extramsg.wParam = VK_ESCAPE_W;
|
|---|
| 1042 | fl |= KC_CHAR;
|
|---|
| 1043 | break;
|
|---|
| 1044 | }
|
|---|
| 1045 |
|
|---|
| 1046 | if(!(fl & KC_CHAR) && msg->message < WINWM_SYSKEYDOWN)
|
|---|
| 1047 | {
|
|---|
| 1048 | return FALSE;
|
|---|
| 1049 | }
|
|---|
| 1050 |
|
|---|
| 1051 | if(fl & KC_VIRTUALKEY)
|
|---|
| 1052 | {
|
|---|
| 1053 | if(msg->wParam)
|
|---|
| 1054 | {
|
|---|
| 1055 | if ((msg->wParam >= VK_NUMPAD0_W) &&
|
|---|
| 1056 | (msg->wParam <= VK_NUMPAD9_W))
|
|---|
| 1057 | extramsg.wParam = msg->wParam - 0x30;
|
|---|
| 1058 | else
|
|---|
| 1059 | extramsg.wParam = msg->wParam;
|
|---|
| 1060 | }
|
|---|
| 1061 | else
|
|---|
| 1062 | extramsg.wParam = SHORT2FROMMP(teb->o.odin.os2msg.mp2);
|
|---|
| 1063 | }
|
|---|
| 1064 |
|
|---|
| 1065 |
|
|---|
| 1066 | if(msg->message >= WINWM_SYSKEYDOWN)
|
|---|
| 1067 | extramsg.message = WINWM_SYSCHAR;
|
|---|
| 1068 | else
|
|---|
| 1069 | extramsg.message = WINWM_CHAR;
|
|---|
| 1070 |
|
|---|
| 1071 | if(fl & KC_DEADKEY)
|
|---|
| 1072 | extramsg.message++; //WM_DEADCHAR/WM_SYSDEADCHAR
|
|---|
| 1073 |
|
|---|
| 1074 |
|
|---|
| 1075 | extramsg.lParam = msg->lParam & 0x00FFFFFF;
|
|---|
| 1076 | if ((fl & KC_ALT) || (msg->lParam & WIN_KEY_ALTHELD))
|
|---|
| 1077 | extramsg.lParam |= WIN_KEY_ALTHELD;
|
|---|
| 1078 | if(fl & KC_PREVDOWN)
|
|---|
| 1079 | extramsg.lParam |= WIN_KEY_PREVSTATE;
|
|---|
| 1080 | if(fl & KC_KEYUP)
|
|---|
| 1081 | extramsg.lParam |= (1<<31);
|
|---|
| 1082 |
|
|---|
| 1083 | // insert message into the queue
|
|---|
| 1084 | setThreadQueueExtraCharMessage(teb, &extramsg);
|
|---|
| 1085 | return TRUE;
|
|---|
| 1086 | }
|
|---|
| 1087 | return FALSE;
|
|---|
| 1088 | }
|
|---|
| 1089 | //******************************************************************************
|
|---|
| 1090 | //******************************************************************************
|
|---|
| 1091 |
|
|---|