Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

403 lines
12 KiB

  1. /*****************************************************************************
  2. *
  3. * diqcaps.c
  4. *
  5. * "Caps" property sheet page.
  6. *
  7. * Also does GetDeviceInfo (as well as GetDeviceCaps).
  8. *
  9. *****************************************************************************/
  10. #include "diquick.h"
  11. #pragma BEGIN_CONST_DATA
  12. CHECKLISTFLAG c_rgcfDidc[] = {
  13. { DIDC_ATTACHED, IDS_ATTACHED, },
  14. { DIDC_POLLEDDEVICE, IDS_POLLEDDEVICE, },
  15. { DIDC_POLLEDDATAFORMAT, IDS_POLLEDDATAFORMAT, },
  16. { DIDC_EMULATED, IDS_EMULATED, },
  17. { DIDC_FORCEFEEDBACK, IDS_FORCEFEEDBACK, },
  18. { DIDC_FFATTACK, IDS_FFATTACK, },
  19. { DIDC_FFFADE, IDS_FFFADE, },
  20. { DIDC_SATURATION, IDS_SATURATION, },
  21. { DIDC_POSNEGCOEFFICIENTS, IDS_POSNEGCOEFFICIENTS, },
  22. { DIDC_POSNEGSATURATION, IDS_POSNEGSATURATION, },
  23. { DIDC_ALIAS, IDS_ALIASDEVICE, },
  24. { DIDC_PHANTOM, IDS_PHANTOMDEVICE, },
  25. };
  26. CHECKLISTFLAG c_rgcfDevType[] = {
  27. { DIDEVTYPE_HID, IDS_CAPS_HID, },
  28. };
  29. #pragma END_CONST_DATA
  30. /*****************************************************************************
  31. *
  32. * Caps_GetGuidPath
  33. *
  34. * Getting the GUID and path is a bit annoying, so we put it in
  35. * a separate function.
  36. *
  37. *****************************************************************************/
  38. void INTERNAL
  39. Caps_GetGuidPath(HWND hwndList, PDEVDLGINFO pddi)
  40. {
  41. DIPROPGUIDANDPATH gp;
  42. HRESULT hres;
  43. gp.diph.dwSize = sizeof(DIPROPGUIDANDPATH);
  44. gp.diph.dwHeaderSize = sizeof(DIPROPHEADER);
  45. gp.diph.dwObj = 0;
  46. gp.diph.dwHow = DIPH_DEVICE;
  47. hres = IDirectInputDevice8_GetProperty(pddi->pdid, DIPROP_GUIDANDPATH,
  48. &gp.diph);
  49. if (SUCCEEDED(hres)) {
  50. TCHAR tsz[MAX_PATH];
  51. Vlist_AddValue(hwndList, IDS_CAPS_CLASSGUID,
  52. MapGUID(&gp.guidClass, tsz));
  53. ConvertString(TRUE, gp.wszPath, tsz, cA(tsz));
  54. Vlist_AddValue(hwndList, IDS_CAPS_PATH, tsz);
  55. }
  56. }
  57. /*****************************************************************************
  58. *
  59. * Caps_SetStringPropCallback
  60. *
  61. *****************************************************************************/
  62. HRESULT CALLBACK
  63. Caps_SetStringPropCallback(LPCTSTR ptszValue, PV pvRef1, PV pvRef2)
  64. {
  65. PDEVDLGINFO pddi = pvRef1;
  66. const GUID *prop = pvRef2;
  67. DIPROPSTRING str;
  68. HRESULT hres;
  69. str.diph.dwSize = sizeof(DIPROPSTRING);
  70. str.diph.dwHeaderSize = sizeof(DIPROPHEADER);
  71. str.diph.dwObj = 0;
  72. str.diph.dwHow = DIPH_DEVICE;
  73. UnconvertString(TRUE, ptszValue, str.wsz, cA(str.wsz));
  74. hres = IDirectInputDevice8_SetProperty(pddi->pdid, prop, &str.diph);
  75. return hres;
  76. }
  77. /*****************************************************************************
  78. *
  79. * Caps_GetStringProp
  80. *
  81. *****************************************************************************/
  82. void INTERNAL
  83. Caps_GetStringProp(HWND hwndList, UINT ids, const GUID *prop, PDEVDLGINFO pddi)
  84. {
  85. DIPROPSTRING str;
  86. HRESULT hres;
  87. str.diph.dwSize = sizeof(DIPROPSTRING);
  88. str.diph.dwHeaderSize = sizeof(DIPROPHEADER);
  89. str.diph.dwObj = 0;
  90. str.diph.dwHow = DIPH_DEVICE;
  91. hres = IDirectInputDevice8_GetProperty(pddi->pdid, prop, &str.diph);
  92. /*
  93. * Anything other than E_NOTIMPL means that it's supported but
  94. * didn't work.
  95. */
  96. if (FAILED(hres) && hres != E_NOTIMPL) {
  97. str.wsz[0] = TEXT('\0');
  98. hres = S_OK;
  99. }
  100. if (SUCCEEDED(hres)) {
  101. TCHAR tsz[MAX_PATH];
  102. ConvertString(TRUE, str.wsz, tsz, cA(tsz));
  103. Vlist_AddValueRW(hwndList, ids, tsz, Caps_SetStringPropCallback,
  104. pddi, (PV)prop);
  105. }
  106. }
  107. /*****************************************************************************
  108. *
  109. * Caps_SetPropCallback
  110. *
  111. *****************************************************************************/
  112. HRESULT CALLBACK
  113. Caps_SetPropCallback(LPDIPROPHEADER pdiph, PV pvRef1, PV pvRef2)
  114. {
  115. PDEVDLGINFO pddi = pvRef1;
  116. const GUID *prop = (const GUID *)pvRef2;
  117. HRESULT hres;
  118. hres = IDirectInputDevice8_SetProperty(pddi->pdid, prop, pdiph);
  119. return hres;
  120. }
  121. /*****************************************************************************
  122. *
  123. * Caps_Refresh
  124. *
  125. * Get the caps and show them, preserving the current selection.
  126. *
  127. *****************************************************************************/
  128. void INTERNAL
  129. Caps_Refresh(HWND hdlg)
  130. {
  131. PDEVDLGINFO pddi = GetDialogPtr(hdlg);
  132. DIDEVCAPS didc;
  133. DIDEVICEINSTANCE didi;
  134. HRESULT hres;
  135. TCHAR tsz[1024];
  136. HWND hwndList;
  137. int iItem;
  138. union {
  139. DIPROPHEADER diph;
  140. DIPROPDWORD dipdw;
  141. DIPROPRANGE diprg;
  142. DIPROPCAL dipcal;
  143. } u;
  144. hwndList = GetDlgItem(hdlg, IDC_CAPS_LIST);
  145. SetWindowRedraw(hwndList, FALSE);
  146. iItem = ListBox_GetCurSel(hwndList);
  147. if (iItem < 0) {
  148. iItem = 0;
  149. }
  150. Vlist_OnDestroy(hwndList);
  151. Vlist_OnInitDialog(hwndList);
  152. didc.dwSize = cbX(DIDEVCAPS_DX3);
  153. hres = IDirectInputDevice8_GetCapabilities(pddi->pdid, &didc);
  154. if (SUCCEEDED(hres)) {
  155. LoadString(g_hinst, IDS_TYPEARRAY + GET_DIDEVICE_TYPE(didc.dwDevType),
  156. tsz, cA(tsz));
  157. if (tsz[0]) {
  158. Vlist_AddValue(hwndList, IDS_CAPS_TYPE, tsz);
  159. LoadString(g_hinst, IDS_TYPEARRAY +
  160. MAKEWORD(GET_DIDEVICE_SUBTYPE(didc.dwDevType),
  161. GET_DIDEVICE_TYPE(didc.dwDevType)),
  162. tsz, cA(tsz));
  163. if (tsz[0]) {
  164. Vlist_AddValue(hwndList, IDS_CAPS_SUBTYPE, tsz);
  165. } else {
  166. Vlist_AddIntValue(hwndList, IDS_CAPS_SUBTYPE,
  167. GET_DIDEVICE_SUBTYPE(didc.dwDevType));
  168. }
  169. } else {
  170. Vlist_AddIntValue(hwndList, IDS_CAPS_TYPE,
  171. GET_DIDEVICE_TYPE(didc.dwDevType));
  172. Vlist_AddIntValue(hwndList, IDS_CAPS_SUBTYPE,
  173. GET_DIDEVICE_SUBTYPE(didc.dwDevType));
  174. }
  175. Vlist_AddFlags(hwndList, didc.dwDevType,
  176. c_rgcfDevType, cA(c_rgcfDevType));
  177. Vlist_AddIntValue(hwndList, IDS_CAPS_AXES, didc.dwAxes);
  178. Vlist_AddIntValue(hwndList, IDS_CAPS_BUTTONS, didc.dwButtons);
  179. Vlist_AddIntValue(hwndList, IDS_CAPS_POVS, didc.dwPOVs);
  180. Vlist_AddFlags(hwndList, didc.dwFlags,
  181. c_rgcfDidc, cA(c_rgcfDidc));
  182. }
  183. didc.dwSize = cbX(DIDEVCAPS);
  184. hres = IDirectInputDevice8_GetCapabilities(pddi->pdid, &didc);
  185. if (SUCCEEDED(hres)) {
  186. Vlist_AddIntValue(hwndList, IDS_CAPS_FFSAMPLEPERIOD,
  187. didc.dwFFSamplePeriod);
  188. Vlist_AddIntValue(hwndList, IDS_CAPS_FFMINTIMERESOLUTION,
  189. didc.dwFFMinTimeResolution);
  190. Vlist_AddHexValue(hwndList, IDS_CAPS_FIRMWAREREVISION,
  191. didc.dwFirmwareRevision);
  192. Vlist_AddHexValue(hwndList, IDS_CAPS_HARDWAREREVISION,
  193. didc.dwHardwareRevision);
  194. Vlist_AddHexValue(hwndList, IDS_CAPS_FFDRIVERVERSION,
  195. didc.dwFFDriverVersion);
  196. }
  197. // BUGBUG -- character set
  198. didi.dwSize = cbX(DIDEVICEINSTANCE_DX3);
  199. hres = GetDeviceInfo(pddi, &didi);
  200. if (SUCCEEDED(hres)) {
  201. Vlist_AddValue(hwndList, IDS_CAPS_GUIDINSTANCE,
  202. MapGUID(&didi.guidInstance, tsz));
  203. Vlist_AddValue(hwndList, IDS_CAPS_GUIDPRODUCT,
  204. MapGUID(&didi.guidProduct, tsz));
  205. // Vlist_AddHexValue(hwndList, IDS_CAPS_DEVTYPE, didi.dwDevType);
  206. Vlist_AddValue(hwndList, IDS_CAPS_INSTANCENAME, didi.tszInstanceName);
  207. Vlist_AddValue(hwndList, IDS_CAPS_PRODUCTNAME, didi.tszProductName);
  208. }
  209. didi.dwSize = cbX(DIDEVICEINSTANCE);
  210. hres = GetDeviceInfo(pddi, &didi);
  211. if (SUCCEEDED(hres)) {
  212. Vlist_AddValue(hwndList, IDS_CAPS_GUIDFFDRIVER,
  213. MapGUID(&didi.guidFFDriver, tsz));
  214. Vlist_AddHexValue(hwndList, IDS_CAPS_USAGEPAGE, didi.wUsagePage);
  215. Vlist_AddHexValue(hwndList, IDS_CAPS_USAGE, didi.wUsage);
  216. }
  217. Caps_GetGuidPath(hwndList, pddi);
  218. Caps_GetStringProp(hwndList, IDS_CAPS_INSTPROP, DIPROP_INSTANCENAME, pddi);
  219. Caps_GetStringProp(hwndList, IDS_CAPS_MFGPROP, DIPROP_PRODUCTNAME, pddi);
  220. Caps_GetStringProp(hwndList, IDS_CAPS_PORTNAME, DIPROP_GETPORTDISPLAYNAME, pddi);
  221. Caps_GetStringProp(hwndList, IDS_CAPS_TYPENAME, DIPROP_TYPENAME, pddi);
  222. hres = IDirectInputDevice8_GetProperty(pddi->pdid, DIPROP_JOYSTICKID,
  223. &u.diph);
  224. if (SUCCEEDED(hres)) {
  225. Vlist_AddIntValue(hwndList, IDS_CAPS_JOYSTICKID, u.dipdw.dwData);
  226. }
  227. if( iItem >= 0 ) {
  228. ListBox_SetCurSel(hwndList, iItem);
  229. Vlist_OnSelChange(hwndList);
  230. }
  231. SetWindowRedraw(hwndList, TRUE);
  232. }
  233. /*****************************************************************************
  234. *
  235. * Caps_OnInitDialog
  236. *
  237. * Get the caps and show them. That's all.
  238. *
  239. *****************************************************************************/
  240. BOOL INTERNAL
  241. Caps_OnInitDialog(HWND hdlg, LPARAM lp)
  242. {
  243. PDEVDLGINFO pddi = (PV)(((LPPROPSHEETPAGE)lp)->lParam);
  244. SetDialogPtr(hdlg, pddi);
  245. Caps_Refresh(hdlg);
  246. return 1;
  247. }
  248. /*****************************************************************************
  249. *
  250. * Caps_OnDestroy
  251. *
  252. * Tell the checklist to go away, too.
  253. *
  254. *****************************************************************************/
  255. void INTERNAL
  256. Caps_OnDestroy(HWND hdlg)
  257. {
  258. Vlist_OnDestroy(GetDlgItem(hdlg, IDC_CAPS_LIST));
  259. // Checklist_OnDestroy(GetDlgItem(hdlg, IDC_CAPS_CHECKLIST));
  260. }
  261. /*****************************************************************************
  262. *
  263. * Caps_OnControlPanel
  264. *
  265. *****************************************************************************/
  266. BOOL INTERNAL
  267. Caps_OnControlPanel(HWND hdlg)
  268. {
  269. PDEVDLGINFO pddi = GetDialogPtr(hdlg);
  270. HRESULT hres;
  271. hres = IDirectInputDevice8_RunControlPanel(pddi->pdid, hdlg, 0);
  272. if (SUCCEEDED(hres)) {
  273. } else {
  274. MessageBoxV(hdlg, IDS_ERR_RUNCPL, hres);
  275. }
  276. return 1;
  277. }
  278. /*****************************************************************************
  279. *
  280. * Caps_OnCommand
  281. *
  282. *****************************************************************************/
  283. BOOL INLINE
  284. Caps_OnCommand(HWND hdlg, int id, UINT cmd)
  285. {
  286. switch (id) {
  287. case IDC_CAPS_CPL: return Caps_OnControlPanel(hdlg);
  288. case IDC_CAPS_LIST:
  289. if (cmd == LBN_SELCHANGE) {
  290. Vlist_OnSelChange(GetDlgItem(hdlg, IDC_CAPS_LIST));
  291. return TRUE;
  292. }
  293. break;
  294. case IDC_CAPS_REFRESH: Caps_Refresh(hdlg); return TRUE;
  295. }
  296. return 0;
  297. }
  298. /*****************************************************************************
  299. *
  300. * Caps_DlgProc
  301. *
  302. *****************************************************************************/
  303. INT_PTR CALLBACK
  304. Caps_DlgProc(HWND hdlg, UINT wm, WPARAM wp, LPARAM lp)
  305. {
  306. switch (wm) {
  307. case WM_INITDIALOG: return Caps_OnInitDialog(hdlg, lp);
  308. case WM_COMMAND:
  309. return Caps_OnCommand(hdlg,
  310. (int)GET_WM_COMMAND_ID(wp, lp),
  311. (UINT)GET_WM_COMMAND_CMD(wp, lp));
  312. case WM_SYSCOLORCHANGE:
  313. case WM_SETTINGCHANGE:
  314. case WM_FONTCHANGE:
  315. case WM_DEVMODECHANGE:
  316. case WM_TIMECHANGE:
  317. case WM_DEVICECHANGE:
  318. // SendDlgItemMessage(hdlg, IDC_CAPS_CHECKLIST, wm, wp, lp);
  319. break;
  320. case WM_DESTROY:
  321. Caps_OnDestroy(hdlg);
  322. break;
  323. }
  324. return 0;
  325. }