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.

474 lines
14 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1999
  5. //
  6. // File: coldata.cpp
  7. //
  8. // Contents: Access Column Persistence data.
  9. //
  10. // History: 25-Jan-99 AnandhaG Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include "stdafx.h"
  14. #include "columninfo.h"
  15. #include "colwidth.h"
  16. CColumnData::CColumnData()
  17. {
  18. }
  19. CColumnData::~CColumnData()
  20. {
  21. }
  22. //+-------------------------------------------------------------------
  23. //
  24. // Member: GetColumnData
  25. //
  26. // Synopsis: Helper function to retrieve the column data for a
  27. // given column-id.
  28. //
  29. // Arguments: [pColID] - Column-Set identifier.
  30. // [columnSetData] - CColumnSetData, used to return the
  31. // persisted column information.
  32. //
  33. // Returns: S_OK - if data found else S_FALSE.
  34. //
  35. // History: 01-25-1999 AnandhaG Created
  36. // 05-04-1999 AnandhaG Changed first param to SColumnSetID.
  37. //
  38. //--------------------------------------------------------------------
  39. HRESULT CColumnData::GetColumnData(SColumnSetID* pColID, CColumnSetData& columnSetData)
  40. {
  41. HRESULT hr = E_FAIL;
  42. do
  43. {
  44. CNodeInitObject* pNodeInit = dynamic_cast<CNodeInitObject*>(this);
  45. if (! pNodeInit)
  46. break;
  47. CViewData* pCV = pNodeInit->m_pNode->GetViewData();
  48. if (! pCV)
  49. break;
  50. CLSID clsidSnapin;
  51. hr = pNodeInit->GetSnapinCLSID(clsidSnapin);
  52. if (FAILED(hr))
  53. {
  54. ASSERT(FALSE);
  55. hr = E_FAIL;
  56. break;
  57. }
  58. // Get the persisted column data.
  59. BOOL bRet = pCV->RetrieveColumnData( clsidSnapin, *pColID, columnSetData);
  60. // No data.
  61. if (! bRet)
  62. {
  63. hr = S_FALSE;
  64. break;
  65. }
  66. hr = S_OK;
  67. } while ( FALSE );
  68. return hr;
  69. }
  70. //+-------------------------------------------------------------------
  71. //
  72. // Member: SetColumnData
  73. //
  74. // Synopsis: Helper function to set the column data for a
  75. // given column-id.
  76. //
  77. // Arguments: [pColID] - Column-Set identifier.
  78. // [columnSetData] - CColumnSetData, that should be
  79. // persisted.
  80. //
  81. // Returns: S_OK - if data is persisted else S_FALSE.
  82. //
  83. // History: 01-25-1999 AnandhaG Created
  84. // 05-04-1999 AnandhaG Changed first param to SColumnSetID.
  85. //
  86. //--------------------------------------------------------------------
  87. HRESULT CColumnData::SetColumnData(SColumnSetID* pColID, CColumnSetData& columnSetData)
  88. {
  89. HRESULT hr = E_FAIL;
  90. do
  91. {
  92. CNodeInitObject* pNodeInit = dynamic_cast<CNodeInitObject*>(this);
  93. if (! pNodeInit)
  94. break;
  95. CViewData* pCV = pNodeInit->m_pNode->GetViewData();
  96. if (! pCV)
  97. break;
  98. CLSID clsidSnapin;
  99. hr = pNodeInit->GetSnapinCLSID(clsidSnapin);
  100. if (FAILED(hr))
  101. {
  102. ASSERT(FALSE);
  103. hr = E_FAIL;
  104. break;
  105. }
  106. // Copy the data into the internal data structures.
  107. BOOL bRet = pCV->SaveColumnData( clsidSnapin, *pColID, columnSetData);
  108. if (! bRet)
  109. {
  110. hr = E_FAIL;
  111. break;
  112. }
  113. hr = S_OK;
  114. } while ( FALSE );
  115. return hr;
  116. }
  117. //+-------------------------------------------------------------------
  118. //
  119. // Member: SetColumnConfigData
  120. //
  121. // Synopsis: Method snapin can call to set the column data for a
  122. // given column-id.
  123. // Any sort data that was persisted will be cleared by
  124. // this call.
  125. //
  126. // Arguments: [pColID] - Column-Set identifier.
  127. // [pcolSetData] - Column data that should be persisted.
  128. //
  129. // Returns: S_OK - if data is persisted else S_FALSE.
  130. //
  131. // History: 01-25-1999 AnandhaG Created
  132. // 05-04-1999 AnandhaG Changed first param to SColumnSetID.
  133. //
  134. //--------------------------------------------------------------------
  135. STDMETHODIMP CColumnData::SetColumnConfigData(SColumnSetID* pColID,
  136. MMC_COLUMN_SET_DATA* pColSetData)
  137. {
  138. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IColumnData::SetColumnConfigData"));
  139. if (NULL == pColID)
  140. {
  141. sc = E_INVALIDARG;
  142. TraceSnapinError(_T("NULL SColumnSetID ptr"), sc);
  143. return sc.ToHr();
  144. }
  145. if (NULL == pColSetData)
  146. {
  147. sc = E_INVALIDARG;
  148. TraceSnapinError(_T("NULL MMC_COLUMN_SET_DATA ptr"), sc);
  149. return sc.ToHr();
  150. }
  151. sc = S_FALSE;
  152. CColumnInfoList colInfoList;
  153. for (int i = 0; i < pColSetData->nNumCols; i++)
  154. {
  155. CColumnInfo colInfo;
  156. MMC_COLUMN_DATA* pColData = &(pColSetData->pColData[i]);
  157. colInfo.SetColWidth(pColData->nWidth);
  158. colInfo.SetColHidden( HDI_HIDDEN & pColData->dwFlags);
  159. colInfo.SetColIndex(pColData->nColIndex);
  160. if ( (colInfo.GetColIndex() == 0) && colInfo.IsColHidden() )
  161. return (sc = E_INVALIDARG).ToHr();
  162. // Add the CColumnInfo to the list.
  163. colInfoList.push_back(colInfo);
  164. }
  165. CColumnSetData columnSetData;
  166. columnSetData.set_ColumnInfoList(colInfoList);
  167. sc = SetColumnData(pColID, columnSetData);
  168. return sc.ToHr();
  169. }
  170. //+-------------------------------------------------------------------
  171. //
  172. // Member: GetColumnConfigData
  173. //
  174. // Synopsis: Method snapin can call to retrieve the column data for a
  175. // given column-id.
  176. //
  177. // Arguments: [pColID] - Column-Set identifier.
  178. // [ppcolSetData] - Persisted column-data that is returned.
  179. //
  180. // Returns: S_OK - if data is found else S_FALSE.
  181. //
  182. // History: 01-25-1999 AnandhaG Created
  183. // 05-04-1999 AnandhaG Changed first param to SColumnSetID.
  184. //
  185. //--------------------------------------------------------------------
  186. STDMETHODIMP CColumnData::GetColumnConfigData(SColumnSetID* pColID,
  187. MMC_COLUMN_SET_DATA** ppColSetData)
  188. {
  189. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IColumnData::GetColumnConfigData"));
  190. if (NULL == pColID)
  191. {
  192. sc = E_INVALIDARG;
  193. TraceSnapinError(_T("NULL SColumnSetID ptr"), sc);
  194. return sc.ToHr();
  195. }
  196. if (NULL == ppColSetData)
  197. {
  198. sc = E_INVALIDARG;
  199. TraceSnapinError(_T("NULL MMC_COLUMN_SET_DATA ptr"), sc);
  200. return sc.ToHr();
  201. }
  202. sc = S_FALSE;
  203. *ppColSetData = NULL;
  204. CColumnSetData columnSetData;
  205. sc = GetColumnData(pColID, columnSetData);
  206. if (S_OK != sc.ToHr())
  207. return sc.ToHr(); // data doesnt exist.
  208. CColumnInfoList* pColInfoList = columnSetData.get_ColumnInfoList();
  209. CColumnInfo colInfo;
  210. int nNumCols = pColInfoList->size();
  211. if (nNumCols <= 0)
  212. {
  213. sc = S_FALSE;
  214. return sc.ToHr();
  215. }
  216. // Allocate memory, copy & return the data.
  217. int cb = sizeof(MMC_COLUMN_SET_DATA) + sizeof(MMC_COLUMN_DATA) * nNumCols;
  218. BYTE* pb = (BYTE*)::CoTaskMemAlloc(cb);
  219. if (! pb)
  220. {
  221. sc = E_OUTOFMEMORY;
  222. return sc.ToHr();
  223. }
  224. *ppColSetData = (MMC_COLUMN_SET_DATA*)pb;
  225. (*ppColSetData)->cbSize = sizeof(MMC_COLUMN_SET_DATA);
  226. (*ppColSetData)->nNumCols = nNumCols;
  227. (*ppColSetData)->pColData = (MMC_COLUMN_DATA*)(pb + sizeof(MMC_COLUMN_SET_DATA));
  228. CColumnInfoList::iterator itColInfo;
  229. int i = 0;
  230. MMC_COLUMN_DATA* pColData = (*ppColSetData)->pColData;
  231. for (itColInfo = pColInfoList->begin();itColInfo != pColInfoList->end(); itColInfo++, i++)
  232. {
  233. pColData[i].nWidth = (*itColInfo).GetColWidth();
  234. pColData[i].dwFlags = (*itColInfo).IsColHidden() ? HDI_HIDDEN : 0;
  235. pColData[i].nColIndex = (*itColInfo).GetColIndex();
  236. }
  237. return sc.ToHr();
  238. }
  239. //+-------------------------------------------------------------------
  240. //
  241. // Member: SetColumnSortData
  242. //
  243. // Synopsis: Method snapin can call to set the sort data for a
  244. // given column-id.
  245. // Any column config data (width, order...) that was
  246. // persisted will not be affected by this call.
  247. //
  248. // Arguments: [pColID] - Column-Set identifier.
  249. // [pcolSorData] - Sort data that should be persisted.
  250. //
  251. // Returns: S_OK - if data is persisted else S_FALSE.
  252. //
  253. // History: 01-25-1999 AnandhaG Created
  254. // 05-04-1999 AnandhaG Changed first param to SColumnSetID.
  255. //
  256. //--------------------------------------------------------------------
  257. STDMETHODIMP CColumnData::SetColumnSortData(SColumnSetID* pColID,
  258. MMC_SORT_SET_DATA* pColSortData)
  259. {
  260. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IColumnData::SetColumnSortData"));
  261. if (NULL == pColID)
  262. {
  263. sc = E_INVALIDARG;
  264. TraceSnapinError(_T("NULL SColumnSetID ptr"), sc);
  265. return sc.ToHr();
  266. }
  267. if (NULL == pColSortData)
  268. {
  269. sc = E_INVALIDARG;
  270. TraceSnapinError(_T("NULL MMC_COLUMN_SET_DATA ptr"), sc);
  271. return sc.ToHr();
  272. }
  273. sc = S_FALSE;
  274. // First get old data. We need to preserve the width, view info.
  275. CColumnSetData columnSetData;
  276. sc = GetColumnData(pColID, columnSetData);
  277. if (sc)
  278. return sc.ToHr();
  279. CColumnSortList* pColSortList = columnSetData.get_ColumnSortList();
  280. pColSortList->clear();
  281. // For MMC version 1.2 we do only single column sorting.
  282. if (pColSortData->nNumItems > 1)
  283. {
  284. sc = S_FALSE;
  285. return sc.ToHr();
  286. }
  287. CColumnSortInfo colSortInfo;
  288. for (int i = 0; i < pColSortData->nNumItems; i++)
  289. {
  290. MMC_SORT_DATA* pSortData = &(pColSortData->pSortData[i]);
  291. ::ZeroMemory(&colSortInfo, sizeof(colSortInfo));
  292. colSortInfo.m_nCol = pSortData->nColIndex;
  293. colSortInfo.m_dwSortOptions = pSortData->dwSortOptions;
  294. colSortInfo.m_lpUserParam = pSortData->ulReserved;
  295. // Add the CColumnSortInfo to the list.
  296. pColSortList->push_back(colSortInfo);
  297. }
  298. sc = SetColumnData(pColID, columnSetData);
  299. return sc.ToHr();
  300. }
  301. //+-------------------------------------------------------------------
  302. //
  303. // Member: GetColumnSortData
  304. //
  305. // Synopsis: Method snapin can call to retrieve the column sort data
  306. // for a given column-id.
  307. //
  308. // Arguments: [pColID] - Column-Set identifier.
  309. // [ppcolSortData] - Persisted column-sort-data that is returned.
  310. //
  311. // Returns: S_OK - if data is found else S_FALSE.
  312. //
  313. // History: 01-25-1999 AnandhaG Created
  314. // 05-04-1999 AnandhaG Changed first param to SColumnSetID.
  315. //
  316. //--------------------------------------------------------------------
  317. STDMETHODIMP CColumnData::GetColumnSortData(SColumnSetID* pColID,
  318. MMC_SORT_SET_DATA** ppColSortData)
  319. {
  320. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IColumnData::SetColumnSortData"));
  321. if (NULL == pColID)
  322. {
  323. sc = E_INVALIDARG;
  324. TraceSnapinError(_T("NULL SColumnSetID ptr"), sc);
  325. return sc.ToHr();
  326. }
  327. if (NULL == ppColSortData)
  328. {
  329. sc = E_INVALIDARG;
  330. TraceSnapinError(_T("NULL MMC_COLUMN_SET_DATA ptr"), sc);
  331. return sc.ToHr();
  332. }
  333. sc = S_FALSE;
  334. *ppColSortData = NULL;
  335. CColumnSetData columnSetData;
  336. sc = GetColumnData(pColID, columnSetData);
  337. if (S_OK != sc.ToHr())
  338. return sc.ToHr();
  339. CColumnSortList* pColSortList = columnSetData.get_ColumnSortList();
  340. CColumnSortInfo colSortInfo;
  341. int nNumItems = pColSortList->size();
  342. if (nNumItems <= 0)
  343. {
  344. sc = S_FALSE;
  345. return sc.ToHr();
  346. }
  347. // For MMC 1.2 we sort on only one column.
  348. ASSERT(nNumItems == 1);
  349. int cb = sizeof(MMC_SORT_SET_DATA) + sizeof(MMC_SORT_DATA) * nNumItems;
  350. BYTE* pb = (BYTE*)::CoTaskMemAlloc(cb);
  351. if (! pb)
  352. {
  353. sc = E_OUTOFMEMORY;
  354. return sc.ToHr();
  355. }
  356. *ppColSortData = (MMC_SORT_SET_DATA*)pb;
  357. (*ppColSortData)->cbSize = sizeof(MMC_SORT_SET_DATA);
  358. (*ppColSortData)->nNumItems = nNumItems;
  359. (*ppColSortData)->pSortData = (MMC_SORT_DATA*)(pb + sizeof(MMC_SORT_SET_DATA));
  360. CColumnSortList::iterator itSortInfo;
  361. int i = 0;
  362. MMC_SORT_DATA* pSortData = (*ppColSortData)->pSortData;
  363. for (itSortInfo = pColSortList->begin();itSortInfo != pColSortList->end(); itSortInfo++, i++)
  364. {
  365. pSortData[i].nColIndex = (*itSortInfo).m_nCol;
  366. pSortData[i].dwSortOptions = (*itSortInfo).m_dwSortOptions;
  367. pSortData[i].ulReserved = (*itSortInfo).m_lpUserParam;
  368. }
  369. sc = S_OK;
  370. return sc.ToHr();
  371. }
  372. HRESULT WINAPI ColumnInterfaceFunc(void* pv, REFIID riid, LPVOID* ppv, DWORD_PTR dw)
  373. {
  374. *ppv = NULL;
  375. ASSERT(IID_IColumnData == riid);
  376. CColumnData* pColData = (CColumnData*)(pv);
  377. CNodeInitObject* pNodeInit = dynamic_cast<CNodeInitObject*>(pColData);
  378. if (pNodeInit && pNodeInit->GetComponent())
  379. {
  380. IColumnData* pIColData = dynamic_cast<IColumnData*>(pNodeInit);
  381. pIColData->AddRef();
  382. *ppv = static_cast<void*>(pIColData);
  383. return S_OK;
  384. }
  385. return E_NOINTERFACE;
  386. }