Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From ecb8279fdbfe27a96a324fb43d27a2fdb9181b5c Mon Sep 17 00:00:00 2001
- From: Lucas Fialho Zawacki <lfzawacki@gmail.com>
- Date: Thu, 28 Jul 2011 19:03:31 -0300
- Subject: dinput: Added object/action enumeration to ConfigureDevices dialog
- ---
- dlls/dinput/config.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++
- 1 files changed, 121 insertions(+), 0 deletions(-)
- diff --git a/dlls/dinput/config.c b/dlls/dinput/config.c
- index ca85797..9c66c01 100644
- --- a/dlls/dinput/config.c
- +++ b/dlls/dinput/config.c
- @@ -48,6 +48,16 @@ static HINSTANCE g_hinstance;
- /*
- * Enumeration callback functions
- */
- +static BOOL CALLBACK collect_objects(LPCDIDEVICEOBJECTINSTANCEW lpddo, LPVOID pvRef)
- +{
- + DeviceData *data = (DeviceData*) pvRef;
- +
- + data->ddo[data->nobjects] = *lpddo;
- +
- + data->nobjects++;
- + return DIENUM_CONTINUE;
- +}
- +
- static BOOL CALLBACK count_devices(LPCDIDEVICEINSTANCEW lpddi, LPDIRECTINPUTDEVICE8W lpdid, DWORD dwFlags, DWORD dwRemaining, LPVOID pvRef)
- {
- DIDevicesData *data = (DIDevicesData*) pvRef;
- @@ -65,13 +75,64 @@ static BOOL CALLBACK collect_devices(LPCDIDEVICEINSTANCEW lpddi, LPDIRECTINPUTDE
- IDirectInputDevice_AddRef(lpdid);
- + device->nobjects = 0;
- + IDirectInputDevice_EnumObjects(lpdid, collect_objects, (LPVOID) device, DIDFT_ALL);
- +
- data->ndevices++;
- return DIENUM_CONTINUE;
- }
- /*
- + * Listview utility functions
- + */
- +static void init_listview_columns(HWND dialog)
- +{
- + LVCOLUMNW listColumn;
- + RECT viewRect;
- + int width;
- + WCHAR column[MAX_PATH];
- +
- + GetClientRect(GetDlgItem(dialog, IDC_DEVICEOBJECTSLIST), &viewRect);
- + width = (viewRect.right - viewRect.left)/2;
- +
- + LoadStringW(g_hinstance, IDS_OBJECTCOLUMN, column, sizeof(column)/sizeof(column[0]));
- + listColumn.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
- + listColumn.pszText = column;
- + listColumn.cchTextMax = lstrlenW(listColumn.pszText);
- + listColumn.cx = width;
- +
- + SendDlgItemMessageW (dialog, IDC_DEVICEOBJECTSLIST, LVM_INSERTCOLUMNW, 0, (LPARAM) &listColumn);
- +
- + LoadStringW(g_hinstance, IDS_ACTIONCOLUMN, column, sizeof(column)/sizeof(column[0]));
- + listColumn.cx = width;
- + listColumn.pszText = column;
- + listColumn.cchTextMax = lstrlenW(listColumn.pszText);
- +
- + SendDlgItemMessageW(dialog, IDC_DEVICEOBJECTSLIST, LVM_INSERTCOLUMNW, 1, (LPARAM) &listColumn);
- +}
- +
- +static void lv_set_item_text(HWND dialog, int item, int subItem, WCHAR *text)
- +{
- + LVITEMW lvItem;
- + if (item < 0 || subItem < 0) return;
- + lvItem.mask = LVIF_TEXT;
- + lvItem.iItem = item;
- + lvItem.iSubItem = subItem;
- + lvItem.pszText = text;
- + lvItem.cchTextMax = lstrlenW(lvItem.pszText);
- +
- + SendDlgItemMessageW(dialog, IDC_DEVICEOBJECTSLIST, LVM_SETITEMW, 0, (LPARAM) &lvItem);
- +}
- +
- +/*
- * Utility functions
- */
- +static DeviceData* get_cur_device(HWND dialog, DIDevicesData *data)
- +{
- + int sel = SendDlgItemMessageW(dialog, IDC_CONTROLLERCOMBO, CB_GETCURSEL, 0, 0);
- + return &data->devices[sel];
- +}
- +
- static void init_devices(HWND dialog, LPDIRECTINPUT8W lpDI, DIDevicesData *data, LPDIACTIONFORMATW lpdiaf)
- {
- int i;
- @@ -90,6 +151,54 @@ static void init_devices(HWND dialog, LPDIRECTINPUT8W lpDI, DIDevicesData *data,
- SendDlgItemMessageW(dialog, IDC_CONTROLLERCOMBO, CB_ADDSTRING, 0, (LPARAM) data->devices[i].ddi.tszProductName );
- }
- +static void fill_device_object_list(HWND dialog, DeviceData *device, LPDIACTIONFORMATW lpdiaf)
- +{
- + LVITEMW item;
- + WCHAR no_action[MAX_PATH];
- + int i, j;
- +
- + LoadStringW(g_hinstance, IDS_NOACTION, no_action, sizeof(no_action)/sizeof(no_action[0]));
- +
- + /* Clean the listview */
- + SendDlgItemMessageW(dialog, IDC_DEVICEOBJECTSLIST, LVM_DELETEALLITEMS, 0, 0);
- +
- + /* Add each object */
- + for (i=0; i < device->nobjects; i++)
- + {
- + WCHAR *action_text = no_action;
- + int action = -1;
- +
- + item.mask = LVIF_TEXT | LVIF_PARAM;
- + item.iItem = i;
- + item.iSubItem = 0;
- + item.pszText = device->ddo[i].tszName;
- + item.cchTextMax = lstrlenW(item.pszText);
- +
- + /* Search for an assigned action for this device */
- + for (j=0; j < lpdiaf->dwNumActions; j++)
- + {
- + if (IsEqualGUID(&lpdiaf->rgoAction[j].guidInstance, &device->ddi.guidInstance) &&
- + lpdiaf->rgoAction[j].dwObjID == device->ddo[i].dwType)
- + {
- + action = j;
- + break;
- + }
- + }
- +
- + /* Keep action index in the listview item */
- + item.lParam = (LPARAM) action;
- +
- + /* Add the item */
- + SendDlgItemMessageW(dialog, IDC_DEVICEOBJECTSLIST, LVM_INSERTITEMW, 0, (LPARAM) &item);
- +
- + if (action != -1)
- + action_text = (WCHAR*) lpdiaf->rgoAction[action].lptszActionName;
- +
- + /* Object/Action text */
- + lv_set_item_text(dialog, i, 1, action_text);
- + }
- +}
- +
- static void destroy_devices(DIDevicesData *data)
- {
- int i;
- @@ -112,6 +221,7 @@ static INT_PTR CALLBACK ConfigureDevicesDlgProc(HWND dialog, UINT uMsg, WPARAM w
- conf_data = (ConfigureDevicesData*) lParam;
- lpdiaf = conf_data->params->lprgFormats;
- + init_listview_columns(dialog);
- init_devices(dialog, conf_data->lpDI, &devices_data, lpdiaf);
- break;
- @@ -120,6 +230,17 @@ static INT_PTR CALLBACK ConfigureDevicesDlgProc(HWND dialog, UINT uMsg, WPARAM w
- switch( LOWORD( wParam ) )
- {
- +
- + case IDC_CONTROLLERCOMBO:
- +
- + switch (HIWORD(wParam))
- + {
- + case CBN_SELCHANGE:
- + fill_device_object_list(dialog, get_cur_device(dialog, &devices_data), lpdiaf);
- + break;
- + }
- + break;
- +
- case IDOK:
- EndDialog(dialog, 0);
- destroy_devices(&devices_data);
- --
- 1.7.0.4
Add Comment
Please, Sign In to add comment