Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-core.git] / dali / public-api / actors / custom-actor-impl.h
1 #ifndef __DALI_CUSTOM_ACTOR_IMPL_H__
2 #define __DALI_CUSTOM_ACTOR_IMPL_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 // INTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/object/property.h>
24 #include <dali/public-api/object/ref-object.h>
25
26 namespace Dali
27 {
28
29 namespace Internal DALI_INTERNAL
30 {
31 class CustomActor;
32 }
33
34 class Actor;
35 class Animation;
36 class CustomActor;
37 class CustomActorImpl;
38 struct KeyEvent;
39 struct TouchEvent;
40 struct HoverEvent;
41 struct MouseWheelEvent;
42 struct Vector3;
43
44 /**
45  * @brief Pointer to Dali::CustomActorImpl object.
46  */
47 typedef IntrusivePtr<CustomActorImpl> CustomActorImplPtr;
48
49 /**
50  * @brief CustomActorImpl is an abstract base class for custom control implementations.
51  *
52  * This provides a series of pure virtual methods, which are called when actor-specific events occur.
53  * An CustomActorImpl is typically owned by a single CustomActor instance; see also CustomActor::New(CustomActorImplPtr).
54  */
55 class DALI_IMPORT_API CustomActorImpl : public Dali::RefObject
56 {
57 public:
58
59   /**
60    * @brief Virtual destructor.
61    */
62   virtual ~CustomActorImpl();
63
64   /**
65    * @brief Used by derived CustomActorImpl instances, to access the public Actor interface.
66    *
67    * @return A pointer to self, or an uninitialized pointer if the CustomActorImpl is not owned.
68    */
69   CustomActor Self() const;
70
71   /**
72    * @brief Called after the actor has been connected to the stage.
73    *
74    * When an actor is connected, it will be directly or indirectly parented to the root Actor.
75    * @note The root Actor is provided automatically by Dali::Stage, and is always considered to be connected.
76    *
77    * @note When the parent of a set of actors is connected to the stage, then all of the children
78    * will received this callback.
79    *
80    * For the following actor tree, the callback order will be A, B, D, E, C, and finally F.
81    *
82    *       A (parent)
83    *      / \
84    *     B   C
85    *    / \   \
86    *   D   E   F
87    */
88   virtual void OnStageConnection() = 0;
89
90   /**
91    * @brief Called after the actor has been disconnected from the stage.
92    *
93    * If an actor is disconnected it either has no parent, or is parented to a disconnected actor.
94    *
95    * @note When the parent of a set of actors is disconnected to the stage, then all of the children
96    * will received this callback, starting with the leaf actors.
97    *
98    * For the following actor tree, the callback order will be D, E, B, F, C, and finally A.
99    *
100    *       A (parent)
101    *      / \
102    *     B   C
103    *    / \   \
104    *   D   E   F
105    */
106   virtual void OnStageDisconnection() = 0;
107
108   /**
109    * @brief Called after a child has been added to the owning actor.
110    *
111    * @param[in] child The child which has been added.
112    */
113   virtual void OnChildAdd(Actor& child) = 0;
114
115   /**
116    * @brief Called after a child has been removed from the owning actor.
117    *
118    * @param[in] child The child being removed.
119    */
120   virtual void OnChildRemove(Actor& child) = 0;
121
122   /**
123    * @brief Called when the owning actor property is set.
124    *
125    * @param[in] index The Property index that was set.
126    * @param[in] propertyValue The value to set.
127    */
128   virtual void OnPropertySet( Property::Index index, Property::Value propertyValue ) ;
129
130   /**
131    * @brief Called when the owning actor's size is set e.g. using Actor::SetSize().
132    *
133    * @param[in] targetSize The target size. Note that this target size may not match the size returned via Actor::GetSize().
134    */
135   virtual void OnSizeSet(const Vector3& targetSize) = 0;
136
137   /**
138    * @brief Called when the owning actor's size is animated e.g. using Animation::Resize().
139    *
140    * @param[in] animation The object which is animating the owning actor.
141    * @param[in] targetSize The target size. Note that this target size may not match the size returned via Actor::GetSize().
142    */
143   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize) = 0;
144
145   /**
146    * @brief Called after a touch-event is received by the owning actor.
147    *
148    * @note This must be enabled during construction; see CustomActorImpl::CustomActorImpl(bool)
149    * @param[in] event The touch event.
150    * @return True if the event should be consumed.
151    */
152   virtual bool OnTouchEvent(const TouchEvent& event) = 0;
153
154   /**
155    * @brief Called after a hover-event is received by the owning actor.
156    *
157    * @note This must be enabled during construction; see CustomActorImpl::SetRequiresHoverEvents(bool)
158    * @param[in] event The hover event.
159    * @return True if the event should be consumed.
160    */
161   virtual bool OnHoverEvent(const HoverEvent& event) = 0;
162
163   /**
164    * @brief Called after a key-event is received by the actor that has had its focus set.
165    *
166    * @param[in] event the Key Event
167    * @return True if the event should be consumed.
168    */
169   virtual bool OnKeyEvent(const KeyEvent& event) = 0;
170
171   /**
172    * @brief Called after a mouse-wheel-event is received by the owning actor.
173    *
174    * @note This must be enabled during construction; see CustomActorImpl::SetRequiresMouseWheelEvents(bool)
175    * @param[in] event The mouse wheel event.
176    * @return True if the event should be consumed.
177    */
178   virtual bool OnMouseWheelEvent(const MouseWheelEvent& event) = 0;
179
180   /**
181    * Return the natural size of the actor
182    *
183    * @return The actor's natural size
184    */
185   virtual Vector3 GetNaturalSize() = 0;
186
187 protected: // For derived classes
188
189   /**
190    * @brief Create a CustomActorImpl.
191    * @param[in] requiresTouchEvents True if the OnTouchEvent() callback is required.
192    */
193   CustomActorImpl(bool requiresTouchEvents);
194
195   /**
196    * @brief Set whether the custom actor requires hover events.
197    * @param[in] requiresHoverEvents True if the OnHoverEvent() callback is required.
198    */
199   void SetRequiresHoverEvents(bool requiresHoverEvents);
200
201   /**
202    * @brief Set whether the custom actor requires mouse wheel events.
203    * @param[in] requiresMouseWheelEvents True if the OnMouseWheelEvent() callback is required.
204    */
205   void SetRequiresMouseWheelEvents(bool requiresMouseWheelEvents);
206
207 public: // Not intended for application developers
208
209   /**
210    * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
211    * @pre The CustomActorImpl is not already owned.
212    * @param[in] owner The owning object.
213    */
214   void Initialize(Internal::CustomActor& owner);
215
216   /**
217    * @brief Get the owner.
218    *
219    * This method is needed when creating additional handle objects to existing objects.
220    * Owner is the Dali::Internal::CustomActor that owns the implementation of the custom actor
221    * inside core. Creation of a handle to Dali public API Actor requires this pointer.
222    * @return a pointer to the Actor implementation that owns this custom actor implementation
223    */
224   Internal::CustomActor* GetOwner() const;
225
226   /**
227    * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
228    * @return True if the OnTouchEvent() callback is required.
229    */
230   bool RequiresTouchEvents() const;
231
232   /**
233    * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
234    * @return True if the OnHoverEvent() callback is required.
235    */
236   bool RequiresHoverEvents() const;
237
238   /**
239    * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
240    * @return True if the OnMouseWheelEvent() callback is required.
241    */
242   bool RequiresMouseWheelEvents() const;
243
244 private:
245
246   Internal::CustomActor* mOwner;  ///< Internal owner of this custom actor implementation
247   bool mRequiresTouchEvents;      ///< Whether the OnTouchEvent() callback is required
248   bool mRequiresHoverEvents;      ///< Whether the OnHoverEvent() callback is required
249   bool mRequiresMouseWheelEvents; ///< Whether the OnMouseWheelEvent() callback is required
250 };
251
252 } // namespace Dali
253
254 #endif // __DALI_CUSTOM_ACTOR_IMPL_H__