forked from hitmen047/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComboBox.h
188 lines (145 loc) · 5.78 KB
/
ComboBox.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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef COMBOBOX_H
#define COMBOBOX_H
#ifdef _WIN32
#pragma once
#endif
#include <vgui_controls/TextEntry.h>
#include <vgui_controls/Menu.h>
#include <vgui_controls/Button.h>
namespace vgui
{
//-----------------------------------------------------------------------------
// Purpose: Scroll bar button
//-----------------------------------------------------------------------------
class ComboBoxButton : public vgui::Button
{
public:
ComboBoxButton(ComboBox *parent, const char *panelName, const char *text);
virtual ~ComboBoxButton() {}
virtual void ApplySchemeSettings(IScheme *pScheme);
virtual IBorder *GetBorder(bool depressed, bool armed, bool selected, bool keyfocus);
virtual void OnCursorExited();
virtual Color GetButtonBgColor()
{
if (IsEnabled())
return Button::GetButtonBgColor();
return m_DisabledBgColor;
}
private:
Color m_DisabledBgColor;
};
//-----------------------------------------------------------------------------
// Purpose: Text entry with drop down options list
//-----------------------------------------------------------------------------
class ComboBox : public TextEntry
{
DECLARE_CLASS_SIMPLE( ComboBox, TextEntry );
public:
ComboBox(Panel *parent, const char *panelName, int numLines, bool allowEdit);
~ComboBox();
// functions designed to be overriden
virtual void OnShowMenu(Menu *menu) {}
virtual void OnHideMenu(Menu *menu) {}
// Set the number of items in the drop down menu.
virtual void SetNumberOfEditLines( int numLines );
// Add an item to the drop down
virtual int AddItem(const char *itemText, const KeyValues *userData);
virtual int AddItem(const wchar_t *itemText, const KeyValues *userData);
virtual int GetItemCount() const;
int GetItemIDFromRow( int row );
// update the item
virtual bool UpdateItem(int itemID, const char *itemText,const KeyValues *userData);
virtual bool UpdateItem(int itemID, const wchar_t *itemText, const KeyValues *userData);
virtual bool IsItemIDValid(int itemID);
// set the enabled state of an item
virtual void SetItemEnabled(const char *itemText, bool state);
virtual void SetItemEnabled(int itemID, bool state);
// Removes a single item
void DeleteItem( int itemID );
// Remove all items from the drop down menu
void RemoveAll();
// deprecated, use above
void DeleteAllItems() { RemoveAll(); }
// Sorts the items in the list - FIXME does nothing
virtual void SortItems();
// Set the visiblity of the drop down menu button.
virtual void SetDropdownButtonVisible(bool state);
// Return true if the combobox current has the dropdown menu open
virtual bool IsDropdownVisible();
// Activate the item in the menu list,as if that
// menu item had been selected by the user
MESSAGE_FUNC_INT( ActivateItem, "ActivateItem", itemID );
void ActivateItemByRow(int row);
void SilentActivateItem(int itemID); // Sets the menu to the appropriate row without sending a TextChanged message
void SilentActivateItemByRow(int row); // Sets the menu to the appropriate row without sending a TextChanged message
int GetActiveItem();
KeyValues *GetActiveItemUserData();
KeyValues *GetItemUserData(int itemID);
void GetItemText( int itemID, OUT_Z_BYTECAP(bufLenInBytes) wchar_t *text, int bufLenInBytes );
void GetItemText( int itemID, OUT_Z_BYTECAP(bufLenInBytes) char *text, int bufLenInBytes );
// sets a custom menu to use for the dropdown
virtual void SetMenu( Menu *menu );
virtual Menu *GetMenu() { return m_pDropDown; }
// Layout the format of the combo box for drawing on screen
virtual void PerformLayout();
/* action signals
"TextChanged" - signals that the text has changed in the combo box
*/
virtual void ShowMenu();
virtual void HideMenu();
virtual void OnKillFocus();
MESSAGE_FUNC( OnMenuClose, "MenuClose" );
virtual void DoClick();
virtual void OnSizeChanged(int wide, int tall);
virtual void SetOpenDirection(Menu::MenuDirection_e direction);
virtual void SetFont( HFont font );
virtual void SetUseFallbackFont( bool bState, HFont hFallback );
ComboBoxButton *GetComboButton( void ) { return m_pButton; }
protected:
// overrides
virtual void OnMousePressed(MouseCode code);
virtual void OnMouseDoublePressed(MouseCode code);
MESSAGE_FUNC( OnMenuItemSelected, "MenuItemSelected" );
virtual void OnCommand( const char *command );
virtual void ApplySchemeSettings(IScheme *pScheme);
virtual void ApplySettings( KeyValues *pInResourceData );
virtual void OnCursorEntered();
virtual void OnCursorExited();
// custom message handlers
MESSAGE_FUNC_WCHARPTR( OnSetText, "SetText", text );
virtual void OnSetFocus(); // called after the panel receives the keyboard focus
#ifdef _X360
virtual void OnKeyCodePressed(KeyCode code);
#endif
virtual void OnKeyCodeTyped(KeyCode code);
virtual void OnKeyTyped(wchar_t unichar);
void SelectMenuItem(int itemToSelect);
void MoveAlongMenuItemList(int direction);
void MoveToFirstMenuItem();
void MoveToLastMenuItem();
private:
void DoMenuLayout();
Menu *m_pDropDown;
ComboBoxButton *m_pButton;
bool m_bPreventTextChangeMessage;
//=============================================================================
// HPE_BEGIN:
// [pfreese] This member variable is never initialized and not used correctly
//=============================================================================
// bool m_bAllowEdit;
//=============================================================================
// HPE_END
//=============================================================================
bool m_bHighlight;
Menu::MenuDirection_e m_iDirection;
int m_iOpenOffsetY;
char m_szBorderOverride[64];
};
} // namespace vgui
#endif // COMBOBOX_H