Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 228 +++++++++++++++++++---------------- dlls/dinput/device_private.h | 4 +- dlls/dinput/joystick_hid.c | 14 +-- dlls/dinput/keyboard.c | 13 +- dlls/dinput/mouse.c | 13 +- 5 files changed, 128 insertions(+), 144 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 5528d3d328c..0f649ec59e8 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -827,111 +827,6 @@ static BOOL set_app_data(IDirectInputDeviceImpl *dev, int offset, UINT_PTR app_d return TRUE; }
-HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, LPCDIDATAFORMAT df) -{ - IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface); - DIDATAFORMAT data_format; - DIOBJECTDATAFORMAT *obj_df = NULL; - DIPROPDWORD dp; - DIPROPRANGE dpr; - DIPROPSTRING dps; - WCHAR username[MAX_PATH]; - DWORD username_size = MAX_PATH; - int i, action = 0, num_actions = 0; - unsigned int offset = 0; - ActionMap *action_map; - - if (This->acquired) return DIERR_ACQUIRED; - - data_format.dwSize = sizeof(data_format); - data_format.dwObjSize = sizeof(DIOBJECTDATAFORMAT); - data_format.dwFlags = DIDF_RELAXIS; - data_format.dwDataSize = lpdiaf->dwDataSize; - - /* Count the actions */ - for (i=0; i < lpdiaf->dwNumActions; i++) - if (IsEqualGUID(&This->guid, &lpdiaf->rgoAction[i].guidInstance)) - num_actions++; - - if (num_actions == 0) return DI_NOEFFECT; - - /* Construct the dataformat and actionmap */ - obj_df = malloc( sizeof(DIOBJECTDATAFORMAT) * num_actions ); - data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df; - data_format.dwNumObjs = num_actions; - - action_map = malloc( sizeof(ActionMap) * num_actions ); - - for (i = 0; i < lpdiaf->dwNumActions; i++) - { - if (IsEqualGUID(&This->guid, &lpdiaf->rgoAction[i].guidInstance)) - { - DWORD inst = DIDFT_GETINSTANCE(lpdiaf->rgoAction[i].dwObjID); - DWORD type = DIDFT_GETTYPE(lpdiaf->rgoAction[i].dwObjID); - LPDIOBJECTDATAFORMAT obj; - - if (type == DIDFT_PSHBUTTON) type = DIDFT_BUTTON; - if (type == DIDFT_RELAXIS) type = DIDFT_AXIS; - - obj = dataformat_to_odf_by_type(df, inst, type); - - memcpy(&obj_df[action], obj, df->dwObjSize); - - action_map[action].uAppData = lpdiaf->rgoAction[i].uAppData; - action_map[action].offset = offset; - obj_df[action].dwOfs = offset; - offset += (type & DIDFT_BUTTON) ? 1 : 4; - - action++; - } - } - - IDirectInputDevice8_SetDataFormat(iface, &data_format); - - This->action_map = action_map; - This->num_actions = num_actions; - - free( obj_df ); - - /* Set the device properties according to the action format */ - dpr.diph.dwSize = sizeof(DIPROPRANGE); - dpr.lMin = lpdiaf->lAxisMin; - dpr.lMax = lpdiaf->lAxisMax; - dpr.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dpr.diph.dwHow = DIPH_DEVICE; - IDirectInputDevice8_SetProperty(iface, DIPROP_RANGE, &dpr.diph); - - if (lpdiaf->dwBufferSize > 0) - { - dp.diph.dwSize = sizeof(DIPROPDWORD); - dp.dwData = lpdiaf->dwBufferSize; - dp.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dp.diph.dwHow = DIPH_DEVICE; - IDirectInputDevice8_SetProperty(iface, DIPROP_BUFFERSIZE, &dp.diph); - } - - /* Retrieve logged user name if necessary */ - if (lpszUserName == NULL) - GetUserNameW(username, &username_size); - else - lstrcpynW(username, lpszUserName, MAX_PATH); - - dps.diph.dwSize = sizeof(dps); - dps.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dps.diph.dwObj = 0; - dps.diph.dwHow = DIPH_DEVICE; - if (dwFlags & DIDSAM_NOUSER) - dps.wsz[0] = '\0'; - else - lstrcpynW(dps.wsz, username, ARRAY_SIZE(dps.wsz)); - IDirectInputDevice2WImpl_SetProperty(iface, DIPROP_USERNAME, &dps.diph); - - /* Save the settings to disk */ - save_mapping_settings(iface, lpdiaf, username); - - return DI_OK; -} - /****************************************************************************** * queue_event - add new event to the ring queue */ @@ -1760,6 +1655,129 @@ HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap( IDirectInputDevice8W *if return DI_OK; }
+HRESULT WINAPI IDirectInputDevice8WImpl_SetActionMap( IDirectInputDevice8W *iface, DIACTIONFORMATW *format, + const WCHAR *username, DWORD flags ) +{ + IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8W( iface ); + DIDATAFORMAT data_format; + DIOBJECTDATAFORMAT *obj_df = NULL; + DIPROPDWORD dp; + DIPROPRANGE dpr; + DIPROPSTRING dps; + WCHAR username_buf[MAX_PATH]; + DWORD username_len = MAX_PATH; + int i, action = 0, num_actions = 0; + unsigned int offset = 0; + const DIDATAFORMAT *df; + ActionMap *action_map; + + FIXME( "iface %p, format %p, username %s, flags %#x semi-stub!\n", iface, format, + debugstr_w(username), flags ); + + if (!format) return DIERR_INVALIDPARAM; + + switch (GET_DIDEVICE_TYPE( impl->instance.dwDevType )) + { + case DIDEVTYPE_KEYBOARD: + case DI8DEVTYPE_KEYBOARD: + df = &c_dfDIKeyboard; + break; + case DIDEVTYPE_MOUSE: + case DI8DEVTYPE_MOUSE: + df = &c_dfDIMouse2; + break; + default: + df = impl->data_format.wine_df; + break; + } + + if (impl->acquired) return DIERR_ACQUIRED; + + data_format.dwSize = sizeof(data_format); + data_format.dwObjSize = sizeof(DIOBJECTDATAFORMAT); + data_format.dwFlags = DIDF_RELAXIS; + data_format.dwDataSize = format->dwDataSize; + + /* Count the actions */ + for (i = 0; i < format->dwNumActions; i++) + if (IsEqualGUID( &impl->guid, &format->rgoAction[i].guidInstance )) + num_actions++; + + if (num_actions == 0) return DI_NOEFFECT; + + /* Construct the dataformat and actionmap */ + obj_df = malloc( sizeof(DIOBJECTDATAFORMAT) * num_actions ); + data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df; + data_format.dwNumObjs = num_actions; + + action_map = malloc( sizeof(ActionMap) * num_actions ); + + for (i = 0; i < format->dwNumActions; i++) + { + if (IsEqualGUID( &impl->guid, &format->rgoAction[i].guidInstance )) + { + DWORD inst = DIDFT_GETINSTANCE( format->rgoAction[i].dwObjID ); + DWORD type = DIDFT_GETTYPE( format->rgoAction[i].dwObjID ); + LPDIOBJECTDATAFORMAT obj; + + if (type == DIDFT_PSHBUTTON) type = DIDFT_BUTTON; + if (type == DIDFT_RELAXIS) type = DIDFT_AXIS; + + obj = dataformat_to_odf_by_type( df, inst, type ); + + memcpy( &obj_df[action], obj, df->dwObjSize ); + + action_map[action].uAppData = format->rgoAction[i].uAppData; + action_map[action].offset = offset; + obj_df[action].dwOfs = offset; + offset += (type & DIDFT_BUTTON) ? 1 : 4; + + action++; + } + } + + IDirectInputDevice8_SetDataFormat( iface, &data_format ); + + impl->action_map = action_map; + impl->num_actions = num_actions; + + free( obj_df ); + + /* Set the device properties according to the action format */ + dpr.diph.dwSize = sizeof(DIPROPRANGE); + dpr.lMin = format->lAxisMin; + dpr.lMax = format->lAxisMax; + dpr.diph.dwHeaderSize = sizeof(DIPROPHEADER); + dpr.diph.dwHow = DIPH_DEVICE; + IDirectInputDevice8_SetProperty( iface, DIPROP_RANGE, &dpr.diph ); + + if (format->dwBufferSize > 0) + { + dp.diph.dwSize = sizeof(DIPROPDWORD); + dp.dwData = format->dwBufferSize; + dp.diph.dwHeaderSize = sizeof(DIPROPHEADER); + dp.diph.dwHow = DIPH_DEVICE; + IDirectInputDevice8_SetProperty( iface, DIPROP_BUFFERSIZE, &dp.diph ); + } + + /* Retrieve logged user name if necessary */ + if (username == NULL) GetUserNameW( username_buf, &username_len ); + else lstrcpynW( username_buf, username, MAX_PATH ); + + dps.diph.dwSize = sizeof(dps); + dps.diph.dwHeaderSize = sizeof(DIPROPHEADER); + dps.diph.dwObj = 0; + dps.diph.dwHow = DIPH_DEVICE; + if (flags & DIDSAM_NOUSER) dps.wsz[0] = '\0'; + else lstrcpynW( dps.wsz, username_buf, ARRAY_SIZE(dps.wsz) ); + IDirectInputDevice2WImpl_SetProperty( iface, DIPROP_USERNAME, &dps.diph ); + + /* Save the settings to disk */ + save_mapping_settings( iface, format, username_buf ); + + return DI_OK; +} + HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface, LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader) { diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index 6aed93a130b..d61a0a3e6e8 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -114,8 +114,6 @@ extern void _dump_OBJECTINSTANCEW(const DIDEVICEOBJECTINSTANCEW *ddoi) DECLSPEC extern void _dump_DIDATAFORMAT(const DIDATAFORMAT *df) DECLSPEC_HIDDEN; extern const char *_dump_dinput_GUID(const GUID *guid) DECLSPEC_HIDDEN;
-extern HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, LPCDIDATAFORMAT df) DECLSPEC_HIDDEN; - /* And the stubs */ extern HRESULT WINAPI IDirectInputDevice2WImpl_Acquire(LPDIRECTINPUTDEVICE8W iface) DECLSPEC_HIDDEN; extern HRESULT WINAPI IDirectInputDevice2WImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface) DECLSPEC_HIDDEN; @@ -178,6 +176,8 @@ extern HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVIC LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags) DECLSPEC_HIDDEN; +extern HRESULT WINAPI IDirectInputDevice8WImpl_SetActionMap( IDirectInputDevice8W *iface, DIACTIONFORMATW *format, + const WCHAR *username, DWORD flags ); extern HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface, LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader) DECLSPEC_HIDDEN;
diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 5921b473f3a..13083a6ac77 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -1385,18 +1385,6 @@ static HRESULT WINAPI hid_joystick_Poll( IDirectInputDevice8W *iface ) return hr; }
-static HRESULT WINAPI hid_joystick_SetActionMap( IDirectInputDevice8W *iface, DIACTIONFORMATW *format, - const WCHAR *username, DWORD flags ) -{ - struct hid_joystick *impl = impl_from_IDirectInputDevice8W( iface ); - - TRACE( "iface %p, format %p, username %s, flags %#x.\n", iface, format, debugstr_w(username), flags ); - - if (!format) return DIERR_INVALIDPARAM; - - return _set_action_map( iface, format, username, flags, impl->base.data_format.wine_df ); -} - static const IDirectInputDevice8WVtbl hid_joystick_vtbl = { /*** IUnknown methods ***/ @@ -1434,7 +1422,7 @@ static const IDirectInputDevice8WVtbl hid_joystick_vtbl = IDirectInputDevice7WImpl_WriteEffectToFile, /*** IDirectInputDevice8 methods ***/ IDirectInputDevice8WImpl_BuildActionMap, - hid_joystick_SetActionMap, + IDirectInputDevice8WImpl_SetActionMap, IDirectInputDevice8WImpl_GetImageInfo, };
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index 98fcf253afa..c367162164a 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -410,17 +410,6 @@ static HRESULT WINAPI SysKeyboardWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface) return res; }
-static HRESULT WINAPI SysKeyboardWImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface, - LPDIACTIONFORMATW lpdiaf, - LPCWSTR lpszUserName, - DWORD dwFlags) -{ - SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface); - FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", This, lpdiaf, debugstr_w(lpszUserName), dwFlags); - - return _set_action_map(iface, lpdiaf, lpszUserName, dwFlags, &c_dfDIKeyboard); -} - static const IDirectInputDevice8WVtbl SysKeyboardWvt = { IDirectInputDevice2WImpl_QueryInterface, @@ -453,6 +442,6 @@ static const IDirectInputDevice8WVtbl SysKeyboardWvt = IDirectInputDevice7WImpl_EnumEffectsInFile, IDirectInputDevice7WImpl_WriteEffectToFile, IDirectInputDevice8WImpl_BuildActionMap, - SysKeyboardWImpl_SetActionMap, + IDirectInputDevice8WImpl_SetActionMap, IDirectInputDevice8WImpl_GetImageInfo }; diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 92c8b110e57..e94cd4e7c50 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -676,17 +676,6 @@ static HRESULT WINAPI SysMouseWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface, return res; }
-static HRESULT WINAPI SysMouseWImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface, - LPDIACTIONFORMATW lpdiaf, - LPCWSTR lpszUserName, - DWORD dwFlags) -{ - SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface); - FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", This, lpdiaf, debugstr_w(lpszUserName), dwFlags); - - return _set_action_map(iface, lpdiaf, lpszUserName, dwFlags, &c_dfDIMouse2); -} - static const IDirectInputDevice8WVtbl SysMouseWvt = { IDirectInputDevice2WImpl_QueryInterface, @@ -719,6 +708,6 @@ static const IDirectInputDevice8WVtbl SysMouseWvt = IDirectInputDevice7WImpl_EnumEffectsInFile, IDirectInputDevice7WImpl_WriteEffectToFile, IDirectInputDevice8WImpl_BuildActionMap, - SysMouseWImpl_SetActionMap, + IDirectInputDevice8WImpl_SetActionMap, IDirectInputDevice8WImpl_GetImageInfo };