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

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

HTTRANSPARENT

File size: 29.1 KB
Line 
1/* $Id: oslibmsgtranslate.cpp,v 1.26 2000-03-31 14:42:47 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
432 return TRUE;
433
434 case WM_BUTTON1DOWN:
435 case WM_BUTTON1UP:
436 case WM_BUTTON1DBLCLK:
437 case WM_BUTTON2DOWN:
438 case WM_BUTTON2UP:
439 case WM_BUTTON2DBLCLK:
440 case WM_BUTTON3DOWN:
441 case WM_BUTTON3UP:
442 case WM_BUTTON3DBLCLK:
443 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
444
445 if(IsNCMouseMsg(win32wnd)) {
446 winMsg->message = WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
447 winMsg->wParam = win32wnd->getLastHitTestVal();
448 winMsg->lParam = MAKELONG(winMsg->pt.x, winMsg->pt.y); //screen coordinates
449 }
450 else {
451 point.x = (*(POINTS *)&os2Msg->mp1).x;
452 point.y = (*(POINTS *)&os2Msg->mp1).y;
453 ClientPoint.x = point.x;
454 ClientPoint.y = mapY(os2Msg->hwnd,point.y);
455
456 winMsg->message = WINWM_LBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
457 winMsg->wParam = GetMouseKeyState();
458 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
459 }
460 if(ISMOUSE_CAPTURED())
461 {
462 if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y)) {
463 goto dummymessage; //dinput swallowed message
464 }
465 }
466
467 break;
468
469 case WM_BUTTON2MOTIONSTART:
470 case WM_BUTTON2MOTIONEND:
471 case WM_BUTTON2CLICK:
472 case WM_BUTTON1MOTIONSTART:
473 case WM_BUTTON1MOTIONEND:
474 case WM_BUTTON1CLICK:
475 case WM_BUTTON3MOTIONSTART:
476 case WM_BUTTON3MOTIONEND:
477 case WM_BUTTON3CLICK:
478 goto dummymessage;
479
480 case WM_MOUSEMOVE:
481 {
482 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
483
484 if(IsNCMouseMsg(win32wnd))
485 {
486 winMsg->message = WINWM_NCMOUSEMOVE;
487 winMsg->wParam = (WPARAM)win32wnd->getLastHitTestVal();
488 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
489 }
490 else
491 {
492 winMsg->message = WINWM_MOUSEMOVE;
493 winMsg->wParam = GetMouseKeyState();
494 winMsg->lParam = MAKELONG(SHORT1FROMMP(os2Msg->mp1),mapY(win32wnd,SHORT2FROMMP(os2Msg->mp1)));
495 }
496 if(ISMOUSE_CAPTURED())
497 {
498 if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y)) {
499 goto dummymessage; //dinput swallowed message
500 }
501 }
502 //OS/2 Window coordinates -> Win32 Window coordinates
503 break;
504 }
505
506 case WM_CONTROL:
507 goto dummymessage;
508
509 case WM_COMMAND:
510 if(SHORT1FROMMP(os2Msg->mp2) == CMDSRC_MENU) {
511 winMsg->message = WINWM_COMMAND;
512 winMsg->wParam = (WPARAM)SHORT1FROMMP(os2Msg->mp1); //id
513 break;
514 }
515 //todo controls
516 goto dummymessage;
517
518 case WM_SYSCOMMAND:
519 {
520 ULONG x = 0, y = 0;
521 ULONG win32sc;
522
523 if(SHORT2FROMMP(os2Msg->mp2) == TRUE) {//syscommand caused by mouse action
524 POINTL pointl;
525 WinQueryPointerPos(HWND_DESKTOP, &pointl);
526 x = pointl.x;
527 y = mapScreenY(y);
528 }
529 switch(SHORT1FROMMP(os2Msg->mp1)) {
530 case SC_MOVE:
531 win32sc = SC_MOVE_W;
532 break;
533 case SC_CLOSE:
534 win32sc = SC_CLOSE_W;
535 break;
536 case SC_MAXIMIZE:
537 win32sc = SC_MAXIMIZE_W;
538 break;
539 case SC_MINIMIZE:
540 win32sc = SC_MINIMIZE_W;
541 break;
542 case SC_NEXTFRAME:
543 case SC_NEXTWINDOW:
544 win32sc = SC_NEXTWINDOW_W;
545 break;
546 case SC_RESTORE:
547 win32sc = SC_RESTORE_W;
548 break;
549 case SC_TASKMANAGER:
550 win32sc = SC_TASKLIST_W;
551 break;
552 default:
553 goto dummymessage;
554 }
555 winMsg->message = WINWM_SYSCOMMAND;
556 winMsg->wParam = (WPARAM)win32sc;
557 winMsg->lParam = MAKELONG((USHORT)x, (USHORT)y);
558 break;
559 }
560 case WM_CHAR:
561 {
562 ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
563 ULONG flags = SHORT1FROMMP(os2Msg->mp1);
564 BOOL keyWasPressed;
565 char c;
566
567 thdb->fTranslated = FALSE;
568 repeatCount = CHAR3FROMMP(os2Msg->mp1);
569 scanCode = CHAR4FROMMP(os2Msg->mp1);
570 keyWasPressed = ((SHORT1FROMMP (os2Msg->mp1) & KC_PREVDOWN) == KC_PREVDOWN);
571
572 dprintf(("PM: WM_CHAR: %x %x %d %x", SHORT1FROMMP(os2Msg->mp2), SHORT2FROMMP(os2Msg->mp2), repeatCount, scanCode));
573 dprintf(("PM: WM_CHAR: %x", flags));
574
575 // vitali add begin
576 if ( ( SHORT1FROMMP(os2Msg->mp2) & 0x0FF ) == 0x0E0 )
577 {
578 // an extended key ( arrows, ins, del and so on )
579 // get "virtual" scancode from character code cause
580 // for "regular" keys they are equal
581 scanCode = ( SHORT1FROMMP(os2Msg->mp2) >> 8) & 0x0FF;
582 }
583 // vitali add end
584
585 // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key
586 // given the OS/2 virtual key and OS/2 character
587
588 //if (((SHORT1FROMMP (mp1) & KC_CHAR) == KC_CHAR) ||
589 // ((SHORT1FROMMP (mp1) & KC_LONEKEY) == KC_LONEKEY))
590 c = 0;
591 if ((SHORT1FROMMP (os2Msg->mp1) & 0xFF) != 0)
592 {
593 c = SHORT1FROMMP (os2Msg->mp2);
594 if ((c >= 'A') && (c <= 'Z')) {
595 virtualKey = c;
596 goto VirtualKeyFound;
597 }
598 if ((c >='a') && (c <= 'z')) {
599 virtualKey = c - 32; // make it uppercase
600 goto VirtualKeyFound;
601 }
602 if ((c >= '0') && (c <= '9')) {
603 virtualKey = c;
604 goto VirtualKeyFound;
605 }
606 }
607
608 // convert OS/2 virtual keys to Win32 virtual key
609 if (SHORT2FROMMP (os2Msg->mp2) <= VK_BLK2)
610 virtualKey = virtualKeyTable [SHORT2FROMMP (os2Msg->mp2)];
611
612VirtualKeyFound:
613 dprintf (("VIRTUALKEYFOUND:(%x)", virtualKey));
614
615 winMsg->wParam = virtualKey;
616 winMsg->lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
617 winMsg->lParam |= (scanCode & 0x0FF) << 16; // bit 16-23, scancode
618
619 //TODO: Is this correct and complete? (how does PM differentiate between
620 // i.e numeric pad pgdn & 'normal' pgdn??)
621 //Check if it's an extended key
622 switch(virtualKey) {
623 case VK_RETURN_W:
624 //The enter key on the numeric keypad is an extended key
625 if(SHORT2FROMMP(os2Msg->mp2) != VK_NEWLINE)
626 break;
627 //no break
628 case VK_LEFT_W:
629 case VK_RIGHT_W:
630 case VK_DOWN_W:
631 case VK_UP_W:
632 case VK_PRIOR_W:
633 case VK_NEXT_W:
634 case VK_END_W:
635 case VK_DIVIDE_W:
636 case VK_DELETE_W:
637 case VK_HOME_W:
638 case VK_INSERT_W:
639 case VK_RCONTROL_W:
640 case VK_RMENU_W: //is this the right alt???
641 winMsg->lParam = winMsg->lParam | (1<<24);
642 break;
643 }
644
645 if(!(SHORT1FROMMP(os2Msg->mp1) & KC_ALT))
646 {
647 //
648 // the Alt key is not pressed
649 //
650 if ((flags & KC_KEYUP) == KC_KEYUP) {
651 // send WM_KEYUP message
652
653 winMsg->message = WINWM_KEYUP;
654 winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
655 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
656 }
657 else {
658 // send WM_KEYDOWN message
659 winMsg->message = WINWM_KEYDOWN;
660 if (keyWasPressed)
661 winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
662 }
663 }
664 else {
665 //
666 // the Alt key is pressed
667 //
668 if ((flags & KC_KEYUP) == KC_KEYUP) {
669 // send WM_SYSKEYUP message
670
671 winMsg->message = WINWM_SYSKEYUP;
672 winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
673 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
674 }
675 else {
676 // send WM_SYSKEYDOWN message
677 winMsg->message = WINWM_SYSKEYDOWN;
678 if (keyWasPressed)
679 winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
680 }
681 }
682 if(ISKDB_CAPTURED())
683 {
684 if(DInputKeyBoardHandler(winMsg)) {
685 goto dummymessage; //dinput swallowed message
686 }
687 }
688 break;
689 }
690
691 case WM_TIMER:
692 if (os2Msg->mp2)
693 {
694 BOOL sys;
695 ULONG id;
696
697 if (TIMER_GetTimerInfo(os2Msg->hwnd,(ULONG)os2Msg->mp1,&sys,&id))
698 {
699 winMsg->wParam = (WPARAM)id;
700 winMsg->message= (sys) ? WINWM_SYSTIMER : WINWM_TIMER;
701 break;
702 }
703 }
704 goto dummymessage; //for caret blinking
705
706 case WM_SETWINDOWPARAMS:
707 {
708 WNDPARAMS *wndParams = (WNDPARAMS *)os2Msg->mp1;
709
710 if(wndParams->fsStatus & WPM_TEXT) {
711 winMsg->message = WINWM_SETTEXT;
712 winMsg->lParam = (LPARAM)wndParams->pszText;
713 break;
714 }
715 goto dummymessage;
716 }
717
718#if 0
719 case WM_QUERYWINDOWPARAMS:
720 {
721 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
722 ULONG textlen;
723 PSZ wintext;
724
725 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
726 {
727 if(wndpars->fsStatus & WPM_CCHTEXT)
728 wndpars->cchText = win32wnd->MsgGetTextLength();
729 if(wndpars->fsStatus & WPM_TEXT)
730 wndpars->pszText = win32wnd->MsgGetText();
731
732 wndpars->fsStatus = 0;
733 wndpars->cbCtlData = 0;
734 wndpars->cbPresParams = 0;
735 goto dummymessage;
736 }
737 }
738#endif
739
740 case WM_PAINT:
741 {
742 if(win32wnd->IsWindowIconic()) {
743 winMsg->message = WINWM_PAINTICON;
744 }
745 else winMsg->message = WINWM_PAINT;
746 break;
747 }
748
749 case WM_CONTEXTMENU:
750 winMsg->message = WINWM_CONTEXTMENU;
751 winMsg->wParam = win32wnd->getWindowHandle();
752 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
753 break;
754
755 case WM_INITMENU:
756 case WM_MENUSELECT:
757 case WM_MENUEND:
758 case WM_NEXTMENU:
759 case WM_SYSCOLORCHANGE:
760 case WM_SYSVALUECHANGED:
761 case WM_SETSELECTION:
762 case WM_PPAINT:
763 case WM_PSETFOCUS:
764 case WM_PSYSCOLORCHANGE:
765 case WM_PSIZE:
766 case WM_PACTIVATE:
767 case WM_PCONTROL:
768 case WM_HELP:
769 case WM_APPTERMINATENOTIFY:
770 case WM_PRESPARAMCHANGED:
771 case WM_DRAWITEM:
772 case WM_MEASUREITEM:
773 case WM_CONTROLPOINTER:
774 case WM_QUERYDLGCODE:
775 case WM_SUBSTITUTESTRING:
776 case WM_MATCHMNEMONIC:
777 case WM_SAVEAPPLICATION:
778 case WM_SEMANTICEVENT:
779 default:
780dummymessage:
781 winMsg->message = 0;
782 winMsg->wParam = 0;
783 winMsg->lParam = 0;
784 return FALSE;
785 }
786 return TRUE;
787}
788//******************************************************************************
789//******************************************************************************
790BOOL OSLibWinTranslateMessage(MSG *msg)
791{
792 THDB *thdb;
793
794 thdb = GetThreadTHDB();
795 if(!thdb) {
796 return FALSE;
797 }
798 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
799 // the newly generated WM_CHAR message.
800 if(!thdb->fTranslated && MsgThreadPtr->msg == WM_CHAR && !((SHORT1FROMMP(MsgThreadPtr->mp1) & KC_KEYUP) == KC_KEYUP))
801 {//TranslatedMessage was called before DispatchMessage, so queue WM_CHAR message
802 ULONG fl = SHORT1FROMMP(MsgThreadPtr->mp1);
803 MSG extramsg;
804
805 memcpy(&extramsg, msg, sizeof(MSG));
806 extramsg.wParam = SHORT1FROMMP(MsgThreadPtr->mp2);
807 extramsg.lParam = 0;
808
809 if(!(fl & KC_CHAR)) {
810 return FALSE;
811 }
812
813 if(fl & KC_VIRTUALKEY) {
814 if(msg->wParam)
815 extramsg.wParam = msg->wParam;
816 else extramsg.wParam = SHORT2FROMMP(MsgThreadPtr->mp2);
817 }
818
819 if(msg->message >= WINWM_SYSKEYDOWN) {
820 extramsg.message = WINWM_SYSCHAR;
821 }
822 else extramsg.message = WINWM_CHAR;
823
824 if(fl & KC_DEADKEY) {
825 extramsg.message++; //WM_DEADCHAR/WM_SYSDEADCHAR
826 }
827
828 extramsg.lParam = msg->lParam & 0x00FFFFFF;
829 if(fl & KC_ALT)
830 extramsg.lParam |= (1<<29);
831 if(fl & KC_PREVDOWN)
832 extramsg.lParam |= (1<<30);
833 if(fl & KC_KEYUP)
834 extramsg.lParam |= (1<<31);
835
836 thdb->fTranslated = TRUE;
837 memcpy(&thdb->msgWCHAR, &extramsg, sizeof(MSG));
838 return TRUE;
839 }
840 return FALSE;
841}
842//******************************************************************************
843//******************************************************************************
844
Note: See TracBrowser for help on using the repository browser.