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