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

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

Gracefully handle WM_QUIT message sent by window list

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