dinput: Common implementation of BuildActionMap for keyboard and mouse.

This commit is contained in:
Lucas Fialho Zawacki 2011-08-23 23:42:49 -03:00 committed by Alexandre Julliard
parent bebc425bb5
commit c0fd222321
4 changed files with 47 additions and 49 deletions

View File

@ -598,6 +598,48 @@ DWORD semantic_to_obj_id(IDirectInputDeviceImpl* This, DWORD dwSemantic)
return type | (0x0000ff00 & (obj_instance << 8));
}
HRESULT _build_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, DWORD devMask, LPCDIDATAFORMAT df)
{
IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
int i, has_actions = 0;
for (i=0; i < lpdiaf->dwNumActions; i++)
{
if ((lpdiaf->rgoAction[i].dwSemantic & devMask) == devMask)
{
DWORD obj_id = semantic_to_obj_id(This, lpdiaf->rgoAction[i].dwSemantic);
DWORD type = DIDFT_GETTYPE(obj_id);
DWORD inst = DIDFT_GETINSTANCE(obj_id);
LPDIOBJECTDATAFORMAT odf;
if (type == DIDFT_PSHBUTTON) type = DIDFT_BUTTON;
if (type == DIDFT_RELAXIS) type = DIDFT_AXIS;
/* Assure that the object exists */
odf = dataformat_to_odf_by_type(df, inst, type);
if (odf != NULL)
{
lpdiaf->rgoAction[i].dwObjID = obj_id;
lpdiaf->rgoAction[i].guidInstance = This->guid;
lpdiaf->rgoAction[i].dwHow = DIAH_DEFAULT;
has_actions = 1;
}
}
else if (!(dwFlags & DIDBAM_PRESERVE))
{
/* we must clear action data belonging to other devices */
memset(&lpdiaf->rgoAction[i].guidInstance, 0, sizeof(GUID));
lpdiaf->rgoAction[i].dwHow = DIAH_UNMAPPED;
}
}
if (!has_actions) return DI_NOEFFECT;
return IDirectInputDevice8WImpl_BuildActionMap(iface, lpdiaf, lpszUserName, dwFlags);
}
/******************************************************************************
* queue_event - add new event to the ring queue
*/

View File

@ -127,6 +127,8 @@ extern const char *_dump_dinput_GUID(const GUID *guid) DECLSPEC_HIDDEN;
extern DWORD semantic_to_obj_id(IDirectInputDeviceImpl* This, DWORD dwSemantic) DECLSPEC_HIDDEN;
extern LPDIOBJECTDATAFORMAT dataformat_to_odf_by_type(LPCDIDATAFORMAT df, int n, DWORD type) DECLSPEC_HIDDEN;
extern HRESULT _build_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, DWORD devMask, LPCDIDATAFORMAT df) DECLSPEC_HIDDEN;
/* And the stubs */
extern HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface) DECLSPEC_HIDDEN;
extern HRESULT WINAPI IDirectInputDevice2WImpl_Acquire(LPDIRECTINPUTDEVICE8W iface) DECLSPEC_HIDDEN;

View File

@ -529,33 +529,9 @@ static HRESULT WINAPI SysKeyboardWImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W ifac
LPCWSTR lpszUserName,
DWORD dwFlags)
{
SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
int i, has_actions = 0;
FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
for (i=0; i < lpdiaf->dwNumActions; i++)
{
if ((lpdiaf->rgoAction[i].dwSemantic & DIKEYBOARD_MASK) == DIKEYBOARD_MASK)
{
DWORD obj_id = semantic_to_obj_id(&This->base, lpdiaf->rgoAction[i].dwSemantic);
lpdiaf->rgoAction[i].dwObjID = obj_id;
lpdiaf->rgoAction[i].guidInstance = This->base.guid;
lpdiaf->rgoAction[i].dwHow = DIAH_DEFAULT;
has_actions = 1;
}
else if (!(dwFlags & DIDBAM_PRESERVE))
{
/* we must clear action data belonging to other devices */
memset(&lpdiaf->rgoAction[i].guidInstance, 0, sizeof(GUID));
lpdiaf->rgoAction[i].dwHow = DIAH_UNMAPPED;
}
}
if (!has_actions) return DI_NOEFFECT;
return IDirectInputDevice8WImpl_BuildActionMap(iface, lpdiaf, lpszUserName, dwFlags);
return _build_action_map(iface, lpdiaf, lpszUserName, dwFlags, DIKEYBOARD_MASK, &c_dfDIKeyboard);
}
static HRESULT WINAPI SysKeyboardAImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,

View File

@ -778,31 +778,9 @@ static HRESULT WINAPI SysMouseWImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
LPCWSTR lpszUserName,
DWORD dwFlags)
{
SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface);
int i, has_actions = 0;
FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
for (i=0; i < lpdiaf->dwNumActions; i++)
{
if ((lpdiaf->rgoAction[i].dwSemantic & DIMOUSE_MASK) == DIMOUSE_MASK)
{
DWORD obj_id = semantic_to_obj_id(&This->base, lpdiaf->rgoAction[i].dwSemantic);
lpdiaf->rgoAction[i].dwObjID = obj_id;
lpdiaf->rgoAction[i].guidInstance = This->base.guid;
lpdiaf->rgoAction[i].dwHow = DIAH_DEFAULT;
has_actions = 1;
}
else if (!(dwFlags & DIDBAM_PRESERVE))
{
/* we must clear action data belonging to other devices */
memset(&lpdiaf->rgoAction[i].guidInstance, 0, sizeof(GUID));
lpdiaf->rgoAction[i].dwHow = DIAH_UNMAPPED;
}
}
if (!has_actions) return DI_NOEFFECT;
return IDirectInputDevice8WImpl_BuildActionMap(iface, lpdiaf, lpszUserName, dwFlags);
return _build_action_map(iface, lpdiaf, lpszUserName, dwFlags, DIMOUSE_MASK, &c_dfDIMouse2);
}
static HRESULT WINAPI SysMouseAImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,