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