Team Fortress 2 Source Code as on 22/4/2020
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.

165 lines
4.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef GROUPLIST_H
  7. #define GROUPLIST_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "utlvector.h"
  12. #define GROUPLIST_MSG_TOGGLE_STATE "GroupList_ToggleState"
  13. #define GROUPLIST_MSG_LEFT_DRAG_DROP "GroupList_LeftDragDrop"
  14. #define GROUPLIST_MSG_RIGHT_DRAG_DROP "GroupList_RightDragDrop"
  15. #define GROUPLIST_MSG_SEL_CHANGE "GroupList_SelChange"
  16. class CVisGroup;
  17. //
  18. // A structure that maps visgroups to HTREEITEMs so that callers don't have
  19. // to deal with the hierarchical data.
  20. //
  21. //struct VisGroupTreeItem_t
  22. //{
  23. // CVisGroup *pVisGroup;
  24. // HTREEITEM hItem;
  25. //};
  26. struct GroupListPair
  27. {
  28. CVisGroup *pVisGroup;
  29. bool bExpanded;
  30. };
  31. class CGroupList : public CTreeCtrl
  32. {
  33. public:
  34. CGroupList();
  35. virtual ~CGroupList();
  36. void DeleteAllItems();
  37. void AddVisGroup(CVisGroup *pVisGroup);
  38. inline bool SubclassDlgItem(int nCtrlID, CWnd *pwndParent);
  39. inline void SetRedraw(bool bRedraw);
  40. inline void Invalidate(bool bErase = true);
  41. void SelectVisGroup(CVisGroup *pVisGroup);
  42. void EnsureVisible(CVisGroup *pVisGroup);
  43. void ExpandAll(void);
  44. void EnableChecks(void);
  45. void UpdateVisGroup(CVisGroup *pVisGroup);
  46. CVisGroup *GetSelectedVisGroup();
  47. int GetVisGroupCount(void);
  48. CVisGroup *GetVisGroup(int nIndex);
  49. void SetCheck(CVisGroup *pVisGroup, int nCheckState);
  50. int GetCheck(CVisGroup *pVisGroup);
  51. int GetGroupPairCount(void);
  52. void SaveVisGroupExpandStates();
  53. void RestoreVisGroupExpandStates();
  54. // ClassWizard generated virtual function overrides
  55. //{{AFX_VIRTUAL(CGroupList)
  56. //}}AFX_VIRTUAL
  57. protected:
  58. // Generated message map functions
  59. //{{AFX_MSG(CGroupList)
  60. afx_msg void OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult);
  61. afx_msg void OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult);
  62. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  63. afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  64. afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
  65. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  66. afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
  67. afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
  68. afx_msg void OnTimer(UINT nIDEvent);
  69. afx_msg void OnContextMenu(CWnd *, CPoint);
  70. afx_msg void OnSelChange(NMHDR *pNMHDR, LRESULT *pResult);
  71. //}}AFX_MSG
  72. DECLARE_MESSAGE_MAP()
  73. private:
  74. enum DropType_t
  75. {
  76. DROP_LEFT = 0,
  77. DROP_RIGHT,
  78. };
  79. void ExpandRecursive(HTREEITEM hItem);
  80. void AddVisGroupRecursive(CVisGroup *pGroup, HTREEITEM hItemParent);
  81. HTREEITEM FindVisGroupItem(CVisGroup *pVisGroup);
  82. HTREEITEM FindVisGroupItemRecursive(HTREEITEM hItem, CVisGroup *pVisGroup);
  83. int GetCheck(HTREEITEM hItem);
  84. HTREEITEM TreeItemForVisGroup(CVisGroup *pVisGroup);
  85. void BeginDrag(CPoint pt, HTREEITEM hItem);
  86. void Drop(DropType_t eDropType, UINT nFlags, CPoint point);
  87. bool m_bRButtonDown;
  88. CPoint m_ptRButtonDown;
  89. CPoint m_ptLDown;
  90. CImageList m_cNormalImageList;
  91. CImageList *m_pDragImageList;
  92. HTREEITEM m_hDragItem;
  93. CUtlVector<CVisGroup *> m_VisGroups;
  94. CUtlVector<GroupListPair> m_GroupPairs;
  95. };
  96. //-----------------------------------------------------------------------------
  97. // Purpose:
  98. //-----------------------------------------------------------------------------
  99. void CGroupList::Invalidate(bool bErase)
  100. {
  101. CTreeCtrl::Invalidate(bErase ? TRUE : FALSE);
  102. }
  103. //-----------------------------------------------------------------------------
  104. // Purpose: Enables or disables updates. Useful for populating the groups list
  105. // and only updating at the end.
  106. //-----------------------------------------------------------------------------
  107. void CGroupList::SetRedraw(bool bRedraw)
  108. {
  109. CTreeCtrl::SetRedraw(bRedraw ? TRUE : FALSE);
  110. }
  111. //-----------------------------------------------------------------------------
  112. // Purpose:
  113. // Input : nCtrlID -
  114. // *pwndParent -
  115. // Output : Returns true on success, false on failure.
  116. //-----------------------------------------------------------------------------
  117. bool CGroupList::SubclassDlgItem(int nCtrlID, CWnd *pwndParent)
  118. {
  119. return (CTreeCtrl::SubclassDlgItem(nCtrlID, pwndParent) == TRUE);
  120. }
  121. #endif // GROUPLIST_H