Commit b0dfa932 authored by Lucas Fialho Zawacki's avatar Lucas Fialho Zawacki Committed by Alexandre Julliard

dinput: Working CANCEL and RESET buttons in ConfigureDevices dialog.

parent 67682c24
...@@ -40,6 +40,7 @@ typedef struct { ...@@ -40,6 +40,7 @@ typedef struct {
typedef struct { typedef struct {
IDirectInput8W *lpDI; IDirectInput8W *lpDI;
LPDIACTIONFORMATW lpdiaf; LPDIACTIONFORMATW lpdiaf;
LPDIACTIONFORMATW original_lpdiaf;
DIDevicesData devices_data; DIDevicesData devices_data;
int display_only; int display_only;
} ConfigureDevicesData; } ConfigureDevicesData;
...@@ -201,16 +202,21 @@ static void init_devices(HWND dialog, IDirectInput8W *lpDI, DIDevicesData *data, ...@@ -201,16 +202,21 @@ static void init_devices(HWND dialog, IDirectInput8W *lpDI, DIDevicesData *data,
SendDlgItemMessageW(dialog, IDC_CONTROLLERCOMBO, CB_ADDSTRING, 0, (LPARAM) data->devices[i].ddi.tszProductName ); SendDlgItemMessageW(dialog, IDC_CONTROLLERCOMBO, CB_ADDSTRING, 0, (LPARAM) data->devices[i].ddi.tszProductName );
} }
static void destroy_devices(HWND dialog) static void destroy_data(HWND dialog)
{ {
int i; int i;
ConfigureDevicesData *data = (ConfigureDevicesData*) GetWindowLongPtrW(dialog, DWLP_USER); ConfigureDevicesData *data = (ConfigureDevicesData*) GetWindowLongPtrW(dialog, DWLP_USER);
DIDevicesData *devices_data = &data->devices_data; DIDevicesData *devices_data = &data->devices_data;
/* Free the devices */
for (i=0; i < devices_data->ndevices; i++) for (i=0; i < devices_data->ndevices; i++)
IDirectInputDevice8_Release(devices_data->devices[i].lpdid); IDirectInputDevice8_Release(devices_data->devices[i].lpdid);
HeapFree(GetProcessHeap(), 0, devices_data->devices); HeapFree(GetProcessHeap(), 0, devices_data->devices);
/* Free the backup LPDIACTIONFORMATW */
HeapFree(GetProcessHeap(), 0, data->original_lpdiaf->rgoAction);
HeapFree(GetProcessHeap(), 0, data->original_lpdiaf);
} }
static void fill_device_object_list(HWND dialog) static void fill_device_object_list(HWND dialog)
...@@ -323,6 +329,26 @@ static void assign_action(HWND dialog) ...@@ -323,6 +329,26 @@ static void assign_action(HWND dialog)
lv_set_action(dialog, obj, action, lpdiaf); lv_set_action(dialog, obj, action, lpdiaf);
} }
static void copy_actions(LPDIACTIONFORMATW to, LPDIACTIONFORMATW from)
{
int i;
for (i=0; i < from->dwNumActions; i++)
{
to->rgoAction[i].guidInstance = from->rgoAction[i].guidInstance;
to->rgoAction[i].dwObjID = from->rgoAction[i].dwObjID;
to->rgoAction[i].dwHow = from->rgoAction[i].dwHow;
to->rgoAction[i].lptszActionName = from->rgoAction[i].lptszActionName;
}
}
static void reset_actions(HWND dialog)
{
ConfigureDevicesData *data = (ConfigureDevicesData*) GetWindowLongPtrW(dialog, DWLP_USER);
LPDIACTIONFORMATW to = data->lpdiaf, from = data->original_lpdiaf;
copy_actions(to, from);
}
static INT_PTR CALLBACK ConfigureDevicesDlgProc(HWND dialog, UINT uMsg, WPARAM wParam, LPARAM lParam) static INT_PTR CALLBACK ConfigureDevicesDlgProc(HWND dialog, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
switch(uMsg) switch(uMsg)
...@@ -339,6 +365,12 @@ static INT_PTR CALLBACK ConfigureDevicesDlgProc(HWND dialog, UINT uMsg, WPARAM w ...@@ -339,6 +365,12 @@ static INT_PTR CALLBACK ConfigureDevicesDlgProc(HWND dialog, UINT uMsg, WPARAM w
init_listview_columns(dialog); init_listview_columns(dialog);
/* Create a backup action format for CANCEL and RESET operations */
data->original_lpdiaf = HeapAlloc(GetProcessHeap(), 0, sizeof(LPDIACTIONFORMATW));
data->original_lpdiaf->dwNumActions = data->lpdiaf->dwNumActions;
data->original_lpdiaf->rgoAction = HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW)*data->lpdiaf->dwNumActions);
copy_actions(data->original_lpdiaf, data->lpdiaf);
break; break;
} }
...@@ -383,15 +415,18 @@ static INT_PTR CALLBACK ConfigureDevicesDlgProc(HWND dialog, UINT uMsg, WPARAM w ...@@ -383,15 +415,18 @@ static INT_PTR CALLBACK ConfigureDevicesDlgProc(HWND dialog, UINT uMsg, WPARAM w
case IDOK: case IDOK:
EndDialog(dialog, 0); EndDialog(dialog, 0);
destroy_devices(dialog); destroy_data(dialog);
break; break;
case IDCANCEL: case IDCANCEL:
reset_actions(dialog);
EndDialog(dialog, 0); EndDialog(dialog, 0);
destroy_devices(dialog); destroy_data(dialog);
break; break;
case IDC_RESET: case IDC_RESET:
reset_actions(dialog);
fill_device_object_list(dialog);
break; break;
} }
break; break;
......
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