Leaked source code of windows server 2003
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.

406 lines
11 KiB

  1. /*++
  2. Copyright (c) 1994-1998, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. mousewhl.c
  5. Abstract:
  6. This module contains the routines for the Mouse Wheel 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. #ifndef ARRAYSIZE
  18. #define ARRAYSIZE(x) (sizeof(x)/sizeof((x)[0]))
  19. #endif
  20. //
  21. // Constant Declarations.
  22. //
  23. #define SCROLL_DEFAULT 3
  24. #define MIN_SCROLL_LINES 1
  25. #define MAX_SCROLL_LINES 100
  26. #define MAX_CHARS_FOR_SCROLL_LINES 3
  27. #ifndef UINT_MAX
  28. #define UINT_MAX ((UINT)-1)
  29. #endif
  30. //
  31. // Typedef Declarations.
  32. //
  33. //
  34. // Dialog Data.
  35. //
  36. typedef struct tag_MouseGenStr
  37. {
  38. UINT nOrigScrollLines; //If this is WHEEL_PAGESCROLL, then we scroll one Page at a time.
  39. HWND hDlg;
  40. } MOUSEWHLSTR, *PMOUSEWHLSTR, *LPMOUSEWHLSTR;
  41. //
  42. // Context Help Ids.
  43. //
  44. const DWORD aMouseWheelHelpIds[] =
  45. {
  46. IDC_GROUPBOX_1, IDH_COMM_GROUPBOX,
  47. IDRAD_SCROLL_LINES, IDH_MOUSE_WHEEL_SCROLLING,
  48. IDRAD_SCROLL_PAGE, IDH_MOUSE_WHEEL_SCROLLING,
  49. IDC_SPIN_SCROLL_LINES, IDH_MOUSE_WHEEL_SCROLLING,
  50. IDT_SCROLL_FEATURE_TXT, IDH_MOUSE_WHEEL_SCROLLING,
  51. IDE_BUDDY_SCROLL_LINES, IDH_MOUSE_WHEEL_SCROLLING,
  52. 0,0
  53. };
  54. ////////////////////////////////////////////////////////////////////////////
  55. //
  56. // EnableMouseWheelDlgControls
  57. //
  58. ////////////////////////////////////////////////////////////////////////////
  59. void EnableMouseWheelDlgControls(HWND hDlg, BOOL bEnable)
  60. {
  61. static const UINT rgidCtl[] = {
  62. IDE_BUDDY_SCROLL_LINES,
  63. IDC_SPIN_SCROLL_LINES,
  64. };
  65. int i;
  66. for (i = 0; i < ARRAYSIZE(rgidCtl); i++)
  67. {
  68. HWND hwnd = GetDlgItem(hDlg, rgidCtl[i]);
  69. if (NULL != hwnd)
  70. {
  71. EnableWindow(hwnd, bEnable);
  72. }
  73. }
  74. }
  75. ////////////////////////////////////////////////////////////////////////////
  76. //
  77. // SetScrollWheelLines
  78. //
  79. ////////////////////////////////////////////////////////////////////////////
  80. void SetScrollWheelLines(HWND hDlg, BOOL bSaveSettings)
  81. {
  82. UINT uNumLines = SCROLL_DEFAULT;
  83. UINT uiSaveFlag = (bSaveSettings) ? SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE : FALSE;
  84. if (IsDlgButtonChecked(hDlg, IDRAD_SCROLL_LINES))
  85. {
  86. //Scrolling n Lines at a time
  87. BOOL fTranslated = FALSE; // numeric conversion successful
  88. // Retrieve number of scroll-lines from edit control.
  89. uNumLines = GetDlgItemInt(hDlg, IDE_BUDDY_SCROLL_LINES,
  90. &fTranslated, FALSE);
  91. if (!fTranslated)
  92. {
  93. uNumLines = SCROLL_DEFAULT;
  94. }
  95. }
  96. else
  97. {
  98. //Scrolling a page at a time
  99. uNumLines = WHEEL_PAGESCROLL;
  100. }
  101. SystemParametersInfo( SPI_SETWHEELSCROLLLINES,
  102. uNumLines,
  103. NULL,
  104. uiSaveFlag);
  105. }
  106. ////////////////////////////////////////////////////////////////////////////
  107. //
  108. // DestroyMouseWheelDlg
  109. //
  110. ////////////////////////////////////////////////////////////////////////////
  111. void DestroyMouseWheelDlg(
  112. PMOUSEWHLSTR pMstr)
  113. {
  114. HWND hDlg = NULL;
  115. if( pMstr )
  116. {
  117. hDlg = pMstr->hDlg;
  118. LocalFree( (HGLOBAL)pMstr );
  119. SetWindowLongPtr( hDlg, DWLP_USER, 0 );
  120. }
  121. }
  122. ////////////////////////////////////////////////////////////////////////////
  123. //
  124. // InitMouseWheelDlg
  125. //
  126. ////////////////////////////////////////////////////////////////////////////
  127. void InitMouseWheelDlg(
  128. HWND hDlg)
  129. {
  130. PMOUSEWHLSTR pMstr = NULL;
  131. HWND hWndBuddy = NULL;
  132. UINT nScrollLines = SCROLL_DEFAULT;
  133. pMstr = (PMOUSEWHLSTR)LocalAlloc(LPTR, sizeof(MOUSEWHLSTR));
  134. if (pMstr == NULL)
  135. {
  136. return;
  137. }
  138. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)pMstr);
  139. pMstr->hDlg = hDlg;
  140. //////////////////////
  141. SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &nScrollLines, 0);
  142. if (nScrollLines < MIN_SCROLL_LINES)
  143. {
  144. nScrollLines = SCROLL_DEFAULT;
  145. }
  146. pMstr->nOrigScrollLines = nScrollLines;
  147. //Set the buddy window
  148. hWndBuddy = GetDlgItem (hDlg, IDE_BUDDY_SCROLL_LINES);
  149. SendDlgItemMessage (hDlg, IDC_SPIN_SCROLL_LINES, UDM_SETBUDDY,
  150. (WPARAM)hWndBuddy, 0L);
  151. //Set the range. The maximum range is UINT_MAX for the scroll-lines feature
  152. //but the up-down control can only accept a max value of UD_MAXVAL. Therefore,
  153. //the scroll-lines feature will only have a setting of UINT_MAX when user
  154. //explicitly specifies to scroll one page at a time.
  155. SendDlgItemMessage (hDlg, IDC_SPIN_SCROLL_LINES, UDM_SETRANGE, 0L,
  156. MAKELONG(MAX_SCROLL_LINES, MIN_SCROLL_LINES));
  157. //Initialize appropriate scroll-line controls depending on value of
  158. //scroll-lines setting.
  159. if (nScrollLines > MAX_SCROLL_LINES)
  160. {
  161. EnableMouseWheelDlgControls(hDlg, FALSE);
  162. SetDlgItemInt (hDlg, IDE_BUDDY_SCROLL_LINES, SCROLL_DEFAULT, FALSE);
  163. CheckRadioButton (hDlg, IDRAD_SCROLL_LINES, IDRAD_SCROLL_PAGE, IDRAD_SCROLL_PAGE);
  164. }
  165. else
  166. {
  167. //Display current value in edit control
  168. SetDlgItemInt (hDlg, IDE_BUDDY_SCROLL_LINES, nScrollLines, FALSE);
  169. //Check scroll-lines or scroll-page button
  170. CheckRadioButton (hDlg, IDRAD_SCROLL_LINES, IDRAD_SCROLL_PAGE, IDRAD_SCROLL_LINES);
  171. }
  172. Edit_LimitText (GetDlgItem (hDlg, IDE_BUDDY_SCROLL_LINES),
  173. MAX_CHARS_FOR_SCROLL_LINES);
  174. }
  175. ////////////////////////////////////////////////////////////////////////////
  176. //
  177. // MouseWheelDlg
  178. //
  179. ////////////////////////////////////////////////////////////////////////////
  180. INT_PTR CALLBACK MouseWheelDlg(
  181. HWND hDlg,
  182. UINT message,
  183. WPARAM wParam,
  184. LPARAM lParam)
  185. {
  186. PMOUSEWHLSTR pMstr = NULL;
  187. BOOL bRet = FALSE;
  188. pMstr = (PMOUSEWHLSTR)GetWindowLongPtr(hDlg, DWLP_USER);
  189. switch (message)
  190. {
  191. case ( WM_INITDIALOG ) :
  192. {
  193. InitMouseWheelDlg(hDlg);
  194. break;
  195. }
  196. case ( WM_DESTROY ) :
  197. {
  198. DestroyMouseWheelDlg(pMstr);
  199. break;
  200. }
  201. case WM_VSCROLL:
  202. {
  203. SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0L);
  204. break;
  205. }
  206. case ( WM_COMMAND ) :
  207. {
  208. switch (LOWORD(wParam))
  209. {
  210. case IDRAD_SCROLL_LINES:
  211. case IDRAD_SCROLL_PAGE :
  212. {
  213. UINT code = HIWORD(wParam);
  214. if (code == BN_CLICKED)
  215. {
  216. EnableMouseWheelDlgControls(hDlg, IsDlgButtonChecked(hDlg, IDRAD_SCROLL_LINES) );
  217. // Set the property
  218. SetScrollWheelLines(hDlg, FALSE);
  219. SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0L);
  220. }
  221. break;
  222. }
  223. case IDE_BUDDY_SCROLL_LINES:
  224. {
  225. UINT code = HIWORD(wParam);
  226. if (code == EN_UPDATE)
  227. {
  228. BOOL fTranslated = FALSE; // numeric conversion successful
  229. // Retrieve number of scroll-lines from edit control.
  230. UINT uNumLines = GetDlgItemInt(hDlg, IDE_BUDDY_SCROLL_LINES,
  231. &fTranslated, FALSE);
  232. if (fTranslated) // valid number converted from text
  233. {
  234. if (uNumLines >= MIN_SCROLL_LINES &&
  235. uNumLines <= MAX_SCROLL_LINES)
  236. { // spin-control range
  237. if (uNumLines != pMstr->nOrigScrollLines) // different value
  238. {
  239. // Set the property
  240. SetScrollWheelLines(hDlg, FALSE);
  241. SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0L);
  242. }
  243. }
  244. else // value out of range
  245. {
  246. fTranslated = FALSE; // discard value
  247. }
  248. }
  249. if (!fTranslated && // invalid (non-numeric) data
  250. // or out of range numeric value
  251. pMstr) //and the Window has been initialized.
  252. {
  253. SetDlgItemInt (hDlg, IDE_BUDDY_SCROLL_LINES,
  254. pMstr->nOrigScrollLines, FALSE); // unsigned
  255. //MessageBeep (0xFFFFFFFF); // chastise user
  256. }
  257. }
  258. }
  259. }//switch
  260. break;
  261. } //WM_COMMAND
  262. case ( WM_NOTIFY ) :
  263. {
  264. ASSERT (lParam);
  265. switch (((NMHDR *)lParam)->code)
  266. {
  267. case ( PSN_APPLY ) :
  268. {
  269. SetScrollWheelLines(hDlg, TRUE);
  270. break;
  271. }
  272. case ( PSN_RESET ) :
  273. {
  274. //
  275. // Restore the original
  276. //
  277. SystemParametersInfo( SPI_SETWHEELSCROLLLINES,
  278. pMstr->nOrigScrollLines,
  279. NULL,
  280. FALSE);
  281. break;
  282. }
  283. default :
  284. {
  285. return (FALSE);
  286. }
  287. }
  288. break;
  289. }
  290. case ( WM_HELP ) : // F1
  291. {
  292. WinHelp( (HWND)((LPHELPINFO)lParam)->hItemHandle,
  293. HELP_FILE,
  294. HELP_WM_HELP,
  295. (DWORD_PTR)(LPTSTR)aMouseWheelHelpIds );
  296. break;
  297. }
  298. case ( WM_CONTEXTMENU ) : // right mouse click
  299. {
  300. WinHelp( (HWND)wParam,
  301. HELP_FILE,
  302. HELP_CONTEXTMENU,
  303. (DWORD_PTR)(LPTSTR)aMouseWheelHelpIds );
  304. break;
  305. }
  306. case ( WM_DISPLAYCHANGE ) :
  307. case ( WM_WININICHANGE ) :
  308. case ( WM_SYSCOLORCHANGE ) :
  309. {
  310. SHPropagateMessage(hDlg, message, wParam, lParam, TRUE);
  311. return TRUE;
  312. }
  313. default :
  314. {
  315. return (FALSE);
  316. }
  317. }
  318. return (TRUE);
  319. }