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.

347 lines
7.8 KiB

  1. /*++
  2. Copyright (c) 1994-1998, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. mouse.c
  5. Abstract:
  6. This module contains the main routines for the Mouse applet.
  7. Revision History:
  8. --*/
  9. //
  10. // Include Files.
  11. //
  12. #include "main.h"
  13. #include "rc.h"
  14. #include "applet.h"
  15. #include <regstr.h>
  16. #include <cplext.h>
  17. #include "util.h"
  18. //
  19. // Constant Declarations.
  20. //
  21. #define MAX_PAGES 32
  22. const HWPAGEINFO c_hpiMouse = {
  23. // Mouse device class
  24. { 0x4d36e96fL, 0xe325, 0x11ce, { 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } },
  25. // Mouse troubleshooter command line
  26. IDS_MOUSE_TSHOOT,
  27. };
  28. //
  29. // Global Variables.
  30. //
  31. //
  32. // Location of prop sheet hooks in the registry.
  33. //
  34. static const TCHAR sc_szRegMouse[] = REGSTR_PATH_CONTROLSFOLDER TEXT("\\Mouse");
  35. //
  36. // Function Prototypes.
  37. //
  38. INT_PTR CALLBACK
  39. MouseButDlg(
  40. HWND hDlg,
  41. UINT message,
  42. WPARAM wParam,
  43. LPARAM lParam);
  44. INT_PTR CALLBACK
  45. MousePtrDlg(
  46. HWND hwnd,
  47. UINT msg,
  48. WPARAM wParam,
  49. LPARAM lParam);
  50. INT_PTR CALLBACK
  51. MouseMovDlg(
  52. HWND hDlg,
  53. UINT message,
  54. WPARAM wParam,
  55. LPARAM lParam);
  56. /*
  57. INT_PTR CALLBACK
  58. MouseActivitiesDlg(
  59. HWND hDlg,
  60. UINT message,
  61. WPARAM wParam,
  62. LPARAM lParam);
  63. */
  64. INT_PTR CALLBACK
  65. MouseWheelDlg(
  66. HWND hDlg,
  67. UINT message,
  68. WPARAM wParam,
  69. LPARAM lParam);
  70. static int
  71. GetClInt( const TCHAR *p );
  72. ////////////////////////////////////////////////////////////////////////////
  73. //
  74. // _AddMousePropSheetPage
  75. //
  76. // Adds a property sheet page.
  77. //
  78. ////////////////////////////////////////////////////////////////////////////
  79. BOOL CALLBACK _AddMousePropSheetPage(
  80. HPROPSHEETPAGE hpage,
  81. LPARAM lParam)
  82. {
  83. PROPSHEETHEADER *ppsh = (PROPSHEETHEADER *)lParam;
  84. if (hpage && (ppsh->nPages < MAX_PAGES))
  85. {
  86. ppsh->phpage[ppsh->nPages++] = hpage;
  87. return (TRUE);
  88. }
  89. return (FALSE);
  90. }
  91. ////////////////////////////////////////////////////////////////////////////
  92. //
  93. // MouseApplet
  94. //
  95. ////////////////////////////////////////////////////////////////////////////
  96. int MouseApplet(
  97. HINSTANCE instance,
  98. HWND parent,
  99. LPCTSTR cmdline)
  100. {
  101. HPROPSHEETPAGE rPages[MAX_PAGES];
  102. PROPSHEETPAGE psp;
  103. PROPSHEETHEADER psh;
  104. HPSXA hpsxa;
  105. int Result;
  106. //
  107. // Make the initial page.
  108. //
  109. psh.dwSize = sizeof(psh);
  110. psh.dwFlags = PSH_PROPTITLE;
  111. psh.hwndParent = parent;
  112. psh.hInstance = instance;
  113. psh.pszCaption = MAKEINTRESOURCE(IDS_MOUSE_TITLE);
  114. psh.nPages = 0;
  115. psh.nStartPage = ( ( cmdline && *cmdline )? GetClInt( cmdline ) : 0 );
  116. psh.phpage = rPages;
  117. //
  118. // Load any installed extensions.
  119. //
  120. hpsxa = SHCreatePropSheetExtArray(HKEY_LOCAL_MACHINE, sc_szRegMouse, 8);
  121. //
  122. // Add the Buttons page, giving the extensions a chance to replace it.
  123. //
  124. if (!hpsxa ||
  125. !SHReplaceFromPropSheetExtArray( hpsxa,
  126. CPLPAGE_MOUSE_BUTTONS,
  127. _AddMousePropSheetPage,
  128. (LPARAM)&psh ))
  129. {
  130. psp.dwSize = sizeof(psp);
  131. psp.dwFlags = PSP_DEFAULT;
  132. psp.hInstance = instance;
  133. psp.pszTemplate = MAKEINTRESOURCE(DLG_MOUSE_BUTTONS);
  134. psp.pfnDlgProc = MouseButDlg;
  135. psp.lParam = 0;
  136. _AddMousePropSheetPage(CreatePropertySheetPage(&psp), (LPARAM)&psh);
  137. }
  138. //
  139. // Add the Pointers page (not replaceable).
  140. //
  141. psp.dwSize = sizeof(psp);
  142. psp.dwFlags = PSP_DEFAULT;
  143. psp.hInstance = instance;
  144. psp.pszTemplate = MAKEINTRESOURCE(DLG_MOUSE_POINTER);
  145. psp.pfnDlgProc = MousePtrDlg;
  146. psp.lParam = 0;
  147. _AddMousePropSheetPage(CreatePropertySheetPage(&psp), (LPARAM)&psh);
  148. //
  149. // Add the Motion page, giving the extensions a chance to replace it.
  150. //
  151. if (!hpsxa ||
  152. !SHReplaceFromPropSheetExtArray( hpsxa,
  153. CPLPAGE_MOUSE_PTRMOTION,
  154. _AddMousePropSheetPage,
  155. (LPARAM)&psh ))
  156. {
  157. psp.dwSize = sizeof(psp);
  158. psp.dwFlags = PSP_DEFAULT;
  159. psp.hInstance = instance;
  160. psp.pszTemplate = MAKEINTRESOURCE(DLG_MOUSE_MOTION);
  161. psp.pfnDlgProc = MouseMovDlg;
  162. psp.lParam = 0;
  163. _AddMousePropSheetPage(CreatePropertySheetPage(&psp), (LPARAM)&psh);
  164. }
  165. /*
  166. /* Not added due to lack of time. ewatson (05/05/2000)
  167. //
  168. // Add the Activities page, giving the extensions a chance to replace it.
  169. //
  170. if (!hpsxa ||
  171. !SHReplaceFromPropSheetExtArray( hpsxa,
  172. CPLPAGE_MOUSE_ACTIVITIES,
  173. _AddMousePropSheetPage,
  174. (LPARAM)&psh ))
  175. {
  176. psp.dwSize = sizeof(psp);
  177. psp.dwFlags = PSP_DEFAULT;
  178. psp.hInstance = instance;
  179. psp.pszTemplate = MAKEINTRESOURCE(DLG_MOUSE_ACTIVITIES);
  180. psp.pfnDlgProc = MouseActivitiesDlg;
  181. psp.lParam = 0;
  182. _AddMousePropSheetPage(CreatePropertySheetPage(&psp), (LPARAM)&psh);
  183. }
  184. */
  185. //
  186. // Add the Wheel page (if mouse with wheel is present)
  187. // This page is replace-able.
  188. //
  189. if (!hpsxa ||
  190. !SHReplaceFromPropSheetExtArray( hpsxa,
  191. CPLPAGE_MOUSE_WHEEL,
  192. _AddMousePropSheetPage,
  193. (LPARAM)&psh ))
  194. {
  195. //
  196. //If a Wheel mouse is present on the system, then display the Wheel property sheet page
  197. //
  198. if (GetSystemMetrics(SM_MOUSEWHEELPRESENT))
  199. {
  200. psp.dwSize = sizeof(psp);
  201. psp.dwFlags = PSP_DEFAULT;
  202. psp.hInstance = instance;
  203. psp.pszTemplate = MAKEINTRESOURCE(DLG_MOUSE_WHEEL);
  204. psp.pfnDlgProc = MouseWheelDlg;
  205. psp.lParam = 0;
  206. _AddMousePropSheetPage(CreatePropertySheetPage(&psp), (LPARAM)&psh);
  207. }
  208. }
  209. _AddMousePropSheetPage(CreateHardwarePage(&c_hpiMouse), (LPARAM)&psh);
  210. //
  211. // Add any extra pages that the extensions want in there.
  212. //
  213. if (hpsxa)
  214. {
  215. UINT cutoff = psh.nPages;
  216. UINT added = SHAddFromPropSheetExtArray( hpsxa,
  217. _AddMousePropSheetPage,
  218. (LPARAM)&psh );
  219. if (psh.nStartPage >= cutoff)
  220. {
  221. psh.nStartPage += added;
  222. }
  223. }
  224. //
  225. // Invoke the Property Sheets.
  226. //
  227. switch (PropertySheet(&psh))
  228. {
  229. case ( ID_PSRESTARTWINDOWS ) :
  230. {
  231. Result = APPLET_RESTART;
  232. break;
  233. }
  234. case ( ID_PSREBOOTSYSTEM ) :
  235. {
  236. Result = APPLET_REBOOT;
  237. break;
  238. }
  239. default :
  240. {
  241. Result = 0;
  242. break;
  243. }
  244. }
  245. //
  246. // Free any loaded extensions.
  247. //
  248. if (hpsxa)
  249. {
  250. SHDestroyPropSheetExtArray(hpsxa);
  251. }
  252. return (Result);
  253. }
  254. ////////////////////////////////////////////////////////////////////////////
  255. //
  256. // GetClInt to determine command line argument.
  257. //
  258. ////////////////////////////////////////////////////////////////////////////
  259. static int
  260. GetClInt( const TCHAR *p )
  261. {
  262. BOOL neg = FALSE;
  263. int v = 0;
  264. while( *p == TEXT(' ') )
  265. p++; // skip spaces
  266. if( *p == TEXT('-') ) // is it negative?
  267. {
  268. neg = TRUE; // yes, remember that
  269. p++; // skip '-' char
  270. }
  271. // parse the absolute portion
  272. while( ( *p >= TEXT('0') ) && ( *p <= TEXT('9') ) ) // digits only
  273. v = v * 10 + *p++ - TEXT('0'); // accumulate the value
  274. return ( neg? -v : v ); // return the result
  275. }