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.

331 lines
9.4 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // TreeItem.h
  7. //
  8. // Abstract:
  9. // Definition of the CTreeItem class.
  10. //
  11. // Implementation File:
  12. // TreeItem.cpp
  13. //
  14. // Author:
  15. // David Potter (davidp) May 3, 1996
  16. //
  17. // Revision History:
  18. //
  19. // Notes:
  20. //
  21. /////////////////////////////////////////////////////////////////////////////
  22. #ifndef _TREEITEM_H_
  23. #define _TREEITEM_H_
  24. #ifndef __AFXTEMPL_H__
  25. #include "afxtempl.h" // for CList
  26. #endif
  27. /////////////////////////////////////////////////////////////////////////////
  28. // Forward Class Declarations
  29. /////////////////////////////////////////////////////////////////////////////
  30. class CTreeItemList;
  31. class CTreeItemContext;
  32. class CTreeItem;
  33. /////////////////////////////////////////////////////////////////////////////
  34. // External Class Declarations
  35. /////////////////////////////////////////////////////////////////////////////
  36. class CClusterItem;
  37. class CSplitterFrame;
  38. class CClusterListView;
  39. class CClusterTreeView;
  40. /////////////////////////////////////////////////////////////////////////////
  41. // Type Definitions
  42. /////////////////////////////////////////////////////////////////////////////
  43. typedef CList<CTreeItemContext *, CTreeItemContext *> CTreeItemContextList;
  44. /////////////////////////////////////////////////////////////////////////////
  45. // Include Files
  46. /////////////////////////////////////////////////////////////////////////////
  47. #ifndef _BASECMDT_H_
  48. #include "BaseCmdT.h" // for CBaseCmdTarget
  49. #endif
  50. #ifndef _COLITEM_H_
  51. #include "ColItem.h" // for CColumnItem
  52. #endif
  53. #ifndef _LISTITEM_H_
  54. #include "ListItem.h" // for CListItemList
  55. #endif
  56. /////////////////////////////////////////////////////////////////////////////
  57. // CTreeItemList
  58. /////////////////////////////////////////////////////////////////////////////
  59. class CTreeItemList : public CList<CTreeItem *, CTreeItem *>
  60. {
  61. public:
  62. CTreeItem * PtiFromPci(
  63. IN const CClusterItem * pci,
  64. OUT POSITION * ppos = NULL
  65. ) const;
  66. // add before head or after tail
  67. POSITION AddHead(CTreeItem * newElement);
  68. POSITION AddTail(CTreeItem * newElement);
  69. // inserting before or after a given position
  70. POSITION InsertBefore(POSITION position, CTreeItem * newElement);
  71. POSITION InsertAfter(POSITION position, CTreeItem * newElement);
  72. }; //*** class CTreeItemList
  73. /////////////////////////////////////////////////////////////////////////////
  74. // CTreeItemContext
  75. /////////////////////////////////////////////////////////////////////////////
  76. class CTreeItemContext : public CObject
  77. {
  78. DECLARE_DYNCREATE(CTreeItemContext)
  79. public:
  80. CSplitterFrame * m_pframe;
  81. CTreeItem * m_pti;
  82. HTREEITEM m_hti;
  83. BOOL m_bExpanded;
  84. DWORD * m_prgnColumnInfo;
  85. CTreeItemContext(void)
  86. {
  87. CommonConstruct();
  88. };
  89. CTreeItemContext(
  90. CSplitterFrame * pframe,
  91. CTreeItem * pti,
  92. HTREEITEM hti,
  93. BOOL bExpanded
  94. )
  95. {
  96. CommonConstruct();
  97. m_pframe = pframe;
  98. m_pti = pti;
  99. m_hti = hti;
  100. m_bExpanded = bExpanded;
  101. }
  102. ~CTreeItemContext(void)
  103. {
  104. SaveProfileInfo();
  105. delete [] m_prgnColumnInfo;
  106. m_prgnColumnInfo = NULL;
  107. }
  108. void CommonConstruct(void)
  109. {
  110. m_pframe = NULL;
  111. m_pti = NULL;
  112. m_hti = NULL;
  113. m_bExpanded = FALSE;
  114. m_prgnColumnInfo = NULL;
  115. }
  116. void Init(void);
  117. void SaveProfileInfo(void);
  118. DWORD * PrgnColumnInfo(void);
  119. BOOL BIsExpanded(void) const;
  120. }; //*** class CTreeItemContext
  121. /////////////////////////////////////////////////////////////////////////////
  122. // CTreeItem command target
  123. /////////////////////////////////////////////////////////////////////////////
  124. class CTreeItem : public CBaseCmdTarget
  125. {
  126. friend class CClusterTreeView;
  127. DECLARE_DYNCREATE(CTreeItem)
  128. CTreeItem(void); // protected constructor used by dynamic creation
  129. CTreeItem(IN OUT CTreeItem * ptiParent, IN OUT CClusterItem * pci, IN BOOL m_fTakeOwnership = FALSE);
  130. void Init(void);
  131. // Attributes
  132. protected:
  133. CTreeItem * m_ptiParent;
  134. CClusterItem * m_pci;
  135. BOOL m_bWeOwnPci;
  136. CString m_strProfileSection;
  137. CColumnItemList m_lpcoli;
  138. CTreeItemList m_lptiChildren;
  139. CListItemList m_lpliChildren;
  140. CTreeItemContextList m_lptic;
  141. const CTreeItemContextList & Lptic(void) const { return m_lptic; }
  142. public:
  143. CTreeItem * PtiParent(void) const { return m_ptiParent; }
  144. CClusterItem * Pci(void) const { return m_pci; }
  145. const CString & StrProfileSection(void);
  146. const CColumnItemList & Lpcoli(void) const { return m_lpcoli; }
  147. const CTreeItemList & LptiChildren(void) const { return m_lptiChildren; }
  148. const CListItemList & LpliChildren(void) const { return m_lpliChildren; }
  149. const CString & StrName(void) const;
  150. DWORD * PrgnColumnInfo(IN const CClusterListView * pclv)
  151. {
  152. CTreeItemContext * ptic;
  153. ptic = PticFromView(pclv);
  154. ASSERT_VALID(ptic);
  155. return ptic->PrgnColumnInfo();
  156. } //*** CTreeItem::PrgnColumnInfo()
  157. // Operations
  158. public:
  159. HTREEITEM HtiInsertInTree(IN OUT CClusterTreeView * pctv);
  160. void RemoveFromAllLists(void);
  161. void PreRemoveFromFrame(IN OUT CSplitterFrame * pframe);
  162. void PreRemoveFromFrameWithChildren(IN OUT CSplitterFrame * pframe);
  163. CColumnItem * PcoliAddColumn(
  164. IN const CString & rstrText,
  165. IN IDS idsColumnID,
  166. IN int nDefaultWidth = -1,
  167. IN int nWidth = -1
  168. );
  169. CColumnItem * PcoliAddColumn(IN IDS idsText, IN int nDefaultWidth = -1, IN int nWidth = -1);
  170. void DeleteAllColumns(void) { m_lpcoli.RemoveAll(); }
  171. void UpdateState(void);
  172. void UpdateAllStatesInTree(void);
  173. void UpdateUIState(void);
  174. void Select(IN OUT CClusterTreeView * pctv, IN BOOL bSelectInTree);
  175. // void Unselect(CClusterTreeView * pctv);
  176. CTreeItem * PtiAddChildBefore(
  177. IN const CClusterItem * pciOld,
  178. OUT CClusterItem * pciNew,
  179. IN BOOL bTakeOwnership = FALSE
  180. );
  181. void InsertChildInAllTrees(IN OUT CTreeItem * ptiNewChild);
  182. CTreeItem * PtiAddChild(IN OUT CClusterItem * pci, IN BOOL bTakeOwnership = FALSE);
  183. CTreeItem * PtiAddChild(IN const CString & rstrName);
  184. CTreeItem * PtiAddChild(IN IDS idsName);
  185. CListItem * PliAddChild(IN OUT CClusterItem * pci);
  186. CTreeItem * PtiChildFromName(IN const CString & rstrName, OUT POSITION * ppos = NULL) const;
  187. CTreeItem * PtiChildFromName(IN IDS idsName, OUT POSITION * ppos = NULL) const;
  188. CTreeItem * PtiChildFromPci(IN const CClusterItem * pci) const;
  189. CListItem * PliChildFromPci(IN const CClusterItem * pci) const;
  190. void RemoveItem(void);
  191. void RemoveChild(IN OUT CClusterItem * pci);
  192. CMenu * PmenuPopup(void);
  193. BOOL BSelectItem(IN OUT CClusterTreeView * pctv);
  194. BOOL BExpand(IN OUT CClusterTreeView * pctv, IN UINT nCode);
  195. void SelectInAllViews(void);
  196. void ExpandInAllViews(IN UINT nCode);
  197. void SetExpandedState(IN const CClusterTreeView * pctv, IN BOOL bExpanded);
  198. BOOL BShouldBeExpanded(IN const CClusterTreeView * pctv) const;
  199. void OpenChild(IN OUT CTreeItem * pti, IN OUT CSplitterFrame * pframe);
  200. void EditLabel(IN OUT CClusterTreeView * pctv);
  201. void Delete(void);
  202. protected:
  203. void Cleanup(void);
  204. // Overrides
  205. // ClassWizard generated virtual function overrides
  206. //{{AFX_VIRTUAL(CTreeItem)
  207. public:
  208. virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
  209. //}}AFX_VIRTUAL
  210. // Implementation
  211. public:
  212. virtual ~CTreeItem(void);
  213. protected:
  214. CTreeItemContext * PticFromFrame(IN const CSplitterFrame * pframe) const;
  215. CTreeItemContext * PticFromView(IN const CClusterTreeView * pctv) const;
  216. CTreeItemContext * PticFromView(IN const CClusterListView * pclv) const;
  217. HTREEITEM HtiFromView(IN const CClusterTreeView * pctv) const;
  218. // Generated message map functions
  219. //{{AFX_MSG(CTreeItem)
  220. //}}AFX_MSG
  221. DECLARE_MESSAGE_MAP()
  222. }; //*** class CTreeItem
  223. /////////////////////////////////////////////////////////////////////////////
  224. // Global Functions
  225. /////////////////////////////////////////////////////////////////////////////
  226. void AFXAPI DestructElements(CTreeItem ** pElements, int nCount);
  227. void DeleteAllItemData(IN OUT CTreeItemList & rlp);
  228. void DeleteAllItemData(IN OUT CTreeItemContextList & rlp);
  229. /////////////////////////////////////////////////////////////////////////////
  230. // Inline Functions
  231. /////////////////////////////////////////////////////////////////////////////
  232. inline POSITION CTreeItemList::AddHead(CTreeItem * newElement)
  233. {
  234. ASSERT_VALID(newElement);
  235. POSITION pos = CList<CTreeItem *,CTreeItem *>::AddHead(newElement);
  236. if (pos != NULL)
  237. newElement->AddRef();
  238. return pos;
  239. } //*** CTreeItemList::AddHead()
  240. inline POSITION CTreeItemList::AddTail(CTreeItem * newElement)
  241. {
  242. ASSERT_VALID(newElement);
  243. POSITION pos = CList<CTreeItem *,CTreeItem *>::AddTail(newElement);
  244. if (pos != NULL)
  245. newElement->AddRef();
  246. return pos;
  247. } //*** CTreeItemList::AddTail()
  248. inline POSITION CTreeItemList::InsertBefore(POSITION position, CTreeItem * newElement)
  249. {
  250. ASSERT_VALID(newElement);
  251. POSITION pos = CList<CTreeItem *,CTreeItem *>::InsertBefore(position, newElement);
  252. if (pos != NULL)
  253. newElement->AddRef();
  254. return pos;
  255. } //*** CTreeItemList::InsertBefore()
  256. inline POSITION CTreeItemList::InsertAfter(POSITION position, CTreeItem * newElement)
  257. {
  258. ASSERT_VALID(newElement);
  259. POSITION pos = CList<CTreeItem *,CTreeItem *>::InsertAfter(position, newElement);
  260. if (pos != NULL)
  261. newElement->AddRef();
  262. return pos;
  263. } //*** CTreeItemList::InsertAfter()
  264. /////////////////////////////////////////////////////////////////////////////
  265. #endif // _TREEITEM_H_