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.

524 lines
14 KiB

  1. // DSColumn.h : Declaration of ds column routines and classes
  2. //
  3. //+-------------------------------------------------------------------------
  4. //
  5. // Microsoft Windows
  6. // Copyright (C) Microsoft Corporation, 1992 - 1999
  7. //
  8. // File: DSColumn.h
  9. //
  10. // Contents: Static data and column set routines and classes
  11. //
  12. // History: 12-mar-99 jeffjon Created
  13. //
  14. //--------------------------------------------------------------------------
  15. #ifndef _DS_COLUMN_H_
  16. #define _DS_COLUMN_H_
  17. class CDSCookie;
  18. ////////////////////////////////////////////////////////////////////////////////
  19. #define DEFAULT_COLUMN_SET L"default"
  20. #define SPECIAL_COLUMN_SET L"special"
  21. typedef enum _ATTRIBUTE_COLUMN_TYPE {
  22. ATTR_COLTYPE_NAME,
  23. ATTR_COLTYPE_CLASS,
  24. ATTR_COLTYPE_DESC,
  25. ATTR_COLTYPE_SPECIAL,
  26. ATTR_COLTYPE_MODIFIED_TIME,
  27. } ATTRIBUTE_COLUMN_TYPE;
  28. typedef BOOL (*COLUMN_EXTRACTION_FUNCTION)(
  29. OUT CString& strref,
  30. IN CDSCookie* pCookie,
  31. IN PADS_SEARCH_COLUMN pColumn);
  32. typedef struct _ATTRIBUTE_COLUMN {
  33. ATTRIBUTE_COLUMN_TYPE coltype;
  34. UINT resid;
  35. int iColumnWidth;
  36. LPCTSTR pcszAttribute;
  37. COLUMN_EXTRACTION_FUNCTION pfnExtract;
  38. } ATTRIBUTE_COLUMN, *PATTRIBUTE_COLUMN;
  39. typedef struct _ColumnsForClass {
  40. LPCTSTR pcszLdapClassName;
  41. LPCTSTR pcszColumnID;
  42. int nColumns;
  43. PATTRIBUTE_COLUMN* apColumns;
  44. } COLUMNS_FOR_CLASS, *PCOLUMNS_FOR_CLASS;
  45. typedef struct _SpecialColumn {
  46. UINT resid;
  47. LPCTSTR ptszAttribute;
  48. int iColumnWidth;
  49. } SPECIAL_COLUMN, *PSPECIAL_COLUMN;
  50. ////////////////////////////////////////////////////////////////////////////////
  51. // CColumn
  52. class CColumn
  53. {
  54. public:
  55. CColumn(LPCWSTR lpszColumnHeader,
  56. int nFormat,
  57. int nWidth,
  58. int nColumnNum,
  59. BOOL bDefaultVisible)
  60. {
  61. m_lpszColumnHeader = NULL;
  62. SetHeader(lpszColumnHeader);
  63. m_nFormat = nFormat;
  64. m_nWidth = nWidth;
  65. m_nColumnNum = nColumnNum;
  66. m_bDefaultVisible = bDefaultVisible;
  67. m_bVisible = bDefaultVisible;
  68. }
  69. virtual ~CColumn()
  70. {
  71. if (m_lpszColumnHeader != NULL)
  72. free(m_lpszColumnHeader);
  73. }
  74. protected:
  75. CColumn() {}
  76. private:
  77. //
  78. // Do nothing copy constructor and operator =
  79. //
  80. CColumn(CColumn&) {}
  81. CColumn& operator=(CColumn&) {}
  82. public:
  83. LPCWSTR GetHeader() { return (LPCWSTR)m_lpszColumnHeader; }
  84. void SetHeader(LPCWSTR lpszColumnHeader)
  85. {
  86. if (m_lpszColumnHeader != NULL)
  87. {
  88. free(m_lpszColumnHeader);
  89. }
  90. size_t iLen = wcslen(lpszColumnHeader);
  91. m_lpszColumnHeader = (LPWSTR)malloc(sizeof(WCHAR) * (iLen + 1));
  92. if (m_lpszColumnHeader != NULL)
  93. {
  94. wcscpy(m_lpszColumnHeader, lpszColumnHeader);
  95. }
  96. }
  97. int GetFormat() { return m_nFormat; }
  98. void SetFormat(int nFormat) { m_nFormat = nFormat; }
  99. int GetWidth() { return m_nWidth; }
  100. void SetWidth(int nWidth) { m_nWidth = nWidth; }
  101. int GetColumnNum() { return m_nColumnNum; }
  102. void SetColumnNum(int nColumnNum) { m_nColumnNum = nColumnNum; }
  103. void SetVisible(BOOL bVisible) { m_bVisible = bVisible; }
  104. BOOL IsVisible() { return m_bVisible; }
  105. void SetDefaultVisibility() { m_bVisible = m_bDefaultVisible; }
  106. protected:
  107. LPWSTR m_lpszColumnHeader;
  108. int m_nFormat;
  109. int m_nWidth;
  110. int m_nColumnNum;
  111. BOOL m_bVisible;
  112. BOOL m_bDefaultVisible;
  113. };
  114. ////////////////////////////////////////////////////////////////////////////////
  115. // CDSColumn
  116. class CDSColumn : public CColumn
  117. {
  118. public:
  119. CDSColumn(LPCWSTR lpszColumnHeader,
  120. int nFormat,
  121. int nWidth,
  122. UINT nColumnNum,
  123. BOOL bDefaultVisible,
  124. LPCWSTR lpszAttribute,
  125. ATTRIBUTE_COLUMN_TYPE type,
  126. COLUMN_EXTRACTION_FUNCTION pfnExtract)
  127. : CColumn(lpszColumnHeader, nFormat, nWidth, nColumnNum, bDefaultVisible)
  128. {
  129. if (lpszAttribute != NULL)
  130. {
  131. // Make a copy of the attribute
  132. size_t iLen = wcslen(lpszAttribute);
  133. m_lpszAttribute = (LPWSTR)malloc(sizeof(WCHAR) * (iLen + 1));
  134. //NTRAID#NTBUG9-572012-2002/03/10-jmessec malloc may have failed, leaving m_lpszAttribute == NULL for following wcscpy
  135. wcscpy(m_lpszAttribute, lpszAttribute);
  136. }
  137. else
  138. {
  139. m_lpszAttribute = NULL;
  140. }
  141. m_type = type;
  142. m_pfnExtract = pfnExtract;
  143. }
  144. virtual ~CDSColumn()
  145. {
  146. if (m_lpszAttribute != NULL)
  147. {
  148. free(m_lpszAttribute);
  149. }
  150. }
  151. protected:
  152. CDSColumn() {}
  153. private:
  154. //
  155. // Do nothing copy constructor and operator =
  156. //
  157. CDSColumn(CDSColumn&) {}
  158. CDSColumn& operator=(CDSColumn&) {}
  159. public:
  160. LPCWSTR GetColumnAttribute() { return (LPCWSTR)m_lpszAttribute; }
  161. ATTRIBUTE_COLUMN_TYPE GetColumnType() { return m_type; }
  162. COLUMN_EXTRACTION_FUNCTION GetExtractionFunction() { return m_pfnExtract; }
  163. private :
  164. LPWSTR m_lpszAttribute;
  165. ATTRIBUTE_COLUMN_TYPE m_type;
  166. COLUMN_EXTRACTION_FUNCTION m_pfnExtract;
  167. };
  168. ////////////////////////////////////////////////////////////////////////////////
  169. // CColumnSet
  170. typedef CList<CColumn*, CColumn*> CColumnList;
  171. class CColumnSet : public CColumnList
  172. {
  173. public :
  174. CColumnSet(LPCWSTR lpszColumnID)
  175. {
  176. // Make a copy of the column set ID
  177. if (lpszColumnID)
  178. {
  179. size_t iLen = wcslen(lpszColumnID);
  180. m_lpszColumnID = (LPWSTR)malloc(sizeof(WCHAR) * (iLen + 1));
  181. if (m_lpszColumnID != NULL)
  182. {
  183. wcscpy(m_lpszColumnID, lpszColumnID);
  184. }
  185. //NTRAID#NTBUG9-571988-2002/03/10-jmessec If malloc fails, object is left in unexpected state
  186. }
  187. else
  188. {
  189. //NTRAID#NTBUG9-567482-2002/03/10-jmessec This does nothing! in release code. Back it up with code.
  190. ASSERT(FALSE);
  191. }
  192. }
  193. virtual ~CColumnSet()
  194. {
  195. while(!IsEmpty())
  196. {
  197. CColumn* pColumn = RemoveTail();
  198. delete pColumn;
  199. }
  200. if (m_lpszColumnID != NULL)
  201. free(m_lpszColumnID);
  202. }
  203. protected:
  204. CColumnSet() {}
  205. private:
  206. //
  207. // Do nothing copy constructor and operator =
  208. //
  209. CColumnSet(CColumnSet&) {}
  210. CColumnSet& operator=(CColumnSet&) {}
  211. public:
  212. void AddColumn(LPCWSTR lpszHeader, int nFormat, int nWidth, UINT nCol, BOOL bDefaultVisible)
  213. {
  214. CColumn* pNewColumn = new CColumn(lpszHeader, nFormat, nWidth, nCol, bDefaultVisible);
  215. AddTail(pNewColumn);
  216. }
  217. void AddColumn(CColumn* pNewColumn) { AddTail(pNewColumn); }
  218. LPCWSTR GetColumnID() { return (LPCWSTR)m_lpszColumnID; }
  219. void SetColumnID(LPCWSTR lpszColumnID)
  220. {
  221. if (m_lpszColumnID != NULL)
  222. {
  223. free(m_lpszColumnID);
  224. }
  225. // Make a copy of the column set ID
  226. size_t iLen = wcslen(lpszColumnID);
  227. m_lpszColumnID = (LPWSTR)malloc(sizeof(WCHAR) * (iLen + 1));
  228. //NTRAID#NTBUG9-571988-2002/03/10-jmessec malloc may have failed, leaving m_lpszColumnID == NULL for following wcscpy
  229. wcscpy(m_lpszColumnID, lpszColumnID);
  230. }
  231. int GetNumCols() { return (int)GetCount(); }
  232. CColumn* GetColumnAt(int idx)
  233. {
  234. POSITION pos = GetHeadPosition();
  235. while (pos != NULL)
  236. {
  237. CColumn* pCol = GetNext(pos);
  238. if (pCol->GetColumnNum() == idx)
  239. return pCol;
  240. }
  241. return NULL;
  242. }
  243. void ClearVisibleColumns()
  244. {
  245. POSITION pos = GetHeadPosition();
  246. while (pos != NULL)
  247. {
  248. CColumn* pCol = GetNext(pos);
  249. pCol->SetVisible(FALSE);
  250. }
  251. }
  252. void AddVisibleColumns(MMC_COLUMN_DATA* pColumnData, int nNumCols)
  253. {
  254. TRACE(L"CColumnSet::AddVisibleColumns(MMC_COLUMN_DATA*) GetColumnID() = %s\n", GetColumnID());
  255. if (pColumnData == NULL)
  256. {
  257. ASSERT(pColumnData != NULL);
  258. return;
  259. }
  260. for (int idx = 0; idx < nNumCols; idx++)
  261. {
  262. TRACE(L"====================\n");
  263. TRACE(L"pColumnData[%d].nColIndex = %d\n", idx, pColumnData[idx].nColIndex);
  264. TRACE(L"pColumnData[%d].dwFlags = 0x%x\n", idx, pColumnData[idx].dwFlags);
  265. CColumn* pCol = GetColumnAt(pColumnData[idx].nColIndex);
  266. ASSERT(pCol != NULL);
  267. if (pCol == NULL)
  268. {
  269. continue;
  270. }
  271. LPCWSTR lpszHeader = pCol->GetHeader();
  272. TRACE(L"Column Header = %s, IsVisible() = %d\n", lpszHeader, pCol->IsVisible());
  273. if (!(pColumnData[idx].dwFlags & HDI_HIDDEN))
  274. {
  275. TRACE(L"pCol->SetVisible(TRUE);\n");
  276. pCol->SetVisible(TRUE);
  277. }
  278. }
  279. }
  280. void AddVisibleColumns(MMC_VISIBLE_COLUMNS* pVisibleColumns)
  281. {
  282. TRACE(L"CColumnSet::AddVisibleColumns(MMC_VISIBLE_COLUMNS*) GetColumnID() = %s\n", GetColumnID());
  283. if (pVisibleColumns == NULL)
  284. {
  285. ASSERT(pVisibleColumns != NULL);
  286. return;
  287. }
  288. for (int idx = 0; idx < pVisibleColumns->nVisibleColumns; idx++)
  289. {
  290. TRACE(L"====================\n");
  291. TRACE(L"pVisibleColumns->rgVisibleCols[%d] = %d\n", idx, pVisibleColumns->rgVisibleCols[idx]);
  292. if (pVisibleColumns->rgVisibleCols[idx] < GetCount())
  293. {
  294. CColumn* pCol = GetColumnAt(pVisibleColumns->rgVisibleCols[idx]);
  295. ASSERT (pCol != NULL);
  296. if (pCol == NULL)
  297. {
  298. continue;
  299. }
  300. LPCWSTR lpszHeader = pCol->GetHeader();
  301. TRACE(L"Column Header = %s, IsVisible() = %d\n", lpszHeader, pCol->IsVisible());
  302. pCol->SetVisible(TRUE);
  303. }
  304. }
  305. }
  306. void SetAllColumnsToDefaultVisibility()
  307. {
  308. POSITION pos = GetHeadPosition();
  309. while (pos != NULL)
  310. {
  311. CColumn* pCol = GetNext(pos);
  312. ASSERT(pCol != NULL);
  313. pCol->SetDefaultVisibility();
  314. }
  315. }
  316. HRESULT LoadFromColumnData(IColumnData* pColumnData)
  317. {
  318. TRACE(L"CColumnSet::LoadFromColumnData(), GetColumnID() = %s\n", GetColumnID());
  319. LPCWSTR lpszID = GetColumnID();
  320. size_t iLen = wcslen(lpszID);
  321. // allocate enough memory for the struct and the column ID
  322. SColumnSetID* pNodeID = (SColumnSetID*)new BYTE[sizeof(SColumnSetID) + (iLen * sizeof(WCHAR))];
  323. if (!pNodeID)
  324. {
  325. return E_OUTOFMEMORY;
  326. }
  327. memset(pNodeID, 0, sizeof(SColumnSetID) + (iLen * sizeof(WCHAR)));
  328. pNodeID->cBytes = static_cast<DWORD>(iLen * sizeof(WCHAR));
  329. memcpy(pNodeID->id, lpszID, static_cast<UINT>(iLen * sizeof(WCHAR)));
  330. MMC_COLUMN_SET_DATA* pColumnSetData = NULL;
  331. HRESULT hr = pColumnData->GetColumnConfigData(pNodeID, &pColumnSetData);
  332. if (hr == S_OK)
  333. {
  334. // the API returns S_OK or S_FALSE, so we check for S_OK
  335. ASSERT(pColumnSetData != NULL);
  336. if (pColumnSetData != NULL)
  337. {
  338. AddVisibleColumns(pColumnSetData->pColData, pColumnSetData->nNumCols);
  339. ::CoTaskMemFree(pColumnSetData);
  340. }
  341. } // if
  342. delete[] pNodeID;
  343. pNodeID = 0;
  344. return hr;
  345. }
  346. HRESULT Save(IStream* pStm);
  347. HRESULT Load(IStream* pStm);
  348. private :
  349. LPWSTR m_lpszColumnID;
  350. };
  351. ////////////////////////////////////////////////////////////////////////////////
  352. // CDSColumnSet
  353. class CDSColumnSet : public CColumnSet
  354. {
  355. public:
  356. CDSColumnSet(LPCWSTR lpszColumnID, LPCWSTR lpszClassName) : CColumnSet(lpszColumnID)
  357. {
  358. if (lpszClassName != NULL)
  359. {
  360. // Make a copy of the column class name
  361. size_t iLen = wcslen(lpszClassName);
  362. m_lpszClassName = (LPWSTR)malloc(sizeof(WCHAR) * (iLen + 1));
  363. //NTRAID#NTBUG9-571990-2002/03/10-jmessec malloc may have failed, leaving m_lpszClassName == NULL for following wcscpy
  364. wcscpy(m_lpszClassName, lpszClassName);
  365. }
  366. else
  367. {
  368. m_lpszClassName = NULL;
  369. }
  370. }
  371. virtual ~CDSColumnSet()
  372. {
  373. if (m_lpszClassName != NULL)
  374. free(m_lpszClassName);
  375. }
  376. protected:
  377. CDSColumnSet() {}
  378. private:
  379. CDSColumnSet(CDSColumnSet&) {}
  380. CDSColumnSet& operator=(CDSColumnSet&) {}
  381. public:
  382. LPCWSTR GetClassName() { return (LPCWSTR)m_lpszClassName; }
  383. static CDSColumnSet* CreateColumnSet(PCOLUMNS_FOR_CLASS pColsForClass, SnapinType snapinType);
  384. static CDSColumnSet* CreateColumnSetFromString(LPCWSTR lpszClassName, SnapinType snapinType);
  385. static CDSColumnSet* CreateDescriptionColumnSet();
  386. static CDSColumnSet* CreateColumnSetFromDisplaySpecifiers(PCWSTR pszClassName,
  387. SnapinType snapinType,
  388. MyBasePathsInfo* pBasePathsInfo);
  389. private:
  390. LPWSTR m_lpszClassName;
  391. };
  392. ////////////////////////////////////////////////////////////////////////////////
  393. // CColumnSetList
  394. class CColumnSetList : public CList<CColumnSet*, CColumnSet*>
  395. {
  396. public :
  397. CColumnSetList() : m_pDefaultColumnSet(NULL), m_pSpecialColumnSet(NULL) {}
  398. private:
  399. CColumnSetList(CColumnSetList&) {}
  400. CColumnSetList& operator=(CColumnSetList&) {}
  401. public:
  402. void Initialize(SnapinType snapinType, MyBasePathsInfo* pBasePathsInfo);
  403. // Find the column set given a column set ID
  404. CColumnSet* FindColumnSet(LPCWSTR lpszColumnID);
  405. void RemoveAndDeleteAllColumnSets()
  406. {
  407. while (!IsEmpty())
  408. {
  409. CColumnSet* pTempSet = RemoveTail();
  410. delete pTempSet;
  411. }
  412. delete m_pDefaultColumnSet;
  413. m_pDefaultColumnSet = NULL;
  414. delete m_pSpecialColumnSet;
  415. m_pSpecialColumnSet = NULL;
  416. }
  417. HRESULT Save(IStream* pStm);
  418. HRESULT Load(IStream* pStm);
  419. CColumnSet* GetDefaultColumnSet();
  420. CColumnSet* GetSpecialColumnSet();
  421. private :
  422. CColumnSet* m_pDefaultColumnSet;
  423. CColumnSet* m_pSpecialColumnSet;
  424. SnapinType m_snapinType;
  425. MyBasePathsInfo* m_pBasePathsInfo;
  426. };
  427. /////////////////////////////////////////////////////////////////////////////////////
  428. //COLUMNS_FOR_CLASS* GetColumnsForClass( LPCTSTR i_pcszLdapClassName );
  429. BOOL ColumnExtractString(
  430. OUT CString& strref,
  431. IN CDSCookie* pCookie,
  432. IN PADS_SEARCH_COLUMN pColumn);
  433. #endif // _DS_COLUMN_H_