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/common/vector-wrapper.h>
23 #include <dali/public-api/object/property.h>
24 #include <dali/public-api/object/ref-object.h>
25 #include <dali/public-api/actors/actor-enumerations.h>
26 #include <dali/public-api/math/compile-time-math.h>
31 namespace Internal DALI_INTERNAL
39 class CustomActorImpl;
40 class RelayoutContainer;
44 struct MouseWheelEvent;
50 * @brief Pointer to Dali::CustomActorImpl object.
52 typedef IntrusivePtr<CustomActorImpl> CustomActorImplPtr;
55 * @brief CustomActorImpl is an abstract base class for custom control implementations.
57 * This provides a series of pure virtual methods, which are called when actor-specific events occur.
58 * An CustomActorImpl is typically owned by a single CustomActor instance; see also CustomActor::New(CustomActorImplPtr).
60 class DALI_IMPORT_API CustomActorImpl : public Dali::RefObject
65 * @brief Virtual destructor.
67 virtual ~CustomActorImpl();
70 * @brief Used by derived CustomActorImpl instances, to access the public Actor interface.
72 * @return A pointer to self, or an uninitialized pointer if the CustomActorImpl is not owned.
74 CustomActor Self() const;
77 * @brief Called after the actor has been connected to the stage.
79 * When an actor is connected, it will be directly or indirectly parented to the root Actor.
80 * @note The root Actor is provided automatically by Dali::Stage, and is always considered to be connected.
82 * @note When the parent of a set of actors is connected to the stage, then all of the children
83 * will received this callback.
85 * For the following actor tree, the callback order will be A, B, D, E, C, and finally F.
93 virtual void OnStageConnection() = 0;
96 * @brief Called after the actor has been disconnected from the stage.
98 * If an actor is disconnected it either has no parent, or is parented to a disconnected actor.
100 * @note When the parent of a set of actors is disconnected to the stage, then all of the children
101 * will received this callback, starting with the leaf actors.
103 * For the following actor tree, the callback order will be D, E, B, F, C, and finally A.
111 virtual void OnStageDisconnection() = 0;
114 * @brief Called after a child has been added to the owning actor.
116 * @param[in] child The child which has been added.
118 virtual void OnChildAdd(Actor& child) = 0;
121 * @brief Called after a child has been removed from the owning actor.
123 * @param[in] child The child being removed.
125 virtual void OnChildRemove(Actor& child) = 0;
128 * @brief Called when the owning actor property is set.
130 * @param[in] index The Property index that was set.
131 * @param[in] propertyValue The value to set.
133 virtual void OnPropertySet( Property::Index index, Property::Value propertyValue ) ;
136 * @brief Called when the owning actor's size is set e.g. using Actor::SetSize().
138 * @param[in] targetSize The target size. Note that this target size may not match the size returned via Actor::GetSize().
140 virtual void OnSizeSet(const Vector3& targetSize) = 0;
143 * @brief Called when the owning actor's size is animated e.g. using Animation::AnimateTo( Property( actor, Actor::Property::SIZE ), ... ).
145 * @param[in] animation The object which is animating the owning actor.
146 * @param[in] targetSize The target size. Note that this target size may not match the size returned via Actor::GetSize().
148 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize) = 0;
151 * @brief Called after a touch-event is received by the owning actor.
153 * @note This must be enabled during construction; see CustomActorImpl::CustomActorImpl(bool)
154 * @param[in] event The touch event.
155 * @return True if the event should be consumed.
157 virtual bool OnTouchEvent(const TouchEvent& event) = 0;
160 * @brief Called after a hover-event is received by the owning actor.
162 * @note This must be enabled during construction; see CustomActorImpl::SetRequiresHoverEvents(bool)
163 * @param[in] event The hover event.
164 * @return True if the event should be consumed.
166 virtual bool OnHoverEvent(const HoverEvent& event) = 0;
169 * @brief Called after a key-event is received by the actor that has had its focus set.
171 * @param[in] event the Key Event
172 * @return True if the event should be consumed.
174 virtual bool OnKeyEvent(const KeyEvent& event) = 0;
177 * @brief Called after a mouse-wheel-event is received by the owning actor.
179 * @note This must be enabled during construction; see CustomActorImpl::SetRequiresMouseWheelEvents(bool)
180 * @param[in] event The mouse wheel event.
181 * @return True if the event should be consumed.
183 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event) = 0;
186 * @brief Called after the size negotiation has been finished for this control.
188 * The control is expected to assign this given size to itself/its children.
190 * Should be overridden by derived classes if they need to layout
191 * actors differently after certain operations like add or remove
192 * actors, resize or after changing specific properties.
194 * Note! As this function is called from inside the size negotiation algorithm, you cannot
195 * call RequestRelayout (the call would just be ignored)
197 * @param[in] size The allocated size.
198 * @param[in,out] container The control should add actors to this container that it is not able
199 * to allocate a size for.
201 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container ) = 0;
204 * @brief Notification for deriving classes
206 * @param[in] policy The policy being set
207 * @param[in] dimension The dimension the policy is being set for
209 virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension ) = 0;
212 * Return the natural size of the actor
214 * @return The actor's natural size
216 virtual Vector3 GetNaturalSize() = 0;
219 * @brief Calculate the size for a child
221 * @param[in] child The child actor to calculate the size for
222 * @param[in] dimension The dimension to calculate the size for. E.g. width or height.
223 * @return Return the calculated size for the given dimension
225 virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension ) = 0;
228 * @brief This method is called during size negotiation when a height is required for a given width.
230 * Derived classes should override this if they wish to customize the height returned.
232 * @param width to use.
233 * @return the height based on the width.
235 virtual float GetHeightForWidth( float width ) = 0;
238 * @brief This method is called during size negotiation when a width is required for a given height.
240 * Derived classes should override this if they wish to customize the width returned.
242 * @param height to use.
243 * @return the width based on the width.
245 virtual float GetWidthForHeight( float height ) = 0;
248 * @brief Determine if this actor is dependent on it's children for relayout
250 * @param dimension The dimension(s) to check for
251 * @return Return if the actor is dependent on it's children
253 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS ) = 0;
256 * @brief Virtual method to notify deriving classes that relayout dependencies have been
257 * met and the size for this object is about to be calculated for the given dimension
259 * @param dimension The dimension that is about to be calculated
261 virtual void OnCalculateRelayoutSize( Dimension::Type dimension ) = 0;
264 * @brief Virtual method to notify deriving classes that the size for a dimension
265 * has just been negotiated
267 * @param[in] size The new size for the given dimension
268 * @param[in] dimension The dimension that was just negotiated
270 virtual void OnLayoutNegotiated( float size, Dimension::Type dimension ) = 0;
272 protected: // For derived classes
274 // Flags for the constructor
277 ACTOR_BEHAVIOUR_NONE = 0,
278 DISABLE_SIZE_NEGOTIATION = 1 << 0, ///< True if control does not need size negotiation, i.e. it can be skipped in the algorithm
279 REQUIRES_TOUCH_EVENTS = 1 << 1, ///< True if the OnTouchEvent() callback is required.
280 REQUIRES_HOVER_EVENTS = 1 << 2, ///< True if the OnHoverEvent() callback is required.
281 REQUIRES_MOUSE_WHEEL_EVENTS = 1 << 3, ///< True if the OnMouseWheelEvent() callback is required.
283 LAST_ACTOR_FLAG ///< Special marker for last actor flag
286 static const int ACTOR_FLAG_COUNT = Log< LAST_ACTOR_FLAG - 1 >::value + 1; ///< Value for deriving classes to continue on the flag enum
289 * @brief Create a CustomActorImpl.
290 * @param[in] flags Bitfield of ActorFlags to define behaviour
292 CustomActorImpl( ActorFlags flags );
295 * @brief Request a relayout, which means performing a size negotiation on this actor, its parent and children (and potentially whole scene)
297 * This method can also be called from a derived class every time it needs a different size.
298 * At the end of event processing, the relayout process starts and
299 * all controls which requested Relayout will have their sizes (re)negotiated.
301 * @note RelayoutRequest() can be called multiple times; the size negotiation is still
302 * only performed once, i.e. there is no need to keep track of this in the calling side.
304 void RelayoutRequest();
307 * @brief Calculate the size for a child using the base actor object
309 * @param[in] child The child actor to calculate the size for
310 * @param[in] dimension The dimension to calculate the size for. E.g. width or height.
311 * @return Return the calculated size for the given dimension
313 float CalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension );
316 * @brief Determine if this actor is dependent on it's children for relayout from the base class
318 * @param dimension The dimension(s) to check for
319 * @return Return if the actor is dependent on it's children
321 bool RelayoutDependentOnChildrenBase( Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
323 public: // Not intended for application developers
326 * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
327 * @pre The CustomActorImpl is not already owned.
328 * @param[in] owner The owning object.
330 void Initialize(Internal::CustomActor& owner);
333 * @brief Get the owner.
335 * This method is needed when creating additional handle objects to existing objects.
336 * Owner is the Dali::Internal::CustomActor that owns the implementation of the custom actor
337 * inside core. Creation of a handle to Dali public API Actor requires this pointer.
338 * @return a pointer to the Actor implementation that owns this custom actor implementation
340 Internal::CustomActor* GetOwner() const;
343 * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
344 * @return True if the OnTouchEvent() callback is required.
346 bool RequiresTouchEvents() const;
349 * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
350 * @return True if the OnHoverEvent() callback is required.
352 bool RequiresHoverEvents() const;
355 * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
356 * @return True if the OnMouseWheelEvent() callback is required.
358 bool RequiresMouseWheelEvents() const;
361 * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
362 * @return Return true if relayout is enabled on the custom actor
364 bool IsRelayoutEnabled() const;
368 Internal::CustomActor* mOwner; ///< Internal owner of this custom actor implementation
369 ActorFlags mFlags :ACTOR_FLAG_COUNT; ///< ActorFlags flags to determine behaviour
374 #endif // __DALI_CUSTOM_ACTOR_IMPL_H__