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.

376 lines
11 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. buttons.c
  5. Abstract: Tablet PC Buttons 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 BUTTONPAGE
  14. #define NUM_HOTKEY_BUTTONS 2
  15. BUTTON_SETTINGS gButtonSettings = {0};
  16. DWORD gButtonTags[NUM_BUTTONS] =
  17. {
  18. 0x00000004,
  19. 0x00000002,
  20. 0x00000001,
  21. 0x00000010,
  22. 0x00000008
  23. };
  24. int giButtonComboIDs[] =
  25. {
  26. IDC_BUTTON_1,
  27. IDC_BUTTON_2,
  28. IDC_BUTTON_3,
  29. IDC_BUTTON_4,
  30. IDC_BUTTON_5
  31. };
  32. COMBOBOX_STRING ButtonComboStringTable[] =
  33. {
  34. ButtonNoAction, IDS_BUTCOMBO_NONE,
  35. InvokeNoteBook, IDS_BUTCOMBO_INVOKENOTEBOOK,
  36. PageUp, IDS_BUTCOMBO_PAGEUP,
  37. PageDown, IDS_BUTCOMBO_PAGEDOWN,
  38. AltEsc, IDS_BUTCOMBO_ALTESC,
  39. AltTab, IDS_BUTCOMBO_ALTTAB,
  40. Enter, IDS_BUTCOMBO_ENTER,
  41. Esc, IDS_BUTCOMBO_ESC,
  42. 0, 0
  43. };
  44. DWORD gButtonsHelpIDs[] =
  45. {
  46. IDC_BUTTON_1, IDH_BUTTONS_BUTTONMAP,
  47. IDC_BUTTON_2, IDH_BUTTONS_BUTTONMAP,
  48. IDC_BUTTON_3, IDH_BUTTONS_BUTTONMAP,
  49. IDC_BUTTON_4, IDH_BUTTONS_BUTTONMAP,
  50. IDC_BUTTON_5, IDH_BUTTONS_BUTTONMAP,
  51. 0, 0
  52. };
  53. /*****************************************************************************
  54. *
  55. * @doc EXTERNAL
  56. *
  57. * @func INT_PTR | ButtonsDlgProc |
  58. * Dialog procedure for the buttons page.
  59. *
  60. * @parm IN HWND | hwnd | Window handle.
  61. * @parm IN UINT | uMsg | Message.
  62. * @parm IN WPARAM | wParam | Word Parameter.
  63. * @parm IN LPARAM | lParam | Long Parameter.
  64. *
  65. * @rvalue Return value depends on the message.
  66. *
  67. *****************************************************************************/
  68. INT_PTR APIENTRY
  69. ButtonsDlgProc(
  70. IN HWND hwnd,
  71. IN UINT uMsg,
  72. IN WPARAM wParam,
  73. IN LPARAM lParam
  74. )
  75. {
  76. TRACEPROC("ButtonsDlgProc", 2)
  77. INT_PTR rc = FALSE;
  78. static BOOL fInitDone = FALSE;
  79. TRACEENTER(("(hwnd=%p,Msg=%s,wParam=%x,lParam=%x)\n",
  80. hwnd, LookupName(uMsg, WMMsgNames), wParam, lParam));
  81. switch (uMsg)
  82. {
  83. case WM_INITDIALOG:
  84. rc = InitButtonPage(hwnd);
  85. if (rc == FALSE)
  86. {
  87. EnableWindow(hwnd, FALSE);
  88. }
  89. else
  90. {
  91. fInitDone = TRUE;
  92. }
  93. break;
  94. case WM_NOTIFY:
  95. {
  96. NMHDR FAR *lpnm = (NMHDR FAR *)lParam;
  97. switch (lpnm->code)
  98. {
  99. case PSN_APPLY:
  100. RPC_TRY("TabSrvSetButtonSettings",
  101. rc = TabSrvSetButtonSettings(ghBinding,
  102. &gButtonSettings));
  103. if (rc == FALSE)
  104. {
  105. ErrorMsg(IDSERR_TABSRV_SETBUTTONSETTINGS);
  106. }
  107. break;
  108. }
  109. break;
  110. }
  111. case WM_COMMAND:
  112. {
  113. int iButtonMapping;
  114. int i, j;
  115. switch (LOWORD(wParam))
  116. {
  117. case IDC_BUTTON_1:
  118. i = BUTTON_1;
  119. goto ButtonCommon;
  120. case IDC_BUTTON_2:
  121. i = BUTTON_2;
  122. goto ButtonCommon;
  123. case IDC_BUTTON_3:
  124. i = BUTTON_3;
  125. goto ButtonCommon;
  126. case IDC_BUTTON_4:
  127. i = BUTTON_4;
  128. goto ButtonCommon;
  129. case IDC_BUTTON_5:
  130. i = BUTTON_5;
  131. ButtonCommon:
  132. switch (HIWORD(wParam))
  133. {
  134. case CBN_SELCHANGE:
  135. iButtonMapping =
  136. (int)SendMessage(GetDlgItem(hwnd,
  137. LOWORD(wParam)),
  138. CB_GETCURSEL,
  139. 0,
  140. 0);
  141. j = MapButtonTagIndex(i);
  142. if (iButtonMapping != gButtonSettings.ButtonMap[j])
  143. {
  144. //
  145. // Mapping has changed, mark the property
  146. // sheet dirty.
  147. //
  148. gButtonSettings.ButtonMap[j] = iButtonMapping;
  149. SendMessage(GetParent(hwnd),
  150. PSM_CHANGED,
  151. (WPARAM)hwnd,
  152. 0);
  153. rc = TRUE;
  154. }
  155. break;
  156. }
  157. break;
  158. case IDC_HOTKEY1:
  159. case IDC_HOTKEY2:
  160. switch (HIWORD(wParam))
  161. {
  162. case EN_UPDATE:
  163. {
  164. int hk1, hk2;
  165. BOOL fOK1, fOK2;
  166. hk1 = GetDlgItemInt(hwnd,
  167. IDC_HOTKEY1,
  168. &fOK1,
  169. FALSE);
  170. hk2 = GetDlgItemInt(hwnd,
  171. IDC_HOTKEY2,
  172. &fOK2,
  173. FALSE);
  174. if (fOK1 && fOK2 &&
  175. (hk1 > 0) && (hk1 <= NUM_BUTTONS) &&
  176. (hk2 > 0) && (hk2 <= NUM_BUTTONS))
  177. {
  178. gButtonSettings.dwHotKeyButtons =
  179. gButtonTags[hk1 - 1] |
  180. gButtonTags[hk2 - 1];
  181. SendMessage(GetParent(hwnd),
  182. PSM_CHANGED,
  183. (WPARAM)hwnd,
  184. 0);
  185. }
  186. else if (fInitDone)
  187. {
  188. SendMessage((HWND)lParam,
  189. EM_SETSEL,
  190. 0,
  191. -1);
  192. MessageBeep(MB_ICONEXCLAMATION);
  193. }
  194. break;
  195. }
  196. }
  197. break;
  198. }
  199. break;
  200. }
  201. case WM_HELP:
  202. WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  203. TEXT("tabletpc.hlp"),
  204. HELP_WM_HELP,
  205. (DWORD_PTR)gButtonsHelpIDs);
  206. break;
  207. case WM_CONTEXTMENU:
  208. WinHelp((HWND)wParam,
  209. TEXT("tabletpc.hlp"),
  210. HELP_CONTEXTMENU,
  211. (DWORD_PTR)gButtonsHelpIDs);
  212. break;
  213. }
  214. TRACEEXIT(("=%x\n", rc));
  215. return rc;
  216. } //ButtonsDlgProc
  217. /*****************************************************************************
  218. *
  219. * @doc INTERNAL
  220. *
  221. * @func BOOL | InitButtonPage |
  222. * Initialize the Button property page.
  223. *
  224. * @parm IN HWND | hwnd | Window handle.
  225. *
  226. * @rvalue SUCCESS | Returns TRUE.
  227. * @rvalue FAILURE | Returns FALSE.
  228. *
  229. *****************************************************************************/
  230. BOOL
  231. InitButtonPage(
  232. IN HWND hwnd
  233. )
  234. {
  235. TRACEPROC("InitButtonPage", 2)
  236. BOOL rc;
  237. TRACEENTER(("(hwnd=%x)\n", hwnd));
  238. RPC_TRY("TabSrvGetButtonSettings",
  239. rc = TabSrvGetButtonSettings(ghBinding,
  240. &gButtonSettings));
  241. if (rc == TRUE)
  242. {
  243. int i, j;
  244. int HotKeys[2] = {0, 0};
  245. for (i = 0; i < NUM_BUTTONS; i++)
  246. {
  247. InsertComboBoxStrings(hwnd,
  248. giButtonComboIDs[i],
  249. ButtonComboStringTable);
  250. j = MapButtonTagIndex(i);
  251. SendDlgItemMessage(hwnd,
  252. giButtonComboIDs[i],
  253. CB_SETCURSEL,
  254. gButtonSettings.ButtonMap[j],
  255. 0);
  256. }
  257. for (i = 0, j = 0; i < NUM_BUTTONS; i++)
  258. {
  259. if (gButtonSettings.dwHotKeyButtons & gButtonTags[i])
  260. {
  261. HotKeys[j] = i + 1;
  262. j++;
  263. if (j >= NUM_HOTKEY_BUTTONS)
  264. {
  265. break;
  266. }
  267. }
  268. }
  269. SendDlgItemMessage(hwnd,
  270. IDC_HOTKEY1_SPIN,
  271. UDM_SETRANGE32,
  272. 1,
  273. NUM_BUTTONS);
  274. SendDlgItemMessage(hwnd,
  275. IDC_HOTKEY2_SPIN,
  276. UDM_SETRANGE32,
  277. 1,
  278. NUM_BUTTONS);
  279. SendDlgItemMessage(hwnd,
  280. IDC_HOTKEY1_SPIN,
  281. UDM_SETPOS32,
  282. 0,
  283. HotKeys[0]);
  284. SendDlgItemMessage(hwnd,
  285. IDC_HOTKEY2_SPIN,
  286. UDM_SETPOS32,
  287. 0,
  288. HotKeys[1]);
  289. }
  290. else
  291. {
  292. ErrorMsg(IDSERR_TABSRV_GETBUTTONSETTINGS);
  293. }
  294. TRACEEXIT(("=%x\n", rc));
  295. return rc;
  296. } //InitButtonPage
  297. /*****************************************************************************
  298. *
  299. * @doc INTERNAL
  300. *
  301. * @func int | MapButtonTagIndex | Map button tag index by Button Number.
  302. *
  303. * @parm IN int | iButton | Button Number.
  304. *
  305. * @rvalue SUCCESS | Returns Button Tag index.
  306. * @rvalue FAILURE | Returns -1.
  307. *
  308. *****************************************************************************/
  309. int
  310. MapButtonTagIndex(
  311. IN int iButton
  312. )
  313. {
  314. TRACEPROC("MapButtonTagIndex", 3)
  315. int i;
  316. TRACEENTER(("(ButtonNumber=%d)\n", iButton));
  317. for (i = 0; i < NUM_BUTTONS; ++i)
  318. {
  319. if (gButtonTags[iButton] == (1 << i))
  320. {
  321. break;
  322. }
  323. }
  324. if (i == NUM_BUTTONS)
  325. {
  326. i = -1;
  327. }
  328. TRACEEXIT(("=%d\n", i));
  329. return i;
  330. } //MapButtonTagIndex
  331. #endif