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

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

EnableWindow fixes & don't send mouse messages to disabled windows

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