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

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

OSLibWinTranslateMessage: removed some strange numpad related hacks that caused problems for VK_DECIMAL processing

File size: 43.9 KB
Line 
1/* $Id: oslibmsgtranslate.cpp,v 1.122 2004-03-23 16:50:08 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 ULONG msg;
485
486 if(winMsg->message >= WINWM_NCLBUTTONDOWN && winMsg->message <= WINWM_NCMBUTTONDBLCLK) {
487 msg = winMsg->message - WINWM_NCLBUTTONDOWN + WINWM_LBUTTONDOWN;
488 }
489 else msg = winMsg->message;
490
491 if(msg == WINWM_LBUTTONDBLCLK) {
492 msg = WINWM_LBUTTONDOWN;
493 }
494 else
495 if(msg == WINWM_RBUTTONDBLCLK) {
496 msg = WINWM_RBUTTONDOWN;
497 }
498 else
499 if(msg == WINWM_MBUTTONDBLCLK) {
500 msg = WINWM_MBUTTONDOWN;
501 }
502
503 // First the low-level mouse hook
504 hook.pt = winMsg->pt;
505 hook.mouseData = 0; //todo: XBUTTON1/2 (XP feature) or wheel data
506 hook.flags = 0; //todo: injected (LLMHF_INJECTED)
507 hook.time = winMsg->time;
508 hook.dwExtraInfo = 0;
509
510 if(HOOK_CallHooksW( WH_MOUSE_LL, HC_ACTION, msg, (LPARAM)&hook)) {
511 goto dummymessage; //hook swallowed message
512 }
513 }
514 MOUSEHOOKSTRUCT mousehk;
515
516 // Now inform the WH_MOUSE hook
517 mousehk.pt = winMsg->pt;
518 mousehk.hwnd = winMsg->hwnd;
519 mousehk.wHitTestCode = win32wnd->getLastHitTestVal();
520 mousehk.dwExtraInfo = 0;
521
522 if(HOOK_CallHooksW( WH_MOUSE_W, (fMsgRemoved == MSG_REMOVE) ? HC_ACTION : HC_NOREMOVE, winMsg->message, (LPARAM)&mousehk)) {
523 //TODO: WH_CBT HCBT_CLICKSKIPPED
524 goto dummymessage; //hook swallowed message
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 MSLLHOOKSTRUCT hook;
603 if(fMsgRemoved == MSG_REMOVE)
604 {
605 hook.pt = winMsg->pt;
606 hook.mouseData = 0;
607 hook.flags = 0; //todo: injected (LLMHF_INJECTED)
608 hook.time = winMsg->time;
609 hook.dwExtraInfo = 0;
610
611 if(HOOK_CallHooksW( WH_MOUSE_LL, HC_ACTION, winMsg->message, (LPARAM)&hook)) {
612 goto dummymessage; //hook swallowed message
613 }
614 }
615 MOUSEHOOKSTRUCT mousehk;
616
617 // Now inform the WH_MOUSE hook
618 mousehk.pt = winMsg->pt;
619 mousehk.hwnd = winMsg->hwnd;
620 mousehk.wHitTestCode = win32wnd->getLastHitTestVal();
621 mousehk.dwExtraInfo = 0;
622
623 if(HOOK_CallHooksW( WH_MOUSE_W, (fMsgRemoved == MSG_REMOVE) ? HC_ACTION : HC_NOREMOVE, winMsg->message, (LPARAM)&mousehk))
624 {
625 goto dummymessage; //hook swallowed message
626 }
627 break;
628 }
629
630 case WM_CONTROL:
631 goto dummymessage;
632
633 case WM_COMMAND:
634 if(SHORT1FROMMP(os2Msg->mp2) == CMDSRC_MENU) {
635 winMsg->message = WINWM_COMMAND;
636 winMsg->wParam = (WPARAM)SHORT1FROMMP(os2Msg->mp1); //id
637 break;
638 }
639 //todo controls
640 goto dummymessage;
641
642 case WM_SYSCOMMAND:
643 {
644 ULONG x = 0, y = 0;
645 ULONG win32sc;
646
647 if(SHORT2FROMMP(os2Msg->mp2) == TRUE) {//syscommand caused by mouse action
648 POINTL pointl;
649 WinQueryPointerPos(HWND_DESKTOP, &pointl);
650 x = pointl.x;
651 y = mapScreenY(y);
652 }
653 switch(SHORT1FROMMP(os2Msg->mp1)) {
654 case SC_MOVE:
655 win32sc = SC_MOVE_W;
656 break;
657 case SC_CLOSE:
658 {
659 //FALSE -> keyboard operation = user pressed Alt-F4 -> close app
660 //TRUE -> user clicked on close button -> close window
661 if(SHORT2FROMMP(os2Msg->mp2) == FALSE)
662 {
663 HWND hwnd = win32wnd->GetTopParent();
664 if(win32wnd->getWindowHandle() != hwnd) {
665 RELEASE_WNDOBJ(win32wnd);
666 win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
667 if(win32wnd == NULL) {
668 DebugInt3();
669 goto dummymessage;
670 }
671 winMsg->hwnd = hwnd;
672 }
673 }
674 win32sc = SC_CLOSE_W;
675 break;
676 }
677 case SC_MAXIMIZE:
678 win32sc = SC_MAXIMIZE_W;
679 break;
680 case SC_MINIMIZE:
681 win32sc = SC_MINIMIZE_W;
682 break;
683 case SC_NEXTFRAME:
684 case SC_NEXTWINDOW:
685 win32sc = SC_NEXTWINDOW_W;
686 break;
687 case SC_RESTORE:
688 win32sc = SC_RESTORE_W;
689 break;
690 case SC_TASKMANAGER:
691 win32sc = SC_TASKLIST_W;
692 break;
693 case SC_SYSMENU:
694 win32sc = SC_KEYMENU_W; //??
695 break;
696 default:
697 dprintf(("Unknown/unsupported SC command %d", SHORT1FROMMP(os2Msg->mp1)));
698 goto dummymessage;
699 }
700 winMsg->message= WINWM_SYSCOMMAND;
701 winMsg->wParam = (WPARAM)win32sc;
702 winMsg->lParam = MAKELONG((USHORT)x, (USHORT)y);
703 break;
704 }
705
706 case WM_CHAR_SPECIAL_ALTGRCONTROL:
707 {
708 // special char message from the keyboard hook
709 dprintf(("PM: WM_CHAR_SPECIAL_ALTGRCONTROL"));
710 // NO BREAK! FALLTHRU CASE!
711 }
712
713 case WM_CHAR_SPECIAL:
714 {
715 // @@@PH
716 // special char message from the keyboard hook
717 if(os2Msg->msg == WM_CHAR_SPECIAL) {
718 dprintf(("PM: WM_CHAR_SPECIAL"));
719 }
720 // NO BREAK! FALLTHRU CASE!
721 }
722
723 case WM_CHAR:
724 {
725 ULONG repeatCount=0;
726 ULONG virtualKey=0;
727 ULONG keyFlags=0;
728 USHORT scanCode=0;
729 ULONG flags = SHORT1FROMMP(os2Msg->mp1);
730 BOOL keyWasPressed;
731 BOOL numPressed = (BOOL)(WinGetKeyState(HWND_DESKTOP,VK_NUMLOCK) & 1);
732 char c;
733 USHORT usPMScanCode = CHAR4FROMMP(os2Msg->mp1);
734
735 teb->o.odin.fTranslated = FALSE;
736 repeatCount = CHAR3FROMMP(os2Msg->mp1);
737 scanCode = CHAR4FROMMP(os2Msg->mp1);
738 keyWasPressed = ((SHORT1FROMMP (os2Msg->mp1) & KC_PREVDOWN) == KC_PREVDOWN);
739
740 dprintf(("PM: WM_CHAR: %x %x rep=%d scancode=%x num=%d", SHORT1FROMMP(os2Msg->mp2), SHORT2FROMMP(os2Msg->mp2), repeatCount, scanCode, numPressed));
741 dprintf(("PM: WM_CHAR: hwnd %x flags %x mp1 %x, mp2 %x, time=%08xh", win32wnd->getWindowHandle(), flags, os2Msg->mp1, os2Msg->mp2, os2Msg->time));
742
743 BOOL fWinExtended;
744 BYTE bWinVKey;
745 WORD wWinScan;
746
747 if ( (!IsDBCSEnv() && scanCode == 0) ||
748 (scanCode==0 ) && !( flags & KC_CHAR ) )
749 {
750 goto dummymessage;
751 }
752
753 if( scanCode != 0 )
754 {
755 KeyTranslatePMScanToWinVKey(usPMScanCode,
756 FALSE,
757 &bWinVKey,
758 &wWinScan,
759 &fWinExtended);
760 winMsg->wParam = bWinVKey;
761 }
762 else
763 {
764 dprintf(("PM: WM_CHAR: DBCS processing "));
765
766 winMsg->wParam = CHAR1FROMMP( os2Msg->mp2 );
767
768 wWinScan = 0;
769 fWinExtended = 0;
770
771 if( CHAR2FROMMP( os2Msg->mp2 )) // DBCS character
772 {
773 CHAR dbcsCh[ 2 ] = { CHAR1FROMMP( os2Msg->mp2 ), CHAR2FROMMP( os2Msg->mp2 )};
774
775 if( isUnicode )
776 {
777 WCHAR uniChar;
778
779 MultiByteToWideChar( CP_ACP, 0, dbcsCh, 2, &uniChar, 1 );
780 winMsg->wParam = ( WPARAM )uniChar;
781 }
782 else
783 winMsg->wParam = ( dbcsCh[ 0 ] << 8 ) | dbcsCh[ 1 ];
784 }
785 }
786 winMsg->lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
787 winMsg->lParam |= (wWinScan & 0x1FF) << 16; // bit 16-23, scancode + bit 15 extended
788
789 // Set the extended bit when appropriate
790 if (fWinExtended)
791 winMsg->lParam = winMsg->lParam | WIN_KEY_EXTENDED;
792
793 //PF When we press shift we enable non-numeric functions of Numpad
794 if ((!numPressed || (flags & KC_SHIFT)) && (scanCode >= PMSCAN_PAD7) && (scanCode <= PMSCAN_PADPERIOD))
795 winMsg->wParam = ConvertNumPadKey(scanCode);
796
797 //@PF This looks ugly but this is just what we have in win32 both in win98/win2k
798 //what happens is that lParam is tweaked in win32 to contain some illegal codes
799 //I simply reproduce here all situation. Absolute values can be kept because
800 //Break scancode can be acheived only by pressing Ctrl-Break combination
801 if ((usPMScanCode == PMSCAN_BREAK) && !(flags & KC_KEYUP) && (flags & KC_CTRL)
802 && (fMsgRemoved && !(teb->o.odin.fTranslated)))
803 {
804 MSG extramsg;
805 memcpy(&extramsg, winMsg, sizeof(MSG));
806 // adjust our WM_CHAR code
807 extramsg.lParam = 0x01460001;
808
809 //After SetFocus(0), all keystrokes are converted in WM_SYS*
810 extramsg.message = (fIgnoreKeystrokes) ? WINWM_SYSCHAR : WINWM_CHAR;
811
812 setThreadQueueExtraCharMessage(teb, &extramsg);
813 // and finally adjust our WM_KEYDOWN code
814 winMsg->lParam = 0x01460001;
815 }
816
817 if (!(flags & KC_ALT))
818 {
819 //
820 // the Alt key is not pressed
821 // or no more pressed
822 //
823 if (flags & KC_KEYUP)
824 {
825 // check for a lonesome ALT key ...
826 // SvL: Only Left Alt; AltGr generates a WM_KEYUP when released
827 if ( (flags & KC_LONEKEY) &&
828 (winMsg->wParam == VK_LMENU_W) )
829 {
830 winMsg->message = WINWM_SYSKEYUP;
831 // held ALT-key when current key is released
832 // generates additional flag 0x2000000
833 // Note: PM seems to do this differently,
834 // KC_ALT is already reset
835 }
836 else
837 {
838 // send WM_KEYUP message
839 winMsg->message = WINWM_KEYUP;
840 }
841 winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, always 1 for a WM_KEYUP message
842 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
843 }
844 else if( scanCode == 0 )
845 {
846 if( CHAR2FROMMP( os2Msg->mp2 ))
847 winMsg->message = WINWM_IME_CHAR;
848 else
849 {
850 //After SetFocus(0), all keystrokes are converted in WM_SYS*
851 winMsg->message = (fIgnoreKeystrokes) ? WINWM_SYSCHAR : WINWM_CHAR;
852 }
853 }
854 else
855 { // send WM_KEYDOWN message
856 winMsg->message = WINWM_KEYDOWN;
857
858 if (keyWasPressed)
859 winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, 1 means key was pressed
860
861 //Shift-Enter and possibly others need to have special handling
862 if (flags & KC_SHIFT)
863 {
864 if(fMsgRemoved && !(teb->o.odin.fTranslated))
865 {
866 dprintf(("PM: KC_SHIFT: %x",winMsg->wParam));
867 if (winMsg->wParam == VK_RETURN_W)
868 {
869 MSG extramsg;
870 memcpy(&extramsg, winMsg, sizeof(MSG));
871
872 //After SetFocus(0), all keystrokes are converted in WM_SYS*
873 extramsg.message = (fIgnoreKeystrokes) ? WINWM_SYSCHAR : WINWM_CHAR;
874
875 // insert message into the queue
876 setThreadQueueExtraCharMessage(teb, &extramsg);
877 winMsg->lParam &= 0x3FFFFFFF;
878 }
879 } // else ???
880 } // KC_SHIFT
881 else
882 {
883 // in case we handle Enter directly through PMKBDHOOK
884 if ((os2Msg->msg == WM_CHAR_SPECIAL) && (winMsg->wParam == VK_RETURN_W)
885 && (fMsgRemoved && !(teb->o.odin.fTranslated)))
886 {
887 MSG extramsg;
888 memcpy(&extramsg, winMsg, sizeof(MSG));
889
890 //After SetFocus(0), all keystrokes are converted in WM_SYS*
891 extramsg.message = (fIgnoreKeystrokes) ? WINWM_SYSCHAR : WINWM_CHAR;
892
893 // insert message into the queue
894 setThreadQueueExtraCharMessage(teb, &extramsg);
895 }
896 }
897 }
898 // if right alt is down, then we need to set the alt down bit too
899 // except for the fake Ctrl WM_CHAR sent for AltGr emulation
900 if (os2Msg->msg != WM_CHAR_SPECIAL_ALTGRCONTROL &&
901 (WinGetKeyState(HWND_DESKTOP, VK_ALTGRAF) & 0x8000))
902 {
903 winMsg->lParam |= WIN_KEY_ALTHELD;
904 }
905 }
906 else
907 {
908 //
909 // the Alt key is pressed
910 //
911 if (flags & KC_KEYUP)
912 {
913 //@@PF Note that without pmkbdhook there will not be correct message for Alt-Enter
914 winMsg->message = WINWM_SYSKEYUP;
915 winMsg->lParam |= WIN_KEY_PREVSTATE;
916 // No ALTHELD for Alt itself ;)
917 winMsg->lParam |= WIN_KEY_ALTHELD;
918 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
919 }
920 else
921 {
922 // send WM_SYSKEYDOWN message
923 winMsg->message = WINWM_SYSKEYDOWN;
924 if (keyWasPressed)
925 winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, 1 means key was pressed
926
927 // pressed ALT-key generates additional flag 0x2000000
928 // if the current window has keyboard focus
929 winMsg->lParam |= WIN_KEY_ALTHELD;
930 }
931 }
932
933 //After SetFocus(0), all keystrokes are converted in WM_SYS*
934 if(fIgnoreKeystrokes) {
935 if(winMsg->message == WINWM_KEYDOWN) {
936 winMsg->message = WINWM_SYSKEYDOWN;
937 }
938 else
939 if(winMsg->message == WINWM_KEYUP) {
940 winMsg->message = WINWM_SYSKEYUP;
941 }
942 }
943 break;
944 }
945
946 case WM_TIMER:
947//Why was this check here????
948// if (os2Msg->mp2)
949// {
950 BOOL sys;
951 ULONG id, proc;
952
953 if (TIMER_GetTimerInfo(os2Msg->hwnd,(ULONG)os2Msg->mp1,&sys,&id, &proc))
954 {
955 winMsg->wParam = (WPARAM)id;
956 winMsg->lParam = (LPARAM)proc;
957 winMsg->message= (sys) ? WINWM_SYSTIMER : WINWM_TIMER;
958 break;
959 }
960// }
961 goto dummymessage; //for caret blinking
962
963 case WM_SETWINDOWPARAMS:
964 {
965 WNDPARAMS *wndParams = (WNDPARAMS *)os2Msg->mp1;
966
967 if(wndParams->fsStatus & WPM_TEXT) {
968 winMsg->message = WINWM_SETTEXT;
969 winMsg->lParam = (LPARAM)wndParams->pszText;
970 break;
971 }
972 goto dummymessage;
973 }
974
975#if 0
976 case WM_QUERYWINDOWPARAMS:
977 {
978 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
979 ULONG textlen;
980 PSZ wintext;
981
982 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
983 {
984 if(wndpars->fsStatus & WPM_CCHTEXT)
985 wndpars->cchText = win32wnd->MsgGetTextLength();
986 if(wndpars->fsStatus & WPM_TEXT)
987 wndpars->pszText = win32wnd->MsgGetText();
988
989 wndpars->fsStatus = 0;
990 wndpars->cbCtlData = 0;
991 wndpars->cbPresParams = 0;
992 goto dummymessage;
993 }
994 }
995#endif
996
997 case WM_PAINT:
998 {
999 if(win32wnd->IsWindowIconic()) {
1000 winMsg->message = WINWM_PAINTICON;
1001 }
1002 else winMsg->message = WINWM_PAINT;
1003 break;
1004 }
1005
1006 case WM_CONTEXTMENU:
1007 winMsg->message = WINWM_CONTEXTMENU;
1008 winMsg->wParam = win32wnd->getWindowHandle();
1009 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
1010 break;
1011
1012 case WM_RENDERFMT:
1013 winMsg->message = WINWM_RENDERFORMAT;
1014 winMsg->wParam = (UINT) os2Msg->mp1;
1015 break;
1016
1017 case WM_RENDERALLFMTS:
1018 winMsg->message = WINWM_RENDERALLFORMATS;
1019 break;
1020
1021 case WM_DESTROYCLIPBOARD:
1022 winMsg->message = WINWM_DESTROYCLIPBOARD;
1023 break;
1024
1025 case WM_DRAWCLIPBOARD:
1026 winMsg->message = WINWM_DRAWCLIPBOARD;
1027 break;
1028
1029 case WM_HSCROLL:
1030 case WM_VSCROLL:
1031 //PF For win32 we support only vertical scrolling for WM_MOUSEWHEEL
1032 if (os2Msg->msg == WM_VSCROLL)
1033 {
1034 POINT CursorPoint;
1035 winMsg->message = WINWM_MOUSEWHEEL;
1036 if (OSLibWinQueryPointerPos(&CursorPoint))
1037 mapScreenPoint((OSLIBPOINT*)&CursorPoint);
1038
1039 if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEDOWN)
1040 winMsg->wParam = MAKELONG(GetMouseKeyState(), -WHEEL_DELTA/OS2_WHEEL_CORRECTION);
1041 else
1042 if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEUP)
1043 winMsg->wParam = MAKELONG(GetMouseKeyState(), WHEEL_DELTA/OS2_WHEEL_CORRECTION);
1044 else
1045 winMsg->wParam = MAKELONG(GetMouseKeyState(), 0);
1046
1047 winMsg->lParam = MAKELONG(CursorPoint.x, CursorPoint.y);
1048
1049 dprintf(("WM_MOUSEWHEEL message delta %d at (%d,%d)",HIWORD(winMsg->wParam),CursorPoint.x, CursorPoint.y));
1050 if (fMsgRemoved == MSG_REMOVE)
1051 {
1052 MSLLHOOKSTRUCT hook;
1053 MOUSEHOOKSTRUCT mousehk;
1054
1055 hook.pt.x = os2Msg->ptl.x & 0xFFFF;
1056 hook.pt.y = mapScreenY(os2Msg->ptl.y);
1057 if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEDOWN)
1058 hook.mouseData = MAKELONG(GetMouseKeyState(), -WHEEL_DELTA/OS2_WHEEL_CORRECTION);
1059 else
1060 if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEUP)
1061 hook.mouseData = MAKELONG(GetMouseKeyState(), WHEEL_DELTA/OS2_WHEEL_CORRECTION);
1062 else goto dummymessage; // IBM driver produces other messages as well sometimes
1063
1064 hook.flags = LLMHF_INJECTED;
1065 hook.time = winMsg->time;
1066 hook.dwExtraInfo = 0;
1067 if(HOOK_CallHooksW( WH_MOUSE_LL, HC_ACTION, WINWM_MOUSEWHEEL, (LPARAM)&hook))
1068 goto dummymessage; //hook swallowed message
1069 }
1070 break;
1071 }
1072 goto dummymessage; //eat this message
1073 break;
1074
1075 case WM_INITMENU:
1076 case WM_MENUSELECT:
1077 case WM_MENUEND:
1078 case WM_NEXTMENU:
1079 case WM_SYSCOLORCHANGE:
1080 case WM_SYSVALUECHANGED:
1081 case WM_SETSELECTION:
1082 case WM_PPAINT:
1083 case WM_PSETFOCUS:
1084 case WM_PSYSCOLORCHANGE:
1085 case WM_PSIZE:
1086 case WM_PACTIVATE:
1087 case WM_PCONTROL:
1088 case WM_HELP:
1089 case WM_APPTERMINATENOTIFY:
1090 case WM_PRESPARAMCHANGED:
1091 case WM_DRAWITEM:
1092 case WM_MEASUREITEM:
1093 case WM_CONTROLPOINTER:
1094 case WM_QUERYDLGCODE:
1095 case WM_SUBSTITUTESTRING:
1096 case WM_MATCHMNEMONIC:
1097 case WM_SAVEAPPLICATION:
1098 case WM_SEMANTICEVENT:
1099 default:
1100dummymessage:
1101 dprintf2(("dummy message %x %x %x %x", os2Msg->hwnd, os2Msg->msg, os2Msg->mp1, os2Msg->mp2));
1102 winMsg->message = 0;
1103 winMsg->wParam = 0;
1104 winMsg->lParam = 0;
1105 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1106 return FALSE;
1107 }
1108msgdone:
1109 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1110 return TRUE;
1111}
1112//******************************************************************************
1113//******************************************************************************
1114BOOL OSLibWinTranslateMessage(MSG *msg)
1115{
1116 TEB *teb;
1117 MSG extramsg;
1118 BOOL numPressed = (BOOL)(WinGetKeyState(HWND_DESKTOP,VK_NUMLOCK) & 1);
1119 teb = GetThreadTEB();
1120 if(!teb)
1121 return FALSE;
1122
1123 UCHAR ucPMScanCode = CHAR4FROMMP(teb->o.odin.os2msg.mp1);
1124 ULONG fl = SHORT1FROMMP(teb->o.odin.os2msg.mp1);
1125
1126
1127 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
1128 // the newly generated WM_CHAR message.
1129 if(!teb->o.odin.fTranslated &&
1130 teb->o.odin.os2msg.msg == WM_CHAR &&
1131 !((SHORT1FROMMP(teb->o.odin.os2msg.mp1) & KC_KEYUP) == KC_KEYUP))
1132 {
1133 //TranslatedMessage was called before DispatchMessage, so queue WM_CHAR message
1134 memcpy(&extramsg, msg, sizeof(MSG));
1135 extramsg.wParam = SHORT1FROMMP(teb->o.odin.os2msg.mp2);
1136 extramsg.lParam = 0;
1137
1138 // ESCAPE generates a WM_CHAR under windows, so take
1139 // special care for this here.
1140 switch (ucPMScanCode)
1141 {
1142 case PMSCAN_ESC:
1143 extramsg.wParam = VK_ESCAPE_W;
1144 fl |= KC_CHAR;
1145 break;
1146 }
1147
1148 // PF With NumLock off do not generate any WM_CHAR messages at all
1149 // PADMINUS,PADPLUS fall in range of PAD7..PADPERIOD but they should generate WM_CHAR
1150 // other PAD(X) buttons miss that range at all and thus generate WM_CHAR
1151 if (!numPressed && (ucPMScanCode != PMSCAN_PADMINUS) && (ucPMScanCode != PMSCAN_PADPLUS) &&
1152 (ucPMScanCode >= PMSCAN_PAD7) && (ucPMScanCode <= PMSCAN_PADPERIOD))
1153 return FALSE;
1154
1155 if(!(fl & KC_CHAR) && msg->message < WINWM_SYSKEYDOWN)
1156 {
1157 return FALSE;
1158 }
1159
1160 //the KC_COMPOSITE flag might be set; in that case this key will
1161 //be combined with the previous dead key, so we must use the scancode
1162 //(e.g. ^ on german keyboards)
1163 if((fl & (KC_VIRTUALKEY|KC_COMPOSITE)) == KC_VIRTUALKEY)
1164 {
1165 if(!msg->wParam)
1166 {//TODO: Why is this here????
1167 DebugInt3();
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.