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.

672 lines
19 KiB

  1. /*++
  2. Copyright (c) 1994-1998, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. mousemov.c
  5. Abstract:
  6. This module contains the routines for the Mouse Pointer Property Sheet
  7. page.
  8. Revision History:
  9. --*/
  10. //
  11. // Include Files.
  12. //
  13. #include "main.h"
  14. #include "util.h"
  15. #include "rc.h"
  16. #include "mousehlp.h"
  17. //
  18. // Constant Declarations.
  19. //
  20. #ifdef WINNT // NT does not currently support Mouse Trails
  21. #define NO_MOUSETRAILS 1
  22. #endif
  23. #define ACCELMIN 0
  24. #define ACCELMAX (ACCELMIN + 6) // range of 7 settings
  25. #define TRAILMIN 2
  26. #define TRAILMAX (TRAILMIN + 5) // range of 8 settings
  27. //
  28. // From shell\inc\shsemip.h
  29. //
  30. #define Assert(f)
  31. //
  32. // Typedef Declarations.
  33. //
  34. //
  35. // Struct for SPI_GETMOUSE.
  36. //
  37. typedef struct tag_GetMouse
  38. {
  39. int Thresh1;
  40. int Thresh2;
  41. int Speed;
  42. } GETMOUSE, *LPGETMOUSE;
  43. //
  44. // Dialog Data.
  45. //
  46. typedef struct tag_MouseGenStr
  47. {
  48. GETMOUSE gmOrig;
  49. GETMOUSE gmNew;
  50. short nSpeed;
  51. short nOrigSpeed;
  52. int nSensitivity;
  53. int nOrigSensitivity;
  54. #ifndef NO_MOUSETRAILS // Mouse Trails are not implemented on NT
  55. short nTrailSize;
  56. short nOrigTrailSize;
  57. HWND hWndTrailScroll;
  58. #endif
  59. BOOL fOrigSnapTo;
  60. HWND hWndSpeedScroll;
  61. HWND hDlg;
  62. } MOUSEPTRSTR, *PMOUSEPTRSTR, *LPMOUSEPTRSTR;
  63. //
  64. // Context Help Ids.
  65. //
  66. const DWORD aMouseMoveHelpIds[] =
  67. {
  68. IDC_GROUPBOX_1, IDH_DLGMOUSE_POINTMO,
  69. IDC_GROUPBOX_2, IDH_COMM_GROUPBOX,
  70. MOUSE_SPEEDBMP, NO_HELP,
  71. MOUSE_SPEEDSCROLL, IDH_DLGMOUSE_POINTMO,
  72. IDC_GROUPBOX_3, IDH_DLGMOUSE_ACCELERATION,
  73. MOUSE_ACCELNONE, IDH_DLGMOUSE_ACCELERATION,
  74. MOUSE_ACCELLOW, IDH_DLGMOUSE_ACCELERATION,
  75. MOUSE_ACCELMEDIUM, IDH_DLGMOUSE_ACCELERATION,
  76. MOUSE_ACCELHIGH, IDH_DLGMOUSE_ACCELERATION,
  77. MOUSE_PTRTRAIL, NO_HELP,
  78. MOUSE_TRAILS, IDH_DLGMOUSE_SHOWTRAIL,
  79. MOUSE_TRAILSCROLLTXT1, IDH_DLGMOUSE_TRAILLENGTH,
  80. MOUSE_TRAILSCROLLTXT2, IDH_DLGMOUSE_TRAILLENGTH,
  81. MOUSE_TRAILSCROLL, IDH_DLGMOUSE_TRAILLENGTH,
  82. MOUSE_PTRSNAPDEF, NO_HELP,
  83. IDC_GROUPBOX_4, IDH_DLGMOUSE_SNAPDEF,
  84. MOUSE_SNAPDEF, IDH_DLGMOUSE_SNAPDEF,
  85. 0, 0
  86. };
  87. ////////////////////////////////////////////////////////////////////////////
  88. //
  89. // DestroyMousePtrDlg
  90. //
  91. ////////////////////////////////////////////////////////////////////////////
  92. void DestroyMousePtrDlg(
  93. PMOUSEPTRSTR pMstr)
  94. {
  95. HWND hDlg;
  96. Assert( pMstr )
  97. if( pMstr )
  98. {
  99. hDlg = pMstr->hDlg;
  100. LocalFree( (HGLOBAL)pMstr );
  101. SetWindowLongPtr( hDlg, DWLP_USER, 0 );
  102. }
  103. }
  104. ////////////////////////////////////////////////////////////////////////////
  105. //
  106. // EnableTrailScroll
  107. //
  108. ////////////////////////////////////////////////////////////////////////////
  109. #ifndef NO_MOUSETRAILS // Mouse Trails are not implemented on NT
  110. void EnableTrailScroll(
  111. HWND hDlg,
  112. BOOL val)
  113. {
  114. EnableWindow(GetDlgItem(hDlg, MOUSE_TRAILSCROLL), val);
  115. EnableWindow(GetDlgItem(hDlg, MOUSE_TRAILSCROLLTXT1), val);
  116. EnableWindow(GetDlgItem(hDlg, MOUSE_TRAILSCROLLTXT2), val);
  117. }
  118. #endif
  119. ////////////////////////////////////////////////////////////////////////////
  120. //
  121. // InitMousePtrDlg
  122. //
  123. ////////////////////////////////////////////////////////////////////////////
  124. BOOL InitMousePtrDlg(
  125. HWND hDlg)
  126. {
  127. PMOUSEPTRSTR pMstr;
  128. BOOL fSnapTo;
  129. pMstr = (PMOUSEPTRSTR)LocalAlloc(LPTR, sizeof(MOUSEPTRSTR));
  130. if (pMstr == NULL)
  131. {
  132. return (TRUE);
  133. }
  134. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)pMstr);
  135. pMstr->hDlg = hDlg;
  136. #ifndef NO_MOUSETRAILS // Mouse trails are not implemented on NT
  137. //
  138. // Enable or disable the Mouse Trails Checkbutton.
  139. //
  140. if (SystemParametersInfo(SPI_GETMOUSETRAILS, 0, &pMstr->nTrailSize, 0))
  141. {
  142. pMstr->nOrigTrailSize = pMstr->nTrailSize;
  143. EnableWindow(GetDlgItem(hDlg,MOUSE_TRAILS), TRUE);
  144. SendDlgItemMessage( hDlg,
  145. MOUSE_TRAILSCROLL,
  146. TBM_SETRANGE,
  147. 0,
  148. MAKELONG(TRAILMIN, TRAILMAX) );
  149. CheckDlgButton(hDlg, MOUSE_TRAILS, (pMstr->nTrailSize > 1));
  150. if (pMstr->nTrailSize > 1)
  151. {
  152. SendDlgItemMessage( hDlg,
  153. MOUSE_TRAILSCROLL,
  154. TBM_SETPOS,
  155. TRUE,
  156. (LONG)pMstr->nTrailSize );
  157. }
  158. else
  159. {
  160. pMstr->nTrailSize = TRAILMAX;
  161. EnableTrailScroll(hDlg, FALSE);
  162. SendDlgItemMessage( hDlg,
  163. MOUSE_TRAILSCROLL,
  164. TBM_SETPOS,
  165. TRUE,
  166. (LONG)pMstr->nTrailSize );
  167. }
  168. }
  169. else
  170. {
  171. CheckDlgButton(hDlg, MOUSE_TRAILS, FALSE);
  172. EnableWindow(GetDlgItem(hDlg, MOUSE_TRAILS), FALSE);
  173. EnableTrailScroll(hDlg, FALSE);
  174. }
  175. #endif
  176. //
  177. // Enable or disable the Snap To Default Checkbutton
  178. //
  179. if (SystemParametersInfo(SPI_GETSNAPTODEFBUTTON, 0, (PVOID)&fSnapTo, FALSE))
  180. {
  181. pMstr->fOrigSnapTo = fSnapTo;
  182. }
  183. CheckDlgButton(hDlg, MOUSE_SNAPDEF, fSnapTo);
  184. SystemParametersInfo(SPI_GETMOUSE, 0, &pMstr->gmNew, FALSE);
  185. SystemParametersInfo(SPI_GETMOUSESPEED, 0, &pMstr->nOrigSensitivity, FALSE);
  186. if ((pMstr->nOrigSensitivity < 1) || (pMstr->nOrigSensitivity > 20))
  187. {
  188. pMstr->nOrigSensitivity = 10;
  189. }
  190. pMstr->nSensitivity = pMstr->nOrigSensitivity;
  191. pMstr->gmOrig.Thresh1 = pMstr->gmNew.Thresh1;
  192. pMstr->gmOrig.Thresh2 = pMstr->gmNew.Thresh2;
  193. pMstr->gmOrig.Speed = pMstr->gmNew.Speed;
  194. if (pMstr->gmOrig.Speed == 0)
  195. {
  196. CheckRadioButton(hDlg, MOUSE_ACCELNONE, MOUSE_ACCELHIGH, MOUSE_ACCELNONE);
  197. }
  198. else if (pMstr->gmOrig.Speed == 1)
  199. {
  200. CheckRadioButton(hDlg, MOUSE_ACCELNONE, MOUSE_ACCELHIGH, MOUSE_ACCELLOW);
  201. }
  202. else if ((pMstr->gmOrig.Speed == 2) && (pMstr->gmOrig.Thresh2 >= 9))
  203. {
  204. CheckRadioButton(hDlg, MOUSE_ACCELNONE, MOUSE_ACCELHIGH, MOUSE_ACCELMEDIUM);
  205. }
  206. else
  207. {
  208. CheckRadioButton(hDlg, MOUSE_ACCELNONE, MOUSE_ACCELHIGH, MOUSE_ACCELHIGH);
  209. }
  210. #ifndef NO_MOUSETRAILS // Mouse Trails are not implemented on NT
  211. pMstr->hWndTrailScroll = GetDlgItem(hDlg, MOUSE_TRAILSCROLL);
  212. #endif
  213. pMstr->hWndSpeedScroll = GetDlgItem(hDlg, MOUSE_SPEEDSCROLL);
  214. //
  215. // 0 Acc = 4
  216. // 1 Acc, 5 xThreshold = 5
  217. // 1 Acc, 4 xThreshold = 6
  218. // 1 Acc, 3 xThreshold = 7
  219. // 1 Acc, 2 xThreshold = 8
  220. // 1 Acc, 1 xThreshold = 9
  221. // 2 Acc, 5 xThreshold = 10
  222. // 2 Acc, 4 xThreshold = 11
  223. // 2 Acc, 3 xThreshold = 12
  224. // 2 Acc, 2 xThreshold = 13
  225. //
  226. pMstr->nOrigSpeed = pMstr->nSpeed = ACCELMIN;
  227. if (pMstr->gmNew.Speed == 2)
  228. {
  229. pMstr->nSpeed += (24 - pMstr->gmNew.Thresh2) / 3;
  230. }
  231. else if (pMstr->gmNew.Speed == 1)
  232. {
  233. pMstr->nSpeed += (13 - pMstr->gmNew.Thresh1) / 3;
  234. }
  235. pMstr->nOrigSpeed = pMstr->nSpeed;
  236. SendDlgItemMessage( hDlg,
  237. MOUSE_SPEEDSCROLL,
  238. TBM_SETRANGE,
  239. 0,
  240. MAKELONG(0, 10) );
  241. SendDlgItemMessage( hDlg,
  242. MOUSE_SPEEDSCROLL,
  243. TBM_SETPOS,
  244. TRUE,
  245. (LONG)pMstr->nOrigSensitivity / 2 );
  246. return (TRUE);
  247. }
  248. ////////////////////////////////////////////////////////////////////////////
  249. //
  250. // TrailScroll
  251. //
  252. ////////////////////////////////////////////////////////////////////////////
  253. #ifndef NO_MOUSETRAILS
  254. void TrailScroll(
  255. WPARAM wParam,
  256. LPARAM lParam,
  257. PMOUSEPTRSTR pMstr)
  258. {
  259. pMstr->nTrailSize = (int)SendMessage((HWND)lParam, TBM_GETPOS, 0, 0L);
  260. SystemParametersInfo(SPI_SETMOUSETRAILS, pMstr->nTrailSize, 0, 0);
  261. }
  262. #endif
  263. ////////////////////////////////////////////////////////////////////////////
  264. //
  265. // SpeedScroll
  266. //
  267. ////////////////////////////////////////////////////////////////////////////
  268. void SpeedScroll(
  269. WPARAM wParam,
  270. LPARAM lParam,
  271. PMOUSEPTRSTR pMstr)
  272. {
  273. pMstr->nSensitivity = (int)SendMessage((HWND)lParam, TBM_GETPOS, 0, 0L) * 2;
  274. if (!pMstr->nSensitivity)
  275. {
  276. pMstr->nSensitivity = 1;
  277. }
  278. //
  279. // Update speed when they let go of the thumb.
  280. //
  281. if (LOWORD(wParam) == SB_ENDSCROLL)
  282. {
  283. SystemParametersInfo( SPI_SETMOUSESPEED,
  284. 0,
  285. (PVOID)pMstr->nSensitivity,
  286. SPIF_SENDCHANGE );
  287. }
  288. }
  289. ////////////////////////////////////////////////////////////////////////////
  290. //
  291. // MouseMovDlg
  292. //
  293. ////////////////////////////////////////////////////////////////////////////
  294. INT_PTR CALLBACK MouseMovDlg(
  295. HWND hDlg,
  296. UINT message,
  297. WPARAM wParam,
  298. LPARAM lParam)
  299. {
  300. PMOUSEPTRSTR pMstr;
  301. BOOL bRet;
  302. BOOL fSnapTo;
  303. pMstr = (PMOUSEPTRSTR)GetWindowLongPtr(hDlg, DWLP_USER);
  304. switch (message)
  305. {
  306. case ( WM_INITDIALOG ) :
  307. {
  308. bRet = InitMousePtrDlg(hDlg);
  309. break;
  310. }
  311. case ( WM_DESTROY ) :
  312. {
  313. DestroyMousePtrDlg(pMstr);
  314. break;
  315. }
  316. case ( WM_HSCROLL ) :
  317. {
  318. SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0L);
  319. if ((HWND)lParam == pMstr->hWndSpeedScroll)
  320. {
  321. SpeedScroll(wParam, lParam, pMstr);
  322. }
  323. #ifndef NO_MOUSETRAILS // Mouse Trails are not implemented on NT
  324. else if ((HWND)lParam == pMstr->hWndTrailScroll)
  325. {
  326. TrailScroll(wParam, lParam, pMstr);
  327. }
  328. #endif
  329. break;
  330. }
  331. case ( WM_COMMAND ) :
  332. {
  333. switch (LOWORD(wParam))
  334. {
  335. #ifndef NO_MOUSETRAILS // Mouse Trails are not implemented on NT
  336. case ( MOUSE_TRAILS ) :
  337. {
  338. if (IsDlgButtonChecked(hDlg, MOUSE_TRAILS))
  339. {
  340. EnableTrailScroll(hDlg, TRUE);
  341. pMstr->nTrailSize =
  342. (int)SendMessage( pMstr->hWndTrailScroll,
  343. TBM_GETPOS,
  344. 0,
  345. 0 );
  346. SystemParametersInfo( SPI_SETMOUSETRAILS,
  347. pMstr->nTrailSize,
  348. 0,
  349. 0 );
  350. }
  351. else
  352. {
  353. EnableTrailScroll(hDlg, FALSE);
  354. SystemParametersInfo(SPI_SETMOUSETRAILS, 0, 0, 0);
  355. }
  356. SendMessage( GetParent(hDlg),
  357. PSM_CHANGED,
  358. (WPARAM)hDlg,
  359. 0L );
  360. break;
  361. }
  362. #endif
  363. case ( MOUSE_SNAPDEF ) :
  364. {
  365. SystemParametersInfo( SPI_SETSNAPTODEFBUTTON,
  366. IsDlgButtonChecked(hDlg, MOUSE_SNAPDEF),
  367. 0,
  368. FALSE );
  369. SendMessage( GetParent(hDlg),
  370. PSM_CHANGED,
  371. (WPARAM)hDlg,
  372. 0L );
  373. break;
  374. }
  375. case ( MOUSE_ACCELNONE ) :
  376. {
  377. pMstr->gmNew.Speed = 0;
  378. pMstr->gmNew.Thresh1 = 0;
  379. pMstr->gmNew.Thresh2 = 0;
  380. SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0L);
  381. SystemParametersInfo(SPI_SETMOUSE, 0, &pMstr->gmNew, FALSE);
  382. break;
  383. }
  384. case ( MOUSE_ACCELLOW ) :
  385. {
  386. pMstr->gmNew.Speed = 1;
  387. pMstr->gmNew.Thresh1 = 7;
  388. pMstr->gmNew.Thresh2 = 0;
  389. SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0L);
  390. SystemParametersInfo(SPI_SETMOUSE, 0, &pMstr->gmNew, FALSE);
  391. break;
  392. }
  393. case ( MOUSE_ACCELMEDIUM ) :
  394. {
  395. pMstr->gmNew.Speed = 2;
  396. pMstr->gmNew.Thresh1 = 4;
  397. pMstr->gmNew.Thresh2 = 12;
  398. SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0L);
  399. SystemParametersInfo(SPI_SETMOUSE, 0, &pMstr->gmNew, FALSE);
  400. break;
  401. }
  402. case ( MOUSE_ACCELHIGH ) :
  403. {
  404. pMstr->gmNew.Speed = 2;
  405. pMstr->gmNew.Thresh1 = 4;
  406. pMstr->gmNew.Thresh2 = 6;
  407. SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0L);
  408. SystemParametersInfo(SPI_SETMOUSE, 0, &pMstr->gmNew, FALSE);
  409. break;
  410. }
  411. }
  412. break;
  413. }
  414. case ( WM_NOTIFY ) :
  415. {
  416. switch (((NMHDR *)lParam)->code)
  417. {
  418. case ( PSN_APPLY ) :
  419. {
  420. //
  421. // Change cursor to hour glass.
  422. //
  423. HourGlass(TRUE);
  424. #ifndef NO_MOUSETRAILS // Mouse Trails are not implemented on NT.
  425. //
  426. // Support mouse trails.
  427. //
  428. if (IsWindowEnabled(GetDlgItem(hDlg, MOUSE_TRAILS)))
  429. {
  430. if (IsDlgButtonChecked(hDlg, MOUSE_TRAILS))
  431. {
  432. SystemParametersInfo( SPI_SETMOUSETRAILS,
  433. pMstr->nTrailSize,
  434. 0,
  435. SPIF_UPDATEINIFILE |
  436. SPIF_SENDCHANGE );
  437. }
  438. else
  439. {
  440. SystemParametersInfo( SPI_SETMOUSETRAILS,
  441. 0,
  442. 0,
  443. SPIF_UPDATEINIFILE |
  444. SPIF_SENDCHANGE );
  445. pMstr->nTrailSize = 0;
  446. }
  447. //
  448. // New original once applied.
  449. //
  450. pMstr->nOrigTrailSize = pMstr->nTrailSize;
  451. }
  452. #endif
  453. //
  454. // Support snap to default.
  455. //
  456. if (IsWindowEnabled(GetDlgItem(hDlg, MOUSE_SNAPDEF)))
  457. {
  458. fSnapTo = IsDlgButtonChecked(hDlg, MOUSE_SNAPDEF);
  459. if (fSnapTo != pMstr->fOrigSnapTo)
  460. {
  461. SystemParametersInfo( SPI_SETSNAPTODEFBUTTON,
  462. fSnapTo,
  463. 0,
  464. SPIF_UPDATEINIFILE |
  465. SPIF_SENDCHANGE );
  466. }
  467. //
  468. // New original once applied.
  469. //
  470. pMstr->fOrigSnapTo = fSnapTo;
  471. }
  472. //
  473. // Apply mouse speed.
  474. //
  475. SystemParametersInfo( SPI_SETMOUSESPEED,
  476. 0,
  477. (PVOID)pMstr->nSensitivity,
  478. SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
  479. pMstr->nOrigSensitivity = pMstr->nSensitivity;
  480. //
  481. // Apply mouse acceleration.
  482. //
  483. SystemParametersInfo( SPI_SETMOUSE,
  484. 0,
  485. &pMstr->gmNew,
  486. SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
  487. pMstr->gmOrig = pMstr->gmNew;
  488. HourGlass(FALSE);
  489. break;
  490. }
  491. case ( PSN_RESET ) :
  492. {
  493. #ifndef NO_MOUSETRAILS // Mouse Trails are not implemented on NT
  494. //
  495. // Support mouse trails.
  496. //
  497. if (IsWindowEnabled(GetDlgItem(hDlg, MOUSE_TRAILS)))
  498. {
  499. pMstr->nTrailSize = pMstr->nOrigTrailSize;
  500. SystemParametersInfo( SPI_SETMOUSETRAILS,
  501. pMstr->nTrailSize,
  502. 0,
  503. 0 );
  504. }
  505. #endif
  506. //
  507. // Support snap to default.
  508. //
  509. if (IsWindowEnabled(GetDlgItem(hDlg, MOUSE_SNAPDEF)))
  510. {
  511. CheckDlgButton(hDlg, MOUSE_SNAPDEF, pMstr->fOrigSnapTo);
  512. SystemParametersInfo( SPI_SETSNAPTODEFBUTTON,
  513. pMstr->fOrigSnapTo,
  514. 0,
  515. 0 );
  516. }
  517. SystemParametersInfo( SPI_SETMOUSE,
  518. 0,
  519. &pMstr->gmOrig,
  520. FALSE );
  521. //
  522. // Restore the original mouse sensitivity.
  523. //
  524. SystemParametersInfo( SPI_SETMOUSESPEED,
  525. 0,
  526. (PVOID)pMstr->nOrigSensitivity,
  527. FALSE );
  528. break;
  529. }
  530. default :
  531. {
  532. return (FALSE);
  533. }
  534. }
  535. break;
  536. }
  537. case ( WM_HELP ) : // F1
  538. {
  539. WinHelp( (HWND)((LPHELPINFO)lParam)->hItemHandle,
  540. HELP_FILE,
  541. HELP_WM_HELP,
  542. (DWORD_PTR)(LPTSTR)aMouseMoveHelpIds );
  543. break;
  544. }
  545. case ( WM_CONTEXTMENU ) : // right mouse click
  546. {
  547. WinHelp( (HWND)wParam,
  548. HELP_FILE,
  549. HELP_CONTEXTMENU,
  550. (DWORD_PTR)(LPTSTR)aMouseMoveHelpIds );
  551. break;
  552. }
  553. case ( WM_DISPLAYCHANGE ) :
  554. case ( WM_WININICHANGE ) :
  555. case ( WM_SYSCOLORCHANGE ) :
  556. {
  557. SHPropagateMessage(hDlg, message, wParam, lParam, TRUE);
  558. return TRUE;
  559. }
  560. default :
  561. {
  562. return (FALSE);
  563. }
  564. }
  565. return (TRUE);
  566. }