1 #ifndef DALI_TOOLKIT_CONTROL_IMPL_H
2 #define DALI_TOOLKIT_CONTROL_IMPL_H
5 * Copyright (c) 2016 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/events/long-press-gesture.h>
24 #include <dali/public-api/events/pan-gesture.h>
25 #include <dali/public-api/events/pinch-gesture.h>
26 #include <dali/public-api/events/tap-gesture.h>
27 #include <dali/public-api/object/property-index-ranges.h>
28 #include <dali/public-api/object/type-info.h>
31 #include <dali-toolkit/public-api/controls/control.h>
39 * @addtogroup dali_toolkit_controls
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.
62 class DALI_IMPORT_API Control : public CustomActorImpl, public ConnectionTrackerInterface
66 * @brief Virtual destructor.
73 class Extension; ///< Forward declare future extension interface
75 // Creation & Destruction
78 * @brief Create a new ControlImpl instance that does not require touch by default.
80 * If touch is required then the user can connect to this class' touch signal.
82 * @return A handle to the ControlImpl instance.
84 static Toolkit::Control New();
89 * @copydoc Dali::Toolkit::Control::SetStyleName
91 void SetStyleName( const std::string& styleName );
94 * @copydoc Dali::Toolkit::Control::GetStyleName
96 const std::string& GetStyleName() const;
101 * @copydoc Dali::Toolkit::Control::SetBackgroundColor
103 void SetBackgroundColor( const Vector4& color );
106 * @copydoc Dali::Toolkit::Control::GetBackgroundColor
108 Vector4 GetBackgroundColor() const;
111 * @copydoc Dali::Toolkit::Control::SetBackgroundImage
113 void SetBackgroundImage( Image image );
116 * @brief Set the background with a property map.
119 * @param[in] map The background property map.
121 void SetBackground(const Property::Map& map);
124 * @copydoc Dali::Toolkit::Control::ClearBackground
126 void ClearBackground();
131 * @brief Allows deriving classes to enable any of the gesture detectors that are available.
133 * Gesture detection can be enabled one at a time or in bitwise format as shown:
135 * EnableGestureDetection(Gesture::Type(Gesture::Pinch | Gesture::Tap | Gesture::Pan));
138 * @param[in] type The gesture type(s) to enable.
140 void EnableGestureDetection( Gesture::Type type );
143 * @brief Allows deriving classes to disable any of the gesture detectors.
145 * Like EnableGestureDetection, this can also be called using bitwise or.
147 * @param[in] type The gesture type(s) to disable.
148 * @see EnableGetureDetection
150 void DisableGestureDetection( Gesture::Type type );
153 * @brief If deriving classes wish to fine tune pinch gesture
154 * detection then they can access the gesture detector through this
155 * API and modify the detection.
158 * @return The pinch gesture detector.
159 * @pre Pinch detection should have been enabled via EnableGestureDetection().
160 * @see EnableGestureDetection
162 PinchGestureDetector GetPinchGestureDetector() const;
165 * @brief If deriving classes wish to fine tune pan gesture
166 * detection then they can access the gesture detector through this
167 * API and modify the detection.
170 * @return The pan gesture detector.
171 * @pre Pan detection should have been enabled via EnableGestureDetection().
172 * @see EnableGestureDetection
174 PanGestureDetector GetPanGestureDetector() const;
177 * @brief If deriving classes wish to fine tune tap gesture
178 * detection then they can access the gesture detector through this
179 * API and modify the detection.
182 * @return The tap gesture detector.
183 * @pre Tap detection should have been enabled via EnableGestureDetection().
184 * @see EnableGestureDetection
186 TapGestureDetector GetTapGestureDetector() const;
189 * @brief If deriving classes wish to fine tune long press gesture
190 * detection then they can access the gesture detector through this
191 * API and modify the detection.
194 * @return The long press gesture detector.
195 * @pre Long press detection should have been enabled via EnableGestureDetection().
196 * @see EnableGestureDetection
198 LongPressGestureDetector GetLongPressGestureDetector() const;
200 // Keyboard Navigation
203 * @brief Sets whether this control supports two dimensional
204 * keyboard navigation (i.e. whether it knows how to handle the
205 * keyboard focus movement between its child actors).
207 * The control doesn't support it by default.
209 * @param[in] isSupported Whether this control supports two dimensional keyboard navigation.
211 void SetKeyboardNavigationSupport( bool isSupported );
214 * @brief Gets whether this control supports two dimensional keyboard navigation.
217 * @return true if this control supports two dimensional keyboard navigation.
219 bool IsKeyboardNavigationSupported();
224 * @copydoc Toolkit::Control::SetKeyInputFocus()
226 void SetKeyInputFocus();
229 * @copydoc Toolkit::Control::HasKeyInputFocus()
231 bool HasKeyInputFocus();
234 * @copydoc Toolkit::Control::ClearKeyInputFocus()
236 void ClearKeyInputFocus();
241 * @brief Sets whether this control is a focus group for keyboard navigation.
243 * (i.e. the scope of keyboard focus movement
244 * can be limitied to its child actors). The control is not a focus group by default.
246 * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation.
248 void SetAsKeyboardFocusGroup( bool isFocusGroup );
251 * @brief Gets whether this control is a focus group for keyboard navigation.
254 * @return true if this control is set as a focus group for keyboard navigation.
256 bool IsKeyboardFocusGroup();
260 * @brief Called by the AccessibilityManager to activate the Control.
263 DALI_INTERNAL void AccessibilityActivate();
266 * @brief Called by the KeyboardFocusManager.
269 DALI_INTERNAL void KeyboardEnter();
275 * @copydoc Dali::Toolkit::Control::KeyEventSignal()
277 Toolkit::Control::KeyEventSignalType& KeyEventSignal();
280 * @copydoc Dali::Toolkit::Control::KeyInputFocusGainedSignal()
282 Toolkit::Control::KeyInputFocusSignalType& KeyInputFocusGainedSignal();
285 * @copydoc Dali::Toolkit::Control::KeyInputFocusLostSignal()
287 Toolkit::Control::KeyInputFocusSignalType& KeyInputFocusLostSignal();
291 * @brief Called by the KeyInputFocusManager to emit key event signals.
294 * @param[in] event The key event.
295 * @return True if the event was consumed.
297 DALI_INTERNAL bool EmitKeyEventSignal( const KeyEvent& event );
300 protected: // For derived classes to call
303 * @brief Register a visual by Property Index, linking an Actor to visual when required.
304 * In the case of the visual being an actor or control deeming visual not required then visual should be an empty handle.
305 * No parenting is done during registration, this should be done by derived class.
309 * @param[in] index The Property index of the visual, used to reference visual
310 * @param[in] visual The visual to register
311 * @note Derived class should not call visual.SetOnStage(actor). It is the responsibility of the base class to connect/disconnect registered visual to stage.
312 * Use below API with enabled set to false if derived class wishes to control when visual is staged.
314 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual );
317 * @brief Register a visual by Property Index, linking an Actor to visual when required.
318 * In the case of the visual being an actor or control deeming visual not required then visual should be an empty handle.
319 * If enabled is false then the visual is not set on stage until enabled by the derived class.
324 * @param[in] index The Property index of the visual, used to reference visual
325 * @param[in] visual The visual to register
326 * @param[in] enabled false if derived class wants to control when visual is set on stage.
329 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled );
332 * @brief Erase the entry matching the given index from the list of registered visuals
333 * @param[in] index The Property index of the visual, used to reference visual
337 void UnregisterVisual( Property::Index index );
340 * @brief Retrieve the visual associated with the given property index.
344 * @param[in] index The Property index of the visual.
345 * @return The registered visual if exist, otherwise empty handle.
346 * @note For managing object life-cycle, do not store the returned visual as a member which increments its reference count.
348 Toolkit::Visual::Base GetVisual( Property::Index index ) const;
351 * @brief Sets the given visual to be displayed or not when parent staged.
355 * @param[in] index The Property index of the visual
356 * @param[in] enable flag to set enabled or disabled.
358 void EnableVisual( Property::Index index, bool enable );
361 * @brief Queries if the given visual is to be displayed when parent staged.
365 * @param[in] index The Property index of the visual
366 * @return bool whether visual is enabled or not
368 bool IsVisualEnabled( Property::Index index ) const;
371 * @brief Create a transition effect on the control.
375 * @param[in] transitionData The transition data describing the effect to create
376 * @return A handle to an animation defined with the given effect, or an empty
377 * handle if no properties match.
379 Dali::Animation CreateTransition( const Toolkit::TransitionData& transitionData );
382 * @brief Emits KeyInputFocusGained signal if true else emits KeyInputFocusLost signal
384 * Should be called last by the control after it acts on the Input Focus change.
387 * @param[in] focusGained True if gained, False if lost
389 void EmitKeyInputFocusSignal( bool focusGained );
391 protected: // From CustomActorImpl, not to be used by application developers
394 * @copydoc CustomActorImpl::OnStageConnection()
395 * @note If overridden, then an up-call to Control::OnStageConnection MUST be made at the start.
397 virtual void OnStageConnection( int depth );
400 * @copydoc CustomActorImpl::OnStageDisconnection()
401 * @note If overridden, then an up-call to Control::OnStageDisconnection MUST be made at the end.
403 virtual void OnStageDisconnection();
406 * @copydoc CustomActorImpl::OnChildAdd()
407 * @note If overridden, then an up-call to Control::OnChildAdd MUST be made at the start.
409 virtual void OnChildAdd( Actor& child );
412 * @copydoc CustomActorImpl::OnChildRemove()
413 * @note If overridden, then an up-call to Control::OnChildRemove MUST be made at the end.
415 virtual void OnChildRemove( Actor& child );
418 * @copydoc CustomActorImpl::OnSizeSet()
419 * @note If overridden, then an up-call to Control::OnSizeSet MUST be made at the start.
421 virtual void OnSizeSet( const Vector3& targetSize );
424 * @copydoc CustomActorImpl::OnSizeAnimation()
425 * @note If overridden, then an up-call to Control::OnSizeAnimation MUST be made at the start.
427 virtual void OnSizeAnimation( Animation& animation, const Vector3& targetSize );
430 * @copydoc CustomActorImpl::OnTouchEvent()
432 virtual bool OnTouchEvent( const TouchEvent& event );
435 * @copydoc CustomActorImpl::OnHoverEvent()
437 virtual bool OnHoverEvent( const HoverEvent& event );
440 * @copydoc CustomActorImpl::OnKeyEvent()
442 virtual bool OnKeyEvent( const KeyEvent& event );
445 * @copydoc CustomActorImpl::OnWheelEvent()
447 virtual bool OnWheelEvent( const WheelEvent& event );
450 * @copydoc CustomActorImpl::OnRelayout()
452 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
455 * @copydoc CustomActorImpl::OnSetResizePolicy()
457 virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension );
460 * @copydoc CustomActorImpl::GetNaturalSize()
462 virtual Vector3 GetNaturalSize();
465 * @copydoc CustomActorImpl::CalculateChildSize()
467 virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension );
470 * @copydoc CustomActorImpl::GetHeightForWidth()
472 virtual float GetHeightForWidth( float width );
475 * @copydoc CustomActorImpl::GetWidthForHeight()
477 virtual float GetWidthForHeight( float height );
480 * @copydoc CustomActorImpl::RelayoutDependentOnChildren()
482 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
485 * @copydoc CustomActorImpl::OnCalculateRelayoutSize()
487 virtual void OnCalculateRelayoutSize( Dimension::Type dimension );
490 * @copydoc CustomActorImpl::OnLayoutNegotiated()
492 virtual void OnLayoutNegotiated( float size, Dimension::Type dimension );
494 protected: // Helpers for deriving classes
499 * @brief Flags for the constructor
502 enum ControlBehaviour
504 CONTROL_BEHAVIOUR_DEFAULT = 0, ///< Default behaviour: Size negotiation is enabled & listens to Style Change signal, but doesn't receive event callbacks. @SINCE_1_2_10
505 REQUIRES_STYLE_CHANGE_SIGNALS = 1 << ( CustomActorImpl::ACTOR_FLAG_COUNT + 0 ), ///< True if needs to monitor style change signals such as theme/font change @SINCE_1_0.0 @DEPRECATED_1_2_10
506 REQUIRES_KEYBOARD_NAVIGATION_SUPPORT = 1 << ( CustomActorImpl::ACTOR_FLAG_COUNT + 1 ), ///< True if needs to support keyboard navigation @SINCE_1_0.0
508 DISABLE_STYLE_CHANGE_SIGNALS = 1 << ( CustomActorImpl::ACTOR_FLAG_COUNT + 2 ), ///< True if control should not monitor style change signals @SINCE_1_2_10
510 LAST_CONTROL_BEHAVIOUR_FLAG
513 static const int CONTROL_BEHAVIOUR_FLAG_COUNT = Log< LAST_CONTROL_BEHAVIOUR_FLAG - 1 >::value + 1; ///< Total count of flags
516 * @brief Control constructor
519 * @param[in] behaviourFlags Behavioural flags from ControlBehaviour enum
521 Control( ControlBehaviour behaviourFlags );
524 * @brief Second phase initialization.
529 public: // API for derived classes to override
534 * @brief This method is called after the Control has been initialized.
536 * Derived classes should do any second phase initialization by overriding this method.
539 virtual void OnInitialize();
542 * @DEPRECATED_1_1.30. Override OnChildAdd instead.
544 * @brief Called whenever an Actor is added to the control.
546 * Could be overridden by derived classes.
549 * @param[in] child The added actor.
551 virtual void OnControlChildAdd( Actor& child ) DALI_DEPRECATED_API;
554 * @DEPRECATED_1_1.30. Override OnChildRemove instead.
556 * @brief Called whenever an Actor is removed from the control.
558 * Could be overridden by derived classes.
561 * @param[in] child The removed actor.
563 virtual void OnControlChildRemove( Actor& child ) DALI_DEPRECATED_API;
568 * @brief This method should be overridden by deriving classes requiring notifications when the style changes.
571 * @param[in] styleManager The StyleManager object.
572 * @param[in] change Information denoting what has changed.
574 virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
579 * @brief This method is called when the control is accessibility activated.
581 * Derived classes should override this to perform custom accessibility activation.
583 * @return true if this control can perform accessibility activation.
585 virtual bool OnAccessibilityActivated();
588 * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
592 * @param[in] gesture The pan gesture.
593 * @return true if the pan gesture has been consumed by this control
595 virtual bool OnAccessibilityPan( PanGesture gesture );
598 * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
602 * @param[in] touchEvent The touch event.
603 * @return true if the touch event has been consumed by this control
605 virtual bool OnAccessibilityTouch( const TouchEvent& touchEvent );
608 * @brief This method should be overridden by deriving classes when they wish to respond
609 * the accessibility up and down action (i.e. value change of slider control).
612 * @param[in] isIncrease Whether the value should be increased or decreased
613 * @return true if the value changed action has been consumed by this control
615 virtual bool OnAccessibilityValueChange( bool isIncrease );
618 * @brief This method should be overridden by deriving classes when they wish to respond
619 * the accessibility zoom action.
622 * @return true if the zoom action has been consumed by this control
624 virtual bool OnAccessibilityZoom();
629 * @brief Called when the control gains key input focus.
631 * Should be overridden by derived classes if they need to customize what happens when focus is gained.
634 virtual void OnKeyInputFocusGained();
637 * @brief Called when the control loses key input focus.
639 * Should be overridden by derived classes if they need to customize what happens when focus is lost.
642 virtual void OnKeyInputFocusLost();
645 * @brief Gets the next keyboard focusable actor in this control towards the given direction.
647 * A control needs to override this function in order to support two dimensional keyboard navigation.
649 * @param[in] currentFocusedActor The current focused actor.
650 * @param[in] direction The direction to move the focus towards.
651 * @param[in] loopEnabled Whether the focus movement should be looped within the control.
652 * @return the next keyboard focusable actor in this control or an empty handle if no actor can be focused.
654 virtual Actor GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled );
657 * @brief Informs this control that its chosen focusable actor will be focused.
659 * This allows the application to preform any actions if wishes
660 * before the focus is actually moved to the chosen actor.
663 * @param[in] commitedFocusableActor The commited focusable actor.
665 virtual void OnKeyboardFocusChangeCommitted( Actor commitedFocusableActor );
668 * @brief This method is called when the control has enter pressed on it.
670 * Derived classes should override this to perform custom actions.
672 * @return true if this control supported this action.
674 virtual bool OnKeyboardEnter();
679 * @brief Called whenever a pinch gesture is detected on this control.
681 * This can be overridden by deriving classes when pinch detection
682 * is enabled. The default behaviour is to scale the control by the
686 * @param[in] pinch The pinch gesture.
687 * @note If overridden, then the default behaviour will not occur.
688 * @note Pinch detection should be enabled via EnableGestureDetection().
689 * @see EnableGestureDetection
691 virtual void OnPinch( const PinchGesture& pinch );
694 * @brief Called whenever a pan gesture is detected on this control.
696 * This should be overridden by deriving classes when pan detection
700 * @param[in] pan The pan gesture.
701 * @note There is no default behaviour with panning.
702 * @note Pan detection should be enabled via EnableGestureDetection().
703 * @see EnableGestureDetection
705 virtual void OnPan( const PanGesture& pan );
708 * @brief Called whenever a tap gesture is detected on this control.
710 * This should be overridden by deriving classes when tap detection
714 * @param[in] tap The tap gesture.
715 * @note There is no default behaviour with a tap.
716 * @note Tap detection should be enabled via EnableGestureDetection().
717 * @see EnableGestureDetection
719 virtual void OnTap( const TapGesture& tap );
722 * @brief Called whenever a long press gesture is detected on this control.
724 * This should be overridden by deriving classes when long press
725 * detection is enabled.
728 * @param[in] longPress The long press gesture.
729 * @note There is no default behaviour associated with a long press.
730 * @note Long press detection should be enabled via EnableGestureDetection().
731 * @see EnableGestureDetection
733 virtual void OnLongPress( const LongPressGesture& longPress );
735 // From ConnectionTrackerInterface
738 * @copydoc ConnectionTrackerInterface::SignalConnected
740 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
743 * @copydoc ConnectionTrackerInterface::SignalDisconnected
745 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
748 * @brief Retrieve the extension for this control
751 * @return The extension if available, NULL otherwise
753 virtual Extension* GetControlExtension()
762 DALI_INTERNAL Control( const Control& );
763 DALI_INTERNAL Control& operator=( const Control& );
772 * @brief Get implementation from the handle.
776 * @return implementation
777 * @pre handle is initialized and points to a control
779 DALI_IMPORT_API Internal::Control& GetImplementation( Dali::Toolkit::Control& handle );
782 * @brief Get implementation from the handle.
786 * @return implementation
787 * @pre handle is initialized and points to a control
789 DALI_IMPORT_API const Internal::Control& GetImplementation( const Dali::Toolkit::Control& handle );
791 } // namespace Internal
796 } // namespace Toolkit
800 #endif // DALI_TOOLKIT_CONTROL_IMPL_H