ElementDataGridRow.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #ifndef ROCKETCONTROLSELEMENTDATAGRIDROW_H
  28. #define ROCKETCONTROLSELEMENTDATAGRIDROW_H
  29. #include <Rocket/Controls/Header.h>
  30. #include <Rocket/Controls/DataSourceListener.h>
  31. #include <Rocket/Controls/DataQuery.h>
  32. #include <Rocket/Core/Element.h>
  33. #include <queue>
  34. namespace Rocket {
  35. namespace Controls {
  36. class ElementDataGrid;
  37. /**
  38. Class for rows inside a data table. Used for both the header and the individual rows.
  39. @author Robert Curry
  40. */
  41. class ROCKETCONTROLS_API ElementDataGridRow : public Core::Element, public DataSourceListener
  42. {
  43. friend class ElementDataGrid;
  44. public:
  45. ElementDataGridRow(const Rocket::Core::String& tag);
  46. virtual ~ElementDataGridRow();
  47. void Initialise(ElementDataGrid* parent_grid, ElementDataGridRow* parent_row = NULL, int child_index = -1, ElementDataGridRow* header_row = NULL, int depth = -1);
  48. void SetChildIndex(int child_index);
  49. int GetDepth();
  50. void SetDataSource(const Rocket::Core::String& data_source_name);
  51. /// Checks dirty children and cells, and loads them if necessary.
  52. /// @return True if any children were updated.
  53. bool UpdateChildren();
  54. /// Returns the number of children that aren't dirty (have been loaded)
  55. int GetNumLoadedChildren();
  56. // Removes all the child cells and fetches them again from the data
  57. // source.
  58. void RefreshRows();
  59. /// Returns whether this row is expanded or not.
  60. bool IsRowExpanded();
  61. /// Shows all of this row's descendants.
  62. void ExpandRow();
  63. /// Hides all of this row's descendants.
  64. void CollapseRow();
  65. /// Expands the row if collapsed, or collapses the row if expanded.
  66. void ToggleRow();
  67. /// Returns the index of this row, relative to its parent.
  68. int GetParentRelativeIndex();
  69. /// Returns the index of this row, relative to the table rather than its parent.
  70. int GetTableRelativeIndex();
  71. /// Returns the parent row of this row.
  72. ElementDataGridRow* GetParentRow();
  73. /// Returns the grid that this row belongs to.
  74. ElementDataGrid* GetParentGrid();
  75. protected:
  76. virtual void OnDataSourceDestroy(DataSource* data_source);
  77. virtual void OnRowAdd(DataSource* data_source, const Rocket::Core::String& table, int first_row_added, int num_rows_added);
  78. virtual void OnRowRemove(DataSource* data_source, const Rocket::Core::String& table, int first_row_removed, int num_rows_removed);
  79. virtual void OnRowChange(DataSource* data_source, const Rocket::Core::String& table, int first_row_changed, int num_rows_changed);
  80. virtual void OnRowChange(DataSource* data_source, const Rocket::Core::String& table);
  81. private:
  82. typedef std::queue< ElementDataGridRow* > RowQueue;
  83. typedef std::vector< ElementDataGridRow* > RowList;
  84. // Called when a row change (addition or removal) occurs in one of our
  85. // children. Causes the table row index to be dirtied on all following
  86. // children.
  87. void ChildChanged(int child_index);
  88. // Checks if any columns are dependent on the number of children
  89. // present, and refreshes them from the data source if they are.
  90. void RefreshChildDependentCells();
  91. // Forces the row to recalculate its relative table index the next time
  92. // it is requested.
  93. void DirtyTableRelativeIndex();
  94. // Works out what the table relative index is for a given child.
  95. int GetChildTableRelativeIndex(int child_index);
  96. // Adds children underneath this row, and fetches their contents (and
  97. // possible children) from the row's data source. If first_row is left
  98. // as the default -1, the rows are appended at the end of the list.
  99. void AddChildren(int first_row_added = -1, int num_rows_added = 1);
  100. // Removes this rows children, and their children, etc, from the table.
  101. // If the num_rows_removed parameter is left as the -1 default, it'll
  102. // default to the rest of the children after the first row.
  103. void RemoveChildren(int first_row_removed = 0, int num_rows_removed = -1);
  104. // Returns the number of rows under this row (children, grandchildren, etc)
  105. int GetNumDescendants();
  106. // Adds or refreshes the cell contents, and undirties the row's cells.
  107. void Load(const Rocket::Controls::DataQuery& row_information);
  108. // Finds all children that have cell information missing (either though being
  109. // refreshed or not being loaded yet) and reloads them.
  110. void LoadChildren(float time_slice);
  111. // Loads a specific set of children. Called by the above function.
  112. void LoadChildren(int first_row_to_load, int num_rows_to_load, Rocket::Core::Time time_slice);
  113. // If the cells need reloading, this takes care of it. If any children
  114. // need updating, they are added to the queue.
  115. void UpdateCellsAndChildren(RowQueue& dirty_rows);
  116. // Sets the dirty_cells flag on this row, and lets our ancestors know.
  117. void DirtyCells();
  118. // Sets the dirty children flag on this row and the row's ancestors.
  119. void DirtyRow();
  120. // This row has one or more cells that need loading.
  121. bool dirty_cells;
  122. // This row has one or more children that have either dirty flag set.
  123. bool dirty_children;
  124. // Shows this row, and, if this was was expanded before it was hidden, its children as well.
  125. void Show();
  126. // Hides this row and all descendants.
  127. void Hide();
  128. bool row_expanded;
  129. int table_relative_index;
  130. bool table_relative_index_dirty;
  131. ElementDataGrid* parent_grid;
  132. ElementDataGridRow* parent_row;
  133. int child_index;
  134. int depth;
  135. RowList children;
  136. // The data source and table that the children are fetched from.
  137. DataSource* data_source;
  138. Rocket::Core::String data_table;
  139. };
  140. }
  141. }
  142. #endif