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

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

PF: Shift/Ctrl/Alt+Numpad keys illegal behaviour. Generic numpad keys like (/*-+) produced garbage

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