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

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

Check if WM_KILLFOCUS was already sent by SetFocus(0) call

File size: 35.9 KB
Line 
1/* $Id: oslibmsgtranslate.cpp,v 1.101 2003-02-13 10:34:48 sandervl Exp $ */
2/*
3 * Window message translation functions for OS/2
4 *
5 *
6 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 * Copyright 1999 Daniela Engert (dani@ngrt.de)
8 * Copyright 1999 Rene Pronk (R.Pronk@twi.tudelft.nl)
9 *
10 * Project Odin Software License can be found in LICENSE.TXT
11 *
12 * TODO: Extra msgs: which messages must be put into the queue and which can be sent directly?
13 * (According to the docs TranslateMessage really inserts a msg in the queue)
14 * TODO: Filter translation isn't correct for posted messages
15 *
16 */
17#define INCL_WIN
18#define INCL_PM
19#define INCL_DOSPROCESS
20#include <os2wrap.h>
21#include <string.h>
22#include <misc.h>
23#include <winconst.h>
24#include <win32api.h>
25#include "oslibmsg.h"
26#include <winuser32.h>
27#include "win32wdesktop.h"
28#include "oslibutil.h"
29#include "timer.h"
30#include <thread.h>
31#include <wprocess.h>
32#include "pmwindow.h"
33#include "oslibwin.h"
34#include "winmouse.h"
35#include <pmkbdhk.h>
36#include <pmscan.h>
37#include <winscan.h>
38#include <winkeyboard.h>
39#include "hook.h"
40#include "user32api.h"
41
42#define DBG_LOCALLOG DBG_oslibmsgtranslate
43#include "dbglocal.h"
44
45static BOOL fGenerateDoubleClick = FALSE;
46static MSG doubleClickMsg = {0};
47
48//For wheel mouse translation
49#define WHEEL_DELTA 120
50#define OS2_WHEEL_CORRECTION 1
51//PF Correction is different for different mouse drivers. For now no correction
52//is ok because lots of Odin controls rely on minimum delta. However in future
53//we will possibly detect mouse driver and use correction if speed will be
54//too high or too low.
55
56//******************************************************************************
57//******************************************************************************
58BOOL setThreadQueueExtraCharMessage(TEB* teb, MSG* pExtraMsg)
59{
60 // check if the single slot is occupied already
61 if (teb->o.odin.fTranslated == TRUE)
62 // there's still an already translated message to be processed
63 return FALSE;
64 teb->o.odin.fTranslated = TRUE;
65 memcpy(&teb->o.odin.msgWCHAR, pExtraMsg, sizeof(MSG));
66 return TRUE;
67}
68
69//******************************************************************************
70//******************************************************************************
71ULONG 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 //If SetFocus(0) was called, then the window has already received
292 //a WM_KILLFOCUS; don't send another one
293 if(!fIgnoreKeystrokes) {
294 winMsg->message = WINWM_KILLFOCUS;
295 winMsg->wParam = (WPARAM)hwndFocus;
296 }
297 else {
298 dprintf(("Window has already received a WM_KILLFOCUS (SetFocus(0)); ignore"));
299 goto dummymessage;
300 }
301 }
302 break;
303 }
304
305 //**************************************************************************
306 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
307 //**************************************************************************
308 case WM_BUTTON1DOWN:
309 case WM_BUTTON1UP:
310 case WM_BUTTON1DBLCLK:
311 case WM_BUTTON2DOWN:
312 case WM_BUTTON2UP:
313 case WM_BUTTON2DBLCLK:
314 case WM_BUTTON3DOWN:
315 case WM_BUTTON3UP:
316 case WM_BUTTON3DBLCLK:
317 {
318 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
319
320 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));
321
322 HWND hwnd;
323
324 DisableLogging();
325 if(GetCapture() != winMsg->hwnd)
326 {
327 hwnd = WindowFromPoint(winMsg->pt);
328 if(win32wnd->getWindowHandle() != hwnd) {
329 RELEASE_WNDOBJ(win32wnd);
330 win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
331 if(win32wnd == NULL) {
332 DebugInt3();
333 EnableLogging();
334 goto dummymessage;
335 }
336 winMsg->hwnd = hwnd;
337 }
338 }
339
340 //if a window is disabled, its parent receives the mouse messages
341 if(!IsWindowEnabled(win32wnd->getWindowHandle())) {
342 if(win32wnd->getParent()) {
343 Win32BaseWindow *parent = win32wnd->getParent();;
344 if(parent) parent->addRef();
345 RELEASE_WNDOBJ(win32wnd);
346 win32wnd = parent;
347 }
348 fWasDisabled = TRUE;
349 }
350
351 if(IsNCMouseMsg(win32wnd)) {
352 winMsg->message = WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
353 winMsg->wParam = win32wnd->getLastHitTestVal();
354 winMsg->lParam = MAKELONG(winMsg->pt.x, winMsg->pt.y); //screen coordinates
355 }
356 else {
357 ClientPoint.x = winMsg->pt.x;
358 ClientPoint.y = winMsg->pt.y;
359 MapWindowPoints(0, win32wnd->getWindowHandle(), (LPPOINT)&ClientPoint, 1);
360 winMsg->message = WINWM_LBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
361 winMsg->wParam = GetMouseKeyState();
362 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
363 }
364 EnableLogging();
365
366 if(fWasDisabled) {
367 if(win32wnd) {
368 winMsg->hwnd = win32wnd->getWindowHandle();
369 }
370 else goto dummymessage; //don't send mouse messages to disabled windows
371 }
372
373 DisableLogging();
374 if ((winMsg->message == WINWM_LBUTTONDOWN) ||
375 (winMsg->message == WINWM_RBUTTONDOWN) ||
376 (winMsg->message == WINWM_MBUTTONDOWN) ||
377 (winMsg->message == WINWM_NCLBUTTONDOWN) ||
378 (winMsg->message == WINWM_NCRBUTTONDOWN) ||
379 (winMsg->message == WINWM_NCMBUTTONDOWN))
380 {
381 if(fGenerateDoubleClick && doubleClickMsg.message == winMsg->message &&
382 winMsg->time - doubleClickMsg.time < GetDoubleClickTime() &&
383 (abs(winMsg->pt.x - doubleClickMsg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK_W)/2) &&
384 (abs(winMsg->pt.y - doubleClickMsg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK_W)/2))
385 {
386 dprintf(("single -> double click"));
387 if(winMsg->message >= WINWM_LBUTTONDOWN) {
388 winMsg->message += (WINWM_LBUTTONDBLCLK - WINWM_LBUTTONDOWN);
389 }
390 else winMsg->message += (WINWM_LBUTTONDBLCLK - WINWM_NCLBUTTONDOWN);
391 if(fMsgRemoved) doubleClickMsg.message = 0;
392 }
393 else {
394 dprintf(("save for double click"));
395 if(fMsgRemoved) {
396 doubleClickMsg = *winMsg;
397 if(doubleClickMsg.message >= WINWM_NCLBUTTONDOWN && doubleClickMsg.message <= WINWM_NCMBUTTONDOWN) {
398 doubleClickMsg.message += (WINWM_LBUTTONDOWN - WINWM_NCLBUTTONDOWN);
399 }
400 }
401 }
402 }
403 EnableLogging();
404
405 if(fMsgRemoved == MSG_REMOVE)
406 {
407 MSLLHOOKSTRUCT hook;
408 ULONG msg;
409
410 if(winMsg->message >= WINWM_NCLBUTTONDOWN && winMsg->message <= WINWM_NCMBUTTONDBLCLK) {
411 msg = winMsg->message - WINWM_NCLBUTTONDOWN + WINWM_LBUTTONDOWN;
412 }
413 else msg = winMsg->message;
414
415 if(msg == WINWM_LBUTTONDBLCLK) {
416 msg = WINWM_LBUTTONDOWN;
417 }
418 else
419 if(msg == WINWM_RBUTTONDBLCLK) {
420 msg = WINWM_RBUTTONDOWN;
421 }
422 else
423 if(msg == WINWM_MBUTTONDBLCLK) {
424 msg = WINWM_MBUTTONDOWN;
425 }
426
427 hook.pt.x = os2Msg->ptl.x & 0xFFFF;
428 hook.pt.y = mapScreenY(os2Msg->ptl.y);
429 hook.mouseData = 0; //todo: XBUTTON1/2 (XP feature) or wheel data
430 hook.flags = 0; //todo: injected (LLMHF_INJECTED)
431 hook.time = winMsg->time;
432 hook.dwExtraInfo = 0;
433
434 if(HOOK_CallHooksW( WH_MOUSE_LL, HC_ACTION, msg, (LPARAM)&hook)) {
435 goto dummymessage; //hook swallowed message
436 }
437 }
438 break;
439 }
440
441 case WM_BUTTON2CLICK:
442 case WM_BUTTON1CLICK:
443 case WM_BUTTON3CLICK:
444 goto dummymessage;
445
446 case WM_BUTTON2MOTIONSTART:
447 case WM_BUTTON2MOTIONEND:
448 case WM_BUTTON1MOTIONSTART:
449 case WM_BUTTON1MOTIONEND:
450 case WM_BUTTON3MOTIONSTART:
451 case WM_BUTTON3MOTIONEND:
452 //no break; translate to WM_MOUSEMOVE
453 //Some applications (e.g. Unreal) retrieve all mouse messages
454 //when a mouse button is pressed and don't expect WM_NULL
455
456 case WM_MOUSEMOVE:
457 {
458 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
459
460 HWND hwnd;
461
462 dprintf2(("WM_MOUSEMOVE (%d,%d)", winMsg->pt.x, winMsg->pt.y));
463 DisableLogging();
464 if(GetCapture() != winMsg->hwnd)
465 {
466 hwnd = WindowFromPoint(winMsg->pt);
467 if(win32wnd->getWindowHandle() != hwnd) {
468 RELEASE_WNDOBJ(win32wnd);
469 win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
470 if(win32wnd == NULL) {
471 DebugInt3();
472 EnableLogging();
473 goto dummymessage;
474 }
475 winMsg->hwnd = hwnd;
476 }
477 }
478
479 //if a window is disabled, its parent receives the mouse messages
480 if(!IsWindowEnabled(win32wnd->getWindowHandle())) {
481 if(win32wnd->getParent()) {
482 Win32BaseWindow *parent = win32wnd->getParent();;
483 if(parent) parent->addRef();
484 RELEASE_WNDOBJ(win32wnd);
485 win32wnd = parent;
486 }
487 fWasDisabled = TRUE;
488 }
489 if(IsNCMouseMsg(win32wnd))
490 {
491 winMsg->message = WINWM_NCMOUSEMOVE;
492 winMsg->wParam = (WPARAM)win32wnd->getLastHitTestVal();
493 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
494 }
495 else
496 {
497 ClientPoint.x = winMsg->pt.x;
498 ClientPoint.y = winMsg->pt.y;
499 MapWindowPoints(0, win32wnd->getWindowHandle(), (LPPOINT)&ClientPoint, 1);
500
501 winMsg->message = WINWM_MOUSEMOVE;
502 winMsg->wParam = GetMouseKeyState();
503 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
504 }
505 EnableLogging();
506 if(fWasDisabled) {
507 if(win32wnd) {
508 winMsg->hwnd = win32wnd->getWindowHandle();
509 }
510 else {
511 goto dummymessage; //don't send mouse messages to disabled windows
512 }
513 }
514 if(fMsgRemoved == MSG_REMOVE)
515 {
516 MSLLHOOKSTRUCT hook;
517
518 hook.pt.x = os2Msg->ptl.x & 0xFFFF;
519 hook.pt.y = mapScreenY(os2Msg->ptl.y);
520 hook.mouseData = 0;
521 hook.flags = 0; //todo: injected (LLMHF_INJECTED)
522 hook.time = winMsg->time;
523 hook.dwExtraInfo = 0;
524
525 if(HOOK_CallHooksW( WH_MOUSE_LL, HC_ACTION, winMsg->message, (LPARAM)&hook)) {
526 goto dummymessage; //hook swallowed message
527 }
528 }
529 break;
530 }
531
532 case WM_CONTROL:
533 goto dummymessage;
534
535 case WM_COMMAND:
536 if(SHORT1FROMMP(os2Msg->mp2) == CMDSRC_MENU) {
537 winMsg->message = WINWM_COMMAND;
538 winMsg->wParam = (WPARAM)SHORT1FROMMP(os2Msg->mp1); //id
539 break;
540 }
541 //todo controls
542 goto dummymessage;
543
544 case WM_SYSCOMMAND:
545 {
546 ULONG x = 0, y = 0;
547 ULONG win32sc;
548
549 if(SHORT2FROMMP(os2Msg->mp2) == TRUE) {//syscommand caused by mouse action
550 POINTL pointl;
551 WinQueryPointerPos(HWND_DESKTOP, &pointl);
552 x = pointl.x;
553 y = mapScreenY(y);
554 }
555 switch(SHORT1FROMMP(os2Msg->mp1)) {
556 case SC_MOVE:
557 win32sc = SC_MOVE_W;
558 break;
559 case SC_CLOSE:
560 {
561 //FALSE -> keyboard operation = user pressed Alt-F4 -> close app
562 //TRUE -> user clicked on close button -> close window
563 if(SHORT2FROMMP(os2Msg->mp2) == FALSE)
564 {
565 HWND hwnd = win32wnd->GetTopParent();
566 if(win32wnd->getWindowHandle() != hwnd) {
567 RELEASE_WNDOBJ(win32wnd);
568 win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
569 if(win32wnd == NULL) {
570 DebugInt3();
571 goto dummymessage;
572 }
573 winMsg->hwnd = hwnd;
574 }
575 }
576 win32sc = SC_CLOSE_W;
577 break;
578 }
579 case SC_MAXIMIZE:
580 win32sc = SC_MAXIMIZE_W;
581 break;
582 case SC_MINIMIZE:
583 win32sc = SC_MINIMIZE_W;
584 break;
585 case SC_NEXTFRAME:
586 case SC_NEXTWINDOW:
587 win32sc = SC_NEXTWINDOW_W;
588 break;
589 case SC_RESTORE:
590 win32sc = SC_RESTORE_W;
591 break;
592 case SC_TASKMANAGER:
593 win32sc = SC_TASKLIST_W;
594 break;
595 default:
596 dprintf(("Unknown/unsupported SC command %d", SHORT1FROMMP(os2Msg->mp1)));
597 goto dummymessage;
598 }
599 winMsg->message= WINWM_SYSCOMMAND;
600 winMsg->wParam = (WPARAM)win32sc;
601 winMsg->lParam = MAKELONG((USHORT)x, (USHORT)y);
602 break;
603 }
604
605 case WM_CHAR_SPECIAL:
606 {
607 // @@@PH
608 // special char message from the keyboard hook
609 dprintf(("PM: WM_CHAR_SPECIAL\n"));
610
611 // NO BREAK! FALLTHRU CASE!
612 }
613
614 case WM_CHAR:
615 {
616 ULONG repeatCount=0;
617 ULONG virtualKey=0;
618 ULONG keyFlags=0;
619 USHORT scanCode=0;
620 ULONG flags = SHORT1FROMMP(os2Msg->mp1);
621 BOOL keyWasPressed;
622 char c;
623 USHORT usPMScanCode = CHAR4FROMMP(os2Msg->mp1);
624
625 teb->o.odin.fTranslated = FALSE;
626 repeatCount = CHAR3FROMMP(os2Msg->mp1);
627 scanCode = CHAR4FROMMP(os2Msg->mp1);
628 keyWasPressed = ((SHORT1FROMMP (os2Msg->mp1) & KC_PREVDOWN) == KC_PREVDOWN);
629
630 dprintf(("PM: WM_CHAR: %x %x rep=%d scancode=%x", SHORT1FROMMP(os2Msg->mp2), SHORT2FROMMP(os2Msg->mp2), repeatCount, scanCode));
631 dprintf(("PM: WM_CHAR: hwnd %x flags %x mp1 %x, mp2 %x, time=%08xh", win32wnd->getWindowHandle(), flags, os2Msg->mp1, os2Msg->mp2, os2Msg->time));
632
633 BOOL fWinExtended;
634 BYTE bWinVKey;
635 WORD wWinScan;
636
637 if (scanCode==0) goto dummymessage;
638
639 // Note: Numlock-state currently ignored, see below
640 KeyTranslatePMScanToWinVKey(usPMScanCode,
641 FALSE,
642 &bWinVKey,
643 &wWinScan,
644 &fWinExtended);
645 winMsg->wParam = bWinVKey;
646 winMsg->lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
647 winMsg->lParam |= (wWinScan & 0x1FF) << 16; // bit 16-23, scancode + bit 15 extended
648
649 // Set the extended bit when appropriate
650 if (fWinExtended)
651 winMsg->lParam = winMsg->lParam | WIN_KEY_EXTENDED;
652
653#if 0
654//TODO
655 // Adjust VKEY value for pad digits if NumLock is on
656 if ((scanCode >= 0x47) && (scanCode <= 0x53) &&
657 (virtualKey >= 0x30) && (virtualKey >= 39))
658 winMsg->wParam = virtualKey + 0x30;
659#endif
660
661
662 //@PF This looks ugly but this is just what we have in win32 both in win98/win2k
663 //what happens is that lParam is tweaked in win32 to contain some illegal codes
664 //I simply reproduce here all situation. Absolute values can be kept because
665 //Break scancode can be acheived only by pressing Ctrl-Break combination
666 if ((usPMScanCode == PMSCAN_BREAK) && !(flags & KC_KEYUP) && (flags & KC_CTRL)
667 && (fMsgRemoved && !(teb->o.odin.fTranslated)))
668 {
669 MSG extramsg;
670 memcpy(&extramsg, winMsg, sizeof(MSG));
671 // adjust our WM_CHAR code
672 extramsg.lParam = 0x01460001;
673
674 //After SetFocus(0), all keystrokes are converted in WM_SYS*
675 extramsg.message = (fIgnoreKeystrokes) ? WINWM_SYSCHAR : WINWM_CHAR;
676
677 setThreadQueueExtraCharMessage(teb, &extramsg);
678 // and finally adjust our WM_KEYDOWN code
679 winMsg->lParam = 0x01460001;
680 }
681
682 if (!(flags & KC_ALT))
683 {
684 //
685 // the Alt key is not pressed
686 // or no more pressed
687 //
688 if (flags & KC_KEYUP)
689 {
690 // check for a lonesome ALT key ...
691 if ( (flags & KC_LONEKEY) &&
692 ((winMsg->wParam == VK_LMENU_W) || (winMsg->wParam == VK_RMENU_W)) )
693 {
694 winMsg->message = WINWM_SYSKEYUP;
695 // held ALT-key when current key is released
696 // generates additional flag 0x2000000
697 // Note: PM seems to do this differently,
698 // KC_ALT is already reset
699 }
700 else
701 {
702 // send WM_KEYUP message
703 winMsg->message = WINWM_KEYUP;
704 }
705 winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, always 1 for a WM_KEYUP message
706 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
707 }
708 else
709 { // send WM_KEYDOWN message
710 winMsg->message = WINWM_KEYDOWN;
711
712 if (keyWasPressed)
713 winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, 1 means key was pressed
714
715 //Shift-Enter and possibly others need to have special handling
716 if (flags & KC_SHIFT)
717 {
718 if(fMsgRemoved && !(teb->o.odin.fTranslated))
719 {
720 dprintf(("PM: KC_SHIFT: %x",winMsg->wParam));
721 if (winMsg->wParam == VK_RETURN_W)
722 {
723 MSG extramsg;
724 memcpy(&extramsg, winMsg, sizeof(MSG));
725
726 //After SetFocus(0), all keystrokes are converted in WM_SYS*
727 extramsg.message = (fIgnoreKeystrokes) ? WINWM_SYSCHAR : WINWM_CHAR;
728
729 // insert message into the queue
730 setThreadQueueExtraCharMessage(teb, &extramsg);
731 winMsg->lParam &= 0x3FFFFFFF;
732 }
733 } // else ???
734 } // KC_SHIFT
735 else
736 {
737 // in case we handle Enter directly through PMKBDHOOK
738 if ((os2Msg->msg == WM_CHAR_SPECIAL) && (winMsg->wParam == VK_RETURN_W)
739 && (fMsgRemoved && !(teb->o.odin.fTranslated)))
740 {
741 MSG extramsg;
742 memcpy(&extramsg, winMsg, sizeof(MSG));
743
744 //After SetFocus(0), all keystrokes are converted in WM_SYS*
745 extramsg.message = (fIgnoreKeystrokes) ? WINWM_SYSCHAR : WINWM_CHAR;
746
747 // insert message into the queue
748 setThreadQueueExtraCharMessage(teb, &extramsg);
749 }
750 }
751 }
752 // if right alt is down, then we need to set the alt down bit too
753 if (WinGetKeyState(HWND_DESKTOP, VK_ALTGRAF) & 0x8000) {
754 winMsg->lParam |= WIN_KEY_ALTHELD;
755 }
756 }
757 else
758 {
759 //
760 // the Alt key is pressed
761 //
762 if (flags & KC_KEYUP)
763 {
764 //@@PF Note that without pmkbdhook there will not be correct message for Alt-Enter
765 winMsg->message = WINWM_SYSKEYUP;
766 winMsg->lParam |= WIN_KEY_PREVSTATE;
767 // No ALTHELD for Alt itself ;)
768 winMsg->lParam |= WIN_KEY_ALTHELD;
769 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
770 }
771 else
772 {
773 // send WM_SYSKEYDOWN message
774 winMsg->message = WINWM_SYSKEYDOWN;
775 if (keyWasPressed)
776 winMsg->lParam |= WIN_KEY_PREVSTATE; // bit 30, previous state, 1 means key was pressed
777
778 // pressed ALT-key generates additional flag 0x2000000
779 // if the current window has keyboard focus
780 winMsg->lParam |= WIN_KEY_ALTHELD;
781 }
782 }
783 //After SetFocus(0), all keystrokes are converted in WM_SYS*
784 if(fIgnoreKeystrokes) {
785 if(winMsg->message == WINWM_KEYDOWN) {
786 winMsg->message = WINWM_SYSKEYDOWN;
787 }
788 else
789 if(winMsg->message == WINWM_KEYUP) {
790 winMsg->message = WINWM_SYSKEYUP;
791 }
792 }
793 break;
794 }
795
796 case WM_TIMER:
797//Why was this check here????
798// if (os2Msg->mp2)
799// {
800 BOOL sys;
801 ULONG id;
802
803 if (TIMER_GetTimerInfo(os2Msg->hwnd,(ULONG)os2Msg->mp1,&sys,&id))
804 {
805 winMsg->wParam = (WPARAM)id;
806 winMsg->message= (sys) ? WINWM_SYSTIMER : WINWM_TIMER;
807 break;
808 }
809// }
810 goto dummymessage; //for caret blinking
811
812 case WM_SETWINDOWPARAMS:
813 {
814 WNDPARAMS *wndParams = (WNDPARAMS *)os2Msg->mp1;
815
816 if(wndParams->fsStatus & WPM_TEXT) {
817 winMsg->message = WINWM_SETTEXT;
818 winMsg->lParam = (LPARAM)wndParams->pszText;
819 break;
820 }
821 goto dummymessage;
822 }
823
824#if 0
825 case WM_QUERYWINDOWPARAMS:
826 {
827 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
828 ULONG textlen;
829 PSZ wintext;
830
831 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
832 {
833 if(wndpars->fsStatus & WPM_CCHTEXT)
834 wndpars->cchText = win32wnd->MsgGetTextLength();
835 if(wndpars->fsStatus & WPM_TEXT)
836 wndpars->pszText = win32wnd->MsgGetText();
837
838 wndpars->fsStatus = 0;
839 wndpars->cbCtlData = 0;
840 wndpars->cbPresParams = 0;
841 goto dummymessage;
842 }
843 }
844#endif
845
846 case WM_PAINT:
847 {
848 if(win32wnd->IsWindowIconic()) {
849 winMsg->message = WINWM_PAINTICON;
850 }
851 else winMsg->message = WINWM_PAINT;
852 break;
853 }
854
855 case WM_CONTEXTMENU:
856 winMsg->message = WINWM_CONTEXTMENU;
857 winMsg->wParam = win32wnd->getWindowHandle();
858 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
859 break;
860
861 case WM_RENDERFMT:
862 winMsg->message = WINWM_RENDERFORMAT;
863 winMsg->wParam = (UINT) os2Msg->mp1;
864 break;
865
866 case WM_RENDERALLFMTS:
867 winMsg->message = WINWM_RENDERALLFORMATS;
868 break;
869
870 case WM_DESTROYCLIPBOARD:
871 winMsg->message = WINWM_DESTROYCLIPBOARD;
872 break;
873
874 case WM_DRAWCLIPBOARD:
875 winMsg->message = WINWM_DRAWCLIPBOARD;
876 break;
877
878 case WM_HSCROLL:
879 case WM_VSCROLL:
880 //PF For win32 we support only vertical scrolling for WM_MOUSEWHEEL
881 if (os2Msg->msg == WM_VSCROLL)
882 {
883 POINT CursorPoint;
884 winMsg->message = WINWM_MOUSEWHEEL;
885 if (OSLibWinQueryPointerPos(&CursorPoint))
886 mapScreenPoint((OSLIBPOINT*)&CursorPoint);
887
888 if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEDOWN)
889 winMsg->wParam = MAKELONG(GetMouseKeyState(), -WHEEL_DELTA/OS2_WHEEL_CORRECTION);
890 else
891 if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEUP)
892 winMsg->wParam = MAKELONG(GetMouseKeyState(), WHEEL_DELTA/OS2_WHEEL_CORRECTION);
893 else
894 winMsg->wParam = MAKELONG(GetMouseKeyState(), 0);
895
896 winMsg->lParam = MAKELONG(CursorPoint.x, CursorPoint.y);
897
898 dprintf(("WM_MOUSEWHEEL message delta %d at (%d,%d)",HIWORD(winMsg->wParam),CursorPoint.x, CursorPoint.y));
899 if (fMsgRemoved == MSG_REMOVE)
900 {
901 MSLLHOOKSTRUCT hook;
902
903 hook.pt.x = os2Msg->ptl.x & 0xFFFF;
904 hook.pt.y = mapScreenY(os2Msg->ptl.y);
905 if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEDOWN)
906 hook.mouseData = MAKELONG(GetMouseKeyState(), -WHEEL_DELTA/OS2_WHEEL_CORRECTION);
907 else
908 if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEUP)
909 hook.mouseData = MAKELONG(GetMouseKeyState(), WHEEL_DELTA/OS2_WHEEL_CORRECTION);
910 else goto dummymessage; // IBM driver produces other messages as well sometimes
911
912 hook.flags = LLMHF_INJECTED;
913 hook.time = winMsg->time;
914 hook.dwExtraInfo = 0;
915 if(HOOK_CallHooksW( WH_MOUSE_LL, HC_ACTION, WINWM_MOUSEWHEEL, (LPARAM)&hook))
916 goto dummymessage; //hook swallowed message
917 }
918 break;
919 }
920 goto dummymessage; //eat this message
921 break;
922
923 case WM_INITMENU:
924 case WM_MENUSELECT:
925 case WM_MENUEND:
926 case WM_NEXTMENU:
927 case WM_SYSCOLORCHANGE:
928 case WM_SYSVALUECHANGED:
929 case WM_SETSELECTION:
930 case WM_PPAINT:
931 case WM_PSETFOCUS:
932 case WM_PSYSCOLORCHANGE:
933 case WM_PSIZE:
934 case WM_PACTIVATE:
935 case WM_PCONTROL:
936 case WM_HELP:
937 case WM_APPTERMINATENOTIFY:
938 case WM_PRESPARAMCHANGED:
939 case WM_DRAWITEM:
940 case WM_MEASUREITEM:
941 case WM_CONTROLPOINTER:
942 case WM_QUERYDLGCODE:
943 case WM_SUBSTITUTESTRING:
944 case WM_MATCHMNEMONIC:
945 case WM_SAVEAPPLICATION:
946 case WM_SEMANTICEVENT:
947 default:
948dummymessage:
949 dprintf2(("dummy message %x %x %x %x", os2Msg->hwnd, os2Msg->msg, os2Msg->mp1, os2Msg->mp2));
950 winMsg->message = 0;
951 winMsg->wParam = 0;
952 winMsg->lParam = 0;
953 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
954 return FALSE;
955 }
956 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
957 return TRUE;
958}
959//******************************************************************************
960//******************************************************************************
961BOOL OSLibWinTranslateMessage(MSG *msg)
962{
963 TEB *teb;
964 MSG extramsg;
965
966 teb = GetThreadTEB();
967 if(!teb)
968 return FALSE;
969
970 UCHAR ucPMScanCode = CHAR4FROMMP(teb->o.odin.os2msg.mp1);
971 ULONG fl = SHORT1FROMMP(teb->o.odin.os2msg.mp1);
972
973
974 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
975 // the newly generated WM_CHAR message.
976 if(!teb->o.odin.fTranslated &&
977 teb->o.odin.os2msg.msg == WM_CHAR &&
978 !((SHORT1FROMMP(teb->o.odin.os2msg.mp1) & KC_KEYUP) == KC_KEYUP))
979 {
980 //TranslatedMessage was called before DispatchMessage, so queue WM_CHAR message
981 memcpy(&extramsg, msg, sizeof(MSG));
982 extramsg.wParam = SHORT1FROMMP(teb->o.odin.os2msg.mp2);
983 extramsg.lParam = 0;
984
985 // ESCAPE generates a WM_CHAR under windows, so take
986 // special care for this here.
987 switch (ucPMScanCode)
988 {
989 case PMSCAN_ESC:
990 extramsg.wParam = VK_ESCAPE_W;
991 fl |= KC_CHAR;
992 break;
993 }
994
995 if(!(fl & KC_CHAR) && msg->message < WINWM_SYSKEYDOWN)
996 {
997 return FALSE;
998 }
999
1000 //the KC_COMPOSITE flag might be set; in that case this key will
1001 //be combined with the previous dead key, so we must use the scancode
1002 //(e.g. ^ on german keyboards)
1003 if(fl & (KC_VIRTUALKEY|KC_COMPOSITE) == KC_VIRTUALKEY)
1004 {
1005 if(msg->wParam)
1006 {
1007 if ((msg->wParam >= VK_NUMPAD0_W) &&
1008 (msg->wParam <= VK_NUMPAD9_W))
1009 extramsg.wParam = msg->wParam - 0x30;
1010 else
1011 extramsg.wParam = msg->wParam;
1012 }
1013 else
1014 extramsg.wParam = SHORT2FROMMP(teb->o.odin.os2msg.mp2);
1015 }
1016
1017
1018 //After SetFocus(0), all keystrokes are converted in WM_SYS*
1019 if(msg->message >= WINWM_SYSKEYDOWN || fIgnoreKeystrokes)
1020 extramsg.message = WINWM_SYSCHAR;
1021 else
1022 extramsg.message = WINWM_CHAR;
1023
1024 if(fl & KC_DEADKEY)
1025 extramsg.message++; //WM_DEADCHAR/WM_SYSDEADCHAR
1026
1027
1028 extramsg.lParam = msg->lParam & 0x00FFFFFF;
1029 if ((fl & KC_ALT) || (msg->lParam & WIN_KEY_ALTHELD))
1030 extramsg.lParam |= WIN_KEY_ALTHELD;
1031 if(fl & KC_PREVDOWN)
1032 extramsg.lParam |= WIN_KEY_PREVSTATE;
1033 if(fl & KC_KEYUP)
1034 extramsg.lParam |= (1<<31);
1035
1036 // insert message into the queue
1037 setThreadQueueExtraCharMessage(teb, &extramsg);
1038 return TRUE;
1039 }
1040 return FALSE;
1041}
1042//******************************************************************************
1043//******************************************************************************
1044
Note: See TracBrowser for help on using the repository browser.