From 42feef0c7bcfa598c8337c61369dfefbf3f7c9fc Mon Sep 17 00:00:00 2001 From: Vitaliy Margolen Date: Wed, 27 Dec 2006 16:32:19 -0700 Subject: [PATCH] dinput: Implement EnumOjects[A|W] in the base device class. --- dlls/dinput/device.c | 66 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 31e05a5489b..da3afa4762e 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -800,13 +800,49 @@ HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects( LPVOID lpvRef, DWORD dwFlags) { - FIXME("(this=%p,%p,%p,%08x): stub!\n", iface, lpCallback, lpvRef, dwFlags); - if (TRACE_ON(dinput)) { - DPRINTF(" - flags = "); - _dump_EnumObjects_flags(dwFlags); - DPRINTF("\n"); + IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface; + DIDEVICEOBJECTINSTANCEA ddoi; + int i, axis = 0, button = 0; + + TRACE("(%p) %p,%p flags:%08x)\n", iface, lpCallback, lpvRef, dwFlags); + TRACE(" - flags = "); + _dump_EnumObjects_flags(dwFlags); + TRACE("\n"); + + /* Only the fields till dwFFMaxForce are relevant */ + memset(&ddoi, 0, sizeof(ddoi)); + ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce); + + for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++) + { + LPDIOBJECTDATAFORMAT odf; + DWORD type; + + odf = (LPDIOBJECTDATAFORMAT)((LPBYTE)This->data_format.wine_df->rgodf + + i * This->data_format.wine_df->dwObjSize); + type = DIEFT_GETTYPE(odf->dwType); + + 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 (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; } @@ -816,14 +852,15 @@ HRESULT WINAPI IDirectInputDevice2WImpl_EnumObjects( LPVOID lpvRef, DWORD dwFlags) { - FIXME("(this=%p,%p,%p,%08x): stub!\n", iface, lpCallback, lpvRef, dwFlags); - if (TRACE_ON(dinput)) { - DPRINTF(" - flags = "); - _dump_EnumObjects_flags(dwFlags); - DPRINTF("\n"); - } - - return DI_OK; + device_enumobjects_AtoWcb_data data; + + data.lpCallBack = lpCallback; + data.lpvRef = lpvRef; + + return IDirectInputDevice2AImpl_EnumObjects( + (LPDIRECTINPUTDEVICE8A) iface, + (LPDIENUMDEVICEOBJECTSCALLBACKA) DIEnumDevicesCallbackAtoW, + (LPVOID) &data, dwFlags); } /****************************************************************************** @@ -884,6 +921,7 @@ HRESULT WINAPI IDirectInputDevice2AImpl_SetProperty( if (pdiph->dwHow == DIPH_DEVICE && pdiph->dwObj) return DIERR_INVALIDPARAM; if (This->acquired) return DIERR_ACQUIRED; if (pdiph->dwHow != DIPH_DEVICE) return DIERR_UNSUPPORTED; + if (!This->data_format.user_df) return DI_OK; TRACE("Axis mode: %s\n", pd->dwData == DIPROPAXISMODE_ABS ? "absolute" : "relative");