Counter Strike : Global Offensive Source Code
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.

294 lines
6.1 KiB

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <windows.h>
  4. #include "msgpack.h"
  5. #include <wintab.h>
  6. #include "mgrdlg.h"
  7. extern HMGR hMgr;
  8. /* Fake a notification msg to our own dialog. */
  9. #define FakeNotify(Ctl, Msg) FORWARD_WM_COMMAND(hDlg, Ctl, \
  10. GetDlgItem(hDlg, Ctl), Msg, SendMessage)
  11. char Logical[]="Button #\0\0\0\0\0";
  12. char *LogNum= Logical+8;
  13. WORD wCsr=0xFFFF; /* Current Cursor */
  14. unsigned char bLogBtns[32]={0}, bSysBtns[32]={0};
  15. char *MseActs[]={
  16. "No Mouse Action",
  17. "Left Click",
  18. "Left Double-Click",
  19. "Left Drag",
  20. "Right Click",
  21. "Right Double-Click",
  22. "Right Drag",
  23. "Middle Click",
  24. "Middle Double-Click",
  25. "Middle Drag",
  26. NULL
  27. };
  28. char *PenActs[]={
  29. "No Pen Action",
  30. "Tip Click",
  31. "Tip Double-Click",
  32. "Tip Drag",
  33. "Inverted Click",
  34. "Inverted Double-Click",
  35. "Inverted Drag",
  36. "Barrel 1 Click",
  37. "Barrel 1 Double-Click",
  38. "Barrel 1 Drag",
  39. "Barrel 2 Click",
  40. "Barrel 2 Double-Click",
  41. "Barrel 2 Drag",
  42. "Barrel 3 Click",
  43. "Barrel 3 Double-Click",
  44. "Barrel 3 Drag",
  45. NULL
  46. };
  47. /* Primitive -- load into globals */
  48. void static GetButtonMaps(HWND hDlg)
  49. {
  50. char NameBuf[500], *Name;
  51. WTInfo(WTI_CURSORS+wCsr, CSR_BTNNAMES, NameBuf);
  52. WTInfo(WTI_CURSORS+wCsr, CSR_BUTTONMAP, bLogBtns);
  53. WTInfo(WTI_CURSORS+wCsr, CSR_SYSBTNMAP, bSysBtns);
  54. /* Clear out old strings */
  55. while (SendDlgItemMessage(hDlg, IDC_NAMES,
  56. CB_DELETESTRING, 0, 0L))
  57. ;
  58. for (Name = NameBuf; *Name != '\0';
  59. Name += lstrlen(Name)+1)
  60. SendDlgItemMessage(hDlg, IDC_NAMES, CB_ADDSTRING,
  61. 0, (LPARAM)(LPSTR)Name);
  62. }
  63. /* Primitive -- Set values from globals */
  64. void static SetButtonMaps(HWND hDlg)
  65. {
  66. if (wCsr == 0xFFFF)
  67. return;
  68. WTMgrCsrButtonMap(hMgr, wCsr, bLogBtns, bSysBtns);
  69. }
  70. /* Primitive -- Set default values */
  71. void static ResetButtonMaps(HWND hDlg)
  72. {
  73. if (wCsr == 0xFFFF)
  74. return;
  75. WTMgrCsrButtonMap(hMgr, wCsr, WTP_LPDEFAULT, WTP_LPDEFAULT);
  76. }
  77. BOOL CALLBACK ButtonDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  78. {
  79. int wTmp, i, wTmpCsr;
  80. static char Name[80];
  81. WORD id, cmd;
  82. HWND hWnd;
  83. switch (msg) {
  84. default:
  85. return FALSE;
  86. case WM_INITDIALOG:
  87. /* Cursor names */
  88. WTInfo(WTI_INTERFACE, IFC_NCURSORS, &wTmp);
  89. for (i = 0; i < wTmp; i++) {
  90. BOOL fActive;
  91. /* remember first active cursor. */
  92. WTInfo(WTI_CURSORS+i, CSR_ACTIVE, &fActive);
  93. if (fActive) {
  94. wTmpCsr = i;
  95. }
  96. WTInfo(WTI_CURSORS+i, CSR_NAME, Name);
  97. SendDlgItemMessage(hDlg, IDC_CURSORS, CB_ADDSTRING, 0,
  98. (LPARAM)(LPSTR)Name);
  99. }
  100. /* Logical button numbers */
  101. for (i = 0; i < 32; i++) {
  102. sprintf( LogNum, "%i", i );
  103. /* itoa(i, LogNum, 10); */
  104. SendDlgItemMessage(hDlg, IDC_LOGICAL, CB_ADDSTRING, 0,
  105. (LPARAM)(LPSTR)Logical);
  106. }
  107. /* Mouse Actions */
  108. for (i = 0; MseActs[i] != NULL; i++) {
  109. SendDlgItemMessage(hDlg, IDC_MOUSE, CB_ADDSTRING, 0,
  110. (LPARAM)(LPSTR)(MseActs[i]));
  111. }
  112. /* Pen Actions */
  113. for (i = 0; PenActs[i] != NULL; i++) {
  114. SendDlgItemMessage(hDlg, IDC_PEN, CB_ADDSTRING, 0,
  115. (LPARAM)(LPSTR)(PenActs[i]));
  116. }
  117. SendDlgItemMessage(hDlg, IDC_NAMES, CB_ADDSTRING,
  118. 0, (LPARAM)(LPSTR)"FOOBAR");
  119. /* start with current cursor selected. */
  120. SendDlgItemMessage(hDlg, IDC_CURSORS,
  121. CB_SETCURSEL, wTmpCsr, 0L);
  122. FakeNotify(IDC_CURSORS, CBN_SELCHANGE);
  123. return TRUE;
  124. case WM_COMMAND:
  125. id = GET_WM_COMMAND_ID(wParam, lParam);
  126. cmd = GET_WM_COMMAND_CMD(wParam, lParam);
  127. hWnd = GET_WM_COMMAND_HWND(wParam, lParam);
  128. switch (id) {
  129. case IDC_CURSORS:
  130. if (cmd == CBN_SELCHANGE) {
  131. /* Set old values */
  132. SetButtonMaps(hDlg);
  133. /* Set Button names and cascade selections. */
  134. wCsr = (WORD)SendDlgItemMessage(hDlg, IDC_CURSORS,
  135. CB_GETCURSEL, 0, 0L);
  136. GetButtonMaps(hDlg);
  137. /* Fake selection to continue cascade */
  138. SendDlgItemMessage(hDlg, IDC_NAMES,
  139. CB_SETCURSEL, 0, 0L);
  140. FakeNotify(IDC_NAMES, CBN_SELCHANGE);
  141. } /* selchange */
  142. break;
  143. case IDC_NAMES:
  144. if (cmd == CBN_SELCHANGE) {
  145. wTmp = (WORD)SendDlgItemMessage(hDlg, IDC_NAMES,
  146. CB_GETCURSEL, 0, 0L);
  147. /* Fake selection to continue cascade */
  148. SendDlgItemMessage(hDlg, IDC_LOGICAL,
  149. CB_SETCURSEL, bLogBtns[wTmp], 0L);
  150. FakeNotify(IDC_LOGICAL, CBN_SELCHANGE);
  151. }
  152. break;
  153. case IDC_LOGICAL:
  154. if (cmd == CBN_SELCHANGE) {
  155. WORD wButton=0;
  156. wButton = (WORD)SendDlgItemMessage(hDlg, IDC_NAMES,
  157. CB_GETCURSEL, 0, 0L);
  158. wTmp = (WORD)SendDlgItemMessage(hDlg, IDC_LOGICAL,
  159. CB_GETCURSEL, 0, 0L);
  160. bLogBtns[wButton] = (BYTE)wTmp;
  161. /* Fake selection to continue cascade */
  162. SendDlgItemMessage(hDlg, IDC_MOUSE,
  163. CB_SETCURSEL, bSysBtns[wTmp] & 0xF, 0L);
  164. SendDlgItemMessage(hDlg, IDC_PEN,
  165. CB_SETCURSEL, bSysBtns[wTmp] >> 4, 0L);
  166. }
  167. break;
  168. case IDC_MOUSE:
  169. if (cmd == CBN_SELCHANGE) {
  170. WORD wButton=0;
  171. wButton = (WORD)SendDlgItemMessage(hDlg, IDC_LOGICAL,
  172. CB_GETCURSEL, 0, 0L);
  173. wTmp = (WORD)SendDlgItemMessage(hDlg, IDC_MOUSE,
  174. CB_GETCURSEL, 0, 0L);
  175. bSysBtns[wButton] &= 0xF0;
  176. bSysBtns[wButton] |= wTmp & 0x0F;
  177. }
  178. break;
  179. case IDC_PEN:
  180. if (cmd == CBN_SELCHANGE) {
  181. WORD wButton=0;
  182. wButton = (WORD)SendDlgItemMessage(hDlg, IDC_LOGICAL,
  183. CB_GETCURSEL, 0, 0L);
  184. wTmp = (WORD)SendDlgItemMessage(hDlg, IDC_PEN,
  185. CB_GETCURSEL, 0, 0L);
  186. bSysBtns[wButton] &= 0x0F;
  187. bSysBtns[wButton] |= (wTmp & 0x0F) << 4;
  188. }
  189. break;
  190. case IDC_DEFAULT:
  191. /* Set maps back to defaults */
  192. ResetButtonMaps(hDlg);
  193. wCsr = 0xFFFF;
  194. FakeNotify(IDC_CURSORS, CBN_SELCHANGE);
  195. break;
  196. case IDOK:
  197. SetButtonMaps(hDlg);
  198. EndDialog(hDlg, id);
  199. break;
  200. case IDCANCEL:
  201. EndDialog(hDlg, id);
  202. break;
  203. } /* Switch id */
  204. } /* Switch msg */
  205. return TRUE;
  206. }
  207.