Leaked source code of windows server 2003
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.

522 lines
15 KiB

  1. /*++
  2. Copyright (C) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. genprop.cpp
  5. Abstract:
  6. <abstract>
  7. --*/
  8. #include "polyline.h"
  9. #include <strsafe.h>
  10. #include <assert.h>
  11. #include "genprop.h"
  12. #include "utils.h"
  13. #include "strids.h"
  14. #include "smonctrl.h"
  15. #include "winhelpr.h"
  16. CGeneralPropPage::CGeneralPropPage ( void )
  17. /*++
  18. Routine Description:
  19. Constructor for CGeneralPropPage class. Initializes the member variables.
  20. Arguments:
  21. None.
  22. Return Value:
  23. None.
  24. --*/
  25. {
  26. m_uIDDialog = IDD_GEN_PROPP_DLG;
  27. m_uIDTitle = IDS_GEN_PROPP_TITLE;
  28. return;
  29. }
  30. CGeneralPropPage::~CGeneralPropPage (
  31. VOID
  32. )
  33. /*++
  34. Routine Description:
  35. Destructor for CGeneralPropPage class. .
  36. Arguments:
  37. None.
  38. Return Value:
  39. None.
  40. --*/
  41. {
  42. return;
  43. }
  44. BOOL
  45. CGeneralPropPage::InitControls(
  46. VOID
  47. )
  48. {
  49. HWND hWndItem = NULL;
  50. hWndItem = GetDlgItem(m_hDlg, IDC_UPDATE_INTERVAL);
  51. if ( NULL != hWndItem ) {
  52. EditSetLimit(hWndItem, MAX_INTERVAL_DIGITS);
  53. hWndItem = NULL;
  54. }
  55. hWndItem = DialogControl (m_hDlg, IDC_COMBOAPPEARANCE) ;
  56. if ( NULL != hWndItem ) {
  57. CBAdd (hWndItem, ResourceString(IDS_APPEARANCE_FLAT));
  58. CBSetData( hWndItem, 0, eAppearFlat );
  59. CBAdd (hWndItem, ResourceString(IDS_APPEARANCE_3D));
  60. CBSetData( hWndItem, 1, eAppear3D );
  61. hWndItem = NULL;
  62. }
  63. hWndItem = DialogControl (m_hDlg, IDC_COMBOBORDERSTYLE) ;
  64. if ( NULL != hWndItem ) {
  65. CBAdd (hWndItem, ResourceString(IDS_BORDERSTYLE_NONE));
  66. CBSetData( hWndItem, 0, eBorderNone );
  67. CBAdd (hWndItem, ResourceString(IDS_BORDERSTYLE_SINGLE));
  68. CBSetData( hWndItem, 1, eBorderSingle );
  69. hWndItem = NULL;
  70. }
  71. return TRUE;
  72. //assert( IsWindowUnicode( m_hDlg ) );
  73. //assert( IsWindowUnicode( hWndItem ) );
  74. }
  75. BOOL
  76. CGeneralPropPage::GetProperties(
  77. VOID
  78. )
  79. /*++
  80. Routine Description:
  81. GetProperties fetches the selected graph's properties via the
  82. ISystemMonitor interface and loads them into the property page dialog.
  83. It also clears all the propery change flags.
  84. Arguments:
  85. None.
  86. Return Value:
  87. Boolean status - TRUE = success
  88. --*/
  89. {
  90. WCHAR szBuff[MAX_VALUE_LEN];
  91. ISystemMonitor *pObj;
  92. INT iPrecision;
  93. HWND hWndItem;
  94. // Make sure a control is selected
  95. if (m_cObjects == 0)
  96. return FALSE;
  97. // Use only the first one
  98. pObj = m_ppISysmon[0];
  99. // Load each graph property
  100. pObj->get_DisplayType(&m_eDisplayType);
  101. CheckRadioButton(m_hDlg, IDC_GALLERY_GRAPH, IDC_GALLERY_REPORT,
  102. IDC_GALLERY_GRAPH + m_eDisplayType - 1);
  103. pObj->get_ReportValueType(&m_eReportValueType);
  104. CheckRadioButton(m_hDlg, IDC_RPT_VALUE_DEFAULT, IDC_RPT_VALUE_MAXIMUM,
  105. IDC_RPT_VALUE_DEFAULT + m_eReportValueType);
  106. pObj->get_ShowLegend(&m_bLegend) ;
  107. CheckDlgButton(m_hDlg, IDC_LEGEND, m_bLegend);
  108. pObj->get_ShowToolbar (&m_bToolbar);
  109. CheckDlgButton (m_hDlg, IDC_TOOLBAR, m_bToolbar);
  110. pObj->get_ShowValueBar(&m_bValueBar);
  111. CheckDlgButton(m_hDlg, IDC_VALUEBAR, m_bValueBar) ;
  112. pObj->get_MonitorDuplicateInstances(&m_bMonitorDuplicateInstances);
  113. CheckDlgButton(m_hDlg, IDC_DUPLICATE_INSTANCE, m_bMonitorDuplicateInstances) ;
  114. pObj->get_Appearance(&m_iAppearance);
  115. hWndItem = DialogControl (m_hDlg, IDC_COMBOAPPEARANCE) ;
  116. CBSetSelection (hWndItem, m_iAppearance) ;
  117. pObj->get_BorderStyle(&m_iBorderStyle);
  118. hWndItem = DialogControl (m_hDlg, IDC_COMBOBORDERSTYLE) ;
  119. CBSetSelection (hWndItem, m_iBorderStyle) ;
  120. pObj->get_UpdateInterval(&m_fSampleInterval);
  121. ((INT)(100 * m_fSampleInterval) != 100 * (INT)m_fSampleInterval) ? iPrecision = 2 : iPrecision = 0;
  122. FormatNumber ( m_fSampleInterval, szBuff, MAX_VALUE_LEN, 0, iPrecision );
  123. SetDlgItemText(m_hDlg, IDC_UPDATE_INTERVAL, szBuff) ;
  124. pObj->get_DisplayFilter(&m_iDisplayInterval);
  125. StringCchPrintf(szBuff, MAX_VALUE_LEN, L"%d", m_iDisplayInterval) ;
  126. SetDlgItemText(m_hDlg, IDC_DISPLAY_INTERVAL, szBuff) ;
  127. pObj->get_ManualUpdate(&m_bManualUpdate);
  128. CheckDlgButton (m_hDlg, IDC_PERIODIC_UPDATE, !m_bManualUpdate);
  129. // If manual update, disable sample (update) and display intervals
  130. DialogEnable (m_hDlg, IDC_UPDATE_INTERVAL, !m_bManualUpdate) ;
  131. DialogEnable (m_hDlg, IDC_INTERVAL_LABEL, !m_bManualUpdate) ;
  132. DialogEnable (m_hDlg, IDC_DISPLAY_INTERVAL, !m_bManualUpdate) ;
  133. DialogEnable (m_hDlg, IDC_DISPLAY_INT_LABEL1, !m_bManualUpdate) ;
  134. DialogEnable (m_hDlg, IDC_DISPLAY_INT_LABEL2, !m_bManualUpdate) ;
  135. // Clear all change flags
  136. m_bLegendChg = FALSE;
  137. m_bValueBarChg = FALSE;
  138. m_bToolbarChg = FALSE;
  139. m_bSampleIntervalChg = FALSE;
  140. m_bDisplayIntervalChg = FALSE;
  141. m_bDisplayTypeChg = FALSE;
  142. m_bReportValueTypeChg = FALSE;
  143. m_bManualUpdateChg = FALSE;
  144. m_bAppearanceChg = FALSE;
  145. m_bBorderStyleChg = FALSE;
  146. m_bMonitorDuplicateInstancesChg = FALSE;
  147. // Clear error flags
  148. m_iErrSampleInterval = 0;
  149. m_iErrDisplayInterval = 0;
  150. return TRUE;
  151. }
  152. BOOL
  153. CGeneralPropPage::SetProperties (
  154. VOID
  155. )
  156. /*++
  157. Routine Description:
  158. SetProperties writes the changed graph properties to the selected control
  159. via the ISystemMonitor interface. It then resets all the change flags.
  160. Arguments:
  161. None.
  162. Return Value:
  163. Boolean status - TRUE = success
  164. --*/
  165. {
  166. ISystemMonitor *pObj;
  167. // Make sure a control is selected
  168. if (m_cObjects == 0)
  169. return FALSE;
  170. // Use only the first control
  171. pObj = m_ppISysmon[0];
  172. // Check for invalid data
  173. if ( !m_bManualUpdate ) {
  174. if ( m_iErrSampleInterval ) {
  175. MessageBox (m_hDlg, ResourceString(IDS_INTERVAL_ERR), ResourceString(IDS_APP_NAME), MB_OK | MB_ICONEXCLAMATION) ;
  176. SetFocus ( GetDlgItem ( m_hDlg, IDC_UPDATE_INTERVAL ) );
  177. return FALSE;
  178. }
  179. if ( m_iErrDisplayInterval ) {
  180. MessageBox (m_hDlg, ResourceString(IDS_DISPLAY_INT_ERR), ResourceString(IDS_APP_NAME), MB_OK | MB_ICONEXCLAMATION) ;
  181. SetFocus ( GetDlgItem ( m_hDlg, IDC_DISPLAY_INTERVAL ) );
  182. return FALSE;
  183. }
  184. }
  185. // Write each changed property to the control
  186. if (m_bLegendChg)
  187. pObj->put_ShowLegend(m_bLegend);
  188. if (m_bToolbarChg)
  189. pObj->put_ShowToolbar(m_bToolbar);
  190. if (m_bValueBarChg)
  191. pObj->put_ShowValueBar(m_bValueBar);
  192. if (m_bSampleIntervalChg)
  193. pObj->put_UpdateInterval(m_fSampleInterval);
  194. if (m_bDisplayIntervalChg) {
  195. pObj->put_DisplayFilter(m_iDisplayInterval);
  196. }
  197. if (m_bDisplayTypeChg)
  198. pObj->put_DisplayType(m_eDisplayType);
  199. if (m_bReportValueTypeChg)
  200. pObj->put_ReportValueType(m_eReportValueType);
  201. if (m_bManualUpdateChg)
  202. pObj->put_ManualUpdate(m_bManualUpdate);
  203. if (m_bAppearanceChg)
  204. pObj->put_Appearance(m_iAppearance);
  205. if (m_bBorderStyleChg)
  206. pObj->put_BorderStyle(m_iBorderStyle);
  207. if (m_bMonitorDuplicateInstancesChg)
  208. pObj->put_MonitorDuplicateInstances(m_bMonitorDuplicateInstances);
  209. // Reset the change flags
  210. m_bLegendChg = FALSE;
  211. m_bValueBarChg = FALSE;
  212. m_bToolbarChg = FALSE;
  213. m_bSampleIntervalChg = FALSE;
  214. m_bDisplayIntervalChg = FALSE;
  215. m_bDisplayTypeChg = FALSE;
  216. m_bReportValueTypeChg = FALSE;
  217. m_bManualUpdateChg = FALSE;
  218. m_bAppearanceChg = FALSE;
  219. m_bBorderStyleChg = FALSE;
  220. return TRUE;
  221. }
  222. VOID
  223. CGeneralPropPage::DialogItemChange (
  224. IN WORD wID,
  225. IN WORD wMsg
  226. )
  227. /*++
  228. Routine Description:
  229. DialogItemChange handles changes to the property page dialog items. On
  230. each change it reads the new property value and set the property's change
  231. flag. On any change the SetChange routine is called to enable the "Apply"
  232. button.
  233. Arguments:
  234. wID - Dialog item ID
  235. wMsg - Notification code
  236. Return Value:
  237. None.
  238. --*/
  239. {
  240. BOOL fChange = FALSE;
  241. INT iTemp;
  242. BOOL bStat = FALSE;
  243. HWND hWndItem;
  244. // Case on dialog item ID
  245. switch(wID) {
  246. case IDC_UPDATE_INTERVAL:
  247. // On change, set change flags
  248. // Wait until focus lost to read final value
  249. if (wMsg == EN_CHANGE) {
  250. fChange = TRUE;
  251. m_bSampleIntervalChg = TRUE;
  252. }
  253. else if (wMsg == EN_KILLFOCUS) {
  254. m_fSampleInterval = DialogFloat(m_hDlg, IDC_UPDATE_INTERVAL, &bStat) ;
  255. if (bStat &&
  256. (m_fSampleInterval <= MAX_UPDATE_INTERVAL
  257. && m_fSampleInterval >= MIN_UPDATE_INTERVAL)) {
  258. m_iErrSampleInterval = 0;
  259. } else {
  260. m_iErrSampleInterval = IDS_INTERVAL_ERR;
  261. }
  262. }
  263. break ;
  264. case IDC_DISPLAY_INTERVAL:
  265. // On change, set change flags
  266. // Wait until focus lost to read final value
  267. if (wMsg == EN_CHANGE) {
  268. fChange = TRUE;
  269. m_bDisplayIntervalChg = TRUE;
  270. } else if (wMsg == EN_KILLFOCUS) {
  271. m_iDisplayInterval = GetDlgItemInt(m_hDlg, IDC_DISPLAY_INTERVAL, &bStat, FALSE);
  272. // TodoDisplayFilter: Support for display filter > sample filter.
  273. // TodoDisplayFilter: Display filter units = seconds instead of samples
  274. if ( 1 != m_iDisplayInterval ) {
  275. WCHAR szBuff[MAX_VALUE_LEN];
  276. MessageBox (
  277. m_hDlg,
  278. L"Display filter > 1 sample not yet implemented.\nDisplay interval in seconds not yet implemented.",
  279. ResourceString(IDS_APP_NAME), MB_OK | MB_ICONEXCLAMATION) ;
  280. m_iDisplayInterval = 1;
  281. StringCchPrintf(szBuff,MAX_VALUE_LEN, L"%d", m_iDisplayInterval) ;
  282. SetDlgItemText(m_hDlg, IDC_DISPLAY_INTERVAL, szBuff) ;
  283. } else {
  284. if ( FALSE == bStat) {
  285. m_iErrDisplayInterval = IDS_DISPLAY_INT_ERR;
  286. } else {
  287. m_iErrDisplayInterval = 0;
  288. }
  289. }
  290. }
  291. break ;
  292. case IDC_PERIODIC_UPDATE:
  293. if (wMsg == BN_CLICKED) {
  294. m_bManualUpdate = !m_bManualUpdate;
  295. m_bManualUpdateChg = TRUE;
  296. fChange = TRUE;
  297. // Disable sample (update) and display intervals if necessary
  298. DialogEnable (m_hDlg, IDC_INTERVAL_LABEL, !m_bManualUpdate) ;
  299. DialogEnable (m_hDlg, IDC_UPDATE_INTERVAL, !m_bManualUpdate) ;
  300. DialogEnable (m_hDlg, IDC_DISPLAY_INTERVAL, !m_bManualUpdate) ;
  301. DialogEnable (m_hDlg, IDC_DISPLAY_INT_LABEL1, !m_bManualUpdate) ;
  302. DialogEnable (m_hDlg, IDC_DISPLAY_INT_LABEL2, !m_bManualUpdate) ;
  303. }
  304. break ;
  305. case IDC_VALUEBAR:
  306. // If checkbox toggled, set change flags
  307. if (wMsg == BN_CLICKED) {
  308. m_bValueBar = !m_bValueBar;
  309. m_bValueBarChg = TRUE;
  310. fChange = TRUE;
  311. }
  312. break ;
  313. case IDC_LEGEND:
  314. // If checkbox toggled, set change flags
  315. if (wMsg == BN_CLICKED) {
  316. m_bLegend = !m_bLegend;
  317. m_bLegendChg = TRUE;
  318. fChange = TRUE;
  319. }
  320. break ;
  321. case IDC_TOOLBAR:
  322. if (wMsg == BN_CLICKED) {
  323. m_bToolbar = !m_bToolbar;
  324. m_bToolbarChg = TRUE;
  325. fChange = TRUE;
  326. }
  327. break;
  328. case IDC_COMBOAPPEARANCE:
  329. if (wMsg == CBN_SELCHANGE) {
  330. hWndItem = DialogControl(m_hDlg, IDC_COMBOAPPEARANCE);
  331. iTemp = (INT)CBSelection(hWndItem);
  332. if ( m_iAppearance != iTemp ) {
  333. m_bAppearanceChg = TRUE;
  334. fChange = TRUE;
  335. }
  336. m_iAppearance = iTemp;
  337. }
  338. break ;
  339. case IDC_COMBOBORDERSTYLE:
  340. if (wMsg == CBN_SELCHANGE) {
  341. hWndItem = DialogControl(m_hDlg, IDC_COMBOBORDERSTYLE);
  342. iTemp = (INT)CBSelection(hWndItem);
  343. if ( m_iBorderStyle != iTemp ) {
  344. m_bBorderStyleChg = TRUE;
  345. fChange = TRUE;
  346. }
  347. m_iBorderStyle = iTemp;
  348. }
  349. break ;
  350. case IDC_DUPLICATE_INSTANCE:
  351. // If checkbox toggled, set change flags
  352. if (wMsg == BN_CLICKED) {
  353. m_bMonitorDuplicateInstances = !m_bMonitorDuplicateInstances;
  354. m_bMonitorDuplicateInstancesChg = TRUE;
  355. fChange = TRUE;
  356. }
  357. break ;
  358. case IDC_GALLERY_GRAPH:
  359. case IDC_GALLERY_HISTOGRAM:
  360. case IDC_GALLERY_REPORT:
  361. // Check which button is involved
  362. iTemp = wID - IDC_GALLERY_GRAPH + 1;
  363. // If state changed
  364. if (wMsg == BN_CLICKED && iTemp != m_eDisplayType) {
  365. // Set change flags and update dialog
  366. fChange = TRUE;
  367. m_bDisplayTypeChg = TRUE;
  368. m_eDisplayType = (DisplayTypeConstants)iTemp;
  369. CheckRadioButton(m_hDlg, IDC_GALLERY_GRAPH,
  370. IDC_GALLERY_REPORT, wID);
  371. }
  372. break ;
  373. case IDC_RPT_VALUE_DEFAULT:
  374. case IDC_RPT_VALUE_CURRENT:
  375. case IDC_RPT_VALUE_AVERAGE:
  376. case IDC_RPT_VALUE_MINIMUM:
  377. case IDC_RPT_VALUE_MAXIMUM:
  378. // Check which button is involved
  379. iTemp = wID - IDC_RPT_VALUE_DEFAULT;
  380. // If state changed
  381. if (wMsg == BN_CLICKED && iTemp != m_eReportValueType) {
  382. // Set change flags and update dialog
  383. fChange = TRUE;
  384. m_bReportValueTypeChg = TRUE;
  385. m_eReportValueType = (ReportValueTypeConstants)iTemp;
  386. CheckRadioButton(m_hDlg, IDC_RPT_VALUE_DEFAULT,
  387. IDC_RPT_VALUE_MAXIMUM, wID);
  388. }
  389. break ;
  390. }
  391. // Enable "Apply" button on any change
  392. if (fChange)
  393. SetChange();
  394. }