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

Last change on this file since 3306 was 3306, checked in by cbratschi, 25 years ago

* empty log message *

File size: 29.0 KB
Line 
1/* $Id: oslibmsgtranslate.cpp,v 1.27 2000-04-02 15:11:50 cbratschi 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 "oslibmsg.h"
25#include "win32wnd.h"
26#include "win32wdesktop.h"
27#include "oslibutil.h"
28#include "timer.h"
29#include <thread.h>
30#include <wprocess.h>
31#include "pmwindow.h"
32#include "oslibwin.h"
33#include "winmouse.h"
34
35#define DBG_LOCALLOG DBG_oslibmsgtranslate
36#include "dbglocal.h"
37
38//Used for key translation while processing WM_CHAR message
39USHORT virtualKeyTable [66] = {
40 0x00, // OS/2 VK Win32 VK, Entry 0 is not used
41 0x01, // VK_BUTTON1 VK_LBUTTON
42 0x02, // VK_BUTTON2 VK_RBUTTON
43 0x04, // VK_BUTTON3 VK_MBUTTON
44 0x03, // VK_BREAK VK_CANCEL
45 0x08, // VK_BACKSPACE VK_BACK
46 0x09, // VK_TAB VK_TAB
47 0x00, // VK_BACKTAB No equivalent!
48 0x0D, // VK_NEWLINE VK_RETURN
49 0x10, // VK_SHIFT VK_SHIFT
50 0x11, // VK_CTRL VK_CONTROL
51 0x12, // VK_ALT VK_MENU, best match I guess
52 0x12, // VK_ALTGRAF VK_MENU, best match I guess
53 0x13, // VK_PAUSE VK_PAUSE
54 0x14, // VK_CAPSLOCK VK_CAPITAL
55 0x1B, // VK_ESC VK_ESCAPE
56 0x20, // VK_SPACE VK_SPACE
57 0x21, // VK_PAGEUP VK_PRIOR
58 0x22, // VK_PAGEDOWN VK_NEXT
59 0x23, // VK_END VK_END
60 0x24, // VK_HOME VK_HOME
61 0x25, // VK_LEFT VK_LEFT
62 0x26, // VK_UP VK_UP
63 0x27, // VK_RIGHT VK_RIGHT
64 0x28, // VK_DOWN VK_DOWN
65 0x2C, // VK_PRINTSCRN VK_SNAPSHOT
66 0x2D, // VK_INSERT VK_INSERT
67 0x2E, // VK_DELETE VK_DELETE
68 0x91, // VK_SCRLLOCK VK_SCROLL
69 0x90, // VK_NUMLOCK VK_NUMLOCK
70 0x0D, // VK_ENTER VK_RETURN
71 0x00, // VK_SYSRQ No equivalent!
72 0x70, // VK_F1 VK_F1
73 0x71, // VK_F2 VK_F2
74 0x72, // VK_F3 VK_F3
75 0x73, // VK_F4 VK_F4
76 0x74, // VK_F5 VK_F5
77 0x75, // VK_F6 VK_F6
78 0x76, // VK_F7 VK_F7
79 0x77, // VK_F8 VK_F8
80 0x78, // VK_F9 VK_F9
81 0x79, // VK_F10 VK_F10
82 0x7A, // VK_F11 VK_F11
83 0x7B, // VK_F12 VK_F12
84 0x7C, // VK_F13 VK_F13
85 0x7D, // VK_F14 VK_F14
86 0x7E, // VK_F15 VK_F15
87 0x7F, // VK_F16 VK_F16
88 0x80, // VK_F17 VK_F17
89 0x81, // VK_F18 VK_F18
90 0x82, // VK_F19 VK_F19
91 0x83, // VK_F20 VK_F20
92 0x84, // VK_F21 VK_F21
93 0x85, // VK_F22 VK_F22
94 0x86, // VK_F23 VK_F23
95 0x87, // VK_F24 VK_F24
96 0x00, // VK_ENDDRAG No equivalent!
97 0x0C, // VK_CLEAR VK_CLEAR
98 0xF9, // VK_EREOF VK_EREOF
99 0xFD, // VK_PA1 VK_PA1
100 0xF6, // VK_ATTN VK_ATTN
101 0xF7, // VK_CRSEL VK_CRSEL
102 0xF8, // VK_EXSEL VK_EXSEL
103 0x00, // VK_COPY No equivalent!
104 0x00, // VK_BLK1 No equivalent!
105 0x00}; // VK_BLK2 No equivalent!
106
107//******************************************************************************
108//******************************************************************************
109ULONG GetMouseKeyState()
110{
111 ULONG keystate = 0;
112
113 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) & 0x8000)
114 keystate |= MK_LBUTTON_W;
115 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2) & 0x8000)
116 keystate |= MK_RBUTTON_W;
117 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3) & 0x8000)
118 keystate |= MK_MBUTTON_W;
119 if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT) & 0x8000)
120 keystate |= MK_SHIFT_W;
121 if(WinGetKeyState(HWND_DESKTOP, VK_CTRL) & 0x8000)
122 keystate |= MK_CONTROL_W;
123
124 return keystate;
125}
126//******************************************************************************
127//******************************************************************************
128LONG IsNCMouseMsg(Win32BaseWindow *win32wnd)
129{
130 return ((win32wnd->getLastHitTestVal() != HTCLIENT_W) && (WinQueryCapture(HWND_DESKTOP) != win32wnd->getOS2WindowHandle()));
131}
132//******************************************************************************
133//******************************************************************************
134BOOL OS2ToWinMsgTranslate(void *pThdb, QMSG *os2Msg, MSG *winMsg, BOOL isUnicode, BOOL fMsgRemoved)
135{
136 Win32BaseWindow *win32wnd = 0;
137 OSLIBPOINT point, ClientPoint;
138 POSTMSG_PACKET *packet;
139 THDB *thdb = (THDB *)pThdb;
140 int i;
141
142 memset(winMsg, 0, sizeof(MSG));
143 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(os2Msg->hwnd);
144 if (!win32wnd) win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(os2Msg->hwnd);
145
146 //PostThreadMessage posts WIN32APP_POSTMSG msg without window handle
147 //Realplayer starts a timer with hwnd 0 & proc 0; check this here
148 if(win32wnd == 0 && (os2Msg->msg != WM_CREATE && os2Msg->msg != WM_QUIT && os2Msg->msg != WM_TIMER && os2Msg->msg != WIN32APP_POSTMSG))
149 {
150 goto dummymessage; //not a win32 client window
151 }
152 winMsg->time = os2Msg->time;
153 //CB: PM bug or undocumented feature? ptl.x highword is set!
154 winMsg->pt.x = os2Msg->ptl.x & 0xFFFF;
155 winMsg->pt.y = mapScreenY(os2Msg->ptl.y);
156
157 if(win32wnd) //==0 for WM_CREATE/WM_QUIT
158 winMsg->hwnd = win32wnd->getWindowHandle();
159
160 if (win32wnd && (os2Msg->hwnd == win32wnd->getOS2FrameWindowHandle()))
161 {
162 //special frame messages
163
164 switch (os2Msg->msg)
165 {
166 case WM_HITTEST:
167 winMsg->message = WINWM_NCHITTEST;
168 winMsg->wParam = 0;
169 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
170
171 return TRUE;
172
173 case WM_BUTTON1DOWN:
174 case WM_BUTTON1UP:
175 case WM_BUTTON1DBLCLK:
176 case WM_BUTTON2DOWN:
177 case WM_BUTTON2UP:
178 case WM_BUTTON2DBLCLK:
179 case WM_BUTTON3DOWN:
180 case WM_BUTTON3UP:
181 case WM_BUTTON3DBLCLK:
182 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
183
184 if (IsNCMouseMsg(win32wnd)) {
185 winMsg->message = WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
186 winMsg->wParam = win32wnd->getLastHitTestVal();
187 winMsg->lParam = MAKELONG(winMsg->pt.x, winMsg->pt.y); //screen coordinates
188 }
189 else {
190 point.x = (*(POINTS *)&os2Msg->mp1).x;
191 point.y = (*(POINTS *)&os2Msg->mp1).y;
192 ClientPoint.x = point.x;
193 ClientPoint.y = mapOS2ToWin32Y(os2Msg->hwnd,win32wnd->getOS2WindowHandle(),point.y);
194
195 winMsg->message = WINWM_LBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
196 winMsg->wParam = GetMouseKeyState();
197 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
198 }
199 if(ISMOUSE_CAPTURED())
200 {
201 if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y)) {
202 goto dummymessage; //dinput swallowed message
203 }
204 }
205
206 return TRUE;
207
208 case WM_BUTTON2MOTIONSTART:
209 case WM_BUTTON2MOTIONEND:
210 case WM_BUTTON2CLICK:
211 case WM_BUTTON1MOTIONSTART:
212 case WM_BUTTON1MOTIONEND:
213 case WM_BUTTON1CLICK:
214 case WM_BUTTON3MOTIONSTART:
215 case WM_BUTTON3MOTIONEND:
216 case WM_BUTTON3CLICK:
217 goto dummymessage;
218
219 case WM_MOUSEMOVE:
220 {
221 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
222
223 if (IsNCMouseMsg(win32wnd))
224 {
225 winMsg->message = WINWM_NCMOUSEMOVE;
226 winMsg->wParam = (WPARAM)win32wnd->getLastHitTestVal();
227 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
228 }
229 else
230 {
231 winMsg->message = WINWM_MOUSEMOVE;
232 winMsg->wParam = GetMouseKeyState();
233 winMsg->lParam = MAKELONG(SHORT1FROMMP(os2Msg->mp1),mapOS2ToWin32Y(win32wnd->getOS2FrameWindowHandle(),win32wnd->getOS2WindowHandle(),SHORT2FROMMP(os2Msg->mp1)));
234 }
235 if(ISMOUSE_CAPTURED())
236 {
237 if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y)) {
238 goto dummymessage; //dinput swallowed message
239 }
240 }
241 //OS/2 Window coordinates -> Win32 Window coordinates
242 return TRUE;
243 }
244
245 case WM_PAINT:
246 {
247 winMsg->message = WINWM_NCPAINT;
248 return TRUE;
249 }
250
251 case WM_ACTIVATE:
252 {
253 winMsg->message = WINWM_NCACTIVATE;
254 winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
255 return TRUE;
256 }
257 case WM_WINDOWPOSCHANGED:
258 {
259 //todo: proper translation
260 return FALSE;
261 }
262 }
263 //do normal translation for all other messages
264 }
265
266 switch(os2Msg->msg)
267 {
268 case WIN32APP_POSTMSG:
269 {
270 packet = (POSTMSG_PACKET *)os2Msg->mp2;
271 if(packet && ((ULONG)os2Msg->mp1 == WIN32MSG_MAGICA || (ULONG)os2Msg->mp1 == WIN32MSG_MAGICW)) {
272 winMsg->message = packet->Msg;
273 winMsg->wParam = packet->wParam;
274 winMsg->lParam = packet->lParam;
275 if(fMsgRemoved == MSG_REMOVE) free(packet); //free the shared memory here
276 break;
277 }
278 goto dummymessage;
279 }
280
281 //OS/2 msgs
282 case WM_CREATE:
283 {
284 if(thdb->newWindow == 0) {
285 DebugInt3();
286 goto dummymessage;
287 }
288
289 win32wnd = (Win32BaseWindow *)thdb->newWindow;
290
291 winMsg->message = WINWM_CREATE;
292 winMsg->hwnd = win32wnd->getWindowHandle();
293 winMsg->wParam = 0;
294 winMsg->lParam = (LPARAM)win32wnd->tmpcs;
295 break;
296 }
297
298 case WM_QUIT:
299 winMsg->message = WINWM_QUIT;
300 break;
301
302 case WM_CLOSE:
303 winMsg->message = WINWM_CLOSE;
304 break;
305
306 case WM_DESTROY:
307 winMsg->message = WINWM_DESTROY;
308 break;
309
310 case WM_ENABLE:
311 winMsg->message = WINWM_ENABLE;
312 winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
313 break;
314
315 case WM_SHOW:
316 winMsg->message = WINWM_SHOWWINDOW;
317 winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
318 break;
319
320 case WM_WINDOWPOSCHANGED:
321 {
322 PSWP pswp = (PSWP)os2Msg->mp1;
323 SWP swpOld = *(pswp + 1);
324 HWND hParent = NULLHANDLE;
325 LONG yDelta = pswp->cy - swpOld.cy;
326 LONG xDelta = pswp->cx - swpOld.cx;
327
328 dprintf(("OS2: WM_WINDOWPOSCHANGED %x %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
329
330 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) goto dummymessage;
331
332 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
333 if (win32wnd->isChild()) {
334 if(win32wnd->getParent()) {
335 hParent = win32wnd->getParent()->getOS2WindowHandle();
336 }
337 else goto dummymessage; //parent has just been destroyed
338 }
339 }
340 OSLibMapSWPtoWINDOWPOS(pswp, &thdb->wp, &swpOld, hParent, win32wnd->getOS2FrameWindowHandle());
341
342 if (!win32wnd->CanReceiveSizeMsgs()) goto dummymessage;
343
344 ULONG windowStyle = WinQueryWindowULong(os2Msg->hwnd, QWL_STYLE);
345 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MAXIMIZE_W|WS_MINIMIZE_W));
346 if (windowStyle & WS_MINIMIZED) {
347 win32wnd->setStyle(win32wnd->getStyle() | WS_MINIMIZE_W);
348 }
349 else
350 if (windowStyle & WS_MAXIMIZED) {
351 win32wnd->setStyle(win32wnd->getStyle() | WS_MAXIMIZE_W);
352 }
353
354 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
355 dprintf(("Set client rectangle to (%d,%d)(%d,%d)", swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy));
356 win32wnd->setClientRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
357
358 thdb->wp.hwnd = win32wnd->getWindowHandle();
359 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
360 {
361 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
362 if(wndAfter)
363 thdb->wp.hwndInsertAfter = wndAfter->getWindowHandle();
364 }
365
366 PRECT lpRect = win32wnd->getWindowRect();
367 //SvL: Only send it when the client has changed & the frame hasn't
368 // If the frame size/position has changed, pmframe.cpp will send
369 // this message
370 if(lpRect->right == thdb->wp.x+thdb->wp.cx && lpRect->bottom == thdb->wp.y+thdb->wp.cy) {
371 winMsg->message = WINWM_WINDOWPOSCHANGED;
372 winMsg->lParam = (LPARAM)&thdb->wp;
373 break;
374 }
375 }
376 goto dummymessage;
377 }
378
379 case WM_ACTIVATE:
380 {
381 HWND hwndActivate = (HWND)os2Msg->mp2;
382 BOOL fMinimized = FALSE;
383
384 if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
385 //another (non-win32) application's window
386 //set to desktop window handle
387 hwndActivate = windowDesktop->getWindowHandle();
388 }
389 else hwndActivate = Win32BaseWindow::OS2ToWin32Handle(hwndActivate);
390
391 if(WinQueryWindowULong(os2Msg->hwnd, QWL_STYLE) & WS_MINIMIZED)
392 {
393 fMinimized = TRUE;
394 }
395
396 winMsg->message = WINWM_ACTIVATE;
397 winMsg->wParam = MAKELONG((SHORT1FROMMP(os2Msg->mp1)) ? WA_ACTIVE_W : WA_INACTIVE_W, fMinimized);
398 winMsg->lParam = (LPARAM)hwndActivate;
399 break;
400 }
401
402 case WM_SETFOCUS:
403 {
404 HWND hwndFocus = (HWND)os2Msg->mp1;
405
406 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
407 //another (non-win32) application's window
408 //set to NULL (allowed according to win32 SDK) to avoid problems
409 hwndFocus = NULL;
410 }
411 else hwndFocus = Win32BaseWindow::OS2ToWin32Handle(hwndFocus);
412
413 if((ULONG)os2Msg->mp2 == TRUE) {
414 winMsg->message = WINWM_SETFOCUS;
415 winMsg->wParam = (WPARAM)hwndFocus;
416 }
417 else {
418 winMsg->message = WINWM_KILLFOCUS;
419 winMsg->wParam = (WPARAM)hwndFocus;
420 }
421 break;
422 }
423
424 //**************************************************************************
425 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
426 //**************************************************************************
427 case WM_HITTEST:
428 winMsg->message = WINWM_NCHITTEST;
429 winMsg->wParam = 0;
430 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
431 break;
432
433 case WM_BUTTON1DOWN:
434 case WM_BUTTON1UP:
435 case WM_BUTTON1DBLCLK:
436 case WM_BUTTON2DOWN:
437 case WM_BUTTON2UP:
438 case WM_BUTTON2DBLCLK:
439 case WM_BUTTON3DOWN:
440 case WM_BUTTON3UP:
441 case WM_BUTTON3DBLCLK:
442 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
443
444 if(IsNCMouseMsg(win32wnd)) {
445 winMsg->message = WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
446 winMsg->wParam = win32wnd->getLastHitTestVal();
447 winMsg->lParam = MAKELONG(winMsg->pt.x, winMsg->pt.y); //screen coordinates
448 }
449 else {
450 point.x = (*(POINTS *)&os2Msg->mp1).x;
451 point.y = (*(POINTS *)&os2Msg->mp1).y;
452 ClientPoint.x = point.x;
453 ClientPoint.y = mapY(os2Msg->hwnd,point.y);
454
455 winMsg->message = WINWM_LBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
456 winMsg->wParam = GetMouseKeyState();
457 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
458 }
459 if(ISMOUSE_CAPTURED())
460 {
461 if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y)) {
462 goto dummymessage; //dinput swallowed message
463 }
464 }
465
466 break;
467
468 case WM_BUTTON2MOTIONSTART:
469 case WM_BUTTON2MOTIONEND:
470 case WM_BUTTON2CLICK:
471 case WM_BUTTON1MOTIONSTART:
472 case WM_BUTTON1MOTIONEND:
473 case WM_BUTTON1CLICK:
474 case WM_BUTTON3MOTIONSTART:
475 case WM_BUTTON3MOTIONEND:
476 case WM_BUTTON3CLICK:
477 goto dummymessage;
478
479 case WM_MOUSEMOVE:
480 {
481 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
482
483 if(IsNCMouseMsg(win32wnd))
484 {
485 winMsg->message = WINWM_NCMOUSEMOVE;
486 winMsg->wParam = (WPARAM)win32wnd->getLastHitTestVal();
487 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
488 }
489 else
490 {
491 winMsg->message = WINWM_MOUSEMOVE;
492 winMsg->wParam = GetMouseKeyState();
493 winMsg->lParam = MAKELONG(SHORT1FROMMP(os2Msg->mp1),mapY(win32wnd,SHORT2FROMMP(os2Msg->mp1)));
494 }
495 if(ISMOUSE_CAPTURED())
496 {
497 if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y)) {
498 goto dummymessage; //dinput swallowed message
499 }
500 }
501 //OS/2 Window coordinates -> Win32 Window coordinates
502 break;
503 }
504
505 case WM_CONTROL:
506 goto dummymessage;
507
508 case WM_COMMAND:
509 if(SHORT1FROMMP(os2Msg->mp2) == CMDSRC_MENU) {
510 winMsg->message = WINWM_COMMAND;
511 winMsg->wParam = (WPARAM)SHORT1FROMMP(os2Msg->mp1); //id
512 break;
513 }
514 //todo controls
515 goto dummymessage;
516
517 case WM_SYSCOMMAND:
518 {
519 ULONG x = 0, y = 0;
520 ULONG win32sc;
521
522 if(SHORT2FROMMP(os2Msg->mp2) == TRUE) {//syscommand caused by mouse action
523 POINTL pointl;
524 WinQueryPointerPos(HWND_DESKTOP, &pointl);
525 x = pointl.x;
526 y = mapScreenY(y);
527 }
528 switch(SHORT1FROMMP(os2Msg->mp1)) {
529 case SC_MOVE:
530 win32sc = SC_MOVE_W;
531 break;
532 case SC_CLOSE:
533 win32sc = SC_CLOSE_W;
534 break;
535 case SC_MAXIMIZE:
536 win32sc = SC_MAXIMIZE_W;
537 break;
538 case SC_MINIMIZE:
539 win32sc = SC_MINIMIZE_W;
540 break;
541 case SC_NEXTFRAME:
542 case SC_NEXTWINDOW:
543 win32sc = SC_NEXTWINDOW_W;
544 break;
545 case SC_RESTORE:
546 win32sc = SC_RESTORE_W;
547 break;
548 case SC_TASKMANAGER:
549 win32sc = SC_TASKLIST_W;
550 break;
551 default:
552 goto dummymessage;
553 }
554 winMsg->message = WINWM_SYSCOMMAND;
555 winMsg->wParam = (WPARAM)win32sc;
556 winMsg->lParam = MAKELONG((USHORT)x, (USHORT)y);
557 break;
558 }
559 case WM_CHAR:
560 {
561 ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
562 ULONG flags = SHORT1FROMMP(os2Msg->mp1);
563 BOOL keyWasPressed;
564 char c;
565
566 thdb->fTranslated = FALSE;
567 repeatCount = CHAR3FROMMP(os2Msg->mp1);
568 scanCode = CHAR4FROMMP(os2Msg->mp1);
569 keyWasPressed = ((SHORT1FROMMP (os2Msg->mp1) & KC_PREVDOWN) == KC_PREVDOWN);
570
571 dprintf(("PM: WM_CHAR: %x %x %d %x", SHORT1FROMMP(os2Msg->mp2), SHORT2FROMMP(os2Msg->mp2), repeatCount, scanCode));
572 dprintf(("PM: WM_CHAR: %x", flags));
573
574 // vitali add begin
575 if ( ( SHORT1FROMMP(os2Msg->mp2) & 0x0FF ) == 0x0E0 )
576 {
577 // an extended key ( arrows, ins, del and so on )
578 // get "virtual" scancode from character code cause
579 // for "regular" keys they are equal
580 scanCode = ( SHORT1FROMMP(os2Msg->mp2) >> 8) & 0x0FF;
581 }
582 // vitali add end
583
584 // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key
585 // given the OS/2 virtual key and OS/2 character
586
587 //if (((SHORT1FROMMP (mp1) & KC_CHAR) == KC_CHAR) ||
588 // ((SHORT1FROMMP (mp1) & KC_LONEKEY) == KC_LONEKEY))
589 c = 0;
590 if ((SHORT1FROMMP (os2Msg->mp1) & 0xFF) != 0)
591 {
592 c = SHORT1FROMMP (os2Msg->mp2);
593 if ((c >= 'A') && (c <= 'Z')) {
594 virtualKey = c;
595 goto VirtualKeyFound;
596 }
597 if ((c >='a') && (c <= 'z')) {
598 virtualKey = c - 32; // make it uppercase
599 goto VirtualKeyFound;
600 }
601 if ((c >= '0') && (c <= '9')) {
602 virtualKey = c;
603 goto VirtualKeyFound;
604 }
605 }
606
607 // convert OS/2 virtual keys to Win32 virtual key
608 if (SHORT2FROMMP (os2Msg->mp2) <= VK_BLK2)
609 virtualKey = virtualKeyTable [SHORT2FROMMP (os2Msg->mp2)];
610
611VirtualKeyFound:
612 dprintf (("VIRTUALKEYFOUND:(%x)", virtualKey));
613
614 winMsg->wParam = virtualKey;
615 winMsg->lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
616 winMsg->lParam |= (scanCode & 0x0FF) << 16; // bit 16-23, scancode
617
618 //TODO: Is this correct and complete? (how does PM differentiate between
619 // i.e numeric pad pgdn & 'normal' pgdn??)
620 //Check if it's an extended key
621 switch(virtualKey) {
622 case VK_RETURN_W:
623 //The enter key on the numeric keypad is an extended key
624 if(SHORT2FROMMP(os2Msg->mp2) != VK_NEWLINE)
625 break;
626 //no break
627 case VK_LEFT_W:
628 case VK_RIGHT_W:
629 case VK_DOWN_W:
630 case VK_UP_W:
631 case VK_PRIOR_W:
632 case VK_NEXT_W:
633 case VK_END_W:
634 case VK_DIVIDE_W:
635 case VK_DELETE_W:
636 case VK_HOME_W:
637 case VK_INSERT_W:
638 case VK_RCONTROL_W:
639 case VK_RMENU_W: //is this the right alt???
640 winMsg->lParam = winMsg->lParam | (1<<24);
641 break;
642 }
643
644 if(!(SHORT1FROMMP(os2Msg->mp1) & KC_ALT))
645 {
646 //
647 // the Alt key is not pressed
648 //
649 if ((flags & KC_KEYUP) == KC_KEYUP) {
650 // send WM_KEYUP message
651
652 winMsg->message = WINWM_KEYUP;
653 winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
654 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
655 }
656 else {
657 // send WM_KEYDOWN message
658 winMsg->message = WINWM_KEYDOWN;
659 if (keyWasPressed)
660 winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
661 }
662 }
663 else {
664 //
665 // the Alt key is pressed
666 //
667 if ((flags & KC_KEYUP) == KC_KEYUP) {
668 // send WM_SYSKEYUP message
669
670 winMsg->message = WINWM_SYSKEYUP;
671 winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
672 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
673 }
674 else {
675 // send WM_SYSKEYDOWN message
676 winMsg->message = WINWM_SYSKEYDOWN;
677 if (keyWasPressed)
678 winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
679 }
680 }
681 if(ISKDB_CAPTURED())
682 {
683 if(DInputKeyBoardHandler(winMsg)) {
684 goto dummymessage; //dinput swallowed message
685 }
686 }
687 break;
688 }
689
690 case WM_TIMER:
691 if (os2Msg->mp2)
692 {
693 BOOL sys;
694 ULONG id;
695
696 if (TIMER_GetTimerInfo(os2Msg->hwnd,(ULONG)os2Msg->mp1,&sys,&id))
697 {
698 winMsg->wParam = (WPARAM)id;
699 winMsg->message= (sys) ? WINWM_SYSTIMER : WINWM_TIMER;
700 break;
701 }
702 }
703 goto dummymessage; //for caret blinking
704
705 case WM_SETWINDOWPARAMS:
706 {
707 WNDPARAMS *wndParams = (WNDPARAMS *)os2Msg->mp1;
708
709 if(wndParams->fsStatus & WPM_TEXT) {
710 winMsg->message = WINWM_SETTEXT;
711 winMsg->lParam = (LPARAM)wndParams->pszText;
712 break;
713 }
714 goto dummymessage;
715 }
716
717#if 0
718 case WM_QUERYWINDOWPARAMS:
719 {
720 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
721 ULONG textlen;
722 PSZ wintext;
723
724 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
725 {
726 if(wndpars->fsStatus & WPM_CCHTEXT)
727 wndpars->cchText = win32wnd->MsgGetTextLength();
728 if(wndpars->fsStatus & WPM_TEXT)
729 wndpars->pszText = win32wnd->MsgGetText();
730
731 wndpars->fsStatus = 0;
732 wndpars->cbCtlData = 0;
733 wndpars->cbPresParams = 0;
734 goto dummymessage;
735 }
736 }
737#endif
738
739 case WM_PAINT:
740 {
741 if(win32wnd->IsWindowIconic()) {
742 winMsg->message = WINWM_PAINTICON;
743 }
744 else winMsg->message = WINWM_PAINT;
745 break;
746 }
747
748 case WM_CONTEXTMENU:
749 winMsg->message = WINWM_CONTEXTMENU;
750 winMsg->wParam = win32wnd->getWindowHandle();
751 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
752 break;
753
754 case WM_INITMENU:
755 case WM_MENUSELECT:
756 case WM_MENUEND:
757 case WM_NEXTMENU:
758 case WM_SYSCOLORCHANGE:
759 case WM_SYSVALUECHANGED:
760 case WM_SETSELECTION:
761 case WM_PPAINT:
762 case WM_PSETFOCUS:
763 case WM_PSYSCOLORCHANGE:
764 case WM_PSIZE:
765 case WM_PACTIVATE:
766 case WM_PCONTROL:
767 case WM_HELP:
768 case WM_APPTERMINATENOTIFY:
769 case WM_PRESPARAMCHANGED:
770 case WM_DRAWITEM:
771 case WM_MEASUREITEM:
772 case WM_CONTROLPOINTER:
773 case WM_QUERYDLGCODE:
774 case WM_SUBSTITUTESTRING:
775 case WM_MATCHMNEMONIC:
776 case WM_SAVEAPPLICATION:
777 case WM_SEMANTICEVENT:
778 default:
779dummymessage:
780 winMsg->message = 0;
781 winMsg->wParam = 0;
782 winMsg->lParam = 0;
783 return FALSE;
784 }
785 return TRUE;
786}
787//******************************************************************************
788//******************************************************************************
789BOOL OSLibWinTranslateMessage(MSG *msg)
790{
791 THDB *thdb;
792
793 thdb = GetThreadTHDB();
794 if(!thdb) {
795 return FALSE;
796 }
797 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
798 // the newly generated WM_CHAR message.
799 if(!thdb->fTranslated && MsgThreadPtr->msg == WM_CHAR && !((SHORT1FROMMP(MsgThreadPtr->mp1) & KC_KEYUP) == KC_KEYUP))
800 {//TranslatedMessage was called before DispatchMessage, so queue WM_CHAR message
801 ULONG fl = SHORT1FROMMP(MsgThreadPtr->mp1);
802 MSG extramsg;
803
804 memcpy(&extramsg, msg, sizeof(MSG));
805 extramsg.wParam = SHORT1FROMMP(MsgThreadPtr->mp2);
806 extramsg.lParam = 0;
807
808 if(!(fl & KC_CHAR)) {
809 return FALSE;
810 }
811
812 if(fl & KC_VIRTUALKEY) {
813 if(msg->wParam)
814 extramsg.wParam = msg->wParam;
815 else extramsg.wParam = SHORT2FROMMP(MsgThreadPtr->mp2);
816 }
817
818 if(msg->message >= WINWM_SYSKEYDOWN) {
819 extramsg.message = WINWM_SYSCHAR;
820 }
821 else extramsg.message = WINWM_CHAR;
822
823 if(fl & KC_DEADKEY) {
824 extramsg.message++; //WM_DEADCHAR/WM_SYSDEADCHAR
825 }
826
827 extramsg.lParam = msg->lParam & 0x00FFFFFF;
828 if(fl & KC_ALT)
829 extramsg.lParam |= (1<<29);
830 if(fl & KC_PREVDOWN)
831 extramsg.lParam |= (1<<30);
832 if(fl & KC_KEYUP)
833 extramsg.lParam |= (1<<31);
834
835 thdb->fTranslated = TRUE;
836 memcpy(&thdb->msgWCHAR, &extramsg, sizeof(MSG));
837 return TRUE;
838 }
839 return FALSE;
840}
841//******************************************************************************
842//******************************************************************************
843
Note: See TracBrowser for help on using the repository browser.