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 "dinput_private.h"
24 /* Wine mouse driver object instances */
25 #define WINE_MOUSE_X_AXIS_INSTANCE 0
26 #define WINE_MOUSE_Y_AXIS_INSTANCE 1
27 #define WINE_MOUSE_Z_AXIS_INSTANCE 2
28 #define WINE_MOUSE_BUTTONS_INSTANCE 3
30 static const IDirectInputDevice8AVtbl SysMouseAvt
;
31 static const IDirectInputDevice8WVtbl SysMouseWvt
;
33 typedef struct SysMouseImpl SysMouseImpl
;
44 struct IDirectInputDeviceImpl base
;
47 /* These are used in case of relative -> absolute transitions */
50 /* warping: whether we need to move mouse back to middle once we
51 * reach window borders (for e.g. shooters, "surface movement" games) */
55 /* This is for mouse reporting. */
56 DIMOUSESTATE2 m_state
;
58 WARP_MOUSE warp_override
;
61 static inline SysMouseImpl
*impl_from_IDirectInputDevice8A(IDirectInputDevice8A
*iface
)
63 return CONTAINING_RECORD(CONTAINING_RECORD(iface
, IDirectInputDeviceImpl
, IDirectInputDevice8A_iface
), SysMouseImpl
, base
);
65 static inline SysMouseImpl
*impl_from_IDirectInputDevice8W(IDirectInputDevice8W
*iface
)
67 return CONTAINING_RECORD(CONTAINING_RECORD(iface
, IDirectInputDeviceImpl
, IDirectInputDevice8W_iface
), SysMouseImpl
, base
);
70 static inline IDirectInputDevice8W
*IDirectInputDevice8W_from_impl(SysMouseImpl
*This
)
72 return &This
->base
.IDirectInputDevice8W_iface
;
75 static int dinput_mouse_hook( LPDIRECTINPUTDEVICE8A iface
, WPARAM wparam
, LPARAM lparam
);
77 const GUID DInput_Wine_Mouse_GUID
= { /* 9e573ed8-7734-11d2-8d4a-23903fb6bdf7 */
78 0x9e573ed8, 0x7734, 0x11d2, {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
81 static void _dump_mouse_state(const DIMOUSESTATE2
*m_state
)
85 if (!TRACE_ON(dinput
)) return;
87 TRACE("(X: %d Y: %d Z: %d", m_state
->lX
, m_state
->lY
, m_state
->lZ
);
88 for (i
= 0; i
< 5; i
++) TRACE(" B%d: %02x", i
, m_state
->rgbButtons
[i
]);
92 static void fill_mouse_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi
, DWORD version
) {
94 DIDEVICEINSTANCEA ddi
;
96 dwSize
= lpddi
->dwSize
;
98 TRACE("%d %p\n", dwSize
, lpddi
);
100 memset(lpddi
, 0, dwSize
);
101 memset(&ddi
, 0, sizeof(ddi
));
104 ddi
.guidInstance
= GUID_SysMouse
;/* DInput's GUID */
105 ddi
.guidProduct
= DInput_Wine_Mouse_GUID
; /* Vendor's GUID */
106 if (version
>= 0x0800)
107 ddi
.dwDevType
= DI8DEVTYPE_MOUSE
| (DI8DEVTYPEMOUSE_TRADITIONAL
<< 8);
109 ddi
.dwDevType
= DIDEVTYPE_MOUSE
| (DIDEVTYPEMOUSE_TRADITIONAL
<< 8);
110 strcpy(ddi
.tszInstanceName
, "Mouse");
111 strcpy(ddi
.tszProductName
, "Wine Mouse");
113 memcpy(lpddi
, &ddi
, (dwSize
< sizeof(ddi
) ? dwSize
: sizeof(ddi
)));
116 static void fill_mouse_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi
, DWORD version
) {
118 DIDEVICEINSTANCEW ddi
;
120 dwSize
= lpddi
->dwSize
;
122 TRACE("%d %p\n", dwSize
, lpddi
);
124 memset(lpddi
, 0, dwSize
);
125 memset(&ddi
, 0, sizeof(ddi
));
128 ddi
.guidInstance
= GUID_SysMouse
;/* DInput's GUID */
129 ddi
.guidProduct
= DInput_Wine_Mouse_GUID
; /* Vendor's GUID */
130 if (version
>= 0x0800)
131 ddi
.dwDevType
= DI8DEVTYPE_MOUSE
| (DI8DEVTYPEMOUSE_TRADITIONAL
<< 8);
133 ddi
.dwDevType
= DIDEVTYPE_MOUSE
| (DIDEVTYPEMOUSE_TRADITIONAL
<< 8);
134 MultiByteToWideChar(CP_ACP
, 0, "Mouse", -1, ddi
.tszInstanceName
, MAX_PATH
);
135 MultiByteToWideChar(CP_ACP
, 0, "Wine Mouse", -1, ddi
.tszProductName
, MAX_PATH
);
137 memcpy(lpddi
, &ddi
, (dwSize
< sizeof(ddi
) ? dwSize
: sizeof(ddi
)));
140 static HRESULT
mousedev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
145 if ((dwDevType
== 0) ||
146 ((dwDevType
== DIDEVTYPE_MOUSE
) && (version
< 0x0800)) ||
147 (((dwDevType
== DI8DEVCLASS_POINTER
) || (dwDevType
== DI8DEVTYPE_MOUSE
)) && (version
>= 0x0800))) {
148 TRACE("Enumerating the mouse device\n");
150 fill_mouse_dideviceinstanceA(lpddi
, version
);
158 static HRESULT
mousedev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
163 if ((dwDevType
== 0) ||
164 ((dwDevType
== DIDEVTYPE_MOUSE
) && (version
< 0x0800)) ||
165 (((dwDevType
== DI8DEVCLASS_POINTER
) || (dwDevType
== DI8DEVTYPE_MOUSE
)) && (version
>= 0x0800))) {
166 TRACE("Enumerating the mouse device\n");
168 fill_mouse_dideviceinstanceW(lpddi
, version
);
176 static SysMouseImpl
*alloc_device(REFGUID rguid
, IDirectInputImpl
*dinput
)
178 SysMouseImpl
* newDevice
;
179 LPDIDATAFORMAT df
= NULL
;
184 newDevice
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(SysMouseImpl
));
185 if (!newDevice
) return NULL
;
186 newDevice
->base
.IDirectInputDevice8A_iface
.lpVtbl
= &SysMouseAvt
;
187 newDevice
->base
.IDirectInputDevice8W_iface
.lpVtbl
= &SysMouseWvt
;
188 newDevice
->base
.ref
= 1;
189 newDevice
->base
.dwCoopLevel
= DISCL_NONEXCLUSIVE
| DISCL_BACKGROUND
;
190 newDevice
->base
.guid
= *rguid
;
191 InitializeCriticalSection(&newDevice
->base
.crit
);
192 newDevice
->base
.crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": SysMouseImpl*->base.crit");
193 newDevice
->base
.dinput
= dinput
;
194 newDevice
->base
.event_proc
= dinput_mouse_hook
;
196 get_app_key(&hkey
, &appkey
);
197 if (!get_config_key(hkey
, appkey
, "MouseWarpOverride", buffer
, sizeof(buffer
)))
199 if (!strcasecmp(buffer
, "disable"))
200 newDevice
->warp_override
= WARP_DISABLE
;
201 else if (!strcasecmp(buffer
, "force"))
202 newDevice
->warp_override
= WARP_FORCE_ON
;
204 if (appkey
) RegCloseKey(appkey
);
205 if (hkey
) RegCloseKey(hkey
);
207 /* Create copy of default data format */
208 if (!(df
= HeapAlloc(GetProcessHeap(), 0, c_dfDIMouse2
.dwSize
))) goto failed
;
209 memcpy(df
, &c_dfDIMouse2
, c_dfDIMouse2
.dwSize
);
210 if (!(df
->rgodf
= HeapAlloc(GetProcessHeap(), 0, df
->dwNumObjs
* df
->dwObjSize
))) goto failed
;
211 memcpy(df
->rgodf
, c_dfDIMouse2
.rgodf
, df
->dwNumObjs
* df
->dwObjSize
);
213 /* Because we don't do any detection yet just modify instance and type */
214 for (i
= 0; i
< df
->dwNumObjs
; i
++)
215 if (DIDFT_GETTYPE(df
->rgodf
[i
].dwType
) & DIDFT_AXIS
)
216 df
->rgodf
[i
].dwType
= DIDFT_MAKEINSTANCE(i
) | DIDFT_RELAXIS
;
218 df
->rgodf
[i
].dwType
= DIDFT_MAKEINSTANCE(i
) | DIDFT_PSHBUTTON
;
220 newDevice
->base
.data_format
.wine_df
= df
;
221 IDirectInput_AddRef(&newDevice
->base
.dinput
->IDirectInput7A_iface
);
223 EnterCriticalSection(&dinput
->crit
);
224 list_add_tail(&dinput
->devices_list
, &newDevice
->base
.entry
);
225 LeaveCriticalSection(&dinput
->crit
);
230 if (df
) HeapFree(GetProcessHeap(), 0, df
->rgodf
);
231 HeapFree(GetProcessHeap(), 0, df
);
232 HeapFree(GetProcessHeap(), 0, newDevice
);
236 static HRESULT
mousedev_create_device(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPVOID
*pdev
, int unicode
)
238 TRACE("%p %s %s %p %i\n", dinput
, debugstr_guid(rguid
), debugstr_guid(riid
), pdev
, unicode
);
241 if (IsEqualGUID(&GUID_SysMouse
, rguid
) || /* Generic Mouse */
242 IsEqualGUID(&DInput_Wine_Mouse_GUID
, rguid
)) /* Wine Mouse */
248 else if (IsEqualGUID(&IID_IDirectInputDeviceA
, riid
) ||
249 IsEqualGUID(&IID_IDirectInputDevice2A
, riid
) ||
250 IsEqualGUID(&IID_IDirectInputDevice7A
, riid
) ||
251 IsEqualGUID(&IID_IDirectInputDevice8A
, riid
))
255 else if (IsEqualGUID(&IID_IDirectInputDeviceW
, riid
) ||
256 IsEqualGUID(&IID_IDirectInputDevice2W
, riid
) ||
257 IsEqualGUID(&IID_IDirectInputDevice7W
, riid
) ||
258 IsEqualGUID(&IID_IDirectInputDevice8W
, riid
))
264 WARN("no interface\n");
265 return DIERR_NOINTERFACE
;
268 This
= alloc_device(rguid
, dinput
);
269 TRACE("Created a Mouse device (%p)\n", This
);
271 if (!This
) return DIERR_OUTOFMEMORY
;
274 *pdev
= &This
->base
.IDirectInputDevice8W_iface
;
276 *pdev
= &This
->base
.IDirectInputDevice8A_iface
;
281 return DIERR_DEVICENOTREG
;
284 const struct dinput_device mouse_device
= {
286 mousedev_enum_deviceA
,
287 mousedev_enum_deviceW
,
288 mousedev_create_device
291 /******************************************************************************
292 * SysMouseA (DInput Mouse support)
295 /* low-level mouse hook */
296 static int dinput_mouse_hook( LPDIRECTINPUTDEVICE8A iface
, WPARAM wparam
, LPARAM lparam
)
298 MSLLHOOKSTRUCT
*hook
= (MSLLHOOKSTRUCT
*)lparam
;
299 SysMouseImpl
* This
= impl_from_IDirectInputDevice8A(iface
);
300 int wdata
= 0, inst_id
= -1, ret
= 0;
302 TRACE("msg %lx @ (%d %d)\n", wparam
, hook
->pt
.x
, hook
->pt
.y
);
304 EnterCriticalSection(&This
->base
.crit
);
312 This
->m_state
.lX
+= pt
.x
= hook
->pt
.x
- pt
.x
;
313 This
->m_state
.lY
+= pt
.y
= hook
->pt
.y
- pt
.y
;
315 if (This
->base
.data_format
.user_df
->dwFlags
& DIDF_ABSAXIS
)
317 pt1
.x
= This
->m_state
.lX
;
318 pt1
.y
= This
->m_state
.lY
;
324 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE
) | DIDFT_RELAXIS
;
329 /* Already have X, need to queue it */
331 queue_event(iface
, inst_id
,
332 wdata
, GetCurrentTime(), This
->base
.dinput
->evsequence
);
333 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE
) | DIDFT_RELAXIS
;
339 if ((This
->warp_override
== WARP_FORCE_ON
) ||
340 (This
->warp_override
!= WARP_DISABLE
&& (This
->base
.dwCoopLevel
& DISCL_EXCLUSIVE
)))
341 This
->need_warp
= TRUE
;
346 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_Z_AXIS_INSTANCE
) | DIDFT_RELAXIS
;
347 This
->m_state
.lZ
+= wdata
= (short)HIWORD(hook
->mouseData
);
348 /* FarCry crashes if it gets a mouse wheel message */
349 /* FIXME: should probably filter out other messages too */
353 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 0) | DIDFT_PSHBUTTON
;
354 This
->m_state
.rgbButtons
[0] = wdata
= 0x80;
357 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 0) | DIDFT_PSHBUTTON
;
358 This
->m_state
.rgbButtons
[0] = wdata
= 0x00;
361 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 1) | DIDFT_PSHBUTTON
;
362 This
->m_state
.rgbButtons
[1] = wdata
= 0x80;
365 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 1) | DIDFT_PSHBUTTON
;
366 This
->m_state
.rgbButtons
[1] = wdata
= 0x00;
369 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 2) | DIDFT_PSHBUTTON
;
370 This
->m_state
.rgbButtons
[2] = wdata
= 0x80;
373 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 2) | DIDFT_PSHBUTTON
;
374 This
->m_state
.rgbButtons
[2] = wdata
= 0x00;
377 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 2 + HIWORD(hook
->mouseData
)) | DIDFT_PSHBUTTON
;
378 This
->m_state
.rgbButtons
[2 + HIWORD(hook
->mouseData
)] = wdata
= 0x80;
381 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 2 + HIWORD(hook
->mouseData
)) | DIDFT_PSHBUTTON
;
382 This
->m_state
.rgbButtons
[2 + HIWORD(hook
->mouseData
)] = wdata
= 0x00;
389 _dump_mouse_state(&This
->m_state
);
390 queue_event(iface
, inst_id
,
391 wdata
, GetCurrentTime(), This
->base
.dinput
->evsequence
++);
394 LeaveCriticalSection(&This
->base
.crit
);
398 static void warp_check( SysMouseImpl
* This
, BOOL force
)
400 DWORD now
= GetCurrentTime();
401 const DWORD interval
= This
->clipped
? 500 : 10;
403 if (force
|| (This
->need_warp
&& (now
- This
->last_warped
> interval
)))
408 This
->last_warped
= now
;
409 This
->need_warp
= FALSE
;
410 if (!GetClientRect(This
->base
.win
, &rect
)) return;
411 MapWindowPoints( This
->base
.win
, 0, (POINT
*)&rect
, 2 );
414 mapped_center
.x
= (rect
.left
+ rect
.right
) / 2;
415 mapped_center
.y
= (rect
.top
+ rect
.bottom
) / 2;
416 TRACE("Warping mouse to %d - %d\n", mapped_center
.x
, mapped_center
.y
);
417 SetCursorPos( mapped_center
.x
, mapped_center
.y
);
419 if (This
->base
.dwCoopLevel
& DISCL_EXCLUSIVE
)
421 /* make sure we clip even if the window covers the whole screen */
422 rect
.left
= max( rect
.left
, GetSystemMetrics( SM_XVIRTUALSCREEN
) + 1 );
423 rect
.top
= max( rect
.top
, GetSystemMetrics( SM_YVIRTUALSCREEN
) + 1 );
424 rect
.right
= min( rect
.right
, rect
.left
+ GetSystemMetrics( SM_CXVIRTUALSCREEN
) - 2 );
425 rect
.bottom
= min( rect
.bottom
, rect
.top
+ GetSystemMetrics( SM_CYVIRTUALSCREEN
) - 2 );
426 TRACE("Clipping mouse to %s\n", wine_dbgstr_rect( &rect
));
428 This
->clipped
= GetClipCursor( &new_rect
) && EqualRect( &rect
, &new_rect
);
434 /******************************************************************************
435 * Acquire : gets exclusive control of the mouse
437 static HRESULT WINAPI
SysMouseWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface
)
439 SysMouseImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
443 TRACE("(this=%p)\n",This
);
445 if ((res
= IDirectInputDevice2WImpl_Acquire(iface
)) != DI_OK
) return res
;
447 /* Init the mouse state */
448 GetCursorPos( &point
);
449 if (This
->base
.data_format
.user_df
->dwFlags
& DIDF_ABSAXIS
)
451 This
->m_state
.lX
= point
.x
;
452 This
->m_state
.lY
= point
.y
;
454 This
->m_state
.lX
= 0;
455 This
->m_state
.lY
= 0;
456 This
->org_coords
= point
;
458 This
->m_state
.lZ
= 0;
459 This
->m_state
.rgbButtons
[0] = GetKeyState(VK_LBUTTON
) & 0x80;
460 This
->m_state
.rgbButtons
[1] = GetKeyState(VK_RBUTTON
) & 0x80;
461 This
->m_state
.rgbButtons
[2] = GetKeyState(VK_MBUTTON
) & 0x80;
463 if (This
->base
.dwCoopLevel
& DISCL_EXCLUSIVE
)
465 ShowCursor(FALSE
); /* hide cursor */
466 warp_check( This
, TRUE
);
468 else if (This
->warp_override
== WARP_FORCE_ON
)
470 /* Need a window to warp mouse in. */
471 if (!This
->base
.win
) This
->base
.win
= GetDesktopWindow();
472 warp_check( This
, TRUE
);
474 else if (This
->clipped
)
477 This
->clipped
= FALSE
;
483 static HRESULT WINAPI
SysMouseAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
485 SysMouseImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
486 return SysMouseWImpl_Acquire(IDirectInputDevice8W_from_impl(This
));
489 /******************************************************************************
490 * Unacquire : frees the mouse
492 static HRESULT WINAPI
SysMouseWImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface
)
494 SysMouseImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
497 TRACE("(this=%p)\n",This
);
499 if ((res
= IDirectInputDevice2WImpl_Unacquire(iface
)) != DI_OK
) return res
;
501 if (This
->base
.dwCoopLevel
& DISCL_EXCLUSIVE
)
504 ShowCursor(TRUE
); /* show cursor */
505 This
->clipped
= FALSE
;
508 /* And put the mouse cursor back where it was at acquire time */
509 if (This
->base
.dwCoopLevel
& DISCL_EXCLUSIVE
|| This
->warp_override
== WARP_FORCE_ON
)
511 TRACE("warping mouse back to %s\n", wine_dbgstr_point(&This
->org_coords
));
512 SetCursorPos(This
->org_coords
.x
, This
->org_coords
.y
);
518 static HRESULT WINAPI
SysMouseAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
520 SysMouseImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
521 return SysMouseWImpl_Unacquire(IDirectInputDevice8W_from_impl(This
));
524 /******************************************************************************
525 * GetDeviceState : returns the "state" of the mouse.
527 * For the moment, only the "standard" return structure (DIMOUSESTATE) is
530 static HRESULT WINAPI
SysMouseWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W iface
, DWORD len
, LPVOID ptr
)
532 SysMouseImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
533 TRACE("(%p)->(%u,%p)\n", This
, len
, ptr
);
535 if(This
->base
.acquired
== 0) return DIERR_NOTACQUIRED
;
537 check_dinput_events();
539 EnterCriticalSection(&This
->base
.crit
);
540 _dump_mouse_state(&This
->m_state
);
542 /* Copy the current mouse state */
543 fill_DataFormat(ptr
, len
, &This
->m_state
, &This
->base
.data_format
);
545 /* Initialize the buffer when in relative mode */
546 if (!(This
->base
.data_format
.user_df
->dwFlags
& DIDF_ABSAXIS
))
548 This
->m_state
.lX
= 0;
549 This
->m_state
.lY
= 0;
550 This
->m_state
.lZ
= 0;
552 LeaveCriticalSection(&This
->base
.crit
);
554 warp_check( This
, FALSE
);
558 static HRESULT WINAPI
SysMouseAImpl_GetDeviceState(LPDIRECTINPUTDEVICE8A iface
, DWORD len
, LPVOID ptr
)
560 SysMouseImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
561 return SysMouseWImpl_GetDeviceState(IDirectInputDevice8W_from_impl(This
), len
, ptr
);
564 /******************************************************************************
565 * GetDeviceData : gets buffered input data.
567 static HRESULT WINAPI
SysMouseWImpl_GetDeviceData(LPDIRECTINPUTDEVICE8W iface
,
568 DWORD dodsize
, LPDIDEVICEOBJECTDATA dod
, LPDWORD entries
, DWORD flags
)
570 SysMouseImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
573 res
= IDirectInputDevice2WImpl_GetDeviceData(iface
, dodsize
, dod
, entries
, flags
);
574 if (SUCCEEDED(res
)) warp_check( This
, FALSE
);
578 static HRESULT WINAPI
SysMouseAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface
,
579 DWORD dodsize
, LPDIDEVICEOBJECTDATA dod
, LPDWORD entries
, DWORD flags
)
581 SysMouseImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
582 return SysMouseWImpl_GetDeviceData(IDirectInputDevice8W_from_impl(This
), dodsize
, dod
, entries
, flags
);
585 /******************************************************************************
586 * GetProperty : get input device properties
588 static HRESULT WINAPI
SysMouseWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
, LPDIPROPHEADER pdiph
)
590 SysMouseImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
592 TRACE("(%p) %s,%p\n", This
, debugstr_guid(rguid
), pdiph
);
593 _dump_DIPROPHEADER(pdiph
);
595 if (IS_DIPROP(rguid
)) {
596 switch (LOWORD(rguid
)) {
597 case (DWORD_PTR
) DIPROP_GRANULARITY
: {
598 LPDIPROPDWORD pr
= (LPDIPROPDWORD
) pdiph
;
600 /* We'll just assume that the app asks about the Z axis */
601 pr
->dwData
= WHEEL_DELTA
;
606 case (DWORD_PTR
) DIPROP_RANGE
: {
607 LPDIPROPRANGE pr
= (LPDIPROPRANGE
) pdiph
;
609 if ((pdiph
->dwHow
== DIPH_BYID
) &&
610 ((pdiph
->dwObj
== (DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE
) | DIDFT_RELAXIS
)) ||
611 (pdiph
->dwObj
== (DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE
) | DIDFT_RELAXIS
)))) {
612 /* Querying the range of either the X or the Y axis. As I do
613 not know the range, do as if the range were
615 pr
->lMin
= DIPROPRANGE_NOMIN
;
616 pr
->lMax
= DIPROPRANGE_NOMAX
;
623 return IDirectInputDevice2WImpl_GetProperty(iface
, rguid
, pdiph
);
630 static HRESULT WINAPI
SysMouseAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
, LPDIPROPHEADER pdiph
)
632 SysMouseImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
633 return SysMouseWImpl_GetProperty(IDirectInputDevice8W_from_impl(This
), rguid
, pdiph
);
636 /******************************************************************************
637 * GetCapabilities : get the device capabilities
639 static HRESULT WINAPI
SysMouseWImpl_GetCapabilities(LPDIRECTINPUTDEVICE8W iface
, LPDIDEVCAPS lpDIDevCaps
)
641 SysMouseImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
644 TRACE("(this=%p,%p)\n",This
,lpDIDevCaps
);
646 if ((lpDIDevCaps
->dwSize
!= sizeof(DIDEVCAPS
)) && (lpDIDevCaps
->dwSize
!= sizeof(DIDEVCAPS_DX3
))) {
647 WARN("invalid parameter\n");
648 return DIERR_INVALIDPARAM
;
651 devcaps
.dwSize
= lpDIDevCaps
->dwSize
;
652 devcaps
.dwFlags
= DIDC_ATTACHED
| DIDC_EMULATED
;
653 if (This
->base
.dinput
->dwVersion
>= 0x0800)
654 devcaps
.dwDevType
= DI8DEVTYPE_MOUSE
| (DI8DEVTYPEMOUSE_TRADITIONAL
<< 8);
656 devcaps
.dwDevType
= DIDEVTYPE_MOUSE
| (DIDEVTYPEMOUSE_TRADITIONAL
<< 8);
658 devcaps
.dwButtons
= 8;
660 devcaps
.dwFFSamplePeriod
= 0;
661 devcaps
.dwFFMinTimeResolution
= 0;
662 devcaps
.dwFirmwareRevision
= 100;
663 devcaps
.dwHardwareRevision
= 100;
664 devcaps
.dwFFDriverVersion
= 0;
666 memcpy(lpDIDevCaps
, &devcaps
, lpDIDevCaps
->dwSize
);
671 static HRESULT WINAPI
SysMouseAImpl_GetCapabilities(LPDIRECTINPUTDEVICE8A iface
, LPDIDEVCAPS lpDIDevCaps
)
673 SysMouseImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
674 return SysMouseWImpl_GetCapabilities(IDirectInputDevice8W_from_impl(This
), lpDIDevCaps
);
677 /******************************************************************************
678 * GetObjectInfo : get information about a device object such as a button
681 static HRESULT WINAPI
SysMouseWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface
,
682 LPDIDEVICEOBJECTINSTANCEW pdidoi
, DWORD dwObj
, DWORD dwHow
)
684 static const WCHAR x_axisW
[] = {'X','-','A','x','i','s',0};
685 static const WCHAR y_axisW
[] = {'Y','-','A','x','i','s',0};
686 static const WCHAR wheelW
[] = {'W','h','e','e','l',0};
687 static const WCHAR buttonW
[] = {'B','u','t','t','o','n',' ','%','d',0};
690 res
= IDirectInputDevice2WImpl_GetObjectInfo(iface
, pdidoi
, dwObj
, dwHow
);
691 if (res
!= DI_OK
) return res
;
693 if (IsEqualGUID(&pdidoi
->guidType
, &GUID_XAxis
)) strcpyW(pdidoi
->tszName
, x_axisW
);
694 else if (IsEqualGUID(&pdidoi
->guidType
, &GUID_YAxis
)) strcpyW(pdidoi
->tszName
, y_axisW
);
695 else if (IsEqualGUID(&pdidoi
->guidType
, &GUID_ZAxis
)) strcpyW(pdidoi
->tszName
, wheelW
);
696 else if (pdidoi
->dwType
& DIDFT_BUTTON
)
697 wsprintfW(pdidoi
->tszName
, buttonW
, DIDFT_GETINSTANCE(pdidoi
->dwType
) - 3);
699 _dump_OBJECTINSTANCEW(pdidoi
);
703 static HRESULT WINAPI
SysMouseAImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8A iface
,
704 LPDIDEVICEOBJECTINSTANCEA pdidoi
, DWORD dwObj
, DWORD dwHow
)
706 SysMouseImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
708 DIDEVICEOBJECTINSTANCEW didoiW
;
709 DWORD dwSize
= pdidoi
->dwSize
;
711 didoiW
.dwSize
= sizeof(didoiW
);
712 res
= SysMouseWImpl_GetObjectInfo(IDirectInputDevice8W_from_impl(This
), &didoiW
, dwObj
, dwHow
);
713 if (res
!= DI_OK
) return res
;
715 memset(pdidoi
, 0, pdidoi
->dwSize
);
716 memcpy(pdidoi
, &didoiW
, FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW
, tszName
));
717 pdidoi
->dwSize
= dwSize
;
718 WideCharToMultiByte(CP_ACP
, 0, didoiW
.tszName
, -1, pdidoi
->tszName
,
719 sizeof(pdidoi
->tszName
), NULL
, NULL
);
724 /******************************************************************************
725 * GetDeviceInfo : get information about a device's identity
727 static HRESULT WINAPI
SysMouseAImpl_GetDeviceInfo(
728 LPDIRECTINPUTDEVICE8A iface
,
729 LPDIDEVICEINSTANCEA pdidi
)
731 SysMouseImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
732 TRACE("(this=%p,%p)\n", This
, pdidi
);
734 if (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEA
)) {
735 WARN(" dinput3 not supported yet...\n");
739 fill_mouse_dideviceinstanceA(pdidi
, This
->base
.dinput
->dwVersion
);
744 static HRESULT WINAPI
SysMouseWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface
, LPDIDEVICEINSTANCEW pdidi
)
746 SysMouseImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
747 TRACE("(this=%p,%p)\n", This
, pdidi
);
749 if (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEW
)) {
750 WARN(" dinput3 not supported yet...\n");
754 fill_mouse_dideviceinstanceW(pdidi
, This
->base
.dinput
->dwVersion
);
759 static HRESULT WINAPI
SysMouseWImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface
,
760 LPDIACTIONFORMATW lpdiaf
,
761 LPCWSTR lpszUserName
,
764 FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface
, lpdiaf
, debugstr_w(lpszUserName
), dwFlags
);
766 return _build_action_map(iface
, lpdiaf
, lpszUserName
, dwFlags
, DIMOUSE_MASK
, &c_dfDIMouse2
);
769 static HRESULT WINAPI
SysMouseAImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface
,
770 LPDIACTIONFORMATA lpdiaf
,
774 SysMouseImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
775 DIACTIONFORMATW diafW
;
777 WCHAR
*lpszUserNameW
= NULL
;
780 diafW
.rgoAction
= HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW
)*lpdiaf
->dwNumActions
);
781 _copy_diactionformatAtoW(&diafW
, lpdiaf
);
783 if (lpszUserName
!= NULL
)
785 username_size
= MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, NULL
, 0);
786 lpszUserNameW
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*username_size
);
787 MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, lpszUserNameW
, username_size
);
790 hr
= SysMouseWImpl_BuildActionMap(&This
->base
.IDirectInputDevice8W_iface
, &diafW
, lpszUserNameW
, dwFlags
);
792 _copy_diactionformatWtoA(lpdiaf
, &diafW
);
793 HeapFree(GetProcessHeap(), 0, diafW
.rgoAction
);
794 HeapFree(GetProcessHeap(), 0, lpszUserNameW
);
799 static HRESULT WINAPI
SysMouseWImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface
,
800 LPDIACTIONFORMATW lpdiaf
,
801 LPCWSTR lpszUserName
,
804 FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface
, lpdiaf
, debugstr_w(lpszUserName
), dwFlags
);
806 return _set_action_map(iface
, lpdiaf
, lpszUserName
, dwFlags
, &c_dfDIMouse2
);
809 static HRESULT WINAPI
SysMouseAImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface
,
810 LPDIACTIONFORMATA lpdiaf
,
814 SysMouseImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
815 DIACTIONFORMATW diafW
;
817 WCHAR
*lpszUserNameW
= NULL
;
820 diafW
.rgoAction
= HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW
)*lpdiaf
->dwNumActions
);
821 _copy_diactionformatAtoW(&diafW
, lpdiaf
);
823 if (lpszUserName
!= NULL
)
825 username_size
= MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, NULL
, 0);
826 lpszUserNameW
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*username_size
);
827 MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, lpszUserNameW
, username_size
);
830 hr
= SysMouseWImpl_SetActionMap(&This
->base
.IDirectInputDevice8W_iface
, &diafW
, lpszUserNameW
, dwFlags
);
832 HeapFree(GetProcessHeap(), 0, diafW
.rgoAction
);
833 HeapFree(GetProcessHeap(), 0, lpszUserNameW
);
838 static const IDirectInputDevice8AVtbl SysMouseAvt
=
840 IDirectInputDevice2AImpl_QueryInterface
,
841 IDirectInputDevice2AImpl_AddRef
,
842 IDirectInputDevice2AImpl_Release
,
843 SysMouseAImpl_GetCapabilities
,
844 IDirectInputDevice2AImpl_EnumObjects
,
845 SysMouseAImpl_GetProperty
,
846 IDirectInputDevice2AImpl_SetProperty
,
847 SysMouseAImpl_Acquire
,
848 SysMouseAImpl_Unacquire
,
849 SysMouseAImpl_GetDeviceState
,
850 SysMouseAImpl_GetDeviceData
,
851 IDirectInputDevice2AImpl_SetDataFormat
,
852 IDirectInputDevice2AImpl_SetEventNotification
,
853 IDirectInputDevice2AImpl_SetCooperativeLevel
,
854 SysMouseAImpl_GetObjectInfo
,
855 SysMouseAImpl_GetDeviceInfo
,
856 IDirectInputDevice2AImpl_RunControlPanel
,
857 IDirectInputDevice2AImpl_Initialize
,
858 IDirectInputDevice2AImpl_CreateEffect
,
859 IDirectInputDevice2AImpl_EnumEffects
,
860 IDirectInputDevice2AImpl_GetEffectInfo
,
861 IDirectInputDevice2AImpl_GetForceFeedbackState
,
862 IDirectInputDevice2AImpl_SendForceFeedbackCommand
,
863 IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
864 IDirectInputDevice2AImpl_Escape
,
865 IDirectInputDevice2AImpl_Poll
,
866 IDirectInputDevice2AImpl_SendDeviceData
,
867 IDirectInputDevice7AImpl_EnumEffectsInFile
,
868 IDirectInputDevice7AImpl_WriteEffectToFile
,
869 SysMouseAImpl_BuildActionMap
,
870 SysMouseAImpl_SetActionMap
,
871 IDirectInputDevice8AImpl_GetImageInfo
874 static const IDirectInputDevice8WVtbl SysMouseWvt
=
876 IDirectInputDevice2WImpl_QueryInterface
,
877 IDirectInputDevice2WImpl_AddRef
,
878 IDirectInputDevice2WImpl_Release
,
879 SysMouseWImpl_GetCapabilities
,
880 IDirectInputDevice2WImpl_EnumObjects
,
881 SysMouseWImpl_GetProperty
,
882 IDirectInputDevice2WImpl_SetProperty
,
883 SysMouseWImpl_Acquire
,
884 SysMouseWImpl_Unacquire
,
885 SysMouseWImpl_GetDeviceState
,
886 SysMouseWImpl_GetDeviceData
,
887 IDirectInputDevice2WImpl_SetDataFormat
,
888 IDirectInputDevice2WImpl_SetEventNotification
,
889 IDirectInputDevice2WImpl_SetCooperativeLevel
,
890 SysMouseWImpl_GetObjectInfo
,
891 SysMouseWImpl_GetDeviceInfo
,
892 IDirectInputDevice2WImpl_RunControlPanel
,
893 IDirectInputDevice2WImpl_Initialize
,
894 IDirectInputDevice2WImpl_CreateEffect
,
895 IDirectInputDevice2WImpl_EnumEffects
,
896 IDirectInputDevice2WImpl_GetEffectInfo
,
897 IDirectInputDevice2WImpl_GetForceFeedbackState
,
898 IDirectInputDevice2WImpl_SendForceFeedbackCommand
,
899 IDirectInputDevice2WImpl_EnumCreatedEffectObjects
,
900 IDirectInputDevice2WImpl_Escape
,
901 IDirectInputDevice2WImpl_Poll
,
902 IDirectInputDevice2WImpl_SendDeviceData
,
903 IDirectInputDevice7WImpl_EnumEffectsInFile
,
904 IDirectInputDevice7WImpl_WriteEffectToFile
,
905 SysMouseWImpl_BuildActionMap
,
906 SysMouseWImpl_SetActionMap
,
907 IDirectInputDevice8WImpl_GetImageInfo