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