From 504798ce9f28276b961451dace8ed6fac218599c Mon Sep 17 00:00:00 2001 From: Vitaliy Margolen Date: Thu, 4 Jan 2007 11:59:23 -0700 Subject: [PATCH] dinput: Change EnumObjects to use GetObjectInfo. Also small debug trace correction to make it more readable. --- dlls/dinput/device.c | 77 ++++++++++++++++---------------------- dlls/dinput/tests/device.c | 4 +- 2 files changed, 34 insertions(+), 47 deletions(-) diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 460c7ee4ee4..469f3d8b81e 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -800,15 +800,12 @@ ULONG WINAPI IDirectInputDevice2AImpl_AddRef( return InterlockedIncrement(&(This->ref)); } -HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects( - LPDIRECTINPUTDEVICE8A iface, - LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback, - LPVOID lpvRef, - DWORD dwFlags) +HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects(LPDIRECTINPUTDEVICE8A iface, + LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback, LPVOID lpvRef, DWORD dwFlags) { IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface; DIDEVICEOBJECTINSTANCEA ddoi; - int i, axis = 0, button = 0; + int i; TRACE("(%p) %p,%p flags:%08x)\n", iface, lpCallback, lpvRef, dwFlags); TRACE(" - flags = "); @@ -821,56 +818,46 @@ HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects( for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++) { - LPDIOBJECTDATAFORMAT odf; - DWORD type; + LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i); - odf = (LPDIOBJECTDATAFORMAT)((LPBYTE)This->data_format.wine_df->rgodf + - i * This->data_format.wine_df->dwObjSize); - type = DIEFT_GETTYPE(odf->dwType); + if (dwFlags != DIDFT_ALL && !(dwFlags & DIEFT_GETTYPE(odf->dwType))) continue; + if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK) + continue; - if (type & DIDFT_AXIS) axis++; - else if (type & DIDFT_BUTTON) button++; - - if (dwFlags != DIDFT_ALL && !(dwFlags & type)) continue; - - ddoi.guidType = *odf->pguid; - ddoi.dwType = odf->dwType; - ddoi.dwFlags = odf->dwFlags; - ddoi.dwOfs = !This->data_format.offsets ? odf->dwOfs : This->data_format.offsets[i]; - - if (IsEqualGUID(&ddoi.guidType, &GUID_XAxis)) strcpy(ddoi.tszName, "X-Axis"); - else if (IsEqualGUID(&ddoi.guidType, &GUID_YAxis)) strcpy(ddoi.tszName, "Y-Axis"); - else if (IsEqualGUID(&ddoi.guidType, &GUID_ZAxis)) strcpy(ddoi.tszName, "Z-Axis"); - else if (IsEqualGUID(&ddoi.guidType, &GUID_Key )) - GetKeyNameTextA((DIDFT_GETINSTANCE(odf->dwType) & 0x80) << 17 | - (DIDFT_GETINSTANCE(odf->dwType) & 0x7f) << 16, - ddoi.tszName, sizeof(ddoi.tszName)); - else if (type & DIDFT_AXIS) wsprintfA(ddoi.tszName, "%d-Axis", axis - 1); - else if (type & DIDFT_BUTTON) wsprintfA(ddoi.tszName, "Button %d", button - 1); - else FIXME("no name\n"); - - _dump_OBJECTINSTANCEA(&ddoi); if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break; } return DI_OK; } -HRESULT WINAPI IDirectInputDevice2WImpl_EnumObjects( - LPDIRECTINPUTDEVICE8W iface, - LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback, - LPVOID lpvRef, - DWORD dwFlags) +HRESULT WINAPI IDirectInputDevice2WImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface, + LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback, LPVOID lpvRef, DWORD dwFlags) { - device_enumobjects_AtoWcb_data data; + IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface; + DIDEVICEOBJECTINSTANCEW ddoi; + int i; - data.lpCallBack = lpCallback; - data.lpvRef = lpvRef; + TRACE("(%p) %p,%p flags:%08x)\n", iface, lpCallback, lpvRef, dwFlags); + TRACE(" - flags = "); + _dump_EnumObjects_flags(dwFlags); + TRACE("\n"); - return IDirectInputDevice2AImpl_EnumObjects( - (LPDIRECTINPUTDEVICE8A) iface, - (LPDIENUMDEVICEOBJECTSCALLBACKA) DIEnumDevicesCallbackAtoW, - (LPVOID) &data, dwFlags); + /* Only the fields till dwFFMaxForce are relevant */ + memset(&ddoi, 0, sizeof(ddoi)); + ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW, dwFFMaxForce); + + for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++) + { + LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i); + + if (dwFlags != DIDFT_ALL && !(dwFlags & DIEFT_GETTYPE(odf->dwType))) continue; + if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK) + continue; + + if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break; + } + + return DI_OK; } /****************************************************************************** diff --git a/dlls/dinput/tests/device.c b/dlls/dinput/tests/device.c index 58c9d8f2e38..2a9c24abb74 100644 --- a/dlls/dinput/tests/device.c +++ b/dlls/dinput/tests/device.c @@ -59,8 +59,8 @@ static const DIDATAFORMAT data_format = { static BOOL CALLBACK enum_callback(LPCDIDEVICEOBJECTINSTANCE oi, LPVOID info) { if (winetest_debug > 1) - trace(" Type:%4x Ofs:%2x Name:%s Flags:%08x\n", - oi->dwType, oi->dwOfs, oi->tszName, oi->dwFlags); + trace(" Type:%4x Ofs:%3d Flags:%08x Name:%s\n", + oi->dwType, oi->dwOfs, oi->dwFlags, oi->tszName); (*(int*)info)++; return DIENUM_CONTINUE; }