1 #ifndef DALI_TOOLKIT_CONTROL_IMPL_H
2 #define DALI_TOOLKIT_CONTROL_IMPL_H
5 * Copyright (c) 2020 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>
38 * @addtogroup dali_toolkit_controls
47 * @brief This is the internal base class for all controls.
49 * It will provide some common functionality required by all controls.
50 * Implements ConnectionTrackerInterface so that signals (typically connected to member functions) will
51 * be disconnected automatically when the control is destroyed.
54 class DALI_TOOLKIT_API Control : public CustomActorImpl, public ConnectionTrackerInterface
57 class Extension; ///< Forward declare future extension interface
59 // Creation & Destruction
62 * @brief Creates a new ControlImpl instance that does not require touch by default.
64 * If touch is required, then the user can connect to this class' touch signal.
66 * @return A handle to the ControlImpl instance
68 static Toolkit::Control New();
72 * @brief Virtual destructor.
81 * @copydoc Dali::Toolkit::Control::SetStyleName
83 void SetStyleName(const std::string& styleName);
86 * @copydoc Dali::Toolkit::Control::GetStyleName
88 const std::string& GetStyleName() const;
93 * @copydoc Dali::Toolkit::Control::SetBackgroundColor
95 void SetBackgroundColor(const Vector4& color);
98 * @brief Sets the background with a property map.
101 * @param[in] map The background property map
103 void SetBackground(const Property::Map& map);
106 * @copydoc Dali::Toolkit::Control::ClearBackground
108 void ClearBackground();
113 * @brief Allows deriving classes to enable any of the gesture detectors that are available.
115 * Gesture detection can be enabled one at a time or in bitwise format as shown:
117 * EnableGestureDetection(GestureType::Value(GestureType::PINCH | GestureType::TAP | GestureType::PAN));
120 * @param[in] type The gesture type(s) to enable
122 void EnableGestureDetection(GestureType::Value type);
125 * @brief Allows deriving classes to disable any of the gesture detectors.
127 * Like EnableGestureDetection, this can also be called using bitwise or.
129 * @param[in] type The gesture type(s) to disable
130 * @see EnableGetureDetection
132 void DisableGestureDetection(GestureType::Value type);
135 * @brief If deriving classes wish to fine tune pinch gesture
136 * detection, then they can access the gesture detector through this
137 * API and modify the detection.
140 * @return The pinch gesture detector
141 * @pre Pinch detection should have been enabled via EnableGestureDetection().
142 * @see EnableGestureDetection
144 PinchGestureDetector GetPinchGestureDetector() const;
147 * @brief If deriving classes wish to fine tune pan gesture
148 * detection, then they can access the gesture detector through this
149 * API and modify the detection.
152 * @return The pan gesture detector
153 * @pre Pan detection should have been enabled via EnableGestureDetection().
154 * @see EnableGestureDetection
156 PanGestureDetector GetPanGestureDetector() const;
159 * @brief If deriving classes wish to fine tune tap gesture
160 * detection, then they can access the gesture detector through this
161 * API and modify the detection.
164 * @return The tap gesture detector
165 * @pre Tap detection should have been enabled via EnableGestureDetection().
166 * @see EnableGestureDetection
168 TapGestureDetector GetTapGestureDetector() const;
171 * @brief If deriving classes wish to fine tune long press gesture
172 * detection, then they can access the gesture detector through this
173 * API and modify the detection.
176 * @return The long press gesture detector
177 * @pre Long press detection should have been enabled via EnableGestureDetection().
178 * @see EnableGestureDetection
180 LongPressGestureDetector GetLongPressGestureDetector() const;
182 // Keyboard Navigation
185 * @brief Sets whether this control supports two dimensional
186 * keyboard navigation (i.e. whether it knows how to handle the
187 * keyboard focus movement between its child actors).
189 * The control doesn't support it by default.
191 * @param[in] isSupported Whether this control supports two dimensional keyboard navigation
193 void SetKeyboardNavigationSupport(bool isSupported);
196 * @brief Gets whether this control supports two dimensional keyboard navigation.
199 * @return true if this control supports two dimensional keyboard navigation
201 bool IsKeyboardNavigationSupported();
206 * @copydoc Toolkit::Control::SetKeyInputFocus()
208 void SetKeyInputFocus();
211 * @copydoc Toolkit::Control::HasKeyInputFocus()
213 bool HasKeyInputFocus();
216 * @copydoc Toolkit::Control::ClearKeyInputFocus()
218 void ClearKeyInputFocus();
223 * @brief Sets whether this control is a focus group for keyboard navigation.
225 * (i.e. the scope of keyboard focus movement
226 * can be limited to its child actors). The control is not a focus group by default.
228 * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation
230 void SetAsKeyboardFocusGroup(bool isFocusGroup);
233 * @brief Gets whether this control is a focus group for keyboard navigation.
236 * @return true if this control is set as a focus group for keyboard navigation
238 bool IsKeyboardFocusGroup();
242 * @brief Called by the AccessibilityManager to activate the Control.
245 DALI_INTERNAL void AccessibilityActivate();
248 * @brief Called by the KeyboardFocusManager.
251 DALI_INTERNAL void KeyboardEnter();
257 * @copydoc Dali::Toolkit::Control::KeyEventSignal()
259 Toolkit::Control::KeyEventSignalType& KeyEventSignal();
262 * @copydoc Dali::Toolkit::Control::KeyInputFocusGainedSignal()
264 Toolkit::Control::KeyInputFocusSignalType& KeyInputFocusGainedSignal();
267 * @copydoc Dali::Toolkit::Control::KeyInputFocusLostSignal()
269 Toolkit::Control::KeyInputFocusSignalType& KeyInputFocusLostSignal();
273 * @brief Called by the KeyInputFocusManager to emit key event signals.
276 * @param[in] event The key event
277 * @return True if the event was consumed
279 DALI_INTERNAL bool EmitKeyEventSignal(const KeyEvent& event);
282 protected: // For derived classes to call
284 * @brief Emits KeyInputFocusGained signal if true else emits KeyInputFocusLost signal.
286 * Should be called last by the control after it acts on the Input Focus change.
289 * @param[in] focusGained True if gained, False if lost
291 void EmitKeyInputFocusSignal(bool focusGained);
293 protected: // From CustomActorImpl
295 * @copydoc CustomActorImpl::OnSceneConnection()
296 * @note If overridden, then an up-call to Control::OnSceneConnection MUST be made at the end.
298 void OnSceneConnection(int depth) override;
301 * @copydoc CustomActorImpl::OnSceneDisconnection()
302 * @note If overridden, then an up-call to Control::OnSceneDisconnection MUST be made at the end.
304 void OnSceneDisconnection() override;
307 * @copydoc CustomActorImpl::OnChildAdd()
308 * @note If overridden, then an up-call to Control::OnChildAdd MUST be made at the end.
310 void OnChildAdd(Actor& child) override;
313 * @copydoc CustomActorImpl::OnChildRemove()
314 * @note If overridden, then an up-call to Control::OnChildRemove MUST be made at the end.
316 void OnChildRemove(Actor& child) override;
319 * @copydoc CustomActorImpl::OnPropertySet()
320 * @note If overridden, then an up-call to Control::OnChildRemove MUST be made at the end.
322 void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
325 * @copydoc CustomActorImpl::OnSizeSet()
326 * @note If overridden, then an up-call to Control::OnSizeSet MUST be made at the end.
328 void OnSizeSet(const Vector3& targetSize) override;
331 * @copydoc CustomActorImpl::OnSizeAnimation()
332 * @note If overridden, then an up-call to Control::OnSizeAnimation MUST be made at the end.
334 void OnSizeAnimation(Animation& animation, const Vector3& targetSize) override;
337 * @copydoc CustomActorImpl::OnRelayout()
339 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
342 * @copydoc CustomActorImpl::OnSetResizePolicy()
344 void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension) override;
347 * @copydoc CustomActorImpl::GetNaturalSize()
349 Vector3 GetNaturalSize() override;
352 * @copydoc CustomActorImpl::CalculateChildSize()
354 float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension) override;
357 * @copydoc CustomActorImpl::GetHeightForWidth()
359 float GetHeightForWidth(float width) override;
362 * @copydoc CustomActorImpl::GetWidthForHeight()
364 float GetWidthForHeight(float height) override;
367 * @copydoc CustomActorImpl::RelayoutDependentOnChildren()
369 bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS) override;
372 * @copydoc CustomActorImpl::OnCalculateRelayoutSize()
374 void OnCalculateRelayoutSize(Dimension::Type dimension) override;
377 * @copydoc CustomActorImpl::OnLayoutNegotiated()
379 void OnLayoutNegotiated(float size, Dimension::Type dimension) override;
381 protected: // Helpers for deriving classes
385 * @brief Flags for the constructor.
388 enum ControlBehaviour
390 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
392 REQUIRES_KEYBOARD_NAVIGATION_SUPPORT = 1 << (CustomActorImpl::ACTOR_FLAG_COUNT + 0), ///< True if needs to support keyboard navigation @SINCE_1_0.0
394 DISABLE_STYLE_CHANGE_SIGNALS = 1 << (CustomActorImpl::ACTOR_FLAG_COUNT + 1), ///< True if control should not monitor style change signals @SINCE_1_2_10
396 LAST_CONTROL_BEHAVIOUR_FLAG
399 static const int CONTROL_BEHAVIOUR_FLAG_COUNT = Log<LAST_CONTROL_BEHAVIOUR_FLAG - 1>::value + 1; ///< Total count of flags
402 * @brief Control constructor.
405 * @param[in] behaviourFlags Behavioural flags from ControlBehaviour enum
407 Control(ControlBehaviour behaviourFlags);
410 * @brief Second phase initialization.
415 public: // API for derived classes to override
419 * @brief This method is called after the Control has been initialized.
421 * Derived classes should do any second phase initialization by overriding this method.
424 virtual void OnInitialize();
429 * @brief This method should be overridden by deriving classes requiring notifications when the style changes.
432 * @param[in] styleManager The StyleManager object
433 * @param[in] change Information denoting what has changed
435 virtual void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change);
440 * @brief This method is called when the control is accessibility activated.
442 * Derived classes should override this to perform custom accessibility activation.
444 * @return true if this control can perform accessibility activation
446 virtual bool OnAccessibilityActivated();
449 * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
453 * @param[in] gesture The pan gesture
454 * @return true if the pan gesture has been consumed by this control
456 virtual bool OnAccessibilityPan(PanGesture gesture);
459 * @brief This method should be overridden by deriving classes when they wish to respond
460 * the accessibility up and down action (i.e. value change of slider control).
463 * @param[in] isIncrease Whether the value should be increased or decreased
464 * @return true if the value changed action has been consumed by this control
466 virtual bool OnAccessibilityValueChange(bool isIncrease);
469 * @brief This method should be overridden by deriving classes when they wish to respond
470 * the accessibility zoom action.
473 * @return true if the zoom action has been consumed by this control
475 virtual bool OnAccessibilityZoom();
480 * @brief Called when the control gains key input focus.
482 * Should be overridden by derived classes if they need to customize what happens when focus is gained.
485 virtual void OnKeyInputFocusGained();
488 * @brief Called when the control loses key input focus.
490 * Should be overridden by derived classes if they need to customize what happens when focus is lost.
493 virtual void OnKeyInputFocusLost();
496 * @brief Gets the next keyboard focusable actor in this control towards the given direction.
498 * A control needs to override this function in order to support two dimensional keyboard navigation.
500 * @param[in] currentFocusedActor The current focused actor
501 * @param[in] direction The direction to move the focus towards
502 * @param[in] loopEnabled Whether the focus movement should be looped within the control
503 * @return The next keyboard focusable actor in this control or an empty handle if no actor can be focused
505 virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled);
508 * @brief Informs this control that its chosen focusable actor will be focused.
510 * This allows the application to perform any actions if wishes
511 * before the focus is actually moved to the chosen actor.
514 * @param[in] commitedFocusableActor The commited focusable actor
516 virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor);
519 * @brief This method is called when the control has enter pressed on it.
521 * Derived classes should override this to perform custom actions.
523 * @return true if this control supported this action
525 virtual bool OnKeyboardEnter();
528 * @brief Called after a key-event is received by the actor that has had its focus set.
531 * @param[in] event The Key Event
532 * @return True if the event should be consumed
534 virtual bool OnKeyEvent(const KeyEvent& event);
539 * @brief Called whenever a pinch gesture is detected on this control.
541 * This can be overridden by deriving classes when pinch detection
542 * is enabled. The default behaviour is to scale the control by the
546 * @param[in] pinch The pinch gesture
547 * @note If overridden, then the default behavior will not occur.
548 * @note Pinch detection should be enabled via EnableGestureDetection().
549 * @see EnableGestureDetection
551 virtual void OnPinch(const PinchGesture& pinch);
554 * @brief Called whenever a pan gesture is detected on this control.
556 * This should be overridden by deriving classes when pan detection
560 * @param[in] pan The pan gesture
561 * @note There is no default behavior with panning.
562 * @note Pan detection should be enabled via EnableGestureDetection().
563 * @see EnableGestureDetection
565 virtual void OnPan(const PanGesture& pan);
568 * @brief Called whenever a tap gesture is detected on this control.
570 * This should be overridden by deriving classes when tap detection
574 * @param[in] tap The tap gesture
575 * @note There is no default behavior with a tap.
576 * @note Tap detection should be enabled via EnableGestureDetection().
577 * @see EnableGestureDetection
579 virtual void OnTap(const TapGesture& tap);
582 * @brief Called whenever a long press gesture is detected on this control.
584 * This should be overridden by deriving classes when long press
585 * detection is enabled.
588 * @param[in] longPress The long press gesture
589 * @note There is no default behaviour associated with a long press.
590 * @note Long press detection should be enabled via EnableGestureDetection().
591 * @see EnableGestureDetection
593 virtual void OnLongPress(const LongPressGesture& longPress);
595 // From ConnectionTrackerInterface
598 * @copydoc ConnectionTrackerInterface::SignalConnected
600 void SignalConnected(SlotObserver* slotObserver, CallbackBase* callback) override;
603 * @copydoc ConnectionTrackerInterface::SignalDisconnected
605 void SignalDisconnected(SlotObserver* slotObserver, CallbackBase* callback) override;
608 * @brief Retrieves the extension for this control.
611 * @return The extension if available, NULL otherwise
613 virtual Extension* GetControlExtension()
621 // Not copyable or movable
622 DALI_INTERNAL Control(const Control&) = delete; ///< Deleted copy constructor.
623 DALI_INTERNAL Control(Control&&) = delete; ///< Deleted move constructor.
624 DALI_INTERNAL Control& operator=(const Control&) = delete; ///< Deleted copy assignment operator.
625 DALI_INTERNAL Control& operator=(Control&&) = delete; ///< Deleted move assignment operator.
628 class DALI_INTERNAL Impl; // Class declaration is public so we can internally add devel API's to the Controls Impl
636 * @brief Gets implementation from the handle.
640 * @return Implementation
641 * @pre handle is initialized and points to a control
643 DALI_TOOLKIT_API Internal::Control& GetImplementation(Dali::Toolkit::Control& handle);
646 * @brief Gets implementation from the handle.
650 * @return Implementation
651 * @pre Handle is initialized and points to a control.
653 DALI_TOOLKIT_API const Internal::Control& GetImplementation(const Dali::Toolkit::Control& handle);
655 } // namespace Internal
660 } // namespace Toolkit
664 #endif // DALI_TOOLKIT_CONTROL_IMPL_H