source: trunk/src/user32/oslibmsgtranslate.cpp@ 8377

Last change on this file since 8377 was 8347, checked in by sandervl, 23 years ago

Implemented WH_MOUSE_LL hook; removed DInput hack for keyboard & mouse message translation

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