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.

263 lines
9.8 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 "setedit.h"
  12. #include "graph.h"
  13. #include "cderr.h"
  14. #include "utils.h"
  15. #include "perfmops.h"
  16. #include "grafdata.h" // for ToggleGraphRefresh
  17. #include "pmhelpid.h" // Help IDs
  18. BOOL LocalManualRefresh ;
  19. INT_PTR
  20. GraphOptionDlg(
  21. HWND hDlg,
  22. UINT msg,
  23. WPARAM wParam,
  24. LPARAM lParam
  25. )
  26. {
  27. static GRAPH_OPTIONS goLocalCopy ;
  28. INT iTimeMilliseconds ;
  29. TCHAR szBuff[MiscTextLen] ;
  30. PGRAPHSTRUCT lgraph;
  31. lParam ;
  32. lgraph = pGraphs;
  33. switch (msg) {
  34. case WM_INITDIALOG:
  35. dwCurrentDlgID = HC_PM_idDlgOptionChart ;
  36. // Init the Radio button, Check boxes and text fields.
  37. goLocalCopy.iGraphOrHistogram =
  38. lgraph->gOptions.iGraphOrHistogram ;
  39. if (lgraph->gOptions.iGraphOrHistogram == LINE_GRAPH)
  40. CheckRadioButton(hDlg, ID_GRAPH, ID_HISTOGRAM, ID_GRAPH) ;
  41. else
  42. CheckRadioButton(hDlg, ID_GRAPH, ID_HISTOGRAM, ID_HISTOGRAM) ;
  43. CheckDlgButton(hDlg, ID_LEGEND, lgraph->gOptions.bLegendChecked) ;
  44. if (!(lgraph->gOptions.bLegendChecked)) {
  45. // can't display valuebar w/o legend
  46. DialogEnable (hDlg, IDD_CHARTOPTIONSVALUEBAR, FALSE) ;
  47. }
  48. CheckDlgButton(hDlg, ID_LABELS, lgraph->gOptions.bLabelsChecked) ;
  49. CheckDlgButton(hDlg, ID_VERT_GRID, lgraph->gOptions.bVertGridChecked) ;
  50. CheckDlgButton(hDlg, ID_HORZ_GRID, lgraph->gOptions.bHorzGridChecked) ;
  51. CheckDlgButton(hDlg, IDD_CHARTOPTIONSVALUEBAR,
  52. lgraph->gOptions.bStatusBarChecked) ;
  53. TSPRINTF(szBuff, TEXT("%d"), lgraph->gOptions.iVertMax) ;
  54. SendDlgItemMessage(hDlg, ID_VERT_MAX, WM_SETTEXT, 0, (LPARAM) szBuff) ;
  55. TSPRINTF(szBuff, TEXT("%3.3f"), lgraph->gOptions.eTimeInterval) ;
  56. ConvertDecimalPoint (szBuff);
  57. SendDlgItemMessage(hDlg, IDD_CHARTOPTIONSINTERVAL, WM_SETTEXT, 0, (LPARAM) szBuff) ;
  58. // Pickup a local copy of the Graph Options.
  59. goLocalCopy = lgraph->gOptions ;
  60. LocalManualRefresh = lgraph->bManualRefresh ;
  61. CheckRadioButton (hDlg,
  62. IDD_CHARTOPTIONSMANUALREFRESH,
  63. IDD_CHARTOPTIONSPERIODIC,
  64. LocalManualRefresh ? IDD_CHARTOPTIONSMANUALREFRESH :
  65. IDD_CHARTOPTIONSPERIODIC) ;
  66. if (lgraph->bManualRefresh) {
  67. DialogEnable (hDlg, IDD_CHARTOPTIONSINTERVALTEXT, FALSE) ;
  68. DialogEnable (hDlg, IDD_CHARTOPTIONSINTERVAL, FALSE) ;
  69. } else {
  70. DialogEnable (hDlg, IDD_CHARTOPTIONSINTERVALTEXT, TRUE) ;
  71. DialogEnable (hDlg, IDD_CHARTOPTIONSINTERVAL, TRUE) ;
  72. }
  73. EditSetLimit (GetDlgItem(hDlg, ID_VERT_MAX),
  74. sizeof(szBuff) / sizeof(TCHAR) - 1) ;
  75. EditSetLimit (GetDlgItem(hDlg, IDD_CHARTOPTIONSINTERVAL),
  76. ShortTextLen) ;
  77. WindowCenter (hDlg) ;
  78. return(TRUE);
  79. case WM_COMMAND:
  80. switch (LOWORD(wParam)) {
  81. case ID_VERT_MAX:
  82. if (HIWORD(wParam) == EN_CHANGE) {
  83. DialogText(hDlg, ID_VERT_MAX, szBuff) ;
  84. swscanf(szBuff, TEXT("%d"), &goLocalCopy.iVertMax) ;
  85. }
  86. break ;
  87. case IDD_CHARTOPTIONSINTERVAL:
  88. if (HIWORD(wParam) == EN_CHANGE) {
  89. goLocalCopy.eTimeInterval =
  90. DialogFloat (hDlg, IDD_CHARTOPTIONSINTERVAL, NULL) ;
  91. }
  92. break ;
  93. case IDD_CHARTOPTIONSPERIODIC:
  94. case IDD_CHARTOPTIONSMANUALREFRESH:
  95. // check if the Manual refresh is currently checked.
  96. // Then toggle the ManualRefresh button
  97. LocalManualRefresh =
  98. IsDlgButtonChecked (hDlg, IDD_CHARTOPTIONSMANUALREFRESH) ;
  99. CheckRadioButton (hDlg,
  100. IDD_CHARTOPTIONSMANUALREFRESH,
  101. IDD_CHARTOPTIONSPERIODIC,
  102. LocalManualRefresh ? IDD_CHARTOPTIONSPERIODIC :
  103. IDD_CHARTOPTIONSMANUALREFRESH) ;
  104. // gray out time interval if necessary...
  105. DialogEnable (hDlg, IDD_CHARTOPTIONSINTERVALTEXT,
  106. LocalManualRefresh) ;
  107. DialogEnable (hDlg, IDD_CHARTOPTIONSINTERVAL,
  108. LocalManualRefresh) ;
  109. LocalManualRefresh = !LocalManualRefresh ;
  110. break ;
  111. case IDD_CHARTOPTIONSVALUEBAR:
  112. if (goLocalCopy.bStatusBarChecked == TRUE)
  113. goLocalCopy.bStatusBarChecked = FALSE ;
  114. else
  115. goLocalCopy.bStatusBarChecked = TRUE ;
  116. break ;
  117. case ID_LEGEND:
  118. if (goLocalCopy.bLegendChecked == TRUE)
  119. goLocalCopy.bLegendChecked = FALSE ;
  120. else
  121. goLocalCopy.bLegendChecked = TRUE ;
  122. DialogEnable (hDlg, IDD_CHARTOPTIONSVALUEBAR,
  123. goLocalCopy.bLegendChecked) ;
  124. break ;
  125. case ID_LABELS:
  126. if (goLocalCopy.bLabelsChecked == TRUE)
  127. goLocalCopy.bLabelsChecked = FALSE ;
  128. else
  129. goLocalCopy.bLabelsChecked = TRUE ;
  130. break ;
  131. case ID_VERT_GRID:
  132. if (goLocalCopy.bVertGridChecked == TRUE)
  133. goLocalCopy.bVertGridChecked = FALSE ;
  134. else
  135. goLocalCopy.bVertGridChecked = TRUE ;
  136. break ;
  137. case ID_HORZ_GRID:
  138. if (goLocalCopy.bHorzGridChecked == TRUE)
  139. goLocalCopy.bHorzGridChecked = FALSE ;
  140. else
  141. goLocalCopy.bHorzGridChecked = TRUE ;
  142. break ;
  143. case ID_GRAPH:
  144. case ID_HISTOGRAM:
  145. if (goLocalCopy.iGraphOrHistogram == BAR_GRAPH) {
  146. goLocalCopy.iGraphOrHistogram = LINE_GRAPH ;
  147. } else {
  148. goLocalCopy.iGraphOrHistogram = BAR_GRAPH ;
  149. }
  150. CheckRadioButton(hDlg, ID_GRAPH, ID_HISTOGRAM,
  151. goLocalCopy.iGraphOrHistogram == LINE_GRAPH ?
  152. ID_GRAPH : ID_HISTOGRAM) ;
  153. break ;
  154. case IDOK:
  155. // verify some numeric entries first
  156. if (goLocalCopy.iVertMax > MAX_VERTICAL ||
  157. goLocalCopy.iVertMax < MIN_VERTICAL) {
  158. DlgErrorBox (hDlg, ERR_BADVERTMAX) ;
  159. SetFocus (DialogControl (hDlg, ID_VERT_MAX)) ;
  160. EditSetTextEndPos (hDlg, ID_VERT_MAX) ;
  161. return (FALSE) ;
  162. break ;
  163. }
  164. if (goLocalCopy.eTimeInterval > MAX_INTERVALSEC ||
  165. goLocalCopy.eTimeInterval < MIN_INTERVALSEC) {
  166. DlgErrorBox (hDlg, ERR_BADTIMEINTERVAL) ;
  167. SetFocus (DialogControl (hDlg, IDD_CHARTOPTIONSINTERVAL)) ;
  168. EditSetTextEndPos (hDlg, IDD_CHARTOPTIONSINTERVAL) ;
  169. return (FALSE) ;
  170. break ;
  171. }
  172. // We need to send a size message to the main window
  173. // so it can setup the redraw of the graph and legend.
  174. lgraph->gOptions.bLegendChecked = goLocalCopy.bLegendChecked ;
  175. lgraph->gOptions.bStatusBarChecked = goLocalCopy.bStatusBarChecked ;
  176. if (lgraph->gOptions.eTimeInterval != goLocalCopy.eTimeInterval
  177. && !LocalManualRefresh) {
  178. iTimeMilliseconds = (INT) (goLocalCopy.eTimeInterval * (FLOAT) 1000.0) ;
  179. pGraphs->gInterval = iTimeMilliseconds ;
  180. lgraph->bManualRefresh = LocalManualRefresh ;
  181. } else if (LocalManualRefresh != lgraph->bManualRefresh) {
  182. ToggleGraphRefresh (hWndGraph) ;
  183. }
  184. // Assign the local copy of the graph options to the
  185. // global copy.
  186. lgraph->gOptions = goLocalCopy ;
  187. // SizeGraphComponents (hWndGraph) ;
  188. // WindowInvalidate (hWndGraph) ;
  189. dwCurrentDlgID = 0 ;
  190. EndDialog (hDlg, 1) ;
  191. return (TRUE) ;
  192. break ;
  193. case IDCANCEL:
  194. dwCurrentDlgID = 0 ;
  195. EndDialog(hDlg,0);
  196. return(TRUE);
  197. case ID_HELP:
  198. CallWinHelp (dwCurrentDlgID) ;
  199. break ;
  200. default:
  201. break;
  202. }
  203. break;
  204. default:
  205. break;
  206. }
  207. return(FALSE);
  208. }