1 #ifndef __DALI_TOOLKIT_INTERNAL_TABLE_VIEW_H__
2 #define __DALI_TOOLKIT_INTERNAL_TABLE_VIEW_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali-toolkit/public-api/controls/control-impl.h>
23 #include <dali-toolkit/public-api/controls/table-view/table-view.h>
36 * TableView is a custom control for laying out actors in a table layout
37 * @see Dali::Toolkit:TableView for more details
39 class TableView : public Control
46 TABLEVIEW_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
47 TABLEVIEW_PROPERTY_END_INDEX = TABLEVIEW_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
51 * Structure for the layout data
57 Toolkit::TableView::CellPosition position;
61 * Create a new TableView.
62 * @return A smart-pointer to the newly allocated TableView.
64 static Toolkit::TableView New( unsigned int initialRows, unsigned int initialColumns );
67 * @copydoc Toolkit::TableView::AddChild
69 bool AddChild( Actor child, Toolkit::TableView::CellPosition position );
72 * @copydoc Toolkit::TableView::GetChildAt
74 Actor GetChildAt( Toolkit::TableView::CellPosition position );
77 * @copydoc Toolkit::TableView::RemoveChildAt
79 Actor RemoveChildAt( Toolkit::TableView::CellPosition position );
82 * @copydoc Toolkit::TableView::FindChildPosition
84 bool FindChildPosition( Actor child, Toolkit::TableView::CellPosition& position );
87 * @copydoc Toolkit::TableView::InsertRow
89 void InsertRow( unsigned int rowIndex );
92 * @copydoc Toolkit::TableView::DeleteRow( unsigned int rowIndex )
94 void DeleteRow( unsigned int rowIndex );
97 * @copydoc Toolkit::TableView::DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed )
99 void DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed );
102 * @copydoc Toolkit::TableView::InsertColumn
104 void InsertColumn( unsigned int columnIndex );
107 * @copydoc Toolkit::TableView::DeleteColumn( unsigned int columnIndex )
109 void DeleteColumn( unsigned int columnIndex );
112 * @copydoc Toolkit::TableView::DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed )
114 void DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed );
117 * @copydoc Toolkit::TableView::Resize( unsigned int rows, unsigned int columns )
119 void Resize( unsigned int rows, unsigned int columns );
122 * @copydoc Toolkit::TableView::Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed )
124 void Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed );
127 * @copydoc Toolkit::TableView::SetCellPadding
129 void SetCellPadding( Size padding );
132 * @copydoc Toolkit::TableView::GetCellPadding
134 Size GetCellPadding();
137 * @copydoc Toolkit::TableView::SetFixedHeight
139 void SetFixedHeight( unsigned int rowIndex, float height );
142 * @copydoc Toolkit::TableView::GetFixedHeight
144 float GetFixedHeight( unsigned int rowIndex ) const;
147 * @copydoc Toolkit::TableView::SetRelativeHeight
149 void SetRelativeHeight( unsigned int rowIndex, float heightPercentage );
152 * @copydoc Toolkit::TableView::GetRelativeHeight
154 float GetRelativeHeight( unsigned int rowIndex ) const;
157 * @copydoc Toolkit::TableView::SetFixedWidth
159 void SetFixedWidth( unsigned int columnIndex, float width );
162 * @copydoc Toolkit::TableView::GetFixedWidth
164 float GetFixedWidth( unsigned int columnIndex ) const;
167 * @copydoc Toolkit::TableView::SetRelativeWidth
169 void SetRelativeWidth( unsigned int columnIndex, float widthPercentage );
172 * @copydoc Toolkit::TableView::GetRelativeWidth
174 float GetRelativeWidth( unsigned int columnIndex ) const;
177 * @copydoc Toolkit::TableView::GetRows
179 unsigned int GetRows();
182 * @copydoc Toolkit::TableView::GetColumns
184 unsigned int GetColumns();
189 * Called when a property of an object of this type is set.
190 * @param[in] object The object whose property is set.
191 * @param[in] index The property index.
192 * @param[in] value The new property value.
194 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
197 * Called to retrieve a property of an object of this type.
198 * @param[in] object The object whose property is to be retrieved.
199 * @param[in] index The property index.
200 * @return The current value of the property.
202 static Property::Value GetProperty( BaseObject* object, Property::Index index );
204 private: // From Control
207 * @copydoc Control::OnControlChildAdd(Actor& child)
209 virtual void OnControlChildAdd(Actor& child);
212 * @copydoc Control::OnControlChildRemove(Actor& child)
214 virtual void OnControlChildRemove(Actor& child);
217 * @copydoc Control::OnRelayout
219 virtual void OnRelayout( const Vector2& size, ActorSizeContainer& container );
222 * @copydoc Control::OnInitialize()
224 virtual void OnInitialize();
227 * @copydoc Control::GetNextKeyboardFocusableActor
229 virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
231 private: // Implementation
234 * Construct a new TableView.
236 TableView( unsigned int initialRows, unsigned int initialColumns );
239 * Resizes the data containers to match the new size
240 * @param [in] rows in the table
241 * @param [in] columns in the table
243 void ResizeContainers( unsigned int rows, unsigned int columns );
246 * Resizes the data containers to match the new size
247 * @param [in] rows in the table
248 * @param [in] columns in the table
249 * @param [out] removed celldata
251 void ResizeContainers( unsigned int rows, unsigned int columns, std::vector<CellData>& removed );
254 * Helper to get the list of lost actors in the case when table looses cells.
255 * Also handles the case when actors span multiple cells
257 * @param removed actors
258 * @param rowsRemoved from table
259 * @param columnsRemoved from table
261 void RemoveAndGetLostActors( const std::vector<CellData>& lost, std::vector<Actor>& removed,
262 unsigned int rowsRemoved, unsigned int columnsRemoved );
265 * Helper to remove all instances of the actor
266 * @param child actor to remove
267 * @return true if the actor was found
269 bool RemoveAllInstances( Actor child );
272 * Helper to update relative sizes
273 * @param fixedHeightsTotal sum of the fixed height rows
274 * @param fixedWidthsTotal sum of the fixed width columns
276 void UpdateRelativeSizes( float& fixedHeightsTotal, float& fixedWidthsTotal );
279 * A reference counted object may only be deleted by calling Unreference()
281 virtual ~TableView();
283 private: // scripting support
286 * Called to set the heights/widths property.
287 * @param[in] tableViewImpl The object whose property is set.
288 * @param[in] funcFixed The set function to call, it can be SetFixedHeight or SetFixedWidths.
289 * @param[in] funcRelative The set function to call, it can be SetRelativeHeight or SetRelativeWidths.
290 * @param[in] value The new property value.
292 static void SetHeightOrWidthProperty( TableView& tableViewImpl,
293 void(TableView::*funcFixed)(unsigned int, float),
294 void(TableView::*funcRelative)(unsigned int, float),
295 const Property::Value& map );
298 * Called to retrieve the property value of row heights.
299 * @return The property value of row heights.
301 Property::Value GetRowHeightsPropertyValue();
304 * Called to retrieve the property value of column widths.
305 * @return The fixed-widths property value.
307 Property::Value GetColumnWidthsPropertyValue();
310 * Generate the map type property value from the size vectors.
311 * @param[in] fixedSize The vector of fixed heights or widths.
312 * @param[in] relativeSize The vector of relative heights or widths.
313 * @param[out] map The property value.
315 void GetMapPropertyValue( const std::vector<float>& fixedSize, const std::vector<float>& relativeSize, Property::Map& map );
319 * Helper class to prevent child adds and removes from causing relayout
320 * when we're already anyways going to do one in the end
322 class RelayoutingLock
327 * Constructor, sets the lock boolean
329 RelayoutingLock( TableView& parent )
330 : mLock( parent.mLayoutingChild )
336 * Destructor, releases lock boolean
341 // Note, we could also call Relayout here. This would save one line of code
342 // from each method that uses this lock but destructors are not meant to do
343 // big processing so better to not do it here. This destructor would also
344 // be called in case of an exception and we don't definitely want to do Relayout
354 // Undefined copy constructor and assignment operators
355 TableView(const TableView&);
356 TableView& operator=(const TableView& rhs);
360 Array2d<CellData> mCellData;
361 Array2d<Size> mRelativeSizes;
362 std::vector<float> mFixedHeights;
363 std::vector<float> mRelativeHeights;
364 std::vector<float> mFixedWidths;
365 std::vector<float> mRelativeWidths;
367 bool mLayoutingChild;
371 } // namespace Internal
373 // Helpers for public-api forwarding methods
375 inline Toolkit::Internal::TableView& GetImpl( Toolkit::TableView& tableView )
377 DALI_ASSERT_ALWAYS(tableView);
379 Dali::RefObject& handle = tableView.GetImplementation();
381 return static_cast<Toolkit::Internal::TableView&>(handle);
384 inline const Toolkit::Internal::TableView& GetImpl( const Toolkit::TableView& tableView )
386 DALI_ASSERT_ALWAYS(tableView);
388 const Dali::RefObject& handle = tableView.GetImplementation();
390 return static_cast<const Toolkit::Internal::TableView&>(handle);
393 } // namespace Toolkit
397 #endif // __DALI_TOOLKIT_INTERNAL_TABLE_VIEW_H__