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.

330 lines
8.3 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 <assert.h>
  9. #include <stdio.h>
  10. #include "grphprop.h"
  11. #include "utils.h"
  12. #include "strids.h"
  13. #include "unihelpr.h"
  14. #include "winhelpr.h"
  15. CGraphPropPage::CGraphPropPage()
  16. {
  17. m_uIDDialog = IDD_GRAPH_PROPP_DLG;
  18. m_uIDTitle = IDS_GRAPH_PROPP_TITLE;
  19. m_pszYaxisTitle = NULL;
  20. m_pszGraphTitle = NULL;
  21. }
  22. CGraphPropPage::~CGraphPropPage()
  23. {
  24. delete m_pszYaxisTitle;
  25. delete m_pszGraphTitle;
  26. }
  27. BOOL CGraphPropPage::InitControls()
  28. {
  29. HWND hwndItem = NULL;
  30. hwndItem = GetDlgItem(m_hDlg, IDC_VERTICAL_MAX);
  31. if ( NULL != hwndItem ) {
  32. EditSetLimit(hwndItem, MAX_SCALE_DIGITS);
  33. hwndItem = NULL;
  34. }
  35. hwndItem = GetDlgItem(m_hDlg, IDC_VERTICAL_MIN);
  36. if ( NULL != hwndItem ) {
  37. EditSetLimit(hwndItem, MAX_SCALE_DIGITS);
  38. hwndItem = NULL;
  39. }
  40. hwndItem = GetDlgItem(m_hDlg, IDC_GRAPH_TITLE);
  41. if ( NULL != hwndItem ) {
  42. EditSetLimit(hwndItem, MAX_TITLE_CHARS);
  43. hwndItem = NULL;
  44. }
  45. hwndItem = GetDlgItem(m_hDlg, IDC_YAXIS_TITLE);
  46. if ( NULL != hwndItem ) {
  47. EditSetLimit(hwndItem, MAX_TITLE_CHARS);
  48. hwndItem = NULL;
  49. }
  50. return TRUE;
  51. }
  52. /*
  53. * CGraphPropPage::GetProperties
  54. *
  55. */
  56. BOOL CGraphPropPage::GetProperties(void)
  57. {
  58. TCHAR szBuff[MAX_SCALE_DIGITS+1];
  59. ISystemMonitor *pObj;
  60. BSTR bstrTemp;
  61. LPTSTR pszTemp;
  62. USES_CONVERSION
  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. _stprintf(szBuff, TEXT("%d"), m_iVertMax) ;
  74. SetDlgItemText(m_hDlg, IDC_VERTICAL_MAX, szBuff) ;
  75. pObj->get_MinimumScale(&m_iVertMin);
  76. _stprintf(szBuff, TEXT("%d"), m_iVertMin) ;
  77. SetDlgItemText(m_hDlg, IDC_VERTICAL_MIN, szBuff) ;
  78. pObj->get_YAxisLabel(&bstrTemp);
  79. if (bstrTemp != NULL) {
  80. pszTemp = W2T(bstrTemp);
  81. m_pszYaxisTitle = new TCHAR[lstrlen(pszTemp)+1];
  82. if (m_pszYaxisTitle) {
  83. lstrcpy(m_pszYaxisTitle, 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 = W2T(bstrTemp);
  91. m_pszGraphTitle = new TCHAR[lstrlen(pszTemp)+1];
  92. if (m_pszGraphTitle) {
  93. lstrcpy(m_pszGraphTitle, 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. USES_CONVERSION
  119. // Get first object
  120. if (m_cObjects == 0)
  121. return FALSE;
  122. pObj = m_ppISysmon[0];
  123. // Check for invalid data
  124. if (m_iErrVertMax) {
  125. SetFocus(GetDlgItem(m_hDlg, IDC_VERTICAL_MAX));
  126. iMsgId = m_iErrVertMax;
  127. } else if (m_iErrVertMin) {
  128. SetFocus(GetDlgItem(m_hDlg, IDC_VERTICAL_MIN));
  129. iMsgId = m_iErrVertMin;
  130. } else if (m_iVertMax <= m_iVertMin) {
  131. SetFocus(GetDlgItem(m_hDlg, IDC_VERTICAL_MAX));
  132. iMsgId = IDS_SCALE_ERR;
  133. }
  134. // on error, alert user and exit
  135. if (iMsgId) {
  136. MessageBox(m_hDlg, ResourceString(iMsgId), ResourceString(IDS_APP_NAME), MB_OK | MB_ICONEXCLAMATION);
  137. return FALSE;
  138. }
  139. // Set all changed properties
  140. if (m_bLabelsChg)
  141. pObj->put_ShowScaleLabels(m_bLabels);
  142. if (m_bVertGridChg)
  143. pObj->put_ShowVerticalGrid(m_bVertGrid);
  144. if (m_bHorzGridChg)
  145. pObj->put_ShowHorizontalGrid(m_bHorzGrid);
  146. if (m_bVertMaxChg)
  147. pObj->put_MaximumScale(m_iVertMax);
  148. if (m_bVertMinChg)
  149. pObj->put_MinimumScale(m_iVertMin);
  150. if (m_bYaxisTitleChg)
  151. pObj->put_YAxisLabel(T2W(m_pszYaxisTitle));
  152. if (m_bGraphTitleChg)
  153. pObj->put_GraphTitle(T2W(m_pszGraphTitle));
  154. // Clear change flags
  155. m_bLabelsChg = FALSE;
  156. m_bVertGridChg = FALSE;
  157. m_bHorzGridChg = FALSE;
  158. m_bVertMinChg = FALSE;
  159. m_bYaxisTitleChg = FALSE;
  160. m_bGraphTitleChg = FALSE;
  161. return TRUE;
  162. }
  163. void CGraphPropPage::DialogItemChange(WORD wID, WORD wMsg)
  164. {
  165. TCHAR szTitleBuf[MAX_TITLE_CHARS+1];
  166. INT iTitleLen;
  167. LPTSTR pszTemp;
  168. BOOL fChange = FALSE;
  169. BOOL fResult;
  170. switch(wID) {
  171. case IDC_VERTICAL_MAX:
  172. if (wMsg == EN_CHANGE) {
  173. fChange = TRUE;
  174. m_bVertMaxChg = TRUE;
  175. } else if ((wMsg == EN_KILLFOCUS) && m_bVertMaxChg) {
  176. m_iVertMax = GetDlgItemInt(m_hDlg, IDC_VERTICAL_MAX, &fResult, FALSE);
  177. if (!fResult) {
  178. m_iErrVertMax = IDS_VERTMAX_ERR;
  179. } else {
  180. m_iErrVertMax = 0;
  181. }
  182. }
  183. break ;
  184. case IDC_VERTICAL_MIN:
  185. if (wMsg == EN_CHANGE) {
  186. fChange = TRUE;
  187. m_bVertMinChg = TRUE;
  188. } else if ((wMsg == EN_KILLFOCUS) && m_bVertMinChg) {
  189. m_iVertMin = GetDlgItemInt(m_hDlg, IDC_VERTICAL_MIN, &fResult, FALSE);
  190. if (!fResult) {
  191. m_iErrVertMin = IDS_VERTMIN_ERR;
  192. } else {
  193. m_iErrVertMin = 0;
  194. }
  195. }
  196. break ;
  197. case IDC_VERTICAL_LABELS:
  198. if (wMsg == BN_CLICKED)
  199. {
  200. m_bLabels = !m_bLabels;
  201. m_bLabelsChg = TRUE;
  202. fChange = TRUE;
  203. }
  204. break ;
  205. case IDC_VERTICAL_GRID:
  206. if (wMsg == BN_CLICKED)
  207. {
  208. m_bVertGrid = !m_bVertGrid;
  209. m_bVertGridChg = TRUE;
  210. fChange = TRUE;
  211. }
  212. break ;
  213. case IDC_HORIZONTAL_GRID:
  214. if (wMsg == BN_CLICKED)
  215. {
  216. m_bHorzGrid = !m_bHorzGrid;
  217. m_bHorzGridChg = TRUE;
  218. fChange = TRUE;
  219. }
  220. break ;
  221. case IDC_YAXIS_TITLE:
  222. if (wMsg == EN_CHANGE) {
  223. fChange = TRUE;
  224. m_bYaxisTitleChg = TRUE;
  225. }
  226. else if ((wMsg == EN_KILLFOCUS) && m_bYaxisTitleChg) {
  227. iTitleLen = DialogText(m_hDlg, IDC_YAXIS_TITLE, szTitleBuf);
  228. if (iTitleLen == 0) {
  229. delete m_pszYaxisTitle;
  230. m_pszYaxisTitle = NULL;
  231. }
  232. else {
  233. pszTemp = new TCHAR[iTitleLen+1];
  234. if (pszTemp) {
  235. delete m_pszYaxisTitle;
  236. m_pszYaxisTitle = pszTemp;
  237. lstrcpy(m_pszYaxisTitle, szTitleBuf);
  238. }
  239. }
  240. }
  241. break ;
  242. case IDC_GRAPH_TITLE:
  243. if (wMsg == EN_CHANGE) {
  244. fChange = TRUE;
  245. m_bGraphTitleChg = TRUE;
  246. }
  247. else if ((wMsg == EN_KILLFOCUS) && m_bGraphTitleChg) {
  248. iTitleLen = DialogText(m_hDlg, IDC_GRAPH_TITLE, szTitleBuf);
  249. if (iTitleLen == 0) {
  250. delete m_pszGraphTitle;
  251. m_pszGraphTitle = NULL;
  252. }
  253. else {
  254. pszTemp = new TCHAR[iTitleLen+1];
  255. if (pszTemp) {
  256. delete m_pszGraphTitle;
  257. m_pszGraphTitle = pszTemp;
  258. lstrcpy(m_pszGraphTitle, szTitleBuf);
  259. }
  260. }
  261. }
  262. break ;
  263. }
  264. if (fChange)
  265. SetChange();
  266. }