IGUITable.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. // Copyright (C) 2003-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #ifndef __I_GUI_TABLE_H_INCLUDED__
  5. #define __I_GUI_TABLE_H_INCLUDED__
  6. #include "IGUIElement.h"
  7. #include "SColor.h"
  8. namespace irr
  9. {
  10. namespace gui
  11. {
  12. class IGUIFont;
  13. class IGUIScrollBar;
  14. //! modes for ordering used when a column header is clicked
  15. enum EGUI_COLUMN_ORDERING
  16. {
  17. //! Do not use ordering
  18. EGCO_NONE,
  19. //! Send a EGET_TABLE_HEADER_CHANGED message when a column header is clicked.
  20. EGCO_CUSTOM,
  21. //! Sort it ascending by it's ascii value like: a,b,c,...
  22. EGCO_ASCENDING,
  23. //! Sort it descending by it's ascii value like: z,x,y,...
  24. EGCO_DESCENDING,
  25. //! Sort it ascending on first click, descending on next, etc
  26. EGCO_FLIP_ASCENDING_DESCENDING,
  27. //! Not used as mode, only to get maximum value for this enum
  28. EGCO_COUNT
  29. };
  30. //! Names for EGUI_COLUMN_ORDERING types
  31. const c8* const GUIColumnOrderingNames[] =
  32. {
  33. "none",
  34. "custom",
  35. "ascend",
  36. "descend",
  37. "ascend_descend",
  38. 0,
  39. };
  40. enum EGUI_ORDERING_MODE
  41. {
  42. //! No element ordering
  43. EGOM_NONE,
  44. //! Elements are ordered from the smallest to the largest.
  45. EGOM_ASCENDING,
  46. //! Elements are ordered from the largest to the smallest.
  47. EGOM_DESCENDING,
  48. //! this value is not used, it only specifies the amount of default ordering types
  49. //! available.
  50. EGOM_COUNT
  51. };
  52. const c8* const GUIOrderingModeNames[] =
  53. {
  54. "none",
  55. "ascending",
  56. "descending",
  57. 0
  58. };
  59. enum EGUI_TABLE_DRAW_FLAGS
  60. {
  61. EGTDF_ROWS = 1,
  62. EGTDF_COLUMNS = 2,
  63. EGTDF_ACTIVE_ROW = 4,
  64. EGTDF_COUNT
  65. };
  66. //! Default list box GUI element.
  67. /** \par This element can create the following events of type EGUI_EVENT_TYPE:
  68. \li EGET_TABLE_CHANGED
  69. \li EGET_TABLE_SELECTED_AGAIN
  70. \li EGET_TABLE_HEADER_CHANGED
  71. */
  72. class IGUITable : public IGUIElement
  73. {
  74. public:
  75. //! constructor
  76. IGUITable(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle)
  77. : IGUIElement(EGUIET_TABLE, environment, parent, id, rectangle) {}
  78. //! Adds a column
  79. /** If columnIndex is outside the current range, do push new column at the end */
  80. virtual void addColumn(const wchar_t* caption, s32 columnIndex=-1) = 0;
  81. //! remove a column from the table
  82. virtual void removeColumn(u32 columnIndex) = 0;
  83. //! Returns the number of columns in the table control
  84. virtual s32 getColumnCount() const = 0;
  85. //! Makes a column active. This will trigger an ordering process.
  86. /** \param idx: The id of the column to make active or a negative number to make non active.
  87. \param doOrder: Do also the ordering which depending on mode for active column
  88. \return True when the column could be set active (aka - it did exist). */
  89. virtual bool setActiveColumn(s32 idx, bool doOrder=false) = 0;
  90. //! Returns which header is currently active
  91. virtual s32 getActiveColumn() const = 0;
  92. //! Returns the ordering used by the currently active column
  93. virtual EGUI_ORDERING_MODE getActiveColumnOrdering() const = 0;
  94. //! Set the width of a column
  95. virtual void setColumnWidth(u32 columnIndex, u32 width) = 0;
  96. //! Get the width of a column
  97. virtual u32 getColumnWidth(u32 columnIndex) const = 0;
  98. //! columns can be resized by drag 'n drop
  99. virtual void setResizableColumns(bool resizable) = 0;
  100. //! can columns be resized by drag 'n drop?
  101. virtual bool hasResizableColumns() const = 0;
  102. //! This tells the table control which ordering mode should be used when a column header is clicked.
  103. /** \param columnIndex The index of the column header.
  104. \param mode: One of the modes defined in EGUI_COLUMN_ORDERING */
  105. virtual void setColumnOrdering(u32 columnIndex, EGUI_COLUMN_ORDERING mode) = 0;
  106. //! Returns which row is currently selected
  107. virtual s32 getSelected() const = 0;
  108. //! set which row is currently selected
  109. virtual void setSelected( s32 index ) = 0;
  110. //! Get amount of rows in the tabcontrol
  111. virtual s32 getRowCount() const = 0;
  112. //! adds a row to the table
  113. /** \param rowIndex Zero based index of rows. The row will be
  114. inserted at this position, if a row already exist there, it
  115. will be placed after it. If the row is larger than the actual
  116. number of row by more than one, it won't be created. Note that
  117. if you create a row that's not at the end, there might be
  118. performance issues.
  119. \return index of inserted row. */
  120. virtual u32 addRow(u32 rowIndex) = 0;
  121. //! Remove a row from the table
  122. virtual void removeRow(u32 rowIndex) = 0;
  123. //! clears the table rows, but keeps the columns intact
  124. virtual void clearRows() = 0;
  125. //! Swap two row positions.
  126. virtual void swapRows(u32 rowIndexA, u32 rowIndexB) = 0;
  127. //! This tells the table to start ordering all the rows.
  128. /** You need to explicitly tell the table to re order the rows
  129. when a new row is added or the cells data is changed. This
  130. makes the system more flexible and doesn't make you pay the
  131. cost of ordering when adding a lot of rows.
  132. \param columnIndex: When set to -1 the active column is used.
  133. \param mode Ordering mode of the rows. */
  134. virtual void orderRows(s32 columnIndex=-1, EGUI_ORDERING_MODE mode=EGOM_NONE) = 0;
  135. //! Set the text of a cell
  136. virtual void setCellText(u32 rowIndex, u32 columnIndex, const core::stringw& text) = 0;
  137. //! Set the text of a cell, and set a color of this cell.
  138. virtual void setCellText(u32 rowIndex, u32 columnIndex, const core::stringw& text, video::SColor color) = 0;
  139. //! Set the data of a cell
  140. virtual void setCellData(u32 rowIndex, u32 columnIndex, void *data) = 0;
  141. //! Set the color of a cell text
  142. virtual void setCellColor(u32 rowIndex, u32 columnIndex, video::SColor color) = 0;
  143. //! Get the text of a cell
  144. virtual const wchar_t* getCellText(u32 rowIndex, u32 columnIndex ) const = 0;
  145. //! Get the data of a cell
  146. virtual void* getCellData(u32 rowIndex, u32 columnIndex ) const = 0;
  147. //! clears the table, deletes all items in the table
  148. virtual void clear() = 0;
  149. //! Set flags, as defined in ::EGUI_TABLE_DRAW_FLAGS, which influence the layout
  150. virtual void setDrawFlags(s32 flags) = 0;
  151. //! Get the flags, as defined in ::EGUI_TABLE_DRAW_FLAGS, which influence the layout
  152. virtual s32 getDrawFlags() const = 0;
  153. //! Sets another skin independent font.
  154. /** If this is set to zero, the button uses the font of the skin.
  155. \param font: New font to set. */
  156. virtual void setOverrideFont(IGUIFont* font=0) = 0;
  157. //! Gets the override font (if any)
  158. /** \return The override font (may be 0) */
  159. virtual IGUIFont* getOverrideFont(void) const = 0;
  160. //! Get the font which is used right now for drawing
  161. /** Currently this is the override font when one is set and the
  162. font of the active skin otherwise */
  163. virtual IGUIFont* getActiveFont() const = 0;
  164. //! Get the height of items/rows
  165. virtual s32 getItemHeight() const = 0;
  166. //! Access the vertical scrollbar
  167. virtual IGUIScrollBar* getVerticalScrollBar() const = 0;
  168. //! Access the horizontal scrollbar
  169. virtual IGUIScrollBar* getHorizontalScrollBar() const = 0;
  170. //! Sets whether to draw the background.
  171. virtual void setDrawBackground(bool draw) = 0;
  172. //! Checks if background drawing is enabled
  173. /** \return true if background drawing is enabled, false otherwise */
  174. virtual bool isDrawBackgroundEnabled() const = 0;
  175. };
  176. } // end namespace gui
  177. } // end namespace irr
  178. #endif