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.

402 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 = IDirectInputDevice_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 = IDirectInputDevice_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 = IDirectInputDevice_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 = IDirectInputDevice_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 = IDirectInputDevice_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 = IDirectInputDevice_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. hres = IDirectInputDevice_GetProperty(pddi->pdid, DIPROP_JOYSTICKID,
  222. &u.diph);
  223. if (SUCCEEDED(hres)) {
  224. Vlist_AddIntValue(hwndList, IDS_CAPS_JOYSTICKID, u.dipdw.dwData);
  225. }
  226. if( iItem >=0 ) {
  227. ListBox_SetCurSel(hwndList, iItem);
  228. Vlist_OnSelChange(hwndList);
  229. }
  230. SetWindowRedraw(hwndList, TRUE);
  231. }
  232. /*****************************************************************************
  233. *
  234. * Caps_OnInitDialog
  235. *
  236. * Get the caps and show them. That's all.
  237. *
  238. *****************************************************************************/
  239. BOOL INTERNAL
  240. Caps_OnInitDialog(HWND hdlg, LPARAM lp)
  241. {
  242. PDEVDLGINFO pddi = (PV)(((LPPROPSHEETPAGE)lp)->lParam);
  243. SetDialogPtr(hdlg, pddi);
  244. Caps_Refresh(hdlg);
  245. return 1;
  246. }
  247. /*****************************************************************************
  248. *
  249. * Caps_OnDestroy
  250. *
  251. * Tell the checklist to go away, too.
  252. *
  253. *****************************************************************************/
  254. void INTERNAL
  255. Caps_OnDestroy(HWND hdlg)
  256. {
  257. Vlist_OnDestroy(GetDlgItem(hdlg, IDC_CAPS_LIST));
  258. // Checklist_OnDestroy(GetDlgItem(hdlg, IDC_CAPS_CHECKLIST));
  259. }
  260. /*****************************************************************************
  261. *
  262. * Caps_OnControlPanel
  263. *
  264. *****************************************************************************/
  265. BOOL INTERNAL
  266. Caps_OnControlPanel(HWND hdlg)
  267. {
  268. PDEVDLGINFO pddi = GetDialogPtr(hdlg);
  269. HRESULT hres;
  270. hres = IDirectInputDevice_RunControlPanel(pddi->pdid, hdlg, 0);
  271. if (SUCCEEDED(hres)) {
  272. } else {
  273. MessageBoxV(hdlg, IDS_ERR_RUNCPL, hres);
  274. }
  275. return 1;
  276. }
  277. /*****************************************************************************
  278. *
  279. * Caps_OnCommand
  280. *
  281. *****************************************************************************/
  282. BOOL INLINE
  283. Caps_OnCommand(HWND hdlg, int id, UINT cmd)
  284. {
  285. switch (id) {
  286. case IDC_CAPS_CPL: return Caps_OnControlPanel(hdlg);
  287. case IDC_CAPS_LIST:
  288. if (cmd == LBN_SELCHANGE) {
  289. Vlist_OnSelChange(GetDlgItem(hdlg, IDC_CAPS_LIST));
  290. return TRUE;
  291. }
  292. break;
  293. case IDC_CAPS_REFRESH: Caps_Refresh(hdlg); return TRUE;
  294. }
  295. return 0;
  296. }
  297. /*****************************************************************************
  298. *
  299. * Caps_DlgProc
  300. *
  301. *****************************************************************************/
  302. INT_PTR CALLBACK
  303. Caps_DlgProc(HWND hdlg, UINT wm, WPARAM wp, LPARAM lp)
  304. {
  305. switch (wm) {
  306. case WM_INITDIALOG: return Caps_OnInitDialog(hdlg, lp);
  307. case WM_COMMAND:
  308. return Caps_OnCommand(hdlg,
  309. (int)GET_WM_COMMAND_ID(wp, lp),
  310. (UINT)GET_WM_COMMAND_CMD(wp, lp));
  311. case WM_SYSCOLORCHANGE:
  312. case WM_SETTINGCHANGE:
  313. case WM_FONTCHANGE:
  314. case WM_DEVMODECHANGE:
  315. case WM_TIMECHANGE:
  316. case WM_DEVICECHANGE:
  317. // SendDlgItemMessage(hdlg, IDC_CAPS_CHECKLIST, wm, wp, lp);
  318. break;
  319. case WM_DESTROY:
  320. Caps_OnDestroy(hdlg);
  321. break;
  322. }
  323. return 0;
  324. }