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