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

dinput: Factor all SetActionMap wrappers together.

parent 30ea1876
...@@ -827,111 +827,6 @@ static BOOL set_app_data(IDirectInputDeviceImpl *dev, int offset, UINT_PTR app_d ...@@ -827,111 +827,6 @@ static BOOL set_app_data(IDirectInputDeviceImpl *dev, int offset, UINT_PTR app_d
return TRUE; 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 * queue_event - add new event to the ring queue
*/ */
...@@ -1760,6 +1655,129 @@ HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap( IDirectInputDevice8W *if ...@@ -1760,6 +1655,129 @@ HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap( IDirectInputDevice8W *if
return DI_OK; 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, HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface,
LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader) LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader)
{ {
......
...@@ -114,8 +114,6 @@ extern void _dump_OBJECTINSTANCEW(const DIDEVICEOBJECTINSTANCEW *ddoi) DECLSPEC ...@@ -114,8 +114,6 @@ extern void _dump_OBJECTINSTANCEW(const DIDEVICEOBJECTINSTANCEW *ddoi) DECLSPEC
extern void _dump_DIDATAFORMAT(const DIDATAFORMAT *df) DECLSPEC_HIDDEN; extern void _dump_DIDATAFORMAT(const DIDATAFORMAT *df) DECLSPEC_HIDDEN;
extern const char *_dump_dinput_GUID(const GUID *guid) 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 */ /* And the stubs */
extern HRESULT WINAPI IDirectInputDevice2WImpl_Acquire(LPDIRECTINPUTDEVICE8W iface) DECLSPEC_HIDDEN; extern HRESULT WINAPI IDirectInputDevice2WImpl_Acquire(LPDIRECTINPUTDEVICE8W iface) DECLSPEC_HIDDEN;
extern HRESULT WINAPI IDirectInputDevice2WImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface) DECLSPEC_HIDDEN; extern HRESULT WINAPI IDirectInputDevice2WImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface) DECLSPEC_HIDDEN;
...@@ -178,6 +176,8 @@ extern HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVIC ...@@ -178,6 +176,8 @@ extern HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVIC
LPDIACTIONFORMATW lpdiaf, LPDIACTIONFORMATW lpdiaf,
LPCWSTR lpszUserName, LPCWSTR lpszUserName,
DWORD dwFlags) DECLSPEC_HIDDEN; 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, extern HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface,
LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader) DECLSPEC_HIDDEN; LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader) DECLSPEC_HIDDEN;
......
...@@ -1385,18 +1385,6 @@ static HRESULT WINAPI hid_joystick_Poll( IDirectInputDevice8W *iface ) ...@@ -1385,18 +1385,6 @@ static HRESULT WINAPI hid_joystick_Poll( IDirectInputDevice8W *iface )
return hr; 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 = static const IDirectInputDevice8WVtbl hid_joystick_vtbl =
{ {
/*** IUnknown methods ***/ /*** IUnknown methods ***/
...@@ -1434,7 +1422,7 @@ static const IDirectInputDevice8WVtbl hid_joystick_vtbl = ...@@ -1434,7 +1422,7 @@ static const IDirectInputDevice8WVtbl hid_joystick_vtbl =
IDirectInputDevice7WImpl_WriteEffectToFile, IDirectInputDevice7WImpl_WriteEffectToFile,
/*** IDirectInputDevice8 methods ***/ /*** IDirectInputDevice8 methods ***/
IDirectInputDevice8WImpl_BuildActionMap, IDirectInputDevice8WImpl_BuildActionMap,
hid_joystick_SetActionMap, IDirectInputDevice8WImpl_SetActionMap,
IDirectInputDevice8WImpl_GetImageInfo, IDirectInputDevice8WImpl_GetImageInfo,
}; };
......
...@@ -410,17 +410,6 @@ static HRESULT WINAPI SysKeyboardWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface) ...@@ -410,17 +410,6 @@ static HRESULT WINAPI SysKeyboardWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface)
return res; 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 = static const IDirectInputDevice8WVtbl SysKeyboardWvt =
{ {
IDirectInputDevice2WImpl_QueryInterface, IDirectInputDevice2WImpl_QueryInterface,
...@@ -453,6 +442,6 @@ static const IDirectInputDevice8WVtbl SysKeyboardWvt = ...@@ -453,6 +442,6 @@ static const IDirectInputDevice8WVtbl SysKeyboardWvt =
IDirectInputDevice7WImpl_EnumEffectsInFile, IDirectInputDevice7WImpl_EnumEffectsInFile,
IDirectInputDevice7WImpl_WriteEffectToFile, IDirectInputDevice7WImpl_WriteEffectToFile,
IDirectInputDevice8WImpl_BuildActionMap, IDirectInputDevice8WImpl_BuildActionMap,
SysKeyboardWImpl_SetActionMap, IDirectInputDevice8WImpl_SetActionMap,
IDirectInputDevice8WImpl_GetImageInfo IDirectInputDevice8WImpl_GetImageInfo
}; };
...@@ -676,17 +676,6 @@ static HRESULT WINAPI SysMouseWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface, ...@@ -676,17 +676,6 @@ static HRESULT WINAPI SysMouseWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface,
return res; 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 = static const IDirectInputDevice8WVtbl SysMouseWvt =
{ {
IDirectInputDevice2WImpl_QueryInterface, IDirectInputDevice2WImpl_QueryInterface,
...@@ -719,6 +708,6 @@ static const IDirectInputDevice8WVtbl SysMouseWvt = ...@@ -719,6 +708,6 @@ static const IDirectInputDevice8WVtbl SysMouseWvt =
IDirectInputDevice7WImpl_EnumEffectsInFile, IDirectInputDevice7WImpl_EnumEffectsInFile,
IDirectInputDevice7WImpl_WriteEffectToFile, IDirectInputDevice7WImpl_WriteEffectToFile,
IDirectInputDevice8WImpl_BuildActionMap, IDirectInputDevice8WImpl_BuildActionMap,
SysMouseWImpl_SetActionMap, IDirectInputDevice8WImpl_SetActionMap,
IDirectInputDevice8WImpl_GetImageInfo IDirectInputDevice8WImpl_GetImageInfo
}; };
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