1 #ifndef DALI_TOOLKIT_CONTROL_IMPL_H
2 #define DALI_TOOLKIT_CONTROL_IMPL_H
5 * Copyright (c) 2023 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
46 namespace DevelControl
48 class ControlAccessible;
50 } // namespace DevelControl
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_TOOLKIT_API Control : public CustomActorImpl, public ConnectionTrackerInterface
65 class Extension; ///< Forward declare future extension interface
67 // Creation & Destruction
69 * @brief Creates 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.
73 * @return A handle to the ControlImpl instance
75 static Toolkit::Control New();
79 * @brief Virtual destructor.
88 * @copydoc Dali::Toolkit::Control::SetStyleName
90 void SetStyleName(const std::string& styleName);
93 * @copydoc Dali::Toolkit::Control::GetStyleName
95 const std::string& GetStyleName() const;
100 * @copydoc Dali::Toolkit::Control::SetBackgroundColor
102 void SetBackgroundColor(const Vector4& color);
105 * @brief Sets the background with a property map.
108 * @param[in] map The background property map
110 void SetBackground(const Property::Map& map);
113 * @copydoc Dali::Toolkit::Control::ClearBackground
115 void ClearBackground();
118 * @brief Called when resources of control are ready. this api does not request relayout.
120 void SetResourceReady();
125 * @brief Gets the Accessible object that represents this control.
127 * This method calls CreateAccessibleObject() if necessary, so a non-null return is expected.
129 * @return The Accessible object
131 * @see CreateAccessibleObject()
133 Toolkit::DevelControl::ControlAccessible* GetAccessibleObject();
138 * @brief Allows deriving classes to enable any of the gesture detectors that are available.
140 * Gesture detection can be enabled one at a time or in bitwise format as shown:
142 * EnableGestureDetection(GestureType::Value(GestureType::PINCH | GestureType::TAP | GestureType::PAN));
145 * @param[in] type The gesture type(s) to enable
147 void EnableGestureDetection(GestureType::Value type);
150 * @brief Allows deriving classes to disable any of the gesture detectors.
152 * Like EnableGestureDetection, this can also be called using bitwise or.
154 * @param[in] type The gesture type(s) to disable
155 * @see EnableGetureDetection
157 void DisableGestureDetection(GestureType::Value type);
160 * @brief If deriving classes wish to fine tune pinch gesture
161 * detection, then they can access the gesture detector through this
162 * API and modify the detection.
165 * @return The pinch gesture detector
166 * @pre Pinch detection should have been enabled via EnableGestureDetection().
167 * @see EnableGestureDetection
169 PinchGestureDetector GetPinchGestureDetector() const;
172 * @brief If deriving classes wish to fine tune pan gesture
173 * detection, then they can access the gesture detector through this
174 * API and modify the detection.
177 * @return The pan gesture detector
178 * @pre Pan detection should have been enabled via EnableGestureDetection().
179 * @see EnableGestureDetection
181 PanGestureDetector GetPanGestureDetector() const;
184 * @brief If deriving classes wish to fine tune tap gesture
185 * detection, then they can access the gesture detector through this
186 * API and modify the detection.
189 * @return The tap gesture detector
190 * @pre Tap detection should have been enabled via EnableGestureDetection().
191 * @see EnableGestureDetection
193 TapGestureDetector GetTapGestureDetector() const;
196 * @brief If deriving classes wish to fine tune long press gesture
197 * detection, then they can access the gesture detector through this
198 * API and modify the detection.
201 * @return The long press gesture detector
202 * @pre Long press detection should have been enabled via EnableGestureDetection().
203 * @see EnableGestureDetection
205 LongPressGestureDetector GetLongPressGestureDetector() const;
207 // Keyboard Navigation
210 * @brief Sets whether this control supports two dimensional
211 * keyboard navigation (i.e. whether it knows how to handle the
212 * keyboard focus movement between its child actors).
214 * The control doesn't support it by default.
216 * @param[in] isSupported Whether this control supports two dimensional keyboard navigation
218 void SetKeyboardNavigationSupport(bool isSupported);
221 * @brief Gets whether this control supports two dimensional keyboard navigation.
224 * @return true if this control supports two dimensional keyboard navigation
226 bool IsKeyboardNavigationSupported();
231 * @copydoc Toolkit::Control::SetKeyInputFocus()
233 void SetKeyInputFocus();
236 * @copydoc Toolkit::Control::HasKeyInputFocus()
238 bool HasKeyInputFocus();
241 * @copydoc Toolkit::Control::ClearKeyInputFocus()
243 void ClearKeyInputFocus();
248 * @brief Sets whether this control is a focus group for keyboard navigation.
250 * (i.e. the scope of keyboard focus movement
251 * can be limited to its child actors). The control is not a focus group by default.
253 * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation
255 void SetAsKeyboardFocusGroup(bool isFocusGroup);
258 * @brief Gets whether this control is a focus group for keyboard navigation.
261 * @return true if this control is set as a focus group for keyboard navigation
263 bool IsKeyboardFocusGroup();
267 * @brief Called by the AccessibilityManager to activate the Control.
270 DALI_INTERNAL void AccessibilityActivate();
273 * @brief Called by the KeyboardFocusManager.
276 DALI_INTERNAL void KeyboardEnter();
282 * @copydoc Dali::Toolkit::Control::KeyEventSignal()
284 Toolkit::Control::KeyEventSignalType& KeyEventSignal();
287 * @copydoc Dali::Toolkit::Control::KeyInputFocusGainedSignal()
289 Toolkit::Control::KeyInputFocusSignalType& KeyInputFocusGainedSignal();
292 * @copydoc Dali::Toolkit::Control::KeyInputFocusLostSignal()
294 Toolkit::Control::KeyInputFocusSignalType& KeyInputFocusLostSignal();
298 * @brief Called by the KeyInputFocusManager to emit key event signals.
301 * @param[in] event The key event
302 * @return True if the event was consumed
304 DALI_INTERNAL bool EmitKeyEventSignal(const KeyEvent& event);
307 protected: // For derived classes to call
309 * @brief Emits KeyInputFocusGained signal if true else emits KeyInputFocusLost signal.
311 * Should be called last by the control after it acts on the Input Focus change.
314 * @param[in] focusGained True if gained, False if lost
316 void EmitKeyInputFocusSignal(bool focusGained);
318 protected: // From CustomActorImpl
320 * @copydoc CustomActorImpl::OnSceneConnection()
321 * @note If overridden, then an up-call to Control::OnSceneConnection MUST be made at the end.
323 void OnSceneConnection(int depth) override;
326 * @copydoc CustomActorImpl::OnSceneDisconnection()
327 * @note If overridden, then an up-call to Control::OnSceneDisconnection MUST be made at the end.
329 void OnSceneDisconnection() override;
332 * @copydoc CustomActorImpl::OnChildAdd()
333 * @note If overridden, then an up-call to Control::OnChildAdd MUST be made at the end.
335 void OnChildAdd(Actor& child) override;
338 * @copydoc CustomActorImpl::OnChildRemove()
339 * @note If overridden, then an up-call to Control::OnChildRemove MUST be made at the end.
341 void OnChildRemove(Actor& child) override;
344 * @copydoc CustomActorImpl::OnPropertySet()
345 * @note If overridden, then an up-call to Control::OnChildRemove MUST be made at the end.
347 void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
350 * @copydoc CustomActorImpl::OnSizeSet()
351 * @note If overridden, then an up-call to Control::OnSizeSet MUST be made at the end.
353 void OnSizeSet(const Vector3& targetSize) override;
356 * @copydoc CustomActorImpl::OnSizeAnimation()
357 * @note If overridden, then an up-call to Control::OnSizeAnimation MUST be made at the end.
359 void OnSizeAnimation(Animation& animation, const Vector3& targetSize) override;
362 * @copydoc CustomActorImpl::OnRelayout()
364 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
367 * @copydoc CustomActorImpl::OnSetResizePolicy()
369 void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension) override;
372 * @copydoc CustomActorImpl::GetNaturalSize()
374 Vector3 GetNaturalSize() override;
377 * @copydoc CustomActorImpl::CalculateChildSize()
379 float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension) override;
382 * @copydoc CustomActorImpl::GetHeightForWidth()
384 float GetHeightForWidth(float width) override;
387 * @copydoc CustomActorImpl::GetWidthForHeight()
389 float GetWidthForHeight(float height) override;
392 * @copydoc CustomActorImpl::RelayoutDependentOnChildren()
394 bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS) override;
397 * @copydoc CustomActorImpl::OnCalculateRelayoutSize()
399 void OnCalculateRelayoutSize(Dimension::Type dimension) override;
402 * @copydoc CustomActorImpl::OnLayoutNegotiated()
404 void OnLayoutNegotiated(float size, Dimension::Type dimension) override;
406 public: // Helpers for deriving classes
408 * @brief Flags for the constructor.
411 enum ControlBehaviour
413 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
414 NOT_IN_USE_1 = 1 << (CustomActorImpl::ACTOR_FLAG_COUNT + 0),
415 REQUIRES_KEYBOARD_NAVIGATION_SUPPORT = 1 << (CustomActorImpl::ACTOR_FLAG_COUNT + 1), ///< True if needs to support keyboard navigation @SINCE_1_0.0
416 DISABLE_STYLE_CHANGE_SIGNALS = 1 << (CustomActorImpl::ACTOR_FLAG_COUNT + 2), ///< True if control should not monitor style change signals @SINCE_1_2_10
418 LAST_CONTROL_BEHAVIOUR_FLAG
421 static const int CONTROL_BEHAVIOUR_FLAG_COUNT = Log<LAST_CONTROL_BEHAVIOUR_FLAG - 1>::value + 1; ///< Total count of flags
424 * @brief Creates a new ControlImpl instance that does not require touch by default.
426 * If touch is required, then the user can connect to this class' touch signal.
428 * @param[in] additionalBehaviour Additional control behaviour.
429 * @return A handle to the ControlImpl instance
431 static Toolkit::Control New(ControlBehaviour additionalBehaviour);
437 * @brief Control constructor.
440 * @param[in] behaviourFlags Behavioural flags from ControlBehaviour enum
442 Control(ControlBehaviour behaviourFlags);
445 * @brief Second phase initialization.
450 public: // API for derived classes to override
454 * @brief This method is called after the Control has been initialized.
456 * Derived classes should do any second phase initialization by overriding this method.
459 virtual void OnInitialize();
462 * @copydoc Dali::Toolkit::Control::IsResourceReady
464 virtual bool IsResourceReady() const;
469 * @brief This method should be overridden by deriving classes requiring notifications when the style changes.
472 * @param[in] styleManager The StyleManager object
473 * @param[in] change Information denoting what has changed
475 virtual void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change);
480 * @brief This method is called when the control is accessibility activated.
482 * Derived classes should override this to perform custom accessibility activation.
484 * @return true if this control can perform accessibility activation
486 virtual bool OnAccessibilityActivated();
489 * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
493 * @param[in] gesture The pan gesture
494 * @return true if the pan gesture has been consumed by this control
496 virtual bool OnAccessibilityPan(PanGesture gesture);
499 * @brief This method should be overridden by deriving classes when they wish to respond
500 * the accessibility up and down action (i.e. value change of slider control).
503 * @param[in] isIncrease Whether the value should be increased or decreased
504 * @return true if the value changed action has been consumed by this control
506 virtual bool OnAccessibilityValueChange(bool isIncrease);
509 * @brief This method should be overridden by deriving classes when they wish to respond
510 * the accessibility zoom action.
513 * @return true if the zoom action has been consumed by this control
515 virtual bool OnAccessibilityZoom();
518 * @brief This method should be overriden by deriving classes when they wish to be
519 * represented by a custom Accessible object implementation.
521 * The AT-SPI infrastructure is responsible for destroying the returned object.
523 * Currently, this method is called at most once in a given Control's lifetime, when
524 * GetAccessibleObject() is called for the first time. A future version of the
525 * AT-SPI infrastructure, however, may delete the Accessible object and request a new
526 * one to be created (by calling this method) multiple times, for example during
527 * scene connection and disconnection.
529 * @return The newly created Accessible object
531 * @see GetAccessibleObject()
533 virtual DevelControl::ControlAccessible* CreateAccessibleObject();
538 * @brief Called when the control gains key input focus.
540 * Should be overridden by derived classes if they need to customize what happens when focus is gained.
543 virtual void OnKeyInputFocusGained();
546 * @brief Called when the control loses key input focus.
548 * Should be overridden by derived classes if they need to customize what happens when focus is lost.
551 virtual void OnKeyInputFocusLost();
554 * @brief Gets the next keyboard focusable actor in this control towards the given direction.
556 * A control needs to override this function in order to support two dimensional keyboard navigation.
558 * @param[in] currentFocusedActor The current focused actor
559 * @param[in] direction The direction to move the focus towards
560 * @param[in] loopEnabled Whether the focus movement should be looped within the control
561 * @return The next keyboard focusable actor in this control or an empty handle if no actor can be focused
563 virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled);
566 * @brief Informs this control that its chosen focusable actor will be focused.
568 * This allows the application to perform any actions if wishes
569 * before the focus is actually moved to the chosen actor.
572 * @param[in] commitedFocusableActor The commited focusable actor
574 virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor);
577 * @brief This method is called when the control has enter pressed on it.
579 * Derived classes should override this to perform custom actions.
581 * @return true if this control supported this action
583 virtual bool OnKeyboardEnter();
586 * @brief Called after a key-event is received by the actor that has had its focus set.
589 * @param[in] event The Key Event
590 * @return True if the event should be consumed
592 virtual bool OnKeyEvent(const KeyEvent& event);
597 * @brief Called whenever a pinch gesture is detected on this control.
599 * This can be overridden by deriving classes when pinch detection
600 * is enabled. The default behaviour is to scale the control by the
604 * @param[in] pinch The pinch gesture
605 * @note If overridden, then the default behavior will not occur.
606 * @note Pinch detection should be enabled via EnableGestureDetection().
607 * @see EnableGestureDetection
609 virtual void OnPinch(const PinchGesture& pinch);
612 * @brief Called whenever a pan gesture is detected on this control.
614 * This should be overridden by deriving classes when pan detection
618 * @param[in] pan The pan gesture
619 * @note There is no default behavior with panning.
620 * @note Pan detection should be enabled via EnableGestureDetection().
621 * @see EnableGestureDetection
623 virtual void OnPan(const PanGesture& pan);
626 * @brief Called whenever a tap gesture is detected on this control.
628 * This should be overridden by deriving classes when tap detection
632 * @param[in] tap The tap gesture
633 * @note There is no default behavior with a tap.
634 * @note Tap detection should be enabled via EnableGestureDetection().
635 * @see EnableGestureDetection
637 virtual void OnTap(const TapGesture& tap);
640 * @brief Called whenever a long press gesture is detected on this control.
642 * This should be overridden by deriving classes when long press
643 * detection is enabled.
646 * @param[in] longPress The long press gesture
647 * @note There is no default behaviour associated with a long press.
648 * @note Long press detection should be enabled via EnableGestureDetection().
649 * @see EnableGestureDetection
651 virtual void OnLongPress(const LongPressGesture& longPress);
653 // From ConnectionTrackerInterface
656 * @copydoc ConnectionTrackerInterface::SignalConnected
658 void SignalConnected(SlotObserver* slotObserver, CallbackBase* callback) override;
661 * @copydoc ConnectionTrackerInterface::SignalDisconnected
663 void SignalDisconnected(SlotObserver* slotObserver, CallbackBase* callback) override;
666 * @brief Retrieves the extension for this control.
669 * @return The extension if available, NULL otherwise
671 virtual Extension* GetControlExtension()
679 * @brief Make visual transition from source control to destination control about specific Visual.
680 * If both of source and destination control have same visual index, than generates information for the transition of this Control.
682 * @param[out] sourcePropertyMap Source property map to be applied on this Control.
683 * @param[out] destinationPropertyMap Destination property map to be applied on this Control.
684 * @param[in] source Source control of the animation.
685 * @param[in] destination Destination control of the animation.
686 * @param[in] visualIndex Property::Index to make animation.
688 void MakeVisualTransition(Dali::Property::Map& sourcePropertyMap, Dali::Property::Map& destinationPropertyMap, Dali::Toolkit::Control source, Dali::Toolkit::Control destination, Dali::Property::Index visualIndex);
691 * @brief Retrieves source and destination visual properties for the Transition of this Control.
692 * The properties of this Control will be transitioned from the propeties of source Control to that of destination control.
693 * If a property value is different between source and destination Control,
694 * the property information of each Control will be included in sourceProperties and destinationProperties.
696 * @param[out] sourceProperties Source property list to be applied on this Control.
697 * @param[out] destinationProperties Destination property list to be applied on this Control.
698 * @param[in] source Source control of the animation.
699 * @param[in] destination Destination control of the animation.
701 * @note This method do not handle Actor properties.
702 * And the size and order of the sourceProperties and destinationProperties must be synchronized.
704 virtual void OnCreateTransitions(std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& sourceProperties,
705 std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& destinationProperties,
706 Dali::Toolkit::Control source,
707 Dali::Toolkit::Control destination)
712 * @brief Update visual properties.
713 * @param[in] properties Property list to be used to update visual properties of this Control.
715 virtual void OnUpdateVisualProperties(const std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& properties)
722 // Not copyable or movable
723 DALI_INTERNAL Control(const Control&) = delete; ///< Deleted copy constructor.
724 DALI_INTERNAL Control(Control&&) = delete; ///< Deleted move constructor.
725 DALI_INTERNAL Control& operator=(const Control&) = delete; ///< Deleted copy assignment operator.
726 DALI_INTERNAL Control& operator=(Control&&) = delete; ///< Deleted move assignment operator.
729 class DALI_INTERNAL Impl; // Class declaration is public so we can internally add devel API's to the Controls Impl
737 * @brief Gets implementation from the handle.
741 * @return Implementation
742 * @pre handle is initialized and points to a control
744 DALI_TOOLKIT_API Internal::Control& GetImplementation(Dali::Toolkit::Control& handle);
747 * @brief Gets implementation from the handle.
751 * @return Implementation
752 * @pre Handle is initialized and points to a control.
754 DALI_TOOLKIT_API const Internal::Control& GetImplementation(const Dali::Toolkit::Control& handle);
756 } // namespace Internal
761 } // namespace Toolkit
765 #endif // DALI_TOOLKIT_CONTROL_IMPL_H