libRocket
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ElementDataGridRow.h
Go to the documentation of this file.
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 
28 #ifndef ROCKETCONTROLSELEMENTDATAGRIDROW_H
29 #define ROCKETCONTROLSELEMENTDATAGRIDROW_H
30 
31 #include "Header.h"
32 #include "DataSourceListener.h"
33 #include "DataQuery.h"
34 #include "../Core/Element.h"
35 #include <queue>
36 
37 namespace Rocket {
38 namespace Controls {
39 
40 class ElementDataGrid;
41 
49 {
50 friend class ElementDataGrid;
51 
52 public:
54  virtual ~ElementDataGridRow();
55 
56  void Initialise(ElementDataGrid* parent_grid, ElementDataGridRow* parent_row = NULL, int child_index = -1, ElementDataGridRow* header_row = NULL, int depth = -1);
57  void SetChildIndex(int child_index);
58  int GetDepth();
59 
60  void SetDataSource(const Rocket::Core::String& data_source_name);
61 
64  bool UpdateChildren();
65 
67  int GetNumLoadedChildren();
68 
69  // Removes all the child cells and fetches them again from the data
70  // source.
71  void RefreshRows();
72 
74  bool IsRowExpanded();
76  void ExpandRow();
78  void CollapseRow();
80  void ToggleRow();
81 
83  int GetParentRelativeIndex();
85  int GetTableRelativeIndex();
87  ElementDataGridRow* GetParentRow();
89  ElementDataGrid* GetParentGrid();
90 
91 protected:
92  virtual void OnDataSourceDestroy(DataSource* data_source);
93  virtual void OnRowAdd(DataSource* data_source, const Rocket::Core::String& table, int first_row_added, int num_rows_added);
94  virtual void OnRowRemove(DataSource* data_source, const Rocket::Core::String& table, int first_row_removed, int num_rows_removed);
95  virtual void OnRowChange(DataSource* data_source, const Rocket::Core::String& table, int first_row_changed, int num_rows_changed);
96  virtual void OnRowChange(DataSource* data_source, const Rocket::Core::String& table);
97 
98 private:
99  typedef std::queue< ElementDataGridRow* > RowQueue;
100  typedef std::vector< ElementDataGridRow* > RowList;
101 
102  // Called when a row change (addition or removal) occurs in one of our
103  // children. Causes the table row index to be dirtied on all following
104  // children.
105  void ChildChanged(int child_index);
106  // Checks if any columns are dependent on the number of children
107  // present, and refreshes them from the data source if they are.
108  void RefreshChildDependentCells();
109 
110  // Forces the row to recalculate its relative table index the next time
111  // it is requested.
112  void DirtyTableRelativeIndex();
113  // Works out what the table relative index is for a given child.
114  int GetChildTableRelativeIndex(int child_index);
115 
116  // Adds children underneath this row, and fetches their contents (and
117  // possible children) from the row's data source. If first_row is left
118  // as the default -1, the rows are appended at the end of the list.
119  void AddChildren(int first_row_added = -1, int num_rows_added = 1);
120  // Removes this rows children, and their children, etc, from the table.
121  // If the num_rows_removed parameter is left as the -1 default, it'll
122  // default to the rest of the children after the first row.
123  void RemoveChildren(int first_row_removed = 0, int num_rows_removed = -1);
124  // Marks children as dirty and dispatches the event.
125  void ChangeChildren(int first_row_changed = 0, int num_rows_changed = -1);
126  // Returns the number of rows under this row (children, grandchildren, etc)
127  int GetNumDescendants();
128 
129  // Adds or refreshes the cell contents, and undirties the row's cells.
130  void Load(const Rocket::Controls::DataQuery& row_information);
131  // Finds all children that have cell information missing (either though being
132  // refreshed or not being loaded yet) and reloads them.
133  void LoadChildren(float time_slice);
134  // Loads a specific set of children. Called by the above function.
135  void LoadChildren(int first_row_to_load, int num_rows_to_load, Rocket::Core::Time time_slice);
136 
137  // If the cells need reloading, this takes care of it. If any children
138  // need updating, they are added to the queue.
139  void UpdateCellsAndChildren(RowQueue& dirty_rows);
140 
141  // Sets the dirty_cells flag on this row, and lets our ancestors know.
142  void DirtyCells();
143  // Sets the dirty children flag on this row and the row's ancestors.
144  void DirtyRow();
145  // This row has one or more cells that need loading.
146  bool dirty_cells;
147  // This row has one or more children that have either dirty flag set.
148  bool dirty_children;
149 
150  // Shows this row, and, if this was was expanded before it was hidden, its children as well.
151  void Show();
152  // Hides this row and all descendants.
153  void Hide();
154  bool row_expanded;
155 
156  int table_relative_index;
157  bool table_relative_index_dirty;
158 
159  ElementDataGrid* parent_grid;
160 
161  ElementDataGridRow* parent_row;
162  int child_index;
163  int depth;
164 
165  RowList children;
166 
167  // The data source and table that the children are fetched from.
168  DataSource* data_source;
169  Rocket::Core::String data_table;
170 };
171 
172 }
173 }
174 
175 #endif
#define NULL
Definition: Types.h:33
Definition: DataQuery.h:48
Definition: Clipboard.h:33
Definition: ElementDataGridRow.h:48
Definition: ElementDataGrid.h:47
ROCKETCONTROLS_API void Initialise()
Registers the instancers for the custom controls.
Definition: DataSource.h:46
#define ROCKETCONTROLS_API
Definition: Header.h:41
Definition: Element.h:71
double Time
Definition: Types.h:52
Definition: DataSourceListener.h:46