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

Last change on this file since 10501 was 10501, checked in by sandervl, 21 years ago

Added support for WH_MOUSE hook

File size: 43.8 KB
Line 
1/* $Id: oslibmsgtranslate.cpp,v 1.120 2004-03-10 09:21:09 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 <winnls.h>
40#include <heapstring.h>
41#include "hook.h"
42#include "user32api.h"
43
44
45#define DBG_LOCALLOG DBG_oslibmsgtranslate
46#include "dbglocal.h"
47
48static BOOL fGenerateDoubleClick = FALSE;
49static MSG doubleClickMsg = {0};
50
51//For wheel mouse translation
52#define WHEEL_DELTA 120
53#define OS2_WHEEL_CORRECTION 1
54//PF Correction is different for different mouse drivers. For now no correction
55//is ok because lots of Odin controls rely on minimum delta. However in future
56//we will possibly detect mouse driver and use correction if speed will be
57//too high or too low.
58
59//******************************************************************************
60//
61// setThreadQueueExtraCharMessage: queues WM_CHAR message so it is retrieved
62// by GetMessage & PeekMessage
63//
64// NOTE: WM_CHAR message always in ascii format
65//
66//******************************************************************************
67BOOL setThreadQueueExtraCharMessage(TEB* teb, MSG* pExtraMsg)
68{
69 if ( teb->o.odin.tidAttachedInputThread
70 && OSLibForwardMessageToAttachedThread(teb, pExtraMsg, NULL))
71 return TRUE;
72
73 // check if the single slot is occupied already
74 if (teb->o.odin.fTranslated == TRUE) {
75 // there's still an already translated message to be processed
76 dprintf(("WARNING: translated message already pending!"));
77 return FALSE;
78 }
79
80 teb->o.odin.fTranslated = TRUE;
81 memcpy(&teb->o.odin.msgWCHAR, pExtraMsg, sizeof(MSG));
82 return TRUE;
83}
84
85//******************************************************************************
86//******************************************************************************
87ULONG ConvertNumPadKey(ULONG pmScan)
88{
89 ULONG ret;
90 BYTE winKey;
91
92 switch (pmScan)
93 {
94 case PMSCAN_PAD7: ret = PMSCAN_HOME; break;
95 case PMSCAN_PAD8: ret = PMSCAN_UP; break;
96 case PMSCAN_PAD9: ret = PMSCAN_PAGEUP; break;
97 case PMSCAN_PAD4: ret = PMSCAN_LEFT; break;
98 case PMSCAN_PAD6: ret = PMSCAN_RIGHT; break;
99 case PMSCAN_PAD1: ret = PMSCAN_END; break;
100 case PMSCAN_PAD2: ret = PMSCAN_DOWN; break;
101 case PMSCAN_PAD3: ret = PMSCAN_PAGEDOWN; break;
102 case PMSCAN_PAD0: ret = PMSCAN_INSERT; break;
103 case PMSCAN_PADPERIOD: ret = PMSCAN_DELETE; break;
104 default:
105 ret = pmScan;
106 }
107
108 KeyTranslatePMScanToWinVKey(ret, FALSE, (PBYTE)&winKey, NULL, NULL);
109 return winKey;
110
111}
112//******************************************************************************
113//******************************************************************************
114LONG IsNCMouseMsg(Win32BaseWindow *win32wnd)
115{
116 return ((win32wnd->getLastHitTestVal() != HTCLIENT_W) && (WinQueryCapture(HWND_DESKTOP) != win32wnd->getOS2WindowHandle()));
117}
118//******************************************************************************
119//******************************************************************************
120void OSLibSetMenuDoubleClick(BOOL fSet)
121{
122 fGenerateDoubleClick = fSet;
123}
124//******************************************************************************
125
126
127/**
128 * Inter process/thread packet cleanup.
129 * See OSLibPackMessage() for details on the packing.
130 *
131 * @param pTeb Pointer to the thread environment block for the current thread.
132 * @param pPacket Pointer to the packet in question.
133 * @param pWinMsg Pointer to the window message corresponding to the packet.
134 */
135inline void OSLibCleanupPacket(TEB *pTeb, POSTMSG_PACKET *pPacket, MSG *pWinMsg)
136{
137 switch (pWinMsg->message)
138 {
139 /*
140 * Place this in the TEB freeing any previous WM_COPYDATA packet.
141 * Note! Nested WM_COPYDATA isn't working.
142 */
143 case WINWM_COPYDATA:
144 {
145 dprintf(("OSLibCleanupPacket: WM_COPYDATA: old %#p new %#p", pTeb->o.odin.pWM_COPYDATA, pPacket));
146 if (pTeb->o.odin.pWM_COPYDATA)
147 _sfree(pTeb->o.odin.pWM_COPYDATA);
148 pTeb->o.odin.pWM_COPYDATA = pPacket;
149 break;
150 }
151
152 /*
153 * Default packing - free the shared memory here.
154 */
155 default:
156 _sfree(pPacket);
157 break;
158 }
159}
160
161//******************************************************************************
162BOOL OS2ToWinMsgTranslate(void *pTeb, QMSG *os2Msg, MSG *winMsg, BOOL isUnicode, BOOL fMsgRemoved)
163{
164 Win32BaseWindow *win32wnd = 0;
165 OSLIBPOINT point, ClientPoint;
166 POSTMSG_PACKET *packet;
167 TEB *teb = (TEB *)pTeb;
168 BOOL fWasDisabled = FALSE;
169 BOOL fIsFrame = FALSE;
170 int i;
171
172 /*
173 * Forwarded input (AttachThreadInput()).
174 */
175 if ( os2Msg->hwnd == NULLHANDLE
176 && os2Msg->msg == WIN32APP_FORWARDEDPOSTMSG
177 && os2Msg->mp2 == (MPARAM)WIN32APP_FORWARDEDPOSTMSG_MAGIC
178 && os2Msg->mp1 != NULL)
179 {
180 *winMsg = *(MSG*)os2Msg->mp1;
181 if (fMsgRemoved)
182 _sfree(os2Msg->mp1);
183 dprintf(("OS2ToWinMsgTranslate: Received forwarded messaged %x\n", os2Msg->msg));
184 return TRUE;
185 }
186
187 memset(winMsg, 0, sizeof(MSG));
188 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(os2Msg->hwnd);
189 if(!win32wnd) {
190 win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(os2Msg->hwnd);
191 if(win32wnd) {
192 fIsFrame = TRUE;
193 }
194 }
195
196 //PostThreadMessage posts WIN32APP_POSTMSG msg without window handle
197 //Realplayer starts a timer with hwnd 0 & proc 0; check this here
198 if(win32wnd == 0 && (os2Msg->msg != WM_CREATE && os2Msg->msg != WM_QUIT && os2Msg->msg != WM_TIMER && os2Msg->msg < WIN32APP_POSTMSG))
199 {
200 goto dummymessage; //not a win32 client window
201 }
202 winMsg->time = os2Msg->time;
203 //CB: PM bug or undocumented feature? ptl.x highword is set!
204 winMsg->pt.x = os2Msg->ptl.x & 0xFFFF;
205 winMsg->pt.y = mapScreenY(os2Msg->ptl.y);
206
207 if(win32wnd) //==0 for WM_CREATE/WM_QUIT
208 winMsg->hwnd = win32wnd->getWindowHandle();
209
210 if(os2Msg->msg >= WIN32APP_POSTMSG) {
211 packet = (POSTMSG_PACKET *)os2Msg->mp2;
212 if(packet && ((ULONG)os2Msg->mp1 == WIN32MSG_MAGICA || (ULONG)os2Msg->mp1 == WIN32MSG_MAGICW)) {
213 winMsg->message = os2Msg->msg - WIN32APP_POSTMSG;
214 winMsg->wParam = packet->wParam;
215 winMsg->lParam = packet->lParam;
216 if (fMsgRemoved == MSG_REMOVE)
217 OSLibCleanupPacket(teb, packet, winMsg);
218 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
219 return TRUE;
220 }
221 else {//broadcasted message (no packet present)
222 winMsg->message = os2Msg->msg - WIN32APP_POSTMSG;
223 winMsg->wParam = (UINT)os2Msg->mp1;
224 winMsg->lParam = (DWORD)os2Msg->mp2;
225 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
226 return TRUE;
227 }
228 goto dummymessage;
229 }
230
231 switch(os2Msg->msg)
232 {
233 //OS/2 msgs
234 case WM_CREATE:
235 {
236 if(teb->o.odin.newWindow == 0) {
237 DebugInt3();
238 goto dummymessage;
239 }
240
241 win32wnd = (Win32BaseWindow *)teb->o.odin.newWindow;
242 win32wnd->addRef();
243
244 winMsg->message = WINWM_CREATE;
245 winMsg->hwnd = win32wnd->getWindowHandle();
246 winMsg->wParam = 0;
247 winMsg->lParam = (LPARAM)win32wnd->tmpcs;
248 break;
249 }
250
251 case WM_QUIT:
252 winMsg->message = WINWM_QUIT;
253 if (fMsgRemoved && win32wnd && (ULONG)os2Msg->mp2 != 0) {
254 // mp2 != 0 -> sent by window list; be nice and close
255 // the window first
256 win32wnd->MsgClose();
257 }
258 break;
259
260 case WM_CLOSE:
261 winMsg->message = WINWM_CLOSE;
262 break;
263
264 case WM_DESTROY:
265 winMsg->message = WINWM_DESTROY;
266 break;
267
268 case WM_ENABLE:
269 winMsg->message = WINWM_ENABLE;
270 winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
271 break;
272
273 case WM_SHOW:
274 winMsg->message = WINWM_SHOWWINDOW;
275 winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
276 break;
277
278 case WM_REALIZEPALETTE:
279 winMsg->message = WINWM_PALETTECHANGED;
280 break;
281
282 case WM_WINDOWPOSCHANGED:
283 {
284 PSWP pswp = (PSWP)os2Msg->mp1;
285 SWP swpOld = *(pswp + 1);
286 HWND hParent = NULLHANDLE;
287 LONG yDelta = pswp->cy - swpOld.cy;
288 LONG xDelta = pswp->cx - swpOld.cx;
289
290 if(!fIsFrame) goto dummymessage;
291
292 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) goto dummymessage;
293
294 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
295 if (win32wnd->isChild()) {
296 if(win32wnd->getParent()) {
297 hParent = win32wnd->getParent()->getOS2WindowHandle();
298 }
299 else goto dummymessage; //parent has just been destroyed
300 }
301 }
302 if(win32wnd->getParent()) {
303 OSLibMapSWPtoWINDOWPOS(pswp, &teb->o.odin.wp, &swpOld, win32wnd->getParent()->getClientHeight(),
304 win32wnd->getOS2WindowHandle());
305 }
306 else OSLibMapSWPtoWINDOWPOS(pswp, &teb->o.odin.wp, &swpOld, OSLibQueryScreenHeight(), win32wnd->getOS2WindowHandle());
307
308 if (!win32wnd->CanReceiveSizeMsgs()) goto dummymessage;
309
310 if(pswp->fl & (SWP_MOVE | SWP_SIZE))
311 {
312 teb->o.odin.wp.hwnd = win32wnd->getWindowHandle();
313 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
314 {
315 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
316 if(wndAfter) {
317 teb->o.odin.wp.hwndInsertAfter = wndAfter->getWindowHandle();
318 RELEASE_WNDOBJ(wndAfter);
319 }
320 else teb->o.odin.wp.hwndInsertAfter = HWND_TOP_W;
321 }
322 }
323 winMsg->message = WINWM_WINDOWPOSCHANGED;
324 winMsg->lParam = (LPARAM)&teb->o.odin.wp;
325 break;
326 }
327
328 case WM_ACTIVATE:
329 {
330 HWND hwndActivate = (HWND)os2Msg->mp2;
331 BOOL fMinimized = FALSE;
332
333 hwndActivate = OS2ToWin32Handle(hwndActivate);
334 if(hwndActivate == 0) {
335 //another (non-win32) application's window
336 //set to desktop window handle
337 hwndActivate = windowDesktop->getWindowHandle();
338 }
339
340 if(win32wnd->getStyle() & WS_MINIMIZE_W)
341 {
342 fMinimized = TRUE;
343 }
344
345 winMsg->message = WINWM_ACTIVATE;
346 winMsg->wParam = MAKELONG((SHORT1FROMMP(os2Msg->mp1)) ? WA_ACTIVE_W : WA_INACTIVE_W, fMinimized);
347 winMsg->lParam = (LPARAM)hwndActivate;
348 break;
349 }
350
351 case WM_SETFOCUS:
352 {
353 HWND hwndFocus = (HWND)os2Msg->mp1;
354
355 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
356 //another (non-win32) application's window
357 //set to NULL (allowed according to win32 SDK) to avoid problems
358 hwndFocus = NULL;
359 }
360 else hwndFocus = OS2ToWin32Handle(hwndFocus);
361
362 if((ULONG)os2Msg->mp2 == TRUE) {
363 winMsg->message = WINWM_SETFOCUS;
364 winMsg->wParam = (WPARAM)hwndFocus;
365 }
366 else {
367 //If SetFocus(0) was called, then the window has already received
368 //a WM_KILLFOCUS; don't send another one
369 if(!fIgnoreKeystrokes) {
370 winMsg->message = WINWM_KILLFOCUS;
371 winMsg->wParam = (WPARAM)hwndFocus;
372 }
373 else {
374 dprintf(("Window has already received a WM_KILLFOCUS (SetFocus(0)); ignore"));
375 goto dummymessage;
376 }
377 }
378 break;
379 }
380
381 //**************************************************************************
382 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
383 //**************************************************************************
384 case WM_BUTTON1DOWN:
385 case WM_BUTTON1UP:
386 case WM_BUTTON1DBLCLK:
387 case WM_BUTTON2DOWN:
388 case WM_BUTTON2UP:
389 case WM_BUTTON2DBLCLK:
390 case WM_BUTTON3DOWN:
391 case WM_BUTTON3UP:
392 case WM_BUTTON3DBLCLK:
393 {
394 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
395
396 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));
397
398 HWND hwnd;
399
400 DisableLogging();
401 if(GetCapture() != winMsg->hwnd)
402 {
403 hwnd = WindowFromPoint(winMsg->pt);
404 if(win32wnd->getWindowHandle() != hwnd) {
405 RELEASE_WNDOBJ(win32wnd);
406 win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
407 if(win32wnd == NULL) {
408 DebugInt3();
409 EnableLogging();
410 goto dummymessage;
411 }
412 winMsg->hwnd = hwnd;
413 }
414 }
415
416 //if a window is disabled, its parent receives the mouse messages
417 if(!IsWindowEnabled(win32wnd->getWindowHandle())) {
418 if(win32wnd->getParent()) {
419 Win32BaseWindow *parent = win32wnd->getParent();;
420 if(parent) parent->addRef();
421 RELEASE_WNDOBJ(win32wnd);
422 win32wnd = parent;
423 }
424 fWasDisabled = TRUE;
425 }
426
427 if(IsNCMouseMsg(win32wnd)) {
428 winMsg->message = WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
429 winMsg->wParam = win32wnd->getLastHitTestVal();
430 winMsg->lParam = MAKELONG(winMsg->pt.x, winMsg->pt.y); //screen coordinates
431 }
432 else {
433 ClientPoint.x = winMsg->pt.x;
434 ClientPoint.y = winMsg->pt.y;
435 MapWindowPoints(0, win32wnd->getWindowHandle(), (LPPOINT)&ClientPoint, 1);
436 winMsg->message = WINWM_LBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
437 winMsg->wParam = GetMouseKeyState();
438 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
439 }
440 EnableLogging();
441
442 if(fWasDisabled) {
443 if(win32wnd) {
444 winMsg->hwnd = win32wnd->getWindowHandle();
445 }
446 else goto dummymessage; //don't send mouse messages to disabled windows
447 }
448
449 DisableLogging();
450 if ((winMsg->message == WINWM_LBUTTONDOWN) ||
451 (winMsg->message == WINWM_RBUTTONDOWN) ||
452 (winMsg->message == WINWM_MBUTTONDOWN) ||
453 (winMsg->message == WINWM_NCLBUTTONDOWN) ||
454 (winMsg->message == WINWM_NCRBUTTONDOWN) ||
455 (winMsg->message == WINWM_NCMBUTTONDOWN))
456 {
457 if(fGenerateDoubleClick && doubleClickMsg.message == winMsg->message &&
458 winMsg->time - doubleClickMsg.time < GetDoubleClickTime() &&
459 (abs(winMsg->pt.x - doubleClickMsg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK_W)/2) &&
460 (abs(winMsg->pt.y - doubleClickMsg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK_W)/2))
461 {
462 dprintf(("single -> double click"));
463 if(winMsg->message >= WINWM_LBUTTONDOWN) {
464 winMsg->message += (WINWM_LBUTTONDBLCLK - WINWM_LBUTTONDOWN);
465 }
466 else winMsg->message += (WINWM_LBUTTONDBLCLK - WINWM_NCLBUTTONDOWN);
467 if(fMsgRemoved) doubleClickMsg.message = 0;
468 }
469 else {
470 dprintf(("save for double click"));
471 if(fMsgRemoved) {
472 doubleClickMsg = *winMsg;
473 if(doubleClickMsg.message >= WINWM_NCLBUTTONDOWN && doubleClickMsg.message <= WINWM_NCMBUTTONDOWN) {
474 doubleClickMsg.message += (WINWM_LBUTTONDOWN - WINWM_NCLBUTTONDOWN);
475 }
476 }
477 }
478 }
479 EnableLogging();
480
481 if(fMsgRemoved == MSG_REMOVE)
482 {
483 MSLLHOOKSTRUCT hook;
484 MOUSEHOOKSTRUCT mousehk;
485 ULONG msg;
486
487 if(winMsg->message >= WINWM_NCLBUTTONDOWN && winMsg->message <= WINWM_NCMBUTTONDBLCLK) {
488 msg = winMsg->message - WINWM_NCLBUTTONDOWN + WINWM_LBUTTONDOWN;
489 }
490 else msg = winMsg->message;
491
492 if(msg == WINWM_LBUTTONDBLCLK) {
493 msg = WINWM_LBUTTONDOWN;
494 }
495 else
496 if(msg == WINWM_RBUTTONDBLCLK) {
497 msg = WINWM_RBUTTONDOWN;
498 }
499 else
500 if(msg == WINWM_MBUTTONDBLCLK) {
501 msg = WINWM_MBUTTONDOWN;
502 }
503
504 // First the low-level mouse hook
505 hook.pt.x = os2Msg->ptl.x & 0xFFFF;
506 hook.pt.y = mapScreenY(os2Msg->ptl.y);
507 hook.mouseData = 0; //todo: XBUTTON1/2 (XP feature) or wheel data
508 hook.flags = 0; //todo: injected (LLMHF_INJECTED)
509 hook.time = winMsg->time;
510 hook.dwExtraInfo = 0;
511
512 if(HOOK_CallHooksW( WH_MOUSE_LL, HC_ACTION, msg, (LPARAM)&hook)) {
513 goto dummymessage; //hook swallowed message
514 }
515
516 // Now inform the WH_MOUSE hook
517 mousehk.pt = hook.pt;
518 mousehk.hwnd = winMsg->hwnd;
519 mousehk.wHitTestCode = win32wnd->getLastHitTestVal();
520 mousehk.dwExtraInfo = 0;
521
522 if(HOOK_CallHooksW( WH_MOUSE_W, HC_ACTION, msg, (LPARAM)&mousehk)) {
523 goto dummymessage; //hook swallowed message
524 }
525 }
526 break;
527 }
528
529 case WM_BUTTON2CLICK:
530 case WM_BUTTON1CLICK:
531 case WM_BUTTON3CLICK:
532 goto dummymessage;
533
534 case WM_BUTTON2MOTIONSTART:
535 case WM_BUTTON2MOTIONEND:
536 case WM_BUTTON1MOTIONSTART:
537 case WM_BUTTON1MOTIONEND:
538 case WM_BUTTON3MOTIONSTART:
539 case WM_BUTTON3MOTIONEND:
540 //no break; translate to WM_MOUSEMOVE
541 //Some applications (e.g. Unreal) retrieve all mouse messages
542 //when a mouse button is pressed and don't expect WM_NULL
543
544 case WM_MOUSEMOVE:
545 {
546 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
547
548 HWND hwnd;
549
550 dprintf2(("WM_MOUSEMOVE (%d,%d)", winMsg->pt.x, winMsg->pt.y));
551 DisableLogging();
552 if(GetCapture() != winMsg->hwnd)
553 {
554 hwnd = WindowFromPoint(winMsg->pt);
555 if(win32wnd->getWindowHandle() != hwnd) {
556 RELEASE_WNDOBJ(win32wnd);
557 win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
558 if(win32wnd == NULL) {
559 DebugInt3();
560 EnableLogging();
561 goto dummymessage;
562 }
563 winMsg->hwnd = hwnd;
564 }
565 }
566
567 //if a window is disabled, its parent receives the mouse messages
568 if(!IsWindowEnabled(win32wnd->getWindowHandle())) {
569 if(win32wnd->getParent()) {
570 Win32BaseWindow *parent = win32wnd->getParent();;
571 if(parent) parent->addRef();
572 RELEASE_WNDOBJ(win32wnd);
573 win32wnd = parent;
574 }
575 fWasDisabled = TRUE;
576 }
577 if(IsNCMouseMsg(win32wnd))
578 {
579 winMsg->message = WINWM_NCMOUSEMOVE;
580 winMsg->wParam = (WPARAM)win32wnd->getLastHitTestVal();
581 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
582 }
583 else
584 {
585 ClientPoint.x = winMsg->pt.x;
586 ClientPoint.y = winMsg->pt.y;
587 MapWindowPoints(0, win32wnd->getWindowHandle(), (LPPOINT)&ClientPoint, 1);
588
589 winMsg->message = WINWM_MOUSEMOVE;
590 winMsg->wParam = GetMouseKeyState();
591 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
592 }
593 EnableLogging();
594 if(fWasDisabled) {
595 if(win32wnd) {
596 winMsg->hwnd = win32wnd->getWindowHandle();
597 }
598 else {
599 goto dummymessage; //don't send mouse messages to disabled windows
600 }
601 }
602 if(fMsgRemoved == MSG_REMOVE)
603 {
604 MSLLHOOKSTRUCT hook;
605
606 hook.pt.x = os2Msg->ptl.x & 0xFFFF;
607 hook.pt.y = mapScreenY(os2Msg->ptl.y);
608 hook.mouseData = 0;
609 hook.flags = 0; //todo: injected (LLMHF_INJECTED)
610 hook.time = winMsg->time;
611 hook.dwExtraInfo = 0;
612
613 if(HOOK_CallHooksW( WH_MOUSE_LL, HC_ACTION, winMsg->message, (LPARAM)&hook)) {
614 goto dummymessage; //hook swallowed message
615 }
616 }
617 break;
618 }
619
620 case WM_CONTROL:
621 goto dummymessage;
622
623 case WM_COMMAND:
624 if(SHORT1FROMMP(os2Msg->mp2) == CMDSRC_MENU) {
625 winMsg->message = WINWM_COMMAND;
626 winMsg->wParam = (WPARAM)SHORT1FROMMP(os2Msg->mp1); //id
627 break;
628 }
629 //todo controls
630 goto dummymessage;
631
632 case WM_SYSCOMMAND:
633 {
634 ULONG x = 0, y = 0;
635 ULONG win32sc;
636
637 if(SHORT2FROMMP(os2Msg->mp2) == TRUE) {//syscommand caused by mouse action
638 POINTL pointl;
639 WinQueryPointerPos(HWND_DESKTOP, &pointl);
640 x = pointl.x;
641 y = mapScreenY(y);
642 }
643 switch(SHORT1FROMMP(os2Msg->mp1)) {
644 case SC_MOVE:
645 win32sc = SC_MOVE_W;
646 break;
647 case SC_CLOSE:
648 {
649 //FALSE -> keyboard operation = user pressed Alt-F4 -> close app
650 //TRUE -> user clicked on close button -> close window
651 if(SHORT2FROMMP(os2Msg->mp2) == FALSE)
652 {
653 HWND hwnd = win32wnd->GetTopParent();
654 if(win32wnd->getWindowHandle() != hwnd) {
655 RELEASE_WNDOBJ(win32wnd);
656 win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
657 if(win32wnd == NULL) {
658 DebugInt3();
659 goto dummymessage;
660 }
661 winMsg->hwnd = hwnd;
662 }
663 }
664 win32sc = SC_CLOSE_W;
665 break;
666 }
667 case SC_MAXIMIZE:
668 win32sc = SC_MAXIMIZE_W;
669 break;
670 case SC_MINIMIZE:
671 win32sc = SC_MINIMIZE_W;
672 break;
673 case SC_NEXTFRAME:
674 case SC_NEXTWINDOW:
675 win32sc = SC_NEXTWINDOW_W;
676 break;
677 case SC_RESTORE:
678 win32sc = SC_RESTORE_W;
679 break;
680 case SC_TASKMANAGER:
681 win32sc = SC_TASKLIST_W;
682 break;
683 case SC_SYSMENU:
684 win32sc = SC_KEYMENU_W; //??
685 break;
686 default:
687 dprintf(("Unknown/unsupported SC command %d", SHORT1FROMMP(os2Msg->mp1)));
688 goto dummymessage;
689 }
690 winMsg->message= WINWM_SYSCOMMAND;
691 winMsg->wParam = (WPARAM)win32sc;
692 winMsg->lParam = MAKELONG((USHORT)x, (USHORT)y);
693 break;
694 }
695
696 case WM_CHAR_SPECIAL_ALTGRCONTROL:
697 {
698 // special char message from the keyboard hook
699 dprintf(("PM: WM_CHAR_SPECIAL_ALTGRCONTROL"));
700 // NO BREAK! FALLTHRU CASE!
701 }
702
703 case WM_CHAR_SPECIAL:
704 {
705 // @@@PH
706 // special char message from the keyboard hook
707 if(os2Msg->msg == WM_CHAR_SPECIAL) {
708 dprintf(("PM: WM_CHAR_SPECIAL"));
709 }
710 // NO BREAK! FALLTHRU CASE!
711 }
712
713 case WM_CHAR:
714 {
715 ULONG repeatCount=0;
716 ULONG virtualKey=0;
717 ULONG keyFlags=0;
718 USHORT scanCode=0;
719 ULONG flags = SHORT1FROMMP(os2Msg->mp1);
720 BOOL keyWasPressed;
721 BOOL numPressed = (BOOL)(WinGetKeyState(HWND_DESKTOP,VK_NUMLOCK) & 1);
722 char c;
723 USHORT usPMScanCode = CHAR4FROMMP(os2Msg->mp1);
724
725 teb->o.odin.fTranslated = FALSE;
726 repeatCount = CHAR3FROMMP(os2Msg->mp1);
727 scanCode = CHAR4FROMMP(os2Msg->mp1);
728 keyWasPressed = ((SHORT1FROMMP (os2Msg->mp1) & KC_PREVDOWN) == KC_PREVDOWN);
729
730 dprintf(("PM: WM_CHAR: %x %x rep=%d scancode=%x num=%d", SHORT1FROMMP(os2Msg->mp2), SHORT2FROMMP(os2Msg->mp2), repeatCount, scanCode, numPressed));
731 dprintf(("PM: WM_CHAR: hwnd %x flags %x mp1 %x, mp2 %x, time=%08xh", win32wnd->getWindowHandle(), flags, os2Msg->mp1, os2Msg->mp2, os2Msg->time));
732
733 BOOL fWinExtended;
734 BYTE bWinVKey;
735 WORD wWinScan;
736
737 if ( (!IsDBCSEnv() && scanCode == 0) ||
738 (scanCode==0 ) && !( flags & KC_CHAR ) )
739 {
740 goto dummymessage;
741 }
742
743 if( scanCode != 0 )
744 {
745 KeyTranslatePMScanToWinVKey(usPMScanCode,
746 FALSE,
747 &bWinVKey,
748 &wWinScan,
749 &fWinExtended);
750 winMsg->wParam = bWinVKey;
751 }
752 else
753 {
754 dprintf(("PM: WM_CHAR: DBCS processing "));
755
756 winMsg->wParam = CHAR1FROMMP( os2Msg->mp2 );
757
758 wWinScan = 0;
759 fWinExtended = 0;
760
761 if( CHAR2FROMMP( os2Msg->mp2 )) // DBCS character
762 {
763 CHAR dbcsCh[ 2 ] = { CHAR1FROMMP( os2Msg->mp2 ), CHAR2FROMMP( os2Msg->mp2 )};
764
765 if( isUnicode )
766 {
767 WCHAR uniChar;
768
769 MultiByteToWideChar( CP_ACP, 0, dbcsCh, 2, &uniChar, 1 );
770 winMsg->wParam = ( WPARAM )uniChar;
771 }
772 else
773 winMsg->wParam = ( dbcsCh[ 0 ] << 8 ) | dbcsCh[ 1 ];
774 }
775 }
776 winMsg->lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
777 winMsg->lParam |= (wWinScan & 0x1FF) << 16; // bit 16-23, scancode + bit 15 extended
778
779 // Set the extended bit when appropriate
780 if (fWinExtended)
781 winMsg->lParam = winMsg->lParam | WIN_KEY_EXTENDED;
782
783 //PF When we press shift we enable non-numeric functions of Numpad
784 if ((!numPressed || (flags & KC_SHIFT)) && (scanCode >= PMSCAN_PAD7) && (scanCode <= PMSCAN_PADPERIOD))
785 winMsg->wParam = ConvertNumPadKey(scanCode);
786
787 //@PF This looks ugly but this is just what we have in win32 both in win98/win2k
788 //what happens is that lParam is tweaked in win32 to contain some illegal codes
789 //I simply reproduce here all situation. Absolute values can be kept because
790 //Break scancode can be acheived only by pressing Ctrl-Break combination
791 if ((usPMScanCode == PMSCAN_BREAK) && !(flags & KC_KEYUP) && (flags & KC_CTRL)
792 && (fMsgRemoved && !(teb->o.odin.fTranslated)))
793 {
794 MSG extramsg;
795 memcpy(&extramsg, winMsg, sizeof(MSG));
796 // adjust our WM_CHAR code
797 extramsg.lParam = 0x01460001;
798
799 //After SetFocus(0), all keystrokes are converted in WM_SYS*
800 extramsg.message = (fIgnoreKeystrokes) ? WINWM_SYSCHAR : WINWM_CHAR;
801
802 setThreadQueueExtraCharMessage(teb, &extramsg);
803 // and finally adjust our WM_KEYDOWN code
804 winMsg->lParam = 0x01460001;
805 }
806
807 if (!(flags & KC_ALT))
808 {
809 //
810 // the Alt key is not pressed
811 // or no more pressed
812 //
813 if (flags & KC_KEYUP)
814 {
815 // check for a lonesome ALT key ...
816 // SvL: Only Left Alt; AltGr generates a WM_KEYUP when released
817 if ( (flags & KC_LONEKEY) &&
818 (winMsg->wParam == VK_LMENU_W) )
819 {
820 winMsg->message = WINWM_SYSKEYUP;
821 // held ALT-key when current key is released
822 // generates additional flag 0x2000000
823 // Note: PM seems to do this differently,
824 // KC_ALT is already reset
825 }
826 else
827 {
828 // send WM_KEYUP message
829 winMsg->message = WINWM_KEYUP;
830 }
831 winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, always 1 for a WM_KEYUP message
832 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
833 }
834 else if( scanCode == 0 )
835 {
836 if( CHAR2FROMMP( os2Msg->mp2 ))
837 winMsg->message = WINWM_IME_CHAR;
838 else
839 {
840 //After SetFocus(0), all keystrokes are converted in WM_SYS*
841 winMsg->message = (fIgnoreKeystrokes) ? WINWM_SYSCHAR : WINWM_CHAR;
842 }
843 }
844 else
845 { // send WM_KEYDOWN message
846 winMsg->message = WINWM_KEYDOWN;
847
848 if (keyWasPressed)
849 winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, 1 means key was pressed
850
851 //Shift-Enter and possibly others need to have special handling
852 if (flags & KC_SHIFT)
853 {
854 if(fMsgRemoved && !(teb->o.odin.fTranslated))
855 {
856 dprintf(("PM: KC_SHIFT: %x",winMsg->wParam));
857 if (winMsg->wParam == VK_RETURN_W)
858 {
859 MSG extramsg;
860 memcpy(&extramsg, winMsg, sizeof(MSG));
861
862 //After SetFocus(0), all keystrokes are converted in WM_SYS*
863 extramsg.message = (fIgnoreKeystrokes) ? WINWM_SYSCHAR : WINWM_CHAR;
864
865 // insert message into the queue
866 setThreadQueueExtraCharMessage(teb, &extramsg);
867 winMsg->lParam &= 0x3FFFFFFF;
868 }
869 } // else ???
870 } // KC_SHIFT
871 else
872 {
873 // in case we handle Enter directly through PMKBDHOOK
874 if ((os2Msg->msg == WM_CHAR_SPECIAL) && (winMsg->wParam == VK_RETURN_W)
875 && (fMsgRemoved && !(teb->o.odin.fTranslated)))
876 {
877 MSG extramsg;
878 memcpy(&extramsg, winMsg, sizeof(MSG));
879
880 //After SetFocus(0), all keystrokes are converted in WM_SYS*
881 extramsg.message = (fIgnoreKeystrokes) ? WINWM_SYSCHAR : WINWM_CHAR;
882
883 // insert message into the queue
884 setThreadQueueExtraCharMessage(teb, &extramsg);
885 }
886 }
887 }
888 // if right alt is down, then we need to set the alt down bit too
889 // except for the fake Ctrl WM_CHAR sent for AltGr emulation
890 if (os2Msg->msg != WM_CHAR_SPECIAL_ALTGRCONTROL &&
891 (WinGetKeyState(HWND_DESKTOP, VK_ALTGRAF) & 0x8000))
892 {
893 winMsg->lParam |= WIN_KEY_ALTHELD;
894 }
895 }
896 else
897 {
898 //
899 // the Alt key is pressed
900 //
901 if (flags & KC_KEYUP)
902 {
903 //@@PF Note that without pmkbdhook there will not be correct message for Alt-Enter
904 winMsg->message = WINWM_SYSKEYUP;
905 winMsg->lParam |= WIN_KEY_PREVSTATE;
906 // No ALTHELD for Alt itself ;)
907 winMsg->lParam |= WIN_KEY_ALTHELD;
908 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
909 }
910 else
911 {
912 // send WM_SYSKEYDOWN message
913 winMsg->message = WINWM_SYSKEYDOWN;
914 if (keyWasPressed)
915 winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, 1 means key was pressed
916
917 // pressed ALT-key generates additional flag 0x2000000
918 // if the current window has keyboard focus
919 winMsg->lParam |= WIN_KEY_ALTHELD;
920 }
921 }
922
923 //After SetFocus(0), all keystrokes are converted in WM_SYS*
924 if(fIgnoreKeystrokes) {
925 if(winMsg->message == WINWM_KEYDOWN) {
926 winMsg->message = WINWM_SYSKEYDOWN;
927 }
928 else
929 if(winMsg->message == WINWM_KEYUP) {
930 winMsg->message = WINWM_SYSKEYUP;
931 }
932 }
933 break;
934 }
935
936 case WM_TIMER:
937//Why was this check here????
938// if (os2Msg->mp2)
939// {
940 BOOL sys;
941 ULONG id, proc;
942
943 if (TIMER_GetTimerInfo(os2Msg->hwnd,(ULONG)os2Msg->mp1,&sys,&id, &proc))
944 {
945 winMsg->wParam = (WPARAM)id;
946 winMsg->lParam = (LPARAM)proc;
947 winMsg->message= (sys) ? WINWM_SYSTIMER : WINWM_TIMER;
948 break;
949 }
950// }
951 goto dummymessage; //for caret blinking
952
953 case WM_SETWINDOWPARAMS:
954 {
955 WNDPARAMS *wndParams = (WNDPARAMS *)os2Msg->mp1;
956
957 if(wndParams->fsStatus & WPM_TEXT) {
958 winMsg->message = WINWM_SETTEXT;
959 winMsg->lParam = (LPARAM)wndParams->pszText;
960 break;
961 }
962 goto dummymessage;
963 }
964
965#if 0
966 case WM_QUERYWINDOWPARAMS:
967 {
968 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
969 ULONG textlen;
970 PSZ wintext;
971
972 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
973 {
974 if(wndpars->fsStatus & WPM_CCHTEXT)
975 wndpars->cchText = win32wnd->MsgGetTextLength();
976 if(wndpars->fsStatus & WPM_TEXT)
977 wndpars->pszText = win32wnd->MsgGetText();
978
979 wndpars->fsStatus = 0;
980 wndpars->cbCtlData = 0;
981 wndpars->cbPresParams = 0;
982 goto dummymessage;
983 }
984 }
985#endif
986
987 case WM_PAINT:
988 {
989 if(win32wnd->IsWindowIconic()) {
990 winMsg->message = WINWM_PAINTICON;
991 }
992 else winMsg->message = WINWM_PAINT;
993 break;
994 }
995
996 case WM_CONTEXTMENU:
997 winMsg->message = WINWM_CONTEXTMENU;
998 winMsg->wParam = win32wnd->getWindowHandle();
999 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
1000 break;
1001
1002 case WM_RENDERFMT:
1003 winMsg->message = WINWM_RENDERFORMAT;
1004 winMsg->wParam = (UINT) os2Msg->mp1;
1005 break;
1006
1007 case WM_RENDERALLFMTS:
1008 winMsg->message = WINWM_RENDERALLFORMATS;
1009 break;
1010
1011 case WM_DESTROYCLIPBOARD:
1012 winMsg->message = WINWM_DESTROYCLIPBOARD;
1013 break;
1014
1015 case WM_DRAWCLIPBOARD:
1016 winMsg->message = WINWM_DRAWCLIPBOARD;
1017 break;
1018
1019 case WM_HSCROLL:
1020 case WM_VSCROLL:
1021 //PF For win32 we support only vertical scrolling for WM_MOUSEWHEEL
1022 if (os2Msg->msg == WM_VSCROLL)
1023 {
1024 POINT CursorPoint;
1025 winMsg->message = WINWM_MOUSEWHEEL;
1026 if (OSLibWinQueryPointerPos(&CursorPoint))
1027 mapScreenPoint((OSLIBPOINT*)&CursorPoint);
1028
1029 if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEDOWN)
1030 winMsg->wParam = MAKELONG(GetMouseKeyState(), -WHEEL_DELTA/OS2_WHEEL_CORRECTION);
1031 else
1032 if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEUP)
1033 winMsg->wParam = MAKELONG(GetMouseKeyState(), WHEEL_DELTA/OS2_WHEEL_CORRECTION);
1034 else
1035 winMsg->wParam = MAKELONG(GetMouseKeyState(), 0);
1036
1037 winMsg->lParam = MAKELONG(CursorPoint.x, CursorPoint.y);
1038
1039 dprintf(("WM_MOUSEWHEEL message delta %d at (%d,%d)",HIWORD(winMsg->wParam),CursorPoint.x, CursorPoint.y));
1040 if (fMsgRemoved == MSG_REMOVE)
1041 {
1042 MSLLHOOKSTRUCT hook;
1043
1044 hook.pt.x = os2Msg->ptl.x & 0xFFFF;
1045 hook.pt.y = mapScreenY(os2Msg->ptl.y);
1046 if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEDOWN)
1047 hook.mouseData = MAKELONG(GetMouseKeyState(), -WHEEL_DELTA/OS2_WHEEL_CORRECTION);
1048 else
1049 if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEUP)
1050 hook.mouseData = MAKELONG(GetMouseKeyState(), WHEEL_DELTA/OS2_WHEEL_CORRECTION);
1051 else goto dummymessage; // IBM driver produces other messages as well sometimes
1052
1053 hook.flags = LLMHF_INJECTED;
1054 hook.time = winMsg->time;
1055 hook.dwExtraInfo = 0;
1056 if(HOOK_CallHooksW( WH_MOUSE_LL, HC_ACTION, WINWM_MOUSEWHEEL, (LPARAM)&hook))
1057 goto dummymessage; //hook swallowed message
1058 }
1059 break;
1060 }
1061 goto dummymessage; //eat this message
1062 break;
1063
1064 case WM_INITMENU:
1065 case WM_MENUSELECT:
1066 case WM_MENUEND:
1067 case WM_NEXTMENU:
1068 case WM_SYSCOLORCHANGE:
1069 case WM_SYSVALUECHANGED:
1070 case WM_SETSELECTION:
1071 case WM_PPAINT:
1072 case WM_PSETFOCUS:
1073 case WM_PSYSCOLORCHANGE:
1074 case WM_PSIZE:
1075 case WM_PACTIVATE:
1076 case WM_PCONTROL:
1077 case WM_HELP:
1078 case WM_APPTERMINATENOTIFY:
1079 case WM_PRESPARAMCHANGED:
1080 case WM_DRAWITEM:
1081 case WM_MEASUREITEM:
1082 case WM_CONTROLPOINTER:
1083 case WM_QUERYDLGCODE:
1084 case WM_SUBSTITUTESTRING:
1085 case WM_MATCHMNEMONIC:
1086 case WM_SAVEAPPLICATION:
1087 case WM_SEMANTICEVENT:
1088 default:
1089dummymessage:
1090 dprintf2(("dummy message %x %x %x %x", os2Msg->hwnd, os2Msg->msg, os2Msg->mp1, os2Msg->mp2));
1091 winMsg->message = 0;
1092 winMsg->wParam = 0;
1093 winMsg->lParam = 0;
1094 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1095 return FALSE;
1096 }
1097msgdone:
1098 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1099 return TRUE;
1100}
1101//******************************************************************************
1102//******************************************************************************
1103BOOL OSLibWinTranslateMessage(MSG *msg)
1104{
1105 TEB *teb;
1106 MSG extramsg;
1107 BOOL numPressed = (BOOL)(WinGetKeyState(HWND_DESKTOP,VK_NUMLOCK) & 1);
1108 teb = GetThreadTEB();
1109 if(!teb)
1110 return FALSE;
1111
1112 UCHAR ucPMScanCode = CHAR4FROMMP(teb->o.odin.os2msg.mp1);
1113 ULONG fl = SHORT1FROMMP(teb->o.odin.os2msg.mp1);
1114
1115
1116 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
1117 // the newly generated WM_CHAR message.
1118 if(!teb->o.odin.fTranslated &&
1119 teb->o.odin.os2msg.msg == WM_CHAR &&
1120 !((SHORT1FROMMP(teb->o.odin.os2msg.mp1) & KC_KEYUP) == KC_KEYUP))
1121 {
1122 //TranslatedMessage was called before DispatchMessage, so queue WM_CHAR message
1123 memcpy(&extramsg, msg, sizeof(MSG));
1124 extramsg.wParam = SHORT1FROMMP(teb->o.odin.os2msg.mp2);
1125 extramsg.lParam = 0;
1126
1127 // ESCAPE generates a WM_CHAR under windows, so take
1128 // special care for this here.
1129 switch (ucPMScanCode)
1130 {
1131 case PMSCAN_ESC:
1132 extramsg.wParam = VK_ESCAPE_W;
1133 fl |= KC_CHAR;
1134 break;
1135 }
1136
1137 // PF With NumLock off do not generate any WM_CHAR messages at all
1138 // PADMINUS,PADPLUS fall in range of PAD7..PADPERIOD but they should generate WM_CHAR
1139 // other PAD(X) buttons miss that range at all and thus generate WM_CHAR
1140 if (!numPressed && (ucPMScanCode != PMSCAN_PADMINUS) && (ucPMScanCode != PMSCAN_PADPLUS) &&
1141 (ucPMScanCode >= PMSCAN_PAD7) && (ucPMScanCode <= PMSCAN_PADPERIOD))
1142 return FALSE;
1143
1144 if(!(fl & KC_CHAR) && msg->message < WINWM_SYSKEYDOWN)
1145 {
1146 return FALSE;
1147 }
1148
1149 //the KC_COMPOSITE flag might be set; in that case this key will
1150 //be combined with the previous dead key, so we must use the scancode
1151 //(e.g. ^ on german keyboards)
1152 if((fl & (KC_VIRTUALKEY|KC_COMPOSITE)) == KC_VIRTUALKEY)
1153 {
1154 if(msg->wParam)
1155 {
1156 if ((msg->wParam >= VK_NUMPAD0_W) &&
1157 (msg->wParam <= VK_NUMPAD9_W))
1158 extramsg.wParam = msg->wParam - 0x30;
1159 else
1160 if (msg->wParam == VK_DECIMAL_W)
1161 extramsg.wParam = VK_DELETE_W;
1162 else
1163 /* PM Sends Bogus Things when pressing Shift+NUMAsterisk */
1164 if (msg->wParam != VK_MULTIPLY_W)
1165 extramsg.wParam = msg->wParam;
1166 }
1167 else
1168 extramsg.wParam = SHORT2FROMMP(teb->o.odin.os2msg.mp2);
1169 }
1170
1171
1172 //After SetFocus(0), all keystrokes are converted in WM_SYS*
1173 if(msg->message >= WINWM_SYSKEYDOWN || fIgnoreKeystrokes)
1174 extramsg.message = WINWM_SYSCHAR;
1175 else
1176 extramsg.message = WINWM_CHAR;
1177
1178 if(fl & KC_DEADKEY)
1179 extramsg.message++; //WM_DEADCHAR/WM_SYSDEADCHAR
1180
1181
1182 extramsg.lParam = msg->lParam & 0x00FFFFFF;
1183 if ((fl & KC_ALT) || (msg->lParam & WIN_KEY_ALTHELD))
1184 extramsg.lParam |= WIN_KEY_ALTHELD;
1185 if(fl & KC_PREVDOWN)
1186 extramsg.lParam |= WIN_KEY_PREVSTATE;
1187 if(fl & KC_KEYUP)
1188 extramsg.lParam |= (1<<31);
1189
1190 // insert message into the queue
1191 setThreadQueueExtraCharMessage(teb, &extramsg);
1192
1193 return TRUE;
1194 }
1195 return FALSE;
1196}
1197//******************************************************************************
1198//******************************************************************************
1199
1200/**
1201 * Checks if the message is one that should be forwarded.
1202 *
1203 * @returns True if the message should be forwarded.
1204 * @returns False if the message doesn't fall in to that group.
1205 * @param pMsg Message to examin.
1206 * @remark Are there more messages???
1207 */
1208BOOL OSLibForwardableMessage(const MSG *pMsg)
1209{
1210 return ( (pMsg->message >= WINWM_KEYFIRST && pMsg->message <= WINWM_KEYLAST)
1211 || (pMsg->message >= WINWM_MOUSEFIRST && pMsg->message <= WINWM_MOUSELAST) );
1212}
1213
1214/**
1215 * Forwards this message to the attached thread if it's in the group of messages
1216 * which is supposed to be forwarded.
1217 *
1218 * @returns True if forwarded.
1219 * @returns False if not forwarded.
1220 * @param pTeb Pointer to the TEB of the current thread.
1221 * @param pMsg Message to forward.
1222 * @author knut st. osmundsen <bird-srcspam@anduin.net>
1223 */
1224BOOL OSLibForwardMessageToAttachedThread(void *pvTeb, MSG *pMsg, void *hmm)
1225{
1226 TEB *pTeb = (TEB *)pvTeb;
1227 dprintf(("OSLibForwardMessageToAttachedThread: %p %p (msg=%x)\n", pvTeb, pMsg, pMsg->message));
1228 if (!OSLibForwardableMessage(pMsg))
1229 return FALSE;
1230
1231 /*
1232 * Find the actual receiver thread.
1233 */
1234 int c = 100;
1235 TEB *pTebTo = pTeb;
1236 do
1237 {
1238 pTebTo = GetTEBFromThreadId(pTebTo->o.odin.tidAttachedInputThread);
1239 } while (c-- > 0 && !pTebTo && pTebTo->o.odin.tidAttachedInputThread);
1240 if (!c || !pTebTo)
1241 {
1242 if (c) dprintf(("OSLibForwardMessageToAttachedThread: The receiver thread is dead or non existing.\n"));
1243 else dprintf(("OSLibForwardMessageToAttachedThread: threads are attached in looooop.\n"));
1244 return FALSE; /* hmm.... */
1245 }
1246 dprintf(("OSLibForwardMessageToAttachedThread: Forwarding message %#x to %#x\n",
1247 pMsg->message, pTeb->o.odin.tidAttachedInputThread));
1248
1249 /*
1250 * Pack down the message into shared memory.
1251 */
1252 MSG *pMsgCopy = (MSG *)_smalloc(sizeof(MSG));
1253 if (!pMsgCopy)
1254 return FALSE;
1255 *pMsgCopy = *pMsg;
1256
1257 /*
1258 * Figure out how we should send the message.
1259 */
1260 if (WinInSendMsg(pTebTo->o.odin.hab))
1261 {
1262#if 0
1263 /*
1264 * Hmm what do we do here....
1265 */
1266 MRESULT rc = WinSendQueueMsg(pTebTo->o.odin.hmq, /*special! */, pMsgCopy, /*magic*/ );
1267 /* if (hmmSendMsgResult)
1268 *hmmSendMsgResult = (???)rc; */
1269#else
1270 dprintf(("OSLibForwardMessage: ERROR! %x in sendmsg!!!\n", pMsg->message));
1271 DebugInt3();
1272
1273 _sfree(pMsgCopy);
1274 return FALSE;
1275#endif
1276 }
1277 else
1278 {
1279 if (!WinPostQueueMsg(pTebTo->o.odin.hmq, WIN32APP_FORWARDEDPOSTMSG, pMsgCopy, (MPARAM)WIN32APP_FORWARDEDPOSTMSG_MAGIC))
1280 {
1281 dprintf(("OSLibForwardMessage: Failed to post queue message to hmq=%#x\n", pTebTo->o.odin.hmq));
1282 _sfree(pMsgCopy);
1283 }
1284 }
1285
1286 return TRUE;
1287}
Note: See TracBrowser for help on using the repository browser.