1 | /* $Id: oslibmsg.cpp,v 1.5 1999-10-28 18:22:26 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 | *
|
---|
13 | */
|
---|
14 | #define INCL_WIN
|
---|
15 | #define INCL_PM
|
---|
16 | #define INCL_DOSPROCESS
|
---|
17 | #include <os2.h>
|
---|
18 | #include <os2wrap.h>
|
---|
19 | #include <string.h>
|
---|
20 | #include <misc.h>
|
---|
21 | #include "oslibmsg.h"
|
---|
22 | #include <win32wnd.h>
|
---|
23 | #include "oslibutil.h"
|
---|
24 | #include "timer.h"
|
---|
25 | #include <thread.h>
|
---|
26 | #include <wprocess.h>
|
---|
27 |
|
---|
28 | typedef BOOL (EXPENTRY FNTRANS)(MSG *, QMSG *);
|
---|
29 | typedef FNTRANS *PFNTRANS;
|
---|
30 |
|
---|
31 | typedef struct
|
---|
32 | {
|
---|
33 | ULONG msgOS2;
|
---|
34 | ULONG msgWin32;
|
---|
35 | // PFNTRANS toOS2;
|
---|
36 | // PFNTRANS toWIN32;
|
---|
37 | } MSGTRANSTAB, *PMSGTRANSTAB;
|
---|
38 |
|
---|
39 | #define MAX_MSGTRANSTAB 15
|
---|
40 | MSGTRANSTAB MsgTransTab[MAX_MSGTRANSTAB] = {
|
---|
41 | 0x0000, 0x0000, // WM_NULL, WM_NULL
|
---|
42 | 0x0024, 0x0113, // WM_TIMER, WM_TIMER
|
---|
43 | 0x0029, 0x0010, // WM_CLOSE, WM_CLOSE
|
---|
44 | 0x002a, 0x0012, // WM_QUIT, WM_QUIT
|
---|
45 | 0x0070, 0x0200, // WM_MOUSEMOVE, WM_MOUSEMOVE
|
---|
46 | 0x0071, 0x0201, // WM_BUTTON1DOWN, WM_LBUTTONDOWN
|
---|
47 | 0x0072, 0x0202, // WM_BUTTON1UP, WM_LBUTTONUP
|
---|
48 | 0x0073, 0x0203, // WM_BUTTON1DBLCLK, WM_LBUTTONDBLCLK
|
---|
49 | 0x0074, 0x0204, // WM_BUTTON2DOWN, WM_RBUTTONDOWN
|
---|
50 | 0x0075, 0x0205, // WM_BUTTON2UP, WM_RBUTTONUP
|
---|
51 | 0x0076, 0x0206, // WM_BUTTON2DBLCLK, WM_RBUTTONDBLCLK
|
---|
52 | 0x0077, 0x0207, // WM_BUTTON3DOWN, WM_MBUTTONDOWN
|
---|
53 | 0x0078, 0x0208, // WM_BUTTON3UP, WM_MBUTTONUP
|
---|
54 | 0x0079, 0x0209, // WM_BUTTON3DBLCLK, WM_MBUTTONDBLCLK
|
---|
55 | 0x020a, 0x020a, // WM_???, WM_???
|
---|
56 | };
|
---|
57 |
|
---|
58 | QMSG *MsgThreadPtr = 0;
|
---|
59 |
|
---|
60 | //******************************************************************************
|
---|
61 | //******************************************************************************
|
---|
62 | BOOL OSLibInitMsgQueue()
|
---|
63 | {
|
---|
64 | if(DosAllocThreadLocalMemory(sizeof(QMSG)/sizeof(ULONG), (PULONG *)&MsgThreadPtr) != 0)
|
---|
65 | {
|
---|
66 | dprintf(("OSLibInitMsgQueue: local thread memory alloc failed!!"));
|
---|
67 | DebugInt3();
|
---|
68 | return FALSE;
|
---|
69 | }
|
---|
70 | return TRUE;
|
---|
71 | }
|
---|
72 | //******************************************************************************
|
---|
73 | //******************************************************************************
|
---|
74 | void WinToOS2MsgTranslate(MSG *winMsg, QMSG *os2Msg, BOOL isUnicode)
|
---|
75 | {
|
---|
76 | int i;
|
---|
77 |
|
---|
78 | memcpy(os2Msg, winMsg, sizeof(MSG));
|
---|
79 | os2Msg->hwnd = Win32Window::Win32ToOS2Handle(winMsg->hwnd);
|
---|
80 | os2Msg->reserved = 0;
|
---|
81 | for(i=0;i<MAX_MSGTRANSTAB;i++)
|
---|
82 | {
|
---|
83 | if(MsgTransTab[i].msgWin32 == winMsg->message)
|
---|
84 | {
|
---|
85 | os2Msg->msg = MsgTransTab[i].msgOS2;
|
---|
86 | break;
|
---|
87 | }
|
---|
88 | }
|
---|
89 | }
|
---|
90 | //******************************************************************************
|
---|
91 | //******************************************************************************
|
---|
92 | void OS2ToWinMsgTranslate(QMSG *os2Msg, MSG *winMsg, BOOL isUnicode)
|
---|
93 | {
|
---|
94 | int i;
|
---|
95 |
|
---|
96 | memcpy(winMsg, os2Msg, sizeof(MSG));
|
---|
97 | winMsg->hwnd = Win32Window::OS2ToWin32Handle(os2Msg->hwnd);
|
---|
98 | for(i=0;i<MAX_MSGTRANSTAB;i++)
|
---|
99 | {
|
---|
100 | if(MsgTransTab[i].msgOS2 == os2Msg->msg)
|
---|
101 | {
|
---|
102 | winMsg->message = MsgTransTab[i].msgWin32;
|
---|
103 | break;
|
---|
104 | }
|
---|
105 | }
|
---|
106 | }
|
---|
107 | //******************************************************************************
|
---|
108 | //TODO!!!
|
---|
109 | //Signal that the incoming messages in pmwindow need to be translated
|
---|
110 | //(i.e. PM WM_CHAR when translated generates WM_CHAR messages, otherwise
|
---|
111 | // WM_KEYUP/DOWN (etc))
|
---|
112 | //******************************************************************************
|
---|
113 | ULONG TranslateWinMsg(ULONG msg)
|
---|
114 | {
|
---|
115 | THDB *thdb;
|
---|
116 |
|
---|
117 | thdb = GetThreadTHDB();
|
---|
118 | if(thdb) {
|
---|
119 | thdb->fMsgTranslated = TRUE;
|
---|
120 | }
|
---|
121 |
|
---|
122 | for(int i=0;i<MAX_MSGTRANSTAB;i++)
|
---|
123 | {
|
---|
124 | if(MsgTransTab[i].msgWin32 == msg)
|
---|
125 | {
|
---|
126 | return MsgTransTab[i].msgOS2;
|
---|
127 | }
|
---|
128 | }
|
---|
129 |
|
---|
130 | return 0;
|
---|
131 | }
|
---|
132 | //******************************************************************************
|
---|
133 | //******************************************************************************
|
---|
134 | void OSLibWinPostQuitMessage(ULONG nExitCode)
|
---|
135 | {
|
---|
136 | APIRET rc;
|
---|
137 |
|
---|
138 | rc = WinPostQueueMsg(NULLHANDLE, WM_QUIT, (MPARAM)nExitCode, 0);
|
---|
139 | dprintf(("WinPostQueueMsg %d returned %d", nExitCode, rc));
|
---|
140 | }
|
---|
141 | //******************************************************************************
|
---|
142 | //******************************************************************************
|
---|
143 | LONG OSLibWinDispatchMsg(MSG *msg, BOOL isUnicode)
|
---|
144 | {
|
---|
145 | BOOL eaten = 0;
|
---|
146 |
|
---|
147 | //TODO: What to do if app changed msg? (translate)
|
---|
148 | // WinToOS2MsgTranslate(msg, &qmsg, isUnicode);
|
---|
149 |
|
---|
150 | //SvL: Some apps use PeeKMessage(remove) & DispatchMessage instead of
|
---|
151 | // GetMessage/DispatchMessage
|
---|
152 | if (MsgThreadPtr->msg == WM_TIMER)
|
---|
153 | eaten = TIMER_HandleTimer (MsgThreadPtr);
|
---|
154 |
|
---|
155 | if(eaten) return 0;
|
---|
156 |
|
---|
157 | return (LONG)WinDispatchMsg(GetThreadHAB(), MsgThreadPtr);
|
---|
158 | }
|
---|
159 | //******************************************************************************
|
---|
160 | //******************************************************************************
|
---|
161 | BOOL OSLibWinGetMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax,
|
---|
162 | BOOL isUnicode)
|
---|
163 | {
|
---|
164 | BOOL rc, eaten;
|
---|
165 |
|
---|
166 | do {
|
---|
167 | eaten = FALSE;
|
---|
168 | rc = WinGetMsg(GetThreadHAB(), MsgThreadPtr, TranslateWinMsg(uMsgFilterMin), TranslateWinMsg(uMsgFilterMax), 0);
|
---|
169 | if (MsgThreadPtr->msg == WM_TIMER)
|
---|
170 | eaten = TIMER_HandleTimer (MsgThreadPtr);
|
---|
171 | } while (eaten);
|
---|
172 |
|
---|
173 | OS2ToWinMsgTranslate(MsgThreadPtr, pMsg, isUnicode);
|
---|
174 | return rc;
|
---|
175 | }
|
---|
176 | //******************************************************************************
|
---|
177 | //******************************************************************************
|
---|
178 | BOOL OSLibWinPeekMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax,
|
---|
179 | BOOL fRemove, BOOL isUnicode)
|
---|
180 | {
|
---|
181 | BOOL rc;
|
---|
182 |
|
---|
183 | rc = WinPeekMsg(GetThreadHAB(), MsgThreadPtr, hwnd, TranslateWinMsg(uMsgFilterMin),
|
---|
184 | TranslateWinMsg(uMsgFilterMax), (fRemove == MSG_REMOVE) ? PM_REMOVE : PM_NOREMOVE);
|
---|
185 | OS2ToWinMsgTranslate(MsgThreadPtr, pMsg, isUnicode);
|
---|
186 | return rc;
|
---|
187 | }
|
---|
188 | //******************************************************************************
|
---|
189 | //******************************************************************************
|
---|