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