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

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

PF: Keyboard fixes for right alt & right shift

File size: 35.2 KB
Line 
1/* $Id: oslibmsgtranslate.cpp,v 1.87 2002-05-23 07:13:00 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 ULONG msg;
386
387 if(winMsg->message >= WINWM_NCLBUTTONDOWN && winMsg->message <= WINWM_NCMBUTTONDBLCLK) {
388 msg = winMsg->message - WINWM_NCLBUTTONDOWN + WINWM_LBUTTONDOWN;
389 }
390 else msg = winMsg->message;
391
392 if(msg == WINWM_LBUTTONDBLCLK) {
393 msg = WINWM_LBUTTONDOWN;
394 }
395 else
396 if(msg == WINWM_RBUTTONDBLCLK) {
397 msg = WINWM_RBUTTONDOWN;
398 }
399 else
400 if(msg == WINWM_MBUTTONDBLCLK) {
401 msg = WINWM_MBUTTONDOWN;
402 }
403
404 hook.pt.x = os2Msg->ptl.x & 0xFFFF;
405 hook.pt.y = mapScreenY(os2Msg->ptl.y);
406 hook.mouseData = 0; //todo: XBUTTON1/2 (XP feature) or wheel data
407 hook.flags = 0; //todo: injected (LLMHF_INJECTED)
408 hook.time = winMsg->time;
409 hook.dwExtraInfo = 0;
410
411 if(HOOK_CallHooksW( WH_MOUSE_LL, HC_ACTION, msg, (LPARAM)&hook)) {
412 goto dummymessage; //hook swallowed message
413 }
414 }
415 break;
416 }
417
418 case WM_BUTTON2CLICK:
419 case WM_BUTTON1CLICK:
420 case WM_BUTTON3CLICK:
421 goto dummymessage;
422
423 case WM_BUTTON2MOTIONSTART:
424 case WM_BUTTON2MOTIONEND:
425 case WM_BUTTON1MOTIONSTART:
426 case WM_BUTTON1MOTIONEND:
427 case WM_BUTTON3MOTIONSTART:
428 case WM_BUTTON3MOTIONEND:
429 //no break; translate to WM_MOUSEMOVE
430 //Some applications (e.g. Unreal) retrieve all mouse messages
431 //when a mouse button is pressed and don't expect WM_NULL
432
433 case WM_MOUSEMOVE:
434 {
435 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
436
437 HWND hwnd;
438
439 dprintf2(("WM_NCMOUSEMOVE (%d,%d)", winMsg->pt.x, winMsg->pt.y));
440 DisableLogging();
441 if(GetCapture() != winMsg->hwnd)
442 {
443 hwnd = WindowFromPoint(winMsg->pt);
444 if(win32wnd->getWindowHandle() != hwnd) {
445 RELEASE_WNDOBJ(win32wnd);
446 win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
447 if(win32wnd == NULL) {
448 DebugInt3();
449 EnableLogging();
450 goto dummymessage;
451 }
452 winMsg->hwnd = hwnd;
453 }
454 }
455
456 //if a window is disabled, it's parent receives the mouse messages
457 if(!IsWindowEnabled(win32wnd->getWindowHandle())) {
458 if(win32wnd->getParent()) {
459 Win32BaseWindow *parent = win32wnd->getParent();;
460 if(parent) parent->addRef();
461 RELEASE_WNDOBJ(win32wnd);
462 win32wnd = parent;
463 }
464 fWasDisabled = TRUE;
465 }
466 if(IsNCMouseMsg(win32wnd))
467 {
468 winMsg->message = WINWM_NCMOUSEMOVE;
469 winMsg->wParam = (WPARAM)win32wnd->getLastHitTestVal();
470 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
471 }
472 else
473 {
474 ClientPoint.x = winMsg->pt.x;
475 ClientPoint.y = winMsg->pt.y;
476 MapWindowPoints(0, win32wnd->getWindowHandle(), (LPPOINT)&ClientPoint, 1);
477
478 winMsg->message = WINWM_MOUSEMOVE;
479 winMsg->wParam = GetMouseKeyState();
480 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
481 }
482 EnableLogging();
483 if(fWasDisabled) {
484 if(win32wnd) {
485 winMsg->hwnd = win32wnd->getWindowHandle();
486 }
487 else {
488 goto dummymessage; //don't send mouse messages to disabled windows
489 }
490 }
491 if(fMsgRemoved == MSG_REMOVE)
492 {
493 MSLLHOOKSTRUCT hook;
494
495 hook.pt.x = os2Msg->ptl.x & 0xFFFF;
496 hook.pt.y = mapScreenY(os2Msg->ptl.y);
497 hook.mouseData = 0;
498 hook.flags = 0; //todo: injected (LLMHF_INJECTED)
499 hook.time = winMsg->time;
500 hook.dwExtraInfo = 0;
501
502 if(HOOK_CallHooksW( WH_MOUSE_LL, HC_ACTION, winMsg->message, (LPARAM)&hook)) {
503 goto dummymessage; //hook swallowed message
504 }
505 }
506 break;
507 }
508
509 case WM_CONTROL:
510 goto dummymessage;
511
512 case WM_COMMAND:
513 if(SHORT1FROMMP(os2Msg->mp2) == CMDSRC_MENU) {
514 winMsg->message = WINWM_COMMAND;
515 winMsg->wParam = (WPARAM)SHORT1FROMMP(os2Msg->mp1); //id
516 break;
517 }
518 //todo controls
519 goto dummymessage;
520
521 case WM_SYSCOMMAND:
522 {
523 ULONG x = 0, y = 0;
524 ULONG win32sc;
525
526 if(SHORT2FROMMP(os2Msg->mp2) == TRUE) {//syscommand caused by mouse action
527 POINTL pointl;
528 WinQueryPointerPos(HWND_DESKTOP, &pointl);
529 x = pointl.x;
530 y = mapScreenY(y);
531 }
532 switch(SHORT1FROMMP(os2Msg->mp1)) {
533 case SC_MOVE:
534 win32sc = SC_MOVE_W;
535 break;
536 case SC_CLOSE:
537 {
538 //FALSE -> keyboard operation = user pressed Alt-F4 -> close app
539 //TRUE -> user clicked on close button -> close window
540 if(SHORT2FROMMP(os2Msg->mp2) == FALSE)
541 {
542 HWND hwnd = win32wnd->GetTopParent();
543 if(win32wnd->getWindowHandle() != hwnd) {
544 RELEASE_WNDOBJ(win32wnd);
545 win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
546 if(win32wnd == NULL) {
547 DebugInt3();
548 goto dummymessage;
549 }
550 winMsg->hwnd = hwnd;
551 }
552 }
553 win32sc = SC_CLOSE_W;
554 break;
555 }
556 case SC_MAXIMIZE:
557 win32sc = SC_MAXIMIZE_W;
558 break;
559 case SC_MINIMIZE:
560 win32sc = SC_MINIMIZE_W;
561 break;
562 case SC_NEXTFRAME:
563 case SC_NEXTWINDOW:
564 win32sc = SC_NEXTWINDOW_W;
565 break;
566 case SC_RESTORE:
567 win32sc = SC_RESTORE_W;
568 break;
569 case SC_TASKMANAGER:
570 win32sc = SC_TASKLIST_W;
571 break;
572 default:
573 dprintf(("Unknown/unsupported SC command %d", SHORT1FROMMP(os2Msg->mp1)));
574 goto dummymessage;
575 }
576 winMsg->message= WINWM_SYSCOMMAND;
577 winMsg->wParam = (WPARAM)win32sc;
578 winMsg->lParam = MAKELONG((USHORT)x, (USHORT)y);
579 break;
580 }
581
582 case WM_CHAR_SPECIAL:
583 {
584 // @@@PH
585 // special char message from the keyboard hook
586 dprintf(("PM: WM_CHAR_SPECIAL\n"));
587
588 // NO BREAK! FALLTHRU CASE!
589 }
590
591 case WM_CHAR:
592 {
593 ULONG repeatCount=0;
594 ULONG virtualKey=0;
595 ULONG keyFlags=0;
596 USHORT scanCode=0;
597 ULONG flags = SHORT1FROMMP(os2Msg->mp1);
598 BOOL keyWasPressed;
599 char c;
600 USHORT usPMScanCode = CHAR4FROMMP(os2Msg->mp1);
601
602 teb->o.odin.fTranslated = FALSE;
603 repeatCount = CHAR3FROMMP(os2Msg->mp1);
604 scanCode = CHAR4FROMMP(os2Msg->mp1);
605 keyWasPressed = ((SHORT1FROMMP (os2Msg->mp1) & KC_PREVDOWN) == KC_PREVDOWN);
606
607 dprintf(("PM: WM_CHAR: %x %x rep=%d scancode=%x", SHORT1FROMMP(os2Msg->mp2), SHORT2FROMMP(os2Msg->mp2), repeatCount, scanCode));
608 dprintf(("PM: WM_CHAR: hwnd %x flags %x mp1 %x, mp2 %x, time=%08xh", win32wnd->getWindowHandle(), flags, os2Msg->mp1, os2Msg->mp2, os2Msg->time));
609
610 BOOL fWinExtended;
611 BYTE bWinVKey;
612 WORD wWinScan;
613
614 if (scanCode==0) goto dummymessage;
615
616 // Note: Numlock-state currently ignored, see below
617 KeyTranslatePMScanToWinVKey(usPMScanCode,
618 FALSE,
619 &bWinVKey,
620 &wWinScan,
621 &fWinExtended);
622 winMsg->wParam = bWinVKey;
623 winMsg->lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
624 winMsg->lParam |= (wWinScan & 0x1FF) << 16; // bit 16-23, scancode + bit 15 extended
625
626 // Set the extended bit when appropriate
627 if (fWinExtended)
628 winMsg->lParam = winMsg->lParam | WIN_KEY_EXTENDED;
629
630 //@PF PM does not add KC_ALT to right alt but win32 does it
631 if (WinGetKeyState(HWND_DESKTOP, VK_ALTGRAF) & 0x8000) flags |= KC_ALT;
632#if 0
633//TODO
634 // Adjust VKEY value for pad digits if NumLock is on
635 if ((scanCode >= 0x47) && (scanCode <= 0x53) &&
636 (virtualKey >= 0x30) && (virtualKey >= 39))
637 winMsg->wParam = virtualKey + 0x30;
638#endif
639
640#ifdef ALTGR_HACK
641
642 if (usPMScanCode == PMSCAN_ALTRIGHT)
643 {
644 // Turn message into CTRL-event
645 // The original PM message is still saved inside
646 // the TEB, the next call to TranslateMessage()
647 // will then generate the required additional message
648 // for the ALTGR-event.
649 winMsg->wParam = VK_LCONTROL_W;
650 winMsg->lParam = repeatCount & 0x0FFFF;
651 winMsg->lParam |= WINSCAN_CTRLLEFT << 16
652 | WIN_KEY_DONTCARE;
653
654 if (flags & KC_KEYUP)
655 {
656 winMsg->message = WINWM_SYSKEYUP;
657 winMsg->lParam |= WIN_KEY_ALTHELD; // bit 29, alt was pressed
658 winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, always 1 for a WM_KEYUP message
659 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
660
661 // Note: altgr affects the alt-key state in windows!
662 // The overlay causes GetKeyState/GetAsyncKeyState to return
663 // the correct states
664 KeySetOverlayKeyState(VK_LCONTROL_W, KEYOVERLAYSTATE_DONTCARE);
665 KeySetOverlayKeyState(VK_CONTROL_W, KEYOVERLAYSTATE_DONTCARE);
666 }
667 else
668 {
669 winMsg->lParam |= WIN_KEY_ALTHELD;
670 if (keyWasPressed)
671 winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, 1 means key was pressed
672 winMsg->message = WINWM_KEYDOWN;
673
674 // Note: altgr affects the alt-key state in windows!
675 // The overlay causes GetKeyState/GetAsyncKeyState to return
676 // the correct states
677 KeySetOverlayKeyState(VK_LCONTROL_W, KEYOVERLAYSTATE_DOWN);
678 KeySetOverlayKeyState(VK_CONTROL_W, KEYOVERLAYSTATE_DOWN);
679 KeySetOverlayKeyState(VK_RMENU_W, KEYOVERLAYSTATE_DOWN);
680 KeySetOverlayKeyState(VK_MENU_W, KEYOVERLAYSTATE_DOWN);
681
682 // Note: when CTRL comes up, windows keeps ALTGR still down!
683 // KeySetOverlayKeyState(VK_RMENU_W, KEYOVERLAYSTATE_DOWN);
684 }
685 }
686#endif
687
688 if (!(flags & KC_ALT))
689 {
690 //
691 // the Alt key is not pressed
692 // or no more pressed
693 //
694 if (flags & KC_KEYUP)
695 {
696 // check for a lonesome ALT key ...
697 if ( (flags & KC_LONEKEY) &&
698 ((winMsg->wParam == VK_LMENU_W) || (winMsg->wParam == VK_RMENU_W)) )
699 {
700 winMsg->message = WINWM_SYSKEYUP;
701 // held ALT-key when current key is released
702 // generates additional flag 0x2000000
703 // Note: PM seems to do this differently,
704 // KC_ALT is already reset
705 }
706 else
707 {
708 // send WM_KEYUP message
709 winMsg->message = WINWM_KEYUP;
710 }
711 winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, always 1 for a WM_KEYUP message
712 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
713 }
714 else
715 { // send WM_KEYDOWN message
716 winMsg->message = WINWM_KEYDOWN;
717 if (keyWasPressed)
718 winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, 1 means key was pressed
719
720 //Shift-Enter and possibly others need to have special handling
721 if (flags & KC_SHIFT)
722 {
723 if(fMsgRemoved && !(teb->o.odin.fTranslated))
724 {
725 dprintf(("PM: KC_SHIFT: %x",winMsg->wParam));
726 if (winMsg->wParam == VK_RETURN_W)
727 {
728 MSG extramsg;
729 memcpy(&extramsg, winMsg, sizeof(MSG));
730
731 extramsg.message = WINWM_CHAR;
732
733 // insert message into the queue
734 setThreadQueueExtraCharMessage(teb, &extramsg);
735 winMsg->lParam &= 0x3FFFFFFF;
736 }
737 } // else ???
738 } // KC_SHIFT
739 else
740 {
741 // in case we handle Enter directly through PMKBDHOOK
742 if ((os2Msg->msg == WM_CHAR_SPECIAL) && (winMsg->wParam == VK_RETURN_W)
743 && (fMsgRemoved && !(teb->o.odin.fTranslated)))
744 {
745 MSG extramsg;
746 memcpy(&extramsg, winMsg, sizeof(MSG));
747
748 extramsg.message = WINWM_CHAR;
749
750 // insert message into the queue
751 setThreadQueueExtraCharMessage(teb, &extramsg);
752 }
753 }
754 }
755 }
756 else
757 {
758 //
759 // the Alt key is pressed
760 //
761 if (flags & KC_KEYUP)
762 {
763 //@@PF Note that without pmkbdhook there will not be correct message for Alt-Enter
764 winMsg->message = WINWM_SYSKEYUP;
765 winMsg->lParam |= WIN_KEY_PREVSTATE;
766 // No ALTHELD for Alt itself ;)
767 winMsg->lParam |= WIN_KEY_ALTHELD;
768 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
769 }
770 else
771 {
772 // send WM_SYSKEYDOWN message
773 winMsg->message = WINWM_SYSKEYDOWN;
774 if (keyWasPressed)
775 winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, 1 means key was pressed
776
777 // pressed ALT-key generates additional flag 0x2000000
778 // if the current window has keyboard focus
779 winMsg->lParam |= WIN_KEY_ALTHELD;
780 }
781 }
782
783#ifdef ALTGR_HACK
784 // it's a PMSCAN_ALTRIGHT WM_CHAR message?
785 // and not previously translated?
786 if(fMsgRemoved && usPMScanCode == PMSCAN_ALTRIGHT && !(teb->o.odin.fTranslated))
787 {
788 dprintf(("Queue ALTRIGHT message"));
789 // special ALTRIGHT treatment:
790 // we try to insert another WM_KEYDOWN or WM_KEYUP instead of
791 // the usual WM_CHAR which is expected here.
792 // -> experimental
793 // it's really an OS/2-style WM_CHAR message?
794 MSG extramsg;
795 memcpy(&extramsg, winMsg, sizeof(MSG));
796
797 // AltGr is not released with WINWM_SYSKEYUP, but WINWM_KEYUP
798 if(flags & KC_KEYUP)
799 {
800 extramsg.message = WINWM_KEYUP;
801 }
802 extramsg.wParam = VK_RMENU_W;
803
804 // mask out message bits and scan code
805 extramsg.lParam &= (0xDC00FFFF);
806 extramsg.lParam |= (WINSCAN_ALTRIGHT & 0x1FF) << 16;
807//// extramsg.lParam |= WIN_KEY_EXTENDED;
808 if (!(flags & KC_KEYUP))
809 extramsg.lParam |= WIN_KEY_ALTHELD;
810
811 // insert message into the queue
812 setThreadQueueExtraCharMessage(teb, &extramsg);
813 }
814#endif
815 break;
816 }
817
818 case WM_TIMER:
819//Why was this check here????
820// if (os2Msg->mp2)
821// {
822 BOOL sys;
823 ULONG id;
824
825 if (TIMER_GetTimerInfo(os2Msg->hwnd,(ULONG)os2Msg->mp1,&sys,&id))
826 {
827 winMsg->wParam = (WPARAM)id;
828 winMsg->message= (sys) ? WINWM_SYSTIMER : WINWM_TIMER;
829 break;
830 }
831// }
832 goto dummymessage; //for caret blinking
833
834 case WM_SETWINDOWPARAMS:
835 {
836 WNDPARAMS *wndParams = (WNDPARAMS *)os2Msg->mp1;
837
838 if(wndParams->fsStatus & WPM_TEXT) {
839 winMsg->message = WINWM_SETTEXT;
840 winMsg->lParam = (LPARAM)wndParams->pszText;
841 break;
842 }
843 goto dummymessage;
844 }
845
846#if 0
847 case WM_QUERYWINDOWPARAMS:
848 {
849 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
850 ULONG textlen;
851 PSZ wintext;
852
853 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
854 {
855 if(wndpars->fsStatus & WPM_CCHTEXT)
856 wndpars->cchText = win32wnd->MsgGetTextLength();
857 if(wndpars->fsStatus & WPM_TEXT)
858 wndpars->pszText = win32wnd->MsgGetText();
859
860 wndpars->fsStatus = 0;
861 wndpars->cbCtlData = 0;
862 wndpars->cbPresParams = 0;
863 goto dummymessage;
864 }
865 }
866#endif
867
868 case WM_PAINT:
869 {
870 if(win32wnd->IsWindowIconic()) {
871 winMsg->message = WINWM_PAINTICON;
872 }
873 else winMsg->message = WINWM_PAINT;
874 break;
875 }
876
877 case WM_CONTEXTMENU:
878 winMsg->message = WINWM_CONTEXTMENU;
879 winMsg->wParam = win32wnd->getWindowHandle();
880 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
881 break;
882
883 case WM_RENDERFMT:
884 winMsg->message = WINWM_RENDERFORMAT;
885 winMsg->wParam = (UINT) os2Msg->mp1;
886 break;
887
888 case WM_RENDERALLFMTS:
889 winMsg->message = WINWM_RENDERALLFORMATS;
890 break;
891
892 case WM_DESTROYCLIPBOARD:
893 winMsg->message = WINWM_DESTROYCLIPBOARD;
894 break;
895
896 case WM_HSCROLL:
897 case WM_VSCROLL:
898 winMsg->message = (os2Msg->msg == WM_HSCROLL) ? WINWM_HSCROLL : WINWM_VSCROLL;
899 winMsg->lParam = 0;
900 winMsg->wParam = 0;
901 switch(SHORT2FROMMP(os2Msg->mp2)) {
902 case SB_LINERIGHT:
903 winMsg->wParam = SB_LINERIGHT_W;
904 break;
905 case SB_LINELEFT:
906 winMsg->wParam = SB_LINELEFT_W;
907 break;
908 case SB_PAGELEFT:
909 winMsg->wParam = SB_PAGELEFT_W;
910 break;
911 case SB_PAGERIGHT:
912 winMsg->wParam = SB_PAGERIGHT_W;
913 break;
914 default:
915 dprintf(("Unsupported WM_H/VSCROLL message %x!!", SHORT2FROMMP(os2Msg->mp2)));
916 goto dummymessage;
917 }
918 break;
919
920 case WM_INITMENU:
921 case WM_MENUSELECT:
922 case WM_MENUEND:
923 case WM_NEXTMENU:
924 case WM_SYSCOLORCHANGE:
925 case WM_SYSVALUECHANGED:
926 case WM_SETSELECTION:
927 case WM_PPAINT:
928 case WM_PSETFOCUS:
929 case WM_PSYSCOLORCHANGE:
930 case WM_PSIZE:
931 case WM_PACTIVATE:
932 case WM_PCONTROL:
933 case WM_HELP:
934 case WM_APPTERMINATENOTIFY:
935 case WM_PRESPARAMCHANGED:
936 case WM_DRAWITEM:
937 case WM_MEASUREITEM:
938 case WM_CONTROLPOINTER:
939 case WM_QUERYDLGCODE:
940 case WM_SUBSTITUTESTRING:
941 case WM_MATCHMNEMONIC:
942 case WM_SAVEAPPLICATION:
943 case WM_SEMANTICEVENT:
944 default:
945dummymessage:
946 dprintf2(("dummy message %x %x %x %x", os2Msg->hwnd, os2Msg->msg, os2Msg->mp1, os2Msg->mp2));
947 winMsg->message = 0;
948 winMsg->wParam = 0;
949 winMsg->lParam = 0;
950 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
951 return FALSE;
952 }
953 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
954 return TRUE;
955}
956//******************************************************************************
957//******************************************************************************
958BOOL OSLibWinTranslateMessage(MSG *msg)
959{
960 TEB *teb;
961 MSG extramsg;
962
963 teb = GetThreadTEB();
964 if(!teb)
965 return FALSE;
966
967 UCHAR ucPMScanCode = CHAR4FROMMP(teb->o.odin.os2msg.mp1);
968 ULONG fl = SHORT1FROMMP(teb->o.odin.os2msg.mp1);
969
970
971 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
972 // the newly generated WM_CHAR message.
973 if(!teb->o.odin.fTranslated &&
974 teb->o.odin.os2msg.msg == WM_CHAR &&
975 !((SHORT1FROMMP(teb->o.odin.os2msg.mp1) & KC_KEYUP) == KC_KEYUP))
976 {
977 //TranslatedMessage was called before DispatchMessage, so queue WM_CHAR message
978 memcpy(&extramsg, msg, sizeof(MSG));
979 extramsg.wParam = SHORT1FROMMP(teb->o.odin.os2msg.mp2);
980 extramsg.lParam = 0;
981
982 // ESCAPE generates a WM_CHAR under windows, so take
983 // special care for this here.
984 switch (ucPMScanCode)
985 {
986 case PMSCAN_ESC:
987 extramsg.wParam = VK_ESCAPE_W;
988 fl |= KC_CHAR;
989 break;
990 }
991
992 if(!(fl & KC_CHAR) && msg->message < WINWM_SYSKEYDOWN)
993 {
994 return FALSE;
995 }
996
997 if(fl & KC_VIRTUALKEY)
998 {
999 if(msg->wParam)
1000 {
1001 if ((msg->wParam >= VK_NUMPAD0_W) &&
1002 (msg->wParam <= VK_NUMPAD9_W))
1003 extramsg.wParam = msg->wParam - 0x30;
1004 else
1005 extramsg.wParam = msg->wParam;
1006 }
1007 else
1008 extramsg.wParam = SHORT2FROMMP(teb->o.odin.os2msg.mp2);
1009 }
1010
1011
1012 if(msg->message >= WINWM_SYSKEYDOWN)
1013 extramsg.message = WINWM_SYSCHAR;
1014 else
1015 extramsg.message = WINWM_CHAR;
1016
1017 if(fl & KC_DEADKEY)
1018 extramsg.message++; //WM_DEADCHAR/WM_SYSDEADCHAR
1019
1020
1021 extramsg.lParam = msg->lParam & 0x00FFFFFF;
1022 if ((fl & KC_ALT) || (msg->lParam & WIN_KEY_ALTHELD))
1023 extramsg.lParam |= WIN_KEY_ALTHELD;
1024 if(fl & KC_PREVDOWN)
1025 extramsg.lParam |= WIN_KEY_PREVSTATE;
1026 if(fl & KC_KEYUP)
1027 extramsg.lParam |= (1<<31);
1028
1029 // insert message into the queue
1030 setThreadQueueExtraCharMessage(teb, &extramsg);
1031 return TRUE;
1032 }
1033 return FALSE;
1034}
1035//******************************************************************************
1036//******************************************************************************
1037
Note: See TracBrowser for help on using the repository browser.