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.

297 lines
8.0 KiB

  1. //-----------------------------------------------------------------------------
  2. // File: flextree.h
  3. //
  4. // Desc: Implements a tree class, similar to a Windows tree control,
  5. // based on CFlexWnd. It is used by the page to display the action
  6. // list when the user wishes to assign an action to a control.
  7. //
  8. // Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  9. //-----------------------------------------------------------------------------
  10. #ifndef __FLEXTREE_H__
  11. #define __FLEXTREE_H__
  12. #include "flexscrollbar.h"
  13. class CFTItem;
  14. class CFlexTree;
  15. typedef struct {
  16. CFlexTree *pTree;
  17. CFTItem *pItem, *pOldItem;
  18. POINT point;
  19. HDC hDC;
  20. WPARAM fwKeys;
  21. BOOL bLeft;
  22. } FLEXTREENOTIFY;
  23. enum {
  24. FTN_CLICK,
  25. FTN_OWNERDRAW,
  26. FTN_SELCHANGED,
  27. FTN_MOUSEOVER
  28. };
  29. enum {
  30. CLMF_NONE = 0x00000000,
  31. CLMF_TEXTCOLOR = 0x00000001,
  32. CLMF_BKCOLOR = 0x00000002,
  33. CLMF_BKMODE = 0x00000004,
  34. CLMF_BKEXTENDS = 0x00000008,
  35. CLMF_FONT = 0x00000010,
  36. CLMF_LINECOLOR = 0x00000020,
  37. CLMF_ALL = 0x0000003f
  38. };
  39. struct _CAPTIONLOOK;
  40. typedef struct _CAPTIONLOOK {
  41. _CAPTIONLOOK() : dwSize(sizeof(_CAPTIONLOOK)), dwMask(CLMF_NONE),
  42. rgbTextColor(RGB(0,0,0)), rgbBkColor(RGB(255,255,255)), rgbLineColor(RGB(255,0,0)), nBkMode(TRANSPARENT),
  43. bBkExtends(FALSE), hFont(NULL) {}
  44. DWORD dwSize;
  45. DWORD dwMask;
  46. COLORREF rgbTextColor, rgbBkColor, rgbLineColor, nBkMode;
  47. BOOL bBkExtends;
  48. HFONT hFont;
  49. } CAPTIONLOOK;
  50. typedef enum {
  51. ATTACH_FIRSTCHILD,
  52. ATTACH_LASTCHILD,
  53. ATTACH_FIRSTSIBLING,
  54. ATTACH_LASTSIBLING,
  55. ATTACH_BEFORE,
  56. ATTACH_AFTER
  57. } ATTACHREL;
  58. class CFlexTree : public CFlexWnd
  59. {
  60. friend class CFTItem;
  61. public:
  62. CFlexTree();
  63. ~CFlexTree();
  64. // creation
  65. BOOL Create(HWND hParent, const RECT &, BOOL bVisible = TRUE, BOOL bOwnerDraw = FALSE);
  66. // look
  67. void SetScrollBarColors(COLORREF bk, COLORREF fill, COLORREF line);
  68. void SetDefCaptionLook(const CAPTIONLOOK &, BOOL bSel = FALSE);
  69. void GetDefCaptionLook(CAPTIONLOOK &, BOOL bSel = FALSE) const;
  70. void SetDefMargin(const RECT &);
  71. void GetDefMargin(RECT &) const;
  72. void SetRootChildIndent(int);
  73. int GetRootChildIndent() const;
  74. void SetDefChildIndent(int);
  75. int GetDefChildIndent() const;
  76. void SetBkColor(COLORREF);
  77. COLORREF GetBkColor() const;
  78. // adding default type items
  79. CFTItem *DefAddItem(LPCTSTR tszCaption, CFTItem *to, ATTACHREL rel = ATTACH_AFTER);
  80. CFTItem *DefAddItem(LPCTSTR tszCaption, ATTACHREL rel = ATTACH_AFTER);
  81. // freeing
  82. void FreeAll();
  83. // root access
  84. operator CFTItem *() const {return m_pRoot;}
  85. CFTItem *GetRoot() const {return m_pRoot;}
  86. // access
  87. CFTItem *GetFirstItem() const;
  88. CFTItem *GetLastItem() const;
  89. CFTItem *GetFirstVisibleItem() const;
  90. CFTItem *GetItemFromPoint(POINT point) const;
  91. // selection
  92. void SetCurSel(CFTItem *);
  93. CFTItem *GetCurSel() const;
  94. // finding
  95. CFTItem *FindItem(const GUID &guid, void *pUserData) const;
  96. CFTItem *FindItemEx(const GUID &guid, DWORD dwFindType, void *pVoid) const;
  97. protected:
  98. virtual BOOL OnEraseBkgnd(HDC hDC) {return TRUE;}
  99. virtual void OnPaint(HDC hDC);
  100. virtual void OnMouseOver(POINT point, WPARAM fwKeys);
  101. virtual void OnClick(POINT point, WPARAM fwKeys, BOOL bLeft);
  102. virtual void OnWheel(POINT point, WPARAM wParam);
  103. virtual LRESULT WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  104. // event notification firing
  105. void FireClick(CFTItem *pItem, POINT point, WPARAM fwKeys, BOOL bLeft);
  106. BOOL FireOwnerDraw(CFTItem *pItem, HDC hDC);
  107. void FireSelChanged(CFTItem *pItem, CFTItem *pOld);
  108. private:
  109. CFTItem *m_pRoot; // root item
  110. CFTItem *m_pCurSel; // selected item
  111. CFTItem *m_pLastAdded;
  112. BOOL m_bOwnerDraw;
  113. POINT m_ptScrollOrigin;
  114. COLORREF m_rgbBkColor;
  115. CAPTIONLOOK m_clDefNormal, m_clDefSelected;
  116. RECT m_defmargin;
  117. int m_nDefChildIndent;
  118. // scrolling
  119. int m_nVertSBWidth;
  120. int m_nHorzSBHeight;
  121. BOOL m_bVertSB, m_bHorzSB;
  122. CFlexScrollBar m_VertSB, m_HorzSB;
  123. int m_nTotalWidth;
  124. // helpers
  125. BOOL m_bNeedPaintBkgnd;
  126. void SetDirty();
  127. void InternalPaint(HDC hDC);
  128. BOOL m_bDirty;
  129. void Calc();
  130. void CalcItems();
  131. BOOL IsMine(CFTItem *pItem);
  132. void LosePointer(CFTItem *pItem);
  133. };
  134. class CFTItem
  135. {
  136. friend class CFlexTree;
  137. public:
  138. CFTItem();
  139. ~CFTItem();
  140. // operations
  141. BOOL IsOut() const;
  142. BOOL IsExpanded() const {return m_bExpanded;}
  143. void Expand(BOOL bAll = FALSE);
  144. void ExpandAll() {Expand(TRUE);}
  145. void Collapse(BOOL bAll = FALSE);
  146. void CollapseAll() {Collapse(TRUE);}
  147. void EnsureVisible();
  148. void Invalidate();
  149. // caption
  150. void SetCaptionLook(const CAPTIONLOOK &, BOOL bSel = FALSE);
  151. void GetCaptionLook(CAPTIONLOOK &, BOOL bSel = FALSE) const;
  152. void SetCaption(LPCTSTR);
  153. LPCTSTR GetCaption() const;
  154. BOOL HasCaption() const {return GetCaption() != NULL;}
  155. void SetMargin(const RECT &);
  156. void GetMargin(RECT &) const;
  157. // attach/detachment
  158. void Detach(); // detaches this leaf/branch from parent. (does not affect children, who may still be attached to this)
  159. void FreeChildren(); // detach and free each child (which in turn frees all their's, etc.)
  160. BOOL Attach(CFTItem *to, ATTACHREL rel);
  161. BOOL Attach(CFTItem &to, ATTACHREL rel) {return Attach(&to, rel);}
  162. BOOL IsOnTree() const;
  163. BOOL IsAttached() const;
  164. BOOL IsAlone() const;
  165. // family access
  166. CFlexTree *GetTree() const {return m_pTree;}
  167. CFTItem *GetParent() const {return m_pParent;}
  168. CFTItem *GetPrevSibling() const {return m_pPrev;}
  169. CFTItem *GetNextSibling() const {return m_pNext;}
  170. CFTItem *GetFirstChild() const {return m_pFirst;}
  171. CFTItem *GetLastChild() const {return m_pLast;}
  172. CFTItem *GetNextOut() const;
  173. CFTItem *GetNext(BOOL bOutOnly = FALSE) const;
  174. BOOL HasChildren() const {return m_pFirst != NULL;}
  175. // dimension access
  176. void GetItemRect(RECT &) const;
  177. void GetBranchRect(RECT &) const;
  178. // user guid/data operations
  179. BOOL IsUserGUID(const GUID &check) const {return IsEqualGUID(m_UserGUID, check);}
  180. void SetUserGUID(const GUID &set) {m_UserGUID = set;}
  181. const GUID &GetUserGUID() const {return m_UserGUID;}
  182. void SetUserData(void *p) {m_pUserData = p;}
  183. void *GetUserData() const {return m_pUserData;}
  184. // selection
  185. BOOL IsSelected() const;
  186. // owner draw
  187. void PaintInto(HDC hDC);
  188. protected:
  189. // internal/derived-customization operations
  190. void SetWidth(int);
  191. int GetWidth() const {return m_nWidth;}
  192. void SetHeight(int);
  193. int GetHeight() const {return m_nHeight;}
  194. void SetIndent(int);
  195. int GetIndent() const {return m_nIndent;}
  196. void SetChildIndent(int);
  197. int GetChildIndent() const {return m_nChildIndent;}
  198. // customization
  199. virtual void OnPaint(HDC hDC);
  200. virtual void OnMouseOver(POINT point, WPARAM fwKeys) {}
  201. virtual void OnClick(POINT point, WPARAM fwKeys, BOOL bLeft);
  202. // expansion customization
  203. public: virtual BOOL IsExpandable() {return GetFirstChild() != NULL;}
  204. protected:
  205. virtual void OnExpand() {}
  206. virtual void OnCollapse() {}
  207. // finding
  208. virtual BOOL FoundItem(DWORD dwUser, void *pUser) const {return FALSE;}
  209. // event notification firing
  210. void FireClick(POINT point, WPARAM fwKeys, BOOL bLeft);
  211. BOOL FireOwnerDraw(HDC hDC);
  212. private:
  213. // caption
  214. LPTSTR m_ptszCaption;
  215. CAPTIONLOOK m_clNormal, m_clSelected;
  216. RECT m_margin;
  217. // user data
  218. GUID m_UserGUID;
  219. void *m_pUserData;
  220. // raw characteristics
  221. int m_nWidth; // item's width (used only to provide horizontal scrolling as necessary)
  222. int m_nHeight; // item's height (not including children)
  223. int m_nIndent; // indent of this item relative to parent's child indent origin (full origin = this + parent origin + parent child indent)
  224. int m_nChildIndent; // indentation of this item's children (relative to this's origin)
  225. // calced characteristics
  226. int m_nBranchHeight; // height of item and all currently expanded children
  227. // calced positioning
  228. POINT m_origin; // relative to ideal tree origin
  229. // state
  230. BOOL m_bExpanded; // is branch expanded/children shown?
  231. // family
  232. CFlexTree *m_pTree;
  233. CFTItem *m_pParent, *m_pPrev, *m_pNext, *m_pFirst, *m_pLast;
  234. // root
  235. BOOL IsRoot() const;
  236. void SetRoot(CFlexTree *);
  237. // helpers
  238. void SetTree(CFlexTree *);
  239. BOOL Attach(CFTItem *pParent, CFTItem *pPrev, CFTItem *pNext);
  240. void SetTreeDirty(CFlexTree *pTree = NULL);
  241. void RecalcText();
  242. void Init();
  243. void SelChangedInternal();
  244. void InternalExpand(BOOL bExpand, BOOL bAll);
  245. };
  246. #endif //__FLEXTREE_H__