configure: Changes from running autconf after previous patch.
[wine/hacks.git] / dlls / dinput / mouse.c
blob731e7596d2050d355895a829ded4dc4703200f5c
1 /* DirectInput Mouse device
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
5 * Copyright 2000-2001 TransGaming Technologies Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <stdarg.h>
26 #include <string.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "winerror.h"
33 #include "winreg.h"
34 #include "dinput.h"
36 #include "dinput_private.h"
37 #include "device_private.h"
38 #include "wine/debug.h"
39 #include "wine/unicode.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
43 /* Wine mouse driver object instances */
44 #define WINE_MOUSE_X_AXIS_INSTANCE 0
45 #define WINE_MOUSE_Y_AXIS_INSTANCE 1
46 #define WINE_MOUSE_Z_AXIS_INSTANCE 2
47 #define WINE_MOUSE_BUTTONS_INSTANCE 3
49 static const IDirectInputDevice8AVtbl SysMouseAvt;
50 static const IDirectInputDevice8WVtbl SysMouseWvt;
52 typedef struct SysMouseImpl SysMouseImpl;
54 typedef enum
56 WARP_DEFAULT,
57 WARP_DISABLE,
58 WARP_FORCE_ON,
59 WARP_FORCE_EDGE
60 } WARP_MOUSE;
62 struct SysMouseImpl
64 struct IDirectInputDevice2AImpl base;
66 /* SysMouseAImpl */
67 /* These are used in case of relative -> absolute transitions */
68 POINT org_coords;
69 POINT mapped_center;
70 DWORD win_centerX, win_centerY;
71 /* warping: whether we need to move mouse back to middle once we
72 * reach window borders (for e.g. shooters, "surface movement" games) */
73 BOOL need_warp;
74 DWORD last_warped;
76 /* This is for mouse reporting. */
77 DIMOUSESTATE2 m_state;
79 WARP_MOUSE warp_override;
82 static int dinput_mouse_hook( LPDIRECTINPUTDEVICE8A iface, WPARAM wparam, LPARAM lparam );
84 const GUID DInput_Wine_Mouse_GUID = { /* 9e573ed8-7734-11d2-8d4a-23903fb6bdf7 */
85 0x9e573ed8, 0x7734, 0x11d2, {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
88 static void _dump_mouse_state(DIMOUSESTATE2 *m_state)
90 int i;
92 if (!TRACE_ON(dinput)) return;
94 TRACE("(X: %d Y: %d Z: %d", m_state->lX, m_state->lY, m_state->lZ);
95 for (i = 0; i < 5; i++) TRACE(" B%d: %02x", i, m_state->rgbButtons[i]);
96 TRACE(")\n");
99 static void fill_mouse_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi, DWORD version) {
100 DWORD dwSize;
101 DIDEVICEINSTANCEA ddi;
103 dwSize = lpddi->dwSize;
105 TRACE("%d %p\n", dwSize, lpddi);
107 memset(lpddi, 0, dwSize);
108 memset(&ddi, 0, sizeof(ddi));
110 ddi.dwSize = dwSize;
111 ddi.guidInstance = GUID_SysMouse;/* DInput's GUID */
112 ddi.guidProduct = DInput_Wine_Mouse_GUID; /* Vendor's GUID */
113 if (version >= 0x0800)
114 ddi.dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
115 else
116 ddi.dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8);
117 strcpy(ddi.tszInstanceName, "Mouse");
118 strcpy(ddi.tszProductName, "Wine Mouse");
120 memcpy(lpddi, &ddi, (dwSize < sizeof(ddi) ? dwSize : sizeof(ddi)));
123 static void fill_mouse_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi, DWORD version) {
124 DWORD dwSize;
125 DIDEVICEINSTANCEW ddi;
127 dwSize = lpddi->dwSize;
129 TRACE("%d %p\n", dwSize, lpddi);
131 memset(lpddi, 0, dwSize);
132 memset(&ddi, 0, sizeof(ddi));
134 ddi.dwSize = dwSize;
135 ddi.guidInstance = GUID_SysMouse;/* DInput's GUID */
136 ddi.guidProduct = DInput_Wine_Mouse_GUID; /* Vendor's GUID */
137 if (version >= 0x0800)
138 ddi.dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
139 else
140 ddi.dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8);
141 MultiByteToWideChar(CP_ACP, 0, "Mouse", -1, ddi.tszInstanceName, MAX_PATH);
142 MultiByteToWideChar(CP_ACP, 0, "Wine Mouse", -1, ddi.tszProductName, MAX_PATH);
144 memcpy(lpddi, &ddi, (dwSize < sizeof(ddi) ? dwSize : sizeof(ddi)));
147 static BOOL mousedev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
149 if (id != 0)
150 return FALSE;
152 if ((dwDevType == 0) ||
153 ((dwDevType == DIDEVTYPE_MOUSE) && (version < 0x0800)) ||
154 (((dwDevType == DI8DEVCLASS_POINTER) || (dwDevType == DI8DEVTYPE_MOUSE)) && (version >= 0x0800))) {
155 TRACE("Enumerating the mouse device\n");
157 fill_mouse_dideviceinstanceA(lpddi, version);
159 return TRUE;
162 return FALSE;
165 static BOOL mousedev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
167 if (id != 0)
168 return FALSE;
170 if ((dwDevType == 0) ||
171 ((dwDevType == DIDEVTYPE_MOUSE) && (version < 0x0800)) ||
172 (((dwDevType == DI8DEVCLASS_POINTER) || (dwDevType == DI8DEVTYPE_MOUSE)) && (version >= 0x0800))) {
173 TRACE("Enumerating the mouse device\n");
175 fill_mouse_dideviceinstanceW(lpddi, version);
177 return TRUE;
180 return FALSE;
183 static SysMouseImpl *alloc_device(REFGUID rguid, const void *mvt, IDirectInputImpl *dinput)
185 SysMouseImpl* newDevice;
186 LPDIDATAFORMAT df = NULL;
187 unsigned i;
188 char buffer[20];
189 HKEY hkey, appkey;
191 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysMouseImpl));
192 if (!newDevice) return NULL;
193 newDevice->base.lpVtbl = mvt;
194 newDevice->base.ref = 1;
195 newDevice->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
196 newDevice->base.guid = *rguid;
197 InitializeCriticalSection(&newDevice->base.crit);
198 newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysMouseImpl*->base.crit");
199 newDevice->base.dinput = dinput;
200 newDevice->base.event_proc = dinput_mouse_hook;
202 get_app_key(&hkey, &appkey);
203 if (!get_config_key(hkey, appkey, "MouseWarpOverride", buffer, sizeof(buffer)))
205 if (!strcasecmp(buffer, "disable"))
206 newDevice->warp_override = WARP_DISABLE;
207 else if (!strcasecmp(buffer, "force"))
208 newDevice->warp_override = WARP_FORCE_ON;
209 else if (!strcasecmp(buffer, "force_edge"))
210 newDevice->warp_override = WARP_FORCE_EDGE;
212 if (appkey) RegCloseKey(appkey);
213 if (hkey) RegCloseKey(hkey);
215 /* Create copy of default data format */
216 if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIMouse2.dwSize))) goto failed;
217 memcpy(df, &c_dfDIMouse2, c_dfDIMouse2.dwSize);
218 if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto failed;
219 memcpy(df->rgodf, c_dfDIMouse2.rgodf, df->dwNumObjs * df->dwObjSize);
221 /* Because we don't do any detection yet just modify instance and type */
222 for (i = 0; i < df->dwNumObjs; i++)
223 if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_AXIS)
224 df->rgodf[i].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_RELAXIS;
225 else
226 df->rgodf[i].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_PSHBUTTON;
228 newDevice->base.data_format.wine_df = df;
229 IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->base.dinput);
230 return newDevice;
232 failed:
233 if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
234 HeapFree(GetProcessHeap(), 0, df);
235 HeapFree(GetProcessHeap(), 0, newDevice);
236 return NULL;
239 static HRESULT mousedev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
241 if ((IsEqualGUID(&GUID_SysMouse,rguid)) || /* Generic Mouse */
242 (IsEqualGUID(&DInput_Wine_Mouse_GUID,rguid))) { /* Wine Mouse */
243 if ((riid == NULL) ||
244 IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
245 IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
246 IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
247 IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
248 *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &SysMouseAvt, dinput);
249 TRACE("Creating a Mouse device (%p)\n", *pdev);
250 if (!*pdev) return DIERR_OUTOFMEMORY;
251 return DI_OK;
252 } else
253 return DIERR_NOINTERFACE;
256 return DIERR_DEVICENOTREG;
259 static HRESULT mousedev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
261 if ((IsEqualGUID(&GUID_SysMouse,rguid)) || /* Generic Mouse */
262 (IsEqualGUID(&DInput_Wine_Mouse_GUID,rguid))) { /* Wine Mouse */
263 if ((riid == NULL) ||
264 IsEqualGUID(&IID_IDirectInputDeviceW,riid) ||
265 IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
266 IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
267 IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
268 *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &SysMouseWvt, dinput);
269 TRACE("Creating a Mouse device (%p)\n", *pdev);
270 if (!*pdev) return DIERR_OUTOFMEMORY;
271 return DI_OK;
272 } else
273 return DIERR_NOINTERFACE;
276 return DIERR_DEVICENOTREG;
279 const struct dinput_device mouse_device = {
280 "Wine mouse driver",
281 mousedev_enum_deviceA,
282 mousedev_enum_deviceW,
283 mousedev_create_deviceA,
284 mousedev_create_deviceW
287 /******************************************************************************
288 * SysMouseA (DInput Mouse support)
291 /* low-level mouse hook */
292 static int dinput_mouse_hook( LPDIRECTINPUTDEVICE8A iface, WPARAM wparam, LPARAM lparam )
294 MSLLHOOKSTRUCT *hook = (MSLLHOOKSTRUCT *)lparam;
295 SysMouseImpl* This = (SysMouseImpl*) iface;
296 DWORD dwCoop;
297 int wdata = 0, inst_id = -1, ret;
299 TRACE("msg %lx @ (%d %d)\n", wparam, hook->pt.x, hook->pt.y);
301 EnterCriticalSection(&This->base.crit);
302 dwCoop = This->base.dwCoopLevel;
303 ret = dwCoop & DISCL_EXCLUSIVE;
305 switch(wparam) {
306 case WM_MOUSEMOVE:
308 POINT pt, pt1;
310 GetCursorPos(&pt);
311 This->m_state.lX += pt.x = hook->pt.x - pt.x;
312 This->m_state.lY += pt.y = hook->pt.y - pt.y;
314 if (This->base.data_format.user_df->dwFlags & DIDF_ABSAXIS)
316 pt1.x = This->m_state.lX;
317 pt1.y = This->m_state.lY;
318 } else
319 pt1 = pt;
321 if (pt.x)
323 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS;
324 wdata = pt1.x;
326 if (pt.y)
328 /* Already have X, need to queue it */
329 if (inst_id != -1)
330 queue_event((LPDIRECTINPUTDEVICE8A)This, inst_id,
331 wdata, GetCurrentTime(), This->base.dinput->evsequence);
332 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS;
333 wdata = pt1.y;
336 This->need_warp = This->warp_override != WARP_DISABLE &&
338 ((pt.x || pt.y) && This->warp_override != WARP_FORCE_EDGE) ||
341 hook->pt.x<2 || hook->pt.y<2 ||
342 hook->pt.x>((2 * This->win_centerX)-2) || hook->pt.y>((2 * This->win_centerY)-2)
343 ) && This->warp_override == WARP_FORCE_EDGE
345 ) &&
346 (dwCoop & DISCL_EXCLUSIVE || This->warp_override >= WARP_FORCE_ON);
347 break;
349 case WM_MOUSEWHEEL:
350 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_Z_AXIS_INSTANCE) | DIDFT_RELAXIS;
351 This->m_state.lZ += wdata = (short)HIWORD(hook->mouseData);
352 break;
353 case WM_LBUTTONDOWN:
354 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 0) | DIDFT_PSHBUTTON;
355 This->m_state.rgbButtons[0] = wdata = 0x80;
356 break;
357 case WM_LBUTTONUP:
358 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 0) | DIDFT_PSHBUTTON;
359 This->m_state.rgbButtons[0] = wdata = 0x00;
360 break;
361 case WM_RBUTTONDOWN:
362 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 1) | DIDFT_PSHBUTTON;
363 This->m_state.rgbButtons[1] = wdata = 0x80;
364 break;
365 case WM_RBUTTONUP:
366 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 1) | DIDFT_PSHBUTTON;
367 This->m_state.rgbButtons[1] = wdata = 0x00;
368 break;
369 case WM_MBUTTONDOWN:
370 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2) | DIDFT_PSHBUTTON;
371 This->m_state.rgbButtons[2] = wdata = 0x80;
372 break;
373 case WM_MBUTTONUP:
374 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2) | DIDFT_PSHBUTTON;
375 This->m_state.rgbButtons[2] = wdata = 0x00;
376 break;
377 case WM_XBUTTONDOWN:
378 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2 + HIWORD(hook->mouseData)) | DIDFT_PSHBUTTON;
379 This->m_state.rgbButtons[2 + HIWORD(hook->mouseData)] = wdata = 0x80;
380 break;
381 case WM_XBUTTONUP:
382 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2 + HIWORD(hook->mouseData)) | DIDFT_PSHBUTTON;
383 This->m_state.rgbButtons[2 + HIWORD(hook->mouseData)] = wdata = 0x00;
384 break;
385 default:
386 ret = 0;
390 if (inst_id != -1)
392 _dump_mouse_state(&This->m_state);
393 queue_event((LPDIRECTINPUTDEVICE8A)This, inst_id,
394 wdata, GetCurrentTime(), This->base.dinput->evsequence++);
397 LeaveCriticalSection(&This->base.crit);
398 return ret;
401 static BOOL dinput_window_check(SysMouseImpl* This) {
402 RECT rect;
403 DWORD centerX, centerY;
405 /* make sure the window hasn't moved */
406 if(!GetWindowRect(This->base.win, &rect))
407 return FALSE;
408 centerX = (rect.right - rect.left) / 2;
409 centerY = (rect.bottom - rect.top ) / 2;
410 if (This->win_centerX != centerX || This->win_centerY != centerY) {
411 This->win_centerX = centerX;
412 This->win_centerY = centerY;
414 This->mapped_center.x = This->win_centerX;
415 This->mapped_center.y = This->win_centerY;
416 MapWindowPoints(This->base.win, HWND_DESKTOP, &This->mapped_center, 1);
417 return TRUE;
421 /******************************************************************************
422 * Acquire : gets exclusive control of the mouse
424 static HRESULT WINAPI SysMouseAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
426 SysMouseImpl *This = (SysMouseImpl *)iface;
427 RECT rect;
428 POINT point;
429 HRESULT res;
431 TRACE("(this=%p)\n",This);
433 if ((res = IDirectInputDevice2AImpl_Acquire(iface)) != DI_OK) return res;
435 /* Init the mouse state */
436 GetCursorPos( &point );
437 if (This->base.data_format.user_df->dwFlags & DIDF_ABSAXIS)
439 This->m_state.lX = point.x;
440 This->m_state.lY = point.y;
441 } else {
442 This->m_state.lX = 0;
443 This->m_state.lY = 0;
444 This->org_coords = point;
446 This->m_state.lZ = 0;
447 This->m_state.rgbButtons[0] = GetKeyState(VK_LBUTTON) & 0x80;
448 This->m_state.rgbButtons[1] = GetKeyState(VK_RBUTTON) & 0x80;
449 This->m_state.rgbButtons[2] = GetKeyState(VK_MBUTTON) & 0x80;
451 /* Install our mouse hook */
452 if (This->base.dwCoopLevel & DISCL_EXCLUSIVE)
454 RECT rc;
456 ShowCursor(FALSE); /* hide cursor */
457 if (GetWindowRect(This->base.win, &rc))
459 FIXME("Clipping cursor to %s\n", wine_dbgstr_rect( &rc ));
460 ClipCursor(&rc);
462 else
463 ERR("Failed to get RECT: %d\n", GetLastError());
466 /* Need a window to warp mouse in. */
467 if (This->warp_override >= WARP_FORCE_ON && !This->base.win)
468 This->base.win = GetDesktopWindow();
470 /* Get the window dimension and find the center */
471 GetWindowRect(This->base.win, &rect);
472 This->win_centerX = (rect.right - rect.left) / 2;
473 This->win_centerY = (rect.bottom - rect.top ) / 2;
475 /* Warp the mouse to the center of the window */
476 if (This->base.dwCoopLevel & DISCL_EXCLUSIVE || This->warp_override >= WARP_FORCE_ON)
478 This->mapped_center.x = This->win_centerX;
479 This->mapped_center.y = This->win_centerY;
480 MapWindowPoints(This->base.win, HWND_DESKTOP, &This->mapped_center, 1);
481 TRACE("Warping mouse to %d - %d\n", This->mapped_center.x, This->mapped_center.y);
482 SetCursorPos( This->mapped_center.x, This->mapped_center.y );
483 This->last_warped = GetCurrentTime();
485 This->need_warp = FALSE;
488 return DI_OK;
491 /******************************************************************************
492 * Unacquire : frees the mouse
494 static HRESULT WINAPI SysMouseAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
496 SysMouseImpl *This = (SysMouseImpl *)iface;
497 HRESULT res;
499 TRACE("(this=%p)\n",This);
501 if ((res = IDirectInputDevice2AImpl_Unacquire(iface)) != DI_OK) return res;
503 if (This->base.dwCoopLevel & DISCL_EXCLUSIVE)
505 ClipCursor(NULL);
506 ShowCursor(TRUE); /* show cursor */
509 /* And put the mouse cursor back where it was at acquire time */
510 if (This->base.dwCoopLevel & DISCL_EXCLUSIVE || This->warp_override >= WARP_FORCE_ON)
512 TRACE(" warping mouse back to (%d , %d)\n", This->org_coords.x, This->org_coords.y);
513 SetCursorPos(This->org_coords.x, This->org_coords.y);
516 return DI_OK;
519 /******************************************************************************
520 * GetDeviceState : returns the "state" of the mouse.
522 * For the moment, only the "standard" return structure (DIMOUSESTATE) is
523 * supported.
525 static HRESULT WINAPI SysMouseAImpl_GetDeviceState(
526 LPDIRECTINPUTDEVICE8A iface,DWORD len,LPVOID ptr
528 SysMouseImpl *This = (SysMouseImpl *)iface;
530 if(This->base.acquired == 0) return DIERR_NOTACQUIRED;
532 TRACE("(this=%p,0x%08x,%p):\n", This, len, ptr);
533 _dump_mouse_state(&This->m_state);
535 EnterCriticalSection(&This->base.crit);
536 /* Copy the current mouse state */
537 fill_DataFormat(ptr, len, &This->m_state, &This->base.data_format);
539 /* Initialize the buffer when in relative mode */
540 if (!(This->base.data_format.user_df->dwFlags & DIDF_ABSAXIS))
542 This->m_state.lX = 0;
543 This->m_state.lY = 0;
544 This->m_state.lZ = 0;
546 LeaveCriticalSection(&This->base.crit);
548 /* Check if we need to do a mouse warping */
549 if (This->need_warp && (GetCurrentTime() - This->last_warped > 10))
551 if(!dinput_window_check(This))
552 return DIERR_GENERIC;
553 TRACE("Warping mouse to %d - %d\n", This->mapped_center.x, This->mapped_center.y);
554 SetCursorPos( This->mapped_center.x, This->mapped_center.y );
555 This->last_warped = GetCurrentTime();
557 This->need_warp = FALSE;
560 return DI_OK;
563 /******************************************************************************
564 * GetDeviceData : gets buffered input data.
566 static HRESULT WINAPI SysMouseAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
567 DWORD dodsize, LPDIDEVICEOBJECTDATA dod, LPDWORD entries, DWORD flags)
569 SysMouseImpl *This = (SysMouseImpl *)iface;
570 HRESULT res;
572 res = IDirectInputDevice2AImpl_GetDeviceData(iface, dodsize, dod, entries, flags);
573 if (FAILED(res)) return res;
575 /* Check if we need to do a mouse warping */
576 if (This->need_warp && (GetCurrentTime() - This->last_warped > 10))
578 if(!dinput_window_check(This))
579 return DIERR_GENERIC;
580 TRACE("Warping mouse to %d - %d\n", This->mapped_center.x, This->mapped_center.y);
581 SetCursorPos( This->mapped_center.x, This->mapped_center.y );
582 This->last_warped = GetCurrentTime();
584 This->need_warp = FALSE;
586 return res;
589 /******************************************************************************
590 * GetProperty : get input device properties
592 static HRESULT WINAPI SysMouseAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
593 REFGUID rguid,
594 LPDIPROPHEADER pdiph)
596 SysMouseImpl *This = (SysMouseImpl *)iface;
598 TRACE("(%p) %s,%p\n", This, debugstr_guid(rguid), pdiph);
599 _dump_DIPROPHEADER(pdiph);
601 if (IS_DIPROP(rguid)) {
602 switch (LOWORD(rguid)) {
603 case (DWORD_PTR) DIPROP_GRANULARITY: {
604 LPDIPROPDWORD pr = (LPDIPROPDWORD) pdiph;
606 /* We'll just assume that the app asks about the Z axis */
607 pr->dwData = WHEEL_DELTA;
609 break;
612 case (DWORD_PTR) DIPROP_RANGE: {
613 LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph;
615 if ((pdiph->dwHow == DIPH_BYID) &&
616 ((pdiph->dwObj == (DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS)) ||
617 (pdiph->dwObj == (DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS)))) {
618 /* Querying the range of either the X or the Y axis. As I do
619 not know the range, do as if the range were
620 unrestricted...*/
621 pr->lMin = DIPROPRANGE_NOMIN;
622 pr->lMax = DIPROPRANGE_NOMAX;
625 break;
628 default:
629 return IDirectInputDevice2AImpl_GetProperty(iface, rguid, pdiph);
633 return DI_OK;
636 /******************************************************************************
637 * GetCapabilities : get the device capabilities
639 static HRESULT WINAPI SysMouseAImpl_GetCapabilities(
640 LPDIRECTINPUTDEVICE8A iface,
641 LPDIDEVCAPS lpDIDevCaps)
643 SysMouseImpl *This = (SysMouseImpl *)iface;
644 DIDEVCAPS devcaps;
646 TRACE("(this=%p,%p)\n",This,lpDIDevCaps);
648 if ((lpDIDevCaps->dwSize != sizeof(DIDEVCAPS)) && (lpDIDevCaps->dwSize != sizeof(DIDEVCAPS_DX3))) {
649 WARN("invalid parameter\n");
650 return DIERR_INVALIDPARAM;
653 devcaps.dwSize = lpDIDevCaps->dwSize;
654 devcaps.dwFlags = DIDC_ATTACHED;
655 if (This->base.dinput->dwVersion >= 0x0800)
656 devcaps.dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
657 else
658 devcaps.dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8);
659 devcaps.dwAxes = 3;
660 devcaps.dwButtons = 8;
661 devcaps.dwPOVs = 0;
662 devcaps.dwFFSamplePeriod = 0;
663 devcaps.dwFFMinTimeResolution = 0;
664 devcaps.dwFirmwareRevision = 100;
665 devcaps.dwHardwareRevision = 100;
666 devcaps.dwFFDriverVersion = 0;
668 memcpy(lpDIDevCaps, &devcaps, lpDIDevCaps->dwSize);
670 return DI_OK;
673 /******************************************************************************
674 * GetObjectInfo : get information about a device object such as a button
675 * or axis
677 static HRESULT WINAPI SysMouseWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface,
678 LPDIDEVICEOBJECTINSTANCEW pdidoi, DWORD dwObj, DWORD dwHow)
680 static const WCHAR x_axisW[] = {'X','-','A','x','i','s',0};
681 static const WCHAR y_axisW[] = {'Y','-','A','x','i','s',0};
682 static const WCHAR wheelW[] = {'W','h','e','e','l',0};
683 static const WCHAR buttonW[] = {'B','u','t','t','o','n',' ','%','d',0};
684 HRESULT res;
686 res = IDirectInputDevice2WImpl_GetObjectInfo(iface, pdidoi, dwObj, dwHow);
687 if (res != DI_OK) return res;
689 if (IsEqualGUID(&pdidoi->guidType, &GUID_XAxis)) strcpyW(pdidoi->tszName, x_axisW);
690 else if (IsEqualGUID(&pdidoi->guidType, &GUID_YAxis)) strcpyW(pdidoi->tszName, y_axisW);
691 else if (IsEqualGUID(&pdidoi->guidType, &GUID_ZAxis)) strcpyW(pdidoi->tszName, wheelW);
692 else if (pdidoi->dwType & DIDFT_BUTTON)
693 wsprintfW(pdidoi->tszName, buttonW, DIDFT_GETINSTANCE(pdidoi->dwType) - 3);
695 _dump_OBJECTINSTANCEW(pdidoi);
696 return res;
699 static HRESULT WINAPI SysMouseAImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8A iface,
700 LPDIDEVICEOBJECTINSTANCEA pdidoi, DWORD dwObj, DWORD dwHow)
702 HRESULT res;
703 DIDEVICEOBJECTINSTANCEW didoiW;
704 DWORD dwSize = pdidoi->dwSize;
706 didoiW.dwSize = sizeof(didoiW);
707 res = SysMouseWImpl_GetObjectInfo((LPDIRECTINPUTDEVICE8W)iface, &didoiW, dwObj, dwHow);
708 if (res != DI_OK) return res;
710 memset(pdidoi, 0, pdidoi->dwSize);
711 memcpy(pdidoi, &didoiW, FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW, tszName));
712 pdidoi->dwSize = dwSize;
713 WideCharToMultiByte(CP_ACP, 0, didoiW.tszName, -1, pdidoi->tszName,
714 sizeof(pdidoi->tszName), NULL, NULL);
716 return res;
719 /******************************************************************************
720 * GetDeviceInfo : get information about a device's identity
722 static HRESULT WINAPI SysMouseAImpl_GetDeviceInfo(
723 LPDIRECTINPUTDEVICE8A iface,
724 LPDIDEVICEINSTANCEA pdidi)
726 SysMouseImpl *This = (SysMouseImpl *)iface;
727 TRACE("(this=%p,%p)\n", This, pdidi);
729 if (pdidi->dwSize != sizeof(DIDEVICEINSTANCEA)) {
730 WARN(" dinput3 not supporte yet...\n");
731 return DI_OK;
734 fill_mouse_dideviceinstanceA(pdidi, This->base.dinput->dwVersion);
736 return DI_OK;
739 static HRESULT WINAPI SysMouseWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface, LPDIDEVICEINSTANCEW pdidi)
741 SysMouseImpl *This = (SysMouseImpl *)iface;
742 TRACE("(this=%p,%p)\n", This, pdidi);
744 if (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW)) {
745 WARN(" dinput3 not supporte yet...\n");
746 return DI_OK;
749 fill_mouse_dideviceinstanceW(pdidi, This->base.dinput->dwVersion);
751 return DI_OK;
755 static const IDirectInputDevice8AVtbl SysMouseAvt =
757 IDirectInputDevice2AImpl_QueryInterface,
758 IDirectInputDevice2AImpl_AddRef,
759 IDirectInputDevice2AImpl_Release,
760 SysMouseAImpl_GetCapabilities,
761 IDirectInputDevice2AImpl_EnumObjects,
762 SysMouseAImpl_GetProperty,
763 IDirectInputDevice2AImpl_SetProperty,
764 SysMouseAImpl_Acquire,
765 SysMouseAImpl_Unacquire,
766 SysMouseAImpl_GetDeviceState,
767 SysMouseAImpl_GetDeviceData,
768 IDirectInputDevice2AImpl_SetDataFormat,
769 IDirectInputDevice2AImpl_SetEventNotification,
770 IDirectInputDevice2AImpl_SetCooperativeLevel,
771 SysMouseAImpl_GetObjectInfo,
772 SysMouseAImpl_GetDeviceInfo,
773 IDirectInputDevice2AImpl_RunControlPanel,
774 IDirectInputDevice2AImpl_Initialize,
775 IDirectInputDevice2AImpl_CreateEffect,
776 IDirectInputDevice2AImpl_EnumEffects,
777 IDirectInputDevice2AImpl_GetEffectInfo,
778 IDirectInputDevice2AImpl_GetForceFeedbackState,
779 IDirectInputDevice2AImpl_SendForceFeedbackCommand,
780 IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
781 IDirectInputDevice2AImpl_Escape,
782 IDirectInputDevice2AImpl_Poll,
783 IDirectInputDevice2AImpl_SendDeviceData,
784 IDirectInputDevice7AImpl_EnumEffectsInFile,
785 IDirectInputDevice7AImpl_WriteEffectToFile,
786 IDirectInputDevice8AImpl_BuildActionMap,
787 IDirectInputDevice8AImpl_SetActionMap,
788 IDirectInputDevice8AImpl_GetImageInfo
791 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
792 # define XCAST(fun) (typeof(SysMouseWvt.fun))
793 #else
794 # define XCAST(fun) (void*)
795 #endif
797 static const IDirectInputDevice8WVtbl SysMouseWvt =
799 IDirectInputDevice2WImpl_QueryInterface,
800 XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
801 XCAST(Release)IDirectInputDevice2AImpl_Release,
802 XCAST(GetCapabilities)SysMouseAImpl_GetCapabilities,
803 IDirectInputDevice2WImpl_EnumObjects,
804 XCAST(GetProperty)SysMouseAImpl_GetProperty,
805 XCAST(SetProperty)IDirectInputDevice2AImpl_SetProperty,
806 XCAST(Acquire)SysMouseAImpl_Acquire,
807 XCAST(Unacquire)SysMouseAImpl_Unacquire,
808 XCAST(GetDeviceState)SysMouseAImpl_GetDeviceState,
809 XCAST(GetDeviceData)SysMouseAImpl_GetDeviceData,
810 XCAST(SetDataFormat)IDirectInputDevice2AImpl_SetDataFormat,
811 XCAST(SetEventNotification)IDirectInputDevice2AImpl_SetEventNotification,
812 XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
813 SysMouseWImpl_GetObjectInfo,
814 SysMouseWImpl_GetDeviceInfo,
815 XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
816 XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
817 XCAST(CreateEffect)IDirectInputDevice2AImpl_CreateEffect,
818 IDirectInputDevice2WImpl_EnumEffects,
819 IDirectInputDevice2WImpl_GetEffectInfo,
820 XCAST(GetForceFeedbackState)IDirectInputDevice2AImpl_GetForceFeedbackState,
821 XCAST(SendForceFeedbackCommand)IDirectInputDevice2AImpl_SendForceFeedbackCommand,
822 XCAST(EnumCreatedEffectObjects)IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
823 XCAST(Escape)IDirectInputDevice2AImpl_Escape,
824 XCAST(Poll)IDirectInputDevice2AImpl_Poll,
825 XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
826 IDirectInputDevice7WImpl_EnumEffectsInFile,
827 IDirectInputDevice7WImpl_WriteEffectToFile,
828 IDirectInputDevice8WImpl_BuildActionMap,
829 IDirectInputDevice8WImpl_SetActionMap,
830 IDirectInputDevice8WImpl_GetImageInfo
832 #undef XCAST