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.

421 lines
11 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993.
  5. //
  6. // File: debugui.cxx
  7. //
  8. // Contents: User interface for trace tags dialog
  9. //
  10. // History: ??
  11. // 10-08-93 ErikGav New UI
  12. // 10-20-93 ErikGav Unicode cleanup
  13. //
  14. //----------------------------------------------------------------------------
  15. #include <headers.h>
  16. #if _DEBUG
  17. #include "resource.h"
  18. // private typedefs
  19. typedef int TMC;
  20. // private function prototypes
  21. void DoTracePointsDialog(BOOL fWait);
  22. VOID EndButton(HWND hwndDlg, TMC tmc, BOOL fDirty);
  23. WORD TagFromSelection(HWND hwndDlg, TMC tmc);
  24. BOOL CALLBACK DlgTraceEtc(HWND hwndDlg, UINT wm, WPARAM wparam, LPARAM lparam);
  25. // Debug UI Globals
  26. //
  27. // Identifies the type of TAG with which the current modal dialog is
  28. // dealing.
  29. //
  30. static BOOL fDirtyDlg;
  31. //+-------------------------------------------------------------------------
  32. //
  33. // Function: TraceTagDlgThread
  34. //
  35. // Synopsis: Thread entry point for trace tag dialog. Keeps caller
  36. // of DoTracePointsDialog from blocking.
  37. //
  38. //--------------------------------------------------------------------------
  39. DWORD
  40. TraceTagDlgThread(void * pv)
  41. {
  42. INT_PTR r;
  43. r = DialogBoxA(g_hinstMain, "TRCAST", g_hwndMain, (DLGPROC)DlgTraceEtc);
  44. if (r == -1)
  45. {
  46. MessageBoxA(NULL, "Couldn't create trace tag dialog", "Error",
  47. MB_OK | MB_ICONSTOP);
  48. }
  49. return (DWORD) r;
  50. }
  51. //+---------------------------------------------------------------------------
  52. //
  53. // Function: DoTracePointsDialog
  54. //
  55. // Synopsis: Brings up and processes trace points dialog. Any changes
  56. // made by the user are copied to the current debug state.
  57. //
  58. // Arguments: [fWait] -- If TRUE, this function will not return until the
  59. // dialog has been closed.
  60. //
  61. //----------------------------------------------------------------------------
  62. void
  63. DoTracePointsDialog( BOOL fWait )
  64. {
  65. HANDLE hThread = NULL;
  66. #ifndef _MAC
  67. DWORD idThread;
  68. #endif
  69. if (!g_fInit)
  70. {
  71. OutputDebugString(_T("DoTracePointsDialog: Debug library not initialized"));
  72. return;
  73. }
  74. if (fWait)
  75. {
  76. TraceTagDlgThread(NULL);
  77. }
  78. else
  79. {
  80. #ifndef _MAC
  81. hThread = CreateThread(NULL, 0, (unsigned long (__stdcall *)(void *)) TraceTagDlgThread, NULL, 0, &idThread);
  82. #else
  83. #pragma message(" DEBUGUI.cxx CreateThread")
  84. Assert (0 && " DEBUGUI.cxx CreateThread");
  85. #endif
  86. if (hThread == NULL)
  87. {
  88. MessageBox(NULL,
  89. _T("Couldn't create trace tag dialog thread"),
  90. _T("Error"),
  91. MB_OK | MB_ICONSTOP);
  92. }
  93. #ifndef _MAC
  94. else
  95. {
  96. CloseHandle(hThread);
  97. }
  98. #endif
  99. }
  100. }
  101. /*
  102. * FFillDebugListbox
  103. *
  104. * Purpose:
  105. * Initializes Windows debug listboxes by adding the correct strings
  106. * to the listbox for the current dialog type. This is only called
  107. * once in the Windows interface when the dialog is initialized.
  108. *
  109. * Parameters:
  110. * hwndDlg Handle to parent dialog box.
  111. *
  112. * Returns:
  113. * TRUE if function is successful, FALSE otherwise.
  114. */
  115. BOOL CALLBACK
  116. FFillDebugListbox(HWND hwndDlg)
  117. {
  118. TAG tag;
  119. LRESULT lresult;
  120. TGRC * ptgrc;
  121. HWND hwndListbox;
  122. CHAR rgch[80];
  123. HFONT hFont;
  124. // Get the listbox handle
  125. hwndListbox = GetDlgItem(hwndDlg, tmcListbox);
  126. Assert(hwndListbox);
  127. // Make sure it's clean
  128. SendMessageA(hwndListbox, CB_RESETCONTENT, 0, 0);
  129. hFont = (HFONT) GetStockObject(SYSTEM_FIXED_FONT);
  130. SendMessage(hwndListbox, WM_SETFONT, (WPARAM) hFont, FALSE);
  131. DeleteObject(hFont);
  132. // Enter strings into the listbox-check all tags.
  133. for (tag = tagMin; tag < tagMac; tag++)
  134. {
  135. // If tag is of correct type, enter the string for it.
  136. if (mptagtgrc[tag].TestFlag(TGRC_FLAG_VALID))
  137. {
  138. ptgrc = mptagtgrc + tag;
  139. #if 0 // old format
  140. _snprintf(rgch, sizeof(rgch), "%d : %s %s",
  141. tag, ptgrc->szOwner, ptgrc->szDescrip);
  142. #endif
  143. _snprintf(rgch, sizeof(rgch), "%-17.17s %s",
  144. ptgrc->szOwner, ptgrc->szDescrip);
  145. lresult = SendMessageA(hwndListbox, CB_ADDSTRING,
  146. 0, (DWORD_PTR)(LPVOID)rgch);
  147. if (lresult == CB_ERR || lresult == CB_ERRSPACE)
  148. return FALSE;
  149. lresult = SendMessageA(
  150. hwndListbox, CB_SETITEMDATA, lresult, tag);
  151. if (lresult == CB_ERR || lresult == CB_ERRSPACE)
  152. return FALSE;
  153. }
  154. }
  155. return TRUE;
  156. }
  157. /*
  158. * FDlgTraceEtc
  159. *
  160. * Purpose:
  161. * Dialog procedure for Trace Points and Asserts dialogs.
  162. * Keeps the state of the checkboxes identical to
  163. * the state of the currently selected TAG in the listbox.
  164. *
  165. * Parameters:
  166. * hwndDlg Handle to dialog window
  167. * wm SDM dialog message
  168. * wparam
  169. * lparam Long parameter
  170. *
  171. * Returns:
  172. * TRUE if the function processed this message, FALSE if not.
  173. */
  174. BOOL CALLBACK
  175. DlgTraceEtc(HWND hwndDlg, UINT wm, WPARAM wparam, LPARAM lparam)
  176. {
  177. TAG tag;
  178. TGRC * ptgrc;
  179. DWORD wNew;
  180. BOOL fEnable; // enable all
  181. TGRC_FLAG tf;
  182. BOOL fTrace;
  183. HWND hwndListBox;
  184. char szTitle[MAX_PATH];
  185. switch (wm)
  186. {
  187. default:
  188. return FALSE;
  189. break;
  190. case WM_INITDIALOG:
  191. fDirtyDlg = FALSE;
  192. if (!FFillDebugListbox(hwndDlg))
  193. {
  194. MessageBoxA(hwndDlg,
  195. "Error initializing listbox. Cannot display dialog.",
  196. "Trace/Assert Dialog", MB_OK);
  197. EndButton(hwndDlg, 0, FALSE);
  198. break;
  199. }
  200. GetModuleFileNameA(NULL, szTitle, MAX_PATH);
  201. SetWindowText(hwndDlg, szTitle);
  202. hwndListBox = GetDlgItem(hwndDlg, tmcListbox);
  203. Assert(hwndListBox);
  204. SendMessage(hwndListBox, CB_SETCURSEL, 0, 0);
  205. SendMessage(
  206. hwndDlg,
  207. WM_COMMAND,
  208. MAKELONG(tmcListbox, CBN_SELCHANGE),
  209. (LPARAM) hwndListBox);
  210. SetForegroundWindow(hwndDlg);
  211. break;
  212. case WM_COMMAND:
  213. switch (LOWORD(wparam))
  214. {
  215. case tmcOk:
  216. case tmcCancel:
  217. EndButton(hwndDlg, LOWORD(wparam), fDirtyDlg);
  218. break;
  219. case tmcEnableAll:
  220. case tmcDisableAll:
  221. fDirtyDlg = TRUE;
  222. fEnable = FALSE;
  223. if (LOWORD(wparam) == tmcEnableAll)
  224. fEnable = TRUE;
  225. for (tag = tagMin; tag < tagMac; tag++)
  226. {
  227. mptagtgrc[tag].fEnabled = fEnable;
  228. }
  229. tag = TagFromSelection(hwndDlg, tmcListbox);
  230. CheckDlgButton(hwndDlg, tmcEnabled, fEnable);
  231. break;
  232. case tmcListbox:
  233. if (HIWORD(wparam) != CBN_SELCHANGE
  234. && HIWORD(wparam) != CBN_DBLCLK)
  235. break;
  236. fDirtyDlg = TRUE;
  237. tag = TagFromSelection(hwndDlg, tmcListbox);
  238. Assert(tag != tagNull);
  239. ptgrc = mptagtgrc + tag;
  240. if (HIWORD(wparam) == CBN_DBLCLK)
  241. ptgrc->fEnabled = !ptgrc->fEnabled;
  242. CheckDlgButton(hwndDlg, tmcEnabled, ptgrc->fEnabled);
  243. CheckDlgButton(hwndDlg, tmcDisk, ptgrc->TestFlag(TGRC_FLAG_DISK));
  244. CheckDlgButton(hwndDlg, tmcCom1, ptgrc->TestFlag(TGRC_FLAG_COM1));
  245. CheckDlgButton(hwndDlg, tmcBreak, ptgrc->TestFlag(TGRC_FLAG_BREAK));
  246. fTrace = (ptgrc->tgty == tgtyTrace);
  247. EnableWindow(GetDlgItem(hwndDlg, tmcDisk), fTrace);
  248. EnableWindow(GetDlgItem(hwndDlg, tmcCom1), fTrace);
  249. EnableWindow(GetDlgItem(hwndDlg, tmcBreak), fTrace);
  250. break;
  251. case tmcEnabled:
  252. case tmcDisk:
  253. case tmcCom1:
  254. case tmcBreak:
  255. fDirtyDlg = TRUE;
  256. tag = TagFromSelection(hwndDlg, tmcListbox);
  257. ptgrc = mptagtgrc + tag;
  258. wNew = IsDlgButtonChecked(hwndDlg, LOWORD(wparam));
  259. if (LOWORD(wparam) == tmcEnabled)
  260. {
  261. ptgrc->fEnabled = wNew;
  262. }
  263. else
  264. {
  265. switch (LOWORD(wparam))
  266. {
  267. case tmcDisk:
  268. tf = TGRC_FLAG_DISK;
  269. break;
  270. case tmcCom1:
  271. tf = TGRC_FLAG_COM1;
  272. break;
  273. case tmcBreak:
  274. tf = TGRC_FLAG_BREAK;
  275. break;
  276. default:
  277. Assert(0 && "Logic error in DlgTraceEtc");
  278. tf = (TGRC_FLAG) 0;
  279. break;
  280. }
  281. ptgrc->SetFlagValue(tf, wNew);
  282. }
  283. }
  284. break;
  285. }
  286. return TRUE;
  287. }
  288. /*
  289. * EndButton
  290. *
  291. * Purpose:
  292. * Does necessary processing when either OK or Cancel is pressed in
  293. * any of the debug dialogs. If OK is pressed, the debug state is
  294. * saved if dirty. If Cancel is hit, the debug state is restored if
  295. * dirty.
  296. *
  297. * In Windows, the EndDialog function must also be called.
  298. *
  299. * Parameters:
  300. * tmc tmc of the button pressed, either tmcOk or tmcCancel.
  301. * fDirty indicates if the debug state has been modified.
  302. */
  303. void
  304. EndButton(HWND hwndDlg, TMC tmc, BOOL fDirty)
  305. {
  306. HCURSOR hCursor;
  307. if (fDirty)
  308. {
  309. hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
  310. ShowCursor(TRUE);
  311. if (tmc == tmcOk)
  312. SaveDefaultDebugState();
  313. else
  314. RestoreDefaultDebugState();
  315. ShowCursor(FALSE);
  316. SetCursor(hCursor);
  317. }
  318. EndDialog(hwndDlg, tmc == tmcOk);
  319. return;
  320. }
  321. /*
  322. * TagFromSelection
  323. *
  324. * Purpose:
  325. * Isolation function for dialog procedures to eliminate a bunch of
  326. * ifdef's everytime the index of the selection in the current listbox
  327. * is requried.
  328. *
  329. * Parameters:
  330. * tmc ID value of the listbox.
  331. *
  332. * Returns:
  333. * ctag for the currently selected listbox item.
  334. */
  335. WORD
  336. TagFromSelection(HWND hwndDlg, TMC tmc)
  337. {
  338. HWND hwndListbox;
  339. LRESULT lresult;
  340. hwndListbox = GetDlgItem(hwndDlg, tmcListbox);
  341. Assert(hwndListbox);
  342. lresult = SendMessageA(hwndListbox, CB_GETCURSEL, 0, 0);
  343. Assert(lresult >= 0);
  344. lresult = SendMessageA(hwndListbox, CB_GETITEMDATA, lresult, 0);
  345. Assert(tagMin <= lresult && lresult < tagMac);
  346. return (WORD) lresult;
  347. }
  348. #endif // _DEBUG