Fix the buffer overflow issue in nanosvg
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / flex-container / flex-container-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_FLEX_CONTAINER_H__
2 #define __DALI_TOOLKIT_INTERNAL_FLEX_CONTAINER_H__
3
4 /*
5  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/object/weak-handle.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/controls/control-impl.h>
26 #include <dali-toolkit/devel-api/controls/flex-container/flex-container.h>
27 extern "C"
28 {
29 #include "layout.h"
30 }
31
32 namespace Dali
33 {
34
35 namespace Toolkit
36 {
37
38 namespace Internal
39 {
40
41 /**
42  * FlexContainer is a custom control for laying out actors in a flexbox layout
43  * @see Dali::Toolkit:FlexContainer for more details
44  */
45 class FlexContainer : public Control
46 {
47 public:
48
49   /**
50    * The structure to store the style properties and layout information of flex item
51    */
52   struct FlexItemNode
53   {
54     WeakHandle< Dali::Actor > actor;      ///< Actor handle of the flex item
55     css_node_t* node;                     ///< The style properties and layout information
56   };
57
58   typedef std::vector< FlexItemNode > FlexItemNodeContainer;
59
60 public:
61
62   /**
63    * Construct a new FlexContainer.
64    */
65   FlexContainer();
66
67   /**
68    * Create a new FlexContainer.
69    * @return A smart-pointer to the newly allocated FlexContainer.
70    */
71   static Toolkit::FlexContainer New();
72
73   /**
74    * @brief Set the primary direction in which content is ordered.
75    * @param[in] contentDirection The direction of the content.
76    */
77   void SetContentDirection(Toolkit::FlexContainer::ContentDirection contentDirection);
78
79   /**
80    * @brief Get the direction of the content.
81    * @return The direction of the content.
82    */
83   Toolkit::FlexContainer::ContentDirection GetContentDirection();
84
85   /**
86    * @brief Set the direction flex items are laid out.
87    * @param[in] flexDirection The direction flex items are laid out.
88    */
89   void SetFlexDirection(Toolkit::FlexContainer::FlexDirection flexDirection);
90
91   /**
92    * @brief Get the direction flex items are laid out.
93    * @return The direction flex items are laid out.
94    */
95   Toolkit::FlexContainer::FlexDirection GetFlexDirection();
96
97   /**
98    * @brief Set whether the flex items should wrap or not, if there
99    * is no enough room for them on one flex line.
100    * @param[in] flexWrap The wrap type.
101    */
102   void SetFlexWrap(Toolkit::FlexContainer::WrapType flexWrap);
103
104   /**
105    * @brief Get whether the flex items should wrap or not, if there
106    * is no enough room for them on one flex line.
107    * @return The wrap type.
108    */
109   Toolkit::FlexContainer::WrapType GetFlexWrap();
110
111   /**
112    * @brief Set the horizontal alignment of the flex items when the items
113    * do not use all available space on the main-axis.
114    * @param[in] justifyContent The horizontal alignment of flex items.
115    */
116   void SetJustifyContent(Toolkit::FlexContainer::Justification justifyContent);
117
118   /**
119    * @brief Get the horizontal alignment of the flex items when the items
120    * do not use all available space on the main-axis.
121    * @return The horizontal alignment of flex items.
122    */
123   Toolkit::FlexContainer::Justification GetJustifyContent();
124
125   /**
126    * @brief Set the vertical alignment of the flex items when the items
127    * do not use all available space on the cross-axis.
128    * @param[in] alignItems The vertical alignment of flex items.
129    */
130   void SetAlignItems(Toolkit::FlexContainer::Alignment alignItems);
131
132   /**
133    * @brief Get the vertical alignment of the flex items when the items
134    * do not use all available space on the cross-axis.
135    * @return The vertical alignment of flex items.
136    */
137   Toolkit::FlexContainer::Alignment GetAlignItems();
138
139   /**
140    * @brief Set the vertical alignment of the flex lines when the lines
141    * do not use all available space on the cross-axis.
142    * @param[in] alignItems The vertical alignment of flex lines.
143    */
144   void SetAlignContent(Toolkit::FlexContainer::Alignment alignContent);
145
146   /**
147    * @brief Get the vertical alignment of the flex lines when the lines
148    * do not use all available space on the cross-axis.
149    * @return The vertical alignment of flex lines.
150    */
151   Toolkit::FlexContainer::Alignment GetAlignContent();
152
153   // Properties
154
155   /**
156    * Called when a property of an object of this type is set.
157    * @param[in] object The object whose property is set.
158    * @param[in] index The property index.
159    * @param[in] value The new property value.
160    */
161   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
162
163   /**
164    * Called to retrieve a property of an object of this type.
165    * @param[in] object The object whose property is to be retrieved.
166    * @param[in] index The property index.
167    * @return The current value of the property.
168    */
169   static Property::Value GetProperty( BaseObject* object, Property::Index index );
170
171 private: // From Control
172
173   /**
174    * @copydoc Control::OnInitialize()
175    */
176   virtual void OnInitialize();
177
178   /**
179    * @copydoc Control::OnChildAdd(Actor& child)
180    */
181   virtual void OnChildAdd( Actor& child );
182
183   /**
184    * @copydoc Control::OnChildRemove(Actor& child)
185    */
186   virtual void OnChildRemove( Actor& child );
187
188   /**
189    * @copydoc Control::OnRelayout
190    */
191   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
192
193   /**
194    * @copydoc Control::RelayoutDependentOnChildren()
195    */
196   virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
197
198   /**
199    * @copydoc Control::GetNextKeyboardFocusableActor
200    */
201   virtual Actor GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled );
202
203   /**
204    * @copydoc CustomActorImpl::OnSizeSet( const Vector3& size )
205    */
206   virtual void OnSizeSet( const Vector3& size );
207
208   /**
209    * @copydoc CustomActorImpl::OnSizeAnimation(Animation&, const Vector3&)
210    */
211   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
212
213 private: // Implementation
214
215   /**
216    * Calculate the layout properties of all the children
217    */
218   void ComputeLayout();
219
220   /**
221    * Calculate the layout of the children and relayout them with their new size and position
222    */
223   void RelayoutChildren();
224
225   /**
226    * A reference counted object may only be deleted by calling Unreference()
227    */
228   virtual ~FlexContainer();
229
230 private:
231
232   // Undefined copy constructor and assignment operators
233   FlexContainer(const FlexContainer&);
234   FlexContainer& operator=(const FlexContainer& rhs);
235
236 private: // Data
237
238   FlexItemNode mRootNode;                    ///< Style properties and layout information of flex container
239   FlexItemNodeContainer mChildrenNodes;      ///< Style properties and layout information of flex items in the container
240
241   Toolkit::FlexContainer::ContentDirection mContentDirection;        ///< The content direction of the container
242   Toolkit::FlexContainer::FlexDirection mFlexDirection;              ///< The flex direction of the container
243   Toolkit::FlexContainer::WrapType mFlexWrap;                        ///< The wrap type of the container
244   Toolkit::FlexContainer::Justification mJustifyContent;             ///< The alignment of flex items in the container on the main-axis
245   Toolkit::FlexContainer::Alignment mAlignItems;                     ///< The alignment of flex items in the container on the cross-axis
246   Toolkit::FlexContainer::Alignment mAlignContent;                   ///< The alignment of flex lines in the container on the cross-axis
247 };
248
249 } // namespace Internal
250
251 // Helpers for public-api forwarding methods
252
253 inline Toolkit::Internal::FlexContainer& GetImpl( Toolkit::FlexContainer& tableView )
254 {
255   DALI_ASSERT_ALWAYS(tableView);
256
257   Dali::RefObject& handle = tableView.GetImplementation();
258
259   return static_cast<Toolkit::Internal::FlexContainer&>(handle);
260 }
261
262 inline const Toolkit::Internal::FlexContainer& GetImpl( const Toolkit::FlexContainer& tableView )
263 {
264   DALI_ASSERT_ALWAYS(tableView);
265
266   const Dali::RefObject& handle = tableView.GetImplementation();
267
268   return static_cast<const Toolkit::Internal::FlexContainer&>(handle);
269 }
270
271 } // namespace Toolkit
272
273 } // namespace Dali
274
275 #endif // __DALI_TOOLKIT_INTERNAL_FLEX_CONTAINER_H__