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.

286 lines
10 KiB

  1. //========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef SECTIONEDLISTPANEL_H
  8. #define SECTIONEDLISTPANEL_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <utlvector.h>
  13. #include <utllinkedlist.h>
  14. #include <vgui/vgui.h>
  15. #include <vgui_controls/Panel.h>
  16. #include <vgui_controls/PHandle.h>
  17. namespace vgui
  18. {
  19. class CSectionHeader;
  20. class CItemButton;
  21. // sorting function, should return true if itemID1 should be displayed before itemID2
  22. typedef bool (*SectionSortFunc_t)(SectionedListPanel *list, int itemID1, int itemID2);
  23. //-----------------------------------------------------------------------------
  24. // Purpose: List panel control that is divided up into discrete sections
  25. //-----------------------------------------------------------------------------
  26. class SectionedListPanel : public Panel
  27. {
  28. DECLARE_CLASS_SIMPLE( SectionedListPanel, Panel );
  29. public:
  30. SectionedListPanel(vgui::Panel *parent, const char *name);
  31. ~SectionedListPanel();
  32. // adds a new section; returns false if section already exists
  33. virtual void AddSection(int sectionID, const char *name, SectionSortFunc_t sortFunc = NULL);
  34. virtual void AddSection(int sectionID, const wchar_t *name, SectionSortFunc_t sortFunc = NULL);
  35. // clears all the sections - leaves the items in place
  36. virtual void RemoveAllSections();
  37. // modifies section info
  38. virtual void SetSectionFgColor(int sectionID, Color color);
  39. virtual void SetSectionDividerColor( int sectionID, Color color);
  40. // forces a section to always be visible
  41. virtual void SetSectionAlwaysVisible(int sectionID, bool visible = true);
  42. // adds a new column to a section
  43. enum ColumnFlags_e
  44. {
  45. HEADER_IMAGE = 0x01, // set if the header for the column is an image instead of text
  46. COLUMN_IMAGE = 0x02, // set if the column contains an image instead of text (images are looked up by index from the ImageList) (see SetImageList below)
  47. COLUMN_BRIGHT = 0x04, // set if the column text should be the bright color
  48. COLUMN_CENTER = 0x08, // set to center the text/image in the column
  49. COLUMN_RIGHT = 0x10, // set to right-align the text in the column
  50. };
  51. virtual bool AddColumnToSection(int sectionID, const char *columnName, const char *columnText, int columnFlags, int width, HFont fallbackFont = INVALID_FONT );
  52. virtual bool AddColumnToSection(int sectionID, const char *columnName, const wchar_t *columnText, int columnFlags, int width, HFont fallbackFont = INVALID_FONT );
  53. // modifies the text in an existing column
  54. virtual bool ModifyColumn(int sectionID, const char *columnName, const wchar_t *columnText);
  55. // adds an item to the list; returns the itemID of the new item
  56. virtual int AddItem(int sectionID, const KeyValues *data);
  57. // modifies an existing item; returns false if the item does not exist
  58. virtual bool ModifyItem(int itemID, int sectionID, const KeyValues *data);
  59. // removes an item from the list; returns false if the item does not exist or is already removed
  60. virtual bool RemoveItem(int itemID);
  61. // clears the list
  62. virtual void RemoveAll() { DeleteAllItems(); }
  63. // DeleteAllItems() is deprecated, use RemoveAll();
  64. virtual void DeleteAllItems();
  65. // set the text color of an item
  66. virtual void SetItemFgColor(int itemID, Color color);
  67. //=============================================================================
  68. // HPE_BEGIN:
  69. // [menglish] Getters and setters for several item and section objects
  70. //=============================================================================
  71. virtual void SetItemBgColor( int itemID, Color color );
  72. virtual int GetColumnIndexByName(int sectionID, char* name);
  73. virtual int GetLineSpacing() { return m_iLineSpacing; }
  74. //=============================================================================
  75. // HPE_END
  76. //=============================================================================
  77. virtual void SetItemFont( int itemID, HFont font );
  78. /* MESSAGES SENT:
  79. "RowSelected"
  80. "itemID" - the selected item id, -1 if nothing selected
  81. // when an item has been clicked on
  82. "RowContextMenu" "itemID"
  83. "RowLeftClick" "itemID"
  84. "RowDoubleLeftClick" "itemID"
  85. */
  86. // returns the number of columns in a section
  87. virtual int GetColumnCountBySection(int sectionID);
  88. // returns the name of a column by section and column index; returns NULL if there are no more columns
  89. // valid range of columnIndex is [0, GetColumnCountBySection)
  90. virtual const char *GetColumnNameBySection(int sectionID, int columnIndex);
  91. virtual const wchar_t *GetColumnTextBySection(int sectionID, int columnIndex);
  92. virtual int GetColumnFlagsBySection(int sectionID, int columnIndex);
  93. virtual int GetColumnWidthBySection(int sectionID, int columnIndex);
  94. virtual HFont GetColumnFallbackFontBySection( int sectionID, int columnIndex );
  95. // returns the id of the currently selected item, -1 if nothing is selected
  96. virtual int GetSelectedItem();
  97. // sets which item is currently selected
  98. virtual void SetSelectedItem(int itemID);
  99. // remove selection
  100. virtual void ClearSelection( void );
  101. // returns the data of a selected item
  102. // InvalidateItem(itemID) needs to be called if the KeyValues are modified
  103. virtual KeyValues *GetItemData(int itemID);
  104. // returns what section an item is in
  105. virtual int GetItemSection(int itemID);
  106. // forces an item to redraw (use when keyvalues have been modified)
  107. virtual void InvalidateItem(int itemID);
  108. // returns true if the itemID is valid for use
  109. virtual bool IsItemIDValid(int itemID);
  110. virtual int GetHighestItemID();
  111. // returns the number of items (ignoring section dividers)
  112. virtual int GetItemCount();
  113. // returns the item ID from the row, again ignoring section dividers - valid from [0, GetItemCount )
  114. virtual int GetItemIDFromRow(int row);
  115. // returns the row that this itemID occupies. -1 if the itemID is invalid
  116. virtual int GetRowFromItemID(int itemID);
  117. // gets the local coordinates of a cell
  118. virtual bool GetCellBounds(int itemID, int column, int &x, int &y, int &wide, int &tall);
  119. //=============================================================================
  120. // HPE_BEGIN:
  121. // [menglish] Get the bounds of an item or column.
  122. //=============================================================================
  123. // gets the local coordinates of a cell using the max width for every column
  124. virtual bool GetMaxCellBounds(int itemID, int column, int &x, int &y, int &wide, int &tall);
  125. // gets the local coordinates of an item
  126. virtual bool GetItemBounds(int itemID, int &x, int &y, int &wide, int &tall);
  127. // [tj] Accessors for clickability
  128. void SetClickable(bool clickable) { m_clickable = clickable; }
  129. bool IsClickable() { return m_clickable; }
  130. // [tj] Accessors for header drawing
  131. void SetDrawHeaders(bool drawHeaders) { m_bDrawSectionHeaders = drawHeaders; }
  132. bool GetDrawHeaders() { return m_bDrawSectionHeaders; }
  133. //=============================================================================
  134. // HPE_END
  135. //=============================================================================
  136. // set up a field for editing
  137. virtual void EnterEditMode(int itemID, int column, vgui::Panel *editPanel);
  138. // leaves editing mode
  139. virtual void LeaveEditMode();
  140. // returns true if we are currently in inline editing mode
  141. virtual bool IsInEditMode();
  142. // sets whether or not the vertical scrollbar should ever be displayed
  143. virtual void SetVerticalScrollbar(bool state);
  144. // returns the size required to fully draw the contents of the panel
  145. virtual void GetContentSize(int &wide, int &tall);
  146. // image handling
  147. virtual void SetImageList(ImageList *imageList, bool deleteImageListWhenDone);
  148. virtual void ScrollToItem(int iItem);
  149. virtual void SetProportional(bool state);
  150. HFont GetHeaderFont( void ) const;
  151. void SetHeaderFont( HFont hFont );
  152. HFont GetRowFont( void ) const;
  153. void SetRowFont( HFont hFont );
  154. void MoveSelectionDown( void );
  155. void MoveSelectionUp( void );
  156. protected:
  157. virtual void PerformLayout();
  158. virtual void ApplySchemeSettings(IScheme *pScheme);
  159. virtual void ApplySettings(KeyValues *inResourceData);
  160. virtual void OnSizeChanged(int wide, int tall);
  161. virtual void OnMouseWheeled(int delta);
  162. virtual void OnMousePressed( MouseCode code);
  163. virtual void OnKeyCodeTyped( KeyCode code);
  164. virtual void OnSetFocus(); // called after the panel receives the keyboard focus
  165. public:
  166. virtual void SetFontSection(int sectionID, HFont font);
  167. private:
  168. MESSAGE_FUNC( OnSliderMoved, "ScrollBarSliderMoved" );
  169. void AddSectionHelper(int sectionID, CSectionHeader *header, SectionSortFunc_t sortFunc);
  170. int GetSectionTall();
  171. void LayoutPanels(int &contentTall);
  172. // Returns the index of a new item button, reusing an existing item button if possible
  173. int GetNewItemButton();
  174. friend class CItemButton;
  175. void SetSelectedItem(CItemButton *item);
  176. DHANDLE<CItemButton> m_hSelectedItem;
  177. struct column_t
  178. {
  179. char m_szColumnName[32];
  180. wchar_t m_szColumnText[64];
  181. int m_iColumnFlags;
  182. int m_iWidth;
  183. HFont m_hFallbackFont;
  184. };
  185. struct section_t
  186. {
  187. int m_iID;
  188. bool m_bAlwaysVisible;
  189. CSectionHeader *m_pHeader;
  190. CUtlVector<column_t> m_Columns;
  191. SectionSortFunc_t m_pSortFunc;
  192. };
  193. CUtlVector<section_t> m_Sections;
  194. CUtlLinkedList<CItemButton *, int> m_Items;
  195. CUtlLinkedList<CItemButton *, int> m_FreeItems;
  196. CUtlVector<CItemButton *> m_SortedItems;
  197. PHandle m_hEditModePanel;
  198. int m_iEditModeItemID;
  199. int m_iEditModeColumn;
  200. int m_iContentHeight;
  201. int m_iLineSpacing;
  202. int FindSectionIndexByID(int sectionID);
  203. void ReSortList();
  204. ScrollBar *m_pScrollBar;
  205. ImageList *m_pImageList;
  206. bool m_bDeleteImageListWhenDone;
  207. bool m_bSortNeeded;
  208. bool m_bVerticalScrollbarEnabled;
  209. //=============================================================================
  210. // HPE_BEGIN:
  211. //=============================================================================
  212. // [tj] Whether or not this list should respond to the mouse
  213. bool m_clickable;
  214. // [tj] Whether or not this list should draw the headers for the sections
  215. bool m_bDrawSectionHeaders;
  216. //=============================================================================
  217. // HPE_END
  218. //=============================================================================
  219. HFont m_hHeaderFont;
  220. HFont m_hRowFont;
  221. CPanelAnimationVar( bool, m_bShowColumns, "show_columns", "false" );
  222. };
  223. } // namespace vgui
  224. #endif // SECTIONEDLISTPANEL_H