| 1 | /* $Id: winmouse.cpp,v 1.16 2001-07-28 13:43:54 sandervl Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | * Mouse handler for DINPUT
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright 1999-2001 Sander van Leeuwen
|
|---|
| 6 | *
|
|---|
| 7 | * TODO: SwapMouseButton:
|
|---|
| 8 | * We shouldn't let win32 apps change this for the whole system
|
|---|
| 9 | * better to change mouse button message translation instead
|
|---|
| 10 | *
|
|---|
| 11 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 12 | *
|
|---|
| 13 | */
|
|---|
| 14 | #include <os2win.h>
|
|---|
| 15 | #include <misc.h>
|
|---|
| 16 | #include "win32wbase.h"
|
|---|
| 17 | #include <winuser32.h>
|
|---|
| 18 | #include <win\mouse.h>
|
|---|
| 19 | #include "winmouse.h"
|
|---|
| 20 | #include "oslibmsg.h"
|
|---|
| 21 | #include "pmwindow.h"
|
|---|
| 22 | #include "oslibwin.h"
|
|---|
| 23 |
|
|---|
| 24 | #define DBG_LOCALLOG DBG_winmouse
|
|---|
| 25 | #include "dbglocal.h"
|
|---|
| 26 |
|
|---|
| 27 | LPMOUSE_EVENT_PROC mouseHandler = NULL;
|
|---|
| 28 | WNDPROC keyboardHandler = NULL;
|
|---|
| 29 |
|
|---|
| 30 | //******************************************************************************
|
|---|
| 31 | //******************************************************************************
|
|---|
| 32 | VOID WIN32API MOUSE_Enable(LPMOUSE_EVENT_PROC lpMouseEventProc)
|
|---|
| 33 | {
|
|---|
| 34 | if(lpMouseEventProc == (LPMOUSE_EVENT_PROC)-1)
|
|---|
| 35 | {
|
|---|
| 36 | mouseHandler = NULL;
|
|---|
| 37 | }
|
|---|
| 38 | else mouseHandler = lpMouseEventProc;
|
|---|
| 39 | }
|
|---|
| 40 | //******************************************************************************
|
|---|
| 41 | //******************************************************************************
|
|---|
| 42 | VOID WIN32API KEYBOARD_Enable(WNDPROC handler)
|
|---|
| 43 | {
|
|---|
| 44 | keyboardHandler = handler;
|
|---|
| 45 | }
|
|---|
| 46 | //******************************************************************************
|
|---|
| 47 | //******************************************************************************
|
|---|
| 48 | BOOL DInputKeyBoardHandler(MSG *msg)
|
|---|
| 49 | {
|
|---|
| 50 | if(!ISKDB_CAPTURED())
|
|---|
| 51 | return FALSE;
|
|---|
| 52 |
|
|---|
| 53 | return keyboardHandler(msg->hwnd, msg->message, msg->wParam, msg->lParam);
|
|---|
| 54 | }
|
|---|
| 55 | //******************************************************************************
|
|---|
| 56 | //******************************************************************************
|
|---|
| 57 | BOOL DInputMouseHandler(HWND hwnd, ULONG msg, ULONG x, ULONG y)
|
|---|
| 58 | {
|
|---|
| 59 | WINE_MOUSEEVENT mouseEvent;
|
|---|
| 60 | DWORD dwFlags = MOUSEEVENTF_ABSOLUTE;
|
|---|
| 61 |
|
|---|
| 62 | if(!ISMOUSE_CAPTURED())
|
|---|
| 63 | return FALSE;
|
|---|
| 64 |
|
|---|
| 65 | mouseEvent.magic = WINE_MOUSEEVENT_MAGIC;
|
|---|
| 66 | mouseEvent.hWnd = hwnd;
|
|---|
| 67 | mouseEvent.time = OSLibWinQueryMsgTime();
|
|---|
| 68 | mouseEvent.keyState = 0; //not used in dinput right now
|
|---|
| 69 | switch(msg)
|
|---|
| 70 | {
|
|---|
| 71 | case WM_NCLBUTTONDOWN:
|
|---|
| 72 | case WM_LBUTTONDOWN:
|
|---|
| 73 | dwFlags |= MOUSEEVENTF_LEFTDOWN;
|
|---|
| 74 | break;
|
|---|
| 75 | case WM_NCLBUTTONUP:
|
|---|
| 76 | case WM_LBUTTONUP:
|
|---|
| 77 | dwFlags |= MOUSEEVENTF_LEFTUP;
|
|---|
| 78 | break;
|
|---|
| 79 | case WM_NCRBUTTONUP:
|
|---|
| 80 | case WM_RBUTTONUP:
|
|---|
| 81 | dwFlags |= MOUSEEVENTF_RIGHTUP;
|
|---|
| 82 | break;
|
|---|
| 83 | case WM_NCRBUTTONDOWN:
|
|---|
| 84 | case WM_RBUTTONDOWN:
|
|---|
| 85 | dwFlags |= MOUSEEVENTF_RIGHTDOWN;
|
|---|
| 86 | break;
|
|---|
| 87 | case WM_NCMBUTTONUP:
|
|---|
| 88 | case WM_MBUTTONUP:
|
|---|
| 89 | dwFlags |= MOUSEEVENTF_MIDDLEUP;
|
|---|
| 90 | break;
|
|---|
| 91 | case WM_NCMBUTTONDOWN:
|
|---|
| 92 | case WM_MBUTTONDOWN:
|
|---|
| 93 | dwFlags |= MOUSEEVENTF_MIDDLEDOWN;
|
|---|
| 94 | break;
|
|---|
| 95 | case WM_MOUSEMOVE:
|
|---|
| 96 | case WM_NCMOUSEMOVE:
|
|---|
| 97 | dwFlags |= MOUSEEVENTF_MOVE;
|
|---|
| 98 | break;
|
|---|
| 99 | default:
|
|---|
| 100 | //TODO: handle double clicks???
|
|---|
| 101 | return FALSE;
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | x = (((long)x << 16) + ScreenWidth-1) / ScreenWidth;
|
|---|
| 105 | y = (((long)y << 16) + ScreenHeight-1) / ScreenHeight;
|
|---|
| 106 |
|
|---|
| 107 | return mouseHandler(dwFlags, x, y, 0, (DWORD)&mouseEvent);
|
|---|
| 108 | }
|
|---|
| 109 | //******************************************************************************
|
|---|
| 110 | //******************************************************************************
|
|---|
| 111 | HWND WIN32API GetCapture(void)
|
|---|
| 112 | {
|
|---|
| 113 | HWND hwnd;
|
|---|
| 114 |
|
|---|
| 115 | hwnd = OS2ToWin32Handle(OSLibWinQueryCapture());
|
|---|
| 116 | dprintf(("USER32: GetCapture returned %x", hwnd));
|
|---|
| 117 | return hwnd;
|
|---|
| 118 | }
|
|---|
| 119 | //******************************************************************************
|
|---|
| 120 | //******************************************************************************
|
|---|
| 121 | HWND WIN32API SetCapture(HWND hwnd)
|
|---|
| 122 | {
|
|---|
| 123 | HWND hwndPrev = GetCapture();
|
|---|
| 124 | BOOL rc;
|
|---|
| 125 |
|
|---|
| 126 | if(hwnd == 0) {
|
|---|
| 127 | ReleaseCapture();
|
|---|
| 128 | return hwndPrev;
|
|---|
| 129 | }
|
|---|
| 130 | if(hwnd == hwndPrev) {
|
|---|
| 131 | dprintf(("USER32: SetCapture %x; already set to that window; ignore", hwnd));
|
|---|
| 132 | return hwndPrev;
|
|---|
| 133 | }
|
|---|
| 134 | if(hwndPrev != NULL) {
|
|---|
| 135 | //SvL: WinSetCapture returns an error if mouse is already captured
|
|---|
| 136 | OSLibWinSetCapture(0);
|
|---|
| 137 | }
|
|---|
| 138 | rc = OSLibWinSetCapture(Win32ToOS2Handle(hwnd));
|
|---|
| 139 | dprintf(("USER32: SetCapture %x (prev %x) returned %d", hwnd, hwndPrev, rc));
|
|---|
| 140 | if(hwndPrev) {
|
|---|
| 141 | SendMessageA(hwndPrev, WM_CAPTURECHANGED, 0L, hwnd);
|
|---|
| 142 | }
|
|---|
| 143 | return hwndPrev;
|
|---|
| 144 | }
|
|---|
| 145 | //******************************************************************************
|
|---|
| 146 | //******************************************************************************
|
|---|
| 147 | BOOL WIN32API ReleaseCapture(void)
|
|---|
| 148 | {
|
|---|
| 149 | HWND hwndPrev;
|
|---|
| 150 | BOOL ret;
|
|---|
| 151 |
|
|---|
| 152 | dprintf(("USER32: ReleaseCapture"));
|
|---|
| 153 | hwndPrev = GetCapture();
|
|---|
| 154 | ret = OSLibWinSetCapture(0);
|
|---|
| 155 | if(hwndPrev) {
|
|---|
| 156 | SendMessageA(hwndPrev, WM_CAPTURECHANGED, 0L, 0L);
|
|---|
| 157 | }
|
|---|
| 158 | return ret;
|
|---|
| 159 | }
|
|---|
| 160 | //******************************************************************************
|
|---|
| 161 | //******************************************************************************
|
|---|
| 162 | UINT WIN32API GetDoubleClickTime(void)
|
|---|
| 163 | {
|
|---|
| 164 | dprintf(("USER32: GetDoubleClickTime"));
|
|---|
| 165 | UINT result = OSLibWinQuerySysValue(SVOS_DBLCLKTIME);
|
|---|
| 166 | if(result == 0)
|
|---|
| 167 | SetLastError(ERROR_INVALID_PARAMETER); //TODO: ????
|
|---|
| 168 |
|
|---|
| 169 | return result;
|
|---|
| 170 | }
|
|---|
| 171 | //******************************************************************************
|
|---|
| 172 | //******************************************************************************
|
|---|
| 173 | BOOL WIN32API SetDoubleClickTime(UINT uInterval)
|
|---|
| 174 | {
|
|---|
| 175 | BOOL ret = TRUE;
|
|---|
| 176 |
|
|---|
| 177 | dprintf(("USER32: SetDoubleClickTime %d", uInterval));
|
|---|
| 178 |
|
|---|
| 179 | ret = OSLibWinSetSysValue(SVOS_DBLCLKTIME, uInterval);
|
|---|
| 180 | if(ret == FALSE )
|
|---|
| 181 | {
|
|---|
| 182 | SetLastError(ERROR_INVALID_PARAMETER); //TODO: ????
|
|---|
| 183 | }
|
|---|
| 184 | return (ret);
|
|---|
| 185 | }
|
|---|
| 186 | //******************************************************************************
|
|---|
| 187 | //TODO: we shouldn't let win32 apps change this for the whole system
|
|---|
| 188 | // better to change mouse button message translation instead
|
|---|
| 189 | BOOL OPEN32API __SwapMouseButton(BOOL swapFlag);
|
|---|
| 190 |
|
|---|
| 191 | inline BOOL _SwapMouseButton(BOOL swapFlag)
|
|---|
| 192 | {
|
|---|
| 193 | BOOL yyrc;
|
|---|
| 194 | USHORT sel = RestoreOS2FS();
|
|---|
| 195 |
|
|---|
| 196 | yyrc = __SwapMouseButton(swapFlag);
|
|---|
| 197 | SetFS(sel);
|
|---|
| 198 |
|
|---|
| 199 | return yyrc;
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | //******************************************************************************
|
|---|
| 203 | BOOL WIN32API SwapMouseButton(BOOL fSwap)
|
|---|
| 204 | {
|
|---|
| 205 | dprintf(("USER32: SwapMouseButton %d", fSwap));
|
|---|
| 206 | return _SwapMouseButton(fSwap);
|
|---|
| 207 | }
|
|---|
| 208 | /*****************************************************************************
|
|---|
| 209 | * Name : VOID WIN32API mouse_event
|
|---|
| 210 | * Purpose : The mouse_event function synthesizes mouse motion and button clicks.
|
|---|
| 211 | * Parameters: DWORD dwFlags flags specifying various motion/click variants
|
|---|
| 212 | * DWORD dx horizontal mouse position or position change
|
|---|
| 213 | * DWORD dy vertical mouse position or position change
|
|---|
| 214 | * DWORD cButtons unused, reserved for future use, set to zero
|
|---|
| 215 | * DWORD dwExtraInfo 32 bits of application-defined information
|
|---|
| 216 | * Variables :
|
|---|
| 217 | * Result :
|
|---|
| 218 | * Remark :
|
|---|
| 219 | * Status : UNTESTED STUB
|
|---|
| 220 | *
|
|---|
| 221 | * Author : Patrick Haller [Thu, 1998/02/26 11:55]
|
|---|
| 222 | *****************************************************************************/
|
|---|
| 223 | VOID WIN32API mouse_event(DWORD dwFlags, DWORD dx, DWORD dy, DWORD cButtons,
|
|---|
| 224 | DWORD dwExtraInfo)
|
|---|
| 225 | {
|
|---|
| 226 | dprintf(("USER32:mouse_event (%08xh,%u,%u,%u,%08x) not implemented",
|
|---|
| 227 | dwFlags, dx, dy, cButtons, dwExtraInfo));
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | DWORD WIN32API TrackMouseEvent(DWORD param1)
|
|---|
| 231 | {
|
|---|
| 232 | dprintf(("USER32: TrackMouseEvent %x not implemented", param1));
|
|---|
| 233 | return 0;
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | DWORD WIN32API SendInput(DWORD param1, DWORD param2, DWORD param3)
|
|---|
| 237 | {
|
|---|
| 238 | dprintf(("USER32: SendInput %x %x %x not implemented", param1, param2, param3));
|
|---|
| 239 | return 0;
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 | /*****************************************************************************
|
|---|
| 243 | * Name : BOOL WIN32API DragDetect
|
|---|
| 244 | * Purpose : The DragDetect function captures the mouse and tracks its movement
|
|---|
| 245 | * Parameters: HWND hwnd
|
|---|
| 246 | * POINT pt
|
|---|
| 247 | * Variables :
|
|---|
| 248 | * Result : If the user moved the mouse outside of the drag rectangle while
|
|---|
| 249 | * holding the left button down, the return value is TRUE.
|
|---|
| 250 | * If the user did not move the mouse outside of the drag rectangle
|
|---|
| 251 | * while holding the left button down, the return value is FALSE.
|
|---|
| 252 | * Remark :
|
|---|
| 253 | * Status : UNTESTED STUB
|
|---|
| 254 | *
|
|---|
| 255 | * Author : Patrick Haller [Thu, 1998/02/26 11:55]
|
|---|
| 256 | *****************************************************************************/
|
|---|
| 257 | BOOL WIN32API DragDetect(HWND hwnd,
|
|---|
| 258 | POINT pt)
|
|---|
| 259 | {
|
|---|
| 260 | dprintf(("USER32:DragDetect(%08xh,...) not implemented", hwnd));
|
|---|
| 261 |
|
|---|
| 262 | return (FALSE);
|
|---|
| 263 | }
|
|---|
| 264 | //******************************************************************************
|
|---|
| 265 | //******************************************************************************
|
|---|