Commit 9f493b0e authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

dinput: Factor all GetObjectInfo implementations together.

parent 71ecc179
......@@ -1352,56 +1352,40 @@ HRESULT WINAPI IDirectInputDevice2WImpl_SetProperty(
return DI_OK;
}
HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo(
LPDIRECTINPUTDEVICE8W iface,
LPDIDEVICEOBJECTINSTANCEW pdidoi,
DWORD dwObj,
DWORD dwHow)
static BOOL CALLBACK get_object_info( const DIDEVICEOBJECTINSTANCEW *instance, void *data )
{
IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
DWORD dwSize;
LPDIOBJECTDATAFORMAT odf;
int idx = -1;
DIDEVICEOBJECTINSTANCEW *dest = data;
DWORD size = dest->dwSize;
TRACE("(%p) %d(0x%08x) -> %p\n", This, dwHow, dwObj, pdidoi);
memcpy( dest, instance, size );
dest->dwSize = size;
if (!pdidoi) return E_POINTER;
if (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEW) &&
pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3W))
return DIERR_INVALIDPARAM;
return DIENUM_STOP;
}
switch (dwHow)
HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo( IDirectInputDevice8W *iface, DIDEVICEOBJECTINSTANCEW *instance,
DWORD obj, DWORD how )
{
IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8W( iface );
const DIPROPHEADER filter =
{
case DIPH_BYOFFSET:
if (!This->data_format.offsets) break;
for (idx = This->data_format.wine_df->dwNumObjs - 1; idx >= 0; idx--)
if (This->data_format.offsets[idx] == dwObj) break;
break;
case DIPH_BYID:
dwObj &= 0x00ffffff;
for (idx = This->data_format.wine_df->dwNumObjs - 1; idx >= 0; idx--)
if ((dataformat_to_odf(This->data_format.wine_df, idx)->dwType & 0x00ffffff) == dwObj)
break;
break;
.dwSize = sizeof(filter),
.dwHeaderSize = sizeof(filter),
.dwHow = how,
.dwObj = obj
};
HRESULT hr;
case DIPH_BYUSAGE:
FIXME("dwHow = DIPH_BYUSAGE not implemented\n");
break;
default:
WARN("invalid parameter: dwHow = %08x\n", dwHow);
return DIERR_INVALIDPARAM;
}
if (idx < 0) return DIERR_OBJECTNOTFOUND;
TRACE( "iface %p, instance %p, obj %#x, how %#x.\n", iface, instance, obj, how );
odf = dataformat_to_odf(This->data_format.wine_df, idx);
dwSize = pdidoi->dwSize; /* save due to memset below */
memset(pdidoi, 0, pdidoi->dwSize);
pdidoi->dwSize = dwSize;
if (odf->pguid) pdidoi->guidType = *odf->pguid;
pdidoi->dwOfs = odf->dwOfs;
pdidoi->dwType = odf->dwType;
pdidoi->dwFlags = odf->dwFlags;
if (!instance) return E_POINTER;
if (instance->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3W) && instance->dwSize != sizeof(DIDEVICEOBJECTINSTANCEW))
return DIERR_INVALIDPARAM;
if (how == DIPH_DEVICE) return DIERR_INVALIDPARAM;
hr = impl->vtbl->enum_objects( iface, &filter, DIDFT_ALL, get_object_info, instance );
if (FAILED(hr)) return hr;
if (hr == DIENUM_CONTINUE) return DIERR_NOTFOUND;
return DI_OK;
}
......
......@@ -950,40 +950,6 @@ static HRESULT WINAPI hid_joystick_GetDeviceState( IDirectInputDevice8W *iface,
return hr;
}
static BOOL get_object_info( struct hid_joystick *impl, struct hid_value_caps *caps,
DIDEVICEOBJECTINSTANCEW *instance, void *data )
{
DIDEVICEOBJECTINSTANCEW *dest = data;
memcpy( dest, instance, dest->dwSize );
return DIENUM_STOP;
}
static HRESULT WINAPI hid_joystick_GetObjectInfo( IDirectInputDevice8W *iface, DIDEVICEOBJECTINSTANCEW *instance,
DWORD obj, DWORD how )
{
struct hid_joystick *impl = impl_from_IDirectInputDevice8W( iface );
const DIPROPHEADER filter =
{
.dwSize = sizeof(filter),
.dwHeaderSize = sizeof(filter),
.dwHow = how,
.dwObj = obj
};
BOOL ret;
TRACE( "iface %p, instance %p, obj %#x, how %#x.\n", iface, instance, obj, how );
if (!instance) return E_POINTER;
if (instance->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3W) &&
instance->dwSize != sizeof(DIDEVICEOBJECTINSTANCEW))
return DIERR_INVALIDPARAM;
if (how == DIPH_DEVICE) return DIERR_INVALIDPARAM;
ret = enum_objects( impl, &filter, DIDFT_ALL, get_object_info, instance );
if (ret != DIENUM_CONTINUE) return DI_OK;
return DIERR_NOTFOUND;
}
static HRESULT hid_joystick_effect_create( struct hid_joystick *joystick, IDirectInputEffect **out );
static HRESULT WINAPI hid_joystick_CreateEffect( IDirectInputDevice8W *iface, const GUID *guid,
......@@ -1342,7 +1308,7 @@ static const IDirectInputDevice8WVtbl hid_joystick_vtbl =
IDirectInputDevice2WImpl_SetDataFormat,
IDirectInputDevice2WImpl_SetEventNotification,
IDirectInputDevice2WImpl_SetCooperativeLevel,
hid_joystick_GetObjectInfo,
IDirectInputDevice2WImpl_GetObjectInfo,
IDirectInputDevice2WImpl_GetDeviceInfo,
IDirectInputDevice2WImpl_RunControlPanel,
IDirectInputDevice2WImpl_Initialize,
......
......@@ -273,66 +273,6 @@ static HRESULT WINAPI SysKeyboardWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W ifac
return DI_OK;
}
static DWORD map_dik_to_scan(DWORD dik_code, DWORD subtype)
{
if (dik_code == DIK_PAUSE || dik_code == DIK_NUMLOCK) dik_code ^= 0x80;
if (subtype == DIDEVTYPEKEYBOARD_JAPAN106)
{
switch (dik_code)
{
case DIK_CIRCUMFLEX:
dik_code = 0x0d;
break;
case DIK_AT:
dik_code = 0x1a;
break;
case DIK_LBRACKET:
dik_code = 0x1b;
break;
case DIK_COLON:
dik_code = 0x28;
break;
case DIK_KANJI:
dik_code = 0x29;
break;
case DIK_RBRACKET:
dik_code = 0x2b;
break;
case DIK_BACKSLASH:
dik_code = 0x73;
break;
}
}
return dik_code;
}
/******************************************************************************
* GetObjectInfo : get information about a device object such as a button
* or axis
*/
static HRESULT WINAPI SysKeyboardWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface,
LPDIDEVICEOBJECTINSTANCEW pdidoi,
DWORD dwObj,
DWORD dwHow)
{
SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
BYTE subtype = GET_DIDEVICE_SUBTYPE( This->base.instance.dwDevType );
HRESULT res;
LONG scan;
res = IDirectInputDevice2WImpl_GetObjectInfo(iface, pdidoi, dwObj, dwHow);
if (res != DI_OK) return res;
scan = map_dik_to_scan( DIDFT_GETINSTANCE( pdidoi->dwType ), subtype );
if (!GetKeyNameTextW((scan & 0x80) << 17 | (scan & 0x7f) << 16,
pdidoi->tszName, ARRAY_SIZE(pdidoi->tszName)))
return DIERR_OBJECTNOTFOUND;
_dump_OBJECTINSTANCEW(pdidoi);
return res;
}
/******************************************************************************
* GetProperty : Retrieves information about the input device.
*/
......@@ -359,7 +299,7 @@ static HRESULT WINAPI SysKeyboardWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface,
didoi.dwSize = sizeof(DIDEVICEOBJECTINSTANCEW);
hr = SysKeyboardWImpl_GetObjectInfo(iface, &didoi, ps->diph.dwObj, ps->diph.dwHow);
hr = IDirectInputDevice8_GetObjectInfo( iface, &didoi, ps->diph.dwObj, ps->diph.dwHow );
if (hr == DI_OK)
memcpy(ps->wsz, didoi.tszName, sizeof(ps->wsz));
return hr;
......@@ -472,7 +412,7 @@ static const IDirectInputDevice8WVtbl SysKeyboardWvt =
IDirectInputDevice2WImpl_SetDataFormat,
IDirectInputDevice2WImpl_SetEventNotification,
IDirectInputDevice2WImpl_SetCooperativeLevel,
SysKeyboardWImpl_GetObjectInfo,
IDirectInputDevice2WImpl_GetObjectInfo,
IDirectInputDevice2WImpl_GetDeviceInfo,
IDirectInputDevice2WImpl_RunControlPanel,
IDirectInputDevice2WImpl_Initialize,
......
......@@ -554,34 +554,6 @@ static HRESULT WINAPI SysMouseWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface, REF
return DI_OK;
}
/******************************************************************************
* GetObjectInfo : get information about a device object such as a button
* or axis
*/
static HRESULT WINAPI SysMouseWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface,
LPDIDEVICEOBJECTINSTANCEW pdidoi, DWORD dwObj, DWORD dwHow)
{
HRESULT res;
res = IDirectInputDevice2WImpl_GetObjectInfo(iface, pdidoi, dwObj, dwHow);
if (res != DI_OK) return res;
if (IsEqualGUID( &pdidoi->guidType, &GUID_XAxis ))
wcscpy( pdidoi->tszName, L"X-Axis" );
else if (IsEqualGUID( &pdidoi->guidType, &GUID_YAxis ))
wcscpy( pdidoi->tszName, L"Y-Axis" );
else if (IsEqualGUID( &pdidoi->guidType, &GUID_ZAxis ))
wcscpy( pdidoi->tszName, L"Wheel" );
else if (pdidoi->dwType & DIDFT_BUTTON)
swprintf( pdidoi->tszName, MAX_PATH, L"Button %d", DIDFT_GETINSTANCE( pdidoi->dwType ) - 3 );
if(pdidoi->dwType & DIDFT_AXIS)
pdidoi->dwFlags |= DIDOI_ASPECTPOSITION;
_dump_OBJECTINSTANCEW(pdidoi);
return res;
}
static HRESULT mouse_internal_acquire( IDirectInputDevice8W *iface )
{
SysMouseImpl *impl = impl_from_IDirectInputDevice8W( iface );
......@@ -783,7 +755,7 @@ static const IDirectInputDevice8WVtbl SysMouseWvt =
IDirectInputDevice2WImpl_SetDataFormat,
IDirectInputDevice2WImpl_SetEventNotification,
IDirectInputDevice2WImpl_SetCooperativeLevel,
SysMouseWImpl_GetObjectInfo,
IDirectInputDevice2WImpl_GetObjectInfo,
IDirectInputDevice2WImpl_GetDeviceInfo,
IDirectInputDevice2WImpl_RunControlPanel,
IDirectInputDevice2WImpl_Initialize,
......
......@@ -1413,7 +1413,6 @@ static void test_mouse_info(void)
objinst.dwSize = sizeof(DIDEVICEOBJECTINSTANCEW);
res = MAKELONG( HID_USAGE_GENERIC_X, HID_USAGE_PAGE_GENERIC );
hr = IDirectInputDevice8_GetObjectInfo( device, &objinst, res, DIPH_BYUSAGE );
todo_wine
ok( hr == DIERR_UNSUPPORTED, "GetObjectInfo returned: %#x\n", hr );
hr = IDirectInputDevice8_GetObjectInfo( device, &objinst, DIMOFS_Y, DIPH_BYOFFSET );
......@@ -1424,7 +1423,7 @@ static void test_mouse_info(void)
check_member( objinst, expect_objects[1], "%#x", dwOfs );
check_member( objinst, expect_objects[1], "%#x", dwType );
check_member( objinst, expect_objects[1], "%#x", dwFlags );
if (!localized) todo_wine check_member_wstr( objinst, expect_objects[1], tszName );
if (!localized) check_member_wstr( objinst, expect_objects[1], tszName );
check_member( objinst, expect_objects[1], "%u", dwFFMaxForce );
check_member( objinst, expect_objects[1], "%u", dwFFForceResolution );
check_member( objinst, expect_objects[1], "%u", wCollectionNumber );
......@@ -1750,7 +1749,6 @@ static void test_keyboard_info(void)
objinst.dwSize = sizeof(DIDEVICEOBJECTINSTANCEW);
res = MAKELONG( HID_USAGE_KEYBOARD_LCTRL, HID_USAGE_PAGE_KEYBOARD );
hr = IDirectInputDevice8_GetObjectInfo( device, &objinst, res, DIPH_BYUSAGE );
todo_wine
ok( hr == DIERR_UNSUPPORTED, "GetObjectInfo returned: %#x\n", hr );
hr = IDirectInputDevice8_GetObjectInfo( device, &objinst, 2, DIPH_BYOFFSET );
......
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