Source code of Windows XP (NT5)
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.

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