Counter Strike : Global Offensive Source Code
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.

154 lines
3.9 KiB

  1. //========= Copyright � 1996-2009, Valve Corporation, All rights reserved. ====
  2. //
  3. //=============================================================================
  4. #ifndef TREELIST_H
  5. #define TREELIST_H
  6. #ifdef _WIN32
  7. #pragma once
  8. #endif
  9. #include "UtlVector.h"
  10. #define TREELIST_MSG_TOGGLE_STATE "TreeList_ToggleState"
  11. #define TREELIST_MSG_LEFT_DRAG_DROP "TreeList_LeftDragDrop"
  12. #define TREELIST_MSG_RIGHT_DRAG_DROP "TreeList_RightDragDrop"
  13. #define TREELIST_MSG_SEL_CHANGE "TreeList_SelChange"
  14. #define TREELIST_MSG_KEY_DOWN "TreeList_KeyDown"
  15. struct TreeListItemState_t
  16. {
  17. void *pItem;
  18. bool bExpanded;
  19. };
  20. class CTreeList : public CTreeCtrl
  21. {
  22. public:
  23. CTreeList();
  24. virtual ~CTreeList();
  25. void DeleteAllItems();
  26. void AddItem(void *pItem, void *pParent, const char *pszText, bool bHasCheckBox );
  27. inline bool SubclassDlgItem(int nCtrlID, CWnd *pwndParent);
  28. inline void SetRedraw(bool bRedraw);
  29. inline void Invalidate(bool bErase = true);
  30. void SelectItem(void *pItem);
  31. void EnsureVisible(void *pItem);
  32. void SelectNearestItem( int nItem );
  33. void EnsureVisible( int nItem );
  34. void ExpandAll();
  35. void EnableChecks();
  36. void UpdateItem(void *pItem, const char *pszText);
  37. void *GetSelectedItem();
  38. int GetSelectedIndex();
  39. int GetItemCount();
  40. void *GetItem(int nIndex);
  41. void SetCheck(void *pItem, int nCheckState);
  42. int GetCheck(void *pItem);
  43. void ExpandItem(void *pItem);
  44. void CollapseItem(void *pItem);
  45. void SaveTreeListExpandStates();
  46. void RestoreTreeListExpandStates();
  47. // Virtuals that can be overridden by the derived class
  48. virtual void OnRenameItem(void *pItem, const char *pszText) {}
  49. // ClassWizard generated virtual function overrides
  50. //{{AFX_VIRTUAL(CGroupList)
  51. //}}AFX_VIRTUAL
  52. protected:
  53. // Generated message map functions
  54. //{{AFX_MSG(CGroupList)
  55. afx_msg void OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult);
  56. afx_msg void OnEndLabelEdit(NMHDR* pNMHDR, LRESULT* pResult);
  57. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  58. afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  59. afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
  60. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  61. afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
  62. afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
  63. afx_msg void OnTimer(UINT nIDEvent);
  64. afx_msg void OnContextMenu(CWnd *, CPoint);
  65. afx_msg void OnSelChange(NMHDR *pNMHDR, LRESULT *pResult);
  66. afx_msg void OnKeyDown( NMHDR *pNMHDR, LRESULT *pResult );
  67. //}}AFX_MSG
  68. DECLARE_MESSAGE_MAP()
  69. private:
  70. enum DropType_t
  71. {
  72. DROP_LEFT = 0,
  73. DROP_RIGHT,
  74. };
  75. void ExpandRecursive(HTREEITEM hItem);
  76. int GetCheck(HTREEITEM hItem);
  77. HTREEITEM FindHTreeItem(void *pItem);
  78. HTREEITEM FindHTreeItemRecursive(HTREEITEM hItem, void *pItem);
  79. void BeginDrag(CPoint pt, HTREEITEM hItem);
  80. void Drop(DropType_t eDropType, UINT nFlags, CPoint point);
  81. bool m_bRButtonDown;
  82. CPoint m_ptRButtonDown;
  83. CPoint m_ptLDown;
  84. CImageList m_cNormalImageList;
  85. CImageList *m_pDragImageList;
  86. HTREEITEM m_hDragItem;
  87. CUtlVector<void *> m_Items;
  88. CUtlVector<TreeListItemState_t> m_ItemState;
  89. };
  90. //-----------------------------------------------------------------------------
  91. //-----------------------------------------------------------------------------
  92. void CTreeList::Invalidate(bool bErase)
  93. {
  94. CTreeCtrl::Invalidate(bErase ? TRUE : FALSE);
  95. }
  96. //-----------------------------------------------------------------------------
  97. // Enables or disables updates. Useful for populating the list and only
  98. // updating at the end.
  99. //-----------------------------------------------------------------------------
  100. void CTreeList::SetRedraw(bool bRedraw)
  101. {
  102. CTreeCtrl::SetRedraw(bRedraw ? TRUE : FALSE);
  103. }
  104. //-----------------------------------------------------------------------------
  105. //-----------------------------------------------------------------------------
  106. bool CTreeList::SubclassDlgItem(int nCtrlID, CWnd *pwndParent)
  107. {
  108. return (CTreeCtrl::SubclassDlgItem(nCtrlID, pwndParent) == TRUE);
  109. }
  110. #endif // TREELIST_H