Modify doxygen group names
[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) 2015 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/object/property.h>
23 #include <dali/public-api/object/ref-object.h>
24 #include <dali/public-api/actors/actor-enumerations.h>
25 #include <dali/public-api/math/compile-time-math.h>
26
27 namespace Dali
28 {
29 /**
30  * @addtogroup dali_core_actors
31  * @{
32  */
33
34 namespace Internal DALI_INTERNAL
35 {
36 class CustomActor;
37 }
38
39 class Actor;
40 class Animation;
41 class CustomActor;
42 class CustomActorImpl;
43 class RelayoutContainer;
44 struct KeyEvent;
45 struct TouchEvent;
46 struct HoverEvent;
47 struct WheelEvent;
48 struct Vector2;
49 struct Vector3;
50
51 /**
52  * @brief Pointer to Dali::CustomActorImpl object.
53  */
54 typedef IntrusivePtr<CustomActorImpl> CustomActorImplPtr;
55
56 /**
57  * @brief CustomActorImpl is an abstract base class for custom control implementations.
58  *
59  * This provides a series of pure virtual methods, which are called when actor-specific events occur.
60  * An CustomActorImpl is typically owned by a single CustomActor instance; see also CustomActor::New(CustomActorImplPtr).
61  */
62 class DALI_IMPORT_API CustomActorImpl : public Dali::RefObject
63 {
64 public:
65
66   class Extension; ///< Forward declare future extension interface
67
68   /**
69    * @brief Virtual destructor.
70    */
71   virtual ~CustomActorImpl();
72
73   /**
74    * @brief Used by derived CustomActorImpl instances, to access the public Actor interface.
75    *
76    * @return A pointer to self, or an uninitialized pointer if the CustomActorImpl is not owned.
77    */
78   CustomActor Self() const;
79
80   /**
81    * @brief Called after the actor has been connected to the stage.
82    *
83    * When an actor is connected, it will be directly or indirectly parented to the root Actor.
84    * @note The root Actor is provided automatically by Dali::Stage, and is always considered to be connected.
85    *
86    * @note When the parent of a set of actors is connected to the stage, then all of the children
87    * will received this callback.
88    *
89    * For the following actor tree, the callback order will be A, B, D, E, C, and finally F.
90    *
91    *       A (parent)
92    *      / \
93    *     B   C
94    *    / \   \
95    *   D   E   F
96    *
97    *   @param[in] depth The depth in the hierarchy for the actor
98    */
99   virtual void OnStageConnection( int depth ) = 0;
100
101   /**
102    * @brief Called after the actor has been disconnected from the stage.
103    *
104    * If an actor is disconnected it either has no parent, or is parented to a disconnected actor.
105    *
106    * @note When the parent of a set of actors is disconnected to the stage, then all of the children
107    * will received this callback, starting with the leaf actors.
108    *
109    * For the following actor tree, the callback order will be D, E, B, F, C, and finally A.
110    *
111    *       A (parent)
112    *      / \
113    *     B   C
114    *    / \   \
115    *   D   E   F
116    */
117   virtual void OnStageDisconnection() = 0;
118
119   /**
120    * @brief Called after a child has been added to the owning actor.
121    *
122    * @param[in] child The child which has been added.
123    */
124   virtual void OnChildAdd(Actor& child) = 0;
125
126   /**
127    * @brief Called after a child has been removed from the owning actor.
128    *
129    * @param[in] child The child being removed.
130    */
131   virtual void OnChildRemove(Actor& child) = 0;
132
133   /**
134    * @brief Called when the owning actor property is set.
135    *
136    * @param[in] index The Property index that was set.
137    * @param[in] propertyValue The value to set.
138    */
139   virtual void OnPropertySet( Property::Index index, Property::Value propertyValue );
140
141   /**
142    * @brief Called when the owning actor's size is set e.g. using Actor::SetSize().
143    *
144    * @param[in] targetSize The target size. Note that this target size may not match the size returned via Actor::GetSize().
145    */
146   virtual void OnSizeSet(const Vector3& targetSize) = 0;
147
148   /**
149    * @brief Called when the owning actor's size is animated e.g. using Animation::AnimateTo( Property( actor, Actor::Property::SIZE ), ... ).
150    *
151    * @param[in] animation The object which is animating the owning actor.
152    * @param[in] targetSize The target size. Note that this target size may not match the size returned via Actor::GetSize().
153    */
154   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize) = 0;
155
156   /**
157    * @brief Called after a touch-event is received by the owning actor.
158    *
159    * @note This must be enabled during construction; see CustomActorImpl::CustomActorImpl(bool)
160    * @param[in] event The touch event.
161    * @return True if the event should be consumed.
162    */
163   virtual bool OnTouchEvent(const TouchEvent& event) = 0;
164
165   /**
166    * @brief Called after a hover-event is received by the owning actor.
167    *
168    * @note This must be enabled during construction; see CustomActorImpl::SetRequiresHoverEvents(bool)
169    * @param[in] event The hover event.
170    * @return True if the event should be consumed.
171    */
172   virtual bool OnHoverEvent(const HoverEvent& event) = 0;
173
174   /**
175    * @brief Called after a key-event is received by the actor that has had its focus set.
176    *
177    * @param[in] event the Key Event
178    * @return True if the event should be consumed.
179    */
180   virtual bool OnKeyEvent(const KeyEvent& event) = 0;
181
182   /**
183    * @brief Called after a wheel-event is received by the owning actor.
184    *
185    * @note This must be enabled during construction; see CustomActorImpl::SetRequiresWheelEvents(bool)
186    * @param[in] event The wheel event.
187    * @return True if the event should be consumed.
188    */
189   virtual bool OnWheelEvent(const WheelEvent& event) = 0;
190
191   /**
192    * @brief Called after the size negotiation has been finished for this control.
193    *
194    * The control is expected to assign this given size to itself/its children.
195    *
196    * Should be overridden by derived classes if they need to layout
197    * actors differently after certain operations like add or remove
198    * actors, resize or after changing specific properties.
199    *
200    * Note! As this function is called from inside the size negotiation algorithm, you cannot
201    * call RequestRelayout (the call would just be ignored)
202    *
203    * @param[in]      size       The allocated size.
204    * @param[in,out]  container  The control should add actors to this container that it is not able
205    *                            to allocate a size for.
206    */
207   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container ) = 0;
208
209   /**
210    * @brief Notification for deriving classes
211    *
212    * @param[in] policy The policy being set
213    * @param[in] dimension The dimension the policy is being set for
214    */
215   virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension ) = 0;
216
217   /**
218    * Return the natural size of the actor
219    *
220    * @return The actor's natural size
221    */
222   virtual Vector3 GetNaturalSize() = 0;
223
224   /**
225    * @brief Calculate the size for a child
226    *
227    * @param[in] child The child actor to calculate the size for
228    * @param[in] dimension The dimension to calculate the size for. E.g. width or height.
229    * @return Return the calculated size for the given dimension
230    */
231   virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension ) = 0;
232
233   /**
234    * @brief This method is called during size negotiation when a height is required for a given width.
235    *
236    * Derived classes should override this if they wish to customize the height returned.
237    *
238    * @param width to use.
239    * @return the height based on the width.
240    */
241   virtual float GetHeightForWidth( float width ) = 0;
242
243   /**
244    * @brief This method is called during size negotiation when a width is required for a given height.
245    *
246    * Derived classes should override this if they wish to customize the width returned.
247    *
248    * @param height to use.
249    * @return the width based on the width.
250    */
251   virtual float GetWidthForHeight( float height ) = 0;
252
253   /**
254    * @brief Determine if this actor is dependent on it's children for relayout
255    *
256    * @param dimension The dimension(s) to check for
257    * @return Return if the actor is dependent on it's children
258    */
259   virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS ) = 0;
260
261   /**
262    * @brief Virtual method to notify deriving classes that relayout dependencies have been
263    * met and the size for this object is about to be calculated for the given dimension
264    *
265    * @param dimension The dimension that is about to be calculated
266    */
267   virtual void OnCalculateRelayoutSize( Dimension::Type dimension ) = 0;
268
269   /**
270    * @brief Virtual method to notify deriving classes that the size for a dimension
271    * has just been negotiated
272    *
273    * @param[in] size The new size for the given dimension
274    * @param[in] dimension The dimension that was just negotiated
275    */
276   virtual void OnLayoutNegotiated( float size, Dimension::Type dimension ) = 0;
277
278   /**
279    * Retrieve the extension for this control
280    *
281    * @return The extension if available, NULL otherwise
282    */
283   virtual Extension* GetExtension()
284   {
285     return NULL;
286   }
287
288 protected: // For derived classes
289
290   // Flags for the constructor
291   enum ActorFlags
292   {
293     ACTOR_BEHAVIOUR_NONE          = 0,
294     DISABLE_SIZE_NEGOTIATION      = 1 << 0,     ///< True if control does not need size negotiation, i.e. it can be skipped in the algorithm
295     REQUIRES_TOUCH_EVENTS         = 1 << 1,     ///< True if the OnTouchEvent() callback is required.
296     REQUIRES_HOVER_EVENTS         = 1 << 2,     ///< True if the OnHoverEvent() callback is required.
297     REQUIRES_WHEEL_EVENTS   = 1 << 3,     ///< True if the OnWheelEvent() callback is required.
298
299     LAST_ACTOR_FLAG                             ///< Special marker for last actor flag
300   };
301
302   static const int ACTOR_FLAG_COUNT = Log< LAST_ACTOR_FLAG - 1 >::value + 1;      ///< Value for deriving classes to continue on the flag enum
303
304   /**
305    * @brief Create a CustomActorImpl.
306    * @param[in] flags Bitfield of ActorFlags to define behaviour
307    */
308   CustomActorImpl( ActorFlags flags );
309
310   // Size negotiation helpers
311
312   /**
313    * @brief Request a relayout, which means performing a size negotiation on this actor, its parent and children (and potentially whole scene)
314    *
315    * This method can also be called from a derived class every time it needs a different size.
316    * At the end of event processing, the relayout process starts and
317    * all controls which requested Relayout will have their sizes (re)negotiated.
318    *
319    * @note RelayoutRequest() can be called multiple times; the size negotiation is still
320    * only performed once, i.e. there is no need to keep track of this in the calling side.
321    */
322   void RelayoutRequest();
323
324   /**
325    * @brief provides the Actor implementation of GetHeightForWidth
326    * @param width to use.
327    * @return the height based on the width.
328    */
329   float GetHeightForWidthBase( float width );
330
331   /**
332    * @brief provides the Actor implementation of GetWidthForHeight
333    * @param height to use.
334    * @return the width based on the height.
335    */
336   float GetWidthForHeightBase( float height );
337
338   /**
339    * @brief Calculate the size for a child using the base actor object
340    *
341    * @param[in] child The child actor to calculate the size for
342    * @param[in] dimension The dimension to calculate the size for. E.g. width or height.
343    * @return Return the calculated size for the given dimension
344    */
345   float CalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension );
346
347   /**
348    * @brief Determine if this actor is dependent on it's children for relayout from the base class
349    *
350    * @param dimension The dimension(s) to check for
351    * @return Return if the actor is dependent on it's children
352    */
353   bool RelayoutDependentOnChildrenBase( Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
354
355 public: // Not intended for application developers
356
357   /**
358    * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
359    * @pre The CustomActorImpl is not already owned.
360    * @param[in] owner The owning object.
361    */
362   void Initialize(Internal::CustomActor& owner);
363
364   /**
365    * @brief Get the owner.
366    *
367    * This method is needed when creating additional handle objects to existing objects.
368    * Owner is the Dali::Internal::CustomActor that owns the implementation of the custom actor
369    * inside core. Creation of a handle to Dali public API Actor requires this pointer.
370    * @return a pointer to the Actor implementation that owns this custom actor implementation
371    */
372   Internal::CustomActor* GetOwner() const;
373
374   /**
375    * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
376    * @return True if the OnTouchEvent() callback is required.
377    */
378   bool RequiresTouchEvents() const;
379
380   /**
381    * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
382    * @return True if the OnHoverEvent() callback is required.
383    */
384   bool RequiresHoverEvents() const;
385
386   /**
387    * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
388    * @return True if the OnWheelEvent() callback is required.
389    */
390   bool RequiresWheelEvents() const;
391
392   /**
393    * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
394    * @return Return true if relayout is enabled on the custom actor
395    */
396   bool IsRelayoutEnabled() const;
397
398 private:
399
400   Internal::CustomActor* mOwner;        ///< Internal owner of this custom actor implementation
401   ActorFlags mFlags :ACTOR_FLAG_COUNT;  ///< ActorFlags flags to determine behaviour
402 };
403
404 /**
405  * @}
406  */
407 } // namespace Dali
408
409 #endif // __DALI_CUSTOM_ACTOR_IMPL_H__