1 #ifndef DALI_TOOLKIT_CONTROL_IMPL_H
2 #define DALI_TOOLKIT_CONTROL_IMPL_H
5 * Copyright (c) 2021 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/animation/alpha-function.h>
24 #include <dali/public-api/animation/time-period.h>
25 #include <dali/public-api/events/long-press-gesture.h>
26 #include <dali/public-api/events/pan-gesture.h>
27 #include <dali/public-api/events/pinch-gesture.h>
28 #include <dali/public-api/events/tap-gesture.h>
29 #include <dali/public-api/object/property-index-ranges.h>
30 #include <dali/public-api/object/type-info.h>
33 #include <dali-toolkit/public-api/controls/control.h>
40 * @addtogroup dali_toolkit_controls
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.
57 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 * @brief Sets the background with a property map.
104 * @param[in] map The background property map
106 void SetBackground(const Property::Map& map);
109 * @copydoc Dali::Toolkit::Control::ClearBackground
111 void ClearBackground();
116 * @brief Allows deriving classes to enable any of the gesture detectors that are available.
118 * Gesture detection can be enabled one at a time or in bitwise format as shown:
120 * EnableGestureDetection(GestureType::Value(GestureType::PINCH | GestureType::TAP | GestureType::PAN));
123 * @param[in] type The gesture type(s) to enable
125 void EnableGestureDetection(GestureType::Value type);
128 * @brief Allows deriving classes to disable any of the gesture detectors.
130 * Like EnableGestureDetection, this can also be called using bitwise or.
132 * @param[in] type The gesture type(s) to disable
133 * @see EnableGetureDetection
135 void DisableGestureDetection(GestureType::Value type);
138 * @brief If deriving classes wish to fine tune pinch gesture
139 * detection, then they can access the gesture detector through this
140 * API and modify the detection.
143 * @return The pinch gesture detector
144 * @pre Pinch detection should have been enabled via EnableGestureDetection().
145 * @see EnableGestureDetection
147 PinchGestureDetector GetPinchGestureDetector() const;
150 * @brief If deriving classes wish to fine tune pan gesture
151 * detection, then they can access the gesture detector through this
152 * API and modify the detection.
155 * @return The pan gesture detector
156 * @pre Pan detection should have been enabled via EnableGestureDetection().
157 * @see EnableGestureDetection
159 PanGestureDetector GetPanGestureDetector() const;
162 * @brief If deriving classes wish to fine tune tap gesture
163 * detection, then they can access the gesture detector through this
164 * API and modify the detection.
167 * @return The tap gesture detector
168 * @pre Tap detection should have been enabled via EnableGestureDetection().
169 * @see EnableGestureDetection
171 TapGestureDetector GetTapGestureDetector() const;
174 * @brief If deriving classes wish to fine tune long press gesture
175 * detection, then they can access the gesture detector through this
176 * API and modify the detection.
179 * @return The long press gesture detector
180 * @pre Long press detection should have been enabled via EnableGestureDetection().
181 * @see EnableGestureDetection
183 LongPressGestureDetector GetLongPressGestureDetector() const;
185 // Keyboard Navigation
188 * @brief Sets whether this control supports two dimensional
189 * keyboard navigation (i.e. whether it knows how to handle the
190 * keyboard focus movement between its child actors).
192 * The control doesn't support it by default.
194 * @param[in] isSupported Whether this control supports two dimensional keyboard navigation
196 void SetKeyboardNavigationSupport(bool isSupported);
199 * @brief Gets whether this control supports two dimensional keyboard navigation.
202 * @return true if this control supports two dimensional keyboard navigation
204 bool IsKeyboardNavigationSupported();
209 * @copydoc Toolkit::Control::SetKeyInputFocus()
211 void SetKeyInputFocus();
214 * @copydoc Toolkit::Control::HasKeyInputFocus()
216 bool HasKeyInputFocus();
219 * @copydoc Toolkit::Control::ClearKeyInputFocus()
221 void ClearKeyInputFocus();
226 * @brief Sets whether this control is a focus group for keyboard navigation.
228 * (i.e. the scope of keyboard focus movement
229 * can be limited to its child actors). The control is not a focus group by default.
231 * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation
233 void SetAsKeyboardFocusGroup(bool isFocusGroup);
236 * @brief Gets whether this control is a focus group for keyboard navigation.
239 * @return true if this control is set as a focus group for keyboard navigation
241 bool IsKeyboardFocusGroup();
245 * @brief Called by the AccessibilityManager to activate the Control.
248 DALI_INTERNAL void AccessibilityActivate();
251 * @brief Called by the KeyboardFocusManager.
254 DALI_INTERNAL void KeyboardEnter();
261 * @copydoc Dali::Toolkit::Control::KeyEventSignal()
263 Toolkit::Control::KeyEventSignalType& KeyEventSignal();
266 * @copydoc Dali::Toolkit::Control::KeyInputFocusGainedSignal()
268 Toolkit::Control::KeyInputFocusSignalType& KeyInputFocusGainedSignal();
271 * @copydoc Dali::Toolkit::Control::KeyInputFocusLostSignal()
273 Toolkit::Control::KeyInputFocusSignalType& KeyInputFocusLostSignal();
277 * @brief Called by the KeyInputFocusManager to emit key event signals.
280 * @param[in] event The key event
281 * @return True if the event was consumed
283 DALI_INTERNAL bool EmitKeyEventSignal(const KeyEvent& event);
286 protected: // For derived classes to call
288 * @brief Emits KeyInputFocusGained signal if true else emits KeyInputFocusLost signal.
290 * Should be called last by the control after it acts on the Input Focus change.
293 * @param[in] focusGained True if gained, False if lost
295 void EmitKeyInputFocusSignal(bool focusGained);
297 protected: // From CustomActorImpl
299 * @copydoc CustomActorImpl::OnSceneConnection()
300 * @note If overridden, then an up-call to Control::OnSceneConnection MUST be made at the end.
302 void OnSceneConnection(int depth) override;
305 * @copydoc CustomActorImpl::OnSceneDisconnection()
306 * @note If overridden, then an up-call to Control::OnSceneDisconnection MUST be made at the end.
308 void OnSceneDisconnection() override;
311 * @copydoc CustomActorImpl::OnChildAdd()
312 * @note If overridden, then an up-call to Control::OnChildAdd MUST be made at the end.
314 void OnChildAdd(Actor& child) override;
317 * @copydoc CustomActorImpl::OnChildRemove()
318 * @note If overridden, then an up-call to Control::OnChildRemove MUST be made at the end.
320 void OnChildRemove(Actor& child) override;
323 * @copydoc CustomActorImpl::OnPropertySet()
324 * @note If overridden, then an up-call to Control::OnChildRemove MUST be made at the end.
326 void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
329 * @copydoc CustomActorImpl::OnSizeSet()
330 * @note If overridden, then an up-call to Control::OnSizeSet MUST be made at the end.
332 void OnSizeSet(const Vector3& targetSize) override;
335 * @copydoc CustomActorImpl::OnSizeAnimation()
336 * @note If overridden, then an up-call to Control::OnSizeAnimation MUST be made at the end.
338 void OnSizeAnimation(Animation& animation, const Vector3& targetSize) override;
341 * @copydoc CustomActorImpl::OnRelayout()
343 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
346 * @copydoc CustomActorImpl::OnSetResizePolicy()
348 void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension) override;
351 * @copydoc CustomActorImpl::GetNaturalSize()
353 Vector3 GetNaturalSize() override;
356 * @copydoc CustomActorImpl::CalculateChildSize()
358 float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension) override;
361 * @copydoc CustomActorImpl::GetHeightForWidth()
363 float GetHeightForWidth(float width) override;
366 * @copydoc CustomActorImpl::GetWidthForHeight()
368 float GetWidthForHeight(float height) override;
371 * @copydoc CustomActorImpl::RelayoutDependentOnChildren()
373 bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS) override;
376 * @copydoc CustomActorImpl::OnCalculateRelayoutSize()
378 void OnCalculateRelayoutSize(Dimension::Type dimension) override;
381 * @copydoc CustomActorImpl::OnLayoutNegotiated()
383 void OnLayoutNegotiated(float size, Dimension::Type dimension) override;
385 protected: // Helpers for deriving classes
389 * @brief Flags for the constructor.
392 enum ControlBehaviour
394 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
395 NOT_IN_USE_1 = 1 << (CustomActorImpl::ACTOR_FLAG_COUNT + 0),
396 REQUIRES_KEYBOARD_NAVIGATION_SUPPORT = 1 << (CustomActorImpl::ACTOR_FLAG_COUNT + 1), ///< True if needs to support keyboard navigation @SINCE_1_0.0
397 DISABLE_STYLE_CHANGE_SIGNALS = 1 << (CustomActorImpl::ACTOR_FLAG_COUNT + 2), ///< True if control should not monitor style change signals @SINCE_1_2_10
399 LAST_CONTROL_BEHAVIOUR_FLAG
402 static const int CONTROL_BEHAVIOUR_FLAG_COUNT = Log<LAST_CONTROL_BEHAVIOUR_FLAG - 1>::value + 1; ///< Total count of flags
405 * @brief Control constructor.
408 * @param[in] behaviourFlags Behavioural flags from ControlBehaviour enum
410 Control(ControlBehaviour behaviourFlags);
413 * @brief Second phase initialization.
418 public: // API for derived classes to override
422 * @brief This method is called after the Control has been initialized.
424 * Derived classes should do any second phase initialization by overriding this method.
427 virtual void OnInitialize();
432 * @brief This method should be overridden by deriving classes requiring notifications when the style changes.
435 * @param[in] styleManager The StyleManager object
436 * @param[in] change Information denoting what has changed
438 virtual void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change);
443 * @brief This method is called when the control is accessibility activated.
445 * Derived classes should override this to perform custom accessibility activation.
447 * @return true if this control can perform accessibility activation
449 virtual bool OnAccessibilityActivated();
452 * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
456 * @param[in] gesture The pan gesture
457 * @return true if the pan gesture has been consumed by this control
459 virtual bool OnAccessibilityPan(PanGesture gesture);
462 * @brief This method should be overridden by deriving classes when they wish to respond
463 * the accessibility up and down action (i.e. value change of slider control).
466 * @param[in] isIncrease Whether the value should be increased or decreased
467 * @return true if the value changed action has been consumed by this control
469 virtual bool OnAccessibilityValueChange(bool isIncrease);
472 * @brief This method should be overridden by deriving classes when they wish to respond
473 * the accessibility zoom action.
476 * @return true if the zoom action has been consumed by this control
478 virtual bool OnAccessibilityZoom();
483 * @brief Called when the control gains key input focus.
485 * Should be overridden by derived classes if they need to customize what happens when focus is gained.
488 virtual void OnKeyInputFocusGained();
491 * @brief Called when the control loses key input focus.
493 * Should be overridden by derived classes if they need to customize what happens when focus is lost.
496 virtual void OnKeyInputFocusLost();
499 * @brief Gets the next keyboard focusable actor in this control towards the given direction.
501 * A control needs to override this function in order to support two dimensional keyboard navigation.
503 * @param[in] currentFocusedActor The current focused actor
504 * @param[in] direction The direction to move the focus towards
505 * @param[in] loopEnabled Whether the focus movement should be looped within the control
506 * @return The next keyboard focusable actor in this control or an empty handle if no actor can be focused
508 virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled);
511 * @brief Informs this control that its chosen focusable actor will be focused.
513 * This allows the application to perform any actions if wishes
514 * before the focus is actually moved to the chosen actor.
517 * @param[in] commitedFocusableActor The commited focusable actor
519 virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor);
522 * @brief This method is called when the control has enter pressed on it.
524 * Derived classes should override this to perform custom actions.
526 * @return true if this control supported this action
528 virtual bool OnKeyboardEnter();
531 * @brief Called after a key-event is received by the actor that has had its focus set.
534 * @param[in] event The Key Event
535 * @return True if the event should be consumed
537 virtual bool OnKeyEvent(const KeyEvent& event);
542 * @brief Called whenever a pinch gesture is detected on this control.
544 * This can be overridden by deriving classes when pinch detection
545 * is enabled. The default behaviour is to scale the control by the
549 * @param[in] pinch The pinch gesture
550 * @note If overridden, then the default behavior will not occur.
551 * @note Pinch detection should be enabled via EnableGestureDetection().
552 * @see EnableGestureDetection
554 virtual void OnPinch(const PinchGesture& pinch);
557 * @brief Called whenever a pan gesture is detected on this control.
559 * This should be overridden by deriving classes when pan detection
563 * @param[in] pan The pan gesture
564 * @note There is no default behavior with panning.
565 * @note Pan detection should be enabled via EnableGestureDetection().
566 * @see EnableGestureDetection
568 virtual void OnPan(const PanGesture& pan);
571 * @brief Called whenever a tap gesture is detected on this control.
573 * This should be overridden by deriving classes when tap detection
577 * @param[in] tap The tap gesture
578 * @note There is no default behavior with a tap.
579 * @note Tap detection should be enabled via EnableGestureDetection().
580 * @see EnableGestureDetection
582 virtual void OnTap(const TapGesture& tap);
585 * @brief Called whenever a long press gesture is detected on this control.
587 * This should be overridden by deriving classes when long press
588 * detection is enabled.
591 * @param[in] longPress The long press gesture
592 * @note There is no default behaviour associated with a long press.
593 * @note Long press detection should be enabled via EnableGestureDetection().
594 * @see EnableGestureDetection
596 virtual void OnLongPress(const LongPressGesture& longPress);
598 // From ConnectionTrackerInterface
601 * @copydoc ConnectionTrackerInterface::SignalConnected
603 void SignalConnected(SlotObserver* slotObserver, CallbackBase* callback) override;
606 * @copydoc ConnectionTrackerInterface::SignalDisconnected
608 void SignalDisconnected(SlotObserver* slotObserver, CallbackBase* callback) override;
611 * @brief Retrieves the extension for this control.
614 * @return The extension if available, NULL otherwise
616 virtual Extension* GetControlExtension()
624 * @brief Make visual transition from source control to destination control about specific Visual.
625 * If both of source and destination control have same visual index, than generates information for the transition of this Control.
627 * @param[out] sourcePropertyMap Source property map to be applied on this Control.
628 * @param[out] destinationPropertyMap Destination property map to be applied on this Control.
629 * @param[in] source Source control of the animation.
630 * @param[in] destination Destination control of the animation.
631 * @param[in] visualIndex Property::Index to make animation.
633 void MakeVisualTransition(Dali::Property::Map& sourcePropertyMap, Dali::Property::Map& destinationPropertyMap,
634 Dali::Toolkit::Control source, Dali::Toolkit::Control destination, Dali::Property::Index visualIndex);
637 * @brief Retrieves source and destination visual properties for the Transition of this Control.
638 * The properties of this Control will be transitioned from the propeties of source Control to that of destination control.
639 * If a property value is different between source and destination Control,
640 * the property information of each Control will be included in sourceProperties and destinationProperties.
642 * @param[out] sourceProperties Source property list to be applied on this Control.
643 * @param[out] destinationProperties Destination property list to be applied on this Control.
644 * @param[in] source Source control of the animation.
645 * @param[in] destination Destination control of the animation.
647 * @note This method do not handle Actor properties.
648 * And the size and order of the sourceProperties and destinationProperties must be synchronized.
650 virtual void OnCreateTransitions(std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& sourceProperties,
651 std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& destinationProperties,
652 Dali::Toolkit::Control source,
653 Dali::Toolkit::Control destination)
658 * @brief Update visual properties.
659 * @param[in] properties Property list to be used to update visual properties of this Control.
661 virtual void OnUpdateVisualProperties(const std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& properties)
668 // Not copyable or movable
669 DALI_INTERNAL Control(const Control&) = delete; ///< Deleted copy constructor.
670 DALI_INTERNAL Control(Control&&) = delete; ///< Deleted move constructor.
671 DALI_INTERNAL Control& operator=(const Control&) = delete; ///< Deleted copy assignment operator.
672 DALI_INTERNAL Control& operator=(Control&&) = delete; ///< Deleted move assignment operator.
675 class DALI_INTERNAL Impl; // Class declaration is public so we can internally add devel API's to the Controls Impl
683 * @brief Gets implementation from the handle.
687 * @return Implementation
688 * @pre handle is initialized and points to a control
690 DALI_TOOLKIT_API Internal::Control& GetImplementation(Dali::Toolkit::Control& handle);
693 * @brief Gets implementation from the handle.
697 * @return Implementation
698 * @pre Handle is initialized and points to a control.
700 DALI_TOOLKIT_API const Internal::Control& GetImplementation(const Dali::Toolkit::Control& handle);
702 } // namespace Internal
707 } // namespace Toolkit
711 #endif // DALI_TOOLKIT_CONTROL_IMPL_H