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

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

PF: Fix for Ctrl-Break

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