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

Last change on this file since 5413 was 5413, checked in by sandervl, 24 years ago

disable logging while processing mouse messages

File size: 28.9 KB
Line 
1/* $Id: oslibmsgtranslate.cpp,v 1.45 2001-03-31 10:48:41 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
36#define DBG_LOCALLOG DBG_oslibmsgtranslate
37#include "dbglocal.h"
38
39// Formerly used method of translation based on OS/2 VKEY value didn't work
40// right. We need to take a look at the scan code we get from PM and derive
41// the Win32 VKEY and scancode from that because sometimes even the scancode
42// used in Win32 is different from the PM scancode!
43// The format is:
44// Win VKEY, Win scancode, (PM scancode) (key description)
45USHORT pmscan2winkey [][2] = {
46 0, 0, // 0x00
47 0x1B, 0x01, // 0x01 Esc
48 0x31, 0x02, // 0x02 1
49 0x32, 0x03, // 0x03 2
50 0x33, 0x04, // 0x04 3
51 0x34, 0x05, // 0x05 4
52 0x35, 0x06, // 0x06 5
53 0x36, 0x07, // 0x07 6
54 0x37, 0x08, // 0x08 7
55 0x38, 0x09, // 0x09 8
56 0x39, 0x0A, // 0x0A 9
57 0x30, 0x0B, // 0x0B 0
58 0xBD, 0x0C, // 0x0C -
59 0xBB, 0x0D, // 0x0D =
60 0x08, 0x0E, // 0x0E Bksp
61 0x09, 0x0F, // 0x0F Tab
62 0x51, 0x10, // 0x10 q
63 0x57, 0x11, // 0x11 w
64 0x45, 0x12, // 0x12 e
65 0x52, 0x13, // 0x13 r
66 0x54, 0x14, // 0x14 t
67 0x59, 0x15, // 0x15 y
68 0x55, 0x16, // 0x16 u
69 0x49, 0x17, // 0x17 i
70 0x4F, 0x18, // 0x18 o
71 0x50, 0x19, // 0x19 p
72 0xDB, 0x1A, // 0x1A [
73 0xDD, 0x1B, // 0x1B ]
74 0x0D, 0x1C, // 0x1C Enter
75 0x11, 0x1D, // 0x1D LCtrl
76 0x41, 0x1E, // 0x1E a
77 0x53, 0x1F, // 0x1F s
78 0x44, 0x20, // 0x20 d
79 0x46, 0x21, // 0x21 f
80 0x47, 0x22, // 0x22 g
81 0x48, 0x23, // 0x23 h
82 0x4A, 0x24, // 0x24 j
83 0x4B, 0x25, // 0x25 k
84 0x4C, 0x26, // 0x26 l
85 0xBA, 0x27, // 0x27 ;
86 0xDE, 0x28, // 0x28 '
87 0xC0, 0x29, // 0x29 `
88 0x10, 0x2A, // 0x2A LShift
89 0xDC, 0x2B, // 0x2B Bkslsh
90 0x5A, 0x2C, // 0x2C z
91 0x58, 0x2D, // 0x2D x
92 0x43, 0x2E, // 0x2E c
93 0x56, 0x2F, // 0x2F v
94 0x42, 0x30, // 0x30 b
95 0x4E, 0x31, // 0x31 n
96 0x4D, 0x32, // 0x32 m
97 0xBC, 0x33, // 0x33 ,
98 0xBE, 0x34, // 0x34 .
99 0xBF, 0x35, // 0x35 /
100 0x10, 0x36, // 0x36 RShift
101 0x6A, 0x37, // 0x37 * Pad
102 0x12, 0x38, // 0x38 LAlt
103 0x20, 0x39, // 0x39 Space
104 0x14, 0x3A, // 0x3A CapsLk
105 0x70, 0x3B, // 0x3B F1
106 0x71, 0x3C, // 0x3C F2
107 0x72, 0x3D, // 0x3D F3
108 0x73, 0x3E, // 0x3E F4
109 0x74, 0x3F, // 0x3F F5
110 0x75, 0x40, // 0x40 F6
111 0x76, 0x41, // 0x41 F7
112 0x77, 0x42, // 0x42 F8
113 0x78, 0x43, // 0x43 F9
114 0x79, 0x44, // 0x44 F10 (?)
115 0x90, 0x145, // 0x45 NumLk
116 0x91, 0x46, // 0x46 ScrLk
117 0x24, 0x47, // 0x47 7 Pad
118 0x26, 0x48, // 0x48 8 Pad
119 0x21, 0x49, // 0x49 9 Pad
120 0x6D, 0x4A, // 0x4A - Pad
121 0x25, 0x4B, // 0x4B 4 Pad
122 0x0C, 0x4C, // 0x4C 5 Pad
123 0x27, 0x4D, // 0x4D 6 Pad
124 0x6B, 0x4E, // 0x4E + Pad
125 0x23, 0x4F, // 0x4F 1 Pad
126 0x28, 0x50, // 0x50 2 Pad
127 0x22, 0x51, // 0x51 3 Pad
128 0x2D, 0x52, // 0x52 0 Pad
129 0x2E, 0x53, // 0x53 . Pad
130 0, 0, // 0x54
131 0, 0, // 0x55
132 0, 0, // 0x56
133 0x7A, 0x57, // 0x57 F11
134 0x7B, 0x58, // 0x58 F12
135 0, 0, // 0x59
136 0x0D, 0x11C, // 0x5A Enter Pad
137 0x11, 0x11D, // 0x5B RCtrl
138 0x6F, 0x135, // 0x5C / Pad
139 0x2D, 0x152, // 0x5D PrtSc
140 0x12, 0x5E, // 0x5E RAlt
141 0x13, 0x45, // 0x5F Pause
142 0, 0, // 0x60
143 0, 0, // 0x61
144 0, 0, // 0x62
145 0, 0, // 0x63
146 0, 0, // 0x64
147 0, 0, // 0x65
148 0, 0, // 0x66
149 0, 0, // 0x67
150 0, 0, // 0x68
151 0, 0, // 0x69
152 0, 0, // 0x6A
153 0, 0, // 0x6B
154 0x5D, 0x15D, // 0x6C RWin (PM scan 0x7C)
155 0, 0, // 0x6D
156 0x5B, 0x15B, // 0x6E LWin (PM scan 0x7E)
157 0x5C, 0x15C // 0x6F RMenu? (PM scan 0x7F)
158};
159
160//******************************************************************************
161//******************************************************************************
162ULONG GetMouseKeyState()
163{
164 ULONG keystate = 0;
165
166 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) & 0x8000)
167 keystate |= MK_LBUTTON_W;
168 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2) & 0x8000)
169 keystate |= MK_RBUTTON_W;
170 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3) & 0x8000)
171 keystate |= MK_MBUTTON_W;
172 if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT) & 0x8000)
173 keystate |= MK_SHIFT_W;
174 if(WinGetKeyState(HWND_DESKTOP, VK_CTRL) & 0x8000)
175 keystate |= MK_CONTROL_W;
176
177 return keystate;
178}
179//******************************************************************************
180//******************************************************************************
181LONG IsNCMouseMsg(Win32BaseWindow *win32wnd)
182{
183 return ((win32wnd->getLastHitTestVal() != HTCLIENT_W) && (WinQueryCapture(HWND_DESKTOP) != win32wnd->getOS2WindowHandle()));
184}
185//******************************************************************************
186//******************************************************************************
187BOOL OS2ToWinMsgTranslate(void *pTeb, QMSG *os2Msg, MSG *winMsg, BOOL isUnicode, BOOL fMsgRemoved)
188{
189 Win32BaseWindow *win32wnd = 0;
190 OSLIBPOINT point, ClientPoint;
191 POSTMSG_PACKET *packet;
192 TEB *teb = (TEB *)pTeb;
193 BOOL fWasDisabled = FALSE;
194 int i;
195
196 memset(winMsg, 0, sizeof(MSG));
197 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(os2Msg->hwnd);
198
199 //PostThreadMessage posts WIN32APP_POSTMSG msg without window handle
200 //Realplayer starts a timer with hwnd 0 & proc 0; check this here
201 if(win32wnd == 0 && (os2Msg->msg != WM_CREATE && os2Msg->msg != WM_QUIT && os2Msg->msg != WM_TIMER && os2Msg->msg != WIN32APP_POSTMSG))
202 {
203 goto dummymessage; //not a win32 client window
204 }
205 winMsg->time = os2Msg->time;
206 //CB: PM bug or undocumented feature? ptl.x highword is set!
207 winMsg->pt.x = os2Msg->ptl.x & 0xFFFF;
208 winMsg->pt.y = mapScreenY(os2Msg->ptl.y);
209
210 if(win32wnd) //==0 for WM_CREATE/WM_QUIT
211 winMsg->hwnd = win32wnd->getWindowHandle();
212
213 switch(os2Msg->msg)
214 {
215 case WIN32APP_POSTMSG:
216 {
217 packet = (POSTMSG_PACKET *)os2Msg->mp2;
218 if(packet && ((ULONG)os2Msg->mp1 == WIN32MSG_MAGICA || (ULONG)os2Msg->mp1 == WIN32MSG_MAGICW)) {
219 winMsg->message = packet->Msg;
220 winMsg->wParam = packet->wParam;
221 winMsg->lParam = packet->lParam;
222 if(fMsgRemoved == MSG_REMOVE) free(packet); //free the shared memory here
223 break;
224 }
225 goto dummymessage;
226 }
227
228 //OS/2 msgs
229 case WM_CREATE:
230 {
231 if(teb->o.odin.newWindow == 0) {
232 DebugInt3();
233 goto dummymessage;
234 }
235
236 win32wnd = (Win32BaseWindow *)teb->o.odin.newWindow;
237
238 winMsg->message = WINWM_CREATE;
239 winMsg->hwnd = win32wnd->getWindowHandle();
240 winMsg->wParam = 0;
241 winMsg->lParam = (LPARAM)win32wnd->tmpcs;
242 break;
243 }
244
245 case WM_QUIT:
246 winMsg->message = WINWM_QUIT;
247 break;
248
249 case WM_CLOSE:
250 winMsg->message = WINWM_CLOSE;
251 break;
252
253 case WM_DESTROY:
254 winMsg->message = WINWM_DESTROY;
255 break;
256
257 case WM_ENABLE:
258 winMsg->message = WINWM_ENABLE;
259 winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
260 break;
261
262 case WM_SHOW:
263 winMsg->message = WINWM_SHOWWINDOW;
264 winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
265 break;
266
267 case WM_WINDOWPOSCHANGED:
268 {
269 PSWP pswp = (PSWP)os2Msg->mp1;
270 SWP swpOld = *(pswp + 1);
271 HWND hParent = NULLHANDLE;
272 LONG yDelta = pswp->cy - swpOld.cy;
273 LONG xDelta = pswp->cx - swpOld.cx;
274
275 dprintf(("OS2: WM_WINDOWPOSCHANGED %x %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
276
277 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) goto dummymessage;
278
279 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
280 if (win32wnd->isChild()) {
281 if(win32wnd->getParent()) {
282 hParent = win32wnd->getParent()->getOS2WindowHandle();
283 }
284 else goto dummymessage; //parent has just been destroyed
285 }
286 }
287 if(win32wnd->getParent()) {
288 OSLibMapSWPtoWINDOWPOS(pswp, &teb->o.odin.wp, &swpOld, win32wnd->getParent()->getWindowHeight(),
289 win32wnd->getParent()->getClientRectPtr()->left,
290 win32wnd->getParent()->getClientRectPtr()->top,
291 win32wnd->getOS2WindowHandle());
292 }
293 else OSLibMapSWPtoWINDOWPOS(pswp, &teb->o.odin.wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, win32wnd->getOS2WindowHandle());
294
295 if (!win32wnd->CanReceiveSizeMsgs()) goto dummymessage;
296
297 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
298///// dprintf(("Set client rectangle to (%d,%d)(%d,%d)", swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy));
299///// win32wnd->setClientRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
300
301 teb->o.odin.wp.hwnd = win32wnd->getWindowHandle();
302 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
303 {
304 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
305 if(wndAfter)
306 teb->o.odin.wp.hwndInsertAfter = wndAfter->getWindowHandle();
307 else teb->o.odin.wp.hwndInsertAfter = HWND_TOP_W;
308 }
309 }
310 winMsg->message = WINWM_WINDOWPOSCHANGED;
311 winMsg->lParam = (LPARAM)&teb->o.odin.wp;
312 break;
313 }
314
315 case WM_ACTIVATE:
316 {
317 HWND hwndActivate = (HWND)os2Msg->mp2;
318 BOOL fMinimized = FALSE;
319
320 hwndActivate = OS2ToWin32Handle(hwndActivate);
321 if(hwndActivate == 0) {
322 //another (non-win32) application's window
323 //set to desktop window handle
324 hwndActivate = windowDesktop->getWindowHandle();
325 }
326
327 if(win32wnd->getStyle() & WS_MINIMIZE_W)
328 {
329 fMinimized = TRUE;
330 }
331
332 winMsg->message = WINWM_ACTIVATE;
333 winMsg->wParam = MAKELONG((SHORT1FROMMP(os2Msg->mp1)) ? WA_ACTIVE_W : WA_INACTIVE_W, fMinimized);
334 winMsg->lParam = (LPARAM)hwndActivate;
335 break;
336 }
337
338 case WM_SETFOCUS:
339 {
340 HWND hwndFocus = (HWND)os2Msg->mp1;
341
342 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
343 //another (non-win32) application's window
344 //set to NULL (allowed according to win32 SDK) to avoid problems
345 hwndFocus = NULL;
346 }
347 else hwndFocus = OS2ToWin32Handle(hwndFocus);
348
349 if((ULONG)os2Msg->mp2 == TRUE) {
350 winMsg->message = WINWM_SETFOCUS;
351 winMsg->wParam = (WPARAM)hwndFocus;
352 }
353 else {
354 winMsg->message = WINWM_KILLFOCUS;
355 winMsg->wParam = (WPARAM)hwndFocus;
356 }
357 break;
358 }
359
360 //**************************************************************************
361 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
362 //**************************************************************************
363#ifndef ODIN_HITTEST
364 case WM_HITTEST:
365 winMsg->message = WINWM_NCHITTEST;
366 winMsg->wParam = 0;
367 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
368 if(!win32wnd->IsWindowEnabled()) {
369 if(win32wnd->getParent()) {
370 winMsg->hwnd = win32wnd->getParent()->getWindowHandle();
371 }
372 else goto dummymessage; //don't send mouse messages to disabled windows
373 }
374 break;
375#endif
376
377 case WM_BUTTON1DOWN:
378 case WM_BUTTON1UP:
379 case WM_BUTTON1DBLCLK:
380 case WM_BUTTON2DOWN:
381 case WM_BUTTON2UP:
382 case WM_BUTTON2DBLCLK:
383 case WM_BUTTON3DOWN:
384 case WM_BUTTON3UP:
385 case WM_BUTTON3DBLCLK:
386 {
387 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
388
389#ifdef ODIN_HITTEST
390 HWND hwnd;
391
392 DisableLogging();
393 hwnd = WindowFromPoint(winMsg->pt);
394 if(win32wnd->getWindowHandle() != hwnd) {
395 win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
396 if(win32wnd == NULL) {
397 DebugInt3();
398 EnableLogging();
399 goto dummymessage;
400 }
401 winMsg->hwnd = hwnd;
402 }
403#endif
404
405 //if a window is disabled, it's parent receives the mouse messages
406 if(!win32wnd->IsWindowEnabled()) {
407 if(win32wnd->getParent()) {
408 win32wnd = win32wnd->getParent();
409 }
410 fWasDisabled = TRUE;
411 }
412
413 if(IsNCMouseMsg(win32wnd)) {
414 winMsg->message = WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
415 winMsg->wParam = win32wnd->getLastHitTestVal();
416 winMsg->lParam = MAKELONG(winMsg->pt.x, winMsg->pt.y); //screen coordinates
417 }
418 else {
419#ifdef ODIN_HITTEST
420 ClientPoint.x = winMsg->pt.x;
421 ClientPoint.y = winMsg->pt.y;
422 MapWindowPoints(0, win32wnd->getWindowHandle(), (LPPOINT)&ClientPoint, 1);
423#else
424 point.x = (*(POINTS *)&os2Msg->mp1).x;
425 point.y = (*(POINTS *)&os2Msg->mp1).y;
426 ClientPoint.x = mapOS2ToWin32X(win32wnd, point.x);
427 ClientPoint.y = mapOS2ToWin32Y(win32wnd, point.y);
428#endif
429 winMsg->message = WINWM_LBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
430 winMsg->wParam = GetMouseKeyState();
431 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
432 }
433#ifdef ODIN_HITTEST
434 EnableLogging();
435#endif
436 if((fMsgRemoved == MSG_REMOVE) && ISMOUSE_CAPTURED())
437 {
438 if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y)) {
439 goto dummymessage; //dinput swallowed message
440 }
441 }
442
443 if(fWasDisabled) {
444 if(win32wnd) {
445 winMsg->hwnd = win32wnd->getWindowHandle();
446 }
447 else goto dummymessage; //don't send mouse messages to disabled windows
448 }
449 break;
450 }
451
452 case WM_BUTTON2CLICK:
453 case WM_BUTTON1CLICK:
454 case WM_BUTTON3CLICK:
455 goto dummymessage;
456
457 case WM_BUTTON2MOTIONSTART:
458 case WM_BUTTON2MOTIONEND:
459 case WM_BUTTON1MOTIONSTART:
460 case WM_BUTTON1MOTIONEND:
461 case WM_BUTTON3MOTIONSTART:
462 case WM_BUTTON3MOTIONEND:
463 //no break; translate to WM_MOUSEMOVE
464 //Some applications (e.g. Unreal) retrieve all mouse messages
465 //when a mouse button is pressed and don't expect WM_NULL
466
467 case WM_MOUSEMOVE:
468 {
469 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
470
471#ifdef ODIN_HITTEST
472 HWND hwnd;
473
474 DisableLogging();
475 hwnd = WindowFromPoint(winMsg->pt);
476 if(win32wnd->getWindowHandle() != hwnd) {
477 win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
478 if(win32wnd == NULL) {
479 DebugInt3();
480 EnableLogging();
481 goto dummymessage;
482 }
483 winMsg->hwnd = hwnd;
484 }
485#endif
486
487 //if a window is disabled, it's parent receives the mouse messages
488 if(!win32wnd->IsWindowEnabled()) {
489 if(win32wnd->getParent()) {
490 win32wnd = win32wnd->getParent();
491 }
492 fWasDisabled = TRUE;
493 }
494 if(IsNCMouseMsg(win32wnd))
495 {
496 winMsg->message = WINWM_NCMOUSEMOVE;
497 winMsg->wParam = (WPARAM)win32wnd->getLastHitTestVal();
498 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
499 }
500 else
501 {
502#ifdef ODIN_HITTEST
503 ClientPoint.x = winMsg->pt.x;
504 ClientPoint.y = winMsg->pt.y;
505 MapWindowPoints(0, win32wnd->getWindowHandle(), (LPPOINT)&ClientPoint, 1);
506#else
507 point.x = (*(POINTS *)&os2Msg->mp1).x;
508 point.y = (*(POINTS *)&os2Msg->mp1).y;
509 ClientPoint.x = mapOS2ToWin32X(win32wnd, point.x);
510 ClientPoint.y = mapOS2ToWin32Y(win32wnd, point.y);
511#endif
512
513 winMsg->message = WINWM_MOUSEMOVE;
514 winMsg->wParam = GetMouseKeyState();
515 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
516 }
517#ifdef ODIN_HITTEST
518 EnableLogging();
519#endif
520 if((fMsgRemoved == MSG_REMOVE) && ISMOUSE_CAPTURED())
521 {
522 if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y)) {
523 goto dummymessage; //dinput swallowed message
524 }
525 }
526 if(fWasDisabled) {
527 if(win32wnd) {
528 winMsg->hwnd = win32wnd->getWindowHandle();
529 }
530 else goto dummymessage; //don't send mouse messages to disabled windows
531 }
532 //OS/2 Window coordinates -> Win32 Window coordinates
533 break;
534 }
535
536 case WM_CONTROL:
537 goto dummymessage;
538
539 case WM_COMMAND:
540 if(SHORT1FROMMP(os2Msg->mp2) == CMDSRC_MENU) {
541 winMsg->message = WINWM_COMMAND;
542 winMsg->wParam = (WPARAM)SHORT1FROMMP(os2Msg->mp1); //id
543 break;
544 }
545 //todo controls
546 goto dummymessage;
547
548 case WM_SYSCOMMAND:
549 {
550 ULONG x = 0, y = 0;
551 ULONG win32sc;
552
553 if(SHORT2FROMMP(os2Msg->mp2) == TRUE) {//syscommand caused by mouse action
554 POINTL pointl;
555 WinQueryPointerPos(HWND_DESKTOP, &pointl);
556 x = pointl.x;
557 y = mapScreenY(y);
558 }
559 switch(SHORT1FROMMP(os2Msg->mp1)) {
560 case SC_MOVE:
561 win32sc = SC_MOVE_W;
562 break;
563 case SC_CLOSE:
564 win32sc = SC_CLOSE_W;
565 break;
566 case SC_MAXIMIZE:
567 win32sc = SC_MAXIMIZE_W;
568 break;
569 case SC_MINIMIZE:
570 win32sc = SC_MINIMIZE_W;
571 break;
572 case SC_NEXTFRAME:
573 case SC_NEXTWINDOW:
574 win32sc = SC_NEXTWINDOW_W;
575 break;
576 case SC_RESTORE:
577 win32sc = SC_RESTORE_W;
578 break;
579 case SC_TASKMANAGER:
580 win32sc = SC_TASKLIST_W;
581 break;
582 default:
583 goto dummymessage;
584 }
585 winMsg->message = WINWM_SYSCOMMAND;
586 winMsg->wParam = (WPARAM)win32sc;
587 winMsg->lParam = MAKELONG((USHORT)x, (USHORT)y);
588 break;
589 }
590 case WM_CHAR:
591 {
592 ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
593 ULONG flags = SHORT1FROMMP(os2Msg->mp1);
594 BOOL keyWasPressed, isExtended = FALSE;
595 char c;
596
597 teb->o.odin.fTranslated = FALSE;
598 repeatCount = CHAR3FROMMP(os2Msg->mp1);
599 scanCode = CHAR4FROMMP(os2Msg->mp1);
600 keyWasPressed = ((SHORT1FROMMP (os2Msg->mp1) & KC_PREVDOWN) == KC_PREVDOWN);
601
602 dprintf(("PM: WM_CHAR: %x %x %d %x", SHORT1FROMMP(os2Msg->mp2), SHORT2FROMMP(os2Msg->mp2), repeatCount, scanCode));
603 dprintf(("PM: WM_CHAR: hwnd %x flags %x", win32wnd->getWindowHandle(), flags));
604
605 // vitali add begin
606 if ( ( SHORT1FROMMP(os2Msg->mp2) & 0x0FF ) == 0x0E0 )
607 {
608 // an extended key ( arrows, ins, del and so on )
609 // get "virtual" scancode from character code because
610 // for "regular" keys they are equal
611 scanCode = ( SHORT1FROMMP(os2Msg->mp2) >> 8) & 0x0FF;
612 isExtended = TRUE;
613 }
614 // vitali add end
615
616 // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key
617 // given the OS/2 virtual key and OS/2 character
618
619 //if (((SHORT1FROMMP (mp1) & KC_CHAR) == KC_CHAR) ||
620 // ((SHORT1FROMMP (mp1) & KC_LONEKEY) == KC_LONEKEY))
621 c = 0;
622 if ((SHORT1FROMMP (os2Msg->mp1) & 0xFF) != 0)
623 {
624 c = SHORT1FROMMP (os2Msg->mp2);
625 if ((c >= 'A') && (c <= 'Z')) {
626 virtualKey = c;
627 goto VirtualKeyFound;
628 }
629 if ((c >='a') && (c <= 'z')) {
630 virtualKey = c - 32; // make it uppercase
631 goto VirtualKeyFound;
632 }
633 if ((c >= '0') && (c <= '9')) {
634 virtualKey = c;
635 goto VirtualKeyFound;
636 }
637 }
638
639VirtualKeyFound:
640// dprintf (("VIRTUALKEYFOUND:(%x)", virtualKey));
641
642 // Adjust PM scancodes for Win* keys
643 if (scanCode >= 0x70)
644 scanCode -= 0x10;
645 winMsg->wParam = pmscan2winkey[scanCode][0];
646 winMsg->lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
647 winMsg->lParam |= (pmscan2winkey[scanCode][1] & 0x1FF) << 16; // bit 16-23, scancode + bit 15 extended
648
649 // Adjust VKEY value for pad digits if NumLock is on
650 if ((scanCode >= 0x47) && (scanCode <= 0x53) &&
651 (virtualKey >= 0x30) && (virtualKey >= 39))
652 winMsg->wParam = virtualKey + 0x30;
653
654 // Set the extended bit when appropriate
655 if (isExtended)
656 winMsg->lParam = winMsg->lParam | (1<<24);
657
658 if (!(SHORT1FROMMP(os2Msg->mp1) & KC_ALT))
659 {
660 //
661 // the Alt key is not pressed
662 //
663 if ((flags & KC_KEYUP) == KC_KEYUP) {
664 // send WM_KEYUP message
665
666 winMsg->message = WINWM_KEYUP;
667 winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
668 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
669 }
670 else {
671 // send WM_KEYDOWN message
672 winMsg->message = WINWM_KEYDOWN;
673 if (keyWasPressed)
674 winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
675 }
676 }
677 else {
678 //
679 // the Alt key is pressed
680 //
681 if ((flags & KC_KEYUP) == KC_KEYUP) {
682 // send WM_SYSKEYUP message
683
684 winMsg->message = WINWM_SYSKEYUP;
685 winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
686 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
687 }
688 else {
689 // send WM_SYSKEYDOWN message
690 winMsg->message = WINWM_SYSKEYDOWN;
691 if (keyWasPressed)
692 winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
693 }
694 if(winMsg->wParam == VK_MENU_W) {
695 winMsg->message = 0; //WM_SYS* already implies Alt
696 }
697 }
698 if (ISKDB_CAPTURED())
699 {
700 if (DInputKeyBoardHandler(winMsg)) {
701 goto dummymessage; //dinput swallowed message
702 }
703 }
704 break;
705 }
706
707 case WM_TIMER:
708 if (os2Msg->mp2)
709 {
710 BOOL sys;
711 ULONG id;
712
713 if (TIMER_GetTimerInfo(os2Msg->hwnd,(ULONG)os2Msg->mp1,&sys,&id))
714 {
715 winMsg->wParam = (WPARAM)id;
716 winMsg->message= (sys) ? WINWM_SYSTIMER : WINWM_TIMER;
717 break;
718 }
719 }
720 goto dummymessage; //for caret blinking
721
722 case WM_SETWINDOWPARAMS:
723 {
724 WNDPARAMS *wndParams = (WNDPARAMS *)os2Msg->mp1;
725
726 if(wndParams->fsStatus & WPM_TEXT) {
727 winMsg->message = WINWM_SETTEXT;
728 winMsg->lParam = (LPARAM)wndParams->pszText;
729 break;
730 }
731 goto dummymessage;
732 }
733
734#if 0
735 case WM_QUERYWINDOWPARAMS:
736 {
737 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
738 ULONG textlen;
739 PSZ wintext;
740
741 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
742 {
743 if(wndpars->fsStatus & WPM_CCHTEXT)
744 wndpars->cchText = win32wnd->MsgGetTextLength();
745 if(wndpars->fsStatus & WPM_TEXT)
746 wndpars->pszText = win32wnd->MsgGetText();
747
748 wndpars->fsStatus = 0;
749 wndpars->cbCtlData = 0;
750 wndpars->cbPresParams = 0;
751 goto dummymessage;
752 }
753 }
754#endif
755
756 case WM_PAINT:
757 {
758 if(win32wnd->IsWindowIconic()) {
759 winMsg->message = WINWM_PAINTICON;
760 }
761 else winMsg->message = WINWM_PAINT;
762 break;
763 }
764
765 case WM_CONTEXTMENU:
766 winMsg->message = WINWM_CONTEXTMENU;
767 winMsg->wParam = win32wnd->getWindowHandle();
768 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
769 break;
770
771 case WM_RENDERFMT:
772 winMsg->message = WINWM_RENDERFORMAT;
773 winMsg->wParam = (UINT) os2Msg->mp1;
774 break;
775
776 case WM_RENDERALLFMTS:
777 winMsg->message = WINWM_RENDERALLFORMATS;
778 break;
779
780 case WM_DESTROYCLIPBOARD:
781 winMsg->message = WINWM_DESTROYCLIPBOARD;
782 break;
783
784 case WM_INITMENU:
785 case WM_MENUSELECT:
786 case WM_MENUEND:
787 case WM_NEXTMENU:
788 case WM_SYSCOLORCHANGE:
789 case WM_SYSVALUECHANGED:
790 case WM_SETSELECTION:
791 case WM_PPAINT:
792 case WM_PSETFOCUS:
793 case WM_PSYSCOLORCHANGE:
794 case WM_PSIZE:
795 case WM_PACTIVATE:
796 case WM_PCONTROL:
797 case WM_HELP:
798 case WM_APPTERMINATENOTIFY:
799 case WM_PRESPARAMCHANGED:
800 case WM_DRAWITEM:
801 case WM_MEASUREITEM:
802 case WM_CONTROLPOINTER:
803 case WM_QUERYDLGCODE:
804 case WM_SUBSTITUTESTRING:
805 case WM_MATCHMNEMONIC:
806 case WM_SAVEAPPLICATION:
807 case WM_SEMANTICEVENT:
808 default:
809dummymessage:
810 winMsg->message = 0;
811 winMsg->wParam = 0;
812 winMsg->lParam = 0;
813 return FALSE;
814 }
815 return TRUE;
816}
817//******************************************************************************
818//******************************************************************************
819BOOL OSLibWinTranslateMessage(MSG *msg)
820{
821 TEB *teb;
822
823 teb = GetThreadTEB();
824 if(!teb) {
825 return FALSE;
826 }
827 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
828 // the newly generated WM_CHAR message.
829 if(!teb->o.odin.fTranslated && teb->o.odin.os2msg.msg == WM_CHAR && !((SHORT1FROMMP(teb->o.odin.os2msg.mp1) & KC_KEYUP) == KC_KEYUP))
830 {//TranslatedMessage was called before DispatchMessage, so queue WM_CHAR message
831 ULONG fl = SHORT1FROMMP(teb->o.odin.os2msg.mp1);
832 MSG extramsg;
833
834 memcpy(&extramsg, msg, sizeof(MSG));
835 extramsg.wParam = SHORT1FROMMP(teb->o.odin.os2msg.mp2);
836 extramsg.lParam = 0;
837
838 if(!(fl & KC_CHAR) && msg->message < WINWM_SYSKEYDOWN) {
839 return FALSE;
840 }
841
842 if(fl & KC_VIRTUALKEY) {
843 if(msg->wParam) {
844 if ((msg->wParam >= VK_NUMPAD0_W) && (msg->wParam <= VK_NUMPAD9_W))
845 extramsg.wParam = msg->wParam - 0x30;
846 else
847 extramsg.wParam = msg->wParam;
848 }
849 else extramsg.wParam = SHORT2FROMMP(teb->o.odin.os2msg.mp2);
850 }
851
852
853 if(msg->message >= WINWM_SYSKEYDOWN) {
854 extramsg.message = WINWM_SYSCHAR;
855 }
856 else extramsg.message = WINWM_CHAR;
857
858 if(fl & KC_DEADKEY) {
859 extramsg.message++; //WM_DEADCHAR/WM_SYSDEADCHAR
860 }
861
862 extramsg.lParam = msg->lParam & 0x00FFFFFF;
863 if(fl & KC_ALT)
864 extramsg.lParam |= (1<<29);
865 if(fl & KC_PREVDOWN)
866 extramsg.lParam |= (1<<30);
867 if(fl & KC_KEYUP)
868 extramsg.lParam |= (1<<31);
869
870 teb->o.odin.fTranslated = TRUE;
871 memcpy(&teb->o.odin.msgWCHAR, &extramsg, sizeof(MSG));
872 return TRUE;
873 }
874 return FALSE;
875}
876//******************************************************************************
877//******************************************************************************
878
Note: See TracBrowser for help on using the repository browser.