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

Last change on this file since 7612 was 7612, checked in by sandervl, 24 years ago

hook, scancode + altgr fixes

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