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.

426 lines
11 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. column.h
  7. Customizable column info.
  8. Use this to get/set configuration data. This class will take
  9. care of versioning of config formats as well as serializing
  10. of the data.
  11. FILE HISTORY:
  12. */
  13. #ifndef _COLUMN_H
  14. #define _COLUMN_H
  15. #ifndef _XSTREAM_H
  16. #include "xstream.h"
  17. #endif
  18. // forward declarations
  19. /*---------------------------------------------------------------------------
  20. Struct: ContainerColumnInfo
  21. This structure will hold column information that doesn't change.
  22. ---------------------------------------------------------------------------*/
  23. struct ContainerColumnInfo
  24. {
  25. ULONG m_ulStringId; // String id of the column header
  26. int m_nSortCriteria; // = 0 for string, = 1 for DWORD
  27. BOOL m_fVisibleByDefault;// TRUE if default is column is visible
  28. ULONG m_ulDefaultColumnWidth; // in number of characters
  29. };
  30. // constants used by m_nSortCriteria
  31. #define CON_SORT_BY_STRING 0
  32. #define CON_SORT_BY_DWORD 1
  33. // constants used for m_ulDefaultColumnWidth
  34. // This should be used to ensure consistency (as well as making it
  35. // easier to change a whole bunch of column widths at the same time).
  36. #define COL_IF_NAME 30
  37. #define COL_IF_DEVICE 30
  38. #define COL_STATUS 12
  39. #define COL_LARGE_NUM 15
  40. #define COL_SMALL_NUM 8
  41. #define COL_DATE 12
  42. #define COL_IPADDR 15
  43. #define COL_STRING 15
  44. #define COL_MACHINE_NAME 20
  45. #define COL_DURATION 10
  46. #define COL_IPXNET 32
  47. #define COL_NETBIOS_NAME 18
  48. #define COL_BIG_STRING 32
  49. //
  50. // Class: ViewColumnInfo
  51. //
  52. // This class is intended as a simple struct rather than a whole class.
  53. // Information needed on a per-view basis.
  54. //
  55. //
  56. class ViewInfo
  57. {
  58. public:
  59. ViewInfo();
  60. ~ViewInfo();
  61. //
  62. // Initializes the data for a single view or column set.
  63. //
  64. void InitViewInfo(ULONG cColumns,
  65. BOOL fConfigurable,
  66. BOOL fDefaultSortDirectionDescending,
  67. const ContainerColumnInfo *pViewColInfo);
  68. //
  69. // Call this to initialize the column data (reset to defaults).
  70. //
  71. void InitNew();
  72. //
  73. // Updates the mapping from the column id to the subitem ids.
  74. //
  75. void UpdateSubitemMap();
  76. //
  77. // Xfers the data to the stream using the given ids.
  78. //
  79. HRESULT Xfer(XferStream *pxstm,
  80. ULONG ulSortColumId,
  81. ULONG ulSortAscendingId,
  82. ULONG ulColumnsId);
  83. ULONG MapColumnToSubitem(ULONG nColumnId);
  84. ULONG MapSubitemToColumn(ULONG nSubitemId);
  85. HRESULT GetColumnData(ULONG cArrayMax, ColumnData *pColData);
  86. HRESULT SetColumnData(ULONG cArray, ColumnData *pColData);
  87. HRESULT GetColumnData(ULONG nColumnId, ULONG cArrayMax, ColumnData *pColData);
  88. int GetSortCriteria(ULONG nColumnId);
  89. ULONG GetStringId(ULONG nColumnId);
  90. DWORD GetColumnWidth(ULONG nColumnId);
  91. ULONG GetVisibleColumns();
  92. BOOL IsSubitemVisible(ULONG nSubitemId);
  93. ULONG GetColumnCount();
  94. ULONG GetSortColumn();
  95. void SetSortColumn(ULONG nSortColumn);
  96. ULONG GetSortDirection();
  97. void SetSortDirection(ULONG ulSortDirection);
  98. const ContainerColumnInfo * GetColumnInfo()
  99. { return m_pViewColumnInfo; }
  100. protected:
  101. // The individual column data (indexed by subitem id)
  102. ColumnData *m_prgColumns;
  103. // Number of columns
  104. ULONG m_cColumns;
  105. // The subitem id that we are sorting by
  106. DWORD m_dwSortColumn;
  107. // TRUE if we are sorting by ascending order
  108. DWORD m_dwSortDirection;
  109. // Pointer to default static data for this view
  110. const ContainerColumnInfo * m_pViewColumnInfo;
  111. // TRUE if the column order can be changed
  112. BOOL m_fConfigurable;
  113. //
  114. // The data after this point is for use during runtime display of data.
  115. // Thus it is organized a little differently then the persisted data.
  116. //
  117. // Number of visible columns.
  118. ULONG m_cVisibleColumns;
  119. // This is the mapping from column id to subitem id. The column ids
  120. // is the order in which the columns actually appear to MMC.
  121. // For example, if there were 3 columns (subitemA, subitemB, subitemC)
  122. // and we wished to show the columns in the order [subitemC, subitemB]
  123. // then m_cVisibleColumns = 2
  124. // and m_rgSubItems[] = { subitemC, subitemB, XXXX }
  125. // Do NOT make changes to this directly! This must be kept in sync
  126. // with the ordered data. This will get updated automatically when
  127. // SetColumnData is called.
  128. ULONG * m_prgSubitems;
  129. BOOL m_fDefaultSortDirection;
  130. };
  131. inline ULONG ViewInfo::MapColumnToSubitem(ULONG nColumnId)
  132. {
  133. Assert(nColumnId < (int) m_cColumns);
  134. // In the new MMC model, the only time we have configurable
  135. // columns are the statistics dialogs.
  136. if (m_fConfigurable)
  137. return m_prgSubitems[nColumnId];
  138. else
  139. return nColumnId;
  140. }
  141. inline int ViewInfo::GetSortCriteria(ULONG nColumnId)
  142. {
  143. Assert(nColumnId < m_cColumns);
  144. return m_pViewColumnInfo[MapColumnToSubitem(nColumnId)].m_nSortCriteria;
  145. }
  146. inline ULONG ViewInfo::GetStringId(ULONG nColumnId)
  147. {
  148. Assert(nColumnId < m_cColumns);
  149. return m_pViewColumnInfo[MapColumnToSubitem(nColumnId)].m_ulStringId;
  150. }
  151. inline ULONG ViewInfo::GetColumnWidth(ULONG nColumnId)
  152. {
  153. Assert(nColumnId < m_cColumns);
  154. Assert(m_prgColumns);
  155. return m_prgColumns[MapColumnToSubitem(nColumnId)].m_dwWidth;
  156. }
  157. inline ULONG ViewInfo::GetVisibleColumns()
  158. {
  159. return m_cVisibleColumns;
  160. }
  161. inline ULONG ViewInfo::GetColumnCount()
  162. {
  163. return m_cColumns;
  164. }
  165. inline BOOL ViewInfo::IsSubitemVisible(ULONG nSubitem)
  166. {
  167. return (m_prgColumns[nSubitem].m_nPosition > 0);
  168. }
  169. inline void ViewInfo::SetSortColumn(ULONG nColumnId)
  170. {
  171. m_dwSortColumn = nColumnId;
  172. }
  173. inline ULONG ViewInfo::GetSortColumn()
  174. {
  175. return m_dwSortColumn;
  176. }
  177. inline void ViewInfo::SetSortDirection(ULONG ulDir)
  178. {
  179. m_dwSortDirection = ulDir;
  180. }
  181. inline ULONG ViewInfo::GetSortDirection()
  182. {
  183. return m_dwSortDirection;
  184. }
  185. /*---------------------------------------------------------------------------
  186. Class: ConfigStream
  187. This class is used to place all configuration information into a
  188. single place.
  189. ---------------------------------------------------------------------------*/
  190. class ConfigStream
  191. {
  192. public:
  193. ConfigStream();
  194. virtual ~ConfigStream();
  195. //
  196. // Allocates the memory for these number of column sets
  197. //
  198. void Init(ULONG cColumnSetsMax);
  199. //
  200. // Initializes the data for a single column set.
  201. //
  202. void InitViewInfo(ULONG ulId,
  203. BOOL fConfigurableColumns,
  204. ULONG cColumns,
  205. BOOL fSortDirection,
  206. const ContainerColumnInfo *pColumnInfo);
  207. HRESULT InitNew(); // set defaults
  208. HRESULT SaveTo(IStream *pstm);
  209. HRESULT SaveAs(UINT nVersion, IStream *pstm);
  210. HRESULT LoadFrom(IStream *pstm);
  211. HRESULT GetSize(ULONG *pcbSize);
  212. BOOL GetDirty() { return m_fDirty; }
  213. void SetDirty(BOOL fDirty) { m_fDirty = fDirty; };
  214. // --------------------------------------------------------
  215. // Accessors
  216. // --------------------------------------------------------
  217. HRESULT GetVersionInfo(DWORD *pnVersion, DWORD *pnAdminVersion);
  218. ULONG MapColumnToSubitem(ULONG ulId, ULONG ulColumnId);
  219. ULONG MapSubitemToColumn(ULONG ulId, ULONG nSubitemId);
  220. HRESULT GetColumnData(ULONG ulId, ULONG cArrayMax, ColumnData *pColData);
  221. HRESULT GetColumnData(ULONG ulId, ULONG nColumnId, ULONG cArrayMax, ColumnData *pColData);
  222. HRESULT SetColumnData(ULONG ulId, ULONG cArray, ColumnData *pColData);
  223. ULONG GetColumnCount(ULONG ulId);
  224. int GetSortCriteria(ULONG ulId, ULONG uColumnId);
  225. ULONG GetStringId(ULONG ulId, ULONG nColumnId);
  226. DWORD GetColumnWidth(ULONG ulId, ULONG nColumnId);
  227. ULONG GetVisibleColumns(ULONG ulId);
  228. BOOL IsSubitemVisible(ULONG ulId, UINT nSubitemId);
  229. const ContainerColumnInfo * GetColumnInfo(ULONG ulId);
  230. void GetStatsWindowRect(ULONG ulId, RECT *prc);
  231. void SetStatsWindowRect(ULONG ulId, RECT rc);
  232. void SetSortColumn(ULONG ulId, ULONG uColumnId);
  233. ULONG GetSortColumn(ULONG ulId);
  234. void SetSortDirection(ULONG ulId, ULONG uSortDir);
  235. ULONG GetSortDirection(ULONG ulId);
  236. protected:
  237. DWORD m_nVersionAdmin;
  238. DWORD m_nVersion;
  239. BOOL m_fDirty;
  240. BOOL m_fConfigurableColumns; // = TRUE if we can change the columns
  241. ULONG m_cColumnSetsMax;
  242. ViewInfo * m_rgViewInfo; // = ViewInfo[m_cColumnSetsMax]
  243. RECT * m_prgrc; // = Rect[m_cColumnSetsMax]
  244. // Overide this to provide basic defaults
  245. virtual HRESULT XferVersion0(IStream *pstm, XferStream::Mode mode, ULONG *pcbSize);
  246. };
  247. inline ULONG ConfigStream::MapColumnToSubitem(ULONG ulId, ULONG nColumnId)
  248. {
  249. Assert(ulId < m_cColumnSetsMax);
  250. return m_rgViewInfo[ulId].MapColumnToSubitem(nColumnId);
  251. }
  252. inline ULONG ConfigStream::MapSubitemToColumn(ULONG ulId, ULONG nSubitemId)
  253. {
  254. Assert(ulId < m_cColumnSetsMax);
  255. return m_rgViewInfo[ulId].MapSubitemToColumn(nSubitemId);
  256. }
  257. inline int ConfigStream::GetSortCriteria(ULONG ulId, ULONG nColumnId)
  258. {
  259. Assert(ulId < m_cColumnSetsMax);
  260. return m_rgViewInfo[ulId].GetSortCriteria(nColumnId);
  261. }
  262. inline ULONG ConfigStream::GetVisibleColumns(ULONG ulId)
  263. {
  264. Assert(ulId < m_cColumnSetsMax);
  265. return m_rgViewInfo[ulId].GetVisibleColumns();
  266. }
  267. inline BOOL ConfigStream::IsSubitemVisible(ULONG ulId, UINT nSubitemId)
  268. {
  269. Assert(ulId < m_cColumnSetsMax);
  270. return m_rgViewInfo[ulId].IsSubitemVisible(nSubitemId);
  271. }
  272. inline ULONG ConfigStream::GetColumnCount(ULONG ulId)
  273. {
  274. Assert(ulId < m_cColumnSetsMax);
  275. return m_rgViewInfo[ulId].GetColumnCount();
  276. }
  277. inline HRESULT ConfigStream::GetColumnData(ULONG ulId, ULONG cArrayMax, ColumnData *pColData)
  278. {
  279. Assert(ulId < m_cColumnSetsMax);
  280. return m_rgViewInfo[ulId].GetColumnData(cArrayMax, pColData);
  281. }
  282. inline HRESULT ConfigStream::GetColumnData(ULONG ulId, ULONG cColData, ULONG cArrayMax, ColumnData *pColData)
  283. {
  284. Assert(ulId < m_cColumnSetsMax);
  285. return m_rgViewInfo[ulId].GetColumnData(cColData, cArrayMax, pColData);
  286. }
  287. inline HRESULT ConfigStream::SetColumnData(ULONG ulId,
  288. ULONG cArrayMax,
  289. ColumnData *pColData)
  290. {
  291. Assert(ulId < m_cColumnSetsMax);
  292. SetDirty(TRUE);
  293. return m_rgViewInfo[ulId].SetColumnData(cArrayMax, pColData);
  294. }
  295. inline const ContainerColumnInfo * ConfigStream::GetColumnInfo(ULONG ulId)
  296. {
  297. Assert(ulId < m_cColumnSetsMax);
  298. return m_rgViewInfo[ulId].GetColumnInfo();
  299. }
  300. inline ULONG ConfigStream::GetStringId(ULONG ulId, ULONG nColumnId)
  301. {
  302. Assert(ulId < m_cColumnSetsMax);
  303. return m_rgViewInfo[ulId].GetStringId(nColumnId);
  304. }
  305. inline DWORD ConfigStream::GetColumnWidth(ULONG ulId, ULONG nColumnId)
  306. {
  307. Assert(ulId < m_cColumnSetsMax);
  308. return m_rgViewInfo[ulId].GetColumnWidth(nColumnId);
  309. }
  310. inline void ConfigStream::SetSortColumn(ULONG ulId, ULONG nColumnId)
  311. {
  312. Assert(ulId < m_cColumnSetsMax);
  313. m_rgViewInfo[ulId].SetSortColumn(nColumnId);
  314. }
  315. inline ULONG ConfigStream::GetSortColumn(ULONG ulId)
  316. {
  317. Assert(ulId < m_cColumnSetsMax);
  318. return m_rgViewInfo[ulId].GetSortColumn();
  319. }
  320. inline void ConfigStream::SetSortDirection(ULONG ulId, ULONG nDir)
  321. {
  322. Assert(ulId < m_cColumnSetsMax);
  323. m_rgViewInfo[ulId].SetSortDirection(nDir);
  324. }
  325. inline ULONG ConfigStream::GetSortDirection(ULONG ulId)
  326. {
  327. Assert(ulId < m_cColumnSetsMax);
  328. return m_rgViewInfo[ulId].GetSortDirection();
  329. }
  330. #endif _COLUMN_H