DALi Version 1.4.20
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / custom-actor-internal.h
1 #ifndef __DALI_INTERNAL_CUSTOM_ACTOR_H__
2 #define __DALI_INTERNAL_CUSTOM_ACTOR_H__
3
4 /*
5  * Copyright (c) 2018 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 // INTERNAL INCLUDES
22 #include <dali/internal/event/actors/actor-impl.h>
23 #include <dali/internal/event/actors/actor-declarations.h>
24 #include <dali/public-api/actors/custom-actor.h>
25 #include <dali/public-api/animation/animation.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 class CustomActor : public Actor
34 {
35 public:
36
37   /**
38    * Create a new custom actor.
39    * @return A smart-pointer to the newly allocated Actor.
40    */
41   static CustomActorPtr New(CustomActorImpl& extension);
42
43   /**
44    * Retrieve the custom actor implementation.
45    * @return The implementation, or an invalid pointer if no implementation was set.
46    */
47   CustomActorImpl& GetImplementation()
48   {
49     return *mImpl;
50   }
51
52   /**
53    * Retrieve the custom actor implementation.
54    * @return The implementation, or an invalid pointer if no implementation was set.
55    */
56   const CustomActorImpl& GetImplementation() const
57   {
58     return *mImpl;
59   }
60
61   /**
62    * Get the type info associated with this object.
63    *
64    * @return The type info
65    */
66   Dali::TypeInfo GetTypeInfo();
67
68 protected:
69
70   /**
71    * A reference counted object may only be deleted by calling Unreference()
72    */
73   virtual ~CustomActor();
74
75 private:
76
77   /**
78    * @copydoc Internal::Actor::OnStageConnectionExternal
79    */
80   virtual void OnStageConnectionExternal( int32_t depth )
81   {
82     mImpl->OnStageConnection( depth );
83   }
84
85   /**
86    * @copydoc Internal::Actor::OnStageDisconnectionExternal
87    */
88   virtual void OnStageDisconnectionExternal()
89   {
90     mImpl->OnStageDisconnection();
91   }
92
93   /**
94    * @copydoc Internal::Actor::OnChildAdd
95    */
96   virtual void OnChildAdd(Actor& child)
97   {
98     Dali::Actor handle(&child);
99     mImpl->OnChildAdd(handle);
100   }
101
102   /**
103    * @copydoc Internal::Actor::OnChildRemove
104    */
105   virtual void OnChildRemove(Actor& child)
106   {
107     Dali::Actor handle(&child);
108     mImpl->OnChildRemove(handle);
109   }
110
111   /**
112    * @copydoc Internal::Actor::OnPropertySet
113    */
114   virtual void OnPropertySet( Property::Index index, Property::Value propertyValue )
115   {
116     mImpl->OnPropertySet(index, propertyValue);
117   }
118
119   /**
120    * @copydoc Internal::Actor::OnSizeSet
121    */
122   virtual void OnSizeSet(const Vector3& targetSize)
123   {
124     mImpl->OnSizeSet(targetSize);
125   }
126
127   /**
128    * @copydoc Internal::Actor::OnSizeAnimation
129    */
130   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
131   {
132     Dali::Animation animationHandle(&animation);
133     mImpl->OnSizeAnimation(animationHandle, targetSize);
134   }
135
136   /**
137    * @copydoc Internal::Actor::OnTouchEvent
138    */
139   virtual bool OnTouchEvent(const TouchEvent& event)
140   {
141     return mImpl->OnTouchEvent(event);
142   }
143
144   /**
145    * @copydoc Internal::Actor::OnHoverEvent
146    */
147   virtual bool OnHoverEvent(const HoverEvent& event)
148   {
149     return mImpl->OnHoverEvent(event);
150   }
151
152   /**
153    * @copydoc Internal::Actor::OnKeyEvent
154    */
155   virtual bool OnKeyEvent(const KeyEvent& event)
156   {
157     return mImpl->OnKeyEvent(event);
158   }
159
160   /**
161    * @copydoc Internal::Actor::OnWheelEvent
162    */
163   virtual bool OnWheelEvent(const WheelEvent& event)
164   {
165     return mImpl->OnWheelEvent(event);
166   }
167
168   /**
169    * @copydoc Internal::Actor::OnRelayout
170    */
171   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
172   {
173     mImpl->OnRelayout( size, container );
174   }
175
176   /**
177    * @copydoc Internal::Actor::OnSetResizePolicy
178    */
179   virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
180   {
181     mImpl->OnSetResizePolicy( policy, dimension );
182   }
183
184   /**
185    * @copydoc Internal::Actor::GetNaturalSize
186    */
187   virtual Vector3 GetNaturalSize() const
188   {
189     return mImpl->GetNaturalSize();
190   }
191
192   /**
193    * @copydoc Internal::Actor::CalculateChildSize
194    */
195   virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
196   {
197     return mImpl->CalculateChildSize( child, dimension );
198   }
199
200   /**
201    * @copydoc Internal::Actor::GetHeightForWidth
202    */
203   virtual float GetHeightForWidth( float width )
204   {
205     return mImpl->GetHeightForWidth( width );
206   }
207
208   /**
209    * @copydoc Internal::Actor::GetWidthForHeight
210    */
211   virtual float GetWidthForHeight( float height )
212   {
213     return mImpl->GetWidthForHeight( height );
214   }
215
216   /**
217    * @copydoc Internal::Actor::RelayoutDependentOnChildren
218    */
219   virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
220   {
221     return mImpl->RelayoutDependentOnChildren( dimension );
222   }
223
224   /**
225    * @copydoc Internal::Actor::OnCalculateRelayoutSize
226    */
227   virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
228   {
229     return mImpl->OnCalculateRelayoutSize( dimension );
230   }
231
232   /**
233    * @copydoc Internal::Actor::OnLayoutNegotiated
234    */
235   virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
236   {
237     return mImpl->OnLayoutNegotiated( size, dimension );
238   }
239
240   /**
241    * Private constructor; see also CustomActor::New()
242    */
243   CustomActor( const SceneGraph::Node& node, CustomActorImpl& extension );
244
245   // no default or copy constructor or assignment
246   CustomActor() = delete;
247   CustomActor( const CustomActor& ) = delete;
248   CustomActor& operator=( const CustomActor& rhs ) = delete;
249
250 protected:
251
252   CustomActorImplPtr mImpl;
253
254 };
255
256 } // namespace Internal
257
258 // Helpers for public-api forwarding methods
259
260 inline Internal::CustomActor& GetImpl(Dali::CustomActor& actor)
261 {
262   DALI_ASSERT_ALWAYS( actor && "CustomActor handle is empty" );
263
264   BaseObject& handle = actor.GetBaseObject();
265
266   return static_cast<Internal::CustomActor&>(handle);
267 }
268
269 inline const Internal::CustomActor& GetImpl(const Dali::CustomActor& actor)
270 {
271   DALI_ASSERT_ALWAYS( actor && "CustomActor handle is empty" );
272
273   const BaseObject& handle = actor.GetBaseObject();
274
275   return static_cast<const Internal::CustomActor&>(handle);
276 }
277
278 } // namespace Dali
279
280 #endif // __DALI_INTERNAL_CUSTOM_ACTOR_H__