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

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

Handle SetFocus(0) correctly: keystrokes are converted into WM_SYSKEYDOWN/(WM_SYSCHAR)/WM_SYSKEYUP messages

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