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

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

Send WM_QUERYNEWPALETTE when a window receives focus; translate WM_REALIZEPALETTE into WM_PALETTECHANGED

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