dinput: Common implementation for joystick, keyboard and mouse SetActionMap.

This commit is contained in:
Lucas Fialho Zawacki 2011-08-23 23:42:50 -03:00 committed by Alexandre Julliard
parent c0fd222321
commit d175c1526f
5 changed files with 90 additions and 175 deletions

View File

@ -640,6 +640,87 @@ HRESULT _build_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf,
return IDirectInputDevice8WImpl_BuildActionMap(iface, lpdiaf, lpszUserName, dwFlags);
}
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;
int i, action = 0, num_actions = 0;
unsigned int offset = 0;
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;
This->num_actions = num_actions;
/* Construct the dataformat and actionmap */
obj_df = HeapAlloc(GetProcessHeap(), 0, sizeof(DIOBJECTDATAFORMAT)*num_actions);
data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df;
data_format.dwNumObjs = num_actions;
This->action_map = HeapAlloc(GetProcessHeap(), 0, 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);
This->action_map[action].uAppData = lpdiaf->rgoAction[i].uAppData;
This->action_map[action].offset = offset;
obj_df[action].dwOfs = offset;
offset += (type & DIDFT_BUTTON) ? 1 : 4;
action++;
}
}
IDirectInputDevice8_SetDataFormat(iface, &data_format);
HeapFree(GetProcessHeap(), 0, 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);
}
return IDirectInputDevice8WImpl_SetActionMap(iface, lpdiaf, lpszUserName, dwFlags);
}
/******************************************************************************
* queue_event - add new event to the ring queue
*/
@ -1487,27 +1568,8 @@ HRESULT WINAPI IDirectInputDevice8WImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface
LPCWSTR lpszUserName,
DWORD dwFlags)
{
DIPROPDWORD dp;
DIPROPRANGE dpr;
FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
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);
}
return DI_OK;
}

View File

@ -128,6 +128,7 @@ extern DWORD semantic_to_obj_id(IDirectInputDeviceImpl* This, DWORD dwSemantic)
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;
extern HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, LPCDIDATAFORMAT df) DECLSPEC_HIDDEN;
/* And the stubs */
extern HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface) DECLSPEC_HIDDEN;

View File

@ -501,66 +501,10 @@ HRESULT WINAPI JoystickWGenericImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
DWORD dwFlags)
{
JoystickGenericImpl *This = impl_from_IDirectInputDevice8W(iface);
DIDATAFORMAT data_format;
DIOBJECTDATAFORMAT *obj_df = NULL;
int i, action = 0, num_actions = 0;
unsigned int offset = 0;
FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
if (This->base.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->base.guid, &lpdiaf->rgoAction[i].guidInstance))
num_actions++;
if (num_actions == 0) return DI_NOEFFECT;
This->base.num_actions = num_actions;
/* Construct the dataformat and actionmap */
obj_df = HeapAlloc(GetProcessHeap(), 0, sizeof(DIOBJECTDATAFORMAT)*num_actions);
data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df;
data_format.dwNumObjs = num_actions;
This->base.action_map = HeapAlloc(GetProcessHeap(), 0, sizeof(ActionMap)*num_actions);
for (i = 0; i < lpdiaf->dwNumActions; i++)
{
if (IsEqualGUID(&This->base.guid, &lpdiaf->rgoAction[i].guidInstance))
{
LPDIDATAFORMAT df = This->base.data_format.wine_df;
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);
This->base.action_map[action].uAppData = lpdiaf->rgoAction[i].uAppData;
This->base.action_map[action].offset = offset;
obj_df[action].dwOfs = offset;
offset += (type & DIDFT_BUTTON) ? 1 : 4;
action++;
}
}
IDirectInputDevice8_SetDataFormat(iface, &data_format);
HeapFree(GetProcessHeap(), 0, obj_df);
return IDirectInputDevice8WImpl_SetActionMap(iface, lpdiaf, lpszUserName, dwFlags);
return _set_action_map(iface, lpdiaf, lpszUserName, dwFlags, This->base.data_format.wine_df);
}
HRESULT WINAPI JoystickAGenericImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,

View File

@ -559,53 +559,9 @@ static HRESULT WINAPI SysKeyboardWImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
LPCWSTR lpszUserName,
DWORD dwFlags)
{
SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
DIDATAFORMAT data_format;
DIOBJECTDATAFORMAT *obj_df = NULL;
int i, action = 0, num_actions = 0;
FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
if (This->base.acquired) return DIERR_ACQUIRED;
data_format.dwSize = sizeof(data_format);
data_format.dwObjSize = sizeof(DIOBJECTDATAFORMAT);
data_format.dwFlags = DIDF_ABSAXIS;
data_format.dwDataSize = lpdiaf->dwDataSize;
/* count the actions */
for (i=0; i < lpdiaf->dwNumActions; i++)
if (IsEqualGUID(&This->base.guid, &lpdiaf->rgoAction[i].guidInstance))
num_actions++;
if (num_actions == 0) return DI_NOEFFECT;
This->base.num_actions = num_actions;
/* Construct the dataformat and actionmap */
obj_df = HeapAlloc(GetProcessHeap(), 0, sizeof(DIOBJECTDATAFORMAT)*num_actions);
data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df;
data_format.dwNumObjs = num_actions;
This->base.action_map = HeapAlloc(GetProcessHeap(), 0, sizeof(ActionMap)*num_actions);
for (i = 0; i < lpdiaf->dwNumActions; i++)
{
if (IsEqualGUID(&This->base.guid, &lpdiaf->rgoAction[i].guidInstance))
{
int instance = DIDFT_GETINSTANCE(lpdiaf->rgoAction[i].dwObjID);
memcpy(&obj_df[action], &c_dfDIKeyboard.rgodf[instance], c_dfDIKeyboard.dwObjSize);
This->base.action_map[action].uAppData = lpdiaf->rgoAction[i].uAppData;
This->base.action_map[action].offset = action;
obj_df[action].dwOfs = action;
action++;
}
}
IDirectInputDevice8_SetDataFormat(iface, &data_format);
HeapFree(GetProcessHeap(), 0, obj_df);
return IDirectInputDevice8WImpl_SetActionMap(iface, lpdiaf, lpszUserName, dwFlags);
return _set_action_map(iface, lpdiaf, lpszUserName, dwFlags, &c_dfDIKeyboard);
}
static HRESULT WINAPI SysKeyboardAImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,

View File

@ -808,57 +808,9 @@ static HRESULT WINAPI SysMouseWImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
LPCWSTR lpszUserName,
DWORD dwFlags)
{
SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface);
DIDATAFORMAT data_format;
DIOBJECTDATAFORMAT *obj_df = NULL;
int i, action = 0, num_actions = 0;
unsigned int offset = 0;
FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
if (This->base.acquired) return DIERR_ACQUIRED;
/* count the actions */
for (i=0; i < lpdiaf->dwNumActions; i++)
if (IsEqualGUID(&This->base.guid, &lpdiaf->rgoAction[i].guidInstance))
num_actions++;
if (num_actions == 0) return DI_NOEFFECT;
data_format.dwSize = sizeof(data_format);
data_format.dwObjSize = sizeof(DIOBJECTDATAFORMAT);
data_format.dwFlags = DIDF_ABSAXIS;
data_format.dwDataSize = lpdiaf->dwDataSize;
This->base.num_actions = num_actions;
/* Constructing the dataformat and actionmap */
obj_df = HeapAlloc(GetProcessHeap(), 0, sizeof(DIOBJECTDATAFORMAT)*num_actions);
data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df;
data_format.dwNumObjs = num_actions;
This->base.action_map = HeapAlloc(GetProcessHeap(), 0, sizeof(ActionMap)*num_actions);
for (i = 0; i < lpdiaf->dwNumActions; i++)
{
if (IsEqualGUID(&This->base.guid, &lpdiaf->rgoAction[i].guidInstance))
{
int instance = DIDFT_GETINSTANCE(lpdiaf->rgoAction[i].dwObjID);
memcpy(&obj_df[action], &c_dfDIMouse.rgodf[instance], c_dfDIMouse.dwObjSize);
This->base.action_map[action].uAppData = lpdiaf->rgoAction[i].uAppData;
This->base.action_map[action].offset = offset;
obj_df[action].dwOfs = offset;
offset += (obj_df[action].dwType & DIDFT_BUTTON) ? 1 : 4;
action++;
}
}
IDirectInputDevice8_SetDataFormat(iface, &data_format);
HeapFree(GetProcessHeap(), 0, obj_df);
return IDirectInputDevice8WImpl_SetActionMap(iface, lpdiaf, lpszUserName, dwFlags);
return _set_action_map(iface, lpdiaf, lpszUserName, dwFlags, &c_dfDIMouse2);
}
static HRESULT WINAPI SysMouseAImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,