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 namespace Internal DALI_INTERNAL
38 class CustomActorImpl;
39 class RelayoutContainer;
43 struct MouseWheelEvent;
49 * @brief Pointer to Dali::CustomActorImpl object.
51 typedef IntrusivePtr<CustomActorImpl> CustomActorImplPtr;
54 * @brief CustomActorImpl is an abstract base class for custom control implementations.
56 * This provides a series of pure virtual methods, which are called when actor-specific events occur.
57 * An CustomActorImpl is typically owned by a single CustomActor instance; see also CustomActor::New(CustomActorImplPtr).
59 class DALI_IMPORT_API CustomActorImpl : public Dali::RefObject
64 * @brief Virtual destructor.
66 virtual ~CustomActorImpl();
69 * @brief Used by derived CustomActorImpl instances, to access the public Actor interface.
71 * @return A pointer to self, or an uninitialized pointer if the CustomActorImpl is not owned.
73 CustomActor Self() const;
76 * @brief Called after the actor has been connected to the stage.
78 * When an actor is connected, it will be directly or indirectly parented to the root Actor.
79 * @note The root Actor is provided automatically by Dali::Stage, and is always considered to be connected.
81 * @note When the parent of a set of actors is connected to the stage, then all of the children
82 * will received this callback.
84 * For the following actor tree, the callback order will be A, B, D, E, C, and finally F.
92 virtual void OnStageConnection() = 0;
95 * @brief Called after the actor has been disconnected from the stage.
97 * If an actor is disconnected it either has no parent, or is parented to a disconnected actor.
99 * @note When the parent of a set of actors is disconnected to the stage, then all of the children
100 * will received this callback, starting with the leaf actors.
102 * For the following actor tree, the callback order will be D, E, B, F, C, and finally A.
110 virtual void OnStageDisconnection() = 0;
113 * @brief Called after a child has been added to the owning actor.
115 * @param[in] child The child which has been added.
117 virtual void OnChildAdd(Actor& child) = 0;
120 * @brief Called after a child has been removed from the owning actor.
122 * @param[in] child The child being removed.
124 virtual void OnChildRemove(Actor& child) = 0;
127 * @brief Called when the owning actor property is set.
129 * @param[in] index The Property index that was set.
130 * @param[in] propertyValue The value to set.
132 virtual void OnPropertySet( Property::Index index, Property::Value propertyValue ) ;
135 * @brief Called when the owning actor's size is set e.g. using Actor::SetSize().
137 * @param[in] targetSize The target size. Note that this target size may not match the size returned via Actor::GetSize().
139 virtual void OnSizeSet(const Vector3& targetSize) = 0;
142 * @brief Called when the owning actor's size is animated e.g. using Animation::AnimateTo( Property( actor, Actor::Property::SIZE ), ... ).
144 * @param[in] animation The object which is animating the owning actor.
145 * @param[in] targetSize The target size. Note that this target size may not match the size returned via Actor::GetSize().
147 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize) = 0;
150 * @brief Called after a touch-event is received by the owning actor.
152 * @note This must be enabled during construction; see CustomActorImpl::CustomActorImpl(bool)
153 * @param[in] event The touch event.
154 * @return True if the event should be consumed.
156 virtual bool OnTouchEvent(const TouchEvent& event) = 0;
159 * @brief Called after a hover-event is received by the owning actor.
161 * @note This must be enabled during construction; see CustomActorImpl::SetRequiresHoverEvents(bool)
162 * @param[in] event The hover event.
163 * @return True if the event should be consumed.
165 virtual bool OnHoverEvent(const HoverEvent& event) = 0;
168 * @brief Called after a key-event is received by the actor that has had its focus set.
170 * @param[in] event the Key Event
171 * @return True if the event should be consumed.
173 virtual bool OnKeyEvent(const KeyEvent& event) = 0;
176 * @brief Called after a mouse-wheel-event is received by the owning actor.
178 * @note This must be enabled during construction; see CustomActorImpl::SetRequiresMouseWheelEvents(bool)
179 * @param[in] event The mouse wheel event.
180 * @return True if the event should be consumed.
182 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event) = 0;
185 * @brief Called after the size negotiation has been finished for this control.
187 * The control is expected to assign this given size to itself/its children.
189 * Should be overridden by derived classes if they need to layout
190 * actors differently after certain operations like add or remove
191 * actors, resize or after changing specific properties.
193 * Note! As this function is called from inside the size negotiation algorithm, you cannot
194 * call RequestRelayout (the call would just be ignored)
196 * @param[in] size The allocated size.
197 * @param[in,out] container The control should add actors to this container that it is not able
198 * to allocate a size for.
200 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container ) = 0;
203 * @brief Notification for deriving classes
205 * @param[in] policy The policy being set
206 * @param[in] dimension The dimension the policy is being set for
208 virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension ) = 0;
211 * Return the natural size of the actor
213 * @return The actor's natural size
215 virtual Vector3 GetNaturalSize() = 0;
218 * @brief Calculate the size for a child
220 * @param[in] child The child actor to calculate the size for
221 * @param[in] dimension The dimension to calculate the size for. E.g. width or height.
222 * @return Return the calculated size for the given dimension
224 virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension ) = 0;
227 * @brief This method is called during size negotiation when a height is required for a given width.
229 * Derived classes should override this if they wish to customize the height returned.
231 * @param width to use.
232 * @return the height based on the width.
234 virtual float GetHeightForWidth( float width ) = 0;
237 * @brief This method is called during size negotiation when a width is required for a given height.
239 * Derived classes should override this if they wish to customize the width returned.
241 * @param height to use.
242 * @return the width based on the width.
244 virtual float GetWidthForHeight( float height ) = 0;
247 * @brief Determine if this actor is dependent on it's children for relayout
249 * @param dimension The dimension(s) to check for
250 * @return Return if the actor is dependent on it's children
252 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS ) = 0;
255 * @brief Virtual method to notify deriving classes that relayout dependencies have been
256 * met and the size for this object is about to be calculated for the given dimension
258 * @param dimension The dimension that is about to be calculated
260 virtual void OnCalculateRelayoutSize( Dimension::Type dimension ) = 0;
263 * @brief Virtual method to notify deriving classes that the size for a dimension
264 * has just been negotiated
266 * @param[in] size The new size for the given dimension
267 * @param[in] dimension The dimension that was just negotiated
269 virtual void OnLayoutNegotiated( float size, Dimension::Type dimension ) = 0;
271 protected: // For derived classes
273 // Flags for the constructor
276 ACTOR_BEHAVIOUR_NONE = 0,
277 DISABLE_SIZE_NEGOTIATION = 1 << 0, ///< True if control does not need size negotiation, i.e. it can be skipped in the algorithm
278 REQUIRES_TOUCH_EVENTS = 1 << 1, ///< True if the OnTouchEvent() callback is required.
279 REQUIRES_HOVER_EVENTS = 1 << 2, ///< True if the OnHoverEvent() callback is required.
280 REQUIRES_MOUSE_WHEEL_EVENTS = 1 << 3, ///< True if the OnMouseWheelEvent() callback is required.
282 LAST_ACTOR_FLAG ///< Special marker for last actor flag
285 static const int ACTOR_FLAG_COUNT = Log< LAST_ACTOR_FLAG - 1 >::value + 1; ///< Value for deriving classes to continue on the flag enum
288 * @brief Create a CustomActorImpl.
289 * @param[in] flags Bitfield of ActorFlags to define behaviour
291 CustomActorImpl( ActorFlags flags );
294 * @brief Request a relayout, which means performing a size negotiation on this actor, its parent and children (and potentially whole scene)
296 * This method can also be called from a derived class every time it needs a different size.
297 * At the end of event processing, the relayout process starts and
298 * all controls which requested Relayout will have their sizes (re)negotiated.
300 * @note RelayoutRequest() can be called multiple times; the size negotiation is still
301 * only performed once, i.e. there is no need to keep track of this in the calling side.
303 void RelayoutRequest();
306 * @brief Calculate the size for a child using the base actor object
308 * @param[in] child The child actor to calculate the size for
309 * @param[in] dimension The dimension to calculate the size for. E.g. width or height.
310 * @return Return the calculated size for the given dimension
312 float CalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension );
315 * @brief Determine if this actor is dependent on it's children for relayout from the base class
317 * @param dimension The dimension(s) to check for
318 * @return Return if the actor is dependent on it's children
320 bool RelayoutDependentOnChildrenBase( Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
322 public: // Not intended for application developers
325 * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
326 * @pre The CustomActorImpl is not already owned.
327 * @param[in] owner The owning object.
329 void Initialize(Internal::CustomActor& owner);
332 * @brief Get the owner.
334 * This method is needed when creating additional handle objects to existing objects.
335 * Owner is the Dali::Internal::CustomActor that owns the implementation of the custom actor
336 * inside core. Creation of a handle to Dali public API Actor requires this pointer.
337 * @return a pointer to the Actor implementation that owns this custom actor implementation
339 Internal::CustomActor* GetOwner() const;
342 * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
343 * @return True if the OnTouchEvent() callback is required.
345 bool RequiresTouchEvents() const;
348 * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
349 * @return True if the OnHoverEvent() callback is required.
351 bool RequiresHoverEvents() const;
354 * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
355 * @return True if the OnMouseWheelEvent() callback is required.
357 bool RequiresMouseWheelEvents() const;
360 * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
361 * @return Return true if relayout is enabled on the custom actor
363 bool IsRelayoutEnabled() const;
367 Internal::CustomActor* mOwner; ///< Internal owner of this custom actor implementation
368 ActorFlags mFlags :ACTOR_FLAG_COUNT; ///< ActorFlags flags to determine behaviour
373 #endif // __DALI_CUSTOM_ACTOR_IMPL_H__