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

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

SendInput fix + handle Alt-F4 in default window handler

File size: 32.4 KB
Line 
1/* $Id: oslibmsgtranslate.cpp,v 1.79 2001-12-12 16:40:43 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;
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 BOOL fWinExtended;
572 BYTE bWinVKey;
573 WORD wWinScan;
574
575 // Note: Numlock-state currently ignored, see below
576 KeyTranslatePMScanToWinVKey(usPMScanCode,
577 FALSE,
578 &bWinVKey,
579 &wWinScan,
580 &fWinExtended);
581 winMsg->wParam = bWinVKey;
582 winMsg->lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
583 winMsg->lParam |= (wWinScan & 0x1FF) << 16; // bit 16-23, scancode + bit 15 extended
584
585 // Set the extended bit when appropriate
586 if (fWinExtended)
587 winMsg->lParam = winMsg->lParam | WIN_KEY_EXTENDED;
588
589#if 0
590//TODO
591 // Adjust VKEY value for pad digits if NumLock is on
592 if ((scanCode >= 0x47) && (scanCode <= 0x53) &&
593 (virtualKey >= 0x30) && (virtualKey >= 39))
594 winMsg->wParam = virtualKey + 0x30;
595#endif
596
597#ifdef ALTGR_HACK
598
599 if (usPMScanCode == PMSCAN_ALTRIGHT)
600 {
601 // Turn message into CTRL-event
602 // The original PM message is still saved inside
603 // the TEB, the next call to TranslateMessage()
604 // will then generate the required additional message
605 // for the ALTGR-event.
606 winMsg->wParam = VK_LCONTROL_W;
607 winMsg->lParam = repeatCount & 0x0FFFF;
608 winMsg->lParam |= WINSCAN_CTRLLEFT << 16
609 | WIN_KEY_DONTCARE;
610
611 if (flags & KC_KEYUP)
612 {
613 winMsg->message = WINWM_SYSKEYUP;
614 winMsg->lParam |= WIN_KEY_ALTHELD; // bit 29, alt was pressed
615 winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, always 1 for a WM_KEYUP message
616 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
617
618 // Note: altgr affects the alt-key state in windows!
619 // The overlay causes GetKeyState/GetAsyncKeyState to return
620 // the correct states
621 KeySetOverlayKeyState(VK_LCONTROL_W, KEYOVERLAYSTATE_DONTCARE);
622 KeySetOverlayKeyState(VK_CONTROL_W, KEYOVERLAYSTATE_DONTCARE);
623 }
624 else
625 {
626 winMsg->lParam |= WIN_KEY_ALTHELD;
627 if (keyWasPressed)
628 winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, 1 means key was pressed
629 winMsg->message = WINWM_KEYDOWN;
630
631 // Note: altgr affects the alt-key state in windows!
632 // The overlay causes GetKeyState/GetAsyncKeyState to return
633 // the correct states
634 KeySetOverlayKeyState(VK_LCONTROL_W, KEYOVERLAYSTATE_DOWN);
635 KeySetOverlayKeyState(VK_CONTROL_W, KEYOVERLAYSTATE_DOWN);
636 KeySetOverlayKeyState(VK_RMENU_W, KEYOVERLAYSTATE_DOWN);
637 KeySetOverlayKeyState(VK_MENU_W, KEYOVERLAYSTATE_DOWN);
638
639 // Note: when CTRL comes up, windows keeps ALTGR still down!
640 // KeySetOverlayKeyState(VK_RMENU_W, KEYOVERLAYSTATE_DOWN);
641 }
642 }
643#endif
644
645 if (!(flags & KC_ALT))
646 {
647 //
648 // the Alt key is not pressed
649 // or no more pressed
650 //
651 if (flags & KC_KEYUP)
652 {
653 // check for a lonesome ALT key ...
654 if ( (flags & KC_LONEKEY) &&
655 (winMsg->wParam == VK_LMENU_W) )
656 {
657 winMsg->message = WINWM_SYSKEYUP;
658
659 // held ALT-key when current key is released
660 // generates additional flag 0x2000000
661 // Note: PM seems to do this differently,
662 // KC_ALT is already reset
663 }
664 else
665 {
666 // send WM_KEYUP message
667 winMsg->message = WINWM_KEYUP;
668 }
669
670 winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, always 1 for a WM_KEYUP message
671 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
672 }
673 else
674 {
675 // send WM_KEYDOWN message
676 winMsg->message = WINWM_KEYDOWN;
677 if (keyWasPressed)
678 winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, 1 means key was pressed
679 }
680 }
681 else
682 {
683 //
684 // the Alt key is pressed
685 //
686 if (flags & KC_KEYUP)
687 {
688 // send WM_SYSKEYUP message
689 winMsg->message = WINWM_SYSKEYUP;
690 winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, always 1 for a WM_KEYUP message
691 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
692 }
693 else
694 {
695 // send WM_SYSKEYDOWN message
696 winMsg->message = WINWM_SYSKEYDOWN;
697 if (keyWasPressed)
698 winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, 1 means key was pressed
699
700 // pressed ALT-key generates additional flag 0x2000000
701 // if the current window has keyboard focus
702 winMsg->lParam |= WIN_KEY_ALTHELD;
703 }
704 }
705
706 if (ISKDB_CAPTURED())
707 {
708 if (DInputKeyBoardHandler(winMsg)) {
709 goto dummymessage; //dinput swallowed message
710 }
711 }
712
713#ifdef ALTGR_HACK
714 // it's a PMSCAN_ALTRIGHT WM_CHAR message?
715 // and not previously translated?
716 if(fMsgRemoved && usPMScanCode == PMSCAN_ALTRIGHT && !(teb->o.odin.fTranslated))
717 {
718 dprintf(("Queue ALTRIGHT message"));
719 // special ALTRIGHT treatment:
720 // we try to insert another WM_KEYDOWN or WM_KEYUP instead of
721 // the usual WM_CHAR which is expected here.
722 // -> experimental
723 // it's really an OS/2-style WM_CHAR message?
724 MSG extramsg;
725 memcpy(&extramsg, winMsg, sizeof(MSG));
726
727 // AltGr is not released with WINWM_SYSKEYUP, but WINWM_KEYUP
728 if(flags & KC_KEYUP)
729 {
730 extramsg.message = WINWM_KEYUP;
731 }
732 extramsg.wParam = VK_RMENU_W;
733
734 // mask out message bits and scan code
735 extramsg.lParam &= (0xDC00FFFF);
736 extramsg.lParam |= (WINSCAN_ALTRIGHT & 0x1FF) << 16;
737//// extramsg.lParam |= WIN_KEY_EXTENDED;
738 if (!(flags & KC_KEYUP))
739 extramsg.lParam |= WIN_KEY_ALTHELD;
740
741 // insert message into the queue
742 setThreadQueueExtraCharMessage(teb, &extramsg);
743 }
744#endif
745 break;
746 }
747
748 case WM_TIMER:
749//Why was this check here????
750// if (os2Msg->mp2)
751// {
752 BOOL sys;
753 ULONG id;
754
755 if (TIMER_GetTimerInfo(os2Msg->hwnd,(ULONG)os2Msg->mp1,&sys,&id))
756 {
757 winMsg->wParam = (WPARAM)id;
758 winMsg->message= (sys) ? WINWM_SYSTIMER : WINWM_TIMER;
759 break;
760 }
761// }
762 goto dummymessage; //for caret blinking
763
764 case WM_SETWINDOWPARAMS:
765 {
766 WNDPARAMS *wndParams = (WNDPARAMS *)os2Msg->mp1;
767
768 if(wndParams->fsStatus & WPM_TEXT) {
769 winMsg->message = WINWM_SETTEXT;
770 winMsg->lParam = (LPARAM)wndParams->pszText;
771 break;
772 }
773 goto dummymessage;
774 }
775
776#if 0
777 case WM_QUERYWINDOWPARAMS:
778 {
779 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
780 ULONG textlen;
781 PSZ wintext;
782
783 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
784 {
785 if(wndpars->fsStatus & WPM_CCHTEXT)
786 wndpars->cchText = win32wnd->MsgGetTextLength();
787 if(wndpars->fsStatus & WPM_TEXT)
788 wndpars->pszText = win32wnd->MsgGetText();
789
790 wndpars->fsStatus = 0;
791 wndpars->cbCtlData = 0;
792 wndpars->cbPresParams = 0;
793 goto dummymessage;
794 }
795 }
796#endif
797
798 case WM_PAINT:
799 {
800 if(win32wnd->IsWindowIconic()) {
801 winMsg->message = WINWM_PAINTICON;
802 }
803 else winMsg->message = WINWM_PAINT;
804 break;
805 }
806
807 case WM_CONTEXTMENU:
808 winMsg->message = WINWM_CONTEXTMENU;
809 winMsg->wParam = win32wnd->getWindowHandle();
810 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
811 break;
812
813 case WM_RENDERFMT:
814 winMsg->message = WINWM_RENDERFORMAT;
815 winMsg->wParam = (UINT) os2Msg->mp1;
816 break;
817
818 case WM_RENDERALLFMTS:
819 winMsg->message = WINWM_RENDERALLFORMATS;
820 break;
821
822 case WM_DESTROYCLIPBOARD:
823 winMsg->message = WINWM_DESTROYCLIPBOARD;
824 break;
825
826 case WM_HSCROLL:
827 case WM_VSCROLL:
828 winMsg->message = (os2Msg->msg == WM_HSCROLL) ? WINWM_HSCROLL : WINWM_VSCROLL;
829 winMsg->lParam = 0;
830 winMsg->wParam = 0;
831 switch(SHORT2FROMMP(os2Msg->mp2)) {
832 case SB_LINERIGHT:
833 winMsg->wParam = SB_LINERIGHT_W;
834 break;
835 case SB_LINELEFT:
836 winMsg->wParam = SB_LINELEFT_W;
837 break;
838 case SB_PAGELEFT:
839 winMsg->wParam = SB_PAGELEFT_W;
840 break;
841 case SB_PAGERIGHT:
842 winMsg->wParam = SB_PAGERIGHT_W;
843 break;
844 default:
845 dprintf(("Unsupported WM_H/VSCROLL message %x!!", SHORT2FROMMP(os2Msg->mp2)));
846 goto dummymessage;
847 }
848 break;
849
850 case WM_INITMENU:
851 case WM_MENUSELECT:
852 case WM_MENUEND:
853 case WM_NEXTMENU:
854 case WM_SYSCOLORCHANGE:
855 case WM_SYSVALUECHANGED:
856 case WM_SETSELECTION:
857 case WM_PPAINT:
858 case WM_PSETFOCUS:
859 case WM_PSYSCOLORCHANGE:
860 case WM_PSIZE:
861 case WM_PACTIVATE:
862 case WM_PCONTROL:
863 case WM_HELP:
864 case WM_APPTERMINATENOTIFY:
865 case WM_PRESPARAMCHANGED:
866 case WM_DRAWITEM:
867 case WM_MEASUREITEM:
868 case WM_CONTROLPOINTER:
869 case WM_QUERYDLGCODE:
870 case WM_SUBSTITUTESTRING:
871 case WM_MATCHMNEMONIC:
872 case WM_SAVEAPPLICATION:
873 case WM_SEMANTICEVENT:
874 default:
875dummymessage:
876 dprintf2(("dummy message %x %x %x %x", os2Msg->hwnd, os2Msg->msg, os2Msg->mp1, os2Msg->mp2));
877 winMsg->message = 0;
878 winMsg->wParam = 0;
879 winMsg->lParam = 0;
880 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
881 return FALSE;
882 }
883 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
884 return TRUE;
885}
886//******************************************************************************
887//******************************************************************************
888BOOL OSLibWinTranslateMessage(MSG *msg)
889{
890 TEB *teb;
891 MSG extramsg;
892
893 teb = GetThreadTEB();
894 if(!teb)
895 return FALSE;
896
897 UCHAR ucPMScanCode = CHAR4FROMMP(teb->o.odin.os2msg.mp1);
898 ULONG fl = SHORT1FROMMP(teb->o.odin.os2msg.mp1);
899
900
901 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
902 // the newly generated WM_CHAR message.
903 if(!teb->o.odin.fTranslated &&
904 teb->o.odin.os2msg.msg == WM_CHAR &&
905 !((SHORT1FROMMP(teb->o.odin.os2msg.mp1) & KC_KEYUP) == KC_KEYUP))
906 {
907 //TranslatedMessage was called before DispatchMessage, so queue WM_CHAR message
908 memcpy(&extramsg, msg, sizeof(MSG));
909 extramsg.wParam = SHORT1FROMMP(teb->o.odin.os2msg.mp2);
910 extramsg.lParam = 0;
911
912 // ESCAPE generates a WM_CHAR under windows, so take
913 // special care for this here.
914 switch (ucPMScanCode)
915 {
916 case PMSCAN_ESC:
917 extramsg.wParam = VK_ESCAPE_W;
918 fl |= KC_CHAR;
919 break;
920 }
921
922 if(!(fl & KC_CHAR) && msg->message < WINWM_SYSKEYDOWN)
923 {
924 return FALSE;
925 }
926
927 if(fl & KC_VIRTUALKEY)
928 {
929 if(msg->wParam)
930 {
931 if ((msg->wParam >= VK_NUMPAD0_W) &&
932 (msg->wParam <= VK_NUMPAD9_W))
933 extramsg.wParam = msg->wParam - 0x30;
934 else
935 extramsg.wParam = msg->wParam;
936 }
937 else
938 extramsg.wParam = SHORT2FROMMP(teb->o.odin.os2msg.mp2);
939 }
940
941
942 if(msg->message >= WINWM_SYSKEYDOWN)
943 extramsg.message = WINWM_SYSCHAR;
944 else
945 extramsg.message = WINWM_CHAR;
946
947 if(fl & KC_DEADKEY)
948 extramsg.message++; //WM_DEADCHAR/WM_SYSDEADCHAR
949
950
951 extramsg.lParam = msg->lParam & 0x00FFFFFF;
952 if(fl & KC_ALT)
953 extramsg.lParam |= WIN_KEY_ALTHELD;
954 if(fl & KC_PREVDOWN)
955 extramsg.lParam |= WIN_KEY_PREVSTATE;
956 if(fl & KC_KEYUP)
957 extramsg.lParam |= (1<<31);
958
959 // insert message into the queue
960 setThreadQueueExtraCharMessage(teb, &extramsg);
961 return TRUE;
962 }
963 return FALSE;
964}
965//******************************************************************************
966//******************************************************************************
967
Note: See TracBrowser for help on using the repository browser.