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 * @addtogroup CAPI_DALI_TOOLKIT_CONTROLS_MODULE
27 #include <dali-toolkit/public-api/controls/control.h>
29 namespace Dali DALI_IMPORT_API
37 namespace Internal DALI_INTERNAL
39 class RelayoutControllerImpl;
40 class KeyInputFocusManager;
43 typedef std::pair< Actor, Vector2 > ActorSizePair; ///< Pair of actor and size
44 typedef std::vector< ActorSizePair > ActorSizeContainer; ///< Container of actors and their sizes
50 * @brief This is the internal base class for all controls.
52 * It will provide some common functionality required by all controls.
53 * Implements ConnectionTrackerInterface so that signals (typically connected to member functions) will
54 * be disconnected automatically when the control is destroyed.
56 class DALI_IMPORT_API Control : public CustomActorImpl, public ConnectionTrackerInterface
63 CONTROL_PROPERTY_START_INDEX = PROPERTY_REGISTRATION_START_INDEX,
64 CONTROL_PROPERTY_END_INDEX = CONTROL_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
70 * @brief Create a new ControlImpl instance that does not require touch by default.
72 * If touch is required then the user can connect to this class' touch signal.
73 * @return A handle to the ConntrolImpl instance.
75 static Toolkit::Control New();
80 * @brief Virtual destructor.
87 * @brief This method should be overridden by deriving classes when they wish to be notified when they
90 virtual void OnActivated() { }
93 * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
96 * @param[in] gesture The pan gesture.
97 * @return true if the pan gesture has been consumed by this control
99 virtual bool OnAccessibilityPan(PanGesture gesture);
102 * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
105 * @param[in] touchEvent The touch event.
106 * @return true if the touch event has been consumed by this control
108 virtual bool OnAccessibilityTouch(const TouchEvent& touchEvent);
111 * @brief This method should be overridden by deriving classes when they wish to respond
112 * the accessibility up and down action (i.e. value change of slider control).
114 * @param[in] isIncrease Whether the value should be increased or decreased
115 * @return true if the value changed action has been consumed by this control
117 virtual bool OnAccessibilityValueChange(bool isIncrease);
120 * @brief Sets whether this control supports two dimensional
121 * keyboard navigation (i.e. whether it knows how to handle the
122 * keyboardn focus movement between its child actors).
124 * The control doesn't support it by default.
125 * @param[in] isSupported Whether this control supports two dimensional keyboard navigation.
127 void SetKeyboardNavigationSupport(bool isSupported);
130 * @brief Gets whether this control supports two dimensional keyboard navigation.
132 * @return true if this control supports two dimensional keyboard navigation.
134 bool IsKeyboardNavigationSupported();
137 * @brief Sets whether this control is a focus group for keyboard navigation.
139 * (i.e. the scope of keyboard focus movement
140 * can be limitied to its child actors). The control is not a focus group by default.
141 * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation.
143 void SetAsKeyboardFocusGroup(bool isFocusGroup);
146 * @brief Gets whether this control is a focus group for keyboard navigation.
148 * @return true if this control is set as a focus group for keyboard navigation.
150 bool IsKeyboardFocusGroup();
153 * @brief Gets the next keyboard focusable actor in this control towards the given direction.
155 * A control needs to override this function in order to support two dimensional keyboard navigation.
156 * @param[in] currentFocusedActor The current focused actor.
157 * @param[in] direction The direction to move the focus towards.
158 * @param[in] loopEnabled Whether the focus movement should be looped within the control.
159 * @return the next keyboard focusable actor in this control or an empty handle if no actor can be focused.
161 virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
164 * @brief Informs this control that its chosen focusable actor will be focused.
166 * This allows the application to preform any actions if wishes
167 * before the focus is actually moved to the chosen actor.
169 * @param[in] commitedFocusableActor The commited focusable actor.
171 virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor) { }
174 * @brief Performs actions as requested using the action name.
176 * @param[in] object The object on which to perform the action.
177 * @param[in] actionName The action to perform.
178 * @param[in] attributes The attributes with which to perfrom this action.
179 * @return true if action has been accepted by this control
181 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
184 * @brief If deriving classes wish to fine tune pinch gesture
185 * detection then they can access the gesture detector through this
186 * API and modify the detection.
188 * @return The pinch gesture detector.
189 * @pre Pinch detection should have been enabled via EnableGestureDetection().
190 * @see EnableGestureDetection
192 PinchGestureDetector GetPinchGestureDetector() const;
195 * @brief If deriving classes wish to fine tune pan gesture
196 * detection then they can access the gesture detector through this
197 * API and modify the detection.
199 * @return The pan gesture detector.
200 * @pre Pan detection should have been enabled via EnableGestureDetection().
201 * @see EnableGestureDetection
203 PanGestureDetector GetPanGestureDetector() const;
206 * @brief If deriving classes wish to fine tune tap gesture
207 * detection then they can access the gesture detector through this
208 * API and modify the detection.
210 * @return The tap gesture detector.
211 * @pre Tap detection should have been enabled via EnableGestureDetection().
212 * @see EnableGestureDetection
214 TapGestureDetector GetTapGestureDetector() const;
217 * @brief If deriving classes wish to fine tune long press gesture
218 * detection then they can access the gesture detector through this
219 * API and modify the detection.
221 * @return The long press gesture detector.
222 * @pre Long press detection should have been enabled via EnableGestureDetection().
223 * @see EnableGestureDetection
225 LongPressGestureDetector GetLongPressGestureDetector() const;
230 * @copydoc Dali::Toolkit::Control::SetBackgroundColor
232 void SetBackgroundColor( const Vector4& color );
235 * @copydoc Dali::Toolkit::Control::GetBackgroundColor
237 Vector4 GetBackgroundColor() const;
240 * @copydoc Dali::Toolkit::Control::SetBackground
242 void SetBackground( Image image );
245 * @copydoc Dali::Toolkit::Control::ClearBackground
247 void ClearBackground();
250 * @copydoc Dali::Toolkit::Control::GetBackgroundActor
252 Actor GetBackgroundActor() const;
257 * @copydoc Dali::Toolkit::Control::KeyEventSignal()
259 Toolkit::Control::KeyEventSignalV2& KeyEventSignal();
266 * @brief Second phase initialization.
273 * @brief Allows deriving classes to enable any of the gesture detectors that are available.
275 * Gesture detection can be enabled one at a time or in bitwise format as shown:
277 * EnableGestureDetection(Gesture::Type(Gesture::Pinch | Gesture::Tap | Gesture::Pan));
279 * @param[in] type The gesture type(s) to enable.
281 void EnableGestureDetection(Gesture::Type type);
284 * @brief Allows deriving classes to disable any of the gesture detectors.
286 * Like EnableGestureDetection, this can also be called using bitwise or.
287 * @param[in] type The gesture type(s) to disable.
288 * @see EnableGetureDetection
290 void DisableGestureDetection(Gesture::Type type);
292 private: // For derived classes to override
295 * @brief This method is called after the Control has been initialized.
297 * Derived classes should do any second phase initialization by
298 * overriding this method.
300 virtual void OnInitialize() { }
303 * @brief This method should be overridden by deriving classes when
304 * they wish to be notified when the style manager changes the theme.
306 * @param[in] styleManager The StyleManager object.
308 virtual void OnThemeChange( Toolkit::StyleManager styleManager );
311 * @brief This method should be overridden by deriving classes when
312 * they wish to be notified when the style changes the default font.
314 * @param[in] defaultFontChange Information denoting whether the default font has changed.
315 * @param[in] defaultFontSizeChange Information denoting whether the default font size has changed.
317 virtual void OnFontChange( bool defaultFontChange, bool defaultFontSizeChange ){ }
320 * @deprecated Use OnFontChange() instead.
321 * Before the using of StyleManager, the StyleChange only deals with font change.
323 * @brief This method should be overridden by deriving classes when
324 * they wish to be notified when the style changes.
326 * @param[in] change Information denoting what has changed.
328 virtual void OnStyleChange( StyleChange change ) { }
331 * @brief Called whenever a pinch gesture is detected on this control.
333 * This can be overridden by deriving classes when pinch detection
334 * is enabled. The default behaviour is to scale the control by the
337 * @note If overridden, then the default behaviour will not occur.
338 * @note Pinch detection should be enabled via EnableGestureDetection().
339 * @param[in] pinch The pinch gesture.
340 * @see EnableGestureDetection
342 virtual void OnPinch(PinchGesture pinch);
345 * @brief Called whenever a pan gesture is detected on this control.
347 * This should be overridden by deriving classes when pan detection
350 * @note There is no default behaviour with panning.
351 * @note Pan detection should be enabled via EnableGestureDetection().
352 * @param[in] pan The pan gesture.
353 * @see EnableGestureDetection
355 virtual void OnPan(PanGesture pan) { }
358 * @brief Called whenever a tap gesture is detected on this control.
360 * This should be overridden by deriving classes when tap detection
363 * @note There is no default behaviour with a tap.
364 * @note Tap detection should be enabled via EnableGestureDetection().
365 * @param[in] tap The tap gesture.
366 * @see EnableGestureDetection
368 virtual void OnTap(TapGesture tap) { }
371 * @brief Called whenever a long press gesture is detected on this control.
373 * This should be overridden by deriving classes when long press
374 * detection is enabled.
376 * @note There is no default behaviour associated with a long press.
377 * @note Long press detection should be enabled via EnableGestureDetection().
378 * @param[in] longPress The long press gesture.
379 * @see EnableGestureDetection
381 virtual void OnLongPress(LongPressGesture longPress) { }
384 * @brief Called whenever the control is added to the stage.
386 * Could be overridden by derived classes.
388 virtual void OnControlStageConnection() { }
391 * @brief Called whenever the control is removed from the stage.
393 * Could be overridden by derived classes.
395 virtual void OnControlStageDisconnection() { }
398 * @brief Called whenever an Actor is added to the control.
400 * Could be overridden by derived classes.
402 * @param[in] child The added actor.
404 virtual void OnControlChildAdd( Actor& child ) { }
407 * @brief Called whenever an Actor is removed from the control.
409 * Could be overridden by derived classes.
411 * @param[in] child The removed actor.
413 virtual void OnControlChildRemove( Actor& child ) { }
416 * @brief Called whenever the Control's size is set.
418 * Could be overridden by derived classes.
420 * @param[in] size The new size.
422 virtual void OnControlSizeSet( const Vector3& size ) { }
425 * @brief Called after the Dali::Stage::SignalMessageQueueFlushed()
426 * signal is emitted if this control requested to be relaid-out.
428 * Should be overridden by derived classes if they need to layout
429 * actors differently after certain operations like add or remove
430 * actors, resize or after changing especific properties.
432 * @param[in] size The allocated size.
433 * @param[in,out] container The control should add actors to this container that it is not able
434 * to allocate a size for.
436 virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
438 private: // From CustomActorImpl, derived classes can override these.
441 * @brief Sends a request to relayout this control.
443 * The control will be relaid out after the
444 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted.
446 * It calls OnControlStageConnection() to notify derived classes.
448 * @see Dali::CustomActorImpl::OnStageConnection()
450 virtual void OnStageConnection();
453 * @brief Calls OnControlStageDisconnection() to notify derived classed.
455 * @see Dali::CustomActorImpl::OnStageDisconnection()
457 virtual void OnStageDisconnection();
460 * @brief Sends a request to relayout this control.
462 * The control will be relaid out after the
463 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
464 * calls OnControlChildAdd() to notify derived classes.
466 * @note This method shouldn't be overridden by derived classes.
468 * @param[in] child The added actor.
470 * @see Dali::CustomActorImpl::OnChildAdd(Actor&)
472 virtual void OnChildAdd(Actor& child);
475 * @brief Sends a request to relayout this control.
477 * The control will be relaid out after the
478 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
479 * calls OnControlChildRemove() to notify derived classes.
481 * @note This method shouldn't be overridden by derived classes.
483 * @param[in] child The removed actor.
485 * @see Dali::CustomActorImpl::OnChildRemove(Actor&)
487 virtual void OnChildRemove(Actor& child);
490 * @brief It stores the size set by size negotiation and relayout.
492 * It also keeps a backup of the size set through the Actor's API used in the size negotiation.
493 * It calls the OnControlSizeSet() to notify derived classes.
495 * @param[in] targetSize The new size.
497 * @see Dali::CustomActorImpl::OnSizeSet(const Vector3&)
499 virtual void OnSizeSet(const Vector3& targetSize);
502 * @copydoc Dali::CustomActorImpl::OnSizeAnimation(Animation&, const Vector3&)
504 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
507 * @copydoc Dali::CustomActorImpl::OnTouchEvent(const TouchEvent&)
509 virtual bool OnTouchEvent(const TouchEvent& event);
512 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
514 virtual bool OnKeyEvent(const KeyEvent& event);
517 * @copydoc Dali::CustomActorImpl::OnMouseWheelEvent(const MouseWheelEvent&)
519 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event);
522 * @copydoc Dali::CustomActorImpl::OnKeyInputFocusGained()
524 virtual void OnKeyInputFocusGained();
527 * @copydoc Dali::CustomActorImpl::OnKeyInputFocusLost()
529 virtual void OnKeyInputFocusLost();
532 * @copydoc Dali::CustomActorImpl::GetChildByAlias(const std::string& actorAlias)
534 virtual Actor GetChildByAlias(const std::string& actorAlias);
539 * @brief This method is the callback for the StyleChangeSignal from StyleManager
541 * @param[in] styleManager The StyleManager Object
542 * @param[in] change Information denoting what has changed.
544 void DoStyleChange( Toolkit::StyleManager styleManager, StyleChange change );
546 protected: // Construction
548 // Flags for the constructor
549 enum ControlBehaviour
551 CONTROL_BEHAVIOUR_NONE = 0x0,
552 REQUIRES_TOUCH_EVENTS = 0x1, ///< True if the OnTouchEvent() callback is required.
553 REQUIRES_STYLE_CHANGE_SIGNALS = 0x2 ///< True if needs to monitor style change signals such as theme/font change
557 * @deprecated Use the constructor taking flags instead
558 * @brief Create a Control.
560 * @param[in] requiresTouchEvents True if the OnTouchEvent() callback is required.
562 Control(bool requiresTouchEvents);
565 * @brief Create a Control.
567 * @param[in] behaviourFlags Behavioural flags from ControlBehaviour enum
569 Control(ControlBehaviour behaviourFlags);
576 * @copydoc Toolkit::Control::SetSizePolicy()
578 void SetSizePolicy( Toolkit::Control::SizePolicy widthPolicy, Toolkit::Control::SizePolicy heightPolicy );
581 * @copydoc Toolkit::Control::GetSizePolicy()
583 void GetSizePolicy( Toolkit::Control::SizePolicy& widthPolicy, Toolkit::Control::SizePolicy& heightPolicy ) const;
586 * @copydoc Toolkit::Control::SetMinimumSize()
588 void SetMinimumSize( const Vector3& size );
591 * @copydoc Toolkit::Control::GetMinimumSize()
593 const Vector3& GetMinimumSize() const;
596 * @copydoc Toolkit::Control::SetMaximumSize()
598 void SetMaximumSize( const Vector3& size );
601 * @copydoc Toolkit::Control::GetMaximumSize()
603 const Vector3& GetMaximumSize() const;
606 * @copydoc Toolkit::Control::GetNaturalSize()
608 virtual Vector3 GetNaturalSize();
611 * @copydoc Toolkit::Control::GetHeightForWidth()
613 virtual float GetHeightForWidth( float width );
616 * @copydoc Toolkit::Control::GetWidthForHeight()
618 virtual float GetWidthForHeight( float height );
621 * @brief Retrieves the current Control's size.
623 * @return The control's size.
625 const Vector3& GetControlSize() const;
628 * @brief Retrieves the Control's size set by the Application / Control.
630 * @return The control's size.
632 const Vector3& GetSizeSet() const;
637 * @copydoc Toolkit::Control::SetKeyInputFocus()
639 void SetKeyInputFocus();
642 * @copydoc Toolkit::Control::HasKeyInputFocus()
644 bool HasKeyInputFocus();
647 * @copydoc Toolkit::Control::ClearKeyInputFocus()
649 void ClearKeyInputFocus();
652 * @copydoc ConnectionTrackerInterface::SignalConnected
654 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
657 * @copydoc ConnectionTrackerInterface::SignalDisconnected
659 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
662 * @copydoc ConnectionTrackerInterface::GetConnectionCount
664 virtual std::size_t GetConnectionCount() const;
669 * @brief Sends a request to be relaid-out.
671 * This method is called from OnStageConnection(), OnChildAdd(),
672 * OnChildRemove(), SetSizePolicy(), SetMinimumSize() and
675 * This method could also be called from derived classes every time
676 * a control's poperty change and it needs to be relaid-out. After
677 * the Dali::Stage::SignalMessageQueueFlushed() is emitted a
678 * relayout process starts and all controls which called this method
679 * will be relaid-out.
681 * @note RelayoutRequest() only sends a request per Control before
682 * the Dali::Stage::SignalMessageQueueFlushed() signal is
683 * emitted. That means a control will be relaid-out only once, even
684 * if more than one request is sent between two consecutive signals.
686 void RelayoutRequest();
689 * @brief Helper method for controls to Relayout their children if
690 * they do not know whether that child is a control or not.
692 * @param[in] actor The actor to relayout.
693 * @param[in] size The size to allocate to the actor.
694 * @param[in,out] container The container that holds actors that have not been allocated a size yet.
696 static void Relayout( Actor actor, Vector2 size, ActorSizeContainer& container );
698 private: // Used by the RelayoutController
701 * @brief Called by the RelayoutController to negotiate the size of a control.
703 * The size allocated by the the algorithm is passed in which the
704 * control must adhere to. A container is passed in as well which
705 * the control should populate with actors it has not / or does not
706 * need to handle in its size negotiation.
708 * @param[in] size The allocated size.
709 * @param[in,out] container The container that holds actors that are fed back into the
710 * RelayoutController algorithm.
712 void NegotiateSize( Vector2 size, ActorSizeContainer& container );
717 * @brief Called by NegotiateSize when the size to allocate to the control has been calculated.
719 * It calls the OnRelaidOut() method which can be overridden by derived classes.
721 * @param[in] size The allocated size.
722 * @param[in,out] container The control should add actors to this container that it is not able
723 * to allocate a size for.
725 void Relayout( Vector2 size, ActorSizeContainer& container );
728 * @brief Used by the KeyInputFocusManager to emit key event signals.
730 * @param[in] event The key event.
731 * @return True if the event was consumed.
733 bool EmitKeyEventSignal(const KeyEvent& event);
740 Control(const Control&);
741 Control& operator=(const Control&);
746 friend class Internal::RelayoutControllerImpl; ///< Relayout controller needs to call Relayout() which is private.
747 friend class Internal::KeyInputFocusManager; ///< KeyInputFocusManager needs to call which is private.
750 } // namespace Internal
752 typedef Internal::Control ControlImpl; ///< @deprecated, Use Internal::Control
754 } // namespace Toolkit
761 #endif // __DALI_TOOLKIT_CONTROL_IMPL_H__