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;
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
63 class Extension; ///< Forward declare future extension interface
66 * @brief Virtual destructor.
68 virtual ~CustomActorImpl();
71 * @brief Used by derived CustomActorImpl instances, to access the public Actor interface.
73 * @return A pointer to self, or an uninitialized pointer if the CustomActorImpl is not owned.
75 CustomActor Self() const;
78 * @brief Called after the actor has been connected to the stage.
80 * When an actor is connected, it will be directly or indirectly parented to the root Actor.
81 * @note The root Actor is provided automatically by Dali::Stage, and is always considered to be connected.
83 * @note When the parent of a set of actors is connected to the stage, then all of the children
84 * will received this callback.
86 * For the following actor tree, the callback order will be A, B, D, E, C, and finally F.
94 * @param[in] depth The depth in the hierarchy for the actor
96 virtual void OnStageConnection( int depth ) = 0;
99 * @brief Called after the actor has been disconnected from the stage.
101 * If an actor is disconnected it either has no parent, or is parented to a disconnected actor.
103 * @note When the parent of a set of actors is disconnected to the stage, then all of the children
104 * will received this callback, starting with the leaf actors.
106 * For the following actor tree, the callback order will be D, E, B, F, C, and finally A.
114 virtual void OnStageDisconnection() = 0;
117 * @brief Called after a child has been added to the owning actor.
119 * @param[in] child The child which has been added.
121 virtual void OnChildAdd(Actor& child) = 0;
124 * @brief Called after a child has been removed from the owning actor.
126 * @param[in] child The child being removed.
128 virtual void OnChildRemove(Actor& child) = 0;
131 * @brief Called when the owning actor property is set.
133 * @param[in] index The Property index that was set.
134 * @param[in] propertyValue The value to set.
136 virtual void OnPropertySet( Property::Index index, Property::Value propertyValue );
139 * @brief Called when the owning actor's size is set e.g. using Actor::SetSize().
141 * @param[in] targetSize The target size. Note that this target size may not match the size returned via Actor::GetSize().
143 virtual void OnSizeSet(const Vector3& targetSize) = 0;
146 * @brief Called when the owning actor's size is animated e.g. using Animation::AnimateTo( Property( actor, Actor::Property::SIZE ), ... ).
148 * @param[in] animation The object which is animating the owning actor.
149 * @param[in] targetSize The target size. Note that this target size may not match the size returned via Actor::GetSize().
151 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize) = 0;
154 * @brief Called after a touch-event is received by the owning actor.
156 * @note This must be enabled during construction; see CustomActorImpl::CustomActorImpl(bool)
157 * @param[in] event The touch event.
158 * @return True if the event should be consumed.
160 virtual bool OnTouchEvent(const TouchEvent& event) = 0;
163 * @brief Called after a hover-event is received by the owning actor.
165 * @note This must be enabled during construction; see CustomActorImpl::SetRequiresHoverEvents(bool)
166 * @param[in] event The hover event.
167 * @return True if the event should be consumed.
169 virtual bool OnHoverEvent(const HoverEvent& event) = 0;
172 * @brief Called after a key-event is received by the actor that has had its focus set.
174 * @param[in] event the Key Event
175 * @return True if the event should be consumed.
177 virtual bool OnKeyEvent(const KeyEvent& event) = 0;
180 * @brief Called after a wheel-event is received by the owning actor.
182 * @note This must be enabled during construction; see CustomActorImpl::SetRequiresWheelEvents(bool)
183 * @param[in] event The wheel event.
184 * @return True if the event should be consumed.
186 virtual bool OnWheelEvent(const WheelEvent& event) = 0;
189 * @brief Called after the size negotiation has been finished for this control.
191 * The control is expected to assign this given size to itself/its children.
193 * Should be overridden by derived classes if they need to layout
194 * actors differently after certain operations like add or remove
195 * actors, resize or after changing specific properties.
197 * Note! As this function is called from inside the size negotiation algorithm, you cannot
198 * call RequestRelayout (the call would just be ignored)
200 * @param[in] size The allocated size.
201 * @param[in,out] container The control should add actors to this container that it is not able
202 * to allocate a size for.
204 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container ) = 0;
207 * @brief Notification for deriving classes
209 * @param[in] policy The policy being set
210 * @param[in] dimension The dimension the policy is being set for
212 virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension ) = 0;
215 * Return the natural size of the actor
217 * @return The actor's natural size
219 virtual Vector3 GetNaturalSize() = 0;
222 * @brief Calculate the size for a child
224 * @param[in] child The child actor to calculate the size for
225 * @param[in] dimension The dimension to calculate the size for. E.g. width or height.
226 * @return Return the calculated size for the given dimension
228 virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension ) = 0;
231 * @brief This method is called during size negotiation when a height is required for a given width.
233 * Derived classes should override this if they wish to customize the height returned.
235 * @param width to use.
236 * @return the height based on the width.
238 virtual float GetHeightForWidth( float width ) = 0;
241 * @brief This method is called during size negotiation when a width is required for a given height.
243 * Derived classes should override this if they wish to customize the width returned.
245 * @param height to use.
246 * @return the width based on the width.
248 virtual float GetWidthForHeight( float height ) = 0;
251 * @brief Determine if this actor is dependent on it's children for relayout
253 * @param dimension The dimension(s) to check for
254 * @return Return if the actor is dependent on it's children
256 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS ) = 0;
259 * @brief Virtual method to notify deriving classes that relayout dependencies have been
260 * met and the size for this object is about to be calculated for the given dimension
262 * @param dimension The dimension that is about to be calculated
264 virtual void OnCalculateRelayoutSize( Dimension::Type dimension ) = 0;
267 * @brief Virtual method to notify deriving classes that the size for a dimension
268 * has just been negotiated
270 * @param[in] size The new size for the given dimension
271 * @param[in] dimension The dimension that was just negotiated
273 virtual void OnLayoutNegotiated( float size, Dimension::Type dimension ) = 0;
276 * Retrieve the extension for this control
278 * @return The extension if available, NULL otherwise
280 virtual Extension* GetExtension()
285 protected: // For derived classes
287 // Flags for the constructor
290 ACTOR_BEHAVIOUR_NONE = 0,
291 DISABLE_SIZE_NEGOTIATION = 1 << 0, ///< True if control does not need size negotiation, i.e. it can be skipped in the algorithm
292 REQUIRES_TOUCH_EVENTS = 1 << 1, ///< True if the OnTouchEvent() callback is required.
293 REQUIRES_HOVER_EVENTS = 1 << 2, ///< True if the OnHoverEvent() callback is required.
294 REQUIRES_WHEEL_EVENTS = 1 << 3, ///< True if the OnWheelEvent() callback is required.
296 LAST_ACTOR_FLAG ///< Special marker for last actor flag
299 static const int ACTOR_FLAG_COUNT = Log< LAST_ACTOR_FLAG - 1 >::value + 1; ///< Value for deriving classes to continue on the flag enum
302 * @brief Create a CustomActorImpl.
303 * @param[in] flags Bitfield of ActorFlags to define behaviour
305 CustomActorImpl( ActorFlags flags );
307 // Size negotiation helpers
310 * @brief Request a relayout, which means performing a size negotiation on this actor, its parent and children (and potentially whole scene)
312 * This method can also be called from a derived class every time it needs a different size.
313 * At the end of event processing, the relayout process starts and
314 * all controls which requested Relayout will have their sizes (re)negotiated.
316 * @note RelayoutRequest() can be called multiple times; the size negotiation is still
317 * only performed once, i.e. there is no need to keep track of this in the calling side.
319 void RelayoutRequest();
322 * @brief provides the Actor implementation of GetHeightForWidth
323 * @param width to use.
324 * @return the height based on the width.
326 float GetHeightForWidthBase( float width );
329 * @brief provides the Actor implementation of GetWidthForHeight
330 * @param height to use.
331 * @return the width based on the height.
333 float GetWidthForHeightBase( float height );
336 * @brief Calculate the size for a child using the base actor object
338 * @param[in] child The child actor to calculate the size for
339 * @param[in] dimension The dimension to calculate the size for. E.g. width or height.
340 * @return Return the calculated size for the given dimension
342 float CalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension );
345 * @brief Determine if this actor is dependent on it's children for relayout from the base class
347 * @param dimension The dimension(s) to check for
348 * @return Return if the actor is dependent on it's children
350 bool RelayoutDependentOnChildrenBase( Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
352 public: // Not intended for application developers
355 * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
356 * @pre The CustomActorImpl is not already owned.
357 * @param[in] owner The owning object.
359 void Initialize(Internal::CustomActor& owner);
362 * @brief Get the owner.
364 * This method is needed when creating additional handle objects to existing objects.
365 * Owner is the Dali::Internal::CustomActor that owns the implementation of the custom actor
366 * inside core. Creation of a handle to Dali public API Actor requires this pointer.
367 * @return a pointer to the Actor implementation that owns this custom actor implementation
369 Internal::CustomActor* GetOwner() const;
372 * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
373 * @return True if the OnTouchEvent() callback is required.
375 bool RequiresTouchEvents() const;
378 * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
379 * @return True if the OnHoverEvent() callback is required.
381 bool RequiresHoverEvents() const;
384 * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
385 * @return True if the OnWheelEvent() callback is required.
387 bool RequiresWheelEvents() const;
390 * @brief Called when ownership of the CustomActorImpl is passed to a CustomActor.
391 * @return Return true if relayout is enabled on the custom actor
393 bool IsRelayoutEnabled() const;
397 Internal::CustomActor* mOwner; ///< Internal owner of this custom actor implementation
398 ActorFlags mFlags :ACTOR_FLAG_COUNT; ///< ActorFlags flags to determine behaviour
403 #endif // __DALI_CUSTOM_ACTOR_IMPL_H__