Formatting API
[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
392     REQUIRES_KEYBOARD_NAVIGATION_SUPPORT = 1 << (CustomActorImpl::ACTOR_FLAG_COUNT + 0), ///< True if needs to support keyboard navigation @SINCE_1_0.0
393
394     DISABLE_STYLE_CHANGE_SIGNALS = 1 << (CustomActorImpl::ACTOR_FLAG_COUNT + 1), ///< True if control should not monitor style change signals @SINCE_1_2_10
395
396     LAST_CONTROL_BEHAVIOUR_FLAG
397   };
398
399   static const int CONTROL_BEHAVIOUR_FLAG_COUNT = Log<LAST_CONTROL_BEHAVIOUR_FLAG - 1>::value + 1; ///< Total count of flags
400
401   /**
402    * @brief Control constructor.
403    *
404    * @SINCE_1_0.0
405    * @param[in] behaviourFlags Behavioural flags from ControlBehaviour enum
406    */
407   Control(ControlBehaviour behaviourFlags);
408
409   /**
410    * @brief Second phase initialization.
411    * @SINCE_1_0.0
412    */
413   void Initialize();
414
415 public: // API for derived classes to override
416   // Lifecycle
417
418   /**
419    * @brief This method is called after the Control has been initialized.
420    *
421    * Derived classes should do any second phase initialization by overriding this method.
422    * @SINCE_1_0.0
423    */
424   virtual void OnInitialize();
425
426   // Styling
427
428   /**
429    * @brief This method should be overridden by deriving classes requiring notifications when the style changes.
430    *
431    * @SINCE_1_0.0
432    * @param[in] styleManager The StyleManager object
433    * @param[in] change Information denoting what has changed
434    */
435   virtual void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change);
436
437   // Accessibility
438
439   /**
440    * @brief This method is called when the control is accessibility activated.
441    *
442    * Derived classes should override this to perform custom accessibility activation.
443    * @SINCE_1_0.0
444    * @return true if this control can perform accessibility activation
445    */
446   virtual bool OnAccessibilityActivated();
447
448   /**
449    * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
450    * pan gesture.
451    *
452    * @SINCE_1_0.0
453    * @param[in] gesture The pan gesture
454    * @return true if the pan gesture has been consumed by this control
455    */
456   virtual bool OnAccessibilityPan(PanGesture gesture);
457
458   /**
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).
461    *
462    * @SINCE_1_0.0
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
465    */
466   virtual bool OnAccessibilityValueChange(bool isIncrease);
467
468   /**
469    * @brief This method should be overridden by deriving classes when they wish to respond
470    * the accessibility zoom action.
471    *
472    * @SINCE_1_0.0
473    * @return true if the zoom action has been consumed by this control
474    */
475   virtual bool OnAccessibilityZoom();
476
477   // Keyboard focus
478
479   /**
480    * @brief Called when the control gains key input focus.
481    *
482    * Should be overridden by derived classes if they need to customize what happens when focus is gained.
483    * @SINCE_1_0.0
484    */
485   virtual void OnKeyInputFocusGained();
486
487   /**
488    * @brief Called when the control loses key input focus.
489    *
490    * Should be overridden by derived classes if they need to customize what happens when focus is lost.
491    * @SINCE_1_0.0
492    */
493   virtual void OnKeyInputFocusLost();
494
495   /**
496    * @brief Gets the next keyboard focusable actor in this control towards the given direction.
497    *
498    * A control needs to override this function in order to support two dimensional keyboard navigation.
499    * @SINCE_1_0.0
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
504    */
505   virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled);
506
507   /**
508    * @brief Informs this control that its chosen focusable actor will be focused.
509    *
510    * This allows the application to perform any actions if wishes
511    * before the focus is actually moved to the chosen actor.
512    *
513    * @SINCE_1_0.0
514    * @param[in] commitedFocusableActor The commited focusable actor
515    */
516   virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor);
517
518   /**
519    * @brief This method is called when the control has enter pressed on it.
520    *
521    * Derived classes should override this to perform custom actions.
522    * @SINCE_1_0.0
523    * @return true if this control supported this action
524    */
525   virtual bool OnKeyboardEnter();
526
527   /**
528    * @brief Called after a key-event is received by the actor that has had its focus set.
529    *
530    * @SINCE_1_0.0
531    * @param[in] event The Key Event
532    * @return True if the event should be consumed
533    */
534   virtual bool OnKeyEvent(const KeyEvent& event);
535
536   // Gestures
537
538   /**
539    * @brief Called whenever a pinch gesture is detected on this control.
540    *
541    * This can be overridden by deriving classes when pinch detection
542    * is enabled.  The default behaviour is to scale the control by the
543    * pinch scale.
544    *
545    * @SINCE_1_0.0
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
550    */
551   virtual void OnPinch(const PinchGesture& pinch);
552
553   /**
554    * @brief Called whenever a pan gesture is detected on this control.
555    *
556    * This should be overridden by deriving classes when pan detection
557    * is enabled.
558    *
559    * @SINCE_1_0.0
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
564    */
565   virtual void OnPan(const PanGesture& pan);
566
567   /**
568    * @brief Called whenever a tap gesture is detected on this control.
569    *
570    * This should be overridden by deriving classes when tap detection
571    * is enabled.
572    *
573    * @SINCE_1_0.0
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
578    */
579   virtual void OnTap(const TapGesture& tap);
580
581   /**
582    * @brief Called whenever a long press gesture is detected on this control.
583    *
584    * This should be overridden by deriving classes when long press
585    * detection is enabled.
586    *
587    * @SINCE_1_0.0
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
592    */
593   virtual void OnLongPress(const LongPressGesture& longPress);
594
595   // From ConnectionTrackerInterface
596
597   /**
598    * @copydoc ConnectionTrackerInterface::SignalConnected
599    */
600   void SignalConnected(SlotObserver* slotObserver, CallbackBase* callback) override;
601
602   /**
603    * @copydoc ConnectionTrackerInterface::SignalDisconnected
604    */
605   void SignalDisconnected(SlotObserver* slotObserver, CallbackBase* callback) override;
606
607   /**
608    * @brief Retrieves the extension for this control.
609    *
610    * @SINCE_1_0.0
611    * @return The extension if available, NULL otherwise
612    */
613   virtual Extension* GetControlExtension()
614   {
615     return NULL;
616   }
617
618 private:
619   /// @cond internal
620
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.
626
627 public:
628   class DALI_INTERNAL Impl; // Class declaration is public so we can internally add devel API's to the Controls Impl
629
630 private:
631   Impl* mImpl;
632   /// @endcond
633 };
634
635 /**
636  * @brief Gets implementation from the handle.
637  *
638  * @SINCE_1_0.0
639  * @param handle
640  * @return Implementation
641  * @pre handle is initialized and points to a control
642  */
643 DALI_TOOLKIT_API Internal::Control& GetImplementation(Dali::Toolkit::Control& handle);
644
645 /**
646  * @brief Gets implementation from the handle.
647  *
648  * @SINCE_1_0.0
649  * @param handle
650  * @return Implementation
651  * @pre Handle is initialized and points to a control.
652  */
653 DALI_TOOLKIT_API const Internal::Control& GetImplementation(const Dali::Toolkit::Control& handle);
654
655 } // namespace Internal
656
657 /**
658  * @}
659  */
660 } // namespace Toolkit
661
662 } // namespace Dali
663
664 #endif // DALI_TOOLKIT_CONTROL_IMPL_H