1 #ifndef __DALI_TOOLKIT_CONTROL_IMPL_H__
2 #define __DALI_TOOLKIT_CONTROL_IMPL_H__
5 * Copyright (c) 2014 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/adaptor-framework/style-change.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <dali/public-api/events/long-press-gesture.h>
25 #include <dali/public-api/events/pan-gesture.h>
26 #include <dali/public-api/events/pinch-gesture.h>
27 #include <dali/public-api/events/tap-gesture.h>
28 #include <dali/public-api/object/property-index.h>
29 #include <dali/public-api/object/type-info.h>
32 #include <dali-toolkit/public-api/controls/control.h>
42 namespace Internal DALI_INTERNAL
44 class RelayoutControllerImpl;
45 class KeyInputFocusManager;
48 typedef std::pair< Actor, Vector2 > ActorSizePair; ///< Pair of actor and size
49 typedef std::vector< ActorSizePair > ActorSizeContainer; ///< Container of actors and their sizes
55 * @brief This is the internal base class for all controls.
57 * It will provide some common functionality required by all controls.
58 * Implements ConnectionTrackerInterface so that signals (typically connected to member functions) will
59 * be disconnected automatically when the control is destroyed.
61 class DALI_IMPORT_API Control : public CustomActorImpl, public ConnectionTrackerInterface
68 CONTROL_PROPERTY_START_INDEX = PROPERTY_REGISTRATION_START_INDEX,
69 CONTROL_PROPERTY_END_INDEX = CONTROL_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
72 // Creation & Destruction
75 * @brief Create a new ControlImpl instance that does not require touch by default.
77 * If touch is required then the user can connect to this class' touch signal.
78 * @return A handle to the ControlImpl instance.
80 static Toolkit::Control New();
83 * @brief Virtual destructor.
90 * @copydoc Toolkit::Control::SetSizePolicy()
92 void SetSizePolicy( Toolkit::Control::SizePolicy widthPolicy, Toolkit::Control::SizePolicy heightPolicy );
95 * @copydoc Toolkit::Control::GetSizePolicy()
97 void GetSizePolicy( Toolkit::Control::SizePolicy& widthPolicy, Toolkit::Control::SizePolicy& heightPolicy ) const;
100 * @copydoc Toolkit::Control::SetMinimumSize()
102 void SetMinimumSize( const Vector3& size );
105 * @copydoc Toolkit::Control::GetMinimumSize()
107 const Vector3& GetMinimumSize() const;
110 * @copydoc Toolkit::Control::SetMaximumSize()
112 void SetMaximumSize( const Vector3& size );
115 * @copydoc Toolkit::Control::GetMaximumSize()
117 const Vector3& GetMaximumSize() const;
120 * @copydoc Toolkit::Control::GetNaturalSize()
122 virtual Vector3 GetNaturalSize();
125 * @brief This method is called during size negotiation when a height is required for a given width.
127 * Derived classes should override this if they wish to customize the height returned.
129 * @param width to use.
130 * @return the height based on the width.
132 virtual float GetHeightForWidth( float width );
135 * @brief This method is called during size negotiation when a width is required for a given height.
137 * Derived classes should override this if they wish to customize the width returned.
139 * @param height to use.
140 * @return the width based on the width.
142 virtual float GetWidthForHeight( float height );
145 * @brief Retrieves the current Control's size.
147 * @return The control's size.
149 const Vector3& GetControlSize() const;
152 * @brief Retrieves the Control's size set by the Application / Control.
154 * @return The control's size.
156 const Vector3& GetSizeSet() const;
161 * @copydoc Toolkit::Control::SetKeyInputFocus()
163 void SetKeyInputFocus();
166 * @copydoc Toolkit::Control::HasKeyInputFocus()
168 bool HasKeyInputFocus();
171 * @copydoc Toolkit::Control::ClearKeyInputFocus()
173 void ClearKeyInputFocus();
178 * @brief If deriving classes wish to fine tune pinch gesture
179 * detection then they can access the gesture detector through this
180 * API and modify the detection.
182 * @return The pinch gesture detector.
183 * @pre Pinch detection should have been enabled via EnableGestureDetection().
184 * @see EnableGestureDetection
186 PinchGestureDetector GetPinchGestureDetector() const;
189 * @brief If deriving classes wish to fine tune pan gesture
190 * detection then they can access the gesture detector through this
191 * API and modify the detection.
193 * @return The pan gesture detector.
194 * @pre Pan detection should have been enabled via EnableGestureDetection().
195 * @see EnableGestureDetection
197 PanGestureDetector GetPanGestureDetector() const;
200 * @brief If deriving classes wish to fine tune tap gesture
201 * detection then they can access the gesture detector through this
202 * API and modify the detection.
204 * @return The tap gesture detector.
205 * @pre Tap detection should have been enabled via EnableGestureDetection().
206 * @see EnableGestureDetection
208 TapGestureDetector GetTapGestureDetector() const;
211 * @brief If deriving classes wish to fine tune long press gesture
212 * detection then they can access the gesture detector through this
213 * API and modify the detection.
215 * @return The long press gesture detector.
216 * @pre Long press detection should have been enabled via EnableGestureDetection().
217 * @see EnableGestureDetection
219 LongPressGestureDetector GetLongPressGestureDetector() const;
224 * @copydoc Dali::Toolkit::Control::SetBackgroundColor
226 void SetBackgroundColor( const Vector4& color );
229 * @copydoc Dali::Toolkit::Control::GetBackgroundColor
231 Vector4 GetBackgroundColor() const;
234 * @copydoc Dali::Toolkit::Control::SetBackground
236 void SetBackground( Image image );
239 * @copydoc Dali::Toolkit::Control::ClearBackground
241 void ClearBackground();
244 * @copydoc Dali::Toolkit::Control::GetBackgroundActor
246 Actor GetBackgroundActor() const;
248 // Keyboard Navigation
251 * @brief Sets whether this control supports two dimensional
252 * keyboard navigation (i.e. whether it knows how to handle the
253 * keyboardn focus movement between its child actors).
255 * The control doesn't support it by default.
256 * @param[in] isSupported Whether this control supports two dimensional keyboard navigation.
258 void SetKeyboardNavigationSupport(bool isSupported);
261 * @brief Gets whether this control supports two dimensional keyboard navigation.
263 * @return true if this control supports two dimensional keyboard navigation.
265 bool IsKeyboardNavigationSupported();
267 // Called by Focus Managers
270 * @brief Called by the focus manager and keyboard focus manager to Activate the Control
272 DALI_INTERNAL void Activate();
275 * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
278 * @param[in] gesture The pan gesture.
279 * @return true if the pan gesture has been consumed by this control
281 virtual bool OnAccessibilityPan(PanGesture gesture);
284 * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
287 * @param[in] touchEvent The touch event.
288 * @return true if the touch event has been consumed by this control
290 virtual bool OnAccessibilityTouch(const TouchEvent& touchEvent);
293 * @brief This method should be overridden by deriving classes when they wish to respond
294 * the accessibility up and down action (i.e. value change of slider control).
296 * @param[in] isIncrease Whether the value should be increased or decreased
297 * @return true if the value changed action has been consumed by this control
299 virtual bool OnAccessibilityValueChange(bool isIncrease);
301 // Called by the RelayoutController
304 * @brief Called by the RelayoutController to negotiate the size of a control.
306 * The size allocated by the the algorithm is passed in which the
307 * control must adhere to. A container is passed in as well which
308 * the control should populate with actors it has not / or does not
309 * need to handle in its size negotiation.
311 * @param[in] size The allocated size.
312 * @param[in,out] container The container that holds actors that are fed back into the
313 * RelayoutController algorithm.
315 DALI_INTERNAL void NegotiateSize( const Vector2& size, ActorSizeContainer& container );
320 * @brief Sets whether this control is a focus group for keyboard navigation.
322 * (i.e. the scope of keyboard focus movement
323 * can be limitied to its child actors). The control is not a focus group by default.
324 * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation.
326 void SetAsKeyboardFocusGroup(bool isFocusGroup);
329 * @brief Gets whether this control is a focus group for keyboard navigation.
331 * @return true if this control is set as a focus group for keyboard navigation.
333 bool IsKeyboardFocusGroup();
336 * @brief Gets the next keyboard focusable actor in this control towards the given direction.
338 * A control needs to override this function in order to support two dimensional keyboard navigation.
339 * @param[in] currentFocusedActor The current focused actor.
340 * @param[in] direction The direction to move the focus towards.
341 * @param[in] loopEnabled Whether the focus movement should be looped within the control.
342 * @return the next keyboard focusable actor in this control or an empty handle if no actor can be focused.
344 virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
347 * @brief Informs this control that its chosen focusable actor will be focused.
349 * This allows the application to preform any actions if wishes
350 * before the focus is actually moved to the chosen actor.
352 * @param[in] commitedFocusableActor The commited focusable actor.
354 virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor);
359 * @brief Performs actions as requested using the action name.
361 * @param[in] object The object on which to perform the action.
362 * @param[in] actionName The action to perform.
363 * @param[in] attributes The attributes with which to perfrom this action.
364 * @return true if action has been accepted by this control
366 static bool DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes);
369 * Connects a callback function with the object's signals.
370 * @param[in] object The object providing the signal.
371 * @param[in] tracker Used to disconnect the signal.
372 * @param[in] signalName The signal to connect to.
373 * @param[in] functor A newly allocated FunctorDelegate.
374 * @return True if the signal was connected.
375 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
377 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
380 * @copydoc Dali::Toolkit::Control::KeyEventSignal()
382 Toolkit::Control::KeyEventSignalType& KeyEventSignal();
385 * @brief Called by the KeyInputFocusManager to emit key event signals.
387 * @param[in] event The key event.
388 * @return True if the event was consumed.
390 DALI_INTERNAL bool EmitKeyEventSignal(const KeyEvent& event);
396 // Flags for the constructor
397 enum ControlBehaviour
399 CONTROL_BEHAVIOUR_NONE = 0,
400 REQUIRES_TOUCH_EVENTS = 1<<1, ///< True if the OnTouchEvent() callback is required.
401 REQUIRES_STYLE_CHANGE_SIGNALS = 1<<2, ///< True if needs to monitor style change signals such as theme/font change
402 NO_SIZE_NEGOTIATION = 1<<3, ///< True if control does not need size negotiation, i.e. it can be skipped in the algorithm
403 REQUIRES_HOVER_EVENTS = 1<<4, ///< True if the OnHoverEvent() callback is required.
404 REQUIRES_MOUSE_WHEEL_EVENTS = 1<<5 ///< True if the OnMouseWheelEvent() callback is required.
408 * @brief Create a Control.
410 * @param[in] behaviourFlags Behavioural flags from ControlBehaviour enum
412 Control(ControlBehaviour behaviourFlags);
415 * @brief Second phase initialization.
422 * @brief Allows deriving classes to enable any of the gesture detectors that are available.
424 * Gesture detection can be enabled one at a time or in bitwise format as shown:
426 * EnableGestureDetection(Gesture::Type(Gesture::Pinch | Gesture::Tap | Gesture::Pan));
428 * @param[in] type The gesture type(s) to enable.
430 void EnableGestureDetection(Gesture::Type type);
433 * @brief Allows deriving classes to disable any of the gesture detectors.
435 * Like EnableGestureDetection, this can also be called using bitwise or.
436 * @param[in] type The gesture type(s) to disable.
437 * @see EnableGetureDetection
439 void DisableGestureDetection(Gesture::Type type);
444 * @brief Request a relayout, which means performing a size negotiation on this control, its parent and children (and potentially whole scene)
446 * This method is automatically called from OnStageConnection(), OnChildAdd(),
447 * OnChildRemove(), SetSizePolicy(), SetMinimumSize() and SetMaximumSize().
449 * This method can also be called from a derived class every time it needs a different size.
450 * At the end of event processing, the relayout process starts and
451 * all controls which requested Relayout will have their sizes (re)negotiated.
453 * @note RelayoutRequest() can be called multiple times; the size negotiation is still
454 * only performed once, i.e. there is no need to keep track of this in the calling side.
456 void RelayoutRequest();
459 * @brief Helper method for controls to Relayout their children if
460 * they do not know whether that child is a control or not.
462 * @param[in] actor The actor to relayout.
463 * @param[in] size The size to allocate to the actor.
464 * @param[in,out] container The container that holds actors that have not been allocated a size yet.
466 static void Relayout( Actor actor, const Vector2& size, ActorSizeContainer& container );
470 // For derived classes to override
473 * @brief This method is called after the Control has been initialized.
475 * Derived classes should do any second phase initialization by overriding this method.
477 virtual void OnInitialize();
480 * @brief This method is called when the control is activates.
482 * Derived classes should override this if they wish to be notified when they are activated.
484 virtual void OnActivated();
487 * @brief This method should be overridden by deriving classes when
488 * they wish to be notified when the style manager changes the theme.
490 * @param[in] styleManager The StyleManager object.
492 virtual void OnThemeChange( Toolkit::StyleManager styleManager );
495 * @brief This method should be overridden by deriving classes when
496 * they wish to be notified when the style changes the default font.
498 * @param[in] defaultFontChange Information denoting whether the default font has changed.
499 * @param[in] defaultFontSizeChange Information denoting whether the default font size has changed.
501 virtual void OnFontChange( bool defaultFontChange, bool defaultFontSizeChange );
504 * @brief Called whenever a pinch gesture is detected on this control.
506 * This can be overridden by deriving classes when pinch detection
507 * is enabled. The default behaviour is to scale the control by the
510 * @note If overridden, then the default behaviour will not occur.
511 * @note Pinch detection should be enabled via EnableGestureDetection().
512 * @param[in] pinch The pinch gesture.
513 * @see EnableGestureDetection
515 virtual void OnPinch(const PinchGesture& pinch);
518 * @brief Called whenever a pan gesture is detected on this control.
520 * This should be overridden by deriving classes when pan detection
523 * @note There is no default behaviour with panning.
524 * @note Pan detection should be enabled via EnableGestureDetection().
525 * @param[in] pan The pan gesture.
526 * @see EnableGestureDetection
528 virtual void OnPan( const PanGesture& pan );
531 * @brief Called whenever a tap gesture is detected on this control.
533 * This should be overridden by deriving classes when tap detection
536 * @note There is no default behaviour with a tap.
537 * @note Tap detection should be enabled via EnableGestureDetection().
538 * @param[in] tap The tap gesture.
539 * @see EnableGestureDetection
541 virtual void OnTap( const TapGesture& tap );
544 * @brief Called whenever a long press gesture is detected on this control.
546 * This should be overridden by deriving classes when long press
547 * detection is enabled.
549 * @note There is no default behaviour associated with a long press.
550 * @note Long press detection should be enabled via EnableGestureDetection().
551 * @param[in] longPress The long press gesture.
552 * @see EnableGestureDetection
554 virtual void OnLongPress( const LongPressGesture& longPress );
557 * @brief Called whenever the control is added to the stage.
559 * Could be overridden by derived classes.
561 virtual void OnControlStageConnection();
564 * @brief Called whenever the control is removed from the stage.
566 * Could be overridden by derived classes.
568 virtual void OnControlStageDisconnection();
571 * @brief Called whenever an Actor is added to the control.
573 * Could be overridden by derived classes.
575 * @param[in] child The added actor.
577 virtual void OnControlChildAdd( Actor& child );
580 * @brief Called whenever an Actor is removed from the control.
582 * Could be overridden by derived classes.
584 * @param[in] child The removed actor.
586 virtual void OnControlChildRemove( Actor& child );
589 * @brief Called whenever the Control's size is set.
591 * Could be overridden by derived classes.
593 * @param[in] size The new size.
595 virtual void OnControlSizeSet( const Vector3& size );
598 * @brief Called after the size negotiation has been finished for this control.
600 * The control is expected to assign this given size to itself/its children.
602 * Should be overridden by derived classes if they need to layout
603 * actors differently after certain operations like add or remove
604 * actors, resize or after changing specific properties.
606 * Note! As this function is called from inside the size negotiation algorithm, you cannot
607 * call RequestRelayout (the call would just be ignored)
609 * @param[in] size The allocated size.
610 * @param[in,out] container The control should add actors to this container that it is not able
611 * to allocate a size for.
613 virtual void OnRelayout( const Vector2& size, ActorSizeContainer& container );
616 * @brief Called when the control gains key input focus.
618 * Should be overridden by derived classes if they need to customize what happens when focus is gained.
620 virtual void OnKeyInputFocusGained();
623 * @brief Called when the control loses key input focus.
625 * Should be overridden by derived classes if they need to customize what happens when focus is lost.
627 virtual void OnKeyInputFocusLost();
629 // From CustomActorImpl, derived classes can override these.
632 * @copydoc Dali::CustomActorImpl::OnSizeAnimation(Animation&, const Vector3&)
634 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
637 * @copydoc Dali::CustomActorImpl::OnTouchEvent(const TouchEvent&)
639 virtual bool OnTouchEvent(const TouchEvent& event);
642 * @copydoc Dali::CustomActorImpl::OnHoverEvent(const HoverEvent&)
644 virtual bool OnHoverEvent(const HoverEvent& event);
647 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
649 virtual bool OnKeyEvent(const KeyEvent& event);
652 * @copydoc Dali::CustomActorImpl::OnMouseWheelEvent(const MouseWheelEvent&)
654 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event);
657 * @copydoc Dali::CustomActorImpl::GetChildByAlias(const std::string& actorAlias)
659 virtual Actor GetChildByAlias(const std::string& actorAlias);
661 // From CustomActorImpl, derived classes should NOT override these.
664 * @brief Sends a request to relayout this control.
666 * The control will be relaid out after the
667 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted.
669 * It calls OnControlStageConnection() to notify derived classes.
671 * @see Dali::CustomActorImpl::OnStageConnection()
673 virtual void OnStageConnection();
676 * @brief Calls OnControlStageDisconnection() to notify derived classed.
678 * @see Dali::CustomActorImpl::OnStageDisconnection()
680 virtual void OnStageDisconnection();
683 * @brief Sends a request to relayout this control.
685 * The control will be relaid out after the
686 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
687 * calls OnControlChildAdd() to notify derived classes.
689 * @note This method shouldn't be overridden by derived classes.
691 * @param[in] child The added actor.
693 * @see Dali::CustomActorImpl::OnChildAdd(Actor&)
695 virtual void OnChildAdd(Actor& child);
698 * @brief Sends a request to relayout this control.
700 * The control will be relaid out after the
701 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
702 * calls OnControlChildRemove() to notify derived classes.
704 * @note This method shouldn't be overridden by derived classes.
706 * @param[in] child The removed actor.
708 * @see Dali::CustomActorImpl::OnChildRemove(Actor&)
710 virtual void OnChildRemove(Actor& child);
713 * @brief It stores the size set by size negotiation and relayout.
715 * It also keeps a backup of the size set through the Actor's API used in the size negotiation.
716 * It calls the OnControlSizeSet() to notify derived classes.
718 * @param[in] targetSize The new size.
720 * @see Dali::CustomActorImpl::OnSizeSet(const Vector3&)
722 virtual void OnSizeSet(const Vector3& targetSize);
724 // From ConnectionTrackerInterface
727 * @copydoc ConnectionTrackerInterface::SignalConnected
729 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
732 * @copydoc ConnectionTrackerInterface::SignalDisconnected
734 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
739 * @brief This method is the callback for the StyleChangeSignal from StyleManager
741 * @param[in] styleManager The StyleManager Object
742 * @param[in] change Information denoting what has changed.
744 DALI_INTERNAL void DoStyleChange( Toolkit::StyleManager styleManager, StyleChange change );
749 DALI_INTERNAL Control(const Control&);
750 DALI_INTERNAL Control& operator=(const Control&);
755 friend class Internal::KeyInputFocusManager; ///< KeyInputFocusManager needs to call several methods which are private. // TODO: Remove
758 } // namespace Internal
760 } // namespace Toolkit
764 #endif // __DALI_TOOLKIT_CONTROL_IMPL_H__