[dali_2.3.19] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / control-impl.h
1 #ifndef DALI_TOOLKIT_CONTROL_IMPL_H
2 #define DALI_TOOLKIT_CONTROL_IMPL_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
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>
29
30 // INTERNAL INCLUDES
31 #include <dali-toolkit/public-api/controls/control.h>
32
33 namespace Dali
34 {
35 namespace Toolkit
36 {
37 /**
38  * @addtogroup dali_toolkit_controls
39  * @{
40  */
41
42 class StyleManager;
43
44 namespace Internal
45 {
46 /**
47  * @brief This is the internal base class for all controls.
48  *
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.
52  * @SINCE_1_0.0
53  */
54 class DALI_TOOLKIT_API Control : public CustomActorImpl, public ConnectionTrackerInterface
55 {
56 public:
57   class Extension; ///< Forward declare future extension interface
58
59   // Creation & Destruction
60
61   /**
62    * @brief Creates a new ControlImpl instance that does not require touch by default.
63    *
64    * If touch is required, then the user can connect to this class' touch signal.
65    * @SINCE_1_0.0
66    * @return A handle to the ControlImpl instance
67    */
68   static Toolkit::Control New();
69
70 protected:
71   /**
72    * @brief Virtual destructor.
73    * @SINCE_1_0.0
74    */
75   virtual ~Control();
76
77 public:
78   // Styling
79
80   /**
81    * @copydoc Dali::Toolkit::Control::SetStyleName
82    */
83   void SetStyleName(const std::string& styleName);
84
85   /**
86    * @copydoc Dali::Toolkit::Control::GetStyleName
87    */
88   const std::string& GetStyleName() const;
89
90   // Background
91
92   /**
93    * @copydoc Dali::Toolkit::Control::SetBackgroundColor
94    */
95   void SetBackgroundColor(const Vector4& color);
96
97   /**
98    * @brief Sets the background with a property map.
99    *
100    * @SINCE_1_0.0
101    * @param[in] map The background property map
102    */
103   void SetBackground(const Property::Map& map);
104
105   /**
106    * @copydoc Dali::Toolkit::Control::ClearBackground
107    */
108   void ClearBackground();
109
110   // Gesture Detection
111
112   /**
113    * @brief Allows deriving classes to enable any of the gesture detectors that are available.
114    *
115    * Gesture detection can be enabled one at a time or in bitwise format as shown:
116    * @code
117    * EnableGestureDetection(GestureType::Value(GestureType::PINCH | GestureType::TAP | GestureType::PAN));
118    * @endcode
119    * @SINCE_1_0.0
120    * @param[in] type The gesture type(s) to enable
121    */
122   void EnableGestureDetection(GestureType::Value type);
123
124   /**
125    * @brief Allows deriving classes to disable any of the gesture detectors.
126    *
127    * Like EnableGestureDetection, this can also be called using bitwise or.
128    * @SINCE_1_0.0
129    * @param[in] type The gesture type(s) to disable
130    * @see EnableGetureDetection
131    */
132   void DisableGestureDetection(GestureType::Value type);
133
134   /**
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.
138    *
139    * @SINCE_1_0.0
140    * @return The pinch gesture detector
141    * @pre Pinch detection should have been enabled via EnableGestureDetection().
142    * @see EnableGestureDetection
143    */
144   PinchGestureDetector GetPinchGestureDetector() const;
145
146   /**
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.
150    *
151    * @SINCE_1_0.0
152    * @return The pan gesture detector
153    * @pre Pan detection should have been enabled via EnableGestureDetection().
154    * @see EnableGestureDetection
155    */
156   PanGestureDetector GetPanGestureDetector() const;
157
158   /**
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.
162    *
163    * @SINCE_1_0.0
164    * @return The tap gesture detector
165    * @pre Tap detection should have been enabled via EnableGestureDetection().
166    * @see EnableGestureDetection
167    */
168   TapGestureDetector GetTapGestureDetector() const;
169
170   /**
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.
174    *
175    * @SINCE_1_0.0
176    * @return The long press gesture detector
177    * @pre Long press detection should have been enabled via EnableGestureDetection().
178    * @see EnableGestureDetection
179    */
180   LongPressGestureDetector GetLongPressGestureDetector() const;
181
182   // Keyboard Navigation
183
184   /**
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).
188    *
189    * The control doesn't support it by default.
190    * @SINCE_1_0.0
191    * @param[in] isSupported Whether this control supports two dimensional keyboard navigation
192    */
193   void SetKeyboardNavigationSupport(bool isSupported);
194
195   /**
196    * @brief Gets whether this control supports two dimensional keyboard navigation.
197    *
198    * @SINCE_1_0.0
199    * @return true if this control supports two dimensional keyboard navigation
200    */
201   bool IsKeyboardNavigationSupported();
202
203   // Key Input
204
205   /**
206    * @copydoc Toolkit::Control::SetKeyInputFocus()
207    */
208   void SetKeyInputFocus();
209
210   /**
211    * @copydoc Toolkit::Control::HasKeyInputFocus()
212    */
213   bool HasKeyInputFocus();
214
215   /**
216    * @copydoc Toolkit::Control::ClearKeyInputFocus()
217    */
218   void ClearKeyInputFocus();
219
220   // Keyboard Focus
221
222   /**
223    * @brief Sets whether this control is a focus group for keyboard navigation.
224    *
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.
227    * @SINCE_1_0.0
228    * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation
229    */
230   void SetAsKeyboardFocusGroup(bool isFocusGroup);
231
232   /**
233    * @brief Gets whether this control is a focus group for keyboard navigation.
234    *
235    * @SINCE_1_0.0
236    * @return true if this control is set as a focus group for keyboard navigation
237    */
238   bool IsKeyboardFocusGroup();
239
240   /// @cond internal
241   /**
242    * @brief Called by the AccessibilityManager to activate the Control.
243    * @SINCE_1_0.0
244    */
245   DALI_INTERNAL void AccessibilityActivate();
246
247   /**
248    * @brief Called by the KeyboardFocusManager.
249    * @SINCE_1_0.0
250    */
251   DALI_INTERNAL void KeyboardEnter();
252   /// @endcond
253
254   // Signals
255
256   /**
257    * @copydoc Dali::Toolkit::Control::KeyEventSignal()
258    */
259   Toolkit::Control::KeyEventSignalType& KeyEventSignal();
260
261   /**
262    * @copydoc Dali::Toolkit::Control::KeyInputFocusGainedSignal()
263    */
264   Toolkit::Control::KeyInputFocusSignalType& KeyInputFocusGainedSignal();
265
266   /**
267    * @copydoc Dali::Toolkit::Control::KeyInputFocusLostSignal()
268    */
269   Toolkit::Control::KeyInputFocusSignalType& KeyInputFocusLostSignal();
270
271   /// @cond internal
272   /**
273    * @brief Called by the KeyInputFocusManager to emit key event signals.
274    *
275    * @SINCE_1_0.0
276    * @param[in] event The key event
277    * @return True if the event was consumed
278    */
279   DALI_INTERNAL bool EmitKeyEventSignal(const KeyEvent& event);
280   /// @endcond
281
282 protected: // For derived classes to call
283   /**
284    * @brief Emits KeyInputFocusGained signal if true else emits KeyInputFocusLost signal.
285    *
286    * Should be called last by the control after it acts on the Input Focus change.
287    *
288    * @SINCE_1_0.0
289    * @param[in] focusGained True if gained, False if lost
290    */
291   void EmitKeyInputFocusSignal(bool focusGained);
292
293 protected: // From CustomActorImpl
294   /**
295    * @copydoc CustomActorImpl::OnSceneConnection()
296    * @note If overridden, then an up-call to Control::OnSceneConnection MUST be made at the end.
297    */
298   void OnSceneConnection(int depth) override;
299
300   /**
301    * @copydoc CustomActorImpl::OnSceneDisconnection()
302    * @note If overridden, then an up-call to Control::OnSceneDisconnection MUST be made at the end.
303    */
304   void OnSceneDisconnection() override;
305
306   /**
307    * @copydoc CustomActorImpl::OnChildAdd()
308    * @note If overridden, then an up-call to Control::OnChildAdd MUST be made at the end.
309    */
310   void OnChildAdd(Actor& child) override;
311
312   /**
313    * @copydoc CustomActorImpl::OnChildRemove()
314    * @note If overridden, then an up-call to Control::OnChildRemove MUST be made at the end.
315    */
316   void OnChildRemove(Actor& child) override;
317
318   /**
319    * @copydoc CustomActorImpl::OnPropertySet()
320    * @note If overridden, then an up-call to Control::OnChildRemove MUST be made at the end.
321    */
322   void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
323
324   /**
325    * @copydoc CustomActorImpl::OnSizeSet()
326    * @note If overridden, then an up-call to Control::OnSizeSet MUST be made at the end.
327    */
328   void OnSizeSet(const Vector3& targetSize) override;
329
330   /**
331    * @copydoc CustomActorImpl::OnSizeAnimation()
332    * @note If overridden, then an up-call to Control::OnSizeAnimation MUST be made at the end.
333    */
334   void OnSizeAnimation(Animation& animation, const Vector3& targetSize) override;
335
336   /**
337    * @copydoc CustomActorImpl::OnRelayout()
338    */
339   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
340
341   /**
342    * @copydoc CustomActorImpl::OnSetResizePolicy()
343    */
344   void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension) override;
345
346   /**
347    * @copydoc CustomActorImpl::GetNaturalSize()
348    */
349   Vector3 GetNaturalSize() override;
350
351   /**
352    * @copydoc CustomActorImpl::CalculateChildSize()
353    */
354   float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension) override;
355
356   /**
357    * @copydoc CustomActorImpl::GetHeightForWidth()
358    */
359   float GetHeightForWidth(float width) override;
360
361   /**
362    * @copydoc CustomActorImpl::GetWidthForHeight()
363    */
364   float GetWidthForHeight(float height) override;
365
366   /**
367    * @copydoc CustomActorImpl::RelayoutDependentOnChildren()
368    */
369   bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS) override;
370
371   /**
372    * @copydoc CustomActorImpl::OnCalculateRelayoutSize()
373    */
374   void OnCalculateRelayoutSize(Dimension::Type dimension) override;
375
376   /**
377    * @copydoc CustomActorImpl::OnLayoutNegotiated()
378    */
379   void OnLayoutNegotiated(float size, Dimension::Type dimension) override;
380
381 protected: // Helpers for deriving classes
382   // Construction
383
384   /**
385    * @brief Flags for the constructor.
386    * @SINCE_1_0.0
387    */
388   enum ControlBehaviour
389   {
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
391     NOT_IN_USE_1                         = 1 << (CustomActorImpl::ACTOR_FLAG_COUNT + 0),
392     REQUIRES_KEYBOARD_NAVIGATION_SUPPORT = 1 << (CustomActorImpl::ACTOR_FLAG_COUNT + 1), ///< True if needs to support keyboard navigation @SINCE_1_0.0
393     DISABLE_STYLE_CHANGE_SIGNALS         = 1 << (CustomActorImpl::ACTOR_FLAG_COUNT + 2), ///< True if control should not monitor style change signals @SINCE_1_2_10
394
395     LAST_CONTROL_BEHAVIOUR_FLAG
396   };
397
398   static const int CONTROL_BEHAVIOUR_FLAG_COUNT = Log<LAST_CONTROL_BEHAVIOUR_FLAG - 1>::value + 1; ///< Total count of flags
399
400   /**
401    * @brief Control constructor.
402    *
403    * @SINCE_1_0.0
404    * @param[in] behaviourFlags Behavioural flags from ControlBehaviour enum
405    */
406   Control(ControlBehaviour behaviourFlags);
407
408   /**
409    * @brief Second phase initialization.
410    * @SINCE_1_0.0
411    */
412   void Initialize();
413
414 public: // API for derived classes to override
415   // Lifecycle
416
417   /**
418    * @brief This method is called after the Control has been initialized.
419    *
420    * Derived classes should do any second phase initialization by overriding this method.
421    * @SINCE_1_0.0
422    */
423   virtual void OnInitialize();
424
425   // Styling
426
427   /**
428    * @brief This method should be overridden by deriving classes requiring notifications when the style changes.
429    *
430    * @SINCE_1_0.0
431    * @param[in] styleManager The StyleManager object
432    * @param[in] change Information denoting what has changed
433    */
434   virtual void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change);
435
436   // Accessibility
437
438   /**
439    * @brief This method is called when the control is accessibility activated.
440    *
441    * Derived classes should override this to perform custom accessibility activation.
442    * @SINCE_1_0.0
443    * @return true if this control can perform accessibility activation
444    */
445   virtual bool OnAccessibilityActivated();
446
447   /**
448    * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
449    * pan gesture.
450    *
451    * @SINCE_1_0.0
452    * @param[in] gesture The pan gesture
453    * @return true if the pan gesture has been consumed by this control
454    */
455   virtual bool OnAccessibilityPan(PanGesture gesture);
456
457   /**
458    * @brief This method should be overridden by deriving classes when they wish to respond
459    * the accessibility up and down action (i.e. value change of slider control).
460    *
461    * @SINCE_1_0.0
462    * @param[in] isIncrease Whether the value should be increased or decreased
463    * @return true if the value changed action has been consumed by this control
464    */
465   virtual bool OnAccessibilityValueChange(bool isIncrease);
466
467   /**
468    * @brief This method should be overridden by deriving classes when they wish to respond
469    * the accessibility zoom action.
470    *
471    * @SINCE_1_0.0
472    * @return true if the zoom action has been consumed by this control
473    */
474   virtual bool OnAccessibilityZoom();
475
476   // Keyboard focus
477
478   /**
479    * @brief Called when the control gains key input focus.
480    *
481    * Should be overridden by derived classes if they need to customize what happens when focus is gained.
482    * @SINCE_1_0.0
483    */
484   virtual void OnKeyInputFocusGained();
485
486   /**
487    * @brief Called when the control loses key input focus.
488    *
489    * Should be overridden by derived classes if they need to customize what happens when focus is lost.
490    * @SINCE_1_0.0
491    */
492   virtual void OnKeyInputFocusLost();
493
494   /**
495    * @brief Gets the next keyboard focusable actor in this control towards the given direction.
496    *
497    * A control needs to override this function in order to support two dimensional keyboard navigation.
498    * @SINCE_1_0.0
499    * @param[in] currentFocusedActor The current focused actor
500    * @param[in] direction The direction to move the focus towards
501    * @param[in] loopEnabled Whether the focus movement should be looped within the control
502    * @return The next keyboard focusable actor in this control or an empty handle if no actor can be focused
503    */
504   virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled);
505
506   /**
507    * @brief Informs this control that its chosen focusable actor will be focused.
508    *
509    * This allows the application to perform any actions if wishes
510    * before the focus is actually moved to the chosen actor.
511    *
512    * @SINCE_1_0.0
513    * @param[in] commitedFocusableActor The commited focusable actor
514    */
515   virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor);
516
517   /**
518    * @brief This method is called when the control has enter pressed on it.
519    *
520    * Derived classes should override this to perform custom actions.
521    * @SINCE_1_0.0
522    * @return true if this control supported this action
523    */
524   virtual bool OnKeyboardEnter();
525
526   /**
527    * @brief Called after a key-event is received by the actor that has had its focus set.
528    *
529    * @SINCE_1_0.0
530    * @param[in] event The Key Event
531    * @return True if the event should be consumed
532    */
533   virtual bool OnKeyEvent(const KeyEvent& event);
534
535   // Gestures
536
537   /**
538    * @brief Called whenever a pinch gesture is detected on this control.
539    *
540    * This can be overridden by deriving classes when pinch detection
541    * is enabled.  The default behaviour is to scale the control by the
542    * pinch scale.
543    *
544    * @SINCE_1_0.0
545    * @param[in] pinch The pinch gesture
546    * @note If overridden, then the default behavior will not occur.
547    * @note Pinch detection should be enabled via EnableGestureDetection().
548    * @see EnableGestureDetection
549    */
550   virtual void OnPinch(const PinchGesture& pinch);
551
552   /**
553    * @brief Called whenever a pan gesture is detected on this control.
554    *
555    * This should be overridden by deriving classes when pan detection
556    * is enabled.
557    *
558    * @SINCE_1_0.0
559    * @param[in] pan The pan gesture
560    * @note There is no default behavior with panning.
561    * @note Pan detection should be enabled via EnableGestureDetection().
562    * @see EnableGestureDetection
563    */
564   virtual void OnPan(const PanGesture& pan);
565
566   /**
567    * @brief Called whenever a tap gesture is detected on this control.
568    *
569    * This should be overridden by deriving classes when tap detection
570    * is enabled.
571    *
572    * @SINCE_1_0.0
573    * @param[in] tap The tap gesture
574    * @note There is no default behavior with a tap.
575    * @note Tap detection should be enabled via EnableGestureDetection().
576    * @see EnableGestureDetection
577    */
578   virtual void OnTap(const TapGesture& tap);
579
580   /**
581    * @brief Called whenever a long press gesture is detected on this control.
582    *
583    * This should be overridden by deriving classes when long press
584    * detection is enabled.
585    *
586    * @SINCE_1_0.0
587    * @param[in] longPress The long press gesture
588    * @note There is no default behaviour associated with a long press.
589    * @note Long press detection should be enabled via EnableGestureDetection().
590    * @see EnableGestureDetection
591    */
592   virtual void OnLongPress(const LongPressGesture& longPress);
593
594   // From ConnectionTrackerInterface
595
596   /**
597    * @copydoc ConnectionTrackerInterface::SignalConnected
598    */
599   void SignalConnected(SlotObserver* slotObserver, CallbackBase* callback) override;
600
601   /**
602    * @copydoc ConnectionTrackerInterface::SignalDisconnected
603    */
604   void SignalDisconnected(SlotObserver* slotObserver, CallbackBase* callback) override;
605
606   /**
607    * @brief Retrieves the extension for this control.
608    *
609    * @SINCE_1_0.0
610    * @return The extension if available, NULL otherwise
611    */
612   virtual Extension* GetControlExtension()
613   {
614     return NULL;
615   }
616
617 private:
618   /// @cond internal
619
620   // Not copyable or movable
621   DALI_INTERNAL Control(const Control&) = delete;            ///< Deleted copy constructor.
622   DALI_INTERNAL Control(Control&&)      = delete;            ///< Deleted move constructor.
623   DALI_INTERNAL Control& operator=(const Control&) = delete; ///< Deleted copy assignment operator.
624   DALI_INTERNAL Control& operator=(Control&&) = delete;      ///< Deleted move assignment operator.
625
626 public:
627   class DALI_INTERNAL Impl; // Class declaration is public so we can internally add devel API's to the Controls Impl
628
629 private:
630   Impl* mImpl;
631   /// @endcond
632 };
633
634 /**
635  * @brief Gets implementation from the handle.
636  *
637  * @SINCE_1_0.0
638  * @param handle
639  * @return Implementation
640  * @pre handle is initialized and points to a control
641  */
642 DALI_TOOLKIT_API Internal::Control& GetImplementation(Dali::Toolkit::Control& handle);
643
644 /**
645  * @brief Gets implementation from the handle.
646  *
647  * @SINCE_1_0.0
648  * @param handle
649  * @return Implementation
650  * @pre Handle is initialized and points to a control.
651  */
652 DALI_TOOLKIT_API const Internal::Control& GetImplementation(const Dali::Toolkit::Control& handle);
653
654 } // namespace Internal
655
656 /**
657  * @}
658  */
659 } // namespace Toolkit
660
661 } // namespace Dali
662
663 #endif // DALI_TOOLKIT_CONTROL_IMPL_H