Moved ControlImpl to Internal namespace & renamed to Control
[platform/core/uifw/dali-toolkit.git] / optional / dali-toolkit / internal / controls / cluster / cluster-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_CLUSTER_H__
2 #define __DALI_TOOLKIT_INTERNAL_CLUSTER_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // INTERNAL INCLUDES
21 #include <dali/public-api/object/ref-object.h>
22
23 #include <dali-toolkit/public-api/controls/cluster/cluster.h>
24 #include <dali-toolkit/public-api/controls/cluster/cluster-style.h>
25 #include <dali-toolkit/public-api/controls/control-impl.h>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 namespace Internal
34 {
35
36 class Cluster;
37
38 typedef IntrusivePtr<Cluster> ClusterPtr;
39
40 class ChildInfo
41 {
42
43 public:
44
45   ChildInfo()
46   : mExpanded(false)
47   {
48   }
49
50   ChildInfo(Actor actor, unsigned int positionIndex)
51   : mActor(actor),
52     mExpanded(false),
53     mPositionIndex(positionIndex)
54   {
55   }
56
57   Actor mActor;
58   bool mExpanded;
59   unsigned int mPositionIndex;
60 };
61
62 typedef std::vector<ChildInfo> ChildInfoContainer;
63 typedef ChildInfoContainer::iterator ChildInfoIter;
64 typedef ChildInfoContainer::const_iterator ChildInfoConstIter;
65
66 /**
67  * Cluster is a container of grouped actors positioned in different cluster styles.
68  * Multiple cluster styles may be provided, to determine the position, size, rotation, scale, color and visibility
69  * of the child actors in the cluster.
70  */
71 class Cluster : public Control
72 {
73 public:
74
75   /**
76    * Create a new Cluster.
77    * @param[in] style of the cluster
78    * @return A public handle to the newly allocated Cluster.
79    */
80   static Dali::Toolkit::Cluster New(Toolkit::ClusterStyle& style);
81
82   /**
83    * @copydoc Toolkit::Cluster::AddChild( Actor child )
84    */
85   void AddChild( Actor child );
86
87   /**
88    * @copydoc Toolkit::Cluster::AddChild( Actor child, unsigned int positionIndex )
89    */
90   void AddChild( Actor child, unsigned int positionIndex );
91
92   /**
93    * @copydoc Toolkit::Cluster::AddChildAt( Actor child, unsigned int index );
94    */
95   void AddChildAt( Actor child, unsigned int index );
96
97   /**
98    * @copydoc Toolkit::Cluster::AddChildAt( Actor child, unsigned int positionIndex, unsigned int index );
99    */
100   void AddChildAt( Actor child, unsigned int positionIndex, unsigned int index );
101
102   /**
103    * Adds a ChildInfo struct to the end of the children list.
104    * @param[in] childInfo the child info to that to children list.
105    */
106   void AddChildInfo( ChildInfo childInfo );
107
108   /**
109    * Adds a ChildInfo struct before the specified index.
110    * @param[in] childInfo the child info to that to children list.
111    * @param[in] index the index within the children list to insert
112    * ChildInfo
113    */
114   void AddChildInfoAt( ChildInfo childInfo, unsigned int index );
115
116   /**
117    * @copydoc Toolkit::Cluster::GetChildAt
118    */
119   Actor GetChildAt( unsigned int index );
120
121   /**
122    * @copydoc Toolkit::Cluster::RemoveChildAt
123    */
124   Actor RemoveChildAt( unsigned int index );
125
126   /**
127    * @copydoc Toolkit::Cluster::ExpandChild
128    */
129   void ExpandChild( unsigned int index );
130
131   /**
132    * @copydoc Toolkit::Cluster::ExpandAllChildren
133    */
134   void ExpandAllChildren();
135
136   /**
137    * @copydoc Toolkit::Cluster::CollapseChild
138    */
139   void CollapseChild( unsigned int index, bool front );
140
141   /**
142    * @copydoc Toolkit::Cluster::CollapseAllChildren
143    */
144   void CollapseAllChildren( bool front );
145
146   /**
147    * @copydoc Toolkit::Cluster::TransformChild
148    */
149   void TransformChild( unsigned int index, const Vector3& position, const Vector3& scale, const Quaternion& rotation, AlphaFunction alpha, const TimePeriod& period );
150
151   /**
152    * @copydoc Toolkit::Cluster::RestoreChild
153    */
154   void RestoreChild( unsigned int index, AlphaFunction alpha, const TimePeriod& period, bool front );
155
156   /**
157    * @copydoc Toolkit::Cluster::SetBackgroundImage
158    */
159   void SetBackgroundImage( Actor image );
160
161   /**
162    * @copydoc Toolkit::Cluster::SetTitle
163    */
164   void SetTitle( Actor text );
165
166   /**
167    * @copydoc Toolkit::Cluster::SetStyle
168    */
169   void SetStyle(Toolkit::ClusterStyle style);
170
171   /**
172    * @copydoc Toolkit::Cluster::GetStyle
173    */
174   Toolkit::ClusterStyle GetStyle() const;
175
176   /**
177    * @copydoc Toolkit::Cluster::GetExpandedCount
178    */
179   unsigned int GetExpandedCount() const;
180
181   /**
182    * @copydoc Toolkit::Cluster::GetTotalCount
183    */
184   unsigned int GetTotalCount() const;
185
186 private:
187
188   ChildInfo GetChildInfoAt( unsigned int index );
189
190   void SetDepth( ChildInfo& childInfo, float depth );
191
192   /**
193    * Updates the style of the Background
194    * (occurs when either background changes or style changes)
195    * @param[in] duration apply duration for style
196    */
197   void UpdateBackground(float duration);
198
199   /**
200    * Updates the style of the Title
201    * (occurs when either background changes or style changes)
202    * @param[in] duration apply duration for style
203    */
204   void UpdateTitle(float duration);
205
206   /**
207    * Action: Expand
208    * Expands one or more actors.
209    *
210    * @param[in] attributes list of indices of actors to expand.
211    * (if no attributes specifies, then all actors expand)
212    */
213   void DoExpandAction(const PropertyValueContainer& attributes);
214
215   /**
216    * Action: Collapse
217    * Collapses one or more actors.
218    *
219    * @param[in] attributes list of indices of actors to collapse.
220    * (if no attributes specifies, then all actors collapse)
221    */
222   void DoCollapseAction(const PropertyValueContainer& attributes);
223
224   /**
225    * Action: Transform
226    * Transforms one actor (index) to a specified position (Vector3),
227    * scale (Vector3), and rotation (Quaternion).
228    *
229    * @param[in] attributes index and transform values.
230    */
231   void DoTransformAction(const PropertyValueContainer& attributes);
232
233 private: // From Control
234   /**
235    * From Control; called shortly before a child is removed from the owning actor.
236    * @param[in] child The child being removed.Ptr
237    */
238   virtual void OnControlChildRemove(Actor& child);
239
240 public:
241
242   /**
243    * Performs actions as requested using the action name.
244    * @param[in] object The object on which to perform the action.
245    * @param[in] actionName The action to perform.
246    * @param[in] attributes The attributes with which to perfrom this action.
247    * @return true if action has been accepted by this control
248    */
249   static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
250
251 private: // From Control
252
253   /**
254    * @copydoc Toolkit::Control::OnInitialize()
255    */
256   virtual void OnInitialize();
257
258 protected:
259
260   /**
261    * Construct a new Cluster.
262    * @param[in] style of the cluster
263    */
264   Cluster(Toolkit::ClusterStyle& style);
265
266   /**
267    * A reference counted object may only be deleted by calling Unreference()
268    */
269   virtual ~Cluster();
270
271 private:
272
273   // Undefined
274   Cluster(const Cluster&);
275
276   // Undefined
277   Cluster& operator=(const Cluster& rhs);
278
279 private:
280
281   Toolkit::ClusterStyle mClusterStyle;
282   ChildInfoContainer mChildren;
283
284   Actor mBackgroundImage;           ///< Stores the background image.
285   Actor mTitle;                     ///< Stores the text title.
286   unsigned int mExpandedCount;      ///< A count of how many children have been expanded.
287
288 };
289
290 } // namespace Internal
291
292 // Helpers for public-api forwarding methods
293
294 inline Toolkit::Internal::Cluster& GetImpl(Toolkit::Cluster& cluster)
295 {
296   DALI_ASSERT_ALWAYS(cluster);
297
298   Dali::RefObject& handle = cluster.GetImplementation();
299
300   return static_cast<Toolkit::Internal::Cluster&>(handle);
301 }
302
303 inline const Toolkit::Internal::Cluster& GetImpl(const Toolkit::Cluster& cluster)
304 {
305   DALI_ASSERT_ALWAYS(cluster);
306
307   const Dali::RefObject& handle = cluster.GetImplementation();
308
309   return static_cast<const Toolkit::Internal::Cluster&>(handle);
310 }
311
312 } // namespace Toolkit
313
314 } // namespace Dali
315
316 #endif // __DALI_TOOLKIT_INTERNAL_CLUSTER_H__