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

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

PF: Fix for double enter keyboard messages

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