1 #ifndef __DALI_CUSTOM_ACTOR_IMPL_H__
2 #define __DALI_CUSTOM_ACTOR_IMPL_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
30 * @addtogroup dali_core_actors
34 namespace Internal DALI_INTERNAL
42 class CustomActorImpl;
43 class RelayoutContainer;
52 * @brief Pointer to Dali::CustomActorImpl object.
55 typedef IntrusivePtr<CustomActorImpl> CustomActorImplPtr;
58 * @brief CustomActorImpl is an abstract base class for custom control implementations.
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 ).
64 class DALI_IMPORT_API CustomActorImpl : public Dali::RefObject
68 class Extension; ///< Forward declare future extension interface
71 * @brief Virtual destructor
74 virtual ~CustomActorImpl();
77 * @brief Used by derived CustomActorImpl instances, to access the public Actor interface.
80 * @return A pointer to self, or an uninitialized pointer if the CustomActorImpl is not owned.
82 CustomActor Self() const;
85 * @brief Called after the actor has been connected to the stage.
87 * When an actor is connected, it will be directly or indirectly parented to the root Actor.
89 * @param[in] depth The depth in the hierarchy for the actor
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.
105 * @param[in] depth The depth in the hierarchy for the actor
107 virtual void OnStageConnection( int depth ) = 0;
110 * @brief Called after the actor has been disconnected from Stage.
112 * If an actor is disconnected it either has no parent, or is parented to a disconnected actor.
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.
129 virtual void OnStageDisconnection() = 0;
132 * @brief Called after a child has been added to the owning actor.
135 * @param[in] child The child which has been added
137 virtual void OnChildAdd(Actor& child) = 0;
140 * @brief Called after the owning actor has attempted to remove a child( regardless of whether it succeeded or not ).
143 * @param[in] child The child being removed
145 virtual void OnChildRemove(Actor& child) = 0;
148 * @brief Called when the owning actor property is set.
151 * @param[in] index The Property index that was set
152 * @param[in] propertyValue The value to set
154 virtual void OnPropertySet( Property::Index index, Property::Value propertyValue );
157 * @brief Called when the owning actor's size is set e.g. using Actor::SetSize().
160 * @param[in] targetSize The target size. Note that this target size may not match the size returned via @ref Actor::GetTargetSize.
162 virtual void OnSizeSet(const Vector3& targetSize) = 0;
165 * @brief Called when the owning actor's size is animated e.g. using Animation::AnimateTo( Property( actor, Actor::Property::SIZE ), ... ).
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.
171 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize) = 0;
174 * @DEPRECATED_1_1.37 Connect to TouchSignal() instead.
176 * @brief Called after a touch-event is received by the owning actor.
179 * @param[in] event The touch event
180 * @return True if the event should be consumed.
181 * @note CustomActorImpl::REQUIRES_TOUCH_EVENTS must be enabled during construction. See CustomActorImpl::CustomActorImpl( ActorFlags flags ).
183 virtual bool OnTouchEvent(const TouchEvent& event) = 0;
186 * @brief Called after a hover-event is received by the owning actor.
189 * @param[in] event The hover event
190 * @return True if the event should be consumed.
191 * @note CustomActorImpl::REQUIRES_HOVER_EVENTS must be enabled during construction. See CustomActorImpl::CustomActorImpl( ActorFlags flags ).
193 virtual bool OnHoverEvent(const HoverEvent& event) = 0;
196 * @brief Called after a key-event is received by the actor that has had its focus set.
199 * @param[in] event the Key Event
200 * @return True if the event should be consumed.
202 virtual bool OnKeyEvent(const KeyEvent& event) = 0;
205 * @brief Called after a wheel-event is received by the owning actor.
208 * @param[in] event The wheel event
209 * @return True if the event should be consumed.
210 * @note CustomActorImpl::REQUIRES_WHEEL_EVENTS must be enabled during construction. See CustomActorImpl::CustomActorImpl( ActorFlags flags ).
212 virtual bool OnWheelEvent(const WheelEvent& event) = 0;
215 * @brief Called after the size negotiation has been finished for this control.
217 * The control is expected to assign this given size to itself/its children.
219 * Should be overridden by derived classes if they need to layout
220 * actors differently after certain operations like add or remove
221 * actors, resize or after changing specific properties.
224 * @param[in] size The allocated size.
225 * @param[in,out] container The control should add actors to this container that it is not able
226 * to allocate a size for.
227 * @note As this function is called from inside the size negotiation algorithm, you cannot
228 * call RequestRelayout (the call would just be ignored).
230 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container ) = 0;
233 * @brief Notification for deriving classes
236 * @param[in] policy The policy being set
237 * @param[in] dimension The dimension the policy is being set for
239 virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension ) = 0;
242 * @brief Return the natural size of the actor.
245 * @return The actor's natural size
247 virtual Vector3 GetNaturalSize() = 0;
250 * @brief Calculate the size for a child.
253 * @param[in] child The child actor to calculate the size for
254 * @param[in] dimension The dimension to calculate the size for. E.g. width or height.
255 * @return Return the calculated size for the given dimension.
257 virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension ) = 0;
260 * @brief This method is called during size negotiation when a height is required for a given width.
262 * Derived classes should override this if they wish to customize the height returned.
265 * @param width Width to use.
266 * @return The height based on the width.
268 virtual float GetHeightForWidth( float width ) = 0;
271 * @brief This method is called during size negotiation when a width is required for a given height.
273 * Derived classes should override this if they wish to customize the width returned.
276 * @param height Height to use.
277 * @return The width based on the width.
279 virtual float GetWidthForHeight( float height ) = 0;
282 * @brief Determine if this actor is dependent on it's children for relayout.
285 * @param dimension The dimension(s) to check for
286 * @return Return if the actor is dependent on it's children.
288 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS ) = 0;
291 * @brief Virtual method to notify deriving classes that relayout dependencies have been
292 * met and the size for this object is about to be calculated for the given dimension
295 * @param dimension The dimension that is about to be calculated
297 virtual void OnCalculateRelayoutSize( Dimension::Type dimension ) = 0;
300 * @brief Virtual method to notify deriving classes that the size for a dimension
301 * has just been negotiated
304 * @param[in] size The new size for the given dimension
305 * @param[in] dimension The dimension that was just negotiated
307 virtual void OnLayoutNegotiated( float size, Dimension::Type dimension ) = 0;
310 * @brief Retrieve the extension for this control.
313 * @return The extension if available, NULL otherwise
315 virtual Extension* GetExtension()
320 protected: // For derived classes
323 * @brief Flags for the constructor
328 ACTOR_BEHAVIOUR_NONE = 0, ///< Use if no change to default behaviour is needed. @DEPRECATED_1_2_10
329 ACTOR_BEHAVIOUR_DEFAULT = 0, ///< Use to provide default behaviour (size negotiation is on, event callbacks are not called). @SINCE_1_2_10
330 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
331 REQUIRES_TOUCH_EVENTS = 1 << 1, ///< True if the OnTouchEvent() callback is required. @SINCE_1_0.0
332 REQUIRES_HOVER_EVENTS = 1 << 2, ///< True if the OnHoverEvent() callback is required. @SINCE_1_0.0
333 REQUIRES_WHEEL_EVENTS = 1 << 3, ///< True if the OnWheelEvent() callback is required. @SINCE_1_0.0
335 LAST_ACTOR_FLAG ///< Special marker for last actor flag @SINCE_1_0.0
338 static const int ACTOR_FLAG_COUNT = Log< LAST_ACTOR_FLAG - 1 >::value + 1; ///< Value for deriving classes to continue on the flag enum
341 * @brief Create a CustomActorImpl.
343 * @param[in] flags Bitfield of ActorFlags to define behaviour
345 CustomActorImpl( ActorFlags flags );
347 // Size negotiation helpers
350 * @brief Request a relayout, which means performing a size negotiation on this actor, its parent and children (and potentially whole scene).
352 * This method can also be called from a derived class every time it needs a different size.
353 * At the end of event processing, the relayout process starts and
354 * all controls which requested Relayout will have their sizes (re)negotiated.
357 * @note RelayoutRequest() can be called multiple times; the size negotiation is still
358 * only performed once, i.e. there is no need to keep track of this in the calling side.
360 void RelayoutRequest();
363 * @brief Provides the Actor implementation of GetHeightForWidth.
365 * @param width Width to use.
366 * @return The height based on the width.
368 float GetHeightForWidthBase( float width );
371 * @brief Provides the Actor implementation of GetWidthForHeight.
373 * @param height Height to use.
374 * @return The width based on the height.
376 float GetWidthForHeightBase( float height );
379 * @brief Calculate the size for a child using the base actor object.
382 * @param[in] child The child actor to calculate the size for
383 * @param[in] dimension The dimension to calculate the size for. E.g. width or height
384 * @return Return the calculated size for the given dimension. If more than one dimension is requested, just return the first one found.
386 float CalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension );
389 * @brief Determine if this actor is dependent on it's children for relayout from the base class.
392 * @param dimension The dimension(s) to check for
393 * @return Return if the actor is dependent on it's children.
395 bool RelayoutDependentOnChildrenBase( Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
397 public: // Not intended for application developers
400 * @brief Initialize a CustomActor.
402 * @param[in] owner The owning object
403 * @pre The CustomActorImpl is not already owned.
404 * @note Called when ownership of the CustomActorImpl is passed to a CustomActor.
406 void Initialize(Internal::CustomActor& owner);
409 * @brief Get the owner.
411 * This method is needed when creating additional handle objects to existing objects.
412 * Owner is the Dali::Internal::CustomActor that owns the implementation of the custom actor
413 * inside core. Creation of a handle to Dali public API Actor requires this pointer.
415 * @return A pointer to the Actor implementation that owns this custom actor implementation
417 Internal::CustomActor* GetOwner() const;
420 * @brief Returns whether the OnTouchEvent() callback is required.
422 * @return True if the OnTouchEvent() callback is required.
423 * @note Called when ownership of the CustomActorImpl is passed to a CustomActor.
425 bool RequiresTouchEvents() const;
428 * @brief Returns whether the OnHoverEvent() callback is required.
430 * @return True if the OnHoverEvent() callback is required.
431 * @note Called when ownership of the CustomActorImpl is passed to a CustomActor.
433 bool RequiresHoverEvents() const;
436 * @brief Returns whether the OnWheelEvent() callback is required.
438 * @return True if the OnWheelEvent() callback is required.
439 * @note Called when ownership of the CustomActorImpl is passed to a CustomActor.
441 bool RequiresWheelEvents() const;
444 * @brief Returns whether relayout is enabled.
446 * @return Return true if relayout is enabled on the custom actor.
447 * @note Called when ownership of the CustomActorImpl is passed to a CustomActor.
449 bool IsRelayoutEnabled() const;
453 Internal::CustomActor* mOwner; ///< Internal owner of this custom actor implementation
454 ActorFlags mFlags :ACTOR_FLAG_COUNT; ///< ActorFlags flags to determine behaviour
462 #endif // __DALI_CUSTOM_ACTOR_IMPL_H__