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

Last change on this file since 7306 was 7306, checked in by phaller, 24 years ago

some altgr fiddling

File size: 33.8 KB
Line 
1/* $Id: oslibmsgtranslate.cpp,v 1.75 2001-11-09 01:26:15 phaller 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 | (1<<24);
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 #define WIN_KEY_EXTENDED 0x01000000
644 #define WIN_KEY_DONTCARE 0x02000000
645 #define WIN_KEY_ALTHELD 0x20000000
646 #define WIN_KEY_PREVSTATE 0x40000000
647
648 if (usPMScanCode == PMSCAN_ALTRIGHT)
649 {
650 // Turn message into CTRL-event
651 // The original PM message is still saved inside
652 // the TEB, the next call to TranslateMessage()
653 // will then generate the required additional message
654 // for the ALTGR-event.
655 winMsg->wParam = VK_LCONTROL_W;
656 winMsg->lParam = repeatCount & 0x0FFFF;
657 winMsg->lParam |= WINSCAN_CTRLLEFT << 16
658 | WIN_KEY_DONTCARE;
659
660 if (flags & KC_KEYUP)
661 {
662 winMsg->message = WINWM_SYSKEYUP;
663 winMsg->lParam |= 1 << 29; // bit 29, alt was pressed
664 winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
665 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
666
667 // Note: altgr affects the alt-key state in windows!
668 // The overlay causes GetKeyState/GetAsyncKeyState to return
669 // the correct states
670 KeySetOverlayKeyState(VK_LMENU_W, KEYOVERLAYSTATE_DONTCARE);
671 KeySetOverlayKeyState(VK_LCONTROL_W, KEYOVERLAYSTATE_DONTCARE);
672 KeySetOverlayKeyState(VK_RMENU_W, KEYOVERLAYSTATE_DONTCARE);
673 }
674 else
675 {
676 winMsg->lParam |= WIN_KEY_ALTHELD;
677 if (keyWasPressed)
678 winMsg->lParam |= 1 << 30; // 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_LMENU_W, KEYOVERLAYSTATE_DOWN);
685 KeySetOverlayKeyState(VK_LCONTROL_W, KEYOVERLAYSTATE_DOWN);
686 KeySetOverlayKeyState(VK_RMENU_W, KEYOVERLAYSTATE_DOWN);
687 }
688
689 break;
690 }
691
692
693 if (!(flags & KC_ALT))
694 {
695 //
696 // the Alt key is not pressed
697 // or no more pressed
698 //
699 if (flags & KC_KEYUP)
700 {
701 // check for a lonesome ALT key ...
702 if ( (flags & KC_LONEKEY) &&
703 (winMsg->wParam == VK_LMENU_W) )
704 {
705 winMsg->message = WINWM_SYSKEYUP;
706
707 // held ALT-key when current key is released
708 // generates additional flag 0x2000000
709 // Note: PM seems to do this differently,
710 // KC_ALT is already reset
711 }
712 else
713 {
714 // send WM_KEYUP message
715 winMsg->message = WINWM_KEYUP;
716 }
717
718 winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
719 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
720 }
721 else
722 {
723 // send WM_KEYDOWN message
724 winMsg->message = WINWM_KEYDOWN;
725 if (keyWasPressed)
726 winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
727 }
728 }
729 else
730 {
731 //
732 // the Alt key is pressed
733 //
734 if (flags & KC_KEYUP)
735 {
736 // send WM_SYSKEYUP message
737 winMsg->message = WINWM_SYSKEYUP;
738 winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
739 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
740 }
741 else
742 {
743 // send WM_SYSKEYDOWN message
744 winMsg->message = WINWM_SYSKEYDOWN;
745 if (keyWasPressed)
746 winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
747
748 // pressed ALT-key generates additional flag 0x2000000
749 // if the current window has keyboard focus
750 winMsg->lParam |= 1 << 29;
751 }
752 }
753
754 if (ISKDB_CAPTURED())
755 {
756 if (DInputKeyBoardHandler(winMsg)) {
757 goto dummymessage; //dinput swallowed message
758 }
759 }
760 break;
761 }
762
763 case WM_TIMER:
764//Why was this check here????
765// if (os2Msg->mp2)
766// {
767 BOOL sys;
768 ULONG id;
769
770 if (TIMER_GetTimerInfo(os2Msg->hwnd,(ULONG)os2Msg->mp1,&sys,&id))
771 {
772 winMsg->wParam = (WPARAM)id;
773 winMsg->message= (sys) ? WINWM_SYSTIMER : WINWM_TIMER;
774 break;
775 }
776// }
777 goto dummymessage; //for caret blinking
778
779 case WM_SETWINDOWPARAMS:
780 {
781 WNDPARAMS *wndParams = (WNDPARAMS *)os2Msg->mp1;
782
783 if(wndParams->fsStatus & WPM_TEXT) {
784 winMsg->message = WINWM_SETTEXT;
785 winMsg->lParam = (LPARAM)wndParams->pszText;
786 break;
787 }
788 goto dummymessage;
789 }
790
791#if 0
792 case WM_QUERYWINDOWPARAMS:
793 {
794 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
795 ULONG textlen;
796 PSZ wintext;
797
798 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
799 {
800 if(wndpars->fsStatus & WPM_CCHTEXT)
801 wndpars->cchText = win32wnd->MsgGetTextLength();
802 if(wndpars->fsStatus & WPM_TEXT)
803 wndpars->pszText = win32wnd->MsgGetText();
804
805 wndpars->fsStatus = 0;
806 wndpars->cbCtlData = 0;
807 wndpars->cbPresParams = 0;
808 goto dummymessage;
809 }
810 }
811#endif
812
813 case WM_PAINT:
814 {
815 if(win32wnd->IsWindowIconic()) {
816 winMsg->message = WINWM_PAINTICON;
817 }
818 else winMsg->message = WINWM_PAINT;
819 break;
820 }
821
822 case WM_CONTEXTMENU:
823 winMsg->message = WINWM_CONTEXTMENU;
824 winMsg->wParam = win32wnd->getWindowHandle();
825 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
826 break;
827
828 case WM_RENDERFMT:
829 winMsg->message = WINWM_RENDERFORMAT;
830 winMsg->wParam = (UINT) os2Msg->mp1;
831 break;
832
833 case WM_RENDERALLFMTS:
834 winMsg->message = WINWM_RENDERALLFORMATS;
835 break;
836
837 case WM_DESTROYCLIPBOARD:
838 winMsg->message = WINWM_DESTROYCLIPBOARD;
839 break;
840
841 case WM_HSCROLL:
842 case WM_VSCROLL:
843 winMsg->message = (os2Msg->msg == WM_HSCROLL) ? WINWM_HSCROLL : WINWM_VSCROLL;
844 winMsg->lParam = 0;
845 winMsg->wParam = 0;
846 switch(SHORT2FROMMP(os2Msg->mp2)) {
847 case SB_LINERIGHT:
848 winMsg->wParam = SB_LINERIGHT_W;
849 break;
850 case SB_LINELEFT:
851 winMsg->wParam = SB_LINELEFT_W;
852 break;
853 case SB_PAGELEFT:
854 winMsg->wParam = SB_PAGELEFT_W;
855 break;
856 case SB_PAGERIGHT:
857 winMsg->wParam = SB_PAGERIGHT_W;
858 break;
859 default:
860 dprintf(("Unsupported WM_H/VSCROLL message %x!!", SHORT2FROMMP(os2Msg->mp2)));
861 goto dummymessage;
862 }
863 break;
864
865 case WM_INITMENU:
866 case WM_MENUSELECT:
867 case WM_MENUEND:
868 case WM_NEXTMENU:
869 case WM_SYSCOLORCHANGE:
870 case WM_SYSVALUECHANGED:
871 case WM_SETSELECTION:
872 case WM_PPAINT:
873 case WM_PSETFOCUS:
874 case WM_PSYSCOLORCHANGE:
875 case WM_PSIZE:
876 case WM_PACTIVATE:
877 case WM_PCONTROL:
878 case WM_HELP:
879 case WM_APPTERMINATENOTIFY:
880 case WM_PRESPARAMCHANGED:
881 case WM_DRAWITEM:
882 case WM_MEASUREITEM:
883 case WM_CONTROLPOINTER:
884 case WM_QUERYDLGCODE:
885 case WM_SUBSTITUTESTRING:
886 case WM_MATCHMNEMONIC:
887 case WM_SAVEAPPLICATION:
888 case WM_SEMANTICEVENT:
889 default:
890dummymessage:
891 dprintf2(("dummy message %x %x %x %x", os2Msg->hwnd, os2Msg->msg, os2Msg->mp1, os2Msg->mp2));
892 winMsg->message = 0;
893 winMsg->wParam = 0;
894 winMsg->lParam = 0;
895 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
896 return FALSE;
897 }
898 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
899 return TRUE;
900}
901//******************************************************************************
902//******************************************************************************
903BOOL OSLibWinTranslateMessage(MSG *msg)
904{
905 TEB *teb;
906 MSG extramsg;
907
908 teb = GetThreadTEB();
909 if(!teb)
910 return FALSE;
911
912 UCHAR ucPMScanCode = CHAR4FROMMP(teb->o.odin.os2msg.mp1);
913 ULONG fl = SHORT1FROMMP(teb->o.odin.os2msg.mp1);
914
915
916 // special ALTRIGHT treatment:
917 // we try to insert another WM_KEYDOWN or WM_KEYUP instead of
918 // the usual WM_CHAR which is expected here.
919 // -> experimental
920 if (ucPMScanCode == PMSCAN_ALTRIGHT)
921 {
922 // it's really an OS/2-style WM_CHAR message?
923 // and not previously translated?
924 if ( ( (teb->o.odin.os2msg.msg != WM_CHAR) &&
925 (teb->o.odin.os2msg.msg != WM_CHAR_SPECIAL) ) ||
926 (teb->o.odin.fTranslated) )
927 return FALSE;
928
929 memcpy(&extramsg, msg, sizeof(MSG));
930
931 // AltGr is not released with WINWM_SYSKEYUP, but WINWM_KEYUP
932 if (fl & KC_KEYUP)
933 extramsg.message = WINWM_KEYUP;
934
935 extramsg.wParam = VK_RMENU_W;
936
937 // mask out message bits and scan code
938 extramsg.lParam &= (0xDC00FFFF);
939 extramsg.lParam |= (WINSCAN_ALTRIGHT & 0x1FF) << 16;
940 extramsg.lParam |= WIN_KEY_EXTENDED;
941 if (!(fl & KC_KEYUP))
942 extramsg.lParam |= WIN_KEY_ALTHELD;
943
944 // insert message into the queue
945 setThreadQueueExtraCharMessage(teb, &extramsg);
946 return TRUE;
947 }
948
949 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
950 // the newly generated WM_CHAR message.
951 if(!teb->o.odin.fTranslated &&
952 teb->o.odin.os2msg.msg == WM_CHAR &&
953 !((SHORT1FROMMP(teb->o.odin.os2msg.mp1) & KC_KEYUP) == KC_KEYUP))
954 {
955 //TranslatedMessage was called before DispatchMessage, so queue WM_CHAR message
956 memcpy(&extramsg, msg, sizeof(MSG));
957 extramsg.wParam = SHORT1FROMMP(teb->o.odin.os2msg.mp2);
958 extramsg.lParam = 0;
959
960 // ESCAPE generates a WM_CHAR under windows, so take
961 // special care for this here.
962 switch (ucPMScanCode)
963 {
964 case PMSCAN_ESC:
965 extramsg.wParam = VK_ESCAPE_W;
966 fl |= KC_CHAR;
967 break;
968 }
969
970 if(!(fl & KC_CHAR) && msg->message < WINWM_SYSKEYDOWN)
971 {
972 return FALSE;
973 }
974
975 if(fl & KC_VIRTUALKEY)
976 {
977 if(msg->wParam)
978 {
979 if ((msg->wParam >= VK_NUMPAD0_W) &&
980 (msg->wParam <= VK_NUMPAD9_W))
981 extramsg.wParam = msg->wParam - 0x30;
982 else
983 extramsg.wParam = msg->wParam;
984 }
985 else
986 extramsg.wParam = SHORT2FROMMP(teb->o.odin.os2msg.mp2);
987 }
988
989
990 if(msg->message >= WINWM_SYSKEYDOWN)
991 extramsg.message = WINWM_SYSCHAR;
992 else
993 extramsg.message = WINWM_CHAR;
994
995 if(fl & KC_DEADKEY)
996 extramsg.message++; //WM_DEADCHAR/WM_SYSDEADCHAR
997
998
999 extramsg.lParam = msg->lParam & 0x00FFFFFF;
1000 if(fl & KC_ALT)
1001 extramsg.lParam |= (1<<29);
1002 if(fl & KC_PREVDOWN)
1003 extramsg.lParam |= (1<<30);
1004 if(fl & KC_KEYUP)
1005 extramsg.lParam |= (1<<31);
1006
1007 // insert message into the queue
1008 setThreadQueueExtraCharMessage(teb, &extramsg);
1009 return TRUE;
1010 }
1011 return FALSE;
1012}
1013//******************************************************************************
1014//******************************************************************************
1015
Note: See TracBrowser for help on using the repository browser.