Guest User

Untitled

a guest
Jan 24th, 2018
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.83 KB | None | 0 0
  1. From ecb8279fdbfe27a96a324fb43d27a2fdb9181b5c Mon Sep 17 00:00:00 2001
  2. From: Lucas Fialho Zawacki <lfzawacki@gmail.com>
  3. Date: Thu, 28 Jul 2011 19:03:31 -0300
  4. Subject: dinput: Added object/action enumeration to ConfigureDevices dialog
  5.  
  6. ---
  7. dlls/dinput/config.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++
  8. 1 files changed, 121 insertions(+), 0 deletions(-)
  9.  
  10. diff --git a/dlls/dinput/config.c b/dlls/dinput/config.c
  11. index ca85797..9c66c01 100644
  12. --- a/dlls/dinput/config.c
  13. +++ b/dlls/dinput/config.c
  14. @@ -48,6 +48,16 @@ static HINSTANCE g_hinstance;
  15. /*
  16. * Enumeration callback functions
  17. */
  18. +static BOOL CALLBACK collect_objects(LPCDIDEVICEOBJECTINSTANCEW lpddo, LPVOID pvRef)
  19. +{
  20. + DeviceData *data = (DeviceData*) pvRef;
  21. +
  22. + data->ddo[data->nobjects] = *lpddo;
  23. +
  24. + data->nobjects++;
  25. + return DIENUM_CONTINUE;
  26. +}
  27. +
  28. static BOOL CALLBACK count_devices(LPCDIDEVICEINSTANCEW lpddi, LPDIRECTINPUTDEVICE8W lpdid, DWORD dwFlags, DWORD dwRemaining, LPVOID pvRef)
  29. {
  30. DIDevicesData *data = (DIDevicesData*) pvRef;
  31. @@ -65,13 +75,64 @@ static BOOL CALLBACK collect_devices(LPCDIDEVICEINSTANCEW lpddi, LPDIRECTINPUTDE
  32.  
  33. IDirectInputDevice_AddRef(lpdid);
  34.  
  35. + device->nobjects = 0;
  36. + IDirectInputDevice_EnumObjects(lpdid, collect_objects, (LPVOID) device, DIDFT_ALL);
  37. +
  38. data->ndevices++;
  39. return DIENUM_CONTINUE;
  40. }
  41.  
  42. /*
  43. + * Listview utility functions
  44. + */
  45. +static void init_listview_columns(HWND dialog)
  46. +{
  47. + LVCOLUMNW listColumn;
  48. + RECT viewRect;
  49. + int width;
  50. + WCHAR column[MAX_PATH];
  51. +
  52. + GetClientRect(GetDlgItem(dialog, IDC_DEVICEOBJECTSLIST), &viewRect);
  53. + width = (viewRect.right - viewRect.left)/2;
  54. +
  55. + LoadStringW(g_hinstance, IDS_OBJECTCOLUMN, column, sizeof(column)/sizeof(column[0]));
  56. + listColumn.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
  57. + listColumn.pszText = column;
  58. + listColumn.cchTextMax = lstrlenW(listColumn.pszText);
  59. + listColumn.cx = width;
  60. +
  61. + SendDlgItemMessageW (dialog, IDC_DEVICEOBJECTSLIST, LVM_INSERTCOLUMNW, 0, (LPARAM) &listColumn);
  62. +
  63. + LoadStringW(g_hinstance, IDS_ACTIONCOLUMN, column, sizeof(column)/sizeof(column[0]));
  64. + listColumn.cx = width;
  65. + listColumn.pszText = column;
  66. + listColumn.cchTextMax = lstrlenW(listColumn.pszText);
  67. +
  68. + SendDlgItemMessageW(dialog, IDC_DEVICEOBJECTSLIST, LVM_INSERTCOLUMNW, 1, (LPARAM) &listColumn);
  69. +}
  70. +
  71. +static void lv_set_item_text(HWND dialog, int item, int subItem, WCHAR *text)
  72. +{
  73. + LVITEMW lvItem;
  74. + if (item < 0 || subItem < 0) return;
  75. + lvItem.mask = LVIF_TEXT;
  76. + lvItem.iItem = item;
  77. + lvItem.iSubItem = subItem;
  78. + lvItem.pszText = text;
  79. + lvItem.cchTextMax = lstrlenW(lvItem.pszText);
  80. +
  81. + SendDlgItemMessageW(dialog, IDC_DEVICEOBJECTSLIST, LVM_SETITEMW, 0, (LPARAM) &lvItem);
  82. +}
  83. +
  84. +/*
  85. * Utility functions
  86. */
  87. +static DeviceData* get_cur_device(HWND dialog, DIDevicesData *data)
  88. +{
  89. + int sel = SendDlgItemMessageW(dialog, IDC_CONTROLLERCOMBO, CB_GETCURSEL, 0, 0);
  90. + return &data->devices[sel];
  91. +}
  92. +
  93. static void init_devices(HWND dialog, LPDIRECTINPUT8W lpDI, DIDevicesData *data, LPDIACTIONFORMATW lpdiaf)
  94. {
  95. int i;
  96. @@ -90,6 +151,54 @@ static void init_devices(HWND dialog, LPDIRECTINPUT8W lpDI, DIDevicesData *data,
  97. SendDlgItemMessageW(dialog, IDC_CONTROLLERCOMBO, CB_ADDSTRING, 0, (LPARAM) data->devices[i].ddi.tszProductName );
  98. }
  99.  
  100. +static void fill_device_object_list(HWND dialog, DeviceData *device, LPDIACTIONFORMATW lpdiaf)
  101. +{
  102. + LVITEMW item;
  103. + WCHAR no_action[MAX_PATH];
  104. + int i, j;
  105. +
  106. + LoadStringW(g_hinstance, IDS_NOACTION, no_action, sizeof(no_action)/sizeof(no_action[0]));
  107. +
  108. + /* Clean the listview */
  109. + SendDlgItemMessageW(dialog, IDC_DEVICEOBJECTSLIST, LVM_DELETEALLITEMS, 0, 0);
  110. +
  111. + /* Add each object */
  112. + for (i=0; i < device->nobjects; i++)
  113. + {
  114. + WCHAR *action_text = no_action;
  115. + int action = -1;
  116. +
  117. + item.mask = LVIF_TEXT | LVIF_PARAM;
  118. + item.iItem = i;
  119. + item.iSubItem = 0;
  120. + item.pszText = device->ddo[i].tszName;
  121. + item.cchTextMax = lstrlenW(item.pszText);
  122. +
  123. + /* Search for an assigned action for this device */
  124. + for (j=0; j < lpdiaf->dwNumActions; j++)
  125. + {
  126. + if (IsEqualGUID(&lpdiaf->rgoAction[j].guidInstance, &device->ddi.guidInstance) &&
  127. + lpdiaf->rgoAction[j].dwObjID == device->ddo[i].dwType)
  128. + {
  129. + action = j;
  130. + break;
  131. + }
  132. + }
  133. +
  134. + /* Keep action index in the listview item */
  135. + item.lParam = (LPARAM) action;
  136. +
  137. + /* Add the item */
  138. + SendDlgItemMessageW(dialog, IDC_DEVICEOBJECTSLIST, LVM_INSERTITEMW, 0, (LPARAM) &item);
  139. +
  140. + if (action != -1)
  141. + action_text = (WCHAR*) lpdiaf->rgoAction[action].lptszActionName;
  142. +
  143. + /* Object/Action text */
  144. + lv_set_item_text(dialog, i, 1, action_text);
  145. + }
  146. +}
  147. +
  148. static void destroy_devices(DIDevicesData *data)
  149. {
  150. int i;
  151. @@ -112,6 +221,7 @@ static INT_PTR CALLBACK ConfigureDevicesDlgProc(HWND dialog, UINT uMsg, WPARAM w
  152. conf_data = (ConfigureDevicesData*) lParam;
  153. lpdiaf = conf_data->params->lprgFormats;
  154.  
  155. + init_listview_columns(dialog);
  156. init_devices(dialog, conf_data->lpDI, &devices_data, lpdiaf);
  157.  
  158. break;
  159. @@ -120,6 +230,17 @@ static INT_PTR CALLBACK ConfigureDevicesDlgProc(HWND dialog, UINT uMsg, WPARAM w
  160.  
  161. switch( LOWORD( wParam ) )
  162. {
  163. +
  164. + case IDC_CONTROLLERCOMBO:
  165. +
  166. + switch (HIWORD(wParam))
  167. + {
  168. + case CBN_SELCHANGE:
  169. + fill_device_object_list(dialog, get_cur_device(dialog, &devices_data), lpdiaf);
  170. + break;
  171. + }
  172. + break;
  173. +
  174. case IDOK:
  175. EndDialog(dialog, 0);
  176. destroy_devices(&devices_data);
  177. --
  178. 1.7.0.4
Add Comment
Please, Sign In to add comment