Update keyboard focus direction enum for Control
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / table-view / table-view-impl.h
index 9939a05..d1d8aef 100644 (file)
@@ -40,21 +40,14 @@ class TableView : public Control
 {
 public:
 
-  // Properties
-  enum
-  {
-    TABLEVIEW_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
-    TABLEVIEW_PROPERTY_END_INDEX = TABLEVIEW_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
-  };
-
   /**
-   * Structure for the layout data
+   * Enum for the size policies of rows and columns
    */
-  struct CellData
+  enum CellSizePolicy
   {
-    // data members
-    Actor actor;
-    Toolkit::TableView::CellPosition position;
+    FILL,       ///< Fill up available space, may have a ratio associated with it
+    FIXED,      ///< A specific fixed width or height
+    FIT         ///< Fit around actors in the row or column
   };
 
   /**
@@ -66,22 +59,22 @@ public:
   /**
    * @copydoc Toolkit::TableView::AddChild
    */
-  bool AddChild( Actor child, Toolkit::TableView::CellPosition position );
+  bool AddChild( Actor& child, const Toolkit::TableView::CellPosition& position );
 
   /**
    * @copydoc Toolkit::TableView::GetChildAt
    */
-  Actor GetChildAt( Toolkit::TableView::CellPosition position );
+  Actor GetChildAt( const Toolkit::TableView::CellPosition& position );
 
   /**
    * @copydoc Toolkit::TableView::RemoveChildAt
    */
-  Actor RemoveChildAt( Toolkit::TableView::CellPosition position );
+  Actor RemoveChildAt( const Toolkit::TableView::CellPosition& position );
 
   /**
    * @copydoc Toolkit::TableView::FindChildPosition
    */
-  bool FindChildPosition( Actor child, Toolkit::TableView::CellPosition& position );
+  bool FindChildPosition( const Actor& child, Toolkit::TableView::CellPosition& positionOut );
 
   /**
    * @copydoc Toolkit::TableView::InsertRow
@@ -134,24 +127,36 @@ public:
   Size GetCellPadding();
 
   /**
-   * @copydoc Toolkit::TableView::SetFixedHeight
+   * @brief Set a row policy
+   *
+   * @param[in] rowIndex The row to set the policy for
+   * @param[in] policy The policy to set
    */
-  void SetFixedHeight( unsigned int rowIndex, float height );
+  void SetRowPolicy( unsigned int rowIndex, CellSizePolicy policy );
 
   /**
-   * @copydoc Toolkit::TableView::GetFixedHeight
+   * @brief Querry a row policy
+   *
+   * @param[in] rowIndex The row to querry
+   * @return Return the policy
    */
-  float GetFixedHeight( unsigned int rowIndex ) const;
+  CellSizePolicy GetRowPolicy( unsigned int rowIndex ) const;
 
   /**
-   * @copydoc Toolkit::TableView::SetRelativeHeight
+   * @brief Set a column policy
+   *
+   * @param[in] columnIndex The column to set the policy for
+   * @param[in] policy The policy to set
    */
-  void SetRelativeHeight( unsigned int rowIndex, float heightPercentage );
+  void SetColumnPolicy( unsigned int columnIndex, CellSizePolicy policy );
 
   /**
-   * @copydoc Toolkit::TableView::GetRelativeHeight
+   * @brief Querry a column policy
+   *
+   * @param[in] columnIndex The column to querry
+   * @return Return the policy
    */
-  float GetRelativeHeight( unsigned int rowIndex ) const;
+  CellSizePolicy GetColumnPolicy( unsigned int columnIndex ) const;
 
   /**
    * @copydoc Toolkit::TableView::SetFixedWidth
@@ -164,6 +169,26 @@ public:
   float GetFixedWidth( unsigned int columnIndex ) const;
 
   /**
+   * @copydoc Toolkit::TableView::SetFixedHeight
+   */
+  void SetFixedHeight( unsigned int rowIndex, float height );
+
+  /**
+   * @copydoc Toolkit::TableView::GetFixedHeight
+   */
+  float GetFixedHeight( unsigned int rowIndex ) const;
+
+  /**
+   * @copydoc Toolkit::TableView::SetRelativeHeight
+   */
+  void SetRelativeHeight( unsigned int rowIndex, float heightPercentage );
+
+  /**
+   * @copydoc Toolkit::TableView::GetRelativeHeight
+   */
+  float GetRelativeHeight( unsigned int rowIndex ) const;
+
+  /**
    * @copydoc Toolkit::TableView::SetRelativeWidth
    */
   void SetRelativeWidth( unsigned int columnIndex, float widthPercentage );
@@ -183,6 +208,11 @@ public:
    */
   unsigned int GetColumns();
 
+  /**
+   * @copydoc Toolkit::TableView::SetCellAlignment
+   */
+  void SetCellAlignment( Toolkit::TableView::CellPosition position, HorizontalAlignment::Type horizontal, VerticalAlignment::Type vertical );
+
   // Properties
 
   /**
@@ -206,17 +236,22 @@ private: // From Control
   /**
    * @copydoc Control::OnControlChildAdd(Actor& child)
    */
-  virtual void OnControlChildAdd(Actor& child);
+  virtual void OnControlChildAdd( Actor& child );
 
   /**
    * @copydoc Control::OnControlChildRemove(Actor& child)
    */
-  virtual void OnControlChildRemove(Actor& child);
+  virtual void OnControlChildRemove( Actor& child );
 
   /**
    * @copydoc Control::OnRelayout
    */
-  virtual void OnRelayout( const Vector2& size, ActorSizeContainer& container );
+  virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
+
+  /**
+   * @copydoc Control::CalculateChildSize
+   */
+  virtual float CalculateChildSize( const Actor& child, Dimension::Type dimension );
 
   /**
    * @copydoc Control::OnInitialize()
@@ -226,11 +261,94 @@ private: // From Control
   /**
    * @copydoc Control::GetNextKeyboardFocusableActor
    */
-  virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
+  virtual Actor GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled );
+
+  /**
+   * @copydoc Control::GetNaturalSize()
+   */
+  virtual Vector3 GetNaturalSize();
+
+  /**
+   * @copydoc Control::RelayoutDependentOnChildren()
+   */
+  virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
+
+  /**
+   * @copydoc Control::OnCalculateRelayoutSize
+   */
+  virtual void OnCalculateRelayoutSize( Dimension::Type dimension );
+
+  /**
+   * @copydoc Control::OnLayoutNegotiated
+   */
+  virtual void OnLayoutNegotiated( float size, Dimension::Type dimension );
 
 private: // Implementation
 
   /**
+   * Struct to hold data for rows and columns
+   *
+   * If sizePolicy is FIXED then size is the absolute size to use.
+   * If sizePolicy is FIT or FILL then size is the calculated value of size.
+   */
+  struct RowColumnData
+  {
+    /**
+     * Default constructor
+     */
+    RowColumnData()
+    : size( 0.0f ),
+      fillRatio( 0.0f ),
+      sizePolicy( FILL ),
+      userFillRatio( false )
+    {
+    }
+
+    /**
+     * Constructor
+     *
+     * @param[in] newSize The size to set for this data
+     * @param[in] newSizePolicy The policy used to interpret the size value
+     */
+    RowColumnData( float newSize, float newFillRatio, CellSizePolicy newSizePolicy, bool newUserFillRatio )
+    : size( newSize ),
+      fillRatio( newFillRatio ),
+      sizePolicy( newSizePolicy ),
+      userFillRatio( newUserFillRatio )
+    {
+    }
+
+    float size;                       ///< Set or calculated size
+    float fillRatio;                  ///< Ratio to fill remaining space
+    CellSizePolicy sizePolicy;        ///< The size policy used to interpret the size value
+    bool userFillRatio : 1;           ///< FillRatio was set by user
+  };
+
+  typedef Dali::Vector<RowColumnData> RowColumnArray;
+
+public:
+
+  /**
+   * Structure for the layout data
+   */
+  struct CellData
+  {
+    CellData()
+    : horizontalAlignment( HorizontalAlignment::LEFT ),
+      verticalAlignment( VerticalAlignment::TOP )
+    {
+    }
+
+    // data members
+    Dali::Actor actor;
+    Toolkit::TableView::CellPosition position;
+    HorizontalAlignment::Type horizontalAlignment;
+    VerticalAlignment::Type verticalAlignment;
+  };
+
+private:
+
+  /**
    * Construct a new TableView.
    */
   TableView( unsigned int initialRows, unsigned int initialColumns );
@@ -266,14 +384,58 @@ private: // Implementation
    * @param child actor to remove
    * @return true if the actor was found
    */
-  bool RemoveAllInstances( Actor child );
+  bool RemoveAllInstances( const Actor& child );
+
+  /**
+   * @brief Compute relative sizes for an array
+   *
+   * @param[in] data The RowColumn data to compute the relative sizes for
+   */
+  void ComputeRelativeSizes( RowColumnArray& data );
+
+  /**
+   * @brief Calculate the total fixed sizes for a row or column
+   *
+   * @param[in] data The row or column data to process
+   */
+  float CalculateTotalFixedSize( const RowColumnArray& data );
 
   /**
-   * Helper to update relative sizes
-   * @param fixedHeightsTotal sum of the fixed height rows
-   * @param fixedWidthsTotal sum of the fixed width columns
+   * @brief Calculate the fixed sizes for a row or column
+   *
+   * @param[in] data The row or column data to process
+   * @param[in] dimension The dimension being calculated: row == Dimension::HEIGHT, column == Dimension::WIDTH
    */
-  void UpdateRelativeSizes( float& fixedHeightsTotal, float& fixedWidthsTotal );
+  void CalculateFixedSizes( RowColumnArray& data, Dimension::Type dimension );
+
+  /**
+   * @brief Calculate the value of the relative sizes
+   *
+   * @param[in] data The row or column data to process
+   * @param[in] size The size of the table view in that dimension
+   */
+  void CalculateRelativeSizes( RowColumnArray& data, float size );
+
+  /**
+   * @brief Search for a FIT cell in the array
+   *
+   * @param[in] data The row or column data to process
+   * @return Return if a FIT cell was found or not
+   */
+  bool FindFit( const RowColumnArray& data );
+
+  /**
+   * @brief Calculate row and column data when it is dirty
+   */
+  void CalculateRowColumnData();
+
+  /**
+   * @brief Return the cell padding for a given dimension
+   *
+   * @param[in] dimension The dimension to return the padding for
+   * @return Return the padding (x = low, y = high)
+   */
+  Vector2 GetCellPadding( Dimension::Type dimension );
 
   /**
    * A reference counted object may only be deleted by calling Unreference()
@@ -308,11 +470,10 @@ private: // scripting support
 
   /**
    * Generate the map type property value from the size vectors.
-   * @param[in] fixedSize The vector of fixed heights or widths.
-   * @param[in] relativeSize The vector of relative heights or widths.
+   * @param[in] data The array of row or column data
    * @param[out] map The property value.
    */
-  void GetMapPropertyValue( const std::vector<float>& fixedSize, const std::vector<float>& relativeSize, Property::Map& map );
+  void GetMapPropertyValue( const RowColumnArray& data, Property::Map& map );
 
 
   /**
@@ -357,15 +518,15 @@ private:
 
 private: // Data
 
-  Array2d<CellData> mCellData;
-  Array2d<Size> mRelativeSizes;
-  std::vector<float> mFixedHeights;
-  std::vector<float> mRelativeHeights;
-  std::vector<float> mFixedWidths;
-  std::vector<float> mRelativeWidths;
-  Size mPadding;
-  bool mLayoutingChild;
+  Array2d<CellData> mCellData;                ///< Data for each cell: Actor, alignment settings etc
+
+  RowColumnArray mRowData;       ///< Data for each row
+  RowColumnArray mColumnData;    ///< Data for each column
+  Size mFixedTotals;             ///< Accumulated totals for fixed width and height
 
+  Size mPadding;                 ///< Padding to apply to each cell
+  bool mLayoutingChild;          ///< Can't be a bitfield due to Relayouting lock
+  bool mRowColumnDirty : 1;       ///< Flag to indicate the row column data is dirty
 };
 
 } // namespace Internal