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
44 * Structure for the layout data
50 Toolkit::TableView::CellPosition position;
54 * Create a new TableView.
55 * @return A smart-pointer to the newly allocated TableView.
57 static Toolkit::TableView New( unsigned int initialRows, unsigned int initialColumns );
60 * @copydoc Toolkit::TableView::AddChild
62 bool AddChild( Actor child, Toolkit::TableView::CellPosition position );
65 * @copydoc Toolkit::TableView::GetChildAt
67 Actor GetChildAt( Toolkit::TableView::CellPosition position );
70 * @copydoc Toolkit::TableView::RemoveChildAt
72 Actor RemoveChildAt( Toolkit::TableView::CellPosition position );
75 * @copydoc Toolkit::TableView::FindChildPosition
77 bool FindChildPosition( Actor child, Toolkit::TableView::CellPosition& position );
80 * @copydoc Toolkit::TableView::InsertRow
82 void InsertRow( unsigned int rowIndex );
85 * @copydoc Toolkit::TableView::DeleteRow( unsigned int rowIndex )
87 void DeleteRow( unsigned int rowIndex );
90 * @copydoc Toolkit::TableView::DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed )
92 void DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed );
95 * @copydoc Toolkit::TableView::InsertColumn
97 void InsertColumn( unsigned int columnIndex );
100 * @copydoc Toolkit::TableView::DeleteColumn( unsigned int columnIndex )
102 void DeleteColumn( unsigned int columnIndex );
105 * @copydoc Toolkit::TableView::DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed )
107 void DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed );
110 * @copydoc Toolkit::TableView::Resize( unsigned int rows, unsigned int columns )
112 void Resize( unsigned int rows, unsigned int columns );
115 * @copydoc Toolkit::TableView::Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed )
117 void Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed );
120 * @copydoc Toolkit::TableView::SetCellPadding
122 void SetCellPadding( Size padding );
125 * @copydoc Toolkit::TableView::GetCellPadding
127 Size GetCellPadding();
130 * @copydoc Toolkit::TableView::SetFixedHeight
132 void SetFixedHeight( unsigned int rowIndex, float height );
135 * @copydoc Toolkit::TableView::GetFixedHeight
137 float GetFixedHeight( unsigned int rowIndex ) const;
140 * @copydoc Toolkit::TableView::SetRelativeHeight
142 void SetRelativeHeight( unsigned int rowIndex, float heightPercentage );
145 * @copydoc Toolkit::TableView::GetRelativeHeight
147 float GetRelativeHeight( unsigned int rowIndex ) const;
150 * @copydoc Toolkit::TableView::SetFixedWidth
152 void SetFixedWidth( unsigned int columnIndex, float width );
155 * @copydoc Toolkit::TableView::GetFixedWidth
157 float GetFixedWidth( unsigned int columnIndex ) const;
160 * @copydoc Toolkit::TableView::SetRelativeWidth
162 void SetRelativeWidth( unsigned int columnIndex, float widthPercentage );
165 * @copydoc Toolkit::TableView::GetRelativeWidth
167 float GetRelativeWidth( unsigned int columnIndex ) const;
170 * @copydoc Toolkit::TableView::GetRows
172 unsigned int GetRows();
175 * @copydoc Toolkit::TableView::GetColumns
177 unsigned int GetColumns();
182 * Called when a property of an object of this type is set.
183 * @param[in] object The object whose property is set.
184 * @param[in] index The property index.
185 * @param[in] value The new property value.
187 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
190 * Called to retrieve a property of an object of this type.
191 * @param[in] object The object whose property is to be retrieved.
192 * @param[in] index The property index.
193 * @return The current value of the property.
195 static Property::Value GetProperty( BaseObject* object, Property::Index index );
197 private: // From Control
200 * @copydoc Control::OnControlChildAdd(Actor& child)
202 virtual void OnControlChildAdd(Actor& child);
205 * @copydoc Control::OnControlChildRemove(Actor& child)
207 virtual void OnControlChildRemove(Actor& child);
210 * @copydoc Control::OnRelayout
212 virtual void OnRelayout( const Vector2& size, ActorSizeContainer& container );
215 * @copydoc Control::OnInitialize()
217 virtual void OnInitialize();
220 * @copydoc Control::GetNextKeyboardFocusableActor
222 virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
224 private: // Implementation
227 * Construct a new TableView.
229 TableView( unsigned int initialRows, unsigned int initialColumns );
232 * Resizes the data containers to match the new size
233 * @param [in] rows in the table
234 * @param [in] columns in the table
236 void ResizeContainers( unsigned int rows, unsigned int columns );
239 * Resizes the data containers to match the new size
240 * @param [in] rows in the table
241 * @param [in] columns in the table
242 * @param [out] removed celldata
244 void ResizeContainers( unsigned int rows, unsigned int columns, std::vector<CellData>& removed );
247 * Helper to get the list of lost actors in the case when table looses cells.
248 * Also handles the case when actors span multiple cells
250 * @param removed actors
251 * @param rowsRemoved from table
252 * @param columnsRemoved from table
254 void RemoveAndGetLostActors( const std::vector<CellData>& lost, std::vector<Actor>& removed,
255 unsigned int rowsRemoved, unsigned int columnsRemoved );
258 * Helper to remove all instances of the actor
259 * @param child actor to remove
260 * @return true if the actor was found
262 bool RemoveAllInstances( Actor child );
265 * Helper to update relative sizes
266 * @param fixedHeightsTotal sum of the fixed height rows
267 * @param fixedWidthsTotal sum of the fixed width columns
269 void UpdateRelativeSizes( float& fixedHeightsTotal, float& fixedWidthsTotal );
272 * A reference counted object may only be deleted by calling Unreference()
274 virtual ~TableView();
276 private: // scripting support
279 * Called to set the heights/widths property.
280 * @param[in] tableViewImpl The object whose property is set.
281 * @param[in] funcFixed The set function to call, it can be SetFixedHeight or SetFixedWidths.
282 * @param[in] funcRelative The set function to call, it can be SetRelativeHeight or SetRelativeWidths.
283 * @param[in] value The new property value.
285 static void SetHeightOrWidthProperty( TableView& tableViewImpl,
286 void(TableView::*funcFixed)(unsigned int, float),
287 void(TableView::*funcRelative)(unsigned int, float),
288 const Property::Value& map );
291 * Called to retrieve the property value of row heights.
292 * @return The property value of row heights.
294 Property::Value GetRowHeightsPropertyValue();
297 * Called to retrieve the property value of column widths.
298 * @return The fixed-widths property value.
300 Property::Value GetColumnWidthsPropertyValue();
303 * Generate the map type property value from the size vectors.
304 * @param[in] fixedSize The vector of fixed heights or widths.
305 * @param[in] relativeSize The vector of relative heights or widths.
306 * @param[out] map The property value.
308 void GetMapPropertyValue( const std::vector<float>& fixedSize, const std::vector<float>& relativeSize, Property::Map& map );
312 * Helper class to prevent child adds and removes from causing relayout
313 * when we're already anyways going to do one in the end
315 class RelayoutingLock
320 * Constructor, sets the lock boolean
322 RelayoutingLock( TableView& parent )
323 : mLock( parent.mLayoutingChild )
329 * Destructor, releases lock boolean
334 // Note, we could also call Relayout here. This would save one line of code
335 // from each method that uses this lock but destructors are not meant to do
336 // big processing so better to not do it here. This destructor would also
337 // be called in case of an exception and we don't definitely want to do Relayout
347 // Undefined copy constructor and assignment operators
348 TableView(const TableView&);
349 TableView& operator=(const TableView& rhs);
353 Array2d<CellData> mCellData;
354 Array2d<Size> mRelativeSizes;
355 std::vector<float> mFixedHeights;
356 std::vector<float> mRelativeHeights;
357 std::vector<float> mFixedWidths;
358 std::vector<float> mRelativeWidths;
360 bool mLayoutingChild;
364 } // namespace Internal
366 // Helpers for public-api forwarding methods
368 inline Toolkit::Internal::TableView& GetImpl( Toolkit::TableView& tableView )
370 DALI_ASSERT_ALWAYS(tableView);
372 Dali::RefObject& handle = tableView.GetImplementation();
374 return static_cast<Toolkit::Internal::TableView&>(handle);
377 inline const Toolkit::Internal::TableView& GetImpl( const Toolkit::TableView& tableView )
379 DALI_ASSERT_ALWAYS(tableView);
381 const Dali::RefObject& handle = tableView.GetImplementation();
383 return static_cast<const Toolkit::Internal::TableView&>(handle);
386 } // namespace Toolkit
390 #endif // __DALI_TOOLKIT_INTERNAL_TABLE_VIEW_H__