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.

511 lines
18 KiB

  1. /*****************************************************************************
  2. *
  3. * Dialogs.c - This module handles the Menu and Dialog user interactions.
  4. *
  5. * Microsoft Confidential
  6. * Copyright (c) 1992-1993 Microsoft Corporation
  7. *
  8. ****************************************************************************/
  9. #include <stdio.h>
  10. #include <wchar.h> // for swscanf
  11. #include "perfmon.h"
  12. #include "perfmops.h" // for ConvertDecimalPoint
  13. #include "alert.h" // for SetAlertTimer, AlertData
  14. #include "graph.h"
  15. #include "cderr.h"
  16. #include "utils.h"
  17. #include "playback.h" // for PlayingBackLog
  18. #include "grafdisp.h" // for ToggleGraphRefresh
  19. #include "pmhelpid.h" // Help IDs
  20. BOOL LocalManualRefresh ;
  21. INT_PTR
  22. GraphOptionDlg(
  23. HWND hDlg,
  24. UINT msg,
  25. WPARAM wParam,
  26. LPARAM lParam
  27. )
  28. {
  29. static GRAPH_OPTIONS goLocalCopy ;
  30. INT iTimeMilliseconds ;
  31. TCHAR szBuff[MiscTextLen] ;
  32. PGRAPHSTRUCT lgraph;
  33. lParam ;
  34. lgraph = pGraphs;
  35. switch (msg) {
  36. case WM_INITDIALOG:
  37. dwCurrentDlgID = HC_PM_idDlgOptionChart ;
  38. // Init the Radio button, Check boxes and text fields.
  39. goLocalCopy.iGraphOrHistogram =
  40. lgraph->gOptions.iGraphOrHistogram ;
  41. if (lgraph->gOptions.iGraphOrHistogram == LINE_GRAPH)
  42. CheckRadioButton(hDlg, ID_GRAPH, ID_HISTOGRAM, ID_GRAPH) ;
  43. else
  44. CheckRadioButton(hDlg, ID_GRAPH, ID_HISTOGRAM, ID_HISTOGRAM) ;
  45. CheckDlgButton(hDlg, ID_LEGEND, lgraph->gOptions.bLegendChecked) ;
  46. if (!(lgraph->gOptions.bLegendChecked)) {
  47. // can't display valuebar w/o legend
  48. DialogEnable (hDlg, IDD_CHARTOPTIONSVALUEBAR, FALSE) ;
  49. }
  50. CheckDlgButton(hDlg, ID_LABELS, lgraph->gOptions.bLabelsChecked) ;
  51. CheckDlgButton(hDlg, ID_VERT_GRID, lgraph->gOptions.bVertGridChecked) ;
  52. CheckDlgButton(hDlg, ID_HORZ_GRID, lgraph->gOptions.bHorzGridChecked) ;
  53. CheckDlgButton(hDlg, IDD_CHARTOPTIONSVALUEBAR,
  54. lgraph->gOptions.bStatusBarChecked) ;
  55. TSPRINTF(szBuff, TEXT("%d"), lgraph->gOptions.iVertMax) ;
  56. SendDlgItemMessage(hDlg, ID_VERT_MAX, WM_SETTEXT, 0, (LONG_PTR) szBuff) ;
  57. TSPRINTF(szBuff, TEXT("%3.3f"), lgraph->gOptions.eTimeInterval) ;
  58. ConvertDecimalPoint (szBuff) ;
  59. SendDlgItemMessage(hDlg, IDD_CHARTOPTIONSINTERVAL, WM_SETTEXT, 0, (LONG_PTR) szBuff) ;
  60. // Pickup a local copy of the Graph Options.
  61. goLocalCopy = lgraph->gOptions ;
  62. LocalManualRefresh = lgraph->bManualRefresh ;
  63. if (PlayingBackLog()) {
  64. DialogEnable (hDlg, IDD_CHARTOPTIONSPERIODIC, FALSE) ;
  65. DialogEnable (hDlg, IDD_CHARTOPTIONSUPDATETEXT, FALSE) ;
  66. DialogEnable (hDlg, IDD_CHARTOPTIONSMANUALREFRESH, FALSE) ;
  67. } else {
  68. CheckRadioButton (hDlg,
  69. IDD_CHARTOPTIONSMANUALREFRESH,
  70. IDD_CHARTOPTIONSPERIODIC,
  71. LocalManualRefresh ? IDD_CHARTOPTIONSMANUALREFRESH :
  72. IDD_CHARTOPTIONSPERIODIC) ;
  73. }
  74. if (lgraph->bManualRefresh || PlayingBackLog()) {
  75. DialogEnable (hDlg, IDD_CHARTOPTIONSINTERVALTEXT, FALSE) ;
  76. DialogEnable (hDlg, IDD_CHARTOPTIONSINTERVAL, FALSE) ;
  77. } else {
  78. DialogEnable (hDlg, IDD_CHARTOPTIONSINTERVALTEXT, TRUE) ;
  79. DialogEnable (hDlg, IDD_CHARTOPTIONSINTERVAL, TRUE) ;
  80. }
  81. EditSetLimit (GetDlgItem(hDlg, ID_VERT_MAX),
  82. sizeof(szBuff) / sizeof(TCHAR) - 1) ;
  83. EditSetLimit (GetDlgItem(hDlg, IDD_CHARTOPTIONSINTERVAL),
  84. ShortTextLen) ;
  85. WindowCenter (hDlg) ;
  86. return(TRUE);
  87. case WM_COMMAND:
  88. switch (LOWORD(wParam)) {
  89. case ID_VERT_MAX:
  90. if (HIWORD(wParam) == EN_CHANGE) {
  91. DialogText(hDlg, ID_VERT_MAX, szBuff) ;
  92. swscanf(szBuff, TEXT("%d"), &goLocalCopy.iVertMax) ;
  93. }
  94. break ;
  95. case IDD_CHARTOPTIONSINTERVAL:
  96. if (HIWORD(wParam) == EN_CHANGE) {
  97. goLocalCopy.eTimeInterval =
  98. DialogFloat (hDlg, IDD_CHARTOPTIONSINTERVAL, NULL) ;
  99. }
  100. break ;
  101. case IDD_CHARTOPTIONSPERIODIC:
  102. case IDD_CHARTOPTIONSMANUALREFRESH:
  103. // check if the Manual refresh is currently checked.
  104. // Then toggle the ManualRefresh button
  105. LocalManualRefresh =
  106. (LOWORD(wParam) == IDD_CHARTOPTIONSMANUALREFRESH) ;
  107. CheckRadioButton (hDlg,
  108. IDD_CHARTOPTIONSMANUALREFRESH,
  109. IDD_CHARTOPTIONSPERIODIC,
  110. LocalManualRefresh ? IDD_CHARTOPTIONSMANUALREFRESH :
  111. IDD_CHARTOPTIONSPERIODIC) ;
  112. // gray out time interval if necessary...
  113. DialogEnable (hDlg, IDD_CHARTOPTIONSINTERVALTEXT,
  114. !LocalManualRefresh) ;
  115. DialogEnable (hDlg, IDD_CHARTOPTIONSINTERVAL,
  116. !LocalManualRefresh) ;
  117. break ;
  118. case IDD_CHARTOPTIONSVALUEBAR:
  119. if (goLocalCopy.bStatusBarChecked == TRUE)
  120. goLocalCopy.bStatusBarChecked = FALSE ;
  121. else
  122. goLocalCopy.bStatusBarChecked = TRUE ;
  123. break ;
  124. case ID_LEGEND:
  125. if (goLocalCopy.bLegendChecked == TRUE)
  126. goLocalCopy.bLegendChecked = FALSE ;
  127. else
  128. goLocalCopy.bLegendChecked = TRUE ;
  129. DialogEnable (hDlg, IDD_CHARTOPTIONSVALUEBAR,
  130. goLocalCopy.bLegendChecked) ;
  131. break ;
  132. case ID_LABELS:
  133. if (goLocalCopy.bLabelsChecked == TRUE)
  134. goLocalCopy.bLabelsChecked = FALSE ;
  135. else
  136. goLocalCopy.bLabelsChecked = TRUE ;
  137. break ;
  138. case ID_VERT_GRID:
  139. if (goLocalCopy.bVertGridChecked == TRUE)
  140. goLocalCopy.bVertGridChecked = FALSE ;
  141. else
  142. goLocalCopy.bVertGridChecked = TRUE ;
  143. break ;
  144. case ID_HORZ_GRID:
  145. if (goLocalCopy.bHorzGridChecked == TRUE)
  146. goLocalCopy.bHorzGridChecked = FALSE ;
  147. else
  148. goLocalCopy.bHorzGridChecked = TRUE ;
  149. break ;
  150. case ID_GRAPH:
  151. case ID_HISTOGRAM:
  152. if (LOWORD(wParam) == ID_GRAPH) {
  153. goLocalCopy.iGraphOrHistogram = LINE_GRAPH ;
  154. } else {
  155. goLocalCopy.iGraphOrHistogram = BAR_GRAPH ;
  156. }
  157. CheckRadioButton(hDlg, ID_GRAPH, ID_HISTOGRAM,
  158. goLocalCopy.iGraphOrHistogram == LINE_GRAPH ?
  159. ID_GRAPH : ID_HISTOGRAM) ;
  160. break ;
  161. case IDOK:
  162. // verify some numeric entries first
  163. if (goLocalCopy.iVertMax > MAX_VERTICAL ||
  164. goLocalCopy.iVertMax < MIN_VERTICAL) {
  165. DlgErrorBox (hDlg, ERR_BADVERTMAX) ;
  166. SetFocus (DialogControl (hDlg, ID_VERT_MAX)) ;
  167. EditSetTextEndPos (hDlg, ID_VERT_MAX) ;
  168. return (FALSE) ;
  169. break ;
  170. }
  171. if (goLocalCopy.eTimeInterval > MAX_INTERVALSEC ||
  172. goLocalCopy.eTimeInterval < MIN_INTERVALSEC) {
  173. DlgErrorBox (hDlg, ERR_BADTIMEINTERVAL) ;
  174. SetFocus (DialogControl (hDlg, IDD_CHARTOPTIONSINTERVAL)) ;
  175. EditSetTextEndPos (hDlg, IDD_CHARTOPTIONSINTERVAL) ;
  176. return (FALSE) ;
  177. break ;
  178. }
  179. // We need to send a size message to the main window
  180. // so it can setup the redraw of the graph and legend.
  181. lgraph->gOptions.bLegendChecked = goLocalCopy.bLegendChecked ;
  182. lgraph->gOptions.bStatusBarChecked = goLocalCopy.bStatusBarChecked ;
  183. if (lgraph->gOptions.eTimeInterval != goLocalCopy.eTimeInterval
  184. && !LocalManualRefresh) {
  185. iTimeMilliseconds = (INT) (goLocalCopy.eTimeInterval * (FLOAT) 1000.0) ;
  186. pGraphs->gInterval = iTimeMilliseconds ;
  187. if (!PlayingBackLog()) {
  188. SetGraphTimer(pGraphs) ;
  189. }
  190. lgraph->bManualRefresh = LocalManualRefresh ;
  191. } else if (LocalManualRefresh != lgraph->bManualRefresh) {
  192. ToggleGraphRefresh (hWndGraph) ;
  193. }
  194. // Assign the local copy of the graph options to the
  195. // global copy.
  196. lgraph->gOptions = goLocalCopy ;
  197. SizeGraphComponents (hWndGraph) ;
  198. WindowInvalidate (hWndGraph) ;
  199. dwCurrentDlgID = 0 ;
  200. EndDialog (hDlg, 1) ;
  201. return (TRUE) ;
  202. break ;
  203. case IDCANCEL:
  204. dwCurrentDlgID = 0 ;
  205. EndDialog(hDlg,0);
  206. return(TRUE);
  207. case ID_HELP:
  208. CallWinHelp (dwCurrentDlgID, hDlg) ;
  209. break ;
  210. default:
  211. break;
  212. }
  213. break;
  214. default:
  215. break;
  216. }
  217. return(FALSE);
  218. }
  219. DWORD iIntervalMSecs ;
  220. void
  221. static
  222. OnAlertOptionDlgInit (
  223. HWND hDlg,
  224. PALERT pAlert
  225. )
  226. {
  227. BOOL EnableFlag ;
  228. iIntervalMSecs = pAlert->iIntervalMSecs ;
  229. LocalManualRefresh = pAlert->bManualRefresh ;
  230. if (PlayingBackLog()) {
  231. // When playingback log, disable all controls except
  232. // the alert interval
  233. //
  234. EnableFlag = TRUE ;
  235. DialogEnable (hDlg, IDD_ALERTOPTIONSMANUALREFRESH, FALSE) ;
  236. DialogEnable (hDlg, IDD_ALERTOPTIONSPOPUP, FALSE) ;
  237. DialogEnable (hDlg, IDD_ALERTOPTIONSNETWORKALERT, FALSE) ;
  238. DialogEnable (hDlg, IDD_ALERTOPTIONSNETGROUPTEXT, FALSE) ;
  239. DialogEnable (hDlg, IDD_ALERTOPTIONSMSGNAME, FALSE) ;
  240. DialogEnable (hDlg, IDD_ALERTOPTIONSMSGNAMETEXT, FALSE) ;
  241. } else {
  242. EnableFlag = !LocalManualRefresh ;
  243. DialogEnable (hDlg, IDD_ALERTOPTIONSMSGNAME, pAlert->bNetworkAlert) ;
  244. DialogEnable (hDlg, IDD_ALERTOPTIONSMSGNAMETEXT, pAlert->bNetworkAlert) ;
  245. }
  246. // setup the Update time interval group items
  247. DialogSetInterval (hDlg, IDD_ALERTOPTIONSINTERVAL, iIntervalMSecs) ;
  248. DialogEnable (hDlg, IDD_ALERTOPTIONSINTERVAL, EnableFlag) ;
  249. DialogEnable (hDlg, IDD_ALERTOPTIONSINTERVALTEXT, EnableFlag) ;
  250. CheckRadioButton(hDlg, IDD_ALERTOPTIONSMANUALREFRESH,
  251. IDD_ALERTOPTIONSPERIODIC,
  252. !EnableFlag ? IDD_ALERTOPTIONSMANUALREFRESH : IDD_ALERTOPTIONSPERIODIC) ;
  253. CheckDlgButton (hDlg, IDD_ALERTOPTIONSEVENTLOG, pAlert->bEventLog) ;
  254. CheckDlgButton (hDlg, IDD_ALERTOPTIONSPOPUP, pAlert->bSwitchToAlert) ;
  255. CheckDlgButton (hDlg, IDD_ALERTOPTIONSNETWORKALERT, pAlert->bNetworkAlert) ;
  256. if (pAlert->MessageName[0]) {
  257. DialogSetString (hDlg, IDD_ALERTOPTIONSMSGNAME, pAlert->MessageName) ;
  258. }
  259. EditSetLimit (GetDlgItem(hDlg, IDD_ALERTOPTIONSMSGNAME),
  260. sizeof(pAlert->MessageName)/sizeof(TCHAR) - 1) ;
  261. dwCurrentDlgID = HC_PM_idDlgOptionAlert ;
  262. WindowCenter (hDlg) ;
  263. }
  264. INT_PTR
  265. AlertOptionDlg (
  266. HWND hDlg,
  267. UINT msg,
  268. WPARAM wParam,
  269. LPARAM lParam
  270. )
  271. {
  272. PALERT pAlert ;
  273. switch (msg) {
  274. case WM_INITDIALOG:
  275. pAlert = (PALERT) lParam ;
  276. OnAlertOptionDlgInit (hDlg, pAlert) ;
  277. return(TRUE);
  278. case WM_COMMAND:
  279. switch (LOWORD(wParam)) {
  280. case IDOK:
  281. {
  282. FLOAT eTimeInterval ;
  283. pAlert = AlertData (hWndAlert) ;
  284. eTimeInterval = DialogFloat (hDlg, IDD_ALERTOPTIONSINTERVAL, NULL) ;
  285. if (eTimeInterval > MAX_INTERVALSEC ||
  286. eTimeInterval < MIN_INTERVALSEC) {
  287. DlgErrorBox (hDlg, ERR_BADTIMEINTERVAL) ;
  288. SetFocus (DialogControl (hDlg, IDD_ALERTOPTIONSINTERVAL)) ;
  289. EditSetTextEndPos (hDlg, IDD_ALERTOPTIONSINTERVAL) ;
  290. return (FALSE) ;
  291. break ;
  292. }
  293. eTimeInterval = eTimeInterval * (FLOAT) 1000.0 +
  294. (FLOAT) 0.5 ;
  295. iIntervalMSecs = (DWORD) eTimeInterval ;
  296. pAlert->bNetworkAlert =
  297. IsDlgButtonChecked (hDlg, IDD_ALERTOPTIONSNETWORKALERT) ;
  298. pAlert->bSwitchToAlert =
  299. IsDlgButtonChecked (hDlg, IDD_ALERTOPTIONSPOPUP) ;
  300. pAlert->bEventLog =
  301. IsDlgButtonChecked (hDlg, IDD_ALERTOPTIONSEVENTLOG) ;
  302. if (!PlayingBackLog()) {
  303. DialogText (hDlg,
  304. IDD_ALERTOPTIONSMSGNAME,
  305. pAlert->MessageName) ;
  306. }
  307. dwCurrentDlgID = 0 ;
  308. EndDialog (hDlg, 1) ;
  309. }
  310. break ;
  311. case IDCANCEL:
  312. dwCurrentDlgID = 0 ;
  313. EndDialog(hDlg,0);
  314. return(TRUE);
  315. case IDD_ALERTOPTIONSPERIODIC:
  316. case IDD_ALERTOPTIONSMANUALREFRESH:
  317. if (!PlayingBackLog()) {
  318. // check if the Manual refresh is currently checked.
  319. // Then toggle the ManualRefresh button
  320. LocalManualRefresh =
  321. (LOWORD(wParam) == IDD_ALERTOPTIONSMANUALREFRESH) ;
  322. CheckRadioButton(hDlg,
  323. IDD_ALERTOPTIONSMANUALREFRESH,
  324. IDD_ALERTOPTIONSPERIODIC,
  325. LocalManualRefresh ? IDD_ALERTOPTIONSMANUALREFRESH :
  326. IDD_ALERTOPTIONSPERIODIC) ;
  327. DialogEnable (hDlg,
  328. IDD_ALERTOPTIONSINTERVAL,
  329. !LocalManualRefresh) ;
  330. DialogEnable (hDlg,
  331. IDD_ALERTOPTIONSINTERVALTEXT,
  332. !LocalManualRefresh) ;
  333. }
  334. break ;
  335. #if 0
  336. case IDD_ALERTOPTIONSPOPUP:
  337. bSwitchToAlert = !bSwitchToAlert ;
  338. CheckDlgButton (hDlg, IDD_ALERTOPTIONSPOPUP, bSwitchToAlert) ;
  339. break;
  340. #endif
  341. case IDD_ALERTOPTIONSNETWORKALERT:
  342. {
  343. BOOL bNetworkAlert ;
  344. bNetworkAlert =
  345. IsDlgButtonChecked (hDlg, IDD_ALERTOPTIONSNETWORKALERT) ;
  346. DialogEnable (hDlg, IDD_ALERTOPTIONSMSGNAME, bNetworkAlert) ;
  347. DialogEnable (hDlg, IDD_ALERTOPTIONSMSGNAMETEXT, bNetworkAlert) ;
  348. if (bNetworkAlert) {
  349. SetFocus (GetDlgItem(hDlg, IDD_ALERTOPTIONSMSGNAME)) ;
  350. SendDlgItemMessage(hDlg, IDD_ALERTOPTIONSMSGNAME,
  351. EM_SETSEL, 0, 16) ;
  352. }
  353. }
  354. break;
  355. case IDD_DISPLAYHELP:
  356. CallWinHelp (dwCurrentDlgID, hDlg) ;
  357. break ;
  358. default:
  359. break;
  360. }
  361. break;
  362. default:
  363. break;
  364. }
  365. return (FALSE);
  366. }
  367. BOOL
  368. DisplayAlertOptions (
  369. HWND hWndParent,
  370. HWND hWndAlert
  371. )
  372. {
  373. PALERT pAlert ;
  374. pAlert = AlertData (hWndParent) ;
  375. if (DialogBoxParam (hInstance, idDlgAlertOptions, hWndParent, AlertOptionDlg, (LPARAM) pAlert)) {
  376. if (pAlert->bNetworkAlert && pAlert->hNetAlertThread == 0) {
  377. AlertCreateThread (pAlert) ;
  378. }
  379. if (PlayingBackLog()) {
  380. if (pAlert->iIntervalMSecs != iIntervalMSecs) {
  381. // a new time interval, re-do the backing back log
  382. // using the new value...
  383. pAlert->iIntervalMSecs = iIntervalMSecs ;
  384. DialogSetInterval (hWndAlert, IDD_ALERTINTERVAL, iIntervalMSecs) ;
  385. if (pAlert->pLineFirst) {
  386. PlaybackAlert (hWndAlert, 0) ;
  387. WindowInvalidate (hWndAlert) ;
  388. }
  389. }
  390. } else if (LocalManualRefresh != pAlert->bManualRefresh) {
  391. if (!LocalManualRefresh) {
  392. pAlert->iIntervalMSecs = iIntervalMSecs ;
  393. DialogSetInterval (hWndAlert, IDD_ALERTINTERVAL, iIntervalMSecs) ;
  394. }
  395. ToggleAlertRefresh (hWndAlert) ;
  396. } else if (!LocalManualRefresh) {
  397. pAlert->iIntervalMSecs = iIntervalMSecs ;
  398. SetAlertTimer (pAlert) ;
  399. DialogSetInterval (hWndAlert, IDD_ALERTINTERVAL, iIntervalMSecs) ;
  400. }
  401. }
  402. return (TRUE) ;
  403. }