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.

426 lines
14 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. mutohpen.c
  5. Abstract: Tablet PC Mutoh Pen Tablet Property Sheet module.
  6. Environment:
  7. User mode
  8. Author:
  9. Michael Tsang (MikeTs) 20-Apr-2000
  10. Revision History:
  11. --*/
  12. #include "pch.h"
  13. #ifdef PENPAGE
  14. #define CHANGED_SAMPLINGRATE 0x00000001
  15. #define CHANGED_SIDESW_MAP 0x00000002
  16. #define CHANGED_DIGITAL_FILTER 0x00000004
  17. #define CHANGED_GLITCH_FILTER 0x00000008
  18. #define CHANGED_PENTILTCAL 0x00000010
  19. #define CHANGED_LINEARCAL 0x00000020
  20. #define CHANGED_FEATURES (CHANGED_SAMPLINGRATE | \
  21. CHANGED_DIGITAL_FILTER | \
  22. CHANGED_GLITCH_FILTER)
  23. DWORD gdwfChanged = 0;
  24. PEN_SETTINGS PenSettings = {0, SWCOMBO_RCLICK};
  25. TCHAR gtszRateTextFormat[32];
  26. COMBOBOX_STRING SwitchComboStringTable[] =
  27. {
  28. SWCOMBO_NONE, IDS_SWCOMBO_NONE,
  29. SWCOMBO_RCLICK, IDS_SWCOMBO_RCLICK,
  30. 0, 0
  31. };
  32. DWORD gMutohPenHelpIDs[] =
  33. {
  34. IDC_SAMPLINGRATE, IDH_MUTOHPEN_SAMPLINGRATE,
  35. IDC_SIDE_SWITCH, IDH_MUTOHPEN_SIDE_SWITCH,
  36. IDC_ENABLE_DIGITALFILTER, IDH_MUTOHPEN_ENABLE_DIGITALFILTER,
  37. IDC_ENABLE_GLITCHFILTER, IDH_MUTOHPEN_ENABLE_GLITCHFILTER,
  38. IDC_CALIBRATE, IDH_CALIBRATE,
  39. 0, 0
  40. };
  41. /*****************************************************************************
  42. *
  43. * @doc EXTERNAL
  44. *
  45. * @func INT_PTR | MutohPenDlgProc |
  46. * Dialog procedure for the pen tablet page.
  47. *
  48. * @parm IN HWND | hwnd | Window handle.
  49. * @parm IN UINT | uMsg | Message.
  50. * @parm IN WPARAM | wParam | Word Parameter.
  51. * @parm IN LPARAM | lParam | Long Parameter.
  52. *
  53. * @rvalue Return value depends on the message.
  54. *
  55. *****************************************************************************/
  56. INT_PTR APIENTRY
  57. MutohPenDlgProc(
  58. IN HWND hwnd,
  59. IN UINT uMsg,
  60. IN WPARAM wParam,
  61. IN LPARAM lParam
  62. )
  63. {
  64. TRACEPROC("MutohPenDlgProc", 2)
  65. INT_PTR rc = FALSE;
  66. ULONG dwFeature, dwMask, Rate;
  67. int iSideSwitchMapping;
  68. TCHAR tszRateText[32];
  69. TRACEENTER(("(hwnd=%p,Msg=%s,wParam=%x,lParam=%x)\n",
  70. hwnd, LookupName(uMsg, WMMsgNames) , wParam, lParam));
  71. switch (uMsg)
  72. {
  73. case WM_INITDIALOG:
  74. rc = InitMutohPenPage(hwnd);
  75. if (rc == FALSE)
  76. {
  77. EnableWindow(hwnd, FALSE);
  78. }
  79. break;
  80. case WM_NOTIFY:
  81. {
  82. NMHDR FAR *lpnm = (NMHDR FAR *)lParam;
  83. switch (lpnm->code)
  84. {
  85. case PSN_APPLY:
  86. rc = TRUE;
  87. RPC_TRY("TabSrvSetPenFeatures",
  88. if ((gdwfChanged & CHANGED_FEATURES) &&
  89. !TabSrvSetPenFeatures(ghBinding,
  90. PENFEATURE_REPORT_ID,
  91. PENFEATURE_USAGE_PAGE,
  92. PENFEATURE_USAGE,
  93. PenSettings.dwFeatures))
  94. {
  95. ErrorMsg(IDSERR_TABSRV_SETPENFEATURE);
  96. rc = FALSE;
  97. }
  98. );
  99. if (gdwfChanged & CHANGED_SIDESW_MAP)
  100. {
  101. //
  102. // BUGBUG: send side switch mapping to TabSrv.
  103. //
  104. }
  105. if (gdwfChanged & CHANGED_PENTILTCAL)
  106. {
  107. RPC_TRY("TabSrvSetPenTilt",
  108. TabSrvSetPenTilt(ghBinding,
  109. PenSettings.dxPenTilt,
  110. PenSettings.dyPenTilt));
  111. }
  112. if (gdwfChanged & CHANGED_LINEARCAL)
  113. {
  114. RPC_TRY("TabSrvSetLinearityMap",
  115. TabSrvSetLinearityMap(ghBinding,
  116. &PenSettings.LinearityMap));
  117. }
  118. gdwfChanged = 0;
  119. break;
  120. }
  121. break;
  122. }
  123. case WM_COMMAND:
  124. {
  125. DWORD Changed = 0;
  126. rc = TRUE;
  127. switch (LOWORD(wParam))
  128. {
  129. case IDC_SIDE_SWITCH:
  130. switch (HIWORD(wParam))
  131. {
  132. case CBN_SELCHANGE:
  133. iSideSwitchMapping =
  134. (int)SendMessage(GetDlgItem(hwnd,
  135. IDC_SIDE_SWITCH),
  136. CB_GETCURSEL,
  137. 0,
  138. 0);
  139. Changed = CHANGED_SIDESW_MAP;
  140. break;
  141. }
  142. break;
  143. case IDC_ENABLE_DIGITALFILTER:
  144. dwFeature = IsDlgButtonChecked(hwnd,
  145. IDC_ENABLE_DIGITALFILTER)?
  146. PENFEATURE_DIGITAL_FILTER_ON: 0;
  147. dwMask = PENFEATURE_DIGITAL_FILTER_ON;
  148. Changed = CHANGED_DIGITAL_FILTER;
  149. break;
  150. case IDC_ENABLE_GLITCHFILTER:
  151. dwFeature = IsDlgButtonChecked(hwnd,
  152. IDC_ENABLE_GLITCHFILTER)?
  153. PENFEATURE_GLITCH_FILTER_ON: 0;
  154. dwMask = PENFEATURE_GLITCH_FILTER_ON;
  155. Changed = CHANGED_GLITCH_FILTER;
  156. break;
  157. case IDC_CALIBRATE:
  158. switch (HIWORD(wParam))
  159. {
  160. case BN_CLICKED:
  161. {
  162. BOOL fCalLinear = ((GetAsyncKeyState(VK_CONTROL) &
  163. 0x8000) &&
  164. (GetAsyncKeyState(VK_MENU) &
  165. 0x8000));
  166. if (fCalLinear)
  167. {
  168. LONG cxScreen = GetSystemMetrics(SM_CXSCREEN);
  169. LONG cyScreen = GetSystemMetrics(SM_CYSCREEN);
  170. if (cxScreen > cyScreen)
  171. {
  172. rc = CreateLinearCalWindow(hwnd);
  173. }
  174. else
  175. {
  176. MessageBeep(MB_ICONEXCLAMATION);
  177. }
  178. }
  179. else if (!CreatePenTiltCalWindow(hwnd))
  180. {
  181. ErrorMsg(IDSERR_CALIBRATE_CREATEWINDOW);
  182. rc = FALSE;
  183. }
  184. break;
  185. }
  186. }
  187. break;
  188. }
  189. if ((rc == TRUE) && (Changed != 0))
  190. {
  191. if (Changed & CHANGED_FEATURES)
  192. {
  193. PenSettings.dwFeatures &= ~dwMask;
  194. PenSettings.dwFeatures |= dwFeature;
  195. }
  196. else if (Changed & CHANGED_SIDESW_MAP)
  197. {
  198. PenSettings.iSideSwitchMap = iSideSwitchMapping;
  199. }
  200. gdwfChanged |= Changed;
  201. SendMessage(GetParent(hwnd), PSM_CHANGED, (WPARAM)hwnd, 0);
  202. }
  203. break;
  204. }
  205. case WM_HSCROLL:
  206. {
  207. dwFeature = (ULONG)(PENFEATURE_RATE_MAX -
  208. SendDlgItemMessage(hwnd,
  209. IDC_SAMPLINGRATE,
  210. TBM_GETPOS,
  211. 0,
  212. 0));
  213. if (dwFeature == 1)
  214. {
  215. dwFeature = 0;
  216. Rate = 100;
  217. }
  218. else if (dwFeature == 0)
  219. {
  220. dwFeature = 1;
  221. Rate = 133;
  222. }
  223. else
  224. {
  225. Rate = 133/dwFeature;
  226. }
  227. if ((PenSettings.dwFeatures ^ dwFeature) & PENFEATURE_RATE_MASK)
  228. {
  229. gdwfChanged |= CHANGED_SAMPLINGRATE;
  230. PenSettings.dwFeatures &= ~PENFEATURE_RATE_MASK;
  231. PenSettings.dwFeatures |= dwFeature;
  232. wsprintf(tszRateText, gtszRateTextFormat, Rate);
  233. SetDlgItemText(hwnd, IDC_RATE_TEXT, tszRateText);
  234. SendMessage(GetParent(hwnd), PSM_CHANGED, (WPARAM)hwnd, 0);
  235. rc = TRUE;
  236. }
  237. break;
  238. }
  239. case WM_PENTILTCAL_DONE:
  240. //
  241. // wParam contains the user response of calibration.
  242. // lParam contains the calibration window handle.
  243. //
  244. if (wParam == IDYES)
  245. {
  246. gdwfChanged |= CHANGED_PENTILTCAL;
  247. SendMessage(GetParent(hwnd), PSM_CHANGED, (WPARAM)hwnd, 0);
  248. }
  249. DestroyWindow((HWND)lParam);
  250. break;
  251. case WM_LINEARCAL_DONE:
  252. //
  253. // wParam contains the user response of calibration.
  254. // lParam contains the calibration window handle.
  255. //
  256. if (wParam == IDYES)
  257. {
  258. gdwfChanged |= CHANGED_LINEARCAL;
  259. SendMessage(GetParent(hwnd), PSM_CHANGED, (WPARAM)hwnd, 0);
  260. }
  261. DestroyWindow((HWND)lParam);
  262. break;
  263. case WM_HELP:
  264. WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  265. TEXT("tabletpc.hlp"),
  266. HELP_WM_HELP,
  267. (DWORD_PTR)gMutohPenHelpIDs);
  268. break;
  269. case WM_CONTEXTMENU:
  270. WinHelp((HWND)wParam,
  271. TEXT("tabletpc.hlp"),
  272. HELP_CONTEXTMENU,
  273. (DWORD_PTR)gMutohPenHelpIDs);
  274. break;
  275. }
  276. TRACEEXIT(("=%x\n", rc));
  277. return rc;
  278. } //MutohPenDlgProc
  279. /*****************************************************************************
  280. *
  281. * @doc INTERNAL
  282. *
  283. * @func BOOL | InitMutohPenPage |
  284. * Initialize the Mutoh Pen property page.
  285. *
  286. * @parm IN HWND | hwnd | Window handle.
  287. *
  288. * @rvalue SUCCESS | Returns TRUE.
  289. * @rvalue FAILURE | Returns FALSE.
  290. *
  291. *****************************************************************************/
  292. BOOL
  293. InitMutohPenPage(
  294. IN HWND hwnd
  295. )
  296. {
  297. TRACEPROC("InitMutohPenPage", 2)
  298. BOOL rc;
  299. ULONG dwFeature, Rate;
  300. TCHAR tszRateText[32];
  301. TRACEENTER(("(hwnd=%x)\n", hwnd));
  302. LoadString(ghInstance,
  303. IDS_RATE_TEXT_FORMAT,
  304. gtszRateTextFormat,
  305. sizeof(gtszRateTextFormat)/sizeof(TCHAR));
  306. SendDlgItemMessage(hwnd,
  307. IDC_SAMPLINGRATE,
  308. TBM_SETRANGE,
  309. TRUE,
  310. MAKELONG(PENFEATURE_RATE_MIN, PENFEATURE_RATE_MAX));
  311. RPC_TRY("TabSrvGetPenFeatures",
  312. rc = TabSrvGetPenFeatures(ghBinding,
  313. PENFEATURE_REPORT_ID,
  314. PENFEATURE_USAGE_PAGE,
  315. PENFEATURE_USAGE,
  316. &PenSettings.dwFeatures));
  317. if (rc == TRUE)
  318. {
  319. dwFeature = PenSettings.dwFeatures & PENFEATURE_RATE_MASK;
  320. if (dwFeature == 1)
  321. {
  322. //
  323. // 1 actual means fastest (133 samples/sec)
  324. //
  325. dwFeature = 0;
  326. Rate = 133;
  327. }
  328. else if (dwFeature == 0)
  329. {
  330. //
  331. // Custom rate (100 samples/sec)
  332. //
  333. dwFeature = 1;
  334. Rate = 100;
  335. }
  336. else
  337. {
  338. Rate = 133/dwFeature;
  339. }
  340. SendDlgItemMessage(hwnd,
  341. IDC_SAMPLINGRATE,
  342. TBM_SETPOS,
  343. TRUE,
  344. PENFEATURE_RATE_MAX - dwFeature);
  345. wsprintf(tszRateText, gtszRateTextFormat, Rate);
  346. SetDlgItemText(hwnd, IDC_RATE_TEXT, tszRateText);
  347. InsertComboBoxStrings(hwnd, IDC_SIDE_SWITCH, SwitchComboStringTable);
  348. SendDlgItemMessage(hwnd,
  349. IDC_SIDE_SWITCH,
  350. CB_SETCURSEL,
  351. PenSettings.iSideSwitchMap,
  352. 0);
  353. CheckDlgButton(hwnd,
  354. IDC_ENABLE_DIGITALFILTER,
  355. (PenSettings.dwFeatures & PENFEATURE_DIGITAL_FILTER_ON)
  356. != 0);
  357. CheckDlgButton(hwnd,
  358. IDC_ENABLE_GLITCHFILTER,
  359. (PenSettings.dwFeatures & PENFEATURE_GLITCH_FILTER_ON)
  360. != 0);
  361. }
  362. else
  363. {
  364. PenSettings.dwFeatures = 0;
  365. ErrorMsg(IDSERR_TABSRV_GETPENFEATURE);
  366. rc = FALSE;
  367. }
  368. if (rc == TRUE)
  369. {
  370. //
  371. // BUGBUG: Read and init side switch mapping.
  372. //
  373. }
  374. TRACEEXIT(("=%x\n", rc));
  375. return rc;
  376. } //InitMutohPenPage
  377. #endif