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