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 Flora License, Version 1.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://floralicense.org/license/
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.
21 * @addtogroup CAPI_DALI_TOOLKIT_CONTROLS_MODULE
26 #include <dali-toolkit/public-api/controls/control.h>
28 namespace Dali DALI_IMPORT_API
36 namespace Internal DALI_INTERNAL
38 class RelayoutControllerImpl;
39 class KeyInputFocusManager;
42 typedef std::pair< Actor, Vector2 > ActorSizePair; ///< Pair of actor and size
43 typedef std::vector< ActorSizePair > ActorSizeContainer; ///< Container of actors and their sizes
49 * @brief This is the internal base class for all controls.
51 * It will provide some common functionality required by all controls.
52 * Implements ConnectionTrackerInterface so that signals (typically connected to member functions) will
53 * be disconnected automatically when the control is destroyed.
55 class DALI_IMPORT_API Control : public CustomActorImpl, public ConnectionTrackerInterface
62 CONTROL_PROPERTY_START_INDEX = PROPERTY_REGISTRATION_START_INDEX,
63 CONTROL_PROPERTY_END_INDEX = CONTROL_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
69 * @brief Create a new ControlImpl instance that does not require touch by default.
71 * If touch is required then the user can connect to this class' touch signal.
72 * @return A handle to the ConntrolImpl instance.
74 static Toolkit::Control New();
79 * @brief Virtual destructor.
86 * @brief This method should be overridden by deriving classes when they wish to be notified when they
89 virtual void OnActivated() { }
92 * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
95 * @param[in] gesture The pan gesture.
96 * @return true if the pan gesture has been consumed by this control
98 virtual bool OnAccessibilityPan(PanGesture gesture);
101 * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
104 * @param[in] touchEvent The touch event.
105 * @return true if the touch event has been consumed by this control
107 virtual bool OnAccessibilityTouch(const TouchEvent& touchEvent);
110 * @brief This method should be overridden by deriving classes when they wish to respond
111 * the accessibility up and down action (i.e. value change of slider control).
113 * @param[in] isIncrease Whether the value should be increased or decreased
114 * @return true if the value changed action has been consumed by this control
116 virtual bool OnAccessibilityValueChange(bool isIncrease);
119 * @brief Sets whether this control supports two dimensional
120 * keyboard navigation (i.e. whether it knows how to handle the
121 * keyboardn focus movement between its child actors).
123 * The control doesn't support it by default.
124 * @param[in] isSupported Whether this control supports two dimensional keyboard navigation.
126 void SetKeyboardNavigationSupport(bool isSupported);
129 * @brief Gets whether this control supports two dimensional keyboard navigation.
131 * @return true if this control supports two dimensional keyboard navigation.
133 bool IsKeyboardNavigationSupported();
136 * @brief Sets whether this control is a focus group for keyboard navigation.
138 * (i.e. the scope of keyboard focus movement
139 * can be limitied to its child actors). The control is not a focus group by default.
140 * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation.
142 void SetAsKeyboardFocusGroup(bool isFocusGroup);
145 * @brief Gets whether this control is a focus group for keyboard navigation.
147 * @return true if this control is set as a focus group for keyboard navigation.
149 bool IsKeyboardFocusGroup();
152 * @brief Gets the next keyboard focusable actor in this control towards the given direction.
154 * A control needs to override this function in order to support two dimensional keyboard navigation.
155 * @param[in] currentFocusedActor The current focused actor.
156 * @param[in] direction The direction to move the focus towards.
157 * @param[in] loopEnabled Whether the focus movement should be looped within the control.
158 * @return the next keyboard focusable actor in this control or an empty handle if no actor can be focused.
160 virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
163 * @brief Informs this control that its chosen focusable actor will be focused.
165 * This allows the application to preform any actions if wishes
166 * before the focus is actually moved to the chosen actor.
168 * @param[in] commitedFocusableActor The commited focusable actor.
170 virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor) { }
173 * @brief Performs actions as requested using the action name.
175 * @param[in] object The object on which to perform the action.
176 * @param[in] actionName The action to perform.
177 * @param[in] attributes The attributes with which to perfrom this action.
178 * @return true if action has been accepted by this control
180 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
183 * @brief If deriving classes wish to fine tune pinch gesture
184 * detection then they can access the gesture detector through this
185 * API and modify the detection.
187 * @return The pinch gesture detector.
188 * @pre Pinch detection should have been enabled via EnableGestureDetection().
189 * @see EnableGestureDetection
191 PinchGestureDetector GetPinchGestureDetector() const;
194 * @brief If deriving classes wish to fine tune pan gesture
195 * detection then they can access the gesture detector through this
196 * API and modify the detection.
198 * @return The pan gesture detector.
199 * @pre Pan detection should have been enabled via EnableGestureDetection().
200 * @see EnableGestureDetection
202 PanGestureDetector GetPanGestureDetector() const;
205 * @brief If deriving classes wish to fine tune tap gesture
206 * detection then they can access the gesture detector through this
207 * API and modify the detection.
209 * @return The tap gesture detector.
210 * @pre Tap detection should have been enabled via EnableGestureDetection().
211 * @see EnableGestureDetection
213 TapGestureDetector GetTapGestureDetector() const;
216 * @brief If deriving classes wish to fine tune long press gesture
217 * detection then they can access the gesture detector through this
218 * API and modify the detection.
220 * @return The long press gesture detector.
221 * @pre Long press detection should have been enabled via EnableGestureDetection().
222 * @see EnableGestureDetection
224 LongPressGestureDetector GetLongPressGestureDetector() const;
229 * @copydoc Dali::Toolkit::Control::SetBackgroundColor
231 void SetBackgroundColor( const Vector4& color );
234 * @copydoc Dali::Toolkit::Control::GetBackgroundColor
236 Vector4 GetBackgroundColor() const;
239 * @copydoc Dali::Toolkit::Control::SetBackground
241 void SetBackground( Image image );
244 * @copydoc Dali::Toolkit::Control::ClearBackground
246 void ClearBackground();
249 * @copydoc Dali::Toolkit::Control::GetBackgroundActor
251 Actor GetBackgroundActor() const;
256 * @copydoc Dali::Toolkit::Control::KeyEventSignal()
258 Toolkit::Control::KeyEventSignalV2& KeyEventSignal();
265 * @brief Second phase initialization.
272 * @brief Allows deriving classes to enable any of the gesture detectors that are available.
274 * Gesture detection can be enabled one at a time or in bitwise format as shown:
276 * EnableGestureDetection(Gesture::Type(Gesture::Pinch | Gesture::Tap | Gesture::Pan));
278 * @param[in] type The gesture type(s) to enable.
280 void EnableGestureDetection(Gesture::Type type);
283 * @brief Allows deriving classes to disable any of the gesture detectors.
285 * Like EnableGestureDetection, this can also be called using bitwise or.
286 * @param[in] type The gesture type(s) to disable.
287 * @see EnableGetureDetection
289 void DisableGestureDetection(Gesture::Type type);
291 private: // For derived classes to override
294 * @brief This method is called after the Control has been initialized.
296 * Derived classes should do any second phase initialization by
297 * overriding this method.
299 virtual void OnInitialize() { }
302 * @brief This method should be overridden by deriving classes when
303 * they wish to be notified when the style manager changes the theme.
305 * @param[in] styleManager The StyleManager object.
307 virtual void OnThemeChange( Toolkit::StyleManager styleManager );
310 * @brief This method should be overridden by deriving classes when
311 * they wish to be notified when the style changes the default font.
313 * @param[in] defaultFontChange Information denoting whether the default font has changed.
314 * @param[in] defaultFontSizeChange Information denoting whether the default font size has changed.
316 virtual void OnFontChange( bool defaultFontChange, bool defaultFontSizeChange ){ }
319 * @deprecated Use OnFontChange() instead.
320 * Before the using of StyleManager, the StyleChange only deals with font change.
322 * @brief This method should be overridden by deriving classes when
323 * they wish to be notified when the style changes.
325 * @param[in] change Information denoting what has changed.
327 virtual void OnStyleChange( StyleChange change ) { }
330 * @brief Called whenever a pinch gesture is detected on this control.
332 * This can be overridden by deriving classes when pinch detection
333 * is enabled. The default behaviour is to scale the control by the
336 * @note If overridden, then the default behaviour will not occur.
337 * @note Pinch detection should be enabled via EnableGestureDetection().
338 * @param[in] pinch The pinch gesture.
339 * @see EnableGestureDetection
341 virtual void OnPinch(PinchGesture pinch);
344 * @brief Called whenever a pan gesture is detected on this control.
346 * This should be overridden by deriving classes when pan detection
349 * @note There is no default behaviour with panning.
350 * @note Pan detection should be enabled via EnableGestureDetection().
351 * @param[in] pan The pan gesture.
352 * @see EnableGestureDetection
354 virtual void OnPan(PanGesture pan) { }
357 * @brief Called whenever a tap gesture is detected on this control.
359 * This should be overridden by deriving classes when tap detection
362 * @note There is no default behaviour with a tap.
363 * @note Tap detection should be enabled via EnableGestureDetection().
364 * @param[in] tap The tap gesture.
365 * @see EnableGestureDetection
367 virtual void OnTap(TapGesture tap) { }
370 * @brief Called whenever a long press gesture is detected on this control.
372 * This should be overridden by deriving classes when long press
373 * detection is enabled.
375 * @note There is no default behaviour associated with a long press.
376 * @note Long press detection should be enabled via EnableGestureDetection().
377 * @param[in] longPress The long press gesture.
378 * @see EnableGestureDetection
380 virtual void OnLongPress(LongPressGesture longPress) { }
383 * @brief Called whenever the control is added to the stage.
385 * Could be overridden by derived classes.
387 virtual void OnControlStageConnection() { }
390 * @brief Called whenever the control is removed from the stage.
392 * Could be overridden by derived classes.
394 virtual void OnControlStageDisconnection() { }
397 * @brief Called whenever an Actor is added to the control.
399 * Could be overridden by derived classes.
401 * @param[in] child The added actor.
403 virtual void OnControlChildAdd( Actor& child ) { }
406 * @brief Called whenever an Actor is removed from the control.
408 * Could be overridden by derived classes.
410 * @param[in] child The removed actor.
412 virtual void OnControlChildRemove( Actor& child ) { }
415 * @brief Called whenever the Control's size is set.
417 * Could be overridden by derived classes.
419 * @param[in] size The new size.
421 virtual void OnControlSizeSet( const Vector3& size ) { }
424 * @brief Called after the Dali::Stage::SignalMessageQueueFlushed()
425 * signal is emitted if this control requested to be relaid-out.
427 * Should be overridden by derived classes if they need to layout
428 * actors differently after certain operations like add or remove
429 * actors, resize or after changing especific properties.
431 * @param[in] size The allocated size.
432 * @param[in,out] container The control should add actors to this container that it is not able
433 * to allocate a size for.
435 virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
437 private: // From CustomActorImpl, derived classes can override these.
440 * @brief Sends a request to relayout this control.
442 * The control will be relaid out after the
443 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted.
445 * It calls OnControlStageConnection() to notify derived classes.
447 * @see Dali::CustomActorImpl::OnStageConnection()
449 virtual void OnStageConnection();
452 * @brief Calls OnControlStageDisconnection() to notify derived classed.
454 * @see Dali::CustomActorImpl::OnStageDisconnection()
456 virtual void OnStageDisconnection();
459 * @brief Sends a request to relayout this control.
461 * The control will be relaid out after the
462 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
463 * calls OnControlChildAdd() to notify derived classes.
465 * @note This method shouldn't be overridden by derived classes.
467 * @param[in] child The added actor.
469 * @see Dali::CustomActorImpl::OnChildAdd(Actor&)
471 virtual void OnChildAdd(Actor& child);
474 * @brief Sends a request to relayout this control.
476 * The control will be relaid out after the
477 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
478 * calls OnControlChildRemove() to notify derived classes.
480 * @note This method shouldn't be overridden by derived classes.
482 * @param[in] child The removed actor.
484 * @see Dali::CustomActorImpl::OnChildRemove(Actor&)
486 virtual void OnChildRemove(Actor& child);
489 * @brief It stores the size set by size negotiation and relayout.
491 * It also keeps a backup of the size set through the Actor's API used in the size negotiation.
492 * It calls the OnControlSizeSet() to notify derived classes.
494 * @param[in] targetSize The new size.
496 * @see Dali::CustomActorImpl::OnSizeSet(const Vector3&)
498 virtual void OnSizeSet(const Vector3& targetSize);
501 * @copydoc Dali::CustomActorImpl::OnSizeAnimation(Animation&, const Vector3&)
503 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
506 * @copydoc Dali::CustomActorImpl::OnTouchEvent(const TouchEvent&)
508 virtual bool OnTouchEvent(const TouchEvent& event);
511 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
513 virtual bool OnKeyEvent(const KeyEvent& event);
516 * @copydoc Dali::CustomActorImpl::OnMouseWheelEvent(const MouseWheelEvent&)
518 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event);
521 * @copydoc Dali::CustomActorImpl::OnKeyInputFocusGained()
523 virtual void OnKeyInputFocusGained();
526 * @copydoc Dali::CustomActorImpl::OnKeyInputFocusLost()
528 virtual void OnKeyInputFocusLost();
531 * @copydoc Dali::CustomActorImpl::GetChildByAlias(const std::string& actorAlias)
533 virtual Actor GetChildByAlias(const std::string& actorAlias);
538 * @brief Perform the activated action.
540 * @param[in] attributes The attributes to perfrom this action.
542 void DoActivatedAction(const PropertyValueContainer& attributes);
545 * @brief This method is the callback for the StyleChangeSignal from StyleManager
547 * @param[in] styleManager The StyleManager Object
548 * @param[in] change Information denoting what has changed.
550 void DoStyleChange( Toolkit::StyleManager styleManager, StyleChange change );
552 protected: // Construction
554 // Flags for the constructor
555 enum ControlBehaviour
557 CONTROL_BEHAVIOUR_NONE = 0x0,
558 REQUIRES_TOUCH_EVENTS = 0x1, ///< True if the OnTouchEvent() callback is required.
559 REQUIRES_STYLE_CHANGE_SIGNALS = 0x2 ///< True if needs to monitor style change signals such as theme/font change
563 * @deprecated Use the constructor taking flags instead
564 * @brief Create a Control.
566 * @param[in] requiresTouchEvents True if the OnTouchEvent() callback is required.
568 Control(bool requiresTouchEvents);
571 * @brief Create a Control.
573 * @param[in] behaviourFlags Behavioural flags from ControlBehaviour enum
575 Control(ControlBehaviour behaviourFlags);
582 * @copydoc Toolkit::Control::SetSizePolicy()
584 void SetSizePolicy( Toolkit::Control::SizePolicy widthPolicy, Toolkit::Control::SizePolicy heightPolicy );
587 * @copydoc Toolkit::Control::GetSizePolicy()
589 void GetSizePolicy( Toolkit::Control::SizePolicy& widthPolicy, Toolkit::Control::SizePolicy& heightPolicy ) const;
592 * @copydoc Toolkit::Control::SetMinimumSize()
594 void SetMinimumSize( const Vector3& size );
597 * @copydoc Toolkit::Control::GetMinimumSize()
599 const Vector3& GetMinimumSize() const;
602 * @copydoc Toolkit::Control::SetMaximumSize()
604 void SetMaximumSize( const Vector3& size );
607 * @copydoc Toolkit::Control::GetMaximumSize()
609 const Vector3& GetMaximumSize() const;
612 * @copydoc Toolkit::Control::GetNaturalSize()
614 virtual Vector3 GetNaturalSize();
617 * @copydoc Toolkit::Control::GetHeightForWidth()
619 virtual float GetHeightForWidth( float width );
622 * @copydoc Toolkit::Control::GetWidthForHeight()
624 virtual float GetWidthForHeight( float height );
627 * @brief Retrieves the current Control's size.
629 * @return The control's size.
631 const Vector3& GetControlSize() const;
634 * @brief Retrieves the Control's size set by the Application / Control.
636 * @return The control's size.
638 const Vector3& GetSizeSet() const;
643 * @copydoc Toolkit::Control::SetKeyInputFocus()
645 void SetKeyInputFocus();
648 * @copydoc Toolkit::Control::HasKeyInputFocus()
650 bool HasKeyInputFocus();
653 * @copydoc Toolkit::Control::ClearKeyInputFocus()
655 void ClearKeyInputFocus();
658 * @copydoc ConnectionTrackerInterface::SignalConnected
660 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
663 * @copydoc ConnectionTrackerInterface::SignalDisconnected
665 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
668 * @copydoc ConnectionTrackerInterface::GetConnectionCount
670 virtual std::size_t GetConnectionCount() const;
675 * @brief Sends a request to be relaid-out.
677 * This method is called from OnStageConnection(), OnChildAdd(),
678 * OnChildRemove(), SetSizePolicy(), SetMinimumSize() and
681 * This method could also be called from derived classes every time
682 * a control's poperty change and it needs to be relaid-out. After
683 * the Dali::Stage::SignalMessageQueueFlushed() is emitted a
684 * relayout process starts and all controls which called this method
685 * will be relaid-out.
687 * @note RelayoutRequest() only sends a request per Control before
688 * the Dali::Stage::SignalMessageQueueFlushed() signal is
689 * emitted. That means a control will be relaid-out only once, even
690 * if more than one request is sent between two consecutive signals.
692 void RelayoutRequest();
695 * @brief Helper method for controls to Relayout their children if
696 * they do not know whether that child is a control or not.
698 * @param[in] actor The actor to relayout.
699 * @param[in] size The size to allocate to the actor.
700 * @param[in,out] container The container that holds actors that have not been allocated a size yet.
702 static void Relayout( Actor actor, Vector2 size, ActorSizeContainer& container );
704 private: // Used by the RelayoutController
707 * @brief Called by the RelayoutController to negotiate the size of a control.
709 * The size allocated by the the algorithm is passed in which the
710 * control must adhere to. A container is passed in as well which
711 * the control should populate with actors it has not / or does not
712 * need to handle in its size negotiation.
714 * @param[in] size The allocated size.
715 * @param[in,out] container The container that holds actors that are fed back into the
716 * RelayoutController algorithm.
718 void NegotiateSize( Vector2 size, ActorSizeContainer& container );
723 * @brief Called by NegotiateSize when the size to allocate to the control has been calculated.
725 * It calls the OnRelaidOut() method which can be overridden by derived classes.
727 * @param[in] size The allocated size.
728 * @param[in,out] container The control should add actors to this container that it is not able
729 * to allocate a size for.
731 void Relayout( Vector2 size, ActorSizeContainer& container );
734 * @brief Used by the KeyInputFocusManager to emit key event signals.
736 * @param[in] event The key event.
737 * @return True if the event was consumed.
739 bool EmitKeyEventSignal(const KeyEvent& event);
746 Control(const Control&);
747 Control& operator=(const Control&);
752 friend class Internal::RelayoutControllerImpl; ///< Relayout controller needs to call Relayout() which is private.
753 friend class Internal::KeyInputFocusManager; ///< KeyInputFocusManager needs to call which is private.
756 } // namespace Internal
758 typedef Internal::Control ControlImpl; ///< @deprecated, Use Internal::Control
760 } // namespace Toolkit
767 #endif // __DALI_TOOLKIT_CONTROL_IMPL_H__