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

Last change on this file since 3101 was 3101, checked in by sandervl, 25 years ago

replaced os2.h includes by os2wrap.h

File size: 28.0 KB
Line 
1/* $Id: oslibmsgtranslate.cpp,v 1.23 2000-03-13 13:10:46 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 "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 0x0A, // VK_NEWLINE 0x0A (no VK_* def)
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 ULONG hittest;
141 int i;
142
143 memset(winMsg, 0, sizeof(MSG));
144 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(os2Msg->hwnd);
145 if (!win32wnd) win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(os2Msg->hwnd);
146
147 //PostThreadMessage posts WIN32APP_POSTMSG msg without window handle
148 //Realplayer starts a timer with hwnd 0 & proc 0; check this here
149 if(win32wnd == 0 && (os2Msg->msg != WM_CREATE && os2Msg->msg != WM_QUIT && os2Msg->msg != WM_TIMER && os2Msg->msg != WIN32APP_POSTMSG))
150 {
151 goto dummymessage; //not a win32 client window
152 }
153 winMsg->time = os2Msg->time;
154 //CB: PM bug or undocumented feature? ptl.x highword is set!
155 winMsg->pt.x = os2Msg->ptl.x & 0xFFFF;
156 winMsg->pt.y = mapScreenY(os2Msg->ptl.y);
157
158 if(win32wnd) //==0 for WM_CREATE/WM_QUIT
159 winMsg->hwnd = win32wnd->getWindowHandle();
160
161 if (win32wnd && (os2Msg->hwnd == win32wnd->getOS2FrameWindowHandle()))
162 {
163 //special frame messages
164
165 switch (os2Msg->msg)
166 {
167 case WM_BUTTON1DOWN:
168 case WM_BUTTON1UP:
169 case WM_BUTTON1DBLCLK:
170 case WM_BUTTON2DOWN:
171 case WM_BUTTON2UP:
172 case WM_BUTTON2DBLCLK:
173 case WM_BUTTON3DOWN:
174 case WM_BUTTON3UP:
175 case WM_BUTTON3DBLCLK:
176 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
177
178 hittest = win32wnd->MsgHitTest(winMsg->pt.x, winMsg->pt.y);
179
180 if (IsNCMouseMsg(win32wnd)) {
181 winMsg->message = WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
182 winMsg->wParam = hittest;
183 winMsg->lParam = MAKELONG(winMsg->pt.x, winMsg->pt.y); //screen coordinates
184 }
185 else {
186 point.x = (*(POINTS *)&os2Msg->mp1).x;
187 point.y = (*(POINTS *)&os2Msg->mp1).y;
188 ClientPoint.x = point.x;
189 ClientPoint.y = mapOS2ToWin32Y(os2Msg->hwnd,win32wnd->getOS2WindowHandle(),point.y);
190
191 winMsg->message = WINWM_LBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
192 winMsg->wParam = GetMouseKeyState();
193 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
194 }
195 if(ISMOUSE_CAPTURED())
196 {
197 if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y))
198 goto dummymessage; //dinput swallowed message
199 }
200
201 return TRUE;
202
203 case WM_BUTTON2MOTIONSTART:
204 case WM_BUTTON2MOTIONEND:
205 case WM_BUTTON2CLICK:
206 case WM_BUTTON1MOTIONSTART:
207 case WM_BUTTON1MOTIONEND:
208 case WM_BUTTON1CLICK:
209 case WM_BUTTON3MOTIONSTART:
210 case WM_BUTTON3MOTIONEND:
211 case WM_BUTTON3CLICK:
212 goto dummymessage;
213
214 case WM_MOUSEMOVE:
215 {
216 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
217 hittest = win32wnd->MsgHitTest(winMsg->pt.x, winMsg->pt.y);
218
219 if (IsNCMouseMsg(win32wnd))
220 {
221 winMsg->message = WINWM_NCMOUSEMOVE;
222 winMsg->wParam = (WPARAM)hittest;
223 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
224 }
225 else
226 {
227 winMsg->message = WINWM_MOUSEMOVE;
228 winMsg->wParam = GetMouseKeyState();
229 winMsg->lParam = MAKELONG(SHORT1FROMMP(os2Msg->mp1),mapOS2ToWin32Y(win32wnd->getOS2FrameWindowHandle(),win32wnd->getOS2WindowHandle(),SHORT2FROMMP(os2Msg->mp1)));
230 }
231 if(ISMOUSE_CAPTURED())
232 {
233 if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y))
234 goto dummymessage; //dinput swallowed message
235 }
236 //OS/2 Window coordinates -> Win32 Window coordinates
237 return TRUE;
238 }
239
240 case WM_PAINT:
241 {
242 winMsg->message = WINWM_NCPAINT;
243 return TRUE;
244 }
245
246 case WM_ACTIVATE:
247 {
248 winMsg->message = WINWM_NCACTIVATE;
249 winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
250 return TRUE;
251 }
252 case WM_WINDOWPOSCHANGED:
253 {
254 //todo: proper translation
255 return FALSE;
256 }
257 }
258 //do normal translation for all other messages
259 }
260
261 switch(os2Msg->msg)
262 {
263 case WIN32APP_POSTMSG:
264 {
265 packet = (POSTMSG_PACKET *)os2Msg->mp2;
266 if(packet && ((ULONG)os2Msg->mp1 == WIN32MSG_MAGICA || (ULONG)os2Msg->mp1 == WIN32MSG_MAGICW)) {
267 winMsg->message = packet->Msg;
268 winMsg->wParam = packet->wParam;
269 winMsg->lParam = packet->lParam;
270 if(fMsgRemoved == MSG_REMOVE) free(packet); //free the shared memory here
271 break;
272 }
273 goto dummymessage;
274 }
275
276 //OS/2 msgs
277 case WM_CREATE:
278 {
279 if(thdb->newWindow == 0) {
280 DebugInt3();
281 goto dummymessage;
282 }
283
284 win32wnd = (Win32BaseWindow *)thdb->newWindow;
285
286 winMsg->message = WINWM_CREATE;
287 winMsg->hwnd = win32wnd->getWindowHandle();
288 winMsg->wParam = 0;
289 winMsg->lParam = (LPARAM)win32wnd->tmpcs;
290 break;
291 }
292
293 case WM_QUIT:
294 winMsg->message = WINWM_QUIT;
295 break;
296
297 case WM_CLOSE:
298 winMsg->message = WINWM_CLOSE;
299 break;
300
301 case WM_DESTROY:
302 winMsg->message = WINWM_DESTROY;
303 break;
304
305 case WM_ENABLE:
306 winMsg->message = WINWM_ENABLE;
307 winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
308 break;
309
310 case WM_SHOW:
311 winMsg->message = WINWM_SHOWWINDOW;
312 winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
313 break;
314
315 case WM_WINDOWPOSCHANGED:
316 {
317 PSWP pswp = (PSWP)os2Msg->mp1;
318 SWP swpOld = *(pswp + 1);
319 HWND hParent = NULLHANDLE;
320 LONG yDelta = pswp->cy - swpOld.cy;
321 LONG xDelta = pswp->cx - swpOld.cx;
322
323 dprintf(("OS2: WM_WINDOWPOSCHANGED %x %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
324
325 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) goto dummymessage;
326
327 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
328 if (win32wnd->isChild()) {
329 if(win32wnd->getParent()) {
330 hParent = win32wnd->getParent()->getOS2WindowHandle();
331 }
332 else goto dummymessage; //parent has just been destroyed
333 }
334 }
335 OSLibMapSWPtoWINDOWPOS(pswp, &thdb->wp, &swpOld, hParent, win32wnd->getOS2FrameWindowHandle());
336
337 if (!win32wnd->CanReceiveSizeMsgs()) goto dummymessage;
338
339 ULONG windowStyle = WinQueryWindowULong(os2Msg->hwnd, QWL_STYLE);
340 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MAXIMIZE_W|WS_MINIMIZE_W));
341 if (windowStyle & WS_MINIMIZED) {
342 win32wnd->setStyle(win32wnd->getStyle() | WS_MINIMIZE_W);
343 }
344 else
345 if (windowStyle & WS_MAXIMIZED) {
346 win32wnd->setStyle(win32wnd->getStyle() | WS_MAXIMIZE_W);
347 }
348
349 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
350 dprintf(("Set client rectangle to (%d,%d)(%d,%d)", swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy));
351 win32wnd->setClientRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
352
353 thdb->wp.hwnd = win32wnd->getWindowHandle();
354 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
355 {
356 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
357 if(wndAfter)
358 thdb->wp.hwndInsertAfter = wndAfter->getWindowHandle();
359 }
360
361 PRECT lpRect = win32wnd->getWindowRect();
362 //SvL: Only send it when the client has changed & the frame hasn't
363 // If the frame size/position has changed, pmframe.cpp will send
364 // this message
365 if(lpRect->right == thdb->wp.x+thdb->wp.cx && lpRect->bottom == thdb->wp.y+thdb->wp.cy) {
366 winMsg->message = WINWM_WINDOWPOSCHANGED;
367 winMsg->lParam = (LPARAM)&thdb->wp;
368 break;
369 }
370 }
371 goto dummymessage;
372 }
373
374 case WM_ACTIVATE:
375 {
376 HWND hwndActivate = (HWND)os2Msg->mp2;
377 BOOL fMinimized = FALSE;
378
379 if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
380 //another (non-win32) application's window
381 //set to desktop window handle
382 hwndActivate = windowDesktop->getWindowHandle();
383 }
384 else hwndActivate = Win32BaseWindow::OS2ToWin32Handle(hwndActivate);
385
386 if(WinQueryWindowULong(os2Msg->hwnd, QWL_STYLE) & WS_MINIMIZED)
387 {
388 fMinimized = TRUE;
389 }
390
391 winMsg->message = WINWM_ACTIVATE;
392 winMsg->wParam = MAKELONG((SHORT1FROMMP(os2Msg->mp1)) ? WA_ACTIVE_W : WA_INACTIVE_W, fMinimized);
393 winMsg->lParam = (LPARAM)hwndActivate;
394 break;
395 }
396
397 case WM_SETFOCUS:
398 {
399 HWND hwndFocus = (HWND)os2Msg->mp1;
400
401 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
402 //another (non-win32) application's window
403 //set to NULL (allowed according to win32 SDK) to avoid problems
404 hwndFocus = NULL;
405 }
406 else hwndFocus = Win32BaseWindow::OS2ToWin32Handle(hwndFocus);
407
408 if((ULONG)os2Msg->mp2 == TRUE) {
409 winMsg->message = WINWM_SETFOCUS;
410 winMsg->wParam = (WPARAM)hwndFocus;
411 }
412 else {
413 winMsg->message = WINWM_KILLFOCUS;
414 winMsg->wParam = (WPARAM)hwndFocus;
415 }
416 break;
417 }
418
419 //**************************************************************************
420 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
421 //**************************************************************************
422 case WM_BUTTON1DOWN:
423 case WM_BUTTON1UP:
424 case WM_BUTTON1DBLCLK:
425 case WM_BUTTON2DOWN:
426 case WM_BUTTON2UP:
427 case WM_BUTTON2DBLCLK:
428 case WM_BUTTON3DOWN:
429 case WM_BUTTON3UP:
430 case WM_BUTTON3DBLCLK:
431 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
432 hittest = win32wnd->MsgHitTest(winMsg->pt.x, winMsg->pt.y);
433
434 if(IsNCMouseMsg(win32wnd)) {
435 winMsg->message = WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
436 winMsg->wParam = hittest;
437 winMsg->lParam = MAKELONG(winMsg->pt.x, winMsg->pt.y); //screen coordinates
438 }
439 else {
440 point.x = (*(POINTS *)&os2Msg->mp1).x;
441 point.y = (*(POINTS *)&os2Msg->mp1).y;
442 ClientPoint.x = point.x;
443 ClientPoint.y = mapY(os2Msg->hwnd,point.y);
444
445 winMsg->message = WINWM_LBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
446 winMsg->wParam = GetMouseKeyState();
447 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
448 }
449 if(ISMOUSE_CAPTURED())
450 {
451 if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y))
452 goto dummymessage; //dinput swallowed message
453 }
454
455 break;
456
457 case WM_BUTTON2MOTIONSTART:
458 case WM_BUTTON2MOTIONEND:
459 case WM_BUTTON2CLICK:
460 case WM_BUTTON1MOTIONSTART:
461 case WM_BUTTON1MOTIONEND:
462 case WM_BUTTON1CLICK:
463 case WM_BUTTON3MOTIONSTART:
464 case WM_BUTTON3MOTIONEND:
465 case WM_BUTTON3CLICK:
466 goto dummymessage;
467
468 case WM_MOUSEMOVE:
469 {
470 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
471 hittest = win32wnd->MsgHitTest(winMsg->pt.x, winMsg->pt.y);
472
473 if(IsNCMouseMsg(win32wnd))
474 {
475 winMsg->message = WINWM_NCMOUSEMOVE;
476 winMsg->wParam = (WPARAM)hittest;
477 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
478 }
479 else
480 {
481 winMsg->message = WINWM_MOUSEMOVE;
482 winMsg->wParam = GetMouseKeyState();
483 winMsg->lParam = MAKELONG(SHORT1FROMMP(os2Msg->mp1),mapY(win32wnd,SHORT2FROMMP(os2Msg->mp1)));
484 }
485 if(ISMOUSE_CAPTURED())
486 {
487 if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y))
488 goto dummymessage; //dinput swallowed message
489 }
490 //OS/2 Window coordinates -> Win32 Window coordinates
491 break;
492 }
493
494 case WM_CONTROL:
495 goto dummymessage;
496
497 case WM_COMMAND:
498 if(SHORT1FROMMP(os2Msg->mp2) == CMDSRC_MENU) {
499 winMsg->message = WINWM_COMMAND;
500 winMsg->wParam = (WPARAM)SHORT1FROMMP(os2Msg->mp1); //id
501 break;
502 }
503 //todo controls
504 goto dummymessage;
505
506 case WM_SYSCOMMAND:
507 {
508 ULONG x = 0, y = 0;
509 ULONG win32sc;
510
511 if(SHORT2FROMMP(os2Msg->mp2) == TRUE) {//syscommand caused by mouse action
512 POINTL pointl;
513 WinQueryPointerPos(HWND_DESKTOP, &pointl);
514 x = pointl.x;
515 y = mapScreenY(y);
516 }
517 switch(SHORT1FROMMP(os2Msg->mp1)) {
518 case SC_MOVE:
519 win32sc = SC_MOVE_W;
520 break;
521 case SC_CLOSE:
522 win32sc = SC_CLOSE_W;
523 break;
524 case SC_MAXIMIZE:
525 win32sc = SC_MAXIMIZE_W;
526 break;
527 case SC_MINIMIZE:
528 win32sc = SC_MINIMIZE_W;
529 break;
530 case SC_NEXTFRAME:
531 case SC_NEXTWINDOW:
532 win32sc = SC_NEXTWINDOW_W;
533 break;
534 case SC_RESTORE:
535 win32sc = SC_RESTORE_W;
536 break;
537 case SC_TASKMANAGER:
538 win32sc = SC_TASKLIST_W;
539 break;
540 default:
541 goto dummymessage;
542 }
543 winMsg->message = WINWM_SYSCOMMAND;
544 winMsg->wParam = (WPARAM)win32sc;
545 winMsg->lParam = MAKELONG((USHORT)x, (USHORT)y);
546 break;
547 }
548 case WM_CHAR:
549 {
550 ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
551 ULONG flags = SHORT1FROMMP(os2Msg->mp1);
552 BOOL keyWasPressed;
553 char c;
554
555 thdb->fTranslated = FALSE;
556 repeatCount = CHAR3FROMMP(os2Msg->mp1);
557 scanCode = CHAR4FROMMP(os2Msg->mp1);
558 keyWasPressed = ((SHORT1FROMMP (os2Msg->mp1) & KC_PREVDOWN) == KC_PREVDOWN);
559
560 dprintf(("PM: WM_CHAR: %x %x %d %x", SHORT1FROMMP(os2Msg->mp2), SHORT2FROMMP(os2Msg->mp2), repeatCount, scanCode));
561 dprintf(("PM: WM_CHAR: %x", flags));
562
563 // vitali add begin
564 if ( ( SHORT1FROMMP(os2Msg->mp2) & 0x0FF ) == 0x0E0 )
565 {
566 // an extended key ( arrows, ins, del and so on )
567 // get "virtual" scancode from character code cause
568 // for "regular" keys they are equal
569 scanCode = ( SHORT1FROMMP(os2Msg->mp2) >> 8) & 0x0FF;
570 }
571 // vitali add end
572
573 // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key
574 // given the OS/2 virtual key and OS/2 character
575
576 //if (((SHORT1FROMMP (mp1) & KC_CHAR) == KC_CHAR) ||
577 // ((SHORT1FROMMP (mp1) & KC_LONEKEY) == KC_LONEKEY))
578 c = 0;
579 if ((SHORT1FROMMP (os2Msg->mp1) & 0xFF) != 0)
580 {
581 c = SHORT1FROMMP (os2Msg->mp2);
582 if ((c >= 'A') && (c <= 'Z')) {
583 virtualKey = c;
584 goto VirtualKeyFound;
585 }
586 if ((c >='a') && (c <= 'z')) {
587 virtualKey = c - 32; // make it uppercase
588 goto VirtualKeyFound;
589 }
590 if ((c >= '0') && (c <= '9')) {
591 virtualKey = c;
592 goto VirtualKeyFound;
593 }
594 }
595
596 // convert OS/2 virtual keys to Win32 virtual key
597 if (SHORT2FROMMP (os2Msg->mp2) <= VK_BLK2)
598 virtualKey = virtualKeyTable [SHORT2FROMMP (os2Msg->mp2)];
599
600VirtualKeyFound:
601 dprintf (("VIRTUALKEYFOUND:(%x)", virtualKey));
602
603 winMsg->wParam = virtualKey;
604 winMsg->lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
605 winMsg->lParam |= (scanCode & 0x0FF) << 16; // bit 16-23, scancode
606 win32wnd->setExtendedKey(virtualKey, (ULONG *)&winMsg->lParam);
607
608 if(!(SHORT1FROMMP(os2Msg->mp1) & KC_ALT))
609 {
610 //
611 // the Alt key is not pressed
612 //
613 if ((flags & KC_KEYUP) == KC_KEYUP) {
614 // send WM_KEYUP message
615
616 winMsg->message = WINWM_KEYUP;
617 winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
618 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
619 }
620 else {
621 // send WM_KEYDOWN message
622 winMsg->message = WINWM_KEYDOWN;
623 if (keyWasPressed)
624 winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
625 }
626 }
627 else {
628 //
629 // the Alt key is pressed
630 //
631 if ((flags & KC_KEYUP) == KC_KEYUP) {
632 // send WM_SYSKEYUP message
633
634 winMsg->message = WINWM_SYSKEYUP;
635 winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
636 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
637 }
638 else {
639 // send WM_SYSKEYDOWN message
640 winMsg->message = WINWM_SYSKEYDOWN;
641 if (keyWasPressed)
642 winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
643 }
644 }
645 if(ISKDB_CAPTURED())
646 {
647 if(DInputKeyBoardHandler(winMsg))
648 goto dummymessage; //dinput swallowed message
649 }
650 break;
651 }
652
653 case WM_TIMER:
654 if (os2Msg->mp2)
655 {
656 BOOL sys;
657 ULONG id;
658
659 if (TIMER_GetTimerInfo(os2Msg->hwnd,(ULONG)os2Msg->mp1,&sys,&id))
660 {
661 winMsg->wParam = (WPARAM)id;
662 winMsg->message= (sys) ? WINWM_SYSTIMER : WINWM_TIMER;
663 break;
664 }
665 }
666 goto dummymessage; //for caret blinking
667
668 case WM_SETWINDOWPARAMS:
669 {
670 WNDPARAMS *wndParams = (WNDPARAMS *)os2Msg->mp1;
671
672 if(wndParams->fsStatus & WPM_TEXT) {
673 winMsg->message = WINWM_SETTEXT;
674 winMsg->lParam = (LPARAM)wndParams->pszText;
675 break;
676 }
677 goto dummymessage;
678 }
679
680#if 0
681 case WM_QUERYWINDOWPARAMS:
682 {
683 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
684 ULONG textlen;
685 PSZ wintext;
686
687 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
688 {
689 if(wndpars->fsStatus & WPM_CCHTEXT)
690 wndpars->cchText = win32wnd->MsgGetTextLength();
691 if(wndpars->fsStatus & WPM_TEXT)
692 wndpars->pszText = win32wnd->MsgGetText();
693
694 wndpars->fsStatus = 0;
695 wndpars->cbCtlData = 0;
696 wndpars->cbPresParams = 0;
697 goto dummymessage;
698 }
699 }
700#endif
701
702 case WM_PAINT:
703 {
704 if(win32wnd->IsWindowIconic()) {
705 winMsg->message = WINWM_PAINTICON;
706 }
707 else winMsg->message = WINWM_PAINT;
708 break;
709 }
710
711 case WM_CONTEXTMENU:
712 winMsg->message = WINWM_CONTEXTMENU;
713 winMsg->wParam = win32wnd->getWindowHandle();
714 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
715 break;
716
717 case WM_INITMENU:
718 case WM_MENUSELECT:
719 case WM_MENUEND:
720 case WM_NEXTMENU:
721 case WM_SYSCOLORCHANGE:
722 case WM_SYSVALUECHANGED:
723 case WM_SETSELECTION:
724 case WM_PPAINT:
725 case WM_PSETFOCUS:
726 case WM_PSYSCOLORCHANGE:
727 case WM_PSIZE:
728 case WM_PACTIVATE:
729 case WM_PCONTROL:
730 case WM_HELP:
731 case WM_APPTERMINATENOTIFY:
732 case WM_PRESPARAMCHANGED:
733 case WM_DRAWITEM:
734 case WM_MEASUREITEM:
735 case WM_CONTROLPOINTER:
736 case WM_QUERYDLGCODE:
737 case WM_SUBSTITUTESTRING:
738 case WM_MATCHMNEMONIC:
739 case WM_SAVEAPPLICATION:
740 case WM_SEMANTICEVENT:
741 default:
742dummymessage:
743 return FALSE;
744 }
745 return TRUE;
746}
747//******************************************************************************
748//******************************************************************************
749BOOL OSLibWinTranslateMessage(MSG *msg)
750{
751 THDB *thdb;
752
753 thdb = GetThreadTHDB();
754 if(!thdb) {
755 return FALSE;
756 }
757 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
758 // the newly generated WM_CHAR message.
759 if(!thdb->fTranslated && MsgThreadPtr->msg == WM_CHAR && !((SHORT1FROMMP(MsgThreadPtr->mp1) & KC_KEYUP) == KC_KEYUP))
760 {//TranslatedMessage was called before DispatchMessage, so queue WM_CHAR message
761 ULONG fl = SHORT1FROMMP(MsgThreadPtr->mp1);
762 MSG extramsg;
763
764 memcpy(&extramsg, msg, sizeof(MSG));
765 extramsg.wParam = SHORT1FROMMP(MsgThreadPtr->mp2);
766 extramsg.lParam = 0;
767
768 if(!(fl & KC_CHAR)) {
769 return FALSE;
770 }
771
772 if(fl & KC_VIRTUALKEY) {
773 if(msg->wParam)
774 extramsg.wParam = msg->wParam;
775 else extramsg.wParam = SHORT2FROMMP(MsgThreadPtr->mp2);
776 }
777
778 if(msg->message >= WINWM_SYSKEYDOWN) {
779 extramsg.message = WINWM_SYSCHAR;
780 }
781 else extramsg.message = WINWM_CHAR;
782
783 if(fl & KC_DEADKEY) {
784 extramsg.message++; //WM_DEADCHAR/WM_SYSDEADCHAR
785 }
786
787 extramsg.lParam = msg->lParam & 0x00FFFFFF;
788 if(fl & KC_ALT)
789 extramsg.lParam |= (1<<29);
790 if(fl & KC_PREVDOWN)
791 extramsg.lParam |= (1<<30);
792 if(fl & KC_KEYUP)
793 extramsg.lParam |= (1<<31);
794
795 thdb->fTranslated = TRUE;
796 memcpy(&thdb->msgWCHAR, &extramsg, sizeof(MSG));
797 return TRUE;
798 }
799 return FALSE;
800}
801//******************************************************************************
802//******************************************************************************
803
Note: See TracBrowser for help on using the repository browser.