summaryrefslogtreecommitdiff
path: root/utils/itemtest_controls/dualpanellist.h
blob: a364a45d5779c3f8fc6448064224901cc8953a65 (plain) (blame)
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
//=============================================================================

#ifndef DUAL_PANEL_LIST_H
#define DUAL_PANEL_LIST_H

#if defined( _WIN32 )
#pragma once
#endif

#include <utllinkedlist.h>
#include <utlvector.h>
#include <vgui/VGUI.h>
#include <vgui_controls/Panel.h>

class KeyValues;

//-----------------------------------------------------------------------------
// Purpose: A list of variable height child panels
//  each list item consists of a label-panel pair. Height of the item is
// determined from the lable.
//-----------------------------------------------------------------------------
class CDualPanelList : public vgui::Panel
{
	DECLARE_CLASS_SIMPLE( CDualPanelList, vgui::Panel );

public:
	CDualPanelList( vgui::Panel *parent, char const *panelName );
	~CDualPanelList();

	// DATA & ROW HANDLING
	// The list now owns the panel
	virtual int AddItem( vgui::Panel *labelPanel, vgui::Panel *panel );
	int	GetItemCount() const;
	int GetItemIDFromRow( int nRow ) const;

	// Iteration. Use these until they return InvalidItemID to iterate all the items.
	int FirstItem() const;
	int NextItem( int nItemID ) const;
	int InvalidItemID() const;

	virtual Panel *GetItemLabel( int itemID ); 
	virtual Panel *GetItemPanel( int itemID ); 
	virtual bool IsItemVisible( int nItemID ) const;
	virtual void SetItemVisible( int nItemID, bool bVisible );

//	vgui::ScrollBar *GetScrollbar() { return m_pScrollBar; }

	virtual void RemoveItem( int itemID );		// removes an item from the table (changing the indices of all following items)
	virtual void DeleteAllItems();				// clears and deletes all the memory used by the data items
	void RemoveAll();

	// painting
	virtual vgui::Panel *GetCellRenderer( int row );

	// layout
	void SetFirstColumnWidth( int width );
	int GetFirstColumnWidth();
	void SetNumColumns( int iNumColumns );
	int GetNumColumns( void );
//	void MoveScrollBarToTop();

	// selection
	void SetSelectedPanel( vgui::Panel *panel );
	Panel *GetSelectedPanel();
	/*
		On a panel being selected, a message gets sent to it
			"PanelSelected"		int "state"
		where state is 1 on selection, 0 on deselection
	*/

	void		SetVerticalBufferPixels( int buffer );

	void		ScrollToItem( int itemNumber );

	CUtlVector< int > *GetSortedVector( void )
	{
		return &m_SortedItems;
	}

protected:
	// overrides
	virtual void OnSizeChanged(int wide, int tall);
	MESSAGE_FUNC_INT( OnSliderMoved, "ScrollBarSliderMoved", position );
	virtual void PerformLayout();
	virtual void ApplySchemeSettings(vgui::IScheme *pScheme);
	virtual void OnMouseWheeled(int delta);

private:
	int	ComputeVPixelsNeeded();

	enum { DEFAULT_HEIGHT = 24, PANELBUFFER = 5 };

	class CDataItem
	{
	public:
		CDataItem()
		: m_bVisible( true )
		{
		}

		void SetVisible( int bVisible )
		{
			m_bVisible = bVisible;

			if ( panel )
			{
				panel->SetVisible( m_bVisible );
			}

			if ( labelPanel )
			{
				labelPanel->SetVisible( m_bVisible );
			}
		}

		bool IsVisible() const { return m_bVisible; }

		// Always store a panel pointer
		vgui::Panel *panel;
		vgui::Panel *labelPanel;
		bool m_bVisible;
	};

	// list of the column headers

	CUtlLinkedList< CDataItem, int>		m_DataItems;
	CUtlVector<int>						m_SortedItems;

	vgui::ScrollBar				*m_pScrollBar;
	vgui::Panel					*m_pPanelEmbedded;

	vgui::PHandle					m_hSelectedItem;
	int						m_iFirstColumnWidth;
	int						m_nNumColumns;
	int						m_iDefaultHeight;
	int						m_iPanelBuffer;

//	CPanelAnimationVar( bool, m_bAutoHideScrollbar, "autohide_scrollbar", "0" );
};


#endif // DUAL_PANEL_LIST_H