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.

372 lines
9.4 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. ipstrm.cpp
  7. FILE HISTORY:
  8. */
  9. #include "stdafx.h"
  10. #include "column.h"
  11. #include "xstream.h"
  12. /*---------------------------------------------------------------------------
  13. ViewInfo implementation
  14. ---------------------------------------------------------------------------*/
  15. ViewInfo::ViewInfo()
  16. {
  17. m_cColumns = 0;
  18. m_prgColumns = NULL;
  19. m_dwSortColumn = 0;
  20. m_dwSortDirection = TRUE;
  21. m_pViewColumnInfo = NULL;
  22. m_cVisibleColumns = 0;
  23. m_prgSubitems = NULL;
  24. m_fConfigurable = TRUE;
  25. }
  26. ViewInfo::~ViewInfo()
  27. {
  28. delete [] m_prgColumns;
  29. delete [] m_prgSubitems;
  30. m_pViewColumnInfo = NULL;
  31. }
  32. /*!--------------------------------------------------------------------------
  33. ViewInfo::InitViewInfo
  34. -
  35. Author: KennT
  36. ---------------------------------------------------------------------------*/
  37. void ViewInfo::InitViewInfo(ULONG cColumns,
  38. BOOL fConfigurable,
  39. BOOL fDefaultSortDirectionDescending,
  40. const ContainerColumnInfo *pViewColInfo)
  41. {
  42. m_cColumns = cColumns;
  43. delete [] m_prgColumns;
  44. m_prgColumns = new ColumnData[cColumns];
  45. delete [] m_prgSubitems;
  46. m_prgSubitems = new ULONG[cColumns];
  47. m_pViewColumnInfo = pViewColInfo;
  48. m_fDefaultSortDirection = fDefaultSortDirectionDescending;
  49. m_fConfigurable = fConfigurable;
  50. InitNew();
  51. }
  52. /*!--------------------------------------------------------------------------
  53. ViewInfo::InitNew
  54. -
  55. Author: KennT
  56. ---------------------------------------------------------------------------*/
  57. void ViewInfo::InitNew()
  58. {
  59. // setup the defaults for this column
  60. for (int i=0; i<(int) m_cColumns; i++)
  61. {
  62. if (m_pViewColumnInfo[i].m_fVisibleByDefault)
  63. m_prgColumns[i].m_nPosition = i+1;
  64. else
  65. m_prgColumns[i].m_nPosition = -(i+1);
  66. m_prgColumns[i].m_dwWidth = AUTO_WIDTH;
  67. }
  68. m_dwSortDirection = m_fDefaultSortDirection;
  69. UpdateSubitemMap();
  70. }
  71. ULONG ViewInfo::MapSubitemToColumn(ULONG nSubitemId)
  72. {
  73. for (ULONG i=0; i<m_cVisibleColumns; i++)
  74. {
  75. if (m_prgSubitems[i] == nSubitemId)
  76. return i;
  77. }
  78. return 0xFFFFFFFF;
  79. }
  80. /*!--------------------------------------------------------------------------
  81. ViewInfo::UpdateSubitemMap
  82. -
  83. Author: KennT
  84. ---------------------------------------------------------------------------*/
  85. void ViewInfo::UpdateSubitemMap()
  86. {
  87. Assert(m_prgSubitems);
  88. ULONG i, cVisible, j;
  89. // Iterate over the entire set of columns
  90. for (i=0, cVisible=0; i<m_cColumns; i++)
  91. {
  92. // look for this column in ColumnData
  93. for (j=0; j<m_cColumns; j++)
  94. {
  95. if ((ULONG) m_prgColumns[j].m_nPosition == (i+1))
  96. break;
  97. }
  98. // Did we find anything? If not go on
  99. if (j >= m_cColumns)
  100. continue;
  101. m_prgSubitems[cVisible++] = j;
  102. }
  103. m_cVisibleColumns = cVisible;
  104. }
  105. HRESULT ViewInfo::Xfer(XferStream *pxstm, ULONG ulSortColumnId,
  106. ULONG ulSortAscendingId, ULONG ulColumnsId)
  107. {
  108. Assert(pxstm);
  109. HRESULT hr = hrOK;
  110. ULONG cColumns;
  111. // Xfer the column data
  112. Assert(m_prgColumns);
  113. cColumns = m_cColumns;
  114. CORg( pxstm->XferColumnData(ulColumnsId, &m_cColumns,
  115. m_prgColumns) );
  116. // The number of columns shouldn't change!
  117. Assert(m_cColumns == cColumns);
  118. // Use the old number of columns (this is for as we change our code)
  119. m_cColumns = cColumns;
  120. // Xfer the sort column
  121. CORg( pxstm->XferDWORD( ulSortColumnId, &m_dwSortColumn) );
  122. // Xfer the ascending data
  123. CORg( pxstm->XferDWORD( ulSortAscendingId, &m_dwSortDirection) );
  124. UpdateSubitemMap();
  125. Error:
  126. return hr;
  127. }
  128. /*---------------------------------------------------------------------------
  129. ConfigStream implementation
  130. ---------------------------------------------------------------------------*/
  131. /*!--------------------------------------------------------------------------
  132. ConfigStream::ConfigStream
  133. -
  134. Author: KennT
  135. ---------------------------------------------------------------------------*/
  136. ConfigStream::ConfigStream()
  137. : m_nVersion(0x00020000),
  138. m_nVersionAdmin(0x0002000),
  139. m_fDirty(FALSE),
  140. m_rgViewInfo(NULL),
  141. m_cColumnSetsMax(0),
  142. m_prgrc(NULL)
  143. {
  144. }
  145. ConfigStream::~ConfigStream()
  146. {
  147. delete [] m_rgViewInfo;
  148. delete [] m_prgrc;
  149. m_cColumnSetsMax = 0;
  150. }
  151. void ConfigStream::Init(ULONG cColumnSetsMax)
  152. {
  153. delete [] m_rgViewInfo;
  154. m_rgViewInfo = NULL;
  155. m_rgViewInfo = new ViewInfo[cColumnSetsMax];
  156. delete [] m_prgrc;
  157. m_prgrc = NULL;
  158. m_prgrc = new RECT[cColumnSetsMax];
  159. m_cColumnSetsMax = cColumnSetsMax;
  160. }
  161. /*!--------------------------------------------------------------------------
  162. ConfigStream::InitViewInfo
  163. Initializes the static data. This is not the same as InitNew.
  164. This will initialize the data for a single view.
  165. Author: KennT
  166. ---------------------------------------------------------------------------*/
  167. void ConfigStream::InitViewInfo(ULONG ulId,
  168. BOOL fConfigurableColumns,
  169. ULONG cColumns,
  170. BOOL fSortDirection,
  171. const ContainerColumnInfo *pViewColumnInfo)
  172. {
  173. Assert(ulId < m_cColumnSetsMax);
  174. m_fConfigurableColumns = fConfigurableColumns;
  175. m_rgViewInfo[ulId].InitViewInfo(cColumns, fConfigurableColumns,
  176. fSortDirection,
  177. pViewColumnInfo);
  178. }
  179. /*!--------------------------------------------------------------------------
  180. ConfigStream::InitNew
  181. -
  182. Author: KennT
  183. ---------------------------------------------------------------------------*/
  184. HRESULT ConfigStream::InitNew()
  185. {
  186. int iVisible=0;
  187. // Setup the appropriate defaults
  188. for (UINT i=0; i<m_cColumnSetsMax; i++)
  189. {
  190. m_rgViewInfo[i].InitNew();
  191. m_prgrc[i].top = m_prgrc[i].bottom = 0;
  192. m_prgrc[i].left = m_prgrc[i].right = 0;
  193. }
  194. return hrOK;
  195. }
  196. /*!--------------------------------------------------------------------------
  197. ConfigStream::SaveTo
  198. -
  199. Author: KennT
  200. ---------------------------------------------------------------------------*/
  201. HRESULT ConfigStream::SaveTo(IStream *pstm)
  202. {
  203. return XferVersion0(pstm, XferStream::MODE_WRITE, NULL);
  204. }
  205. /*!--------------------------------------------------------------------------
  206. ConfigStream::SaveAs
  207. -
  208. Author: KennT
  209. ---------------------------------------------------------------------------*/
  210. HRESULT ConfigStream::SaveAs(UINT nVersion, IStream *pstm)
  211. {
  212. return XferVersion0(pstm, XferStream::MODE_WRITE, NULL);
  213. }
  214. /*!--------------------------------------------------------------------------
  215. ConfigStream::LoadFrom
  216. -
  217. Author: KennT
  218. ---------------------------------------------------------------------------*/
  219. HRESULT ConfigStream::LoadFrom(IStream *pstm)
  220. {
  221. return XferVersion0(pstm, XferStream::MODE_READ, NULL);
  222. }
  223. /*!--------------------------------------------------------------------------
  224. ConfigStream::GetSize
  225. -
  226. Author: KennT
  227. ---------------------------------------------------------------------------*/
  228. HRESULT ConfigStream::GetSize(ULONG *pcbSize)
  229. {
  230. return XferVersion0(NULL, XferStream::MODE_SIZE, NULL);
  231. }
  232. /*!--------------------------------------------------------------------------
  233. ConfigStream::GetVersionInfo
  234. -
  235. Author: KennT
  236. ---------------------------------------------------------------------------*/
  237. HRESULT ConfigStream::GetVersionInfo(DWORD *pdwVersion, DWORD *pdwAdminVersion)
  238. {
  239. if (pdwVersion)
  240. *pdwVersion = m_nVersion;
  241. if (pdwAdminVersion)
  242. *pdwAdminVersion = m_nVersionAdmin;
  243. return hrOK;
  244. }
  245. /*!--------------------------------------------------------------------------
  246. ConfigStream::XferVersion0
  247. -
  248. Author: KennT
  249. ---------------------------------------------------------------------------*/
  250. HRESULT ConfigStream::XferVersion0(IStream *pstm, XferStream::Mode mode, ULONG *pcbSize)
  251. {
  252. Panic0("Should be implemented by derived classes!");
  253. return E_NOTIMPL;
  254. }
  255. void ConfigStream::GetStatsWindowRect(ULONG ulId, RECT *prc)
  256. {
  257. *prc = m_prgrc[ulId];
  258. }
  259. void ConfigStream::SetStatsWindowRect(ULONG ulId, RECT rc)
  260. {
  261. m_prgrc[ulId] = rc;
  262. }
  263. /*!--------------------------------------------------------------------------
  264. ViewInfo::GetColumnData
  265. -
  266. Author: KennT
  267. ---------------------------------------------------------------------------*/
  268. HRESULT ViewInfo::GetColumnData(ULONG cColData,
  269. ColumnData *prgColData)
  270. {
  271. Assert(cColData <= m_cColumns);
  272. Assert(prgColData);
  273. Assert(!IsBadWritePtr(prgColData, sizeof(ColumnData)*cColData));
  274. HRESULT hr = hrOK;
  275. memcpy(prgColData, m_prgColumns, sizeof(ColumnData)*cColData);
  276. return hr;
  277. }
  278. HRESULT ViewInfo::GetColumnData(ULONG nColumnId, ULONG cColData,
  279. ColumnData *prgColData)
  280. {
  281. Assert(cColData <= m_cColumns);
  282. Assert(prgColData);
  283. Assert(!IsBadWritePtr(prgColData, sizeof(ColumnData)*cColData));
  284. HRESULT hr = hrOK;
  285. memcpy(prgColData, m_prgColumns + nColumnId, sizeof(ColumnData)*cColData);
  286. return hr;
  287. }
  288. HRESULT ViewInfo::SetColumnData(ULONG cColData, ColumnData*prgColData)
  289. {
  290. // For now we don't do resizing
  291. Assert(cColData == m_cColumns);
  292. Assert(prgColData);
  293. Assert(!IsBadReadPtr(prgColData, sizeof(ColumnData)*cColData));
  294. HRESULT hr = hrOK;
  295. memcpy(m_prgColumns, prgColData, sizeof(ColumnData)*cColData);
  296. UpdateSubitemMap();
  297. return hr;
  298. }