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