1 | /* $Id: oslibmsgtranslate.cpp,v 1.11 2000-01-09 14:37:09 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 | * NOTE: WM_NCHITTEST messages are sent whenever the mouse cursor moves or a mouse button is clicked/released
|
---|
11 | * (directly when receiving those messages)
|
---|
12 | *
|
---|
13 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
14 | *
|
---|
15 | * TODO: Extra msgs: which messages must be put into the queue and which can be sent directly?
|
---|
16 | * (According to the docs TranslateMessage really inserts a msg in the queue)
|
---|
17 | * TODO: Filter translation isn't correct for posted messages
|
---|
18 | *
|
---|
19 | */
|
---|
20 | #define INCL_WIN
|
---|
21 | #define INCL_PM
|
---|
22 | #define INCL_DOSPROCESS
|
---|
23 | #include <os2.h>
|
---|
24 | #include <os2wrap.h>
|
---|
25 | #include <string.h>
|
---|
26 | #include <misc.h>
|
---|
27 | #include "oslibmsg.h"
|
---|
28 | #include <win32wnd.h>
|
---|
29 | #include "oslibutil.h"
|
---|
30 | #include "timer.h"
|
---|
31 | #include <thread.h>
|
---|
32 | #include <wprocess.h>
|
---|
33 | #include "pmwindow.h"
|
---|
34 | #include "oslibwin.h"
|
---|
35 |
|
---|
36 | //Used for key translation while processing WM_CHAR message
|
---|
37 | USHORT virtualKeyTable [66] = {
|
---|
38 | 0x00, // OS/2 VK Win32 VK, Entry 0 is not used
|
---|
39 | 0x01, // VK_BUTTON1 VK_LBUTTON
|
---|
40 | 0x02, // VK_BUTTON2 VK_RBUTTON
|
---|
41 | 0x04, // VK_BUTTON3 VK_MBUTTON
|
---|
42 | 0x03, // VK_BREAK VK_CANCEL
|
---|
43 | 0x08, // VK_BACKSPACE VK_BACK
|
---|
44 | 0x09, // VK_TAB VK_TAB
|
---|
45 | 0x00, // VK_BACKTAB No equivalent!
|
---|
46 | 0x0A, // VK_NEWLINE 0x0A (no VK_* def)
|
---|
47 | 0x10, // VK_SHIFT VK_SHIFT
|
---|
48 | 0x11, // VK_CTRL VK_CONTROL
|
---|
49 | 0x12, // VK_ALT VK_MENU, best match I guess
|
---|
50 | 0x12, // VK_ALTGRAF VK_MENU, best match I guess
|
---|
51 | 0x13, // VK_PAUSE VK_PAUSE
|
---|
52 | 0x14, // VK_CAPSLOCK VK_CAPITAL
|
---|
53 | 0x1B, // VK_ESC VK_ESCAPE
|
---|
54 | 0x20, // VK_SPACE VK_SPACE
|
---|
55 | 0x21, // VK_PAGEUP VK_PRIOR
|
---|
56 | 0x22, // VK_PAGEDOWN VK_NEXT
|
---|
57 | 0x23, // VK_END VK_END
|
---|
58 | 0x24, // VK_HOME VK_HOME
|
---|
59 | 0x25, // VK_LEFT VK_LEFT
|
---|
60 | 0x26, // VK_UP VK_UP
|
---|
61 | 0x27, // VK_RIGHT VK_RIGHT
|
---|
62 | 0x28, // VK_DOWN VK_DOWN
|
---|
63 | 0x2C, // VK_PRINTSCRN VK_SNAPSHOT
|
---|
64 | 0x2D, // VK_INSERT VK_INSERT
|
---|
65 | 0x2E, // VK_DELETE VK_DELETE
|
---|
66 | 0x91, // VK_SCRLLOCK VK_SCROLL
|
---|
67 | 0x90, // VK_NUMLOCK VK_NUMLOCK
|
---|
68 | 0x0D, // VK_ENTER VK_RETURN
|
---|
69 | 0x00, // VK_SYSRQ No equivalent!
|
---|
70 | 0x70, // VK_F1 VK_F1
|
---|
71 | 0x71, // VK_F2 VK_F2
|
---|
72 | 0x72, // VK_F3 VK_F3
|
---|
73 | 0x73, // VK_F4 VK_F4
|
---|
74 | 0x74, // VK_F5 VK_F5
|
---|
75 | 0x75, // VK_F6 VK_F6
|
---|
76 | 0x76, // VK_F7 VK_F7
|
---|
77 | 0x77, // VK_F8 VK_F8
|
---|
78 | 0x78, // VK_F9 VK_F9
|
---|
79 | 0x79, // VK_F10 VK_F10
|
---|
80 | 0x7A, // VK_F11 VK_F11
|
---|
81 | 0x7B, // VK_F12 VK_F12
|
---|
82 | 0x7C, // VK_F13 VK_F13
|
---|
83 | 0x7D, // VK_F14 VK_F14
|
---|
84 | 0x7E, // VK_F15 VK_F15
|
---|
85 | 0x7F, // VK_F16 VK_F16
|
---|
86 | 0x80, // VK_F17 VK_F17
|
---|
87 | 0x81, // VK_F18 VK_F18
|
---|
88 | 0x82, // VK_F19 VK_F19
|
---|
89 | 0x83, // VK_F20 VK_F20
|
---|
90 | 0x84, // VK_F21 VK_F21
|
---|
91 | 0x85, // VK_F22 VK_F22
|
---|
92 | 0x86, // VK_F23 VK_F23
|
---|
93 | 0x87, // VK_F24 VK_F24
|
---|
94 | 0x00, // VK_ENDDRAG No equivalent!
|
---|
95 | 0x0C, // VK_CLEAR VK_CLEAR
|
---|
96 | 0xF9, // VK_EREOF VK_EREOF
|
---|
97 | 0xFD, // VK_PA1 VK_PA1
|
---|
98 | 0xF6, // VK_ATTN VK_ATTN
|
---|
99 | 0xF7, // VK_CRSEL VK_CRSEL
|
---|
100 | 0xF8, // VK_EXSEL VK_EXSEL
|
---|
101 | 0x00, // VK_COPY No equivalent!
|
---|
102 | 0x00, // VK_BLK1 No equivalent!
|
---|
103 | 0x00}; // VK_BLK2 No equivalent!
|
---|
104 |
|
---|
105 | //******************************************************************************
|
---|
106 | //******************************************************************************
|
---|
107 | BOOL OS2ToWinMsgTranslate(void *pThdb, QMSG *os2Msg, MSG *winMsg, BOOL isUnicode, BOOL fMsgRemoved)
|
---|
108 | {
|
---|
109 | Win32BaseWindow *win32wnd = 0;
|
---|
110 | OSLIBPOINT point, ClientPoint;
|
---|
111 | POSTMSG_PACKET *packet;
|
---|
112 | THDB *thdb = (THDB *)pThdb;
|
---|
113 | BOOL fIsFrameControl = FALSE, fTranslateFrameControlMsg = FALSE;
|
---|
114 | int i;
|
---|
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_ACTIVATE & 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 | if(fIsFrameControl) {
|
---|
258 | fTranslateFrameControlMsg = TRUE; //we want a win32 app to see this msg for a frame control
|
---|
259 | winMsg->message = WINWM_NCACTIVATE;
|
---|
260 | winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
|
---|
261 | }
|
---|
262 | else
|
---|
263 | {
|
---|
264 | winMsg->message = WINWM_ACTIVATE;
|
---|
265 | winMsg->wParam = MAKELONG((SHORT1FROMMP(os2Msg->mp1)) ? WA_ACTIVE_W : WA_INACTIVE_W, fMinimized);
|
---|
266 | winMsg->lParam = (LPARAM)hwndActivate;
|
---|
267 | }
|
---|
268 | break;
|
---|
269 | }
|
---|
270 |
|
---|
271 | case WM_SETFOCUS:
|
---|
272 | {
|
---|
273 | HWND hwndFocus = (HWND)os2Msg->mp1;
|
---|
274 |
|
---|
275 | if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
|
---|
276 | //another (non-win32) application's window
|
---|
277 | //set to NULL (allowed according to win32 SDK) to avoid problems
|
---|
278 | hwndFocus = NULL;
|
---|
279 | }
|
---|
280 | else hwndFocus = Win32BaseWindow::OS2ToWin32Handle(hwndFocus);
|
---|
281 |
|
---|
282 | if((ULONG)os2Msg->mp2 == TRUE) {
|
---|
283 | winMsg->message = WINWM_SETFOCUS;
|
---|
284 | winMsg->wParam = (WPARAM)hwndFocus;
|
---|
285 | }
|
---|
286 | else {
|
---|
287 | winMsg->message = WINWM_KILLFOCUS;
|
---|
288 | winMsg->wParam = (WPARAM)hwndFocus;
|
---|
289 | }
|
---|
290 | break;
|
---|
291 | }
|
---|
292 |
|
---|
293 | //**************************************************************************
|
---|
294 | //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
|
---|
295 | //**************************************************************************
|
---|
296 | case WM_BUTTON1DOWN:
|
---|
297 | case WM_BUTTON1UP:
|
---|
298 | case WM_BUTTON1DBLCLK:
|
---|
299 | case WM_BUTTON2DOWN:
|
---|
300 | case WM_BUTTON2UP:
|
---|
301 | case WM_BUTTON2DBLCLK:
|
---|
302 | case WM_BUTTON3DOWN:
|
---|
303 | case WM_BUTTON3UP:
|
---|
304 | case WM_BUTTON3DBLCLK:
|
---|
305 | {
|
---|
306 | ULONG hittest;
|
---|
307 |
|
---|
308 | if(fIsFrameControl) {
|
---|
309 | fTranslateFrameControlMsg = TRUE; //we want a win32 app to see this msg for a frame control
|
---|
310 | }
|
---|
311 |
|
---|
312 | hittest = win32wnd->MsgHitTest(winMsg->pt.x, winMsg->pt.y);
|
---|
313 |
|
---|
314 | //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
|
---|
315 | if(hittest != HTCLIENT_W) {
|
---|
316 | winMsg->message = WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
|
---|
317 | winMsg->wParam = hittest;
|
---|
318 | winMsg->lParam = MAKELONG(winMsg->pt.x, winMsg->pt.y); //screen coordinates
|
---|
319 | }
|
---|
320 | else {
|
---|
321 | point.x = (*(POINTS *)&os2Msg->mp1).x;
|
---|
322 | point.y = (*(POINTS *)&os2Msg->mp1).y;
|
---|
323 | ClientPoint.x = point.x;
|
---|
324 | ClientPoint.y = mapY(os2Msg->hwnd,point.y);
|
---|
325 |
|
---|
326 | winMsg->message = WINWM_LBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
|
---|
327 | winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
|
---|
328 | }
|
---|
329 | break;
|
---|
330 | }
|
---|
331 |
|
---|
332 | case WM_BUTTON2MOTIONSTART:
|
---|
333 | case WM_BUTTON2MOTIONEND:
|
---|
334 | case WM_BUTTON2CLICK:
|
---|
335 | case WM_BUTTON1MOTIONSTART:
|
---|
336 | case WM_BUTTON1MOTIONEND:
|
---|
337 | case WM_BUTTON1CLICK:
|
---|
338 | case WM_BUTTON3MOTIONSTART:
|
---|
339 | case WM_BUTTON3MOTIONEND:
|
---|
340 | case WM_BUTTON3CLICK:
|
---|
341 | goto dummymessage;
|
---|
342 |
|
---|
343 | case WM_MOUSEMOVE:
|
---|
344 | {
|
---|
345 | ULONG keystate = 0, setcursormsg = WINWM_MOUSEMOVE, hittest;
|
---|
346 |
|
---|
347 | if(fIsFrameControl) {
|
---|
348 | fTranslateFrameControlMsg = TRUE; //we want a win32 app to see this msg for a frame control
|
---|
349 | }
|
---|
350 |
|
---|
351 | if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) & 0x8000)
|
---|
352 | keystate |= MK_LBUTTON_W;
|
---|
353 | if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2) & 0x8000)
|
---|
354 | keystate |= MK_RBUTTON_W;
|
---|
355 | if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3) & 0x8000)
|
---|
356 | keystate |= MK_MBUTTON_W;
|
---|
357 | if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT) & 0x8000)
|
---|
358 | keystate |= MK_SHIFT_W;
|
---|
359 | if(WinGetKeyState(HWND_DESKTOP, VK_CTRL) & 0x8000)
|
---|
360 | keystate |= MK_CONTROL_W;
|
---|
361 |
|
---|
362 | hittest = win32wnd->MsgHitTest(winMsg->pt.x, winMsg->pt.y);
|
---|
363 |
|
---|
364 | //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
|
---|
365 | if(hittest != HTCLIENT_W)
|
---|
366 | {
|
---|
367 | setcursormsg = WINWM_NCMOUSEMOVE;
|
---|
368 | winMsg->wParam = (WPARAM)hittest;
|
---|
369 | winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
|
---|
370 | }
|
---|
371 | else
|
---|
372 | {
|
---|
373 | winMsg->wParam = (WPARAM)keystate;
|
---|
374 | winMsg->lParam = MAKELONG(SHORT1FROMMP(os2Msg->mp1),mapY(win32wnd,SHORT2FROMMP(os2Msg->mp1)));
|
---|
375 | }
|
---|
376 | //OS/2 Window coordinates -> Win32 Window coordinates
|
---|
377 | winMsg->message = setcursormsg;
|
---|
378 | break;
|
---|
379 | }
|
---|
380 |
|
---|
381 | case WM_CONTROL:
|
---|
382 | goto dummymessage;
|
---|
383 |
|
---|
384 | case WM_COMMAND:
|
---|
385 | if(SHORT1FROMMP(os2Msg->mp2) == CMDSRC_MENU) {
|
---|
386 | winMsg->message = WINWM_COMMAND;
|
---|
387 | winMsg->wParam = (WPARAM)SHORT1FROMMP(os2Msg->mp1); //id
|
---|
388 | break;
|
---|
389 | }
|
---|
390 | //todo controls
|
---|
391 | goto dummymessage;
|
---|
392 |
|
---|
393 | case WM_SYSCOMMAND:
|
---|
394 | {
|
---|
395 | ULONG x = 0, y = 0;
|
---|
396 | ULONG win32sc;
|
---|
397 |
|
---|
398 | if(SHORT2FROMMP(os2Msg->mp2) == TRUE) {//syscommand caused by mouse action
|
---|
399 | POINTL pointl;
|
---|
400 | WinQueryPointerPos(HWND_DESKTOP, &pointl);
|
---|
401 | x = pointl.x;
|
---|
402 | y = mapScreenY(y);
|
---|
403 | }
|
---|
404 | switch(SHORT1FROMMP(os2Msg->mp1)) {
|
---|
405 | case SC_MOVE:
|
---|
406 | win32sc = SC_MOVE_W;
|
---|
407 | break;
|
---|
408 | case SC_CLOSE:
|
---|
409 | win32sc = SC_CLOSE_W;
|
---|
410 | break;
|
---|
411 | case SC_MAXIMIZE:
|
---|
412 | win32sc = SC_MAXIMIZE_W;
|
---|
413 | break;
|
---|
414 | case SC_MINIMIZE:
|
---|
415 | win32sc = SC_MINIMIZE_W;
|
---|
416 | break;
|
---|
417 | case SC_NEXTFRAME:
|
---|
418 | case SC_NEXTWINDOW:
|
---|
419 | win32sc = SC_NEXTWINDOW_W;
|
---|
420 | break;
|
---|
421 | case SC_RESTORE:
|
---|
422 | win32sc = SC_RESTORE_W;
|
---|
423 | break;
|
---|
424 | case SC_TASKMANAGER:
|
---|
425 | win32sc = SC_TASKLIST_W;
|
---|
426 | break;
|
---|
427 | default:
|
---|
428 | goto dummymessage;
|
---|
429 | }
|
---|
430 | winMsg->message = WINWM_SYSCOMMAND;
|
---|
431 | winMsg->wParam = (WPARAM)win32sc;
|
---|
432 | winMsg->lParam = MAKELONG((USHORT)x, (USHORT)y);
|
---|
433 | break;
|
---|
434 | }
|
---|
435 | case WM_CHAR:
|
---|
436 | {
|
---|
437 | ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
|
---|
438 | ULONG flags = SHORT1FROMMP(os2Msg->mp1);
|
---|
439 | BOOL keyWasPressed;
|
---|
440 | char c;
|
---|
441 |
|
---|
442 | thdb->fTranslated = FALSE;
|
---|
443 | repeatCount = CHAR3FROMMP(os2Msg->mp1);
|
---|
444 | scanCode = CHAR4FROMMP(os2Msg->mp1);
|
---|
445 | keyWasPressed = ((SHORT1FROMMP (os2Msg->mp1) & KC_PREVDOWN) == KC_PREVDOWN);
|
---|
446 |
|
---|
447 | dprintf(("PM: WM_CHAR: %x %x %d %x", SHORT1FROMMP(os2Msg->mp2), SHORT2FROMMP(os2Msg->mp2), repeatCount, scanCode));
|
---|
448 | dprintf(("PM: WM_CHAR: %x", flags));
|
---|
449 |
|
---|
450 | // vitali add begin
|
---|
451 | if ( ( SHORT1FROMMP(os2Msg->mp2) & 0x0FF ) == 0x0E0 )
|
---|
452 | {
|
---|
453 | // an extended key ( arrows, ins, del and so on )
|
---|
454 | // get "virtual" scancode from character code cause
|
---|
455 | // for "regular" keys they are equal
|
---|
456 | scanCode = ( SHORT1FROMMP(os2Msg->mp2) >> 8) & 0x0FF;
|
---|
457 | }
|
---|
458 | // vitali add end
|
---|
459 |
|
---|
460 | // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key
|
---|
461 | // given the OS/2 virtual key and OS/2 character
|
---|
462 |
|
---|
463 | //if (((SHORT1FROMMP (mp1) & KC_CHAR) == KC_CHAR) ||
|
---|
464 | // ((SHORT1FROMMP (mp1) & KC_LONEKEY) == KC_LONEKEY))
|
---|
465 | c = 0;
|
---|
466 | if ((SHORT1FROMMP (os2Msg->mp1) & 0xFF) != 0)
|
---|
467 | {
|
---|
468 | c = SHORT1FROMMP (os2Msg->mp2);
|
---|
469 | if ((c >= 'A') && (c <= 'Z')) {
|
---|
470 | virtualKey = c;
|
---|
471 | goto VirtualKeyFound;
|
---|
472 | }
|
---|
473 | if ((c >='a') && (c <= 'z')) {
|
---|
474 | virtualKey = c - 32; // make it uppercase
|
---|
475 | goto VirtualKeyFound;
|
---|
476 | }
|
---|
477 | if ((c >= '0') && (c <= '9')) {
|
---|
478 | virtualKey = c;
|
---|
479 | goto VirtualKeyFound;
|
---|
480 | }
|
---|
481 | }
|
---|
482 |
|
---|
483 | // convert OS/2 virtual keys to Win32 virtual key
|
---|
484 | if (SHORT2FROMMP (os2Msg->mp2) <= VK_BLK2)
|
---|
485 | virtualKey = virtualKeyTable [SHORT2FROMMP (os2Msg->mp2)];
|
---|
486 |
|
---|
487 | VirtualKeyFound:
|
---|
488 | dprintf (("VIRTUALKEYFOUND:(%x)", virtualKey));
|
---|
489 |
|
---|
490 | winMsg->wParam = virtualKey;
|
---|
491 | winMsg->lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
|
---|
492 | winMsg->lParam |= (scanCode & 0x0FF) << 16; // bit 16-23, scancode
|
---|
493 | win32wnd->setExtendedKey(virtualKey, (ULONG *)&winMsg->lParam);
|
---|
494 |
|
---|
495 | if(!(SHORT1FROMMP(os2Msg->mp1) & KC_ALT))
|
---|
496 | {
|
---|
497 | //
|
---|
498 | // the Alt key is not pressed
|
---|
499 | //
|
---|
500 | if ((flags & KC_KEYUP) == KC_KEYUP) {
|
---|
501 | // send WM_KEYUP message
|
---|
502 |
|
---|
503 | winMsg->message = WINWM_KEYUP;
|
---|
504 | winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
|
---|
505 | winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
|
---|
506 | }
|
---|
507 | else {
|
---|
508 | // send WM_KEYDOWN message
|
---|
509 | winMsg->message = WINWM_KEYDOWN;
|
---|
510 | if (keyWasPressed)
|
---|
511 | winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
|
---|
512 | }
|
---|
513 | }
|
---|
514 | else {
|
---|
515 | //
|
---|
516 | // the Alt key is pressed
|
---|
517 | //
|
---|
518 | if ((flags & KC_KEYUP) == KC_KEYUP) {
|
---|
519 | // send WM_SYSKEYUP message
|
---|
520 |
|
---|
521 | winMsg->message = WINWM_SYSKEYUP;
|
---|
522 | winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
|
---|
523 | winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
|
---|
524 | }
|
---|
525 | else {
|
---|
526 | // send WM_SYSKEYDOWN message
|
---|
527 | winMsg->message = WINWM_SYSKEYDOWN;
|
---|
528 | if (keyWasPressed)
|
---|
529 | winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
|
---|
530 | }
|
---|
531 | }
|
---|
532 |
|
---|
533 | break;
|
---|
534 | }
|
---|
535 |
|
---|
536 | case WM_INITMENU:
|
---|
537 | winMsg->message = WINWM_INITMENU;
|
---|
538 | winMsg->wParam = (WPARAM)os2Msg->mp2; //hMenu
|
---|
539 | break;
|
---|
540 |
|
---|
541 | case WM_MENUSELECT:
|
---|
542 | case WM_MENUEND:
|
---|
543 | case WM_NEXTMENU:
|
---|
544 | goto dummymessage;
|
---|
545 |
|
---|
546 | case WM_TIMER:
|
---|
547 | if (os2Msg->mp2)
|
---|
548 | {
|
---|
549 | BOOL sys;
|
---|
550 | ULONG id;
|
---|
551 |
|
---|
552 | if (TIMER_GetTimerInfo(os2Msg->hwnd,(ULONG)os2Msg->mp1,&sys,&id))
|
---|
553 | {
|
---|
554 | winMsg->wParam = (WPARAM)id;
|
---|
555 | winMsg->message= (sys) ? WINWM_SYSTIMER : WINWM_TIMER;
|
---|
556 | break;
|
---|
557 | }
|
---|
558 | }
|
---|
559 | goto dummymessage; //for caret blinking
|
---|
560 |
|
---|
561 | case WM_SETWINDOWPARAMS:
|
---|
562 | {
|
---|
563 | WNDPARAMS *wndParams = (WNDPARAMS *)os2Msg->mp1;
|
---|
564 |
|
---|
565 | if(wndParams->fsStatus & WPM_TEXT) {
|
---|
566 | winMsg->message = WINWM_SETTEXT;
|
---|
567 | winMsg->lParam = (LPARAM)wndParams->pszText;
|
---|
568 | break;
|
---|
569 | }
|
---|
570 | goto dummymessage;
|
---|
571 | }
|
---|
572 |
|
---|
573 | #if 0
|
---|
574 | case WM_QUERYWINDOWPARAMS:
|
---|
575 | {
|
---|
576 | PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
|
---|
577 | ULONG textlen;
|
---|
578 | PSZ wintext;
|
---|
579 |
|
---|
580 | if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
|
---|
581 | {
|
---|
582 | if(wndpars->fsStatus & WPM_CCHTEXT)
|
---|
583 | wndpars->cchText = win32wnd->MsgGetTextLength();
|
---|
584 | if(wndpars->fsStatus & WPM_TEXT)
|
---|
585 | wndpars->pszText = win32wnd->MsgGetText();
|
---|
586 |
|
---|
587 | wndpars->fsStatus = 0;
|
---|
588 | wndpars->cbCtlData = 0;
|
---|
589 | wndpars->cbPresParams = 0;
|
---|
590 | goto dummymessage;
|
---|
591 | }
|
---|
592 | }
|
---|
593 | #endif
|
---|
594 |
|
---|
595 | case WM_PAINT:
|
---|
596 | {
|
---|
597 | if(fIsFrameControl) {
|
---|
598 | fTranslateFrameControlMsg = TRUE; //we want a win32 app to see this msg for a frame control
|
---|
599 | winMsg->message = WINWM_NCPAINT;
|
---|
600 | }
|
---|
601 | else
|
---|
602 | if(win32wnd->IsIconic()) {
|
---|
603 | winMsg->message = WINWM_PAINTICON;
|
---|
604 | }
|
---|
605 | else winMsg->message = WINWM_PAINT;
|
---|
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:
|
---|
643 | dummymessage:
|
---|
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 | //******************************************************************************
|
---|
656 | BOOL 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 |
|
---|