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