Rename of Control Renderers to Visuals
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / control-impl.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/public-api/controls/control-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <cstring> // for strcmp
23 #include <limits>
24 #include <stack>
25 #include <dali/public-api/animation/constraint.h>
26 #include <dali/public-api/animation/constraints.h>
27 #include <dali/public-api/object/type-registry.h>
28 #include <dali/public-api/object/type-registry-helper.h>
29 #include <dali/public-api/rendering/renderer.h>
30 #include <dali/public-api/size-negotiation/relayout-container.h>
31 #include <dali/devel-api/scripting/scripting.h>
32 #include <dali/integration-api/debug.h>
33
34 // INTERNAL INCLUDES
35 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
36 #include <dali-toolkit/public-api/controls/control.h>
37 #include <dali-toolkit/public-api/styling/style-manager.h>
38 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
39 #include <dali-toolkit/devel-api/controls/visual-factory/visual-factory.h>
40 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
41 #include <dali-toolkit/internal/styling/style-manager-impl.h>
42 #include <dali-toolkit/internal/controls/renderers/color/color-visual.h>
43 #include <dali-toolkit/internal/controls/renderers/visual-string-constants.h>
44
45 namespace Dali
46 {
47
48 namespace Toolkit
49 {
50
51 namespace
52 {
53
54 /**
55  * Creates control through type registry
56  */
57 BaseHandle Create()
58 {
59   return Internal::Control::New();
60 }
61
62 /**
63  * Performs actions as requested using the action name.
64  * @param[in] object The object on which to perform the action.
65  * @param[in] actionName The action to perform.
66  * @param[in] attributes The attributes with which to perfrom this action.
67  * @return true if action has been accepted by this control
68  */
69 const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibilityActivated";
70 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
71 {
72   bool ret = false;
73
74   if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ) )
75   {
76     Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
77     if( control )
78     {
79       // if cast succeeds there is an implementation so no need to check
80       ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
81     }
82   }
83
84   return ret;
85 }
86
87 /**
88  * Connects a callback function with the object's signals.
89  * @param[in] object The object providing the signal.
90  * @param[in] tracker Used to disconnect the signal.
91  * @param[in] signalName The signal to connect to.
92  * @param[in] functor A newly allocated FunctorDelegate.
93  * @return True if the signal was connected.
94  * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
95  */
96 const char* SIGNAL_KEY_EVENT = "keyEvent";
97 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "keyInputFocusGained";
98 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "keyInputFocusLost";
99 const char* SIGNAL_TAPPED = "tapped";
100 const char* SIGNAL_PANNED = "panned";
101 const char* SIGNAL_PINCHED = "pinched";
102 const char* SIGNAL_LONG_PRESSED = "longPressed";
103 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
104 {
105   Dali::BaseHandle handle( object );
106
107   bool connected( false );
108   Toolkit::Control control = Toolkit::Control::DownCast( handle );
109   if ( control )
110   {
111     Internal::Control& controlImpl( Internal::GetImplementation( control ) );
112     connected = true;
113
114     if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
115     {
116       controlImpl.KeyEventSignal().Connect( tracker, functor );
117     }
118     else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
119     {
120       controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
121     }
122     else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
123     {
124       controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
125     }
126     else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
127     {
128       controlImpl.EnableGestureDetection( Gesture::Tap );
129       controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
130     }
131     else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
132     {
133       controlImpl.EnableGestureDetection( Gesture::Pan );
134       controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
135     }
136     else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
137     {
138       controlImpl.EnableGestureDetection( Gesture::Pinch );
139       controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
140     }
141     else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
142     {
143       controlImpl.EnableGestureDetection( Gesture::LongPress );
144       controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
145     }
146   }
147   return connected;
148 }
149
150 // Setup signals and actions using the type-registry.
151 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
152
153 // Note: Properties are registered separately below.
154
155 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
156 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
157 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
158 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
159 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
160 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
161 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
162
163 TypeAction registerAction( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &DoAction );
164
165 DALI_TYPE_REGISTRATION_END()
166
167 } // unnamed namespace
168
169 namespace Internal
170 {
171
172 class Control::Impl : public ConnectionTracker
173 {
174 public:
175
176   // Construction & Destruction
177   Impl(Control& controlImpl)
178 : mControlImpl( controlImpl ),
179   mStyleName(""),
180   mBackgroundRenderer(),
181   mBackgroundColor(Color::TRANSPARENT),
182   mStartingPinchScale( NULL ),
183   mKeyEventSignal(),
184   mPinchGestureDetector(),
185   mPanGestureDetector(),
186   mTapGestureDetector(),
187   mLongPressGestureDetector(),
188   mFlags( Control::ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ),
189   mIsKeyboardNavigationSupported( false ),
190   mIsKeyboardFocusGroup( false )
191 {
192 }
193
194   ~Impl()
195   {
196     // All gesture detectors will be destroyed so no need to disconnect.
197     delete mStartingPinchScale;
198   }
199
200   // Gesture Detection Methods
201
202   void PinchDetected(Actor actor, const PinchGesture& pinch)
203   {
204     mControlImpl.OnPinch(pinch);
205   }
206
207   void PanDetected(Actor actor, const PanGesture& pan)
208   {
209     mControlImpl.OnPan(pan);
210   }
211
212   void TapDetected(Actor actor, const TapGesture& tap)
213   {
214     mControlImpl.OnTap(tap);
215   }
216
217   void LongPressDetected(Actor actor, const LongPressGesture& longPress)
218   {
219     mControlImpl.OnLongPress(longPress);
220   }
221
222   // Properties
223
224   /**
225    * Called when a property of an object of this type is set.
226    * @param[in] object The object whose property is set.
227    * @param[in] index The property index.
228    * @param[in] value The new property value.
229    */
230   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
231   {
232     Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
233
234     if ( control )
235     {
236       Control& controlImpl( GetImplementation( control ) );
237
238       switch ( index )
239       {
240         case Toolkit::Control::Property::STYLE_NAME:
241         {
242           controlImpl.SetStyleName( value.Get< std::string >() );
243           break;
244         }
245
246         case Toolkit::Control::Property::BACKGROUND_COLOR:
247         {
248           DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
249           controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
250           break;
251         }
252
253         case Toolkit::Control::Property::BACKGROUND_IMAGE:
254         {
255           DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
256           Image image = Scripting::NewImage( value );
257           if ( image )
258           {
259             controlImpl.SetBackgroundImage( image );
260           }
261           else
262           {
263             // An empty map means the background is no longer required
264             controlImpl.ClearBackground();
265           }
266           break;
267         }
268
269         case Toolkit::Control::Property::KEY_INPUT_FOCUS:
270         {
271           if ( value.Get< bool >() )
272           {
273             controlImpl.SetKeyInputFocus();
274           }
275           else
276           {
277             controlImpl.ClearKeyInputFocus();
278           }
279           break;
280         }
281
282         case Toolkit::Control::Property::BACKGROUND:
283         {
284           const Property::Map* map = value.GetMap();
285           if( map )
286           {
287             controlImpl.SetBackground( *map );
288           }
289           else
290           {
291             // The background is not a property map, so we should clear the background
292             controlImpl.ClearBackground();
293           }
294           break;
295         }
296       }
297     }
298   }
299
300   /**
301    * Called to retrieve a property of an object of this type.
302    * @param[in] object The object whose property is to be retrieved.
303    * @param[in] index The property index.
304    * @return The current value of the property.
305    */
306   static Property::Value GetProperty( BaseObject* object, Property::Index index )
307   {
308     Property::Value value;
309
310     Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
311
312     if ( control )
313     {
314       Control& controlImpl( GetImplementation( control ) );
315
316       switch ( index )
317       {
318         case Toolkit::Control::Property::STYLE_NAME:
319         {
320           value = controlImpl.GetStyleName();
321           break;
322         }
323
324         case Toolkit::Control::Property::BACKGROUND_COLOR:
325         {
326           DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
327           value = controlImpl.GetBackgroundColor();
328           break;
329         }
330
331         case Toolkit::Control::Property::BACKGROUND_IMAGE:
332         {
333           DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
334           Property::Map map;
335           if( controlImpl.mImpl->mBackgroundRenderer )
336           {
337             controlImpl.mImpl->mBackgroundRenderer.CreatePropertyMap( map );
338           }
339           value = map;
340           break;
341         }
342
343         case Toolkit::Control::Property::KEY_INPUT_FOCUS:
344         {
345           value = controlImpl.HasKeyInputFocus();
346           break;
347         }
348
349         case Toolkit::Control::Property::BACKGROUND:
350         {
351           Property::Map map;
352           if( controlImpl.mImpl->mBackgroundRenderer )
353           {
354             (controlImpl.mImpl->mBackgroundRenderer).CreatePropertyMap( map );
355           }
356
357           value = map;
358           break;
359         }
360
361       }
362     }
363
364     return value;
365   }
366
367   // Data
368
369   Control& mControlImpl;
370   std::string mStyleName;
371   Toolkit::Visual mBackgroundRenderer;   ///< The control renderer to render the background
372   Vector4 mBackgroundColor;                       ///< The color of the background renderer
373   Vector3* mStartingPinchScale;      ///< The scale when a pinch gesture starts, TODO: consider removing this
374   Toolkit::Control::KeyEventSignalType mKeyEventSignal;
375   Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
376   Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
377
378   // Gesture Detection
379   PinchGestureDetector mPinchGestureDetector;
380   PanGestureDetector mPanGestureDetector;
381   TapGestureDetector mTapGestureDetector;
382   LongPressGestureDetector mLongPressGestureDetector;
383
384   ControlBehaviour mFlags :CONTROL_BEHAVIOUR_FLAG_COUNT;    ///< Flags passed in from constructor.
385   bool mIsKeyboardNavigationSupported :1;  ///< Stores whether keyboard navigation is supported by the control.
386   bool mIsKeyboardFocusGroup :1;           ///< Stores whether the control is a focus group.
387
388   // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
389   static const PropertyRegistration PROPERTY_1;
390   static const PropertyRegistration PROPERTY_2;
391   static const PropertyRegistration PROPERTY_3;
392   static const PropertyRegistration PROPERTY_4;
393   static const PropertyRegistration PROPERTY_5;
394 };
395
396 // Properties registered without macro to use specific member variables.
397 const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName",       Toolkit::Control::Property::STYLE_NAME,       Property::STRING,  &Control::Impl::SetProperty, &Control::Impl::GetProperty );
398 const PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "backgroundColor", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
399 const PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "backgroundImage", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP,     &Control::Impl::SetProperty, &Control::Impl::GetProperty );
400 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus",   Toolkit::Control::Property::KEY_INPUT_FOCUS,  Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
401 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background",      Toolkit::Control::Property::BACKGROUND,       Property::MAP,     &Control::Impl::SetProperty, &Control::Impl::GetProperty );
402
403 Toolkit::Control Control::New()
404 {
405   // Create the implementation, temporarily owned on stack
406   IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) );
407
408   // Pass ownership to handle
409   Toolkit::Control handle( *controlImpl );
410
411   // Second-phase init of the implementation
412   // This can only be done after the CustomActor connection has been made...
413   controlImpl->Initialize();
414
415   return handle;
416 }
417
418 Control::~Control()
419 {
420   delete mImpl;
421 }
422
423 void Control::SetStyleName( const std::string& styleName )
424 {
425   if( styleName != mImpl->mStyleName )
426   {
427     mImpl->mStyleName = styleName;
428
429     // Apply new style, if stylemanager is available
430     Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
431     if( styleManager )
432     {
433       GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
434     }
435   }
436 }
437
438 const std::string& Control::GetStyleName() const
439 {
440   return mImpl->mStyleName;
441 }
442
443 void Control::SetBackgroundColor( const Vector4& color )
444 {
445   Actor self( Self() );
446   mImpl->mBackgroundColor = color;
447   Property::Map map;
448   map[ RENDERER_TYPE ] = COLOR_RENDERER;
449   map[ "mixColor" ] = color;
450   InitializeVisual( self, mImpl->mBackgroundRenderer, map );
451   if( mImpl->mBackgroundRenderer )
452   {
453     mImpl->mBackgroundRenderer.SetDepthIndex( DepthIndex::BACKGROUND );
454   }
455 }
456
457 Vector4 Control::GetBackgroundColor() const
458 {
459   return mImpl->mBackgroundColor;
460 }
461
462 void Control::SetBackground( const Property::Map& map )
463 {
464   Actor self( Self() );
465   InitializeVisual( self, mImpl->mBackgroundRenderer, map );
466   if( mImpl->mBackgroundRenderer )
467   {
468     mImpl->mBackgroundRenderer.SetDepthIndex( DepthIndex::BACKGROUND );
469   }
470 }
471
472 void Control::SetBackgroundImage( Image image )
473 {
474   Actor self( Self() );
475   InitializeVisual( self, mImpl->mBackgroundRenderer, image );
476   if( mImpl->mBackgroundRenderer )
477   {
478     mImpl->mBackgroundRenderer.SetDepthIndex( DepthIndex::BACKGROUND );
479   }
480 }
481
482 void Control::ClearBackground()
483 {
484   Actor self( Self() );
485   mImpl->mBackgroundRenderer.RemoveAndReset( self );
486 }
487
488 void Control::EnableGestureDetection(Gesture::Type type)
489 {
490   if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
491   {
492     mImpl->mPinchGestureDetector = PinchGestureDetector::New();
493     mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
494     mImpl->mPinchGestureDetector.Attach(Self());
495   }
496
497   if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
498   {
499     mImpl->mPanGestureDetector = PanGestureDetector::New();
500     mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
501     mImpl->mPanGestureDetector.Attach(Self());
502   }
503
504   if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
505   {
506     mImpl->mTapGestureDetector = TapGestureDetector::New();
507     mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
508     mImpl->mTapGestureDetector.Attach(Self());
509   }
510
511   if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
512   {
513     mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
514     mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
515     mImpl->mLongPressGestureDetector.Attach(Self());
516   }
517 }
518
519 void Control::DisableGestureDetection(Gesture::Type type)
520 {
521   if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
522   {
523     mImpl->mPinchGestureDetector.Detach(Self());
524     mImpl->mPinchGestureDetector.Reset();
525   }
526
527   if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
528   {
529     mImpl->mPanGestureDetector.Detach(Self());
530     mImpl->mPanGestureDetector.Reset();
531   }
532
533   if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
534   {
535     mImpl->mTapGestureDetector.Detach(Self());
536     mImpl->mTapGestureDetector.Reset();
537   }
538
539   if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
540   {
541     mImpl->mLongPressGestureDetector.Detach(Self());
542     mImpl->mLongPressGestureDetector.Reset();
543   }
544 }
545
546 PinchGestureDetector Control::GetPinchGestureDetector() const
547 {
548   return mImpl->mPinchGestureDetector;
549 }
550
551 PanGestureDetector Control::GetPanGestureDetector() const
552 {
553   return mImpl->mPanGestureDetector;
554 }
555
556 TapGestureDetector Control::GetTapGestureDetector() const
557 {
558   return mImpl->mTapGestureDetector;
559 }
560
561 LongPressGestureDetector Control::GetLongPressGestureDetector() const
562 {
563   return mImpl->mLongPressGestureDetector;
564 }
565
566 void Control::SetKeyboardNavigationSupport(bool isSupported)
567 {
568   mImpl->mIsKeyboardNavigationSupported = isSupported;
569 }
570
571 bool Control::IsKeyboardNavigationSupported()
572 {
573   return mImpl->mIsKeyboardNavigationSupported;
574 }
575
576 void Control::SetKeyInputFocus()
577 {
578   if( Self().OnStage() )
579   {
580     Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
581   }
582 }
583
584 bool Control::HasKeyInputFocus()
585 {
586   bool result = false;
587   if( Self().OnStage() )
588   {
589     result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
590   }
591   return result;
592 }
593
594 void Control::ClearKeyInputFocus()
595 {
596   if( Self().OnStage() )
597   {
598     Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
599   }
600 }
601
602 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
603 {
604   mImpl->mIsKeyboardFocusGroup = isFocusGroup;
605
606   // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
607   Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
608 }
609
610 bool Control::IsKeyboardFocusGroup()
611 {
612   return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
613 }
614
615 void Control::AccessibilityActivate()
616 {
617   // Inform deriving classes
618   OnAccessibilityActivated();
619 }
620
621 void Control::KeyboardEnter()
622 {
623   // Inform deriving classes
624   OnKeyboardEnter();
625 }
626
627 bool Control::OnAccessibilityActivated()
628 {
629   return false; // Accessibility activation is not handled by default
630 }
631
632 bool Control::OnKeyboardEnter()
633 {
634   return false; // Keyboard enter is not handled by default
635 }
636
637 bool Control::OnAccessibilityPan(PanGesture gesture)
638 {
639   return false; // Accessibility pan gesture is not handled by default
640 }
641
642 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
643 {
644   return false; // Accessibility touch event is not handled by default
645 }
646
647 bool Control::OnAccessibilityValueChange(bool isIncrease)
648 {
649   return false; // Accessibility value change action is not handled by default
650 }
651
652 bool Control::OnAccessibilityZoom()
653 {
654   return false; // Accessibility zoom action is not handled by default
655 }
656
657 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
658 {
659   return Actor();
660 }
661
662 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
663 {
664 }
665
666 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
667 {
668   return mImpl->mKeyEventSignal;
669 }
670
671 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusGainedSignal()
672 {
673   return mImpl->mKeyInputFocusGainedSignal;
674 }
675
676 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusLostSignal()
677 {
678   return mImpl->mKeyInputFocusLostSignal;
679 }
680
681 bool Control::EmitKeyEventSignal( const KeyEvent& event )
682 {
683   // Guard against destruction during signal emission
684   Dali::Toolkit::Control handle( GetOwner() );
685
686   bool consumed = false;
687
688   // signals are allocated dynamically when someone connects
689   if ( !mImpl->mKeyEventSignal.Empty() )
690   {
691     consumed = mImpl->mKeyEventSignal.Emit( handle, event );
692   }
693
694   if (!consumed)
695   {
696     // Notification for derived classes
697     consumed = OnKeyEvent(event);
698   }
699
700   return consumed;
701 }
702
703 Control::Control( ControlBehaviour behaviourFlags )
704 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
705   mImpl(new Impl(*this))
706 {
707   mImpl->mFlags = behaviourFlags;
708 }
709
710 void Control::Initialize()
711 {
712   // Call deriving classes so initialised before styling is applied to them.
713   OnInitialize();
714
715   if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
716   {
717     Toolkit::StyleManager styleManager = StyleManager::Get();
718
719     // if stylemanager is available
720     if( styleManager )
721     {
722       StyleManager& styleManagerImpl = GetImpl( styleManager );
723
724       // Register for style changes
725       styleManagerImpl.ControlStyleChangeSignal().Connect( this, &Control::OnStyleChange );
726
727       // Apply the current style
728       styleManagerImpl.ApplyThemeStyleAtInit( Toolkit::Control( GetOwner() ) );
729     }
730   }
731
732   if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
733   {
734     SetKeyboardNavigationSupport( true );
735   }
736 }
737
738 void Control::OnInitialize()
739 {
740 }
741
742 void Control::OnControlChildAdd( Actor& child )
743 {
744 }
745
746 void Control::OnControlChildRemove( Actor& child )
747 {
748 }
749
750 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
751 {
752   // By default the control is only interested in theme (not font) changes
753   if( styleManager && change == StyleChange::THEME_CHANGE )
754   {
755     GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
756   }
757 }
758
759 void Control::OnPinch(const PinchGesture& pinch)
760 {
761   if( !( mImpl->mStartingPinchScale ) )
762   {
763     // lazy allocate
764     mImpl->mStartingPinchScale = new Vector3;
765   }
766
767   if( pinch.state == Gesture::Started )
768   {
769     *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
770   }
771
772   Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
773 }
774
775 void Control::OnPan( const PanGesture& pan )
776 {
777 }
778
779 void Control::OnTap(const TapGesture& tap)
780 {
781 }
782
783 void Control::OnLongPress( const LongPressGesture& longPress )
784 {
785 }
786
787 void Control::EmitKeyInputFocusSignal( bool focusGained )
788 {
789   Dali::Toolkit::Control handle( GetOwner() );
790
791   if ( focusGained )
792   {
793     // signals are allocated dynamically when someone connects
794     if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
795     {
796       mImpl->mKeyInputFocusGainedSignal.Emit( handle );
797     }
798   }
799   else
800   {
801     // signals are allocated dynamically when someone connects
802     if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
803     {
804       mImpl->mKeyInputFocusLostSignal.Emit( handle );
805     }
806   }
807 }
808
809 void Control::OnStageConnection( int depth )
810 {
811   if( mImpl->mBackgroundRenderer)
812   {
813     Actor self( Self() );
814     mImpl->mBackgroundRenderer.SetOnStage( self );
815   }
816 }
817
818 void Control::OnStageDisconnection()
819 {
820   if( mImpl->mBackgroundRenderer )
821   {
822     Actor self( Self() );
823     mImpl->mBackgroundRenderer.SetOffStage( self );
824   }
825 }
826
827 void Control::OnKeyInputFocusGained()
828 {
829   EmitKeyInputFocusSignal( true );
830 }
831
832 void Control::OnKeyInputFocusLost()
833 {
834   EmitKeyInputFocusSignal( false );
835 }
836
837 void Control::OnChildAdd(Actor& child)
838 {
839   // Notify derived classes.
840   OnControlChildAdd( child );
841 }
842
843 void Control::OnChildRemove(Actor& child)
844 {
845   // Notify derived classes.
846   OnControlChildRemove( child );
847 }
848
849 void Control::OnSizeSet(const Vector3& targetSize)
850 {
851   if( mImpl->mBackgroundRenderer )
852   {
853     Vector2 size( targetSize );
854     mImpl->mBackgroundRenderer.SetSize( size );
855   }
856 }
857
858 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
859 {
860   // @todo size negotiate background to new size, animate as well?
861 }
862
863 bool Control::OnTouchEvent(const TouchEvent& event)
864 {
865   return false; // Do not consume
866 }
867
868 bool Control::OnHoverEvent(const HoverEvent& event)
869 {
870   return false; // Do not consume
871 }
872
873 bool Control::OnKeyEvent(const KeyEvent& event)
874 {
875   return false; // Do not consume
876 }
877
878 bool Control::OnWheelEvent(const WheelEvent& event)
879 {
880   return false; // Do not consume
881 }
882
883 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
884 {
885   for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
886   {
887     container.Add( Self().GetChildAt( i ), size );
888   }
889 }
890
891 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
892 {
893 }
894
895 Vector3 Control::GetNaturalSize()
896 {
897   if( mImpl->mBackgroundRenderer )
898   {
899     Vector2 naturalSize;
900     mImpl->mBackgroundRenderer.GetNaturalSize(naturalSize);
901     return Vector3(naturalSize);
902   }
903   return Vector3::ZERO;
904 }
905
906 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
907 {
908   return CalculateChildSizeBase( child, dimension );
909 }
910
911 float Control::GetHeightForWidth( float width )
912 {
913   return GetHeightForWidthBase( width );
914 }
915
916 float Control::GetWidthForHeight( float height )
917 {
918   return GetWidthForHeightBase( height );
919 }
920
921 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
922 {
923   return RelayoutDependentOnChildrenBase( dimension );
924 }
925
926 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
927 {
928 }
929
930 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
931 {
932 }
933
934 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
935 {
936   mImpl->SignalConnected( slotObserver, callback );
937 }
938
939 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
940 {
941   mImpl->SignalDisconnected( slotObserver, callback );
942 }
943
944 Control& GetImplementation( Dali::Toolkit::Control& handle )
945 {
946   CustomActorImpl& customInterface = handle.GetImplementation();
947   // downcast to control
948   Control& impl = dynamic_cast< Internal::Control& >( customInterface );
949   return impl;
950 }
951
952 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
953 {
954   const CustomActorImpl& customInterface = handle.GetImplementation();
955   // downcast to control
956   const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
957   return impl;
958 }
959
960 } // namespace Internal
961
962 } // namespace Toolkit
963
964 } // namespace Dali