[3.0] Fix Control::ClearBackground
[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/public-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   mImpl->mBackgroundColor = Color::TRANSPARENT;
483 }
484
485 void Control::EnableGestureDetection(Gesture::Type type)
486 {
487   if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
488   {
489     mImpl->mPinchGestureDetector = PinchGestureDetector::New();
490     mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
491     mImpl->mPinchGestureDetector.Attach(Self());
492   }
493
494   if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
495   {
496     mImpl->mPanGestureDetector = PanGestureDetector::New();
497     mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
498     mImpl->mPanGestureDetector.Attach(Self());
499   }
500
501   if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
502   {
503     mImpl->mTapGestureDetector = TapGestureDetector::New();
504     mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
505     mImpl->mTapGestureDetector.Attach(Self());
506   }
507
508   if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
509   {
510     mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
511     mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
512     mImpl->mLongPressGestureDetector.Attach(Self());
513   }
514 }
515
516 void Control::DisableGestureDetection(Gesture::Type type)
517 {
518   if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
519   {
520     mImpl->mPinchGestureDetector.Detach(Self());
521     mImpl->mPinchGestureDetector.Reset();
522   }
523
524   if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
525   {
526     mImpl->mPanGestureDetector.Detach(Self());
527     mImpl->mPanGestureDetector.Reset();
528   }
529
530   if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
531   {
532     mImpl->mTapGestureDetector.Detach(Self());
533     mImpl->mTapGestureDetector.Reset();
534   }
535
536   if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
537   {
538     mImpl->mLongPressGestureDetector.Detach(Self());
539     mImpl->mLongPressGestureDetector.Reset();
540   }
541 }
542
543 PinchGestureDetector Control::GetPinchGestureDetector() const
544 {
545   return mImpl->mPinchGestureDetector;
546 }
547
548 PanGestureDetector Control::GetPanGestureDetector() const
549 {
550   return mImpl->mPanGestureDetector;
551 }
552
553 TapGestureDetector Control::GetTapGestureDetector() const
554 {
555   return mImpl->mTapGestureDetector;
556 }
557
558 LongPressGestureDetector Control::GetLongPressGestureDetector() const
559 {
560   return mImpl->mLongPressGestureDetector;
561 }
562
563 void Control::SetKeyboardNavigationSupport(bool isSupported)
564 {
565   mImpl->mIsKeyboardNavigationSupported = isSupported;
566 }
567
568 bool Control::IsKeyboardNavigationSupported()
569 {
570   return mImpl->mIsKeyboardNavigationSupported;
571 }
572
573 void Control::SetKeyInputFocus()
574 {
575   if( Self().OnStage() )
576   {
577     Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
578   }
579 }
580
581 bool Control::HasKeyInputFocus()
582 {
583   bool result = false;
584   if( Self().OnStage() )
585   {
586     result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
587   }
588   return result;
589 }
590
591 void Control::ClearKeyInputFocus()
592 {
593   if( Self().OnStage() )
594   {
595     Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
596   }
597 }
598
599 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
600 {
601   mImpl->mIsKeyboardFocusGroup = isFocusGroup;
602
603   // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
604   Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
605 }
606
607 bool Control::IsKeyboardFocusGroup()
608 {
609   return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
610 }
611
612 void Control::AccessibilityActivate()
613 {
614   // Inform deriving classes
615   OnAccessibilityActivated();
616 }
617
618 void Control::KeyboardEnter()
619 {
620   // Inform deriving classes
621   OnKeyboardEnter();
622 }
623
624 bool Control::OnAccessibilityActivated()
625 {
626   return false; // Accessibility activation is not handled by default
627 }
628
629 bool Control::OnKeyboardEnter()
630 {
631   return false; // Keyboard enter is not handled by default
632 }
633
634 bool Control::OnAccessibilityPan(PanGesture gesture)
635 {
636   return false; // Accessibility pan gesture is not handled by default
637 }
638
639 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
640 {
641   return false; // Accessibility touch event is not handled by default
642 }
643
644 bool Control::OnAccessibilityValueChange(bool isIncrease)
645 {
646   return false; // Accessibility value change action is not handled by default
647 }
648
649 bool Control::OnAccessibilityZoom()
650 {
651   return false; // Accessibility zoom action is not handled by default
652 }
653
654 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
655 {
656   return Actor();
657 }
658
659 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
660 {
661 }
662
663 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
664 {
665   return mImpl->mKeyEventSignal;
666 }
667
668 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusGainedSignal()
669 {
670   return mImpl->mKeyInputFocusGainedSignal;
671 }
672
673 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusLostSignal()
674 {
675   return mImpl->mKeyInputFocusLostSignal;
676 }
677
678 bool Control::EmitKeyEventSignal( const KeyEvent& event )
679 {
680   // Guard against destruction during signal emission
681   Dali::Toolkit::Control handle( GetOwner() );
682
683   bool consumed = false;
684
685   // signals are allocated dynamically when someone connects
686   if ( !mImpl->mKeyEventSignal.Empty() )
687   {
688     consumed = mImpl->mKeyEventSignal.Emit( handle, event );
689   }
690
691   if (!consumed)
692   {
693     // Notification for derived classes
694     consumed = OnKeyEvent(event);
695   }
696
697   return consumed;
698 }
699
700 Control::Control( ControlBehaviour behaviourFlags )
701 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
702   mImpl(new Impl(*this))
703 {
704   mImpl->mFlags = behaviourFlags;
705 }
706
707 void Control::Initialize()
708 {
709   // Call deriving classes so initialised before styling is applied to them.
710   OnInitialize();
711
712   if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
713   {
714     Toolkit::StyleManager styleManager = StyleManager::Get();
715
716     // if stylemanager is available
717     if( styleManager )
718     {
719       StyleManager& styleManagerImpl = GetImpl( styleManager );
720
721       // Register for style changes
722       styleManagerImpl.ControlStyleChangeSignal().Connect( this, &Control::OnStyleChange );
723
724       // Apply the current style
725       styleManagerImpl.ApplyThemeStyleAtInit( Toolkit::Control( GetOwner() ) );
726     }
727   }
728
729   if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
730   {
731     SetKeyboardNavigationSupport( true );
732   }
733 }
734
735 void Control::OnInitialize()
736 {
737 }
738
739 void Control::OnControlChildAdd( Actor& child )
740 {
741 }
742
743 void Control::OnControlChildRemove( Actor& child )
744 {
745 }
746
747 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
748 {
749   // By default the control is only interested in theme (not font) changes
750   if( styleManager && change == StyleChange::THEME_CHANGE )
751   {
752     GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
753   }
754 }
755
756 void Control::OnPinch(const PinchGesture& pinch)
757 {
758   if( !( mImpl->mStartingPinchScale ) )
759   {
760     // lazy allocate
761     mImpl->mStartingPinchScale = new Vector3;
762   }
763
764   if( pinch.state == Gesture::Started )
765   {
766     *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
767   }
768
769   Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
770 }
771
772 void Control::OnPan( const PanGesture& pan )
773 {
774 }
775
776 void Control::OnTap(const TapGesture& tap)
777 {
778 }
779
780 void Control::OnLongPress( const LongPressGesture& longPress )
781 {
782 }
783
784 void Control::EmitKeyInputFocusSignal( bool focusGained )
785 {
786   Dali::Toolkit::Control handle( GetOwner() );
787
788   if ( focusGained )
789   {
790     // signals are allocated dynamically when someone connects
791     if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
792     {
793       mImpl->mKeyInputFocusGainedSignal.Emit( handle );
794     }
795   }
796   else
797   {
798     // signals are allocated dynamically when someone connects
799     if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
800     {
801       mImpl->mKeyInputFocusLostSignal.Emit( handle );
802     }
803   }
804 }
805
806 void Control::OnStageConnection( int depth )
807 {
808   if( mImpl->mBackgroundRenderer)
809   {
810     Actor self( Self() );
811     mImpl->mBackgroundRenderer.SetOnStage( self );
812   }
813 }
814
815 void Control::OnStageDisconnection()
816 {
817   if( mImpl->mBackgroundRenderer )
818   {
819     Actor self( Self() );
820     mImpl->mBackgroundRenderer.SetOffStage( self );
821   }
822 }
823
824 void Control::OnKeyInputFocusGained()
825 {
826   EmitKeyInputFocusSignal( true );
827 }
828
829 void Control::OnKeyInputFocusLost()
830 {
831   EmitKeyInputFocusSignal( false );
832 }
833
834 void Control::OnChildAdd(Actor& child)
835 {
836   // Notify derived classes.
837   OnControlChildAdd( child );
838 }
839
840 void Control::OnChildRemove(Actor& child)
841 {
842   // Notify derived classes.
843   OnControlChildRemove( child );
844 }
845
846 void Control::OnSizeSet(const Vector3& targetSize)
847 {
848   if( mImpl->mBackgroundRenderer )
849   {
850     Vector2 size( targetSize );
851     mImpl->mBackgroundRenderer.SetSize( size );
852   }
853 }
854
855 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
856 {
857   // @todo size negotiate background to new size, animate as well?
858 }
859
860 bool Control::OnTouchEvent(const TouchEvent& event)
861 {
862   return false; // Do not consume
863 }
864
865 bool Control::OnHoverEvent(const HoverEvent& event)
866 {
867   return false; // Do not consume
868 }
869
870 bool Control::OnKeyEvent(const KeyEvent& event)
871 {
872   return false; // Do not consume
873 }
874
875 bool Control::OnWheelEvent(const WheelEvent& event)
876 {
877   return false; // Do not consume
878 }
879
880 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
881 {
882   for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
883   {
884     container.Add( Self().GetChildAt( i ), size );
885   }
886 }
887
888 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
889 {
890 }
891
892 Vector3 Control::GetNaturalSize()
893 {
894   if( mImpl->mBackgroundRenderer )
895   {
896     Vector2 naturalSize;
897     mImpl->mBackgroundRenderer.GetNaturalSize(naturalSize);
898     return Vector3(naturalSize);
899   }
900   return Vector3::ZERO;
901 }
902
903 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
904 {
905   return CalculateChildSizeBase( child, dimension );
906 }
907
908 float Control::GetHeightForWidth( float width )
909 {
910   return GetHeightForWidthBase( width );
911 }
912
913 float Control::GetWidthForHeight( float height )
914 {
915   return GetWidthForHeightBase( height );
916 }
917
918 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
919 {
920   return RelayoutDependentOnChildrenBase( dimension );
921 }
922
923 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
924 {
925 }
926
927 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
928 {
929 }
930
931 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
932 {
933   mImpl->SignalConnected( slotObserver, callback );
934 }
935
936 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
937 {
938   mImpl->SignalDisconnected( slotObserver, callback );
939 }
940
941 Control& GetImplementation( Dali::Toolkit::Control& handle )
942 {
943   CustomActorImpl& customInterface = handle.GetImplementation();
944   // downcast to control
945   Control& impl = dynamic_cast< Internal::Control& >( customInterface );
946   return impl;
947 }
948
949 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
950 {
951   const CustomActorImpl& customInterface = handle.GetImplementation();
952   // downcast to control
953   const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
954   return impl;
955 }
956
957 } // namespace Internal
958
959 } // namespace Toolkit
960
961 } // namespace Dali