| 1 | /* $Id: oslibmsg.cpp,v 1.13 1999-11-27 00:10:20 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 |
|
|---|
| 29 | typedef BOOL (EXPENTRY FNTRANS)(MSG *, QMSG *);
|
|---|
| 30 | typedef FNTRANS *PFNTRANS;
|
|---|
| 31 |
|
|---|
| 32 | typedef struct
|
|---|
| 33 | {
|
|---|
| 34 | ULONG msgOS2;
|
|---|
| 35 | ULONG msgWin32;
|
|---|
| 36 | // PFNTRANS toOS2;
|
|---|
| 37 | // PFNTRANS toWIN32;
|
|---|
| 38 | } MSGTRANSTAB, *PMSGTRANSTAB;
|
|---|
| 39 |
|
|---|
| 40 | MSGTRANSTAB MsgTransTab[] = {
|
|---|
| 41 | WM_NULL, WINWM_NULL,
|
|---|
| 42 | WM_CREATE, WINWM_CREATE,
|
|---|
| 43 | WM_DESTROY, WINWM_DESTROY,
|
|---|
| 44 | WM_TIMER, WINWM_TIMER,
|
|---|
| 45 | WM_CLOSE, WINWM_CLOSE,
|
|---|
| 46 | WM_QUIT, WINWM_QUIT,
|
|---|
| 47 |
|
|---|
| 48 | WM_ENABLE, WINWM_ENABLE,
|
|---|
| 49 | WM_SHOW, WINWM_SHOWWINDOW,
|
|---|
| 50 | WM_MOVE, WINWM_MOVE,
|
|---|
| 51 | WM_SIZE, WINWM_SIZE,
|
|---|
| 52 | //
|
|---|
| 53 | WM_HITTEST, WINWM_NCHITTEST,
|
|---|
| 54 | //
|
|---|
| 55 | WM_ACTIVATE, WINWM_ACTIVATE,
|
|---|
| 56 | WM_SETFOCUS, WINWM_SETFOCUS,
|
|---|
| 57 | //
|
|---|
| 58 | WM_COMMAND, WINWM_COMMAND,
|
|---|
| 59 | WM_SYSCOMMAND, WINWM_SYSCOMMAND,
|
|---|
| 60 | //
|
|---|
| 61 | WM_PAINT, WINWM_PAINT,
|
|---|
| 62 | WM_TIMER, WINWM_TIMER,
|
|---|
| 63 | //
|
|---|
| 64 | WM_CLOSE, WINWM_CLOSE,
|
|---|
| 65 | WM_QUIT, WINWM_QUIT,
|
|---|
| 66 | //
|
|---|
| 67 | WM_CONTROL, WINWM_COMMAND,
|
|---|
| 68 | //
|
|---|
| 69 | WM_MOUSEMOVE, WINWM_MOUSEMOVE,
|
|---|
| 70 | WM_BUTTON1DOWN, WINWM_LBUTTONDOWN,
|
|---|
| 71 | WM_BUTTON1UP, WINWM_LBUTTONUP,
|
|---|
| 72 | WM_BUTTON1DBLCLK, WINWM_LBUTTONDBLCLK,
|
|---|
| 73 | WM_BUTTON2DOWN, WINWM_RBUTTONDOWN,
|
|---|
| 74 | WM_BUTTON2UP, WINWM_RBUTTONUP,
|
|---|
| 75 | WM_BUTTON2DBLCLK, WINWM_RBUTTONDBLCLK,
|
|---|
| 76 | WM_BUTTON3DOWN, WINWM_MBUTTONDOWN,
|
|---|
| 77 | WM_BUTTON3UP, WINWM_MBUTTONUP,
|
|---|
| 78 | WM_BUTTON3DBLCLK, WINWM_MBUTTONDBLCLK,
|
|---|
| 79 | 0x020a, 0x020a, // WM_???, WM_???
|
|---|
| 80 | WM_CHAR, WINWM_CHAR,
|
|---|
| 81 |
|
|---|
| 82 | //TODO: Needs better translation!
|
|---|
| 83 | WM_CHAR, WINWM_KEYDOWN,
|
|---|
| 84 | WM_CHAR, WINWM_KEYUP,
|
|---|
| 85 | WM_CHAR, WINWM_SYSKEYDOWN,
|
|---|
| 86 | WM_CHAR, WINWM_SYSKEYUP,
|
|---|
| 87 | WM_CHAR, WINWM_KEYLAST
|
|---|
| 88 | };
|
|---|
| 89 | #define MAX_MSGTRANSTAB (sizeof(MsgTransTab)/sizeof(MsgTransTab[0]))
|
|---|
| 90 |
|
|---|
| 91 | QMSG *MsgThreadPtr = 0;
|
|---|
| 92 |
|
|---|
| 93 | //******************************************************************************
|
|---|
| 94 | //******************************************************************************
|
|---|
| 95 | BOOL OSLibInitMsgQueue()
|
|---|
| 96 | {
|
|---|
| 97 | if(DosAllocThreadLocalMemory(sizeof(QMSG)/sizeof(ULONG), (PULONG *)&MsgThreadPtr) != 0)
|
|---|
| 98 | {
|
|---|
| 99 | dprintf(("OSLibInitMsgQueue: local thread memory alloc failed!!"));
|
|---|
| 100 | DebugInt3();
|
|---|
| 101 | return FALSE;
|
|---|
| 102 | }
|
|---|
| 103 | return TRUE;
|
|---|
| 104 | }
|
|---|
| 105 | //******************************************************************************
|
|---|
| 106 | //******************************************************************************
|
|---|
| 107 | void WinToOS2MsgTranslate(MSG *winMsg, QMSG *os2Msg, BOOL isUnicode)
|
|---|
| 108 | {
|
|---|
| 109 | int i;
|
|---|
| 110 |
|
|---|
| 111 | memcpy(os2Msg, winMsg, sizeof(MSG));
|
|---|
| 112 | os2Msg->hwnd = Win32Window::Win32ToOS2Handle(winMsg->hwnd);
|
|---|
| 113 | os2Msg->reserved = 0;
|
|---|
| 114 | for(i=0;i<MAX_MSGTRANSTAB;i++)
|
|---|
| 115 | {
|
|---|
| 116 | if(MsgTransTab[i].msgWin32 == winMsg->message)
|
|---|
| 117 | {
|
|---|
| 118 | os2Msg->msg = MsgTransTab[i].msgOS2;
|
|---|
| 119 | break;
|
|---|
| 120 | }
|
|---|
| 121 | }
|
|---|
| 122 | }
|
|---|
| 123 | //******************************************************************************
|
|---|
| 124 | //******************************************************************************
|
|---|
| 125 | void OS2ToWinMsgTranslate(QMSG *os2Msg, MSG *winMsg, BOOL isUnicode)
|
|---|
| 126 | {
|
|---|
| 127 | POSTMSG_PACKET *packet;
|
|---|
| 128 | int i;
|
|---|
| 129 |
|
|---|
| 130 | memcpy(winMsg, os2Msg, sizeof(MSG));
|
|---|
| 131 | winMsg->hwnd = Win32Window::OS2ToWin32Handle(os2Msg->hwnd);
|
|---|
| 132 |
|
|---|
| 133 | if(os2Msg->msg == WIN32APP_POSTMSG) {
|
|---|
| 134 | packet = (POSTMSG_PACKET *)os2Msg->mp2;
|
|---|
| 135 | if(packet && (ULONG)os2Msg->mp1 == WIN32PM_MAGIC) {
|
|---|
| 136 | winMsg->message = packet->Msg;
|
|---|
| 137 | winMsg->wParam = packet->wParam;
|
|---|
| 138 | winMsg->lParam = packet->lParam;
|
|---|
| 139 | }
|
|---|
| 140 | return;
|
|---|
| 141 | }
|
|---|
| 142 | for(i=0;i<MAX_MSGTRANSTAB;i++)
|
|---|
| 143 | {
|
|---|
| 144 | if(MsgTransTab[i].msgOS2 == os2Msg->msg)
|
|---|
| 145 | {
|
|---|
| 146 | winMsg->message = MsgTransTab[i].msgWin32;
|
|---|
| 147 | break;
|
|---|
| 148 | }
|
|---|
| 149 | }
|
|---|
| 150 | }
|
|---|
| 151 | //******************************************************************************
|
|---|
| 152 | //TODO!!!
|
|---|
| 153 | //Signal that the incoming messages in pmwindow need to be translated
|
|---|
| 154 | //(i.e. PM WM_CHAR when translated generates WM_CHAR messages, otherwise
|
|---|
| 155 | // WM_KEYUP/DOWN (etc))
|
|---|
| 156 | //******************************************************************************
|
|---|
| 157 | ULONG TranslateWinMsg(ULONG msg)
|
|---|
| 158 | {
|
|---|
| 159 | POSTMSG_PACKET *packet;
|
|---|
| 160 | THDB *thdb;
|
|---|
| 161 |
|
|---|
| 162 | thdb = GetThreadTHDB();
|
|---|
| 163 | if(thdb) {
|
|---|
| 164 | thdb->fMsgTranslated = TRUE;
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | if(msg >= WINWM_USER)
|
|---|
| 168 | return WIN32APP_POSTMSG;
|
|---|
| 169 |
|
|---|
| 170 | for(int i=0;i<MAX_MSGTRANSTAB;i++)
|
|---|
| 171 | {
|
|---|
| 172 | if(MsgTransTab[i].msgWin32 == msg)
|
|---|
| 173 | {
|
|---|
| 174 | return MsgTransTab[i].msgOS2;
|
|---|
| 175 | }
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | return 0;
|
|---|
| 179 | }
|
|---|
| 180 | //******************************************************************************
|
|---|
| 181 | //******************************************************************************
|
|---|
| 182 | void OSLibWinPostQuitMessage(ULONG nExitCode)
|
|---|
| 183 | {
|
|---|
| 184 | APIRET rc;
|
|---|
| 185 |
|
|---|
| 186 | rc = WinPostQueueMsg(NULLHANDLE, WM_QUIT, (MPARAM)nExitCode, 0);
|
|---|
| 187 | dprintf(("WinPostQueueMsg %d returned %d", nExitCode, rc));
|
|---|
| 188 | }
|
|---|
| 189 | //******************************************************************************
|
|---|
| 190 | //******************************************************************************
|
|---|
| 191 | LONG OSLibWinDispatchMsg(MSG *msg, BOOL isUnicode)
|
|---|
| 192 | {
|
|---|
| 193 | BOOL eaten = 0;
|
|---|
| 194 |
|
|---|
| 195 | //TODO: What to do if app changed msg? (translate)
|
|---|
| 196 | // WinToOS2MsgTranslate(msg, &qmsg, isUnicode);
|
|---|
| 197 |
|
|---|
| 198 | //SvL: Some apps use PeeKMessage(remove) & DispatchMessage instead of
|
|---|
| 199 | // GetMessage/DispatchMessage
|
|---|
| 200 | if (MsgThreadPtr->msg == WM_TIMER)
|
|---|
| 201 | eaten = TIMER_HandleTimer (MsgThreadPtr);
|
|---|
| 202 |
|
|---|
| 203 | if(eaten) return 0;
|
|---|
| 204 |
|
|---|
| 205 | return (LONG)WinDispatchMsg(GetThreadHAB(), MsgThreadPtr);
|
|---|
| 206 | }
|
|---|
| 207 | //******************************************************************************
|
|---|
| 208 | //******************************************************************************
|
|---|
| 209 | BOOL OSLibWinGetMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax,
|
|---|
| 210 | BOOL isUnicode)
|
|---|
| 211 | {
|
|---|
| 212 | BOOL rc, eaten;
|
|---|
| 213 |
|
|---|
| 214 | do {
|
|---|
| 215 | eaten = FALSE;
|
|---|
| 216 | rc = WinGetMsg(GetThreadHAB(), MsgThreadPtr, TranslateWinMsg(uMsgFilterMin), TranslateWinMsg(uMsgFilterMax), 0);
|
|---|
| 217 | if (MsgThreadPtr->msg == WM_TIMER)
|
|---|
| 218 | eaten = TIMER_HandleTimer (MsgThreadPtr);
|
|---|
| 219 | } while (eaten);
|
|---|
| 220 |
|
|---|
| 221 | OS2ToWinMsgTranslate(MsgThreadPtr, pMsg, isUnicode);
|
|---|
| 222 | return rc;
|
|---|
| 223 | }
|
|---|
| 224 | //******************************************************************************
|
|---|
| 225 | //******************************************************************************
|
|---|
| 226 | BOOL OSLibWinPeekMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax,
|
|---|
| 227 | BOOL fRemove, BOOL isUnicode)
|
|---|
| 228 | {
|
|---|
| 229 | BOOL rc;
|
|---|
| 230 |
|
|---|
| 231 | rc = WinPeekMsg(GetThreadHAB(), MsgThreadPtr, hwnd, TranslateWinMsg(uMsgFilterMin),
|
|---|
| 232 | TranslateWinMsg(uMsgFilterMax), (fRemove == MSG_REMOVE) ? PM_REMOVE : PM_NOREMOVE);
|
|---|
| 233 | OS2ToWinMsgTranslate(MsgThreadPtr, pMsg, isUnicode);
|
|---|
| 234 | return rc;
|
|---|
| 235 | }
|
|---|
| 236 | //******************************************************************************
|
|---|
| 237 | //******************************************************************************
|
|---|
| 238 | ULONG OSLibWinQueryMsgTime()
|
|---|
| 239 | {
|
|---|
| 240 | return WinQueryMsgTime(GetThreadHAB());
|
|---|
| 241 | }
|
|---|
| 242 | //******************************************************************************
|
|---|
| 243 | //******************************************************************************
|
|---|
| 244 | BOOL OSLibWinWaitMessage()
|
|---|
| 245 | {
|
|---|
| 246 | return WinWaitMsg(GetThreadHAB(), 0, 0);
|
|---|
| 247 | }
|
|---|
| 248 | //******************************************************************************
|
|---|
| 249 | //TODO: QS_HOTKEY
|
|---|
| 250 | //******************************************************************************
|
|---|
| 251 | ULONG OSLibWinQueryQueueStatus()
|
|---|
| 252 | {
|
|---|
| 253 | ULONG statusOS2, statusWin32;
|
|---|
| 254 |
|
|---|
| 255 | statusOS2 = WinQueryQueueStatus(HWND_DESKTOP);
|
|---|
| 256 |
|
|---|
| 257 | if(statusOS2 & QS_KEY)
|
|---|
| 258 | statusWin32 |= QS_KEY_W;
|
|---|
| 259 | if(statusOS2 & QS_MOUSEBUTTON)
|
|---|
| 260 | statusWin32 |= QS_MOUSEBUTTON_W;
|
|---|
| 261 | if(statusOS2 & QS_MOUSEMOVE)
|
|---|
| 262 | statusWin32 |= QS_MOUSEMOVE_W;
|
|---|
| 263 | if(statusOS2 & QS_TIMER)
|
|---|
| 264 | statusWin32 |= QS_TIMER_W;
|
|---|
| 265 | if(statusOS2 & QS_PAINT)
|
|---|
| 266 | statusWin32 |= QS_PAINT_W;
|
|---|
| 267 | if(statusOS2 & QS_POSTMSG)
|
|---|
| 268 | statusWin32 |= QS_POSTMESSAGE_W;
|
|---|
| 269 | if(statusOS2 & QS_SENDMSG)
|
|---|
| 270 | statusWin32 |= QS_SENDMESSAGE_W;
|
|---|
| 271 |
|
|---|
| 272 | return statusWin32;
|
|---|
| 273 | }
|
|---|
| 274 | //******************************************************************************
|
|---|
| 275 | //******************************************************************************
|
|---|