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.

349 lines
9.8 KiB

  1. //=============================================================================
  2. // This file contains code to implement the CMSInfoCategory and
  3. // CMSInfoColumn classes.
  4. //=============================================================================
  5. #include "stdafx.h"
  6. #include "category.h"
  7. //=============================================================================
  8. // CMSInfoCategory
  9. //=============================================================================
  10. //-----------------------------------------------------------------------------
  11. // Get the name and/or caption for the category (loading the name from the
  12. // string resources if necessary).
  13. //-----------------------------------------------------------------------------
  14. void CMSInfoCategory::GetNames(CString * pstrCaption, CString * pstrName)
  15. {
  16. if (pstrName)
  17. *pstrName = m_strName;
  18. if (pstrCaption)
  19. {
  20. if (m_uiCaption)
  21. {
  22. TCHAR szCaption[MAX_PATH];
  23. ::LoadString(_Module.GetResourceInstance(), m_uiCaption, szCaption, MAX_PATH);
  24. m_strCaption = szCaption;
  25. m_uiCaption = 0;
  26. }
  27. *pstrCaption = m_strCaption;
  28. }
  29. }
  30. //-----------------------------------------------------------------------------
  31. // Get the number of rows and/or columns.
  32. //-----------------------------------------------------------------------------
  33. BOOL CMSInfoCategory::GetCategoryDimensions(int * piColumnCount, int * piRowCount)
  34. {
  35. if (piColumnCount)
  36. {
  37. if (SUCCEEDED(m_hrError))
  38. *piColumnCount = m_iColCount;
  39. else
  40. *piColumnCount = 1;
  41. }
  42. if (piRowCount)
  43. {
  44. if (SUCCEEDED(m_hrError))
  45. *piRowCount = m_iRowCount;
  46. else
  47. *piRowCount = 1;
  48. }
  49. return TRUE;
  50. }
  51. //-----------------------------------------------------------------------------
  52. // Is the specified row advanced?
  53. //-----------------------------------------------------------------------------
  54. BOOL CMSInfoCategory::IsRowAdvanced(int iRow)
  55. {
  56. if (FAILED(m_hrError) && iRow == 0)
  57. return FALSE;
  58. ASSERT(iRow < m_iRowCount);
  59. if (iRow >= m_iRowCount)
  60. return FALSE;
  61. return m_afRowAdvanced[iRow];
  62. }
  63. //-----------------------------------------------------------------------------
  64. // Is the specified column advanced?
  65. //-----------------------------------------------------------------------------
  66. BOOL CMSInfoCategory::IsColumnAdvanced(int iColumn)
  67. {
  68. if (FAILED(m_hrError) && iColumn == 0)
  69. return FALSE;
  70. ASSERT(iColumn < m_iColCount);
  71. if (m_acolumns == NULL || iColumn >= m_iColCount)
  72. return FALSE;
  73. return m_acolumns[iColumn].m_fAdvanced;
  74. }
  75. //-----------------------------------------------------------------------------
  76. // Get information about the specified column.
  77. //-----------------------------------------------------------------------------
  78. BOOL CMSInfoCategory::GetColumnInfo(int iColumn, CString * pstrCaption, UINT * puiWidth, BOOL * pfSorts, BOOL * pfLexical)
  79. {
  80. ASSERT(iColumn < m_iColCount);
  81. if (iColumn >= m_iColCount)
  82. return FALSE;
  83. CMSInfoColumn * pCol = &m_acolumns[iColumn];
  84. if (FAILED(m_hrError) && iColumn == 0)
  85. {
  86. if (pstrCaption)
  87. pstrCaption->Empty();
  88. if (puiWidth)
  89. *puiWidth = 240;
  90. if (pfSorts)
  91. *pfSorts = FALSE;
  92. return TRUE;
  93. }
  94. if (pstrCaption)
  95. {
  96. if (pCol->m_uiCaption)
  97. {
  98. TCHAR szCaption[MAX_PATH];
  99. ::LoadString(_Module.GetResourceInstance(), pCol->m_uiCaption, szCaption, MAX_PATH);
  100. pCol->m_strCaption = szCaption;
  101. pCol->m_uiCaption = 0;
  102. }
  103. *pstrCaption = pCol->m_strCaption;
  104. }
  105. if (puiWidth)
  106. *puiWidth = pCol->m_uiWidth;
  107. if (pfSorts)
  108. *pfSorts = pCol->m_fSorts;
  109. if (pfLexical)
  110. *pfLexical = pCol->m_fLexical;
  111. return TRUE;
  112. }
  113. //-----------------------------------------------------------------------------
  114. // Save the width of the specified column.
  115. //-----------------------------------------------------------------------------
  116. void CMSInfoCategory::SetColumnWidth(int iCol, int iWidth)
  117. {
  118. ASSERT(iCol < m_iColCount && iCol >= 0);
  119. if (iCol >= m_iColCount || iCol < 0)
  120. return;
  121. m_acolumns[iCol].m_uiWidth = (UINT) iWidth;
  122. }
  123. //-----------------------------------------------------------------------------
  124. // Get data for the specified row and column.
  125. //-----------------------------------------------------------------------------
  126. static CString strErrorMessage;
  127. BOOL CMSInfoCategory::GetData(int iRow, int iCol, CString ** ppstrData, DWORD * pdwData)
  128. {
  129. if (FAILED(m_hrError) && iCol == 0 && iRow == 0)
  130. {
  131. if (ppstrData)
  132. {
  133. GetErrorText(&strErrorMessage, NULL);
  134. *ppstrData = &strErrorMessage;
  135. }
  136. if (pdwData)
  137. *pdwData = 0;
  138. return TRUE;
  139. }
  140. ASSERT(iRow < m_iRowCount && iCol < m_iColCount);
  141. if (iRow >= m_iRowCount || iCol >= m_iColCount)
  142. return FALSE;
  143. if (ppstrData)
  144. *ppstrData = &m_astrData[iRow * m_iColCount + iCol];
  145. if (pdwData)
  146. *pdwData = m_adwData[iRow * m_iColCount + iCol];
  147. return TRUE;
  148. }
  149. //-----------------------------------------------------------------------------
  150. // Get the error strings for this category (subclasses should override this).
  151. //-----------------------------------------------------------------------------
  152. void CMSInfoCategory::GetErrorText(CString * pstrTitle, CString * pstrMessage)
  153. {
  154. if (pstrTitle)
  155. pstrTitle->Empty();
  156. if (pstrMessage)
  157. pstrMessage->Empty();
  158. }
  159. //=============================================================================
  160. // Helper functions for managing the arrays of data.
  161. //=============================================================================
  162. #ifndef SAFE_DELETE_ARRAY
  163. #define SAFE_DELETE_ARRAY(x) { if (x) { delete [] x; x = NULL; } }
  164. #endif
  165. //-----------------------------------------------------------------------------
  166. // Deletes all the content (except the array of columns if m_fDynamicColumns
  167. // is false). Generally, this will be used when the category is destructing.
  168. //-----------------------------------------------------------------------------
  169. void CMSInfoCategory::DeleteAllContent()
  170. {
  171. DeleteContent();
  172. if (m_fDynamicColumns)
  173. {
  174. SAFE_DELETE_ARRAY(m_acolumns);
  175. m_iColCount = 0;
  176. }
  177. }
  178. //-----------------------------------------------------------------------------
  179. // Deletes all of the refreshed data (strings and DWORDs) and sets the number
  180. // of rows to zero. It leaves the column information alone. This will be called
  181. // when the data for a category is being refreshed.
  182. //-----------------------------------------------------------------------------
  183. void CMSInfoCategory::DeleteContent()
  184. {
  185. SAFE_DELETE_ARRAY(m_astrData);
  186. SAFE_DELETE_ARRAY(m_adwData);
  187. SAFE_DELETE_ARRAY(m_afRowAdvanced);
  188. m_iRowCount = 0;
  189. }
  190. //-----------------------------------------------------------------------------
  191. // Allocates space for the specified number of rows and columns, including
  192. // the column array. Automatically sets the m_fDynamicColumns to TRUE.
  193. // This will be called when the CMSInfoCategory is being created for the
  194. // first time, and the columns are going to be dynamically set.
  195. //-----------------------------------------------------------------------------
  196. void CMSInfoCategory::AllocateAllContent(int iRowCount, int iColCount)
  197. {
  198. ASSERT(iColCount);
  199. DeleteAllContent();
  200. m_iColCount = iColCount;
  201. m_fDynamicColumns = TRUE;
  202. m_acolumns = new CMSInfoColumn[m_iColCount];
  203. // TBD - memory errors?
  204. AllocateContent(iRowCount);
  205. }
  206. //-----------------------------------------------------------------------------
  207. // Allocates the space for the specified number of rows. Leaves the column
  208. // information alone. This would typically be called when new data is
  209. // available from a refresh and the arrays need to be set for the new row
  210. // size.
  211. //-----------------------------------------------------------------------------
  212. void CMSInfoCategory::AllocateContent(int iRowCount)
  213. {
  214. ASSERT(iRowCount);
  215. DeleteContent();
  216. m_iRowCount = iRowCount;
  217. m_astrData = new CString[m_iColCount * m_iRowCount];
  218. m_adwData = new DWORD[m_iColCount * m_iRowCount];
  219. m_afRowAdvanced = new BOOL[m_iRowCount];
  220. if (m_astrData == NULL || m_adwData == NULL || m_afRowAdvanced == NULL)
  221. return; // TBD what to do?
  222. for (int iRow = 0; iRow < m_iRowCount; iRow++)
  223. {
  224. m_afRowAdvanced[iRow] = FALSE;
  225. for (int iCol = 0; iCol < m_iColCount; iCol++)
  226. m_adwData[iRow * m_iColCount + iCol] = 0;
  227. }
  228. }
  229. //-----------------------------------------------------------------------------
  230. // Put the specified string and DWORD into the arrays of data.
  231. //-----------------------------------------------------------------------------
  232. void CMSInfoCategory::SetData(int iRow, int iCol, const CString & strData, DWORD dwData)
  233. {
  234. ASSERT(iRow < m_iRowCount && iCol < m_iColCount);
  235. if (m_astrData)
  236. m_astrData[iRow * m_iColCount + iCol] = strData;
  237. if (m_adwData)
  238. m_adwData[iRow * m_iColCount + iCol] = dwData;
  239. }
  240. //-----------------------------------------------------------------------------
  241. // Set the specified row's advanced flag.
  242. //-----------------------------------------------------------------------------
  243. void CMSInfoCategory::SetAdvancedFlag(int iRow, BOOL fAdvanced)
  244. {
  245. ASSERT(iRow < m_iRowCount);
  246. if (m_afRowAdvanced)
  247. m_afRowAdvanced[iRow] = fAdvanced;
  248. }
  249. //=============================================================================
  250. // CMSInfoColumn
  251. //=============================================================================
  252. CMSInfoColumn::CMSInfoColumn(UINT uiCaption, UINT uiWidth, BOOL fSorts, BOOL fLexical, BOOL fAdvanced) :
  253. m_uiCaption(uiCaption),
  254. m_strCaption(_T("")),
  255. m_uiWidth(uiWidth),
  256. m_fSorts(fSorts),
  257. m_fLexical(fLexical),
  258. m_fAdvanced(fAdvanced)
  259. {
  260. }
  261. CMSInfoColumn::CMSInfoColumn() :
  262. m_uiCaption(0),
  263. m_strCaption(_T("")),
  264. m_uiWidth(0),
  265. m_fSorts(FALSE),
  266. m_fLexical(FALSE),
  267. m_fAdvanced(FALSE)
  268. {
  269. }
  270. CMSInfoColumn::~CMSInfoColumn()
  271. {
  272. }