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