1 | /* $Id: oslibmsg.cpp,v 1.14 1999-12-05 00:31:47 sandervl Exp $ */
|
---|
2 | /*
|
---|
3 | * Window message translation functions for OS/2
|
---|
4 | *
|
---|
5 | *
|
---|
6 | * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
10 | *
|
---|
11 | * TODO: Simply copy for now. Need to make a real translation
|
---|
12 | * TODO: Filter translation isn't correct for posted messages
|
---|
13 | *
|
---|
14 | */
|
---|
15 | #define INCL_WIN
|
---|
16 | #define INCL_PM
|
---|
17 | #define INCL_DOSPROCESS
|
---|
18 | #include <os2.h>
|
---|
19 | #include <os2wrap.h>
|
---|
20 | #include <string.h>
|
---|
21 | #include <misc.h>
|
---|
22 | #include "oslibmsg.h"
|
---|
23 | #include <win32wnd.h>
|
---|
24 | #include "oslibutil.h"
|
---|
25 | #include "timer.h"
|
---|
26 | #include <thread.h>
|
---|
27 | #include <wprocess.h>
|
---|
28 | #include "pmwindow.h"
|
---|
29 |
|
---|
30 | typedef BOOL (EXPENTRY FNTRANS)(MSG *, QMSG *);
|
---|
31 | typedef FNTRANS *PFNTRANS;
|
---|
32 |
|
---|
33 | typedef struct
|
---|
34 | {
|
---|
35 | ULONG msgOS2;
|
---|
36 | ULONG msgWin32;
|
---|
37 | // PFNTRANS toOS2;
|
---|
38 | // PFNTRANS toWIN32;
|
---|
39 | } MSGTRANSTAB, *PMSGTRANSTAB;
|
---|
40 |
|
---|
41 | MSGTRANSTAB MsgTransTab[] = {
|
---|
42 | WM_NULL, WINWM_NULL,
|
---|
43 | WM_CREATE, WINWM_CREATE,
|
---|
44 | WM_DESTROY, WINWM_DESTROY,
|
---|
45 | WM_TIMER, WINWM_TIMER,
|
---|
46 | WM_CLOSE, WINWM_CLOSE,
|
---|
47 | WM_QUIT, WINWM_QUIT,
|
---|
48 |
|
---|
49 | WM_ENABLE, WINWM_ENABLE,
|
---|
50 | WM_SHOW, WINWM_SHOWWINDOW,
|
---|
51 | WM_MOVE, WINWM_MOVE,
|
---|
52 | WM_SIZE, WINWM_SIZE,
|
---|
53 | //
|
---|
54 | WM_HITTEST, WINWM_NCHITTEST,
|
---|
55 | //
|
---|
56 | WM_ACTIVATE, WINWM_ACTIVATE,
|
---|
57 | WM_SETFOCUS, WINWM_SETFOCUS,
|
---|
58 | //
|
---|
59 | WM_COMMAND, WINWM_COMMAND,
|
---|
60 | WM_SYSCOMMAND, WINWM_SYSCOMMAND,
|
---|
61 | //
|
---|
62 | WM_PAINT, WINWM_PAINT,
|
---|
63 | WM_TIMER, WINWM_TIMER,
|
---|
64 | //
|
---|
65 | WM_CLOSE, WINWM_CLOSE,
|
---|
66 | WM_QUIT, WINWM_QUIT,
|
---|
67 | //
|
---|
68 | WM_CONTROL, WINWM_COMMAND,
|
---|
69 | //
|
---|
70 | WM_MOUSEMOVE, WINWM_MOUSEMOVE,
|
---|
71 | WM_BUTTON1DOWN, WINWM_LBUTTONDOWN,
|
---|
72 | WM_BUTTON1UP, WINWM_LBUTTONUP,
|
---|
73 | WM_BUTTON1DBLCLK, WINWM_LBUTTONDBLCLK,
|
---|
74 | WM_BUTTON2DOWN, WINWM_RBUTTONDOWN,
|
---|
75 | WM_BUTTON2UP, WINWM_RBUTTONUP,
|
---|
76 | WM_BUTTON2DBLCLK, WINWM_RBUTTONDBLCLK,
|
---|
77 | WM_BUTTON3DOWN, WINWM_MBUTTONDOWN,
|
---|
78 | WM_BUTTON3UP, WINWM_MBUTTONUP,
|
---|
79 | WM_BUTTON3DBLCLK, WINWM_MBUTTONDBLCLK,
|
---|
80 | 0x020a, 0x020a, // WM_???, WM_???
|
---|
81 | WM_CHAR, WINWM_CHAR,
|
---|
82 |
|
---|
83 | //TODO: Needs better translation!
|
---|
84 | WM_CHAR, WINWM_KEYDOWN,
|
---|
85 | WM_CHAR, WINWM_KEYUP,
|
---|
86 | WM_CHAR, WINWM_SYSKEYDOWN,
|
---|
87 | WM_CHAR, WINWM_SYSKEYUP,
|
---|
88 | WM_CHAR, WINWM_KEYLAST
|
---|
89 | };
|
---|
90 | #define MAX_MSGTRANSTAB (sizeof(MsgTransTab)/sizeof(MsgTransTab[0]))
|
---|
91 |
|
---|
92 | QMSG *MsgThreadPtr = 0;
|
---|
93 |
|
---|
94 | //******************************************************************************
|
---|
95 | //******************************************************************************
|
---|
96 | BOOL OSLibInitMsgQueue()
|
---|
97 | {
|
---|
98 | if(DosAllocThreadLocalMemory(sizeof(QMSG)/sizeof(ULONG), (PULONG *)&MsgThreadPtr) != 0)
|
---|
99 | {
|
---|
100 | dprintf(("OSLibInitMsgQueue: local thread memory alloc failed!!"));
|
---|
101 | DebugInt3();
|
---|
102 | return FALSE;
|
---|
103 | }
|
---|
104 | return TRUE;
|
---|
105 | }
|
---|
106 | //******************************************************************************
|
---|
107 | //******************************************************************************
|
---|
108 | void WinToOS2MsgTranslate(MSG *winMsg, QMSG *os2Msg, BOOL isUnicode)
|
---|
109 | {
|
---|
110 | int i;
|
---|
111 |
|
---|
112 | memcpy(os2Msg, winMsg, sizeof(MSG));
|
---|
113 | os2Msg->hwnd = Win32Window::Win32ToOS2Handle(winMsg->hwnd);
|
---|
114 | os2Msg->reserved = 0;
|
---|
115 | for(i=0;i<MAX_MSGTRANSTAB;i++)
|
---|
116 | {
|
---|
117 | if(MsgTransTab[i].msgWin32 == winMsg->message)
|
---|
118 | {
|
---|
119 | os2Msg->msg = MsgTransTab[i].msgOS2;
|
---|
120 | break;
|
---|
121 | }
|
---|
122 | }
|
---|
123 | }
|
---|
124 | //******************************************************************************
|
---|
125 | //******************************************************************************
|
---|
126 | void OS2ToWinMsgTranslate(QMSG *os2Msg, MSG *winMsg, BOOL isUnicode)
|
---|
127 | {
|
---|
128 | POSTMSG_PACKET *packet;
|
---|
129 | int i;
|
---|
130 |
|
---|
131 | memcpy(winMsg, os2Msg, sizeof(MSG));
|
---|
132 | winMsg->hwnd = Win32Window::OS2ToWin32Handle(os2Msg->hwnd);
|
---|
133 |
|
---|
134 | if(os2Msg->msg == WIN32APP_POSTMSG) {
|
---|
135 | packet = (POSTMSG_PACKET *)os2Msg->mp2;
|
---|
136 | if(packet && (ULONG)os2Msg->mp1 == WIN32PM_MAGIC) {
|
---|
137 | winMsg->message = packet->Msg;
|
---|
138 | winMsg->wParam = packet->wParam;
|
---|
139 | winMsg->lParam = packet->lParam;
|
---|
140 | }
|
---|
141 | return;
|
---|
142 | }
|
---|
143 | for(i=0;i<MAX_MSGTRANSTAB;i++)
|
---|
144 | {
|
---|
145 | if(MsgTransTab[i].msgOS2 == os2Msg->msg)
|
---|
146 | {
|
---|
147 | winMsg->message = MsgTransTab[i].msgWin32;
|
---|
148 | break;
|
---|
149 | }
|
---|
150 | }
|
---|
151 | }
|
---|
152 | //******************************************************************************
|
---|
153 | //TODO!!!
|
---|
154 | //Signal that the incoming messages in pmwindow need to be translated
|
---|
155 | //(i.e. PM WM_CHAR when translated generates WM_CHAR messages, otherwise
|
---|
156 | // WM_KEYUP/DOWN (etc))
|
---|
157 | //******************************************************************************
|
---|
158 | ULONG TranslateWinMsg(ULONG msg)
|
---|
159 | {
|
---|
160 | POSTMSG_PACKET *packet;
|
---|
161 | THDB *thdb;
|
---|
162 |
|
---|
163 | thdb = GetThreadTHDB();
|
---|
164 | if(thdb) {
|
---|
165 | thdb->fMsgTranslated = TRUE;
|
---|
166 | }
|
---|
167 |
|
---|
168 | if(msg >= WINWM_USER)
|
---|
169 | return WIN32APP_POSTMSG;
|
---|
170 |
|
---|
171 | for(int i=0;i<MAX_MSGTRANSTAB;i++)
|
---|
172 | {
|
---|
173 | if(MsgTransTab[i].msgWin32 == msg)
|
---|
174 | {
|
---|
175 | return MsgTransTab[i].msgOS2;
|
---|
176 | }
|
---|
177 | }
|
---|
178 |
|
---|
179 | return 0;
|
---|
180 | }
|
---|
181 | //******************************************************************************
|
---|
182 | //******************************************************************************
|
---|
183 | void OSLibWinPostQuitMessage(ULONG nExitCode)
|
---|
184 | {
|
---|
185 | APIRET rc;
|
---|
186 |
|
---|
187 | rc = WinPostQueueMsg(NULLHANDLE, WM_QUIT, (MPARAM)nExitCode, 0);
|
---|
188 | dprintf(("WinPostQueueMsg %d returned %d", nExitCode, rc));
|
---|
189 | }
|
---|
190 | //******************************************************************************
|
---|
191 | //******************************************************************************
|
---|
192 | LONG OSLibWinDispatchMsg(MSG *msg, BOOL isUnicode)
|
---|
193 | {
|
---|
194 | BOOL eaten = 0;
|
---|
195 |
|
---|
196 | //TODO: What to do if app changed msg? (translate)
|
---|
197 | // WinToOS2MsgTranslate(msg, &qmsg, isUnicode);
|
---|
198 |
|
---|
199 | //SvL: Some apps use PeeKMessage(remove) & DispatchMessage instead of
|
---|
200 | // GetMessage/DispatchMessage
|
---|
201 | if (MsgThreadPtr->msg == WM_TIMER)
|
---|
202 | eaten = TIMER_HandleTimer (MsgThreadPtr);
|
---|
203 |
|
---|
204 | if(eaten) return 0;
|
---|
205 |
|
---|
206 | return (LONG)WinDispatchMsg(GetThreadHAB(), MsgThreadPtr);
|
---|
207 | }
|
---|
208 | //******************************************************************************
|
---|
209 | //******************************************************************************
|
---|
210 | BOOL OSLibWinGetMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax,
|
---|
211 | BOOL isUnicode)
|
---|
212 | {
|
---|
213 | BOOL rc, eaten;
|
---|
214 |
|
---|
215 | do {
|
---|
216 | eaten = FALSE;
|
---|
217 | rc = WinGetMsg(GetThreadHAB(), MsgThreadPtr, TranslateWinMsg(uMsgFilterMin), TranslateWinMsg(uMsgFilterMax), 0);
|
---|
218 | if (MsgThreadPtr->msg == WM_TIMER)
|
---|
219 | eaten = TIMER_HandleTimer (MsgThreadPtr);
|
---|
220 | } while (eaten);
|
---|
221 |
|
---|
222 | OS2ToWinMsgTranslate(MsgThreadPtr, pMsg, isUnicode);
|
---|
223 | return rc;
|
---|
224 | }
|
---|
225 | //******************************************************************************
|
---|
226 | //******************************************************************************
|
---|
227 | BOOL OSLibWinPeekMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax,
|
---|
228 | BOOL fRemove, BOOL isUnicode)
|
---|
229 | {
|
---|
230 | BOOL rc;
|
---|
231 |
|
---|
232 | rc = WinPeekMsg(GetThreadHAB(), MsgThreadPtr, hwnd, TranslateWinMsg(uMsgFilterMin),
|
---|
233 | TranslateWinMsg(uMsgFilterMax), (fRemove == MSG_REMOVE) ? PM_REMOVE : PM_NOREMOVE);
|
---|
234 | OS2ToWinMsgTranslate(MsgThreadPtr, pMsg, isUnicode);
|
---|
235 | return rc;
|
---|
236 | }
|
---|
237 | //******************************************************************************
|
---|
238 | //******************************************************************************
|
---|
239 | ULONG OSLibWinQueryMsgTime()
|
---|
240 | {
|
---|
241 | return WinQueryMsgTime(GetThreadHAB());
|
---|
242 | }
|
---|
243 | //******************************************************************************
|
---|
244 | //******************************************************************************
|
---|
245 | BOOL OSLibWinWaitMessage()
|
---|
246 | {
|
---|
247 | return WinWaitMsg(GetThreadHAB(), 0, 0);
|
---|
248 | }
|
---|
249 | //******************************************************************************
|
---|
250 | //TODO: QS_HOTKEY
|
---|
251 | //******************************************************************************
|
---|
252 | ULONG OSLibWinQueryQueueStatus()
|
---|
253 | {
|
---|
254 | ULONG statusOS2, statusWin32;
|
---|
255 |
|
---|
256 | statusOS2 = WinQueryQueueStatus(HWND_DESKTOP);
|
---|
257 |
|
---|
258 | if(statusOS2 & QS_KEY)
|
---|
259 | statusWin32 |= QS_KEY_W;
|
---|
260 | if(statusOS2 & QS_MOUSEBUTTON)
|
---|
261 | statusWin32 |= QS_MOUSEBUTTON_W;
|
---|
262 | if(statusOS2 & QS_MOUSEMOVE)
|
---|
263 | statusWin32 |= QS_MOUSEMOVE_W;
|
---|
264 | if(statusOS2 & QS_TIMER)
|
---|
265 | statusWin32 |= QS_TIMER_W;
|
---|
266 | if(statusOS2 & QS_PAINT)
|
---|
267 | statusWin32 |= QS_PAINT_W;
|
---|
268 | if(statusOS2 & QS_POSTMSG)
|
---|
269 | statusWin32 |= QS_POSTMESSAGE_W;
|
---|
270 | if(statusOS2 & QS_SENDMSG)
|
---|
271 | statusWin32 |= QS_SENDMESSAGE_W;
|
---|
272 |
|
---|
273 | return statusWin32;
|
---|
274 | }
|
---|
275 | //******************************************************************************
|
---|
276 | //******************************************************************************
|
---|
277 | BOOL OSLibWinInSendMessage()
|
---|
278 | {
|
---|
279 | return WinInSendMsg(GetThreadHAB());
|
---|
280 | }
|
---|
281 | //******************************************************************************
|
---|
282 | //******************************************************************************
|
---|
283 | DWORD OSLibWinGetMessagePos()
|
---|
284 | {
|
---|
285 | APIRET rc;
|
---|
286 | POINTL ptl;
|
---|
287 |
|
---|
288 | rc = WinQueryMsgPos(GetThreadHAB(), &ptl);
|
---|
289 | if(!rc) {
|
---|
290 | return 0;
|
---|
291 | }
|
---|
292 | //convert to windows coordinates
|
---|
293 | return MAKEULONG(ptl.x, ScreenHeight - ptl.y - 1);
|
---|
294 | }
|
---|
295 | //******************************************************************************
|
---|
296 | //******************************************************************************
|
---|
297 | LONG OSLibWinGetMessageTime()
|
---|
298 | {
|
---|
299 | return (LONG)WinQueryMsgTime(GetThreadHAB());
|
---|
300 | }
|
---|
301 | //******************************************************************************
|
---|
302 | //******************************************************************************
|
---|
303 | BOOL OSLibWinReplyMessage(ULONG result)
|
---|
304 | {
|
---|
305 | return (BOOL)WinReplyMsg( NULLHANDLE, NULLHANDLE, HMQ_CURRENT, (MRESULT)result);
|
---|
306 | }
|
---|
307 | //******************************************************************************
|
---|
308 | //******************************************************************************
|
---|