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

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

WH_MOUSE_LL hook fixes

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