Commit 89c59e77 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

dinput: Factor all GetDeviceState implementations together.

parent 59fad291
......@@ -1522,6 +1522,47 @@ HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo( IDirectInputDevice8W *ifa
return DI_OK;
}
static BOOL CALLBACK reset_axis_data( const DIDEVICEOBJECTINSTANCEW *instance, void *data )
{
*(ULONG *)((char *)data + instance->dwOfs) = 0;
return DIENUM_CONTINUE;
}
HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceState( IDirectInputDevice8W *iface, DWORD size, void *data )
{
IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8W( iface );
DIPROPHEADER filter =
{
.dwSize = sizeof(filter),
.dwHeaderSize = sizeof(filter),
.dwHow = DIPH_DEVICE,
.dwObj = 0,
};
HRESULT hr;
TRACE( "iface %p, size %u, data %p.\n", iface, size, data );
if (!data) return DIERR_INVALIDPARAM;
IDirectInputDevice2_Poll( iface );
EnterCriticalSection( &impl->crit );
if (!impl->acquired)
hr = DIERR_NOTACQUIRED;
else if (size != impl->data_format.user_df->dwDataSize)
hr = DIERR_INVALIDPARAM;
else
{
fill_DataFormat( data, size, impl->device_state, &impl->data_format );
if (!(impl->data_format.user_df->dwFlags & DIDF_ABSAXIS))
impl->vtbl->enum_objects( iface, &filter, DIDFT_RELAXIS, reset_axis_data, impl->device_state );
hr = DI_OK;
}
LeaveCriticalSection( &impl->crit );
return hr;
}
HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceData(LPDIRECTINPUTDEVICE8W iface, DWORD dodsize,
LPDIDEVICEOBJECTDATA dod, LPDWORD entries, DWORD flags)
{
......
......@@ -157,6 +157,7 @@ extern HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo(LPDIRECTINPUTDEVICE
LPDIDEVICEOBJECTINSTANCEW pdidoi,
DWORD dwObj,
DWORD dwHow) DECLSPEC_HIDDEN;
extern HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceState( IDirectInputDevice8W *iface, DWORD len, void *ptr );
extern HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceData(LPDIRECTINPUTDEVICE8W iface, DWORD dodsize, LPDIDEVICEOBJECTDATA dod,
LPDWORD entries, DWORD flags) DECLSPEC_HIDDEN;
extern HRESULT WINAPI IDirectInputDevice2WImpl_RunControlPanel(LPDIRECTINPUTDEVICE8W iface, HWND hwndOwner, DWORD dwFlags) DECLSPEC_HIDDEN;
......
......@@ -818,22 +818,6 @@ static HRESULT hid_joystick_internal_unacquire( IDirectInputDevice8W *iface )
return DI_OK;
}
static HRESULT WINAPI hid_joystick_GetDeviceState( IDirectInputDevice8W *iface, DWORD len, void *ptr )
{
struct hid_joystick *impl = impl_from_IDirectInputDevice8W( iface );
HRESULT hr = DI_OK;
if (!ptr) return DIERR_INVALIDPARAM;
if (len != impl->base.data_format.user_df->dwDataSize) return DIERR_INVALIDPARAM;
EnterCriticalSection( &impl->base.crit );
if (!impl->base.acquired) hr = DIERR_NOTACQUIRED;
else fill_DataFormat( ptr, len, impl->base.device_state, &impl->base.data_format );
LeaveCriticalSection( &impl->base.crit );
return hr;
}
static HRESULT hid_joystick_effect_create( struct hid_joystick *joystick, IDirectInputEffect **out );
static HRESULT WINAPI hid_joystick_CreateEffect( IDirectInputDevice8W *iface, const GUID *guid,
......@@ -1175,7 +1159,7 @@ static const IDirectInputDevice8WVtbl hid_joystick_vtbl =
IDirectInputDevice2WImpl_SetProperty,
IDirectInputDevice2WImpl_Acquire,
IDirectInputDevice2WImpl_Unacquire,
hid_joystick_GetDeviceState,
IDirectInputDevice2WImpl_GetDeviceState,
IDirectInputDevice2WImpl_GetDeviceData,
IDirectInputDevice2WImpl_SetDataFormat,
IDirectInputDevice2WImpl_SetEventNotification,
......
......@@ -241,35 +241,6 @@ const struct dinput_device keyboard_device = {
keyboarddev_create_device
};
static HRESULT WINAPI SysKeyboardWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W iface, DWORD len, LPVOID ptr)
{
SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
DWORD i;
TRACE("(%p)->(%d,%p)\n", This, len, ptr);
if (!This->base.acquired) return DIERR_NOTACQUIRED;
if (len != This->base.data_format.user_df->dwDataSize )
return DIERR_INVALIDPARAM;
check_dinput_events();
EnterCriticalSection(&This->base.crit);
if (TRACE_ON(dinput))
{
TRACE( "pressed keys:" );
for (i = 0; i < len; i++) if (This->base.device_state[i]) TRACE( " %02x", i );
TRACE( "\n" );
}
fill_DataFormat( ptr, len, This->base.device_state, &This->base.data_format );
LeaveCriticalSection(&This->base.crit);
return DI_OK;
}
static HRESULT keyboard_internal_poll( IDirectInputDevice8W *iface )
{
check_dinput_events();
......@@ -379,7 +350,7 @@ static const IDirectInputDevice8WVtbl SysKeyboardWvt =
IDirectInputDevice2WImpl_SetProperty,
IDirectInputDevice2WImpl_Acquire,
IDirectInputDevice2WImpl_Unacquire,
SysKeyboardWImpl_GetDeviceState,
IDirectInputDevice2WImpl_GetDeviceState,
IDirectInputDevice2WImpl_GetDeviceData,
IDirectInputDevice2WImpl_SetDataFormat,
IDirectInputDevice2WImpl_SetEventNotification,
......
......@@ -442,39 +442,6 @@ static void warp_check( SysMouseImpl* This, BOOL force )
}
}
/******************************************************************************
* GetDeviceState : returns the "state" of the mouse.
*
* For the moment, only the "standard" return structure (DIMOUSESTATE) is
* supported.
*/
static HRESULT WINAPI SysMouseWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W iface, DWORD len, LPVOID ptr)
{
SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface);
DIMOUSESTATE2 *state = (DIMOUSESTATE2 *)This->base.device_state;
TRACE("(%p)->(%u,%p)\n", This, len, ptr);
if(This->base.acquired == 0) return DIERR_NOTACQUIRED;
check_dinput_events();
EnterCriticalSection(&This->base.crit);
/* Copy the current mouse state */
fill_DataFormat( ptr, len, state, &This->base.data_format );
/* Initialize the buffer when in relative mode */
if (!(This->base.data_format.user_df->dwFlags & DIDF_ABSAXIS))
{
state->lX = 0;
state->lY = 0;
state->lZ = 0;
}
LeaveCriticalSection(&This->base.crit);
return DI_OK;
}
static HRESULT mouse_internal_poll( IDirectInputDevice8W *iface )
{
SysMouseImpl *impl = impl_from_IDirectInputDevice8W( iface );
......@@ -696,7 +663,7 @@ static const IDirectInputDevice8WVtbl SysMouseWvt =
IDirectInputDevice2WImpl_SetProperty,
IDirectInputDevice2WImpl_Acquire,
IDirectInputDevice2WImpl_Unacquire,
SysMouseWImpl_GetDeviceState,
IDirectInputDevice2WImpl_GetDeviceState,
IDirectInputDevice2WImpl_GetDeviceData,
IDirectInputDevice2WImpl_SetDataFormat,
IDirectInputDevice2WImpl_SetEventNotification,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment