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.

526 lines
14 KiB

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