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
23 #include "wine/port.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
;
63 struct IDirectInputDeviceImpl base
;
66 /* These are used in case of relative -> absolute transitions */
69 /* warping: whether we need to move mouse back to middle once we
70 * reach window borders (for e.g. shooters, "surface movement" games) */
74 /* This is for mouse reporting. */
75 DIMOUSESTATE2 m_state
;
77 WARP_MOUSE warp_override
;
80 static inline SysMouseImpl
*impl_from_IDirectInputDevice8A(IDirectInputDevice8A
*iface
)
82 return CONTAINING_RECORD(CONTAINING_RECORD(iface
, IDirectInputDeviceImpl
, IDirectInputDevice8A_iface
), SysMouseImpl
, base
);
84 static inline SysMouseImpl
*impl_from_IDirectInputDevice8W(IDirectInputDevice8W
*iface
)
86 return CONTAINING_RECORD(CONTAINING_RECORD(iface
, IDirectInputDeviceImpl
, IDirectInputDevice8W_iface
), SysMouseImpl
, base
);
88 static inline IDirectInputDevice8A
*IDirectInputDevice8A_from_impl(SysMouseImpl
*This
)
90 return &This
->base
.IDirectInputDevice8A_iface
;
92 static inline IDirectInputDevice8W
*IDirectInputDevice8W_from_impl(SysMouseImpl
*This
)
94 return &This
->base
.IDirectInputDevice8W_iface
;
97 static int dinput_mouse_hook( LPDIRECTINPUTDEVICE8A iface
, WPARAM wparam
, LPARAM lparam
);
99 const GUID DInput_Wine_Mouse_GUID
= { /* 9e573ed8-7734-11d2-8d4a-23903fb6bdf7 */
100 0x9e573ed8, 0x7734, 0x11d2, {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
103 static void _dump_mouse_state(const DIMOUSESTATE2
*m_state
)
107 if (!TRACE_ON(dinput
)) return;
109 TRACE("(X: %d Y: %d Z: %d", m_state
->lX
, m_state
->lY
, m_state
->lZ
);
110 for (i
= 0; i
< 5; i
++) TRACE(" B%d: %02x", i
, m_state
->rgbButtons
[i
]);
114 static void fill_mouse_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi
, DWORD version
) {
116 DIDEVICEINSTANCEA ddi
;
118 dwSize
= lpddi
->dwSize
;
120 TRACE("%d %p\n", dwSize
, lpddi
);
122 memset(lpddi
, 0, dwSize
);
123 memset(&ddi
, 0, sizeof(ddi
));
126 ddi
.guidInstance
= GUID_SysMouse
;/* DInput's GUID */
127 ddi
.guidProduct
= DInput_Wine_Mouse_GUID
; /* Vendor's GUID */
128 if (version
>= 0x0800)
129 ddi
.dwDevType
= DI8DEVTYPE_MOUSE
| (DI8DEVTYPEMOUSE_TRADITIONAL
<< 8);
131 ddi
.dwDevType
= DIDEVTYPE_MOUSE
| (DIDEVTYPEMOUSE_TRADITIONAL
<< 8);
132 strcpy(ddi
.tszInstanceName
, "Mouse");
133 strcpy(ddi
.tszProductName
, "Wine Mouse");
135 memcpy(lpddi
, &ddi
, (dwSize
< sizeof(ddi
) ? dwSize
: sizeof(ddi
)));
138 static void fill_mouse_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi
, DWORD version
) {
140 DIDEVICEINSTANCEW ddi
;
142 dwSize
= lpddi
->dwSize
;
144 TRACE("%d %p\n", dwSize
, lpddi
);
146 memset(lpddi
, 0, dwSize
);
147 memset(&ddi
, 0, sizeof(ddi
));
150 ddi
.guidInstance
= GUID_SysMouse
;/* DInput's GUID */
151 ddi
.guidProduct
= DInput_Wine_Mouse_GUID
; /* Vendor's GUID */
152 if (version
>= 0x0800)
153 ddi
.dwDevType
= DI8DEVTYPE_MOUSE
| (DI8DEVTYPEMOUSE_TRADITIONAL
<< 8);
155 ddi
.dwDevType
= DIDEVTYPE_MOUSE
| (DIDEVTYPEMOUSE_TRADITIONAL
<< 8);
156 MultiByteToWideChar(CP_ACP
, 0, "Mouse", -1, ddi
.tszInstanceName
, MAX_PATH
);
157 MultiByteToWideChar(CP_ACP
, 0, "Wine Mouse", -1, ddi
.tszProductName
, MAX_PATH
);
159 memcpy(lpddi
, &ddi
, (dwSize
< sizeof(ddi
) ? dwSize
: sizeof(ddi
)));
162 static BOOL
mousedev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
167 if ((dwDevType
== 0) ||
168 ((dwDevType
== DIDEVTYPE_MOUSE
) && (version
< 0x0800)) ||
169 (((dwDevType
== DI8DEVCLASS_POINTER
) || (dwDevType
== DI8DEVTYPE_MOUSE
)) && (version
>= 0x0800))) {
170 TRACE("Enumerating the mouse device\n");
172 fill_mouse_dideviceinstanceA(lpddi
, version
);
180 static BOOL
mousedev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
185 if ((dwDevType
== 0) ||
186 ((dwDevType
== DIDEVTYPE_MOUSE
) && (version
< 0x0800)) ||
187 (((dwDevType
== DI8DEVCLASS_POINTER
) || (dwDevType
== DI8DEVTYPE_MOUSE
)) && (version
>= 0x0800))) {
188 TRACE("Enumerating the mouse device\n");
190 fill_mouse_dideviceinstanceW(lpddi
, version
);
198 static SysMouseImpl
*alloc_device(REFGUID rguid
, IDirectInputImpl
*dinput
)
200 SysMouseImpl
* newDevice
;
201 LPDIDATAFORMAT df
= NULL
;
206 newDevice
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(SysMouseImpl
));
207 if (!newDevice
) return NULL
;
208 newDevice
->base
.IDirectInputDevice8A_iface
.lpVtbl
= &SysMouseAvt
;
209 newDevice
->base
.IDirectInputDevice8W_iface
.lpVtbl
= &SysMouseWvt
;
210 newDevice
->base
.ref
= 1;
211 newDevice
->base
.dwCoopLevel
= DISCL_NONEXCLUSIVE
| DISCL_BACKGROUND
;
212 newDevice
->base
.guid
= *rguid
;
213 InitializeCriticalSection(&newDevice
->base
.crit
);
214 newDevice
->base
.crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": SysMouseImpl*->base.crit");
215 newDevice
->base
.dinput
= dinput
;
216 newDevice
->base
.event_proc
= dinput_mouse_hook
;
218 get_app_key(&hkey
, &appkey
);
219 if (!get_config_key(hkey
, appkey
, "MouseWarpOverride", buffer
, sizeof(buffer
)))
221 if (!strcasecmp(buffer
, "disable"))
222 newDevice
->warp_override
= WARP_DISABLE
;
223 else if (!strcasecmp(buffer
, "force"))
224 newDevice
->warp_override
= WARP_FORCE_ON
;
226 if (appkey
) RegCloseKey(appkey
);
227 if (hkey
) RegCloseKey(hkey
);
229 /* Create copy of default data format */
230 if (!(df
= HeapAlloc(GetProcessHeap(), 0, c_dfDIMouse2
.dwSize
))) goto failed
;
231 memcpy(df
, &c_dfDIMouse2
, c_dfDIMouse2
.dwSize
);
232 if (!(df
->rgodf
= HeapAlloc(GetProcessHeap(), 0, df
->dwNumObjs
* df
->dwObjSize
))) goto failed
;
233 memcpy(df
->rgodf
, c_dfDIMouse2
.rgodf
, df
->dwNumObjs
* df
->dwObjSize
);
235 /* Because we don't do any detection yet just modify instance and type */
236 for (i
= 0; i
< df
->dwNumObjs
; i
++)
237 if (DIDFT_GETTYPE(df
->rgodf
[i
].dwType
) & DIDFT_AXIS
)
238 df
->rgodf
[i
].dwType
= DIDFT_MAKEINSTANCE(i
) | DIDFT_RELAXIS
;
240 df
->rgodf
[i
].dwType
= DIDFT_MAKEINSTANCE(i
) | DIDFT_PSHBUTTON
;
242 newDevice
->base
.data_format
.wine_df
= df
;
243 IDirectInput_AddRef(&newDevice
->base
.dinput
->IDirectInput7A_iface
);
245 EnterCriticalSection(&dinput
->crit
);
246 list_add_tail(&dinput
->devices_list
, &newDevice
->base
.entry
);
247 LeaveCriticalSection(&dinput
->crit
);
252 if (df
) HeapFree(GetProcessHeap(), 0, df
->rgodf
);
253 HeapFree(GetProcessHeap(), 0, df
);
254 HeapFree(GetProcessHeap(), 0, newDevice
);
258 static HRESULT
mousedev_create_device(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPVOID
*pdev
, int unicode
)
260 TRACE("%p %s %s %p %i\n", dinput
, debugstr_guid(rguid
), debugstr_guid(riid
), pdev
, unicode
);
263 if (IsEqualGUID(&GUID_SysMouse
, rguid
) || /* Generic Mouse */
264 IsEqualGUID(&DInput_Wine_Mouse_GUID
, rguid
)) /* Wine Mouse */
270 else if (IsEqualGUID(&IID_IDirectInputDeviceA
, riid
) ||
271 IsEqualGUID(&IID_IDirectInputDevice2A
, riid
) ||
272 IsEqualGUID(&IID_IDirectInputDevice7A
, riid
) ||
273 IsEqualGUID(&IID_IDirectInputDevice8A
, riid
))
277 else if (IsEqualGUID(&IID_IDirectInputDeviceW
, riid
) ||
278 IsEqualGUID(&IID_IDirectInputDevice2W
, riid
) ||
279 IsEqualGUID(&IID_IDirectInputDevice7W
, riid
) ||
280 IsEqualGUID(&IID_IDirectInputDevice8W
, riid
))
286 WARN("no interface\n");
287 return DIERR_NOINTERFACE
;
290 This
= alloc_device(rguid
, dinput
);
291 TRACE("Created a Mouse device (%p)\n", This
);
293 if (!This
) return DIERR_OUTOFMEMORY
;
296 *pdev
= &This
->base
.IDirectInputDevice8W_iface
;
298 *pdev
= &This
->base
.IDirectInputDevice8A_iface
;
303 return DIERR_DEVICENOTREG
;
306 const struct dinput_device mouse_device
= {
308 mousedev_enum_deviceA
,
309 mousedev_enum_deviceW
,
310 mousedev_create_device
313 /******************************************************************************
314 * SysMouseA (DInput Mouse support)
317 /* low-level mouse hook */
318 static int dinput_mouse_hook( LPDIRECTINPUTDEVICE8A iface
, WPARAM wparam
, LPARAM lparam
)
320 MSLLHOOKSTRUCT
*hook
= (MSLLHOOKSTRUCT
*)lparam
;
321 SysMouseImpl
* This
= impl_from_IDirectInputDevice8A(iface
);
322 int wdata
= 0, inst_id
= -1;
324 TRACE("msg %lx @ (%d %d)\n", wparam
, hook
->pt
.x
, hook
->pt
.y
);
326 EnterCriticalSection(&This
->base
.crit
);
334 This
->m_state
.lX
+= pt
.x
= hook
->pt
.x
- pt
.x
;
335 This
->m_state
.lY
+= pt
.y
= hook
->pt
.y
- pt
.y
;
337 if (This
->base
.data_format
.user_df
->dwFlags
& DIDF_ABSAXIS
)
339 pt1
.x
= This
->m_state
.lX
;
340 pt1
.y
= This
->m_state
.lY
;
346 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE
) | DIDFT_RELAXIS
;
351 /* Already have X, need to queue it */
353 queue_event(iface
, inst_id
,
354 wdata
, GetCurrentTime(), This
->base
.dinput
->evsequence
);
355 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE
) | DIDFT_RELAXIS
;
361 if ((This
->warp_override
== WARP_FORCE_ON
) ||
362 (This
->warp_override
!= WARP_DISABLE
&& (This
->base
.dwCoopLevel
& DISCL_EXCLUSIVE
)))
363 This
->need_warp
= TRUE
;
368 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_Z_AXIS_INSTANCE
) | DIDFT_RELAXIS
;
369 This
->m_state
.lZ
+= wdata
= (short)HIWORD(hook
->mouseData
);
372 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 0) | DIDFT_PSHBUTTON
;
373 This
->m_state
.rgbButtons
[0] = wdata
= 0x80;
376 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 0) | DIDFT_PSHBUTTON
;
377 This
->m_state
.rgbButtons
[0] = wdata
= 0x00;
380 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 1) | DIDFT_PSHBUTTON
;
381 This
->m_state
.rgbButtons
[1] = wdata
= 0x80;
384 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 1) | DIDFT_PSHBUTTON
;
385 This
->m_state
.rgbButtons
[1] = wdata
= 0x00;
388 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 2) | DIDFT_PSHBUTTON
;
389 This
->m_state
.rgbButtons
[2] = wdata
= 0x80;
392 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 2) | DIDFT_PSHBUTTON
;
393 This
->m_state
.rgbButtons
[2] = wdata
= 0x00;
396 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 2 + HIWORD(hook
->mouseData
)) | DIDFT_PSHBUTTON
;
397 This
->m_state
.rgbButtons
[2 + HIWORD(hook
->mouseData
)] = wdata
= 0x80;
400 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 2 + HIWORD(hook
->mouseData
)) | DIDFT_PSHBUTTON
;
401 This
->m_state
.rgbButtons
[2 + HIWORD(hook
->mouseData
)] = wdata
= 0x00;
408 _dump_mouse_state(&This
->m_state
);
409 queue_event(iface
, inst_id
,
410 wdata
, GetCurrentTime(), This
->base
.dinput
->evsequence
++);
413 LeaveCriticalSection(&This
->base
.crit
);
417 static void warp_check( SysMouseImpl
* This
, BOOL force
)
419 DWORD now
= GetCurrentTime();
420 const DWORD interval
= This
->clipped
? 500 : 10;
422 if (force
|| (This
->need_warp
&& (now
- This
->last_warped
> interval
)))
427 This
->last_warped
= now
;
428 This
->need_warp
= FALSE
;
429 if (!GetWindowRect(This
->base
.win
, &rect
)) return;
432 mapped_center
.x
= (rect
.left
+ rect
.right
) / 2;
433 mapped_center
.y
= (rect
.top
+ rect
.bottom
) / 2;
434 TRACE("Warping mouse to %d - %d\n", mapped_center
.x
, mapped_center
.y
);
435 SetCursorPos( mapped_center
.x
, mapped_center
.y
);
437 if (This
->base
.dwCoopLevel
& DISCL_EXCLUSIVE
)
439 /* make sure we clip even if the window covers the whole screen */
440 rect
.left
= max( rect
.left
, GetSystemMetrics( SM_XVIRTUALSCREEN
) + 1 );
441 rect
.top
= max( rect
.top
, GetSystemMetrics( SM_YVIRTUALSCREEN
) + 1 );
442 rect
.right
= min( rect
.right
, rect
.left
+ GetSystemMetrics( SM_CXVIRTUALSCREEN
) - 2 );
443 rect
.bottom
= min( rect
.bottom
, rect
.top
+ GetSystemMetrics( SM_CYVIRTUALSCREEN
) - 2 );
444 TRACE("Clipping mouse to %s\n", wine_dbgstr_rect( &rect
));
445 This
->clipped
= ClipCursor( &rect
);
451 /******************************************************************************
452 * Acquire : gets exclusive control of the mouse
454 static HRESULT WINAPI
SysMouseWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface
)
456 SysMouseImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
460 TRACE("(this=%p)\n",This
);
462 if ((res
= IDirectInputDevice2WImpl_Acquire(iface
)) != DI_OK
) return res
;
464 /* Init the mouse state */
465 GetCursorPos( &point
);
466 if (This
->base
.data_format
.user_df
->dwFlags
& DIDF_ABSAXIS
)
468 This
->m_state
.lX
= point
.x
;
469 This
->m_state
.lY
= point
.y
;
471 This
->m_state
.lX
= 0;
472 This
->m_state
.lY
= 0;
473 This
->org_coords
= point
;
475 This
->m_state
.lZ
= 0;
476 This
->m_state
.rgbButtons
[0] = GetKeyState(VK_LBUTTON
) & 0x80;
477 This
->m_state
.rgbButtons
[1] = GetKeyState(VK_RBUTTON
) & 0x80;
478 This
->m_state
.rgbButtons
[2] = GetKeyState(VK_MBUTTON
) & 0x80;
480 if (This
->base
.dwCoopLevel
& DISCL_EXCLUSIVE
)
482 ShowCursor(FALSE
); /* hide cursor */
483 warp_check( This
, TRUE
);
485 else if (This
->warp_override
== WARP_FORCE_ON
)
487 /* Need a window to warp mouse in. */
488 if (!This
->base
.win
) This
->base
.win
= GetDesktopWindow();
489 warp_check( This
, TRUE
);
491 else if (This
->clipped
)
494 This
->clipped
= FALSE
;
500 static HRESULT WINAPI
SysMouseAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
502 SysMouseImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
503 return SysMouseWImpl_Acquire(IDirectInputDevice8W_from_impl(This
));
506 /******************************************************************************
507 * Unacquire : frees the mouse
509 static HRESULT WINAPI
SysMouseWImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface
)
511 SysMouseImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
514 TRACE("(this=%p)\n",This
);
516 if ((res
= IDirectInputDevice2WImpl_Unacquire(iface
)) != DI_OK
) return res
;
518 if (This
->base
.dwCoopLevel
& DISCL_EXCLUSIVE
)
521 ShowCursor(TRUE
); /* show cursor */
522 This
->clipped
= FALSE
;
525 /* And put the mouse cursor back where it was at acquire time */
526 if (This
->base
.dwCoopLevel
& DISCL_EXCLUSIVE
|| This
->warp_override
== WARP_FORCE_ON
)
528 TRACE(" warping mouse back to (%d , %d)\n", This
->org_coords
.x
, This
->org_coords
.y
);
529 SetCursorPos(This
->org_coords
.x
, This
->org_coords
.y
);
535 static HRESULT WINAPI
SysMouseAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
537 SysMouseImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
538 return SysMouseWImpl_Unacquire(IDirectInputDevice8W_from_impl(This
));
541 /******************************************************************************
542 * GetDeviceState : returns the "state" of the mouse.
544 * For the moment, only the "standard" return structure (DIMOUSESTATE) is
547 static HRESULT WINAPI
SysMouseWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W iface
, DWORD len
, LPVOID ptr
)
549 SysMouseImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
551 if(This
->base
.acquired
== 0) return DIERR_NOTACQUIRED
;
553 TRACE("(this=%p,0x%08x,%p):\n", This
, len
, ptr
);
554 _dump_mouse_state(&This
->m_state
);
556 EnterCriticalSection(&This
->base
.crit
);
557 /* Copy the current mouse state */
558 fill_DataFormat(ptr
, len
, &This
->m_state
, &This
->base
.data_format
);
560 /* Initialize the buffer when in relative mode */
561 if (!(This
->base
.data_format
.user_df
->dwFlags
& DIDF_ABSAXIS
))
563 This
->m_state
.lX
= 0;
564 This
->m_state
.lY
= 0;
565 This
->m_state
.lZ
= 0;
567 LeaveCriticalSection(&This
->base
.crit
);
569 warp_check( This
, FALSE
);
573 static HRESULT WINAPI
SysMouseAImpl_GetDeviceState(LPDIRECTINPUTDEVICE8A iface
, DWORD len
, LPVOID ptr
)
575 SysMouseImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
576 return SysMouseWImpl_GetDeviceState(IDirectInputDevice8W_from_impl(This
), len
, ptr
);
579 /******************************************************************************
580 * GetDeviceData : gets buffered input data.
582 static HRESULT WINAPI
SysMouseWImpl_GetDeviceData(LPDIRECTINPUTDEVICE8W iface
,
583 DWORD dodsize
, LPDIDEVICEOBJECTDATA dod
, LPDWORD entries
, DWORD flags
)
585 SysMouseImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
588 res
= IDirectInputDevice2WImpl_GetDeviceData(iface
, dodsize
, dod
, entries
, flags
);
589 if (SUCCEEDED(res
)) warp_check( This
, FALSE
);
593 static HRESULT WINAPI
SysMouseAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface
,
594 DWORD dodsize
, LPDIDEVICEOBJECTDATA dod
, LPDWORD entries
, DWORD flags
)
596 SysMouseImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
597 return SysMouseWImpl_GetDeviceData(IDirectInputDevice8W_from_impl(This
), dodsize
, dod
, entries
, flags
);
600 /******************************************************************************
601 * GetProperty : get input device properties
603 static HRESULT WINAPI
SysMouseWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
, LPDIPROPHEADER pdiph
)
605 SysMouseImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
607 TRACE("(%p) %s,%p\n", This
, debugstr_guid(rguid
), pdiph
);
608 _dump_DIPROPHEADER(pdiph
);
610 if (IS_DIPROP(rguid
)) {
611 switch (LOWORD(rguid
)) {
612 case (DWORD_PTR
) DIPROP_GRANULARITY
: {
613 LPDIPROPDWORD pr
= (LPDIPROPDWORD
) pdiph
;
615 /* We'll just assume that the app asks about the Z axis */
616 pr
->dwData
= WHEEL_DELTA
;
621 case (DWORD_PTR
) DIPROP_RANGE
: {
622 LPDIPROPRANGE pr
= (LPDIPROPRANGE
) pdiph
;
624 if ((pdiph
->dwHow
== DIPH_BYID
) &&
625 ((pdiph
->dwObj
== (DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE
) | DIDFT_RELAXIS
)) ||
626 (pdiph
->dwObj
== (DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE
) | DIDFT_RELAXIS
)))) {
627 /* Querying the range of either the X or the Y axis. As I do
628 not know the range, do as if the range were
630 pr
->lMin
= DIPROPRANGE_NOMIN
;
631 pr
->lMax
= DIPROPRANGE_NOMAX
;
638 return IDirectInputDevice2WImpl_GetProperty(iface
, rguid
, pdiph
);
645 static HRESULT WINAPI
SysMouseAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
, LPDIPROPHEADER pdiph
)
647 SysMouseImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
648 return SysMouseWImpl_GetProperty(IDirectInputDevice8W_from_impl(This
), rguid
, pdiph
);
651 /******************************************************************************
652 * GetCapabilities : get the device capabilities
654 static HRESULT WINAPI
SysMouseWImpl_GetCapabilities(LPDIRECTINPUTDEVICE8W iface
, LPDIDEVCAPS lpDIDevCaps
)
656 SysMouseImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
659 TRACE("(this=%p,%p)\n",This
,lpDIDevCaps
);
661 if ((lpDIDevCaps
->dwSize
!= sizeof(DIDEVCAPS
)) && (lpDIDevCaps
->dwSize
!= sizeof(DIDEVCAPS_DX3
))) {
662 WARN("invalid parameter\n");
663 return DIERR_INVALIDPARAM
;
666 devcaps
.dwSize
= lpDIDevCaps
->dwSize
;
667 devcaps
.dwFlags
= DIDC_ATTACHED
| DIDC_EMULATED
;
668 if (This
->base
.dinput
->dwVersion
>= 0x0800)
669 devcaps
.dwDevType
= DI8DEVTYPE_MOUSE
| (DI8DEVTYPEMOUSE_TRADITIONAL
<< 8);
671 devcaps
.dwDevType
= DIDEVTYPE_MOUSE
| (DIDEVTYPEMOUSE_TRADITIONAL
<< 8);
673 devcaps
.dwButtons
= 8;
675 devcaps
.dwFFSamplePeriod
= 0;
676 devcaps
.dwFFMinTimeResolution
= 0;
677 devcaps
.dwFirmwareRevision
= 100;
678 devcaps
.dwHardwareRevision
= 100;
679 devcaps
.dwFFDriverVersion
= 0;
681 memcpy(lpDIDevCaps
, &devcaps
, lpDIDevCaps
->dwSize
);
686 static HRESULT WINAPI
SysMouseAImpl_GetCapabilities(LPDIRECTINPUTDEVICE8A iface
, LPDIDEVCAPS lpDIDevCaps
)
688 SysMouseImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
689 return SysMouseWImpl_GetCapabilities(IDirectInputDevice8W_from_impl(This
), lpDIDevCaps
);
692 /******************************************************************************
693 * GetObjectInfo : get information about a device object such as a button
696 static HRESULT WINAPI
SysMouseWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface
,
697 LPDIDEVICEOBJECTINSTANCEW pdidoi
, DWORD dwObj
, DWORD dwHow
)
699 static const WCHAR x_axisW
[] = {'X','-','A','x','i','s',0};
700 static const WCHAR y_axisW
[] = {'Y','-','A','x','i','s',0};
701 static const WCHAR wheelW
[] = {'W','h','e','e','l',0};
702 static const WCHAR buttonW
[] = {'B','u','t','t','o','n',' ','%','d',0};
705 res
= IDirectInputDevice2WImpl_GetObjectInfo(iface
, pdidoi
, dwObj
, dwHow
);
706 if (res
!= DI_OK
) return res
;
708 if (IsEqualGUID(&pdidoi
->guidType
, &GUID_XAxis
)) strcpyW(pdidoi
->tszName
, x_axisW
);
709 else if (IsEqualGUID(&pdidoi
->guidType
, &GUID_YAxis
)) strcpyW(pdidoi
->tszName
, y_axisW
);
710 else if (IsEqualGUID(&pdidoi
->guidType
, &GUID_ZAxis
)) strcpyW(pdidoi
->tszName
, wheelW
);
711 else if (pdidoi
->dwType
& DIDFT_BUTTON
)
712 wsprintfW(pdidoi
->tszName
, buttonW
, DIDFT_GETINSTANCE(pdidoi
->dwType
) - 3);
714 _dump_OBJECTINSTANCEW(pdidoi
);
718 static HRESULT WINAPI
SysMouseAImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8A iface
,
719 LPDIDEVICEOBJECTINSTANCEA pdidoi
, DWORD dwObj
, DWORD dwHow
)
721 SysMouseImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
723 DIDEVICEOBJECTINSTANCEW didoiW
;
724 DWORD dwSize
= pdidoi
->dwSize
;
726 didoiW
.dwSize
= sizeof(didoiW
);
727 res
= SysMouseWImpl_GetObjectInfo(IDirectInputDevice8W_from_impl(This
), &didoiW
, dwObj
, dwHow
);
728 if (res
!= DI_OK
) return res
;
730 memset(pdidoi
, 0, pdidoi
->dwSize
);
731 memcpy(pdidoi
, &didoiW
, FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW
, tszName
));
732 pdidoi
->dwSize
= dwSize
;
733 WideCharToMultiByte(CP_ACP
, 0, didoiW
.tszName
, -1, pdidoi
->tszName
,
734 sizeof(pdidoi
->tszName
), NULL
, NULL
);
739 /******************************************************************************
740 * GetDeviceInfo : get information about a device's identity
742 static HRESULT WINAPI
SysMouseAImpl_GetDeviceInfo(
743 LPDIRECTINPUTDEVICE8A iface
,
744 LPDIDEVICEINSTANCEA pdidi
)
746 SysMouseImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
747 TRACE("(this=%p,%p)\n", This
, pdidi
);
749 if (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEA
)) {
750 WARN(" dinput3 not supported yet...\n");
754 fill_mouse_dideviceinstanceA(pdidi
, This
->base
.dinput
->dwVersion
);
759 static HRESULT WINAPI
SysMouseWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface
, LPDIDEVICEINSTANCEW pdidi
)
761 SysMouseImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
762 TRACE("(this=%p,%p)\n", This
, pdidi
);
764 if (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEW
)) {
765 WARN(" dinput3 not supported yet...\n");
769 fill_mouse_dideviceinstanceW(pdidi
, This
->base
.dinput
->dwVersion
);
774 static HRESULT WINAPI
SysMouseWImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface
,
775 LPDIACTIONFORMATW lpdiaf
,
776 LPCWSTR lpszUserName
,
779 FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface
, lpdiaf
, debugstr_w(lpszUserName
), dwFlags
);
781 return _build_action_map(iface
, lpdiaf
, lpszUserName
, dwFlags
, DIMOUSE_MASK
, &c_dfDIMouse2
);
784 static HRESULT WINAPI
SysMouseAImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface
,
785 LPDIACTIONFORMATA lpdiaf
,
789 SysMouseImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
790 DIACTIONFORMATW diafW
;
792 WCHAR
*lpszUserNameW
= NULL
;
795 diafW
.rgoAction
= HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW
)*lpdiaf
->dwNumActions
);
796 _copy_diactionformatAtoW(&diafW
, lpdiaf
);
798 if (lpszUserName
!= NULL
)
800 username_size
= MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, NULL
, 0);
801 lpszUserNameW
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*username_size
);
802 MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, lpszUserNameW
, username_size
);
805 hr
= SysMouseWImpl_BuildActionMap(&This
->base
.IDirectInputDevice8W_iface
, &diafW
, lpszUserNameW
, dwFlags
);
807 _copy_diactionformatWtoA(lpdiaf
, &diafW
);
808 HeapFree(GetProcessHeap(), 0, diafW
.rgoAction
);
809 HeapFree(GetProcessHeap(), 0, lpszUserNameW
);
814 static HRESULT WINAPI
SysMouseWImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface
,
815 LPDIACTIONFORMATW lpdiaf
,
816 LPCWSTR lpszUserName
,
819 FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface
, lpdiaf
, debugstr_w(lpszUserName
), dwFlags
);
821 return _set_action_map(iface
, lpdiaf
, lpszUserName
, dwFlags
, &c_dfDIMouse2
);
824 static HRESULT WINAPI
SysMouseAImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface
,
825 LPDIACTIONFORMATA lpdiaf
,
829 SysMouseImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
830 DIACTIONFORMATW diafW
;
832 WCHAR
*lpszUserNameW
= NULL
;
835 diafW
.rgoAction
= HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW
)*lpdiaf
->dwNumActions
);
836 _copy_diactionformatAtoW(&diafW
, lpdiaf
);
838 if (lpszUserName
!= NULL
)
840 username_size
= MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, NULL
, 0);
841 lpszUserNameW
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*username_size
);
842 MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, lpszUserNameW
, username_size
);
845 hr
= SysMouseWImpl_SetActionMap(&This
->base
.IDirectInputDevice8W_iface
, &diafW
, lpszUserNameW
, dwFlags
);
847 HeapFree(GetProcessHeap(), 0, diafW
.rgoAction
);
848 HeapFree(GetProcessHeap(), 0, lpszUserNameW
);
853 static const IDirectInputDevice8AVtbl SysMouseAvt
=
855 IDirectInputDevice2AImpl_QueryInterface
,
856 IDirectInputDevice2AImpl_AddRef
,
857 IDirectInputDevice2AImpl_Release
,
858 SysMouseAImpl_GetCapabilities
,
859 IDirectInputDevice2AImpl_EnumObjects
,
860 SysMouseAImpl_GetProperty
,
861 IDirectInputDevice2AImpl_SetProperty
,
862 SysMouseAImpl_Acquire
,
863 SysMouseAImpl_Unacquire
,
864 SysMouseAImpl_GetDeviceState
,
865 SysMouseAImpl_GetDeviceData
,
866 IDirectInputDevice2AImpl_SetDataFormat
,
867 IDirectInputDevice2AImpl_SetEventNotification
,
868 IDirectInputDevice2AImpl_SetCooperativeLevel
,
869 SysMouseAImpl_GetObjectInfo
,
870 SysMouseAImpl_GetDeviceInfo
,
871 IDirectInputDevice2AImpl_RunControlPanel
,
872 IDirectInputDevice2AImpl_Initialize
,
873 IDirectInputDevice2AImpl_CreateEffect
,
874 IDirectInputDevice2AImpl_EnumEffects
,
875 IDirectInputDevice2AImpl_GetEffectInfo
,
876 IDirectInputDevice2AImpl_GetForceFeedbackState
,
877 IDirectInputDevice2AImpl_SendForceFeedbackCommand
,
878 IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
879 IDirectInputDevice2AImpl_Escape
,
880 IDirectInputDevice2AImpl_Poll
,
881 IDirectInputDevice2AImpl_SendDeviceData
,
882 IDirectInputDevice7AImpl_EnumEffectsInFile
,
883 IDirectInputDevice7AImpl_WriteEffectToFile
,
884 SysMouseAImpl_BuildActionMap
,
885 SysMouseAImpl_SetActionMap
,
886 IDirectInputDevice8AImpl_GetImageInfo
889 static const IDirectInputDevice8WVtbl SysMouseWvt
=
891 IDirectInputDevice2WImpl_QueryInterface
,
892 IDirectInputDevice2WImpl_AddRef
,
893 IDirectInputDevice2WImpl_Release
,
894 SysMouseWImpl_GetCapabilities
,
895 IDirectInputDevice2WImpl_EnumObjects
,
896 SysMouseWImpl_GetProperty
,
897 IDirectInputDevice2WImpl_SetProperty
,
898 SysMouseWImpl_Acquire
,
899 SysMouseWImpl_Unacquire
,
900 SysMouseWImpl_GetDeviceState
,
901 SysMouseWImpl_GetDeviceData
,
902 IDirectInputDevice2WImpl_SetDataFormat
,
903 IDirectInputDevice2WImpl_SetEventNotification
,
904 IDirectInputDevice2WImpl_SetCooperativeLevel
,
905 SysMouseWImpl_GetObjectInfo
,
906 SysMouseWImpl_GetDeviceInfo
,
907 IDirectInputDevice2WImpl_RunControlPanel
,
908 IDirectInputDevice2WImpl_Initialize
,
909 IDirectInputDevice2WImpl_CreateEffect
,
910 IDirectInputDevice2WImpl_EnumEffects
,
911 IDirectInputDevice2WImpl_GetEffectInfo
,
912 IDirectInputDevice2WImpl_GetForceFeedbackState
,
913 IDirectInputDevice2WImpl_SendForceFeedbackCommand
,
914 IDirectInputDevice2WImpl_EnumCreatedEffectObjects
,
915 IDirectInputDevice2WImpl_Escape
,
916 IDirectInputDevice2WImpl_Poll
,
917 IDirectInputDevice2WImpl_SendDeviceData
,
918 IDirectInputDevice7WImpl_EnumEffectsInFile
,
919 IDirectInputDevice7WImpl_WriteEffectToFile
,
920 SysMouseWImpl_BuildActionMap
,
921 SysMouseWImpl_SetActionMap
,
922 IDirectInputDevice8WImpl_GetImageInfo