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