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.

203 lines
5.2 KiB

  1. /* ------------------------------- infodlg.c -------------------------------- */
  2. /* 11-25-91 DMH -- Dialog boxes to mediate cursor/extension info-boxes, */
  3. /* 6/1/98 Napoli -- Added WTI_DDCTXS, WTI_DSCTXS */
  4. /* -- Copied from wttest32 to mgrtest */
  5. #include <string.h>
  6. #include <windows.h>
  7. #include <tchar.h>
  8. #include "wintab.h"
  9. #include "mgrtest.h"
  10. #define Abort() EndDialog(hDlg, -2)
  11. extern HANDLE hInst;
  12. #ifndef WIN32
  13. #define TCHAR char
  14. #define wcscpy(a,b) strcpy((a),(b))
  15. #define TEXT(a) (a)
  16. #endif
  17. BOOL CALLBACK CursInfoDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LONG lParam)
  18. {
  19. int cBaseCat;
  20. /* Base category -- cursors, devices, extensions? */
  21. int cNumCats=0;
  22. int nNameCat=1; /* For all three the *_NAME Index is 1. &&&MAGIC&&&*/
  23. int cSize;
  24. long nCat;
  25. TCHAR *szCatName;
  26. TCHAR PhraseBuf[40];
  27. TCHAR TextBuf[40];
  28. TCHAR szNameBuf[128];
  29. lParam = lParam; /* Nuke warning */
  30. switch (Msg) {
  31. default:
  32. return FALSE;
  33. case WM_INITDIALOG:
  34. cBaseCat = LOWORD(lParam);
  35. switch (cBaseCat) {
  36. default:
  37. EndDialog(hDlg, -2);
  38. break;
  39. case WTI_DDCTXS:
  40. case WTI_DSCTXS:
  41. case WTI_DEVICES:
  42. szCatName = TEXT("Device");
  43. WTInfo(WTI_INTERFACE, IFC_NDEVICES, &cNumCats);
  44. if( cBaseCat == WTI_DDCTXS || cBaseCat == WTI_DSCTXS ) {
  45. WORD ver;
  46. if( !WTInfo(WTI_INTERFACE,IFC_SPECVERSION, &ver) ||
  47. ((ver >> 8) <= 1 && (ver & 0xff) <= 10) ) {
  48. /* Apparently, this version of Wintab doesn't support WTI_DDCTXS
  49. or WTI_DSCTXS; return cNumCats, to indicate "default device"
  50. since no other categories actually exist. */
  51. EndDialog(hDlg, cNumCats);
  52. return TRUE;
  53. }
  54. }
  55. break;
  56. case WTI_CURSORS:
  57. szCatName = TEXT("Cursor");
  58. WTInfo(WTI_INTERFACE, IFC_NCURSORS, &cNumCats);
  59. break;
  60. case WTI_EXTENSIONS:
  61. szCatName = TEXT("Extension");
  62. WTInfo(WTI_INTERFACE, IFC_NEXTENSIONS, &cNumCats);
  63. break;
  64. /* Failure to support IFC_N* is handled later. */
  65. } /* Switch on lParam */
  66. if (cNumCats == 1)
  67. EndDialog(hDlg, 0);
  68. /*&&& Send message to secret field, indicating this window's
  69. cBaseCat. Also, set window's title field and caption. */
  70. GetWindowText(hDlg, TextBuf, sizeof(TextBuf));
  71. wsprintf(PhraseBuf, TextBuf, (LPSTR)szCatName);
  72. SetWindowText(hDlg, PhraseBuf);
  73. GetDlgItemText(hDlg, LBC_TITLE, TextBuf, sizeof(TextBuf));
  74. wsprintf(PhraseBuf, TextBuf, (LPSTR)szCatName);
  75. SetDlgItemText(hDlg, LBC_TITLE, PhraseBuf);
  76. SetDlgItemInt(hDlg, LBC_BASECAT, cBaseCat, FALSE);
  77. /* How many items are there? Catch un-reported items.*/
  78. while (WTInfo(cBaseCat + cNumCats, 0, NULL))
  79. cNumCats++;
  80. while (cNumCats > 0 && !WTInfo(cBaseCat + cNumCats-1, 0, NULL))
  81. cNumCats--;
  82. if (cNumCats == 0) {
  83. wsprintf(PhraseBuf, TEXT("No %ss defined!"), (LPSTR)szCatName);
  84. MessageBox(hInst, PhraseBuf, TEXT("Info Boxes"),
  85. MB_ICONINFORMATION | MB_OK);
  86. EndDialog(hDlg, -2);
  87. return TRUE;
  88. }
  89. /* Fill list Box */
  90. for (nCat = 0; nCat < cNumCats; nCat++) {
  91. cSize = WTInfo(cBaseCat + (int)nCat, CSR_NAME,
  92. (LPVOID) szNameBuf);
  93. if (cSize == 0 || szNameBuf[0] == '\0')
  94. wsprintf(szNameBuf, TEXT("%s #%d"), (LPSTR)szCatName,(int)nCat);
  95. cSize = (int)SendDlgItemMessage(hDlg, LBC_LISTBOX,
  96. LB_INSERTSTRING, (WPARAM)-1, (DWORD)(LPSTR)szNameBuf);
  97. if (cSize == LB_ERR || cSize == LB_ERRSPACE) {
  98. MessageBox(hInst, TEXT("Couldn't set an item name!"), TEXT("Info Boxes"),
  99. MB_ICONINFORMATION | MB_OK);
  100. /* EndDialog(hDlg, -2);
  101. return TRUE; /* Abort on failure */
  102. } /* Abort on failure */
  103. else
  104. ;
  105. } /* for each cursor */
  106. if( cBaseCat == WTI_DDCTXS || cBaseCat == WTI_DSCTXS ) {
  107. /* Give a 'Default Device' choice, to fall back to WTI_DEFCONTEXT, WTI_DEFSYSCTX */
  108. wcscpy((wchar_t *)szNameBuf, (wchar_t *)TEXT("Default Device"));
  109. SendDlgItemMessage(hDlg, LBC_LISTBOX, LB_INSERTSTRING, (WPARAM)-1, (DWORD)(LPSTR)szNameBuf);
  110. }
  111. /* Default selection was current cursor. Now, skipping the whole
  112. thing, because there can be multiple active cursors! */
  113. nCat = 0; /* Index of 0, First item. */
  114. if (LB_ERR == (int)SendDlgItemMessage(hDlg, LBC_LISTBOX,
  115. LB_SETCURSEL, (int)nCat, (long)NULL))
  116. MessageBox(hInst, TEXT("Couldn't set current selection!"),
  117. TEXT("Info Boxes"),
  118. MB_ICONINFORMATION | MB_OK);
  119. return TRUE;
  120. case WM_COMMAND:
  121. switch (wParam) {
  122. default:
  123. return FALSE;
  124. case LBC_LISTBOX:
  125. if (HIWORD(lParam)!=LBN_DBLCLK)
  126. return FALSE;
  127. // fall through on double click!
  128. case IDOK:
  129. cBaseCat = GetDlgItemInt(hDlg, LBC_BASECAT, NULL,
  130. FALSE);
  131. nCat = (int)SendDlgItemMessage(hDlg, LBC_LISTBOX,
  132. LB_GETCURSEL, 0,
  133. (long)NULL);
  134. EndDialog(hDlg, (int)nCat);
  135. return TRUE;
  136. case IDCANCEL:
  137. EndDialog(hDlg, -1);
  138. return TRUE;
  139. } /* Switch wParam on WM_COMMAND */
  140. } /* switch Msg number */
  141. return FALSE;
  142. } /* CursInfoDlgProc */