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.

340 lines
9.0 KiB

  1. /*++
  2. Copyright (C) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. grphprop.cpp
  5. Abstract:
  6. Implementation of the graph property page class.
  7. --*/
  8. #include "polyline.h"
  9. #include <strsafe.h>
  10. #include <assert.h>
  11. #include "grphprop.h"
  12. #include "utils.h"
  13. #include "strids.h"
  14. #include "unihelpr.h"
  15. #include "winhelpr.h"
  16. CGraphPropPage::CGraphPropPage()
  17. {
  18. m_uIDDialog = IDD_GRAPH_PROPP_DLG;
  19. m_uIDTitle = IDS_GRAPH_PROPP_TITLE;
  20. m_pszYaxisTitle = NULL;
  21. m_pszGraphTitle = NULL;
  22. }
  23. CGraphPropPage::~CGraphPropPage()
  24. {
  25. delete [] m_pszYaxisTitle;
  26. delete [] m_pszGraphTitle;
  27. }
  28. BOOL CGraphPropPage::InitControls()
  29. {
  30. HWND hwndItem = NULL;
  31. hwndItem = GetDlgItem(m_hDlg, IDC_VERTICAL_MAX);
  32. if ( NULL != hwndItem ) {
  33. EditSetLimit(hwndItem, MAX_SCALE_DIGITS);
  34. hwndItem = NULL;
  35. }
  36. hwndItem = GetDlgItem(m_hDlg, IDC_VERTICAL_MIN);
  37. if ( NULL != hwndItem ) {
  38. EditSetLimit(hwndItem, MAX_SCALE_DIGITS);
  39. hwndItem = NULL;
  40. }
  41. hwndItem = GetDlgItem(m_hDlg, IDC_GRAPH_TITLE);
  42. if ( NULL != hwndItem ) {
  43. EditSetLimit(hwndItem, MAX_TITLE_CHARS);
  44. hwndItem = NULL;
  45. }
  46. hwndItem = GetDlgItem(m_hDlg, IDC_YAXIS_TITLE);
  47. if ( NULL != hwndItem ) {
  48. EditSetLimit(hwndItem, MAX_TITLE_CHARS);
  49. hwndItem = NULL;
  50. }
  51. return TRUE;
  52. }
  53. /*
  54. * CGraphPropPage::GetProperties
  55. *
  56. */
  57. BOOL CGraphPropPage::GetProperties(void)
  58. {
  59. WCHAR szBuff[MAX_SCALE_DIGITS+1];
  60. ISystemMonitor *pObj;
  61. BSTR bstrTemp;
  62. LPWSTR pszTemp;
  63. if (m_cObjects == 0)
  64. return FALSE;
  65. pObj = m_ppISysmon[0];
  66. pObj->get_ShowScaleLabels(&m_bLabels);
  67. CheckDlgButton(m_hDlg, IDC_VERTICAL_LABELS, m_bLabels) ;
  68. pObj->get_ShowVerticalGrid(&m_bVertGrid);
  69. CheckDlgButton(m_hDlg, IDC_VERTICAL_GRID, m_bVertGrid) ;
  70. pObj->get_ShowHorizontalGrid(&m_bHorzGrid);
  71. CheckDlgButton(m_hDlg, IDC_HORIZONTAL_GRID, m_bHorzGrid) ;
  72. pObj->get_MaximumScale(&m_iVertMax);
  73. StringCchPrintf(szBuff, MAX_SCALE_DIGITS+1, L"%d", m_iVertMax) ;
  74. SetDlgItemText(m_hDlg, IDC_VERTICAL_MAX, szBuff) ;
  75. pObj->get_MinimumScale(&m_iVertMin);
  76. StringCchPrintf(szBuff, MAX_SCALE_DIGITS+1, L"%d", m_iVertMin) ;
  77. SetDlgItemText(m_hDlg, IDC_VERTICAL_MIN, szBuff) ;
  78. pObj->get_YAxisLabel(&bstrTemp);
  79. if (bstrTemp != NULL) {
  80. pszTemp = bstrTemp;
  81. m_pszYaxisTitle = new WCHAR[lstrlen(pszTemp)+1];
  82. if (m_pszYaxisTitle) {
  83. StringCchCopy(m_pszYaxisTitle, lstrlen(pszTemp)+1, pszTemp);
  84. SetDlgItemText(m_hDlg, IDC_YAXIS_TITLE, m_pszYaxisTitle);
  85. }
  86. SysFreeString(bstrTemp);
  87. }
  88. pObj->get_GraphTitle(&bstrTemp);
  89. if (bstrTemp != NULL) {
  90. pszTemp = bstrTemp;
  91. m_pszGraphTitle = new WCHAR[lstrlen(pszTemp)+1];
  92. if (m_pszGraphTitle) {
  93. StringCchCopy(m_pszGraphTitle, lstrlen(pszTemp)+1, pszTemp);
  94. SetDlgItemText(m_hDlg, IDC_GRAPH_TITLE, m_pszGraphTitle);
  95. }
  96. SysFreeString(bstrTemp);
  97. }
  98. // Clear change flags
  99. m_bLabelsChg = FALSE;
  100. m_bVertGridChg = FALSE;
  101. m_bHorzGridChg = FALSE;
  102. m_bVertMinChg = FALSE;
  103. m_bYaxisTitleChg = FALSE;
  104. m_bGraphTitleChg = FALSE;
  105. // Clear error flags
  106. m_iErrVertMax = 0;
  107. m_iErrVertMin = 0;
  108. return TRUE;
  109. }
  110. /*
  111. * CGraphPropPage::SetProperties
  112. *
  113. */
  114. BOOL CGraphPropPage::SetProperties(void)
  115. {
  116. ISystemMonitor *pObj;
  117. INT iMsgId = 0;
  118. BSTR pTitle;
  119. USES_CONVERSION
  120. // Get first object
  121. if (m_cObjects == 0)
  122. return FALSE;
  123. pObj = m_ppISysmon[0];
  124. // Check for invalid data
  125. if (m_iErrVertMax) {
  126. SetFocus(GetDlgItem(m_hDlg, IDC_VERTICAL_MAX));
  127. iMsgId = m_iErrVertMax;
  128. } else if (m_iErrVertMin) {
  129. SetFocus(GetDlgItem(m_hDlg, IDC_VERTICAL_MIN));
  130. iMsgId = m_iErrVertMin;
  131. } else if (m_iVertMax <= m_iVertMin) {
  132. SetFocus(GetDlgItem(m_hDlg, IDC_VERTICAL_MAX));
  133. iMsgId = IDS_SCALE_ERR;
  134. }
  135. // on error, alert user and exit
  136. if (iMsgId) {
  137. MessageBox(m_hDlg, ResourceString(iMsgId), ResourceString(IDS_APP_NAME), MB_OK | MB_ICONEXCLAMATION);
  138. return FALSE;
  139. }
  140. // Set all changed properties
  141. if (m_bLabelsChg)
  142. pObj->put_ShowScaleLabels(m_bLabels);
  143. if (m_bVertGridChg)
  144. pObj->put_ShowVerticalGrid(m_bVertGrid);
  145. if (m_bHorzGridChg)
  146. pObj->put_ShowHorizontalGrid(m_bHorzGrid);
  147. if (m_bVertMaxChg)
  148. pObj->put_MaximumScale(m_iVertMax);
  149. if (m_bVertMinChg)
  150. pObj->put_MinimumScale(m_iVertMin);
  151. if (m_bYaxisTitleChg) {
  152. pTitle = SysAllocString(m_pszYaxisTitle);
  153. pObj->put_YAxisLabel(pTitle);
  154. if (pTitle) {
  155. SysFreeString(pTitle);
  156. }
  157. }
  158. if (m_bGraphTitleChg) {
  159. pTitle = SysAllocString(m_pszGraphTitle);
  160. pObj->put_GraphTitle(pTitle);
  161. if (pTitle) {
  162. SysFreeString(pTitle);
  163. }
  164. }
  165. // Clear change flags
  166. m_bLabelsChg = FALSE;
  167. m_bVertGridChg = FALSE;
  168. m_bHorzGridChg = FALSE;
  169. m_bVertMinChg = FALSE;
  170. m_bYaxisTitleChg = FALSE;
  171. m_bGraphTitleChg = FALSE;
  172. return TRUE;
  173. }
  174. void CGraphPropPage::DialogItemChange(WORD wID, WORD wMsg)
  175. {
  176. WCHAR szTitleBuf[MAX_TITLE_CHARS+1];
  177. INT iTitleLen;
  178. LPWSTR pszTemp;
  179. BOOL fChange = FALSE;
  180. BOOL fResult;
  181. switch(wID) {
  182. case IDC_VERTICAL_MAX:
  183. if (wMsg == EN_CHANGE) {
  184. fChange = TRUE;
  185. m_bVertMaxChg = TRUE;
  186. } else if ((wMsg == EN_KILLFOCUS) && m_bVertMaxChg) {
  187. m_iVertMax = GetDlgItemInt(m_hDlg, IDC_VERTICAL_MAX, &fResult, FALSE);
  188. if (!fResult) {
  189. m_iErrVertMax = IDS_VERTMAX_ERR;
  190. } else {
  191. m_iErrVertMax = 0;
  192. }
  193. }
  194. break ;
  195. case IDC_VERTICAL_MIN:
  196. if (wMsg == EN_CHANGE) {
  197. fChange = TRUE;
  198. m_bVertMinChg = TRUE;
  199. } else if ((wMsg == EN_KILLFOCUS) && m_bVertMinChg) {
  200. m_iVertMin = GetDlgItemInt(m_hDlg, IDC_VERTICAL_MIN, &fResult, FALSE);
  201. if (!fResult) {
  202. m_iErrVertMin = IDS_VERTMIN_ERR;
  203. } else {
  204. m_iErrVertMin = 0;
  205. }
  206. }
  207. break ;
  208. case IDC_VERTICAL_LABELS:
  209. if (wMsg == BN_CLICKED)
  210. {
  211. m_bLabels = !m_bLabels;
  212. m_bLabelsChg = TRUE;
  213. fChange = TRUE;
  214. }
  215. break ;
  216. case IDC_VERTICAL_GRID:
  217. if (wMsg == BN_CLICKED)
  218. {
  219. m_bVertGrid = !m_bVertGrid;
  220. m_bVertGridChg = TRUE;
  221. fChange = TRUE;
  222. }
  223. break ;
  224. case IDC_HORIZONTAL_GRID:
  225. if (wMsg == BN_CLICKED)
  226. {
  227. m_bHorzGrid = !m_bHorzGrid;
  228. m_bHorzGridChg = TRUE;
  229. fChange = TRUE;
  230. }
  231. break ;
  232. case IDC_YAXIS_TITLE:
  233. if (wMsg == EN_CHANGE) {
  234. fChange = TRUE;
  235. m_bYaxisTitleChg = TRUE;
  236. }
  237. else if ((wMsg == EN_KILLFOCUS) && m_bYaxisTitleChg) {
  238. iTitleLen = DialogText(m_hDlg, IDC_YAXIS_TITLE, szTitleBuf);
  239. if (iTitleLen == 0) {
  240. delete [] m_pszYaxisTitle;
  241. m_pszYaxisTitle = NULL;
  242. }
  243. else {
  244. pszTemp = new WCHAR[iTitleLen+1];
  245. if (pszTemp) {
  246. delete [] m_pszYaxisTitle;
  247. m_pszYaxisTitle = pszTemp;
  248. StringCchCopy(m_pszYaxisTitle, iTitleLen+1, szTitleBuf);
  249. }
  250. }
  251. }
  252. break ;
  253. case IDC_GRAPH_TITLE:
  254. if (wMsg == EN_CHANGE) {
  255. fChange = TRUE;
  256. m_bGraphTitleChg = TRUE;
  257. }
  258. else if ((wMsg == EN_KILLFOCUS) && m_bGraphTitleChg) {
  259. iTitleLen = DialogText(m_hDlg, IDC_GRAPH_TITLE, szTitleBuf);
  260. if (iTitleLen == 0) {
  261. delete [] m_pszGraphTitle;
  262. m_pszGraphTitle = NULL;
  263. }
  264. else {
  265. pszTemp = new WCHAR[iTitleLen+1];
  266. if (pszTemp) {
  267. delete [] m_pszGraphTitle;
  268. m_pszGraphTitle = pszTemp;
  269. StringCchCopy(m_pszGraphTitle, iTitleLen+1, szTitleBuf);
  270. }
  271. }
  272. }
  273. break ;
  274. }
  275. if (fChange)
  276. SetChange();
  277. }