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.

433 lines
11 KiB

  1. /*****************************************************************************
  2. *
  3. * diqmode.c
  4. *
  5. * "Mode" property sheet page.
  6. *
  7. *****************************************************************************/
  8. #include "diquick.h"
  9. /*****************************************************************************
  10. *
  11. * Common_AcqSetDataFormat
  12. *
  13. * Common worker function that sets the data format.
  14. *
  15. *****************************************************************************/
  16. STDMETHODIMP
  17. Common_AcqSetDataFormat(PDEVDLGINFO pddi)
  18. {
  19. return IDirectInputDevice_SetDataFormat(pddi->pdid, pddi->pvtbl->pdf);
  20. }
  21. /*****************************************************************************
  22. *
  23. * Common_AcqDestroy
  24. *
  25. * Common worker function that doesn't do anything.
  26. *
  27. *****************************************************************************/
  28. STDMETHODIMP_(void)
  29. Common_AcqDestroy(PDEVDLGINFO pddi)
  30. {
  31. }
  32. /*****************************************************************************
  33. *
  34. * Mode_SyncCheckButtons
  35. *
  36. * Sync the dialog buttons with the IDirectInputXxx object.
  37. *
  38. *****************************************************************************/
  39. void INTERNAL
  40. Mode_SyncCheckButtons(PDEVDLGINFO pddi, HWND hdlg)
  41. {
  42. UINT idc;
  43. DWORD dw;
  44. switch (pddi->discl) {
  45. default:
  46. case DISCL_BACKGROUND | DISCL_NONEXCLUSIVE:
  47. idc = IDC_DEV_PASSIVE; break;
  48. case DISCL_FOREGROUND | DISCL_NONEXCLUSIVE:
  49. idc = IDC_DEV_PASSIVE_FOREGROUND; break;
  50. case DISCL_BACKGROUND | DISCL_EXCLUSIVE:
  51. idc = IDC_DEV_ACTIVE_BACKGROUND; break;
  52. case DISCL_FOREGROUND | DISCL_EXCLUSIVE:
  53. idc = IDC_DEV_ACTIVE; break;
  54. }
  55. CheckRadioButton(hdlg, IDC_DEV_PASSIVE, IDC_DEV_ACTIVE, idc);
  56. CheckRadioButton(hdlg, IDC_DEV_POLLED, IDC_DEV_EVENT,
  57. pddi->fPoll ? IDC_DEV_POLLED : IDC_DEV_EVENT);
  58. EnableWindow(GetDlgItem(hdlg, IDC_DEV_NOWINKEY), FALSE);
  59. if (pddi->pvtbl == &c_acqvtblDevMouse || pddi->pvtbl == &c_acqvtblDevMouse2 ) {
  60. idc = IDC_DEV_MOUSE;
  61. } else if (pddi->pvtbl == &c_acqvtblDevKbd) {
  62. idc = IDC_DEV_KEYBOARD;
  63. EnableWindow(GetDlgItem(hdlg, IDC_DEV_NOWINKEY), TRUE);
  64. } else if (pddi->pvtbl == &c_acqvtblDevJoy) {
  65. idc = IDC_DEV_JOYSTICK;
  66. } else if (pddi->pvtbl == &c_acqvtblDev) {
  67. idc = IDC_DEV_DEVICE;
  68. } else {
  69. idc = 0;
  70. }
  71. CheckRadioButton(hdlg, IDC_DEV_MOUSE, IDC_DEV_DEVICE, idc);
  72. if (SUCCEEDED(GetDwordProperty(pddi->pdid, DIPROP_AXISMODE, &dw))) {
  73. CheckRadioButton(hdlg, IDC_DEV_ABS, IDC_DEV_REL,
  74. dw == DIPROPAXISMODE_ABS ? IDC_DEV_ABS
  75. : IDC_DEV_REL);
  76. }
  77. if (SUCCEEDED(GetDwordProperty(pddi->pdid, DIPROP_CALIBRATIONMODE, &dw))) {
  78. } else {
  79. dw = 0;
  80. }
  81. CheckDlgButton(hdlg, IDC_DEV_CAL, dw);
  82. }
  83. /*****************************************************************************
  84. *
  85. * Mode_OnDataFormat
  86. *
  87. * Change the device data format.
  88. *
  89. *****************************************************************************/
  90. BOOL INTERNAL
  91. Mode_OnDataFormat(PDEVDLGINFO pddi, HWND hdlg, UINT id)
  92. {
  93. DIDEVCAPS didc;
  94. HRESULT hres;
  95. UINT idDev;
  96. /*
  97. * Kill the old data format before setting the new one.
  98. */
  99. if (pddi->pvtbl) {
  100. pddi->pvtbl->Destroy(pddi);
  101. }
  102. if( id == 0 ) { //from On_InitDialog
  103. didc.dwSize = cbX(DIDEVCAPS_DX3);
  104. hres = IDirectInputDevice_GetCapabilities(pddi->pdid, &didc);
  105. if (SUCCEEDED(hres))
  106. idDev = GET_DIDEVICE_TYPE(didc.dwDevType);
  107. } else
  108. idDev = id;
  109. switch (idDev) {
  110. case DIDEVTYPE_MOUSE:
  111. case IDC_DEV_MOUSE:
  112. #if DIRECTINPUT_VERSION >= 0x700
  113. pddi->pvtbl = &c_acqvtblDevMouse2;
  114. #else
  115. pddi->pvtbl = &c_acqvtblDevMouse;
  116. #endif
  117. break;
  118. case DIDEVTYPE_KEYBOARD:
  119. case IDC_DEV_KEYBOARD:
  120. pddi->pvtbl = &c_acqvtblDevKbd;
  121. break;
  122. case DIDEVTYPE_JOYSTICK:
  123. case IDC_DEV_JOYSTICK:
  124. pddi->pvtbl = &c_acqvtblDevJoy;
  125. break;
  126. case DIDEVTYPE_DEVICE:
  127. case IDC_DEV_DEVICE:
  128. pddi->pvtbl = &c_acqvtblDev;
  129. break;
  130. }
  131. if (pddi->pvtbl) {
  132. HRESULT hres;
  133. hres = pddi->pvtbl->SetDataFormat(pddi);
  134. if (FAILED(hres)) {
  135. MessageBoxV(GetParent(hdlg), IDS_ERR_DATAFORMAT);
  136. }
  137. }
  138. /* Always sync buttons, because the data format may change axis modes */
  139. Mode_SyncCheckButtons(pddi, hdlg);
  140. return 1;
  141. }
  142. /*****************************************************************************
  143. *
  144. * Mode_OnInitDialog
  145. *
  146. * Set up all the random switches.
  147. *
  148. * Notice that GetCapabilities is in the same location in all the
  149. * DirectInputXxx interfaces.
  150. *
  151. *****************************************************************************/
  152. #pragma BEGIN_CONST_DATA
  153. /*
  154. * Acceleration info: Accelerate in steps of 32, then 128.
  155. */
  156. UDACCEL c_uda[] = {
  157. { 0, 32 },
  158. { 1, 128 },
  159. };
  160. #pragma END_CONST_DATA
  161. BOOL INTERNAL
  162. Mode_OnInitDialog(HWND hdlg, LPARAM lp)
  163. {
  164. PDEVDLGINFO pddi = (PV)(((LPPROPSHEETPAGE)lp)->lParam);
  165. SetDialogPtr(hdlg, pddi);
  166. CheckRadioButton(hdlg, IDC_DEV_ABS, IDC_DEV_REL, IDC_DEV_ABS);
  167. /*
  168. * Note that we do not check any device format.
  169. * This lets us make sure that things work when nothing is selected.
  170. */
  171. Mode_SyncCheckButtons(pddi, hdlg);
  172. /*
  173. * Configure the buffer size edit and its updown control.
  174. */
  175. SetDlgItemInt(hdlg, IDC_DEV_BUFSIZE, 0, 0);
  176. SendDlgItemMessage(hdlg, IDC_DEV_BUFSIZEUD, UDM_SETACCEL,
  177. cA(c_uda), (LPARAM)&c_uda);
  178. SendDlgItemMessage(hdlg, IDC_DEV_BUFSIZEUD, UDM_SETRANGE,
  179. 0, MAKELONG(1025, 0)); /* 1025 is illegal */
  180. Mode_OnDataFormat( pddi, hdlg, 0 );
  181. return 1;
  182. }
  183. /*****************************************************************************
  184. *
  185. * Mode_OnCooperativity
  186. *
  187. *****************************************************************************/
  188. BOOL INTERNAL
  189. Mode_OnCooperativity(PDEVDLGINFO pddi, HWND hdlg, int id)
  190. {
  191. HRESULT hres;
  192. DWORD discl = 0;
  193. switch (id) {
  194. case IDC_DEV_ACTIVE_BACKGROUND:
  195. discl = DISCL_BACKGROUND | DISCL_EXCLUSIVE; break;
  196. case IDC_DEV_ACTIVE:
  197. discl = DISCL_FOREGROUND | DISCL_EXCLUSIVE; break;
  198. case IDC_DEV_PASSIVE_FOREGROUND:
  199. discl = DISCL_FOREGROUND | DISCL_NONEXCLUSIVE; break;
  200. case IDC_DEV_PASSIVE:
  201. discl = DISCL_BACKGROUND | DISCL_NONEXCLUSIVE; break;
  202. case IDC_DEV_NOWINKEY:
  203. if( IsDlgButtonChecked(hdlg, IDC_DEV_NOWINKEY) ) {
  204. discl = pddi->disclLastTry | DISCL_NOWINKEY;
  205. } else {
  206. discl = pddi->disclLastTry & ~DISCL_NOWINKEY;
  207. }
  208. }
  209. if( id != IDC_DEV_NOWINKEY ) {
  210. if( IsDlgButtonChecked(hdlg, IDC_DEV_NOWINKEY) ) {
  211. discl = discl | DISCL_NOWINKEY;
  212. } else {
  213. discl = discl & ~DISCL_NOWINKEY;
  214. }
  215. }
  216. if (discl != pddi->disclLastTry && discl != pddi->discl) {
  217. pddi->disclLastTry = discl;
  218. hres = IDirectInputDevice_SetCooperativeLevel(pddi->pdid,
  219. GetParent(hdlg), discl);
  220. if (SUCCEEDED(hres)) {
  221. pddi->discl = discl;
  222. } else {
  223. CheckDlgButton( hdlg, IDC_DEV_NOWINKEY, BST_UNCHECKED );
  224. Mode_SyncCheckButtons(pddi, hdlg);
  225. MessageBoxV(GetParent(hdlg), IDS_ERR_COOPERATIVITY);
  226. }
  227. }
  228. return 1;
  229. }
  230. /*****************************************************************************
  231. *
  232. * Mode_OnDataMode
  233. *
  234. *****************************************************************************/
  235. BOOL INTERNAL
  236. Mode_OnDataMode(PDEVDLGINFO pddi, HWND hdlg, int id)
  237. {
  238. pddi->fPoll = (id == IDC_DEV_POLLED);
  239. return 1;
  240. }
  241. /*****************************************************************************
  242. *
  243. * Mode_OnAxisMode
  244. *
  245. *****************************************************************************/
  246. BOOL INTERNAL
  247. Mode_OnAxisMode(PDEVDLGINFO pddi, HWND hdlg, int id)
  248. {
  249. if (pddi && pddi->pdid) {
  250. DWORD dwMode;
  251. HRESULT hres;
  252. if (id == IDC_DEV_ABS) {
  253. dwMode = DIPROPAXISMODE_ABS;
  254. } else {
  255. dwMode = DIPROPAXISMODE_REL;
  256. }
  257. hres = SetDwordProperty(pddi->pdid, DIPROP_AXISMODE, dwMode);
  258. if (SUCCEEDED(hres)) {
  259. } else {
  260. MessageBoxV(GetParent(hdlg), IDS_ERR_AXISMODE);
  261. }
  262. }
  263. return 1;
  264. }
  265. /*****************************************************************************
  266. *
  267. * Mode_OnCalMode
  268. *
  269. *****************************************************************************/
  270. BOOL INTERNAL
  271. Mode_OnCalMode(PDEVDLGINFO pddi, HWND hdlg)
  272. {
  273. if (pddi && pddi->pdid) {
  274. DWORD dwMode;
  275. HRESULT hres;
  276. dwMode = IsDlgButtonChecked(hdlg, IDC_DEV_CAL);
  277. hres = SetDwordProperty(pddi->pdid, DIPROP_CALIBRATIONMODE, dwMode);
  278. if (SUCCEEDED(hres)) {
  279. } else {
  280. MessageBoxV(GetParent(hdlg), IDS_ERR_CALMODE);
  281. }
  282. }
  283. return 1;
  284. }
  285. /*****************************************************************************
  286. *
  287. * Mode_SyncBufferSize
  288. *
  289. *****************************************************************************/
  290. BOOL INTERNAL
  291. Mode_SyncBufferSize(PDEVDLGINFO pddi, HWND hdlg)
  292. {
  293. if (pddi && pddi->pdid) {
  294. UINT ui = GetDlgItemInt(hdlg, IDC_DEV_BUFSIZE, 0, 0);
  295. HRESULT hres;
  296. hres = SetDwordProperty(pddi->pdid, DIPROP_BUFFERSIZE, ui);
  297. if (SUCCEEDED(hres)) {
  298. } else {
  299. MessageBoxV(GetParent(hdlg), IDS_ERR_BUFFERSIZE);
  300. }
  301. }
  302. return 1;
  303. }
  304. /*****************************************************************************
  305. *
  306. * Mode_OnCommand
  307. *
  308. *****************************************************************************/
  309. BOOL INTERNAL
  310. Mode_OnCommand(HWND hdlg, int id, UINT cmd)
  311. {
  312. PDEVDLGINFO pddi = GetDialogPtr(hdlg);
  313. if (cmd == BN_CLICKED) {
  314. switch (id) {
  315. case IDC_DEV_PASSIVE:
  316. case IDC_DEV_PASSIVE_FOREGROUND:
  317. case IDC_DEV_ACTIVE_BACKGROUND:
  318. case IDC_DEV_ACTIVE:
  319. case IDC_DEV_NOWINKEY:
  320. return Mode_OnCooperativity(pddi, hdlg, id);
  321. case IDC_DEV_POLLED:
  322. case IDC_DEV_EVENT: return Mode_OnDataMode(pddi, hdlg, id);
  323. case IDC_DEV_ABS:
  324. case IDC_DEV_REL: return Mode_OnAxisMode(pddi, hdlg, id);
  325. case IDC_DEV_CAL: return Mode_OnCalMode(pddi, hdlg);
  326. case IDC_DEV_MOUSE:
  327. case IDC_DEV_KEYBOARD:
  328. case IDC_DEV_JOYSTICK:
  329. case IDC_DEV_DEVICE: return Mode_OnDataFormat(pddi, hdlg, id);
  330. }
  331. } else if (cmd == EN_UPDATE) {
  332. if (id == IDC_DEV_BUFSIZE) {
  333. return Mode_SyncBufferSize(pddi, hdlg);
  334. }
  335. }
  336. return 0;
  337. }
  338. /*****************************************************************************
  339. *
  340. * Mode_DlgProc
  341. *
  342. *****************************************************************************/
  343. INT_PTR CALLBACK
  344. Mode_DlgProc(HWND hdlg, UINT wm, WPARAM wp, LPARAM lp)
  345. {
  346. switch (wm) {
  347. case WM_INITDIALOG: return Mode_OnInitDialog(hdlg, lp);
  348. case WM_COMMAND:
  349. return Mode_OnCommand(hdlg,
  350. (int)GET_WM_COMMAND_ID(wp, lp),
  351. (UINT)GET_WM_COMMAND_CMD(wp, lp));
  352. }
  353. return 0;
  354. }