| 1 | /* $Id: oslibmsg.cpp,v 1.6 1999-10-28 22:41:00 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 | #define MAX_MSGTRANSTAB (sizeof(MsgTransTab)/sizeof(MsgTransTab[0])) | 
|---|
| 82 |  | 
|---|
| 83 | QMSG *MsgThreadPtr = 0; | 
|---|
| 84 |  | 
|---|
| 85 | //****************************************************************************** | 
|---|
| 86 | //****************************************************************************** | 
|---|
| 87 | BOOL OSLibInitMsgQueue() | 
|---|
| 88 | { | 
|---|
| 89 | if(DosAllocThreadLocalMemory(sizeof(QMSG)/sizeof(ULONG), (PULONG *)&MsgThreadPtr) != 0) | 
|---|
| 90 | { | 
|---|
| 91 | dprintf(("OSLibInitMsgQueue: local thread memory alloc failed!!")); | 
|---|
| 92 | DebugInt3(); | 
|---|
| 93 | return FALSE; | 
|---|
| 94 | } | 
|---|
| 95 | return TRUE; | 
|---|
| 96 | } | 
|---|
| 97 | //****************************************************************************** | 
|---|
| 98 | //****************************************************************************** | 
|---|
| 99 | void WinToOS2MsgTranslate(MSG *winMsg, QMSG *os2Msg, BOOL isUnicode) | 
|---|
| 100 | { | 
|---|
| 101 | int i; | 
|---|
| 102 |  | 
|---|
| 103 | memcpy(os2Msg, winMsg, sizeof(MSG)); | 
|---|
| 104 | os2Msg->hwnd = Win32Window::Win32ToOS2Handle(winMsg->hwnd); | 
|---|
| 105 | os2Msg->reserved = 0; | 
|---|
| 106 | for(i=0;i<MAX_MSGTRANSTAB;i++) | 
|---|
| 107 | { | 
|---|
| 108 | if(MsgTransTab[i].msgWin32 == winMsg->message) | 
|---|
| 109 | { | 
|---|
| 110 | os2Msg->msg = MsgTransTab[i].msgOS2; | 
|---|
| 111 | break; | 
|---|
| 112 | } | 
|---|
| 113 | } | 
|---|
| 114 | } | 
|---|
| 115 | //****************************************************************************** | 
|---|
| 116 | //****************************************************************************** | 
|---|
| 117 | void OS2ToWinMsgTranslate(QMSG *os2Msg, MSG *winMsg, BOOL isUnicode) | 
|---|
| 118 | { | 
|---|
| 119 | int i; | 
|---|
| 120 |  | 
|---|
| 121 | memcpy(winMsg, os2Msg, sizeof(MSG)); | 
|---|
| 122 | winMsg->hwnd = Win32Window::OS2ToWin32Handle(os2Msg->hwnd); | 
|---|
| 123 | for(i=0;i<MAX_MSGTRANSTAB;i++) | 
|---|
| 124 | { | 
|---|
| 125 | if(MsgTransTab[i].msgOS2 == os2Msg->msg) | 
|---|
| 126 | { | 
|---|
| 127 | winMsg->message = MsgTransTab[i].msgWin32; | 
|---|
| 128 | break; | 
|---|
| 129 | } | 
|---|
| 130 | } | 
|---|
| 131 | } | 
|---|
| 132 | //****************************************************************************** | 
|---|
| 133 | //TODO!!! | 
|---|
| 134 | //Signal that the incoming messages in pmwindow need to be translated | 
|---|
| 135 | //(i.e. PM WM_CHAR when translated generates WM_CHAR messages, otherwise | 
|---|
| 136 | // WM_KEYUP/DOWN (etc)) | 
|---|
| 137 | //****************************************************************************** | 
|---|
| 138 | ULONG TranslateWinMsg(ULONG msg) | 
|---|
| 139 | { | 
|---|
| 140 | THDB *thdb; | 
|---|
| 141 |  | 
|---|
| 142 | thdb = GetThreadTHDB(); | 
|---|
| 143 | if(thdb) { | 
|---|
| 144 | thdb->fMsgTranslated = TRUE; | 
|---|
| 145 | } | 
|---|
| 146 |  | 
|---|
| 147 | for(int i=0;i<MAX_MSGTRANSTAB;i++) | 
|---|
| 148 | { | 
|---|
| 149 | if(MsgTransTab[i].msgWin32 == msg) | 
|---|
| 150 | { | 
|---|
| 151 | return MsgTransTab[i].msgOS2; | 
|---|
| 152 | } | 
|---|
| 153 | } | 
|---|
| 154 |  | 
|---|
| 155 | return 0; | 
|---|
| 156 | } | 
|---|
| 157 | //****************************************************************************** | 
|---|
| 158 | //****************************************************************************** | 
|---|
| 159 | void OSLibWinPostQuitMessage(ULONG nExitCode) | 
|---|
| 160 | { | 
|---|
| 161 | APIRET rc; | 
|---|
| 162 |  | 
|---|
| 163 | rc = WinPostQueueMsg(NULLHANDLE, WM_QUIT, (MPARAM)nExitCode, 0); | 
|---|
| 164 | dprintf(("WinPostQueueMsg %d returned %d", nExitCode, rc)); | 
|---|
| 165 | } | 
|---|
| 166 | //****************************************************************************** | 
|---|
| 167 | //****************************************************************************** | 
|---|
| 168 | LONG OSLibWinDispatchMsg(MSG *msg, BOOL isUnicode) | 
|---|
| 169 | { | 
|---|
| 170 | BOOL eaten = 0; | 
|---|
| 171 |  | 
|---|
| 172 | //TODO: What to do if app changed msg? (translate) | 
|---|
| 173 | //  WinToOS2MsgTranslate(msg, &qmsg, isUnicode); | 
|---|
| 174 |  | 
|---|
| 175 | //SvL: Some apps use PeeKMessage(remove) & DispatchMessage instead of | 
|---|
| 176 | //     GetMessage/DispatchMessage | 
|---|
| 177 | if (MsgThreadPtr->msg == WM_TIMER) | 
|---|
| 178 | eaten = TIMER_HandleTimer (MsgThreadPtr); | 
|---|
| 179 |  | 
|---|
| 180 | if(eaten)     return 0; | 
|---|
| 181 |  | 
|---|
| 182 | return (LONG)WinDispatchMsg(GetThreadHAB(), MsgThreadPtr); | 
|---|
| 183 | } | 
|---|
| 184 | //****************************************************************************** | 
|---|
| 185 | //****************************************************************************** | 
|---|
| 186 | BOOL OSLibWinGetMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax, | 
|---|
| 187 | BOOL isUnicode) | 
|---|
| 188 | { | 
|---|
| 189 | BOOL rc, eaten; | 
|---|
| 190 |  | 
|---|
| 191 | do { | 
|---|
| 192 | eaten = FALSE; | 
|---|
| 193 | rc = WinGetMsg(GetThreadHAB(), MsgThreadPtr, TranslateWinMsg(uMsgFilterMin), TranslateWinMsg(uMsgFilterMax), 0); | 
|---|
| 194 | if (MsgThreadPtr->msg == WM_TIMER) | 
|---|
| 195 | eaten = TIMER_HandleTimer (MsgThreadPtr); | 
|---|
| 196 | } while (eaten); | 
|---|
| 197 |  | 
|---|
| 198 | OS2ToWinMsgTranslate(MsgThreadPtr, pMsg, isUnicode); | 
|---|
| 199 | return rc; | 
|---|
| 200 | } | 
|---|
| 201 | //****************************************************************************** | 
|---|
| 202 | //****************************************************************************** | 
|---|
| 203 | BOOL  OSLibWinPeekMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax, | 
|---|
| 204 | BOOL fRemove, BOOL isUnicode) | 
|---|
| 205 | { | 
|---|
| 206 | BOOL rc; | 
|---|
| 207 |  | 
|---|
| 208 | rc = WinPeekMsg(GetThreadHAB(), MsgThreadPtr, hwnd, TranslateWinMsg(uMsgFilterMin), | 
|---|
| 209 | TranslateWinMsg(uMsgFilterMax), (fRemove == MSG_REMOVE) ? PM_REMOVE : PM_NOREMOVE); | 
|---|
| 210 | OS2ToWinMsgTranslate(MsgThreadPtr, pMsg, isUnicode); | 
|---|
| 211 | return rc; | 
|---|
| 212 | } | 
|---|
| 213 | //****************************************************************************** | 
|---|
| 214 | //****************************************************************************** | 
|---|