1 #ifndef DALI_TOOLKIT_CONTROL_IMPL_H
2 #define DALI_TOOLKIT_CONTROL_IMPL_H
5 * Copyright (c) 2018 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
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.
56 class DALI_TOOLKIT_API Control : public CustomActorImpl, public ConnectionTrackerInterface
60 class Extension; ///< Forward declare future extension interface
62 // Creation & Destruction
65 * @brief Creates a new ControlImpl instance that does not require touch by default.
67 * If touch is required, then the user can connect to this class' touch signal.
69 * @return A handle to the ControlImpl instance
71 static Toolkit::Control New();
75 * @brief Virtual destructor.
84 * @copydoc Dali::Toolkit::Control::SetStyleName
86 void SetStyleName( const std::string& styleName );
89 * @copydoc Dali::Toolkit::Control::GetStyleName
91 const std::string& GetStyleName() const;
96 * @copydoc Dali::Toolkit::Control::SetBackgroundColor
98 void SetBackgroundColor( const Vector4& color );
101 * @copydoc Dali::Toolkit::Control::GetBackgroundColor
103 Vector4 GetBackgroundColor() const;
106 * @copydoc Dali::Toolkit::Control::SetBackgroundImage
108 void SetBackgroundImage( Image image );
111 * @brief Sets the background with a property map.
114 * @param[in] map The background property map
116 void SetBackground(const Property::Map& map);
119 * @copydoc Dali::Toolkit::Control::ClearBackground
121 void ClearBackground();
126 * @brief Allows deriving classes to enable any of the gesture detectors that are available.
128 * Gesture detection can be enabled one at a time or in bitwise format as shown:
130 * EnableGestureDetection(Gesture::Type(Gesture::Pinch | Gesture::Tap | Gesture::Pan));
133 * @param[in] type The gesture type(s) to enable
135 void EnableGestureDetection( Gesture::Type type );
138 * @brief Allows deriving classes to disable any of the gesture detectors.
140 * Like EnableGestureDetection, this can also be called using bitwise or.
142 * @param[in] type The gesture type(s) to disable
143 * @see EnableGetureDetection
145 void DisableGestureDetection( Gesture::Type type );
148 * @brief If deriving classes wish to fine tune pinch gesture
149 * detection, then they can access the gesture detector through this
150 * API and modify the detection.
153 * @return The pinch gesture detector
154 * @pre Pinch detection should have been enabled via EnableGestureDetection().
155 * @see EnableGestureDetection
157 PinchGestureDetector GetPinchGestureDetector() const;
160 * @brief If deriving classes wish to fine tune pan gesture
161 * detection, then they can access the gesture detector through this
162 * API and modify the detection.
165 * @return The pan gesture detector
166 * @pre Pan detection should have been enabled via EnableGestureDetection().
167 * @see EnableGestureDetection
169 PanGestureDetector GetPanGestureDetector() const;
172 * @brief If deriving classes wish to fine tune tap gesture
173 * detection, then they can access the gesture detector through this
174 * API and modify the detection.
177 * @return The tap gesture detector
178 * @pre Tap detection should have been enabled via EnableGestureDetection().
179 * @see EnableGestureDetection
181 TapGestureDetector GetTapGestureDetector() const;
184 * @brief If deriving classes wish to fine tune long press gesture
185 * detection, then they can access the gesture detector through this
186 * API and modify the detection.
189 * @return The long press gesture detector
190 * @pre Long press detection should have been enabled via EnableGestureDetection().
191 * @see EnableGestureDetection
193 LongPressGestureDetector GetLongPressGestureDetector() const;
195 // Keyboard Navigation
198 * @brief Sets whether this control supports two dimensional
199 * keyboard navigation (i.e. whether it knows how to handle the
200 * keyboard focus movement between its child actors).
202 * The control doesn't support it by default.
204 * @param[in] isSupported Whether this control supports two dimensional keyboard navigation
206 void SetKeyboardNavigationSupport( bool isSupported );
209 * @brief Gets whether this control supports two dimensional keyboard navigation.
212 * @return true if this control supports two dimensional keyboard navigation
214 bool IsKeyboardNavigationSupported();
219 * @copydoc Toolkit::Control::SetKeyInputFocus()
221 void SetKeyInputFocus();
224 * @copydoc Toolkit::Control::HasKeyInputFocus()
226 bool HasKeyInputFocus();
229 * @copydoc Toolkit::Control::ClearKeyInputFocus()
231 void ClearKeyInputFocus();
236 * @brief Sets whether this control is a focus group for keyboard navigation.
238 * (i.e. the scope of keyboard focus movement
239 * can be limited to its child actors). The control is not a focus group by default.
241 * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation
243 void SetAsKeyboardFocusGroup( bool isFocusGroup );
246 * @brief Gets whether this control is a focus group for keyboard navigation.
249 * @return true if this control is set as a focus group for keyboard navigation
251 bool IsKeyboardFocusGroup();
255 * @brief Called by the AccessibilityManager to activate the Control.
258 DALI_INTERNAL void AccessibilityActivate();
261 * @brief Called by the KeyboardFocusManager.
264 DALI_INTERNAL void KeyboardEnter();
270 * @copydoc Dali::Toolkit::Control::KeyEventSignal()
272 Toolkit::Control::KeyEventSignalType& KeyEventSignal();
275 * @copydoc Dali::Toolkit::Control::KeyInputFocusGainedSignal()
277 Toolkit::Control::KeyInputFocusSignalType& KeyInputFocusGainedSignal();
280 * @copydoc Dali::Toolkit::Control::KeyInputFocusLostSignal()
282 Toolkit::Control::KeyInputFocusSignalType& KeyInputFocusLostSignal();
286 * @brief Called by the KeyInputFocusManager to emit key event signals.
289 * @param[in] event The key event
290 * @return True if the event was consumed
292 DALI_INTERNAL bool EmitKeyEventSignal( const KeyEvent& event );
295 protected: // For derived classes to call
298 * @brief Emits KeyInputFocusGained signal if true else emits KeyInputFocusLost signal.
300 * Should be called last by the control after it acts on the Input Focus change.
303 * @param[in] focusGained True if gained, False if lost
305 void EmitKeyInputFocusSignal( bool focusGained );
307 protected: // From CustomActorImpl, not to be used by application developers
310 * @copydoc CustomActorImpl::OnStageConnection()
311 * @note If overridden, then an up-call to Control::OnStageConnection MUST be made at the end.
313 virtual void OnStageConnection( int depth );
316 * @copydoc CustomActorImpl::OnStageDisconnection()
317 * @note If overridden, then an up-call to Control::OnStageDisconnection MUST be made at the end.
319 virtual void OnStageDisconnection();
322 * @copydoc CustomActorImpl::OnChildAdd()
323 * @note If overridden, then an up-call to Control::OnChildAdd MUST be made at the end.
325 virtual void OnChildAdd( Actor& child );
328 * @copydoc CustomActorImpl::OnChildRemove()
329 * @note If overridden, then an up-call to Control::OnChildRemove MUST be made at the end.
331 virtual void OnChildRemove( Actor& child );
334 * @copydoc CustomActorImpl::OnPropertySet()
335 * @note If overridden, then an up-call to Control::OnChildRemove MUST be made at the end.
337 virtual void OnPropertySet( Property::Index index, Property::Value propertyValue );
340 * @copydoc CustomActorImpl::OnSizeSet()
341 * @note If overridden, then an up-call to Control::OnSizeSet MUST be made at the end.
343 virtual void OnSizeSet( const Vector3& targetSize );
346 * @copydoc CustomActorImpl::OnSizeAnimation()
347 * @note If overridden, then an up-call to Control::OnSizeAnimation MUST be made at the end.
349 virtual void OnSizeAnimation( Animation& animation, const Vector3& targetSize );
352 * @copydoc CustomActorImpl::OnTouchEvent()
354 virtual bool OnTouchEvent( const TouchEvent& event );
357 * @copydoc CustomActorImpl::OnHoverEvent()
359 virtual bool OnHoverEvent( const HoverEvent& event );
362 * @copydoc CustomActorImpl::OnKeyEvent()
364 virtual bool OnKeyEvent( const KeyEvent& event );
367 * @copydoc CustomActorImpl::OnWheelEvent()
369 virtual bool OnWheelEvent( const WheelEvent& event );
372 * @copydoc CustomActorImpl::OnRelayout()
374 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
377 * @copydoc CustomActorImpl::OnSetResizePolicy()
379 virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension );
382 * @copydoc CustomActorImpl::GetNaturalSize()
384 virtual Vector3 GetNaturalSize();
387 * @copydoc CustomActorImpl::CalculateChildSize()
389 virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension );
392 * @copydoc CustomActorImpl::GetHeightForWidth()
394 virtual float GetHeightForWidth( float width );
397 * @copydoc CustomActorImpl::GetWidthForHeight()
399 virtual float GetWidthForHeight( float height );
402 * @copydoc CustomActorImpl::RelayoutDependentOnChildren()
404 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
407 * @copydoc CustomActorImpl::OnCalculateRelayoutSize()
409 virtual void OnCalculateRelayoutSize( Dimension::Type dimension );
412 * @copydoc CustomActorImpl::OnLayoutNegotiated()
414 virtual void OnLayoutNegotiated( float size, Dimension::Type dimension );
416 protected: // Helpers for deriving classes
421 * @brief Flags for the constructor.
424 enum ControlBehaviour
426 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
427 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
428 REQUIRES_KEYBOARD_NAVIGATION_SUPPORT = 1 << ( CustomActorImpl::ACTOR_FLAG_COUNT + 1 ), ///< True if needs to support keyboard navigation @SINCE_1_0.0
430 DISABLE_STYLE_CHANGE_SIGNALS = 1 << ( CustomActorImpl::ACTOR_FLAG_COUNT + 2 ), ///< True if control should not monitor style change signals @SINCE_1_2_10
432 LAST_CONTROL_BEHAVIOUR_FLAG
435 static const int CONTROL_BEHAVIOUR_FLAG_COUNT = Log< LAST_CONTROL_BEHAVIOUR_FLAG - 1 >::value + 1; ///< Total count of flags
438 * @brief Control constructor.
441 * @param[in] behaviourFlags Behavioural flags from ControlBehaviour enum
443 Control( ControlBehaviour behaviourFlags );
446 * @brief Second phase initialization.
451 public: // API for derived classes to override
456 * @brief This method is called after the Control has been initialized.
458 * Derived classes should do any second phase initialization by overriding this method.
461 virtual void OnInitialize();
464 * @DEPRECATED_1_1.30. Override OnChildAdd instead.
466 * @brief Called whenever an Actor is added to the control.
468 * Could be overridden by derived classes.
471 * @param[in] child The added actor
473 virtual void OnControlChildAdd( Actor& child ) DALI_DEPRECATED_API;
476 * @DEPRECATED_1_1.30. Override OnChildRemove instead.
478 * @brief Called whenever an Actor is removed from the control.
480 * Could be overridden by derived classes.
483 * @param[in] child The removed actor
485 virtual void OnControlChildRemove( Actor& child ) DALI_DEPRECATED_API;
490 * @brief This method should be overridden by deriving classes requiring notifications when the style changes.
493 * @param[in] styleManager The StyleManager object
494 * @param[in] change Information denoting what has changed
496 virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
501 * @brief This method is called when the control is accessibility activated.
503 * Derived classes should override this to perform custom accessibility activation.
505 * @return true if this control can perform accessibility activation
507 virtual bool OnAccessibilityActivated();
510 * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
514 * @param[in] gesture The pan gesture
515 * @return true if the pan gesture has been consumed by this control
517 virtual bool OnAccessibilityPan( PanGesture gesture );
520 * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
524 * @param[in] touchEvent The touch event
525 * @return true if the touch event has been consumed by this control
527 virtual bool OnAccessibilityTouch( const TouchEvent& touchEvent );
530 * @brief This method should be overridden by deriving classes when they wish to respond
531 * the accessibility up and down action (i.e. value change of slider control).
534 * @param[in] isIncrease Whether the value should be increased or decreased
535 * @return true if the value changed action has been consumed by this control
537 virtual bool OnAccessibilityValueChange( bool isIncrease );
540 * @brief This method should be overridden by deriving classes when they wish to respond
541 * the accessibility zoom action.
544 * @return true if the zoom action has been consumed by this control
546 virtual bool OnAccessibilityZoom();
551 * @brief Called when the control gains key input focus.
553 * Should be overridden by derived classes if they need to customize what happens when focus is gained.
556 virtual void OnKeyInputFocusGained();
559 * @brief Called when the control loses key input focus.
561 * Should be overridden by derived classes if they need to customize what happens when focus is lost.
564 virtual void OnKeyInputFocusLost();
567 * @brief Gets the next keyboard focusable actor in this control towards the given direction.
569 * A control needs to override this function in order to support two dimensional keyboard navigation.
571 * @param[in] currentFocusedActor The current focused actor
572 * @param[in] direction The direction to move the focus towards
573 * @param[in] loopEnabled Whether the focus movement should be looped within the control
574 * @return The next keyboard focusable actor in this control or an empty handle if no actor can be focused
576 virtual Actor GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled );
579 * @brief Informs this control that its chosen focusable actor will be focused.
581 * This allows the application to perform any actions if wishes
582 * before the focus is actually moved to the chosen actor.
585 * @param[in] commitedFocusableActor The commited focusable actor
587 virtual void OnKeyboardFocusChangeCommitted( Actor commitedFocusableActor );
590 * @brief This method is called when the control has enter pressed on it.
592 * Derived classes should override this to perform custom actions.
594 * @return true if this control supported this action
596 virtual bool OnKeyboardEnter();
601 * @brief Called whenever a pinch gesture is detected on this control.
603 * This can be overridden by deriving classes when pinch detection
604 * is enabled. The default behaviour is to scale the control by the
608 * @param[in] pinch The pinch gesture
609 * @note If overridden, then the default behavior will not occur.
610 * @note Pinch detection should be enabled via EnableGestureDetection().
611 * @see EnableGestureDetection
613 virtual void OnPinch( const PinchGesture& pinch );
616 * @brief Called whenever a pan gesture is detected on this control.
618 * This should be overridden by deriving classes when pan detection
622 * @param[in] pan The pan gesture
623 * @note There is no default behavior with panning.
624 * @note Pan detection should be enabled via EnableGestureDetection().
625 * @see EnableGestureDetection
627 virtual void OnPan( const PanGesture& pan );
630 * @brief Called whenever a tap gesture is detected on this control.
632 * This should be overridden by deriving classes when tap detection
636 * @param[in] tap The tap gesture
637 * @note There is no default behavior with a tap.
638 * @note Tap detection should be enabled via EnableGestureDetection().
639 * @see EnableGestureDetection
641 virtual void OnTap( const TapGesture& tap );
644 * @brief Called whenever a long press gesture is detected on this control.
646 * This should be overridden by deriving classes when long press
647 * detection is enabled.
650 * @param[in] longPress The long press gesture
651 * @note There is no default behaviour associated with a long press.
652 * @note Long press detection should be enabled via EnableGestureDetection().
653 * @see EnableGestureDetection
655 virtual void OnLongPress( const LongPressGesture& longPress );
657 // From ConnectionTrackerInterface
660 * @copydoc ConnectionTrackerInterface::SignalConnected
662 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
665 * @copydoc ConnectionTrackerInterface::SignalDisconnected
667 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
670 * @brief Retrieves the extension for this control.
673 * @return The extension if available, NULL otherwise
675 virtual Extension* GetControlExtension()
684 DALI_INTERNAL Control( const Control& );
685 DALI_INTERNAL Control& operator=( const Control& );
688 class Impl; // Class declaration is public so we can internally add devel API's to the Controls Impl
697 * @brief Gets implementation from the handle.
701 * @return Implementation
702 * @pre handle is initialized and points to a control
704 DALI_TOOLKIT_API Internal::Control& GetImplementation( Dali::Toolkit::Control& handle );
707 * @brief Gets implementation from the handle.
711 * @return Implementation
712 * @pre Handle is initialized and points to a control.
714 DALI_TOOLKIT_API const Internal::Control& GetImplementation( const Dali::Toolkit::Control& handle );
716 } // namespace Internal
721 } // namespace Toolkit
725 #endif // DALI_TOOLKIT_CONTROL_IMPL_H