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.

173 lines
5.0 KiB

  1. //========= Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef COMBOBOX_H
  8. #define COMBOBOX_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <vgui_controls/TextEntry.h>
  13. #include <vgui_controls/Menu.h>
  14. #include <vgui_controls/Button.h>
  15. namespace vgui
  16. {
  17. //-----------------------------------------------------------------------------
  18. // Purpose: Scroll bar button
  19. //-----------------------------------------------------------------------------
  20. class ComboBoxButton : public vgui::Button
  21. {
  22. public:
  23. ComboBoxButton(ComboBox *parent, const char *panelName, const char *text);
  24. virtual void ApplySchemeSettings(IScheme *pScheme);
  25. virtual IBorder *GetBorder(bool depressed, bool armed, bool selected, bool keyfocus);
  26. virtual void OnCursorExited();
  27. virtual Color GetButtonBgColor()
  28. {
  29. if (IsEnabled())
  30. return Button::GetButtonBgColor();
  31. return m_DisabledBgColor;
  32. }
  33. private:
  34. Color m_DisabledBgColor;
  35. };
  36. //-----------------------------------------------------------------------------
  37. // Purpose: Text entry with drop down options list
  38. //-----------------------------------------------------------------------------
  39. class ComboBox : public TextEntry
  40. {
  41. DECLARE_CLASS_SIMPLE( ComboBox, TextEntry );
  42. public:
  43. ComboBox(Panel *parent, const char *panelName, int numLines, bool allowEdit);
  44. ~ComboBox();
  45. // functions designed to be overriden
  46. virtual void OnShowMenu(Menu *menu) {}
  47. virtual void OnHideMenu(Menu *menu) {}
  48. // Set the number of items in the drop down menu.
  49. virtual void SetNumberOfEditLines( int numLines );
  50. // Add an item to the drop down
  51. virtual int AddItem(const char *itemText, const KeyValues *userData);
  52. virtual int AddItem(const wchar_t *itemText, const KeyValues *userData);
  53. virtual int GetItemCount();
  54. int GetItemIDFromRow( int row );
  55. // update the item
  56. virtual bool UpdateItem(int itemID, const char *itemText,const KeyValues *userData);
  57. virtual bool UpdateItem(int itemID, const wchar_t *itemText, const KeyValues *userData);
  58. virtual bool IsItemIDValid(int itemID);
  59. // set the enabled state of an item
  60. virtual void SetItemEnabled(const char *itemText, bool state);
  61. virtual void SetItemEnabled(int itemID, bool state);
  62. // Removes a single item
  63. void DeleteItem( int itemID );
  64. // Remove all items from the drop down menu
  65. void RemoveAll();
  66. // deprecated, use above
  67. void DeleteAllItems() { RemoveAll(); }
  68. // Sorts the items in the list - FIXME does nothing
  69. virtual void SortItems();
  70. // Set the visiblity of the drop down menu button.
  71. virtual void SetDropdownButtonVisible(bool state);
  72. // Return true if the combobox current has the dropdown menu open
  73. virtual bool IsDropdownVisible();
  74. // Activate the item in the menu list,as if that
  75. // menu item had been selected by the user
  76. MESSAGE_FUNC_INT( ActivateItem, "ActivateItem", itemID );
  77. void ActivateItemByRow(int row);
  78. int GetActiveItem();
  79. KeyValues *GetActiveItemUserData();
  80. KeyValues *GetItemUserData(int itemID);
  81. void GetItemText( int itemID, OUT_Z_BYTECAP(bufLenInBytes) wchar_t *text, int bufLenInBytes );
  82. void GetItemText( int itemID, OUT_Z_BYTECAP(bufLenInBytes) char *text, int bufLenInBytes );
  83. // sets a custom menu to use for the dropdown
  84. virtual void SetMenu( Menu *menu );
  85. virtual Menu *GetMenu() { return m_pDropDown; }
  86. // Layout the format of the combo box for drawing on screen
  87. virtual void PerformLayout();
  88. /* action signals
  89. "TextChanged" - signals that the text has changed in the combo box
  90. */
  91. virtual void ShowMenu();
  92. virtual void HideMenu();
  93. virtual void OnKillFocus();
  94. MESSAGE_FUNC( OnMenuClose, "MenuClose" );
  95. virtual void DoClick();
  96. virtual void OnSizeChanged(int wide, int tall);
  97. virtual void SetOpenDirection(Menu::MenuDirection_e direction);
  98. virtual void SetFont( HFont font );
  99. virtual void SetUseFallbackFont( bool bState, HFont hFallback );
  100. ComboBoxButton *GetComboButton( void ) { return m_pButton; }
  101. protected:
  102. // overrides
  103. virtual void OnMousePressed(MouseCode code);
  104. virtual void OnMouseDoublePressed(MouseCode code);
  105. MESSAGE_FUNC( OnMenuItemSelected, "MenuItemSelected" );
  106. virtual void OnCommand( const char *command );
  107. virtual void ApplySchemeSettings(IScheme *pScheme);
  108. virtual void OnCursorEntered();
  109. virtual void OnCursorExited();
  110. // custom message handlers
  111. MESSAGE_FUNC_WCHARPTR( OnSetText, "SetText", text );
  112. virtual void OnSetFocus(); // called after the panel receives the keyboard focus
  113. #ifdef _GAMECONSOLE
  114. virtual void OnKeyCodePressed(KeyCode code);
  115. #endif
  116. virtual void OnKeyCodeTyped(KeyCode code);
  117. virtual void OnKeyTyped(wchar_t unichar);
  118. void SelectMenuItem(int itemToSelect);
  119. void MoveAlongMenuItemList(int direction);
  120. void MoveToFirstMenuItem();
  121. void MoveToLastMenuItem();
  122. private:
  123. void DoMenuLayout();
  124. Menu *m_pDropDown;
  125. ComboBoxButton *m_pButton;
  126. bool m_bHighlight;
  127. Menu::MenuDirection_e m_iDirection;
  128. int m_iOpenOffsetY;
  129. };
  130. } // namespace vgui
  131. #endif // COMBOBOX_H