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.

231 lines
8.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef TREEVIEW_H
  8. #define TREEVIEW_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <utllinkedlist.h>
  13. #include <utlvector.h>
  14. #include <vgui/vgui.h>
  15. #include <vgui_controls/Panel.h>
  16. class KeyValues;
  17. namespace vgui
  18. {
  19. class ExpandButton;
  20. class TreeNode;
  21. class TreeViewSubPanel;
  22. // sorting function, should return true if node1 should be displayed before node2
  23. typedef bool (*TreeViewSortFunc_t)(KeyValues *node1, KeyValues *node2);
  24. class TreeView : public Panel
  25. {
  26. DECLARE_CLASS_SIMPLE( TreeView, Panel );
  27. public:
  28. TreeView(Panel *parent, const char *panelName);
  29. ~TreeView();
  30. void SetSortFunc(TreeViewSortFunc_t pSortFunc);
  31. virtual int AddItem(KeyValues *data, int parentItemIndex);
  32. virtual int GetRootItemIndex();
  33. virtual int GetNumChildren( int itemIndex );
  34. virtual int GetChild( int iParentItemIndex, int iChild ); // between 0 and GetNumChildren( iParentItemIndex ).
  35. virtual int GetItemCount(void);
  36. virtual KeyValues *GetItemData(int itemIndex) const;
  37. virtual void RemoveItem(int itemIndex, bool bPromoteChildren, bool bRecursivelyRemove = false );
  38. virtual void RemoveAll();
  39. virtual bool ModifyItem(int itemIndex, KeyValues *data);
  40. virtual int GetItemParent(int itemIndex) const;
  41. virtual void SetFont(HFont font);
  42. virtual void SetImageList(ImageList *imageList, bool deleteImageListWhenDone);
  43. void SetTreeIndent( int nIndentAmount );
  44. void SetAllowMultipleSelections( bool state );
  45. bool IsMultipleSelectionAllowed() const;
  46. virtual void ClearSelection();
  47. virtual void AddSelectedItem( int itemIndex, bool clearCurrentSelection, bool requestFocus = true, bool bMakeItemVisible = true );
  48. virtual void RemoveSelectedItem( int itemIndex );
  49. virtual void SelectAll();
  50. virtual bool IsItemSelected( int itemIndex ) const;
  51. virtual void RangeSelectItems( int clickedItem );
  52. virtual void FindNodesInRange( int startItem, int endItem, CUtlVector< int >& itemIndices );
  53. // returns the id of the currently selected item, -1 if nothing is selected
  54. virtual int GetSelectedItemCount() const;
  55. virtual int GetFirstSelectedItem() const;
  56. virtual int GetSelectedItem( int nSelectionIndex ) const;
  57. virtual void GetSelectedItems( CUtlVector< int >& list ) const;
  58. virtual void GetSelectedItemsForDrag( int nPrimaryDagItem, CUtlVector< int >& list );
  59. virtual void GetSelectedItemData( CUtlVector< KeyValues * >& list );
  60. // set colors for individual elments
  61. virtual void SetItemFgColor(int itemIndex, const Color& color);
  62. virtual void SetItemBgColor(int itemIndex, const Color& color);
  63. virtual void SetItemSelectionTextColor( int itemIndex, const Color& clr );
  64. virtual void SetItemSelectionBgColor( int itemIndex, const Color& clr );
  65. virtual void SetItemSelectionUnfocusedBgColor( int itemIndex, const Color& clr );
  66. // returns true if the itemID is valid for use
  67. virtual bool IsItemIDValid(int itemIndex);
  68. // item iterators
  69. // iterate from [0..GetHighestItemID()],
  70. // and check each with IsItemIDValid() before using
  71. virtual int GetHighestItemID();
  72. virtual void ExpandItem(int itemIndex, bool bExpand);
  73. virtual bool IsItemExpanded( int itemIndex );
  74. virtual void MakeItemVisible(int itemIndex);
  75. // This tells which of the visible items is the top one.
  76. virtual void GetVBarInfo( int &top, int &nItemsVisible, bool& hbarVisible );
  77. virtual HFont GetFont();
  78. virtual void GenerateDragDataForItem( int itemIndex, KeyValues *msg );
  79. virtual void SetDragEnabledItems( bool state );
  80. virtual void OnLabelChanged( int itemIndex, char const *oldString, char const *newString );
  81. virtual bool IsLabelEditingAllowed() const;
  82. virtual bool IsLabelBeingEdited() const;
  83. virtual void SetAllowLabelEditing( bool state );
  84. virtual bool CanCurrentlyEditLabel( int nItemIndex ) const;
  85. /* message sent
  86. "TreeViewItemSelected" int "itemIndex"
  87. called when the selected item changes
  88. "TreeViewItemDeselected" int "itemIndex"
  89. called when item is deselected
  90. */
  91. int GetRowHeight();
  92. int GetVisibleMaxWidth();
  93. virtual void OnMousePressed(MouseCode code);
  94. // By default, the tree view expands nodes on left-click. This enables/disables that feature
  95. void EnableExpandTreeOnLeftClick( bool bEnable );
  96. virtual void SetLabelEditingAllowed( int itemIndex, bool state );
  97. virtual void StartEditingLabel( int itemIndex );
  98. virtual bool IsItemDroppable( int itemIndex, bool bInsertBefore, CUtlVector< KeyValues * >& msglist );
  99. virtual void OnItemDropped( int itemIndex, bool bInsertBefore, CUtlVector< KeyValues * >& msglist );
  100. virtual bool GetItemDropContextMenu( int itemIndex, Menu *menu, CUtlVector< KeyValues * >& msglist );
  101. virtual HCursor GetItemDropCursor( int itemIndex, CUtlVector< KeyValues * >& msglist );
  102. virtual int GetPrevChildItemIndex( int itemIndex );
  103. virtual int GetNextChildItemIndex( int itemIndex );
  104. virtual void PerformLayout();
  105. // Makes the scrollbar parented to some other panel...
  106. ScrollBar *SetScrollBarExternal( bool vertical, Panel *newParent );
  107. void GetScrollBarSize( bool vertical, int& w, int& h );
  108. int FindItemUnderMouse( int mx, int my );
  109. // Returns false if item is not visible
  110. bool GetItemBounds( int itemIndex, int &x, int &y, int &w, int &h );
  111. bool IsItemBeingDisplayed( int itemIndex );
  112. // If set to false, all of the immediate children of the root node are displayed, but not the root
  113. void SetShowRootNode( bool bRootVisible );
  114. // Insert drop toggle and state, the insert drop location functionality provides drop
  115. // locations between nodes which can be used to perform an insertion at a specific location.
  116. void SetEnableInsertDropLocation( bool bEnable );
  117. bool AreInsertDropLocationsEnabled() const;
  118. // Use these until they return InvalidItemID to iterate all the items.
  119. virtual int FirstItem() const;
  120. virtual int NextItem( int iItem ) const;
  121. virtual int InvalidItemID() const;
  122. protected:
  123. // functions to override
  124. // called when a node, marked as "Expand", needs to generate it's child nodes when expanded
  125. virtual void GenerateChildrenOfNode(int itemIndex) {}
  126. // override to open a custom context menu on a node being selected and right-clicked
  127. virtual void GenerateContextMenu( int itemIndex, int x, int y ) {}
  128. // override to change selection behavior when right clicking to open a context menu
  129. virtual void OnContextMenuSelection( int itemIndex );
  130. // overrides
  131. virtual void OnMouseWheeled(int delta);
  132. virtual void OnSizeChanged(int wide, int tall);
  133. virtual void ApplySchemeSettings(IScheme *pScheme);
  134. MESSAGE_FUNC_INT( OnSliderMoved, "ScrollBarSliderMoved", position );
  135. virtual void SetBgColor( Color color );
  136. private:
  137. friend class TreeNode;
  138. friend class TreeNodeText;
  139. TreeNode* GetItem( int itemIndex );
  140. virtual void RemoveChildrenOfNode( int itemIndex );
  141. void SetLabelBeingEdited( bool state );
  142. // Clean up the image list
  143. void CleanUpImageList( );
  144. // to be accessed by TreeNodes
  145. IImage* GetImage(int index);
  146. // Add the specified list of items to the selection list.
  147. void AddSelectedItems( const CUtlVector< TreeNode * > &selectionList, bool clearCurrentSelection, bool requestFocus = true, bool bMakeItemVisible = true );
  148. // bools
  149. bool m_bAllowLabelEditing : 1;
  150. bool m_bDragEnabledItems : 1;
  151. bool m_bDeleteImageListWhenDone : 1;
  152. bool m_bLeftClickExpandsTree : 1;
  153. bool m_bLabelBeingEdited : 1;
  154. bool m_bAllowMultipleSelections : 1;
  155. bool m_bRootVisible : 1;
  156. bool m_bInsertDropLocations : 1;
  157. // cross reference - no hierarchy ordering in this list
  158. CUtlLinkedList<TreeNode *, int> m_NodeList;
  159. ScrollBar *m_pHorzScrollBar, *m_pVertScrollBar;
  160. int m_nRowHeight;
  161. int m_nTreeIndent;
  162. ImageList *m_pImageList;
  163. TreeNode *m_pRootNode;
  164. TreeViewSortFunc_t m_pSortFunc;
  165. HFont m_Font;
  166. CUtlVector< TreeNode * > m_SelectedItems;
  167. TreeViewSubPanel *m_pSubPanel;
  168. int m_nMostRecentlySelectedItem;
  169. bool m_bScrollbarExternal[ 2 ]; // 0 = vert, 1 = horz
  170. };
  171. }
  172. #endif // TREEVIEW_H