Revert "[SRUK] (StyleManager) Create a style manager"
[platform/core/uifw/dali-toolkit.git] / capi / 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) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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  * @addtogroup CAPI_DALI_TOOLKIT_CONTROLS_MODULE
22  * @{
23  */
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/public-api/controls/control.h>
27
28 namespace Dali DALI_IMPORT_API
29 {
30
31 namespace Toolkit
32 {
33
34 class StyleManager;
35
36 namespace Internal DALI_INTERNAL
37 {
38 class StyleChangeProcessor;
39 class RelayoutControllerImpl;
40 class KeyInputFocusManager;
41 }
42
43 typedef std::pair< Actor, Vector2 > ActorSizePair;       ///< Pair of actor and size
44 typedef std::vector< ActorSizePair > ActorSizeContainer; ///< Container of actors and their sizes
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   // Properties
61   enum
62   {
63     CONTROL_PROPERTY_START_INDEX = PROPERTY_REGISTRATION_START_INDEX,
64     CONTROL_PROPERTY_END_INDEX = CONTROL_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
65   };
66
67   // Creation
68
69   /**
70    * @brief Create a new ControlImpl instance that does not require touch by default.
71    *
72    * If touch is required then the user can connect to this class' touch signal.
73    * @return A handle to the ConntrolImpl instance.
74    */
75   static Toolkit::Control New();
76
77   // Destruction
78
79   /**
80    * @brief Virtual destructor.
81    */
82   virtual ~Control();
83
84   // Actions
85
86   /**
87    * @brief This method should be overridden by deriving classes when they wish to be notified when they
88    * are activated.
89    */
90   virtual void OnActivated() { }
91
92   /**
93    * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
94    * pan gesture.
95    *
96    * @param[in] gesture The pan gesture.
97    * @return true if the pan gesture has been consumed by this control
98    */
99   virtual bool OnAccessibilityPan(PanGesture gesture);
100
101   /**
102    * @brief This method should be overridden by deriving classes when they wish to respond
103    * the accessibility up and down action (i.e. value change of slider control).
104    *
105    * @param[in] isIncrease Whether the value should be increased or decreased
106    * @return true if the value changed action has been consumed by this control
107    */
108   virtual bool OnAccessibilityValueChange(bool isIncrease);
109
110   /**
111    * @brief Sets whether this control supports two dimensional
112    * keyboard navigation (i.e. whether it knows how to handle the
113    * keyboardn focus movement between its child actors).
114    *
115    * The control doesn't support it by default.
116    * @param[in] isSupported Whether this control supports two dimensional keyboard navigation.
117    */
118   void SetKeyboardNavigationSupport(bool isSupported);
119
120   /**
121    * @brief Gets whether this control supports two dimensional keyboard navigation.
122    *
123    * @return true if this control supports two dimensional keyboard navigation.
124    */
125   bool IsKeyboardNavigationSupported();
126
127   /**
128    * @brief Sets whether this control is a focus group for keyboard navigation.
129    *
130    * (i.e. the scope of keyboard focus movement
131    * can be limitied to its child actors). The control is not a focus group by default.
132    * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation.
133    */
134   void SetAsKeyboardFocusGroup(bool isFocusGroup);
135
136   /**
137    * @brief Gets whether this control is a focus group for keyboard navigation.
138    *
139    * @return true if this control is set as a focus group for keyboard navigation.
140    */
141   bool IsKeyboardFocusGroup();
142
143   /**
144    * @brief Gets the next keyboard focusable actor in this control towards the given direction.
145    *
146    * A control needs to override this function in order to support two dimensional keyboard navigation.
147    * @param[in] currentFocusedActor The current focused actor.
148    * @param[in] direction The direction to move the focus towards.
149    * @param[in] loopEnabled Whether the focus movement should be looped within the control.
150    * @return the next keyboard focusable actor in this control or an empty handle if no actor can be focused.
151    */
152   virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
153
154   /**
155    * @brief Informs this control that its chosen focusable actor will be focused.
156    *
157    * This allows the application to preform any actions if wishes
158    * before the focus is actually moved to the chosen actor.
159    *
160    * @param[in] commitedFocusableActor The commited focusable actor.
161    */
162   virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor) { }
163
164   /**
165    * @brief Performs actions as requested using the action name.
166    *
167    * @param[in] object The object on which to perform the action.
168    * @param[in] actionName The action to perform.
169    * @param[in] attributes The attributes with which to perfrom this action.
170    * @return true if action has been accepted by this control
171    */
172   static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
173
174   /**
175    * @brief If deriving classes wish to fine tune pinch gesture
176    * detection then they can access the gesture detector through this
177    * API and modify the detection.
178    *
179    * @return The pinch gesture detector.
180    * @pre Pinch detection should have been enabled via EnableGestureDetection().
181    * @see EnableGestureDetection
182    */
183   PinchGestureDetector GetPinchGestureDetector() const;
184
185   /**
186    * @brief If deriving classes wish to fine tune pan gesture
187    * detection then they can access the gesture detector through this
188    * API and modify the detection.
189    *
190    * @return The pan gesture detector.
191    * @pre Pan detection should have been enabled via EnableGestureDetection().
192    * @see EnableGestureDetection
193    */
194   PanGestureDetector GetPanGestureDetector() const;
195
196   /**
197    * @brief If deriving classes wish to fine tune tap gesture
198    * detection then they can access the gesture detector through this
199    * API and modify the detection.
200    *
201    * @return The tap gesture detector.
202    * @pre Tap detection should have been enabled via EnableGestureDetection().
203    * @see EnableGestureDetection
204    */
205   TapGestureDetector GetTapGestureDetector() const;
206
207   /**
208    * @brief If deriving classes wish to fine tune long press gesture
209    * detection then they can access the gesture detector through this
210    * API and modify the detection.
211    *
212    * @return The long press gesture detector.
213    * @pre Long press detection should have been enabled via EnableGestureDetection().
214    * @see EnableGestureDetection
215    */
216   LongPressGestureDetector GetLongPressGestureDetector() const;
217
218   // Background
219
220   /**
221    * @copydoc Dali::Toolkit::Control::SetBackgroundColor
222    */
223   void SetBackgroundColor( const Vector4& color );
224
225   /**
226    * @copydoc Dali::Toolkit::Control::GetBackgroundColor
227    */
228   Vector4 GetBackgroundColor() const;
229
230   /**
231    * @copydoc Dali::Toolkit::Control::SetBackground
232    */
233   void SetBackground( Image image );
234
235   /**
236    * @copydoc Dali::Toolkit::Control::ClearBackground
237    */
238   void ClearBackground();
239
240   /**
241    * @copydoc Dali::Toolkit::Control::GetBackgroundActor
242    */
243   Actor GetBackgroundActor() const;
244
245 public:
246
247   /**
248    * @copydoc Dali::Toolkit::Control::KeyEventSignal()
249    */
250   Toolkit::Control::KeyEventSignalV2& KeyEventSignal();
251
252 protected:
253
254   // Construction
255
256   /**
257    * @brief Second phase initialization.
258    */
259   void Initialize();
260
261   // Gesture Detection
262
263   /**
264    * @brief Allows deriving classes to enable any of the gesture detectors that are available.
265    *
266    * Gesture detection can be enabled one at a time or in bitwise format as shown:
267    * @code
268    * EnableGestureDetection(Gesture::Type(Gesture::Pinch | Gesture::Tap | Gesture::Pan));
269    * @endcode
270    * @param[in]  type  The gesture type(s) to enable.
271    */
272   void EnableGestureDetection(Gesture::Type type);
273
274   /**
275    * @brief Allows deriving classes to disable any of the gesture detectors.
276    *
277    * Like EnableGestureDetection, this can also be called using bitwise or.
278    * @param[in]  type  The gesture type(s) to disable.
279    * @see EnableGetureDetection
280    */
281   void DisableGestureDetection(Gesture::Type type);
282
283 private: // For derived classes to override
284
285   /**
286    * @brief This method is called after the Control has been initialized.
287    *
288    * Derived classes should do any second phase initialization by
289    * overriding this method.
290    */
291   virtual void OnInitialize() { }
292
293   /**
294    * @brief This method should be overridden by deriving classes when
295    * they wish to be notified when the style changes.
296    *
297    * @param[in] change  Information denoting what has changed.
298    */
299   virtual void OnStyleChange(StyleChange change) { }
300
301   /**
302    * @brief Called whenever a pinch gesture is detected on this control.
303    *
304    * This can be overridden by deriving classes when pinch detection
305    * is enabled.  The default behaviour is to scale the control by the
306    * pinch scale.
307    *
308    * @note If overridden, then the default behaviour will not occur.
309    * @note Pinch detection should be enabled via EnableGestureDetection().
310    * @param[in]  pinch  The pinch gesture.
311    * @see EnableGestureDetection
312    */
313   virtual void OnPinch(PinchGesture pinch);
314
315   /**
316    * @brief Called whenever a pan gesture is detected on this control.
317    *
318    * This should be overridden by deriving classes when pan detection
319    * is enabled.
320    *
321    * @note There is no default behaviour with panning.
322    * @note Pan detection should be enabled via EnableGestureDetection().
323    * @param[in]  pan  The pan gesture.
324    * @see EnableGestureDetection
325    */
326   virtual void OnPan(PanGesture pan) { }
327
328   /**
329    * @brief Called whenever a tap gesture is detected on this control.
330    *
331    * This should be overridden by deriving classes when tap detection
332    * is enabled.
333    *
334    * @note There is no default behaviour with a tap.
335    * @note Tap detection should be enabled via EnableGestureDetection().
336    * @param[in]  tap  The tap gesture.
337    * @see EnableGestureDetection
338    */
339   virtual void OnTap(TapGesture tap) { }
340
341   /**
342    * @brief Called whenever a long press gesture is detected on this control.
343    *
344    * This should be overridden by deriving classes when long press
345    * detection is enabled.
346    *
347    * @note There is no default behaviour associated with a long press.
348    * @note Long press detection should be enabled via EnableGestureDetection().
349    * @param[in]  longPress  The long press gesture.
350    * @see EnableGestureDetection
351    */
352   virtual void OnLongPress(LongPressGesture longPress) { }
353
354   /**
355    * @brief Called whenever the control is added to the stage.
356    *
357    * Could be overridden by derived classes.
358    */
359   virtual void OnControlStageConnection() { }
360
361   /**
362    * @brief Called whenever the control is removed from the stage.
363    *
364    * Could be overridden by derived classes.
365    */
366   virtual void OnControlStageDisconnection() { }
367
368   /**
369    * @brief Called whenever an Actor is added to the control.
370    *
371    * Could be overridden by derived classes.
372    *
373    * @param[in] child The added actor.
374    */
375   virtual void OnControlChildAdd( Actor& child ) { }
376
377   /**
378    * @brief Called whenever an Actor is removed from the control.
379    *
380    * Could be overridden by derived classes.
381    *
382    * @param[in] child The removed actor.
383    */
384   virtual void OnControlChildRemove( Actor& child ) { }
385
386   /**
387    * @brief Called whenever the Control's size is set.
388    *
389    * Could be overridden by derived classes.
390    *
391    * @param[in] size The new size.
392    */
393   virtual void OnControlSizeSet( const Vector3& size ) { }
394
395   /**
396    * @brief Called after the Dali::Stage::SignalMessageQueueFlushed()
397    * signal is emitted if this control requested to be relaid-out.
398    *
399    * Should be overridden by derived classes if they need to layout
400    * actors differently after certain operations like add or remove
401    * actors, resize or after changing especific properties.
402    *
403    * @param[in]      size       The allocated size.
404    * @param[in,out]  container  The control should add actors to this container that it is not able
405    *                            to allocate a size for.
406    */
407   virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
408
409 private: // From CustomActorImpl, derived classes can override these.
410
411   /**
412    * @brief Sends a request to relayout this control.
413    *
414    * The control will be relaid out after the
415    * Dali::Stage::SignalMessageQueueFlushed() signal is emitted.
416    *
417    * It calls OnControlStageConnection() to notify derived classes.
418    *
419    * @see Dali::CustomActorImpl::OnStageConnection()
420    */
421   virtual void OnStageConnection();
422
423   /**
424    * @brief Calls OnControlStageDisconnection() to notify derived classed.
425    *
426    * @see Dali::CustomActorImpl::OnStageDisconnection()
427    */
428   virtual void OnStageDisconnection();
429
430   /**
431    * @brief Sends a request to relayout this control.
432    *
433    * The control will be relaid out after the
434    * Dali::Stage::SignalMessageQueueFlushed() signal is emitted.  It
435    * calls OnControlChildAdd() to notify derived classes.
436    *
437    * @note This method shouldn't be overridden by derived classes.
438    *
439    * @param[in] child The added actor.
440    *
441    * @see Dali::CustomActorImpl::OnChildAdd(Actor&)
442    */
443   virtual void OnChildAdd(Actor& child);
444
445   /**
446    * @brief Sends a request to relayout this control.
447    *
448    * The control will be relaid out after the
449    * Dali::Stage::SignalMessageQueueFlushed() signal is emitted.  It
450    * calls OnControlChildRemove() to notify derived classes.
451    *
452    * @note This method shouldn't be overridden by derived classes.
453    *
454    * @param[in] child The removed actor.
455    *
456    * @see Dali::CustomActorImpl::OnChildRemove(Actor&)
457    */
458   virtual void OnChildRemove(Actor& child);
459
460   /**
461    * @brief It stores the size set by size negotiation and relayout.
462    *
463    * It also keeps a backup of the size set through the Actor's API used in the size negotiation.
464    * It calls the OnControlSizeSet() to notify derived classes.
465    *
466    * @param[in] targetSize The new size.
467    *
468    * @see Dali::CustomActorImpl::OnSizeSet(const Vector3&)
469    */
470   virtual void OnSizeSet(const Vector3& targetSize);
471
472   /**
473    * @copydoc Dali::CustomActorImpl::OnSizeAnimation(Animation&, const Vector3&)
474    */
475   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
476
477   /**
478    * @copydoc Dali::CustomActorImpl::OnTouchEvent(const TouchEvent&)
479    */
480   virtual bool OnTouchEvent(const TouchEvent& event);
481
482   /**
483    * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
484    */
485   virtual bool OnKeyEvent(const KeyEvent& event);
486
487   /**
488    * @copydoc Dali::CustomActorImpl::OnMouseWheelEvent(const MouseWheelEvent&)
489    */
490   virtual bool OnMouseWheelEvent(const MouseWheelEvent& event);
491
492   /**
493    * @copydoc Dali::CustomActorImpl::OnKeyInputFocusGained()
494    */
495   virtual void OnKeyInputFocusGained();
496
497   /**
498    * @copydoc Dali::CustomActorImpl::OnKeyInputFocusLost()
499    */
500   virtual void OnKeyInputFocusLost();
501
502   /**
503    * @copydoc Dali::CustomActorImpl::GetChildByAlias(const std::string& actorAlias)
504    */
505   virtual Actor GetChildByAlias(const std::string& actorAlias);
506
507 private:
508
509   /**
510    * @brief Perform the activated action.
511    *
512    * @param[in] attributes The attributes to perfrom this action.
513    */
514   void DoActivatedAction(const PropertyValueContainer& attributes);
515
516 protected: // Construction
517
518   /**
519    * @brief Create a Control.
520    *
521    * @param[in] requiresTouchEvents True if the OnTouchEvent() callback is required.
522    */
523   Control(bool requiresTouchEvents);
524
525 public:
526
527   // Size negotiation
528
529   /**
530    * @copydoc Toolkit::Control::SetSizePolicy()
531    */
532   void SetSizePolicy( Toolkit::Control::SizePolicy widthPolicy, Toolkit::Control::SizePolicy heightPolicy );
533
534   /**
535    * @copydoc Toolkit::Control::GetSizePolicy()
536    */
537   void GetSizePolicy( Toolkit::Control::SizePolicy& widthPolicy, Toolkit::Control::SizePolicy& heightPolicy ) const;
538
539   /**
540    * @copydoc Toolkit::Control::SetMinimumSize()
541    */
542   void SetMinimumSize( const Vector3& size );
543
544   /**
545    * @copydoc Toolkit::Control::GetMinimumSize()
546    */
547   const Vector3& GetMinimumSize() const;
548
549   /**
550    * @copydoc Toolkit::Control::SetMaximumSize()
551    */
552   void SetMaximumSize( const Vector3& size );
553
554   /**
555    * @copydoc Toolkit::Control::GetMaximumSize()
556    */
557   const Vector3& GetMaximumSize() const;
558
559   /**
560    * @copydoc Toolkit::Control::GetNaturalSize()
561    */
562   virtual Vector3 GetNaturalSize();
563
564   /**
565    * @copydoc Toolkit::Control::GetHeightForWidth()
566    */
567   virtual float GetHeightForWidth( float width );
568
569   /**
570    * @copydoc Toolkit::Control::GetWidthForHeight()
571    */
572   virtual float GetWidthForHeight( float height );
573
574   /**
575    * @brief Retrieves the current Control's size.
576    *
577    * @return The control's size.
578    */
579   const Vector3& GetControlSize() const;
580
581   /**
582    * @brief Retrieves the Control's size set by the Application / Control.
583    *
584    * @return The control's size.
585    */
586   const Vector3& GetSizeSet() const;
587
588   //KeyInput
589
590   /**
591    * @copydoc Toolkit::Control::SetKeyInputFocus()
592    */
593   void SetKeyInputFocus();
594
595   /**
596    * @copydoc Toolkit::Control::HasKeyInputFocus()
597    */
598   bool HasKeyInputFocus();
599
600   /**
601    * @copydoc Toolkit::Control::ClearKeyInputFocus()
602    */
603   void ClearKeyInputFocus();
604
605   /**
606    * @copydoc ConnectionTrackerInterface::SignalConnected
607    */
608   virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
609
610   /**
611    * @copydoc ConnectionTrackerInterface::SignalDisconnected
612    */
613   virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
614
615   /**
616    * @copydoc ConnectionTrackerInterface::GetConnectionCount
617    */
618   virtual std::size_t GetConnectionCount() const;
619
620 protected:
621
622   /**
623    * @brief Sends a request to be relaid-out.
624    *
625    * This method is called from OnStageConnection(), OnChildAdd(),
626    * OnChildRemove(), SetSizePolicy(), SetMinimumSize() and
627    * SetMaximumSize().
628    *
629    * This method could also be called from derived classes every time
630    * a control's poperty change and it needs to be relaid-out.  After
631    * the Dali::Stage::SignalMessageQueueFlushed() is emitted a
632    * relayout process starts and all controls which called this method
633    * will be relaid-out.
634    *
635    * @note RelayoutRequest() only sends a request per Control before
636    * the Dali::Stage::SignalMessageQueueFlushed() signal is
637    * emitted. That means a control will be relaid-out only once, even
638    * if more than one request is sent between two consecutive signals.
639    */
640   void RelayoutRequest();
641
642   /**
643    * @brief Helper method for controls to Relayout their children if
644    * they do not know whether that child is a control or not.
645    *
646    * @param[in]      actor      The actor to relayout.
647    * @param[in]      size       The size to allocate to the actor.
648    * @param[in,out]  container  The container that holds actors that have not been allocated a size yet.
649    */
650   static void Relayout( Actor actor, Vector2 size, ActorSizeContainer& container );
651
652 private: // Used by the RelayoutController
653
654   /**
655    * @brief Called by the RelayoutController to negotiate the size of a control.
656    *
657    * The size allocated by the the algorithm is passed in which the
658    * control must adhere to.  A container is passed in as well which
659    * the control should populate with actors it has not / or does not
660    * need to handle in its size negotiation.
661    *
662    * @param[in]      size       The allocated size.
663    * @param[in,out]  container  The container that holds actors that are fed back into the
664    *                            RelayoutController algorithm.
665    */
666   void NegotiateSize( Vector2 size, ActorSizeContainer& container );
667
668 private:
669
670   /**
671    * @brief Called by NegotiateSize when the size to allocate to the control has been calculated.
672    *
673    * It calls the OnRelaidOut() method which can be overridden by derived classes.
674    *
675    * @param[in]      size       The allocated size.
676    * @param[in,out]  container  The control should add actors to this container that it is not able
677    *                            to allocate a size for.
678    */
679   void Relayout( Vector2 size, ActorSizeContainer& container );
680
681   /**
682    * @brief Used by the KeyInputFocusManager to emit key event signals.
683    *
684    * @param[in] event The key event.
685    * @return True if the event was consumed.
686    */
687   bool EmitKeyEventSignal(const KeyEvent& event);
688
689
690
691 private:
692
693   // Undefined
694   Control(const Control&);
695   Control& operator=(const Control&);
696
697   class Impl;
698   Impl *mImpl;
699
700   friend class Internal::StyleChangeProcessor;
701   friend class Internal::RelayoutControllerImpl;   ///< Relayout controller needs to call Relayout() which is private.
702   friend class Internal::KeyInputFocusManager;     ///< KeyInputFocusManager needs to call which is private.
703 };
704
705 } // namespace Internal
706
707 typedef Internal::Control ControlImpl; ///< @deprecated, Use Internal::Control
708
709 } // namespace Toolkit
710
711 } // namespace Dali
712
713 /**
714  * @}
715  */
716 #endif // __DALI_TOOLKIT_CONTROL_IMPL_H__