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