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

Last change on this file since 10190 was 10190, checked in by sandervl, 22 years ago

KOMH: DBCS updates/fixes

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