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.

227 lines
6.4 KiB

  1. /* -------------------------------------------------------------------------- */
  2. /* Set the Button Mask and XBTNMASK extension */
  3. /* -------------------------------------------------------------------------- */
  4. #include <windows.h>
  5. #include "wintab.h"
  6. #include "Mgrdlg.h"
  7. #include "Mgrtest.h"
  8. #include "resource.h"
  9. typedef struct {
  10. LOGCONTEXT * lc;
  11. BOOL xBtnMask_avail;
  12. XBTNMASK xBtnMask;
  13. } btn_info;
  14. static const unsigned nbitboxes = 18;
  15. static const int bitbox_id[] = {
  16. XBU_DISPLAY1, XBU_DISPLAY2, XBU_DISPLAY3, XBU_DISPLAY4, XBU_DISPLAY5, XBU_DISPLAY6, XBU_DISPLAY7, XBU_DISPLAY8,
  17. XBD_DISPLAY1, XBD_DISPLAY2, XBD_DISPLAY3, XBD_DISPLAY4, XBD_DISPLAY5, XBD_DISPLAY6, XBD_DISPLAY7, XBD_DISPLAY8,
  18. BNU_DISPLAY, BND_DISPLAY
  19. };
  20. extern HANDLE hInst;
  21. extern BOOL FAR PASCAL ButtonDlgProc(HWND, UINT, WPARAM, LPARAM);
  22. void
  23. static DisplayBits( HWND hDlg, const btn_info * btn )
  24. {
  25. static char buf[33];
  26. int i;
  27. buf[32] = 0;
  28. /* Display the XBTNMASK bits */
  29. for( i = 0; i < 8; i++ ) {
  30. unsigned j;
  31. for( j = 0; j < 32; j++ )
  32. buf[j] = '0' + ((btn->xBtnMask.xBtnUpMask[4*i + j/8] >> (j%8)) & 0x01);
  33. SetWindowText(GetDlgItem(hDlg, bitbox_id[i]), buf);
  34. }
  35. for( i = 8; i < 16; i++ ) {
  36. unsigned j;
  37. for( j = 0; j < 32; j++ )
  38. buf[j] = '0' + ((btn->xBtnMask.xBtnDnMask[4*(i-8) + j/8] >> (j%8)) & 0x01);
  39. SetWindowText(GetDlgItem(hDlg, bitbox_id[i]), buf);
  40. }
  41. /* Display the regular button mask bits */
  42. for( i = 0; i < 32; i++ )
  43. buf[i] = (char)('0' + ((btn->lc->lcBtnUpMask >> i) & 0x01));
  44. SetWindowText(GetDlgItem(hDlg, BNU_DISPLAY), buf);
  45. for( i = 0; i < 32; i++ )
  46. buf[i] = (char)('0' + ((btn->lc->lcBtnDnMask >> i) & 0x01));
  47. SetWindowText(GetDlgItem(hDlg, BND_DISPLAY), buf);
  48. }
  49. /* -------------------------------------------------------------------------- */
  50. BOOL
  51. CALLBACK BtnMaskDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LONG lParam)
  52. {
  53. static btn_info * btn;
  54. BOOL fResult;
  55. int bit;
  56. switch (Msg) {
  57. case WM_INITDIALOG:
  58. btn = (btn_info *)lParam;
  59. if( !btn->xBtnMask_avail ) {
  60. EnableWindow( GetDlgItem(hDlg, XBD_BOX), FALSE );
  61. EnableWindow( GetDlgItem(hDlg, XBU_BOX), FALSE );
  62. for( bit = 0; bit < 16; bit++ )
  63. EnableWindow( GetDlgItem(hDlg, bitbox_id[bit]), FALSE );
  64. }
  65. DisplayBits(hDlg, btn);
  66. break;
  67. case WM_LBUTTONDOWN: /* Change the xBtnMask bits */
  68. /* If clicked on a digit in ???_DISPLAY?, then change it's corrisponding bit */
  69. /* Luckily 1 and 0 have the same width in the default font */
  70. bit = test_bitboxes( hDlg, lParam, 32, nbitboxes, bitbox_id );
  71. if( bit > -1 ) {
  72. /* Flip the bit. The first 32 bits of XBTNMASK should match the regular
  73. 32 bit button mask */
  74. if( bit/32 == 16 ) { /* Regular button mask */
  75. btn->lc->lcBtnUpMask ^= 1 << (bit%32);
  76. if( btn->xBtnMask_avail )
  77. btn->xBtnMask.xBtnUpMask[(bit%32)/8] ^= 1 << (bit%32);
  78. } else
  79. if( bit/32 == 17 ) {
  80. btn->lc->lcBtnDnMask ^= 1 << (bit%32);
  81. if( btn->xBtnMask_avail )
  82. btn->xBtnMask.xBtnDnMask[(bit%32)/8] ^= 1 << (bit%32);
  83. } else /* xBtnMask */
  84. if( btn->xBtnMask_avail )
  85. if( bit >= 256 ) {
  86. btn->xBtnMask.xBtnDnMask[(bit-256)/8] ^= 1 << (bit%8);
  87. if( bit-256 < 32 )
  88. btn->lc->lcBtnDnMask ^= 1 << (bit%32);
  89. } else {
  90. btn->xBtnMask.xBtnUpMask[bit / 8] ^= 1 << (bit%8);
  91. if( bit < 32 )
  92. btn->lc->lcBtnUpMask ^= 1 << (bit%32);
  93. }
  94. DisplayBits(hDlg, btn);
  95. }
  96. fResult = TRUE;
  97. break;
  98. case WM_COMMAND:
  99. if (wParam == IDOK) {
  100. EndDialog(hDlg, wParam);
  101. fResult = TRUE;
  102. }
  103. else if (wParam == IDCANCEL) {
  104. EndDialog(hDlg, wParam);
  105. fResult = TRUE;
  106. }
  107. break;
  108. default:
  109. fResult = FALSE;
  110. }
  111. return fResult;
  112. } /* BtnMaskDlgProc */
  113. void
  114. set_default_BtnMask( HWND hWnd, HMGR hMgr, int fSys )
  115. {
  116. int wDev;
  117. FARPROC lpProcDlg;
  118. /* Get a device # */
  119. lpProcDlg = MakeProcInstance(CursInfoDlgProc, hWnd);
  120. wDev = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_INFOLIST),
  121. hWnd, lpProcDlg, WTI_DDCTXS);
  122. FreeProcInstance(lpProcDlg);
  123. if( wDev >= 0 ) {
  124. FARPROC fpProc;
  125. btn_info btn;
  126. HCTX hCtx;
  127. int id;
  128. unsigned numDevices;
  129. LOGCONTEXT lc;
  130. WTInfo(WTI_INTERFACE, IFC_NDEVICES, &numDevices);
  131. if( wDev < (int)numDevices ) {
  132. hCtx = WTMgrDefContextEx(hMgr, wDev, fSys);
  133. if( !hCtx )
  134. hCtx = WTMgrDefContext(hMgr, fSys);
  135. } else
  136. hCtx = WTMgrDefContext(hMgr, fSys); /* 'Default Device' was the last choice in the dialog */
  137. btn.lc = &lc;
  138. /* Read the button masks */
  139. if( !hCtx ) {
  140. MessageBox( hWnd, "Failed to open default context.", "MgrTest", MB_ICONHAND | MB_OK );
  141. return;
  142. }
  143. if( !WTGet( hCtx, btn.lc ) ) {
  144. MessageBox( hWnd, "WTGet failed.", "MgrTest", MB_ICONHAND | MB_OK );
  145. return;
  146. }
  147. if( WTExtGet( hCtx, WTX_XBTNMASK, &btn.xBtnMask ) )
  148. btn.xBtnMask_avail = TRUE;
  149. else {
  150. btn.xBtnMask_avail = FALSE;
  151. memset( btn.xBtnMask.xBtnDnMask, 0, sizeof(XBTNMASK) );
  152. }
  153. /* Do the button bit dialog */
  154. fpProc = MakeProcInstance((FARPROC)BtnMaskDlgProc, hWnd);
  155. id = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_BTNMASKS), hWnd, fpProc, (long)&btn);
  156. FreeProcInstance(fpProc);
  157. /* Set the new button masks */
  158. if( id == IDOK ) {
  159. if( !WTSet( hCtx, btn.lc ) )
  160. MessageBox( hWnd, "WTSet failed.", "MgrTest", MB_ICONHAND | MB_OK );
  161. if( btn.xBtnMask_avail && !WTExtSet( hCtx, WTX_XBTNMASK, &btn.xBtnMask ) )
  162. MessageBox( hWnd, "WTExtSet failed.", "MgrTest", MB_ICONHAND | MB_OK );
  163. }
  164. }
  165. }
  166. void
  167. set_ctx_BtnMask( HWND hWnd, HCTX hCtx, LOGCONTEXT * lc )
  168. {
  169. FARPROC fpProc;
  170. btn_info btn;
  171. int id;
  172. btn.lc = lc;
  173. if( WTExtGet( hCtx, WTX_XBTNMASK, &btn.xBtnMask ) )
  174. btn.xBtnMask_avail = TRUE;
  175. else {
  176. btn.xBtnMask_avail = FALSE;
  177. memset( btn.xBtnMask.xBtnDnMask, 0, sizeof(XBTNMASK) );
  178. }
  179. fpProc = MakeProcInstance((FARPROC)BtnMaskDlgProc, hWnd);
  180. id = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_BTNMASKS), hWnd, fpProc, (long)&btn);
  181. FreeProcInstance(fpProc);
  182. if( id == IDOK ) {
  183. /* Set the new button masks */
  184. if( !WTSet( hCtx, btn.lc ) )
  185. MessageBox( hWnd, "WTSet failed.", "MgrTest", MB_ICONHAND | MB_OK );
  186. if( btn.xBtnMask_avail && !WTExtSet( hCtx, WTX_XBTNMASK, &btn.xBtnMask ) )
  187. MessageBox( hWnd, "WTExtSet failed.", "MgrTest", MB_ICONHAND | MB_OK );
  188. }
  189. }