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

Last change on this file since 2371 was 2371, checked in by sandervl, 26 years ago

OSLibGetMsg bugfix + WM_QUIT translation fix

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