2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/public-api/controls/control-impl.h>
22 #include <cstring> // for strcmp
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>
35 #include <dali-toolkit/public-api/controls/control-depth-index-ranges.h>
36 #include <dali-toolkit/devel-api/controls/renderer-factory/renderer-factory.h>
37 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
38 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
39 #include <dali-toolkit/public-api/controls/control.h>
40 #include <dali-toolkit/devel-api/styling/style-manager.h>
41 #include <dali-toolkit/internal/styling/style-manager-impl.h>
42 #include <dali-toolkit/internal/controls/renderers/color/color-renderer.h>
43 #include <dali-toolkit/internal/controls/renderers/image/image-renderer.h>
55 * Creates control through type registry
59 return Internal::Control::New();
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
69 const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibility-activated";
70 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
74 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ) )
76 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
79 // if cast succeeds there is an implementation so no need to check
80 ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
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.
96 const char* SIGNAL_KEY_EVENT = "key-event";
97 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "key-input-focus-gained";
98 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "key-input-focus-lost";
99 const char* SIGNAL_TAPPED = "tapped";
100 const char* SIGNAL_PANNED = "panned";
101 const char* SIGNAL_PINCHED = "pinched";
102 const char* SIGNAL_LONG_PRESSED = "long-pressed";
103 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
105 Dali::BaseHandle handle( object );
107 bool connected( false );
108 Toolkit::Control control = Toolkit::Control::DownCast( handle );
111 Internal::Control& controlImpl( Internal::GetImplementation( control ) );
114 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
116 controlImpl.KeyEventSignal().Connect( tracker, functor );
118 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
120 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
122 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
124 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
126 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
128 controlImpl.EnableGestureDetection( Gesture::Tap );
129 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
131 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
133 controlImpl.EnableGestureDetection( Gesture::Pan );
134 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
136 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
138 controlImpl.EnableGestureDetection( Gesture::Pinch );
139 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
141 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
143 controlImpl.EnableGestureDetection( Gesture::LongPress );
144 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
150 // Setup signals and actions using the type-registry.
151 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
153 // Note: Properties are registered separately below.
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 );
163 TypeAction registerAction( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &DoAction );
165 DALI_TYPE_REGISTRATION_END()
167 const char * const BACKGROUND_COLOR_NAME("color");
169 } // unnamed namespace
174 class Control::Impl : public ConnectionTracker
178 // Construction & Destruction
179 Impl(Control& controlImpl)
180 : mControlImpl( controlImpl ),
182 mBackgroundRenderer(),
183 mStartingPinchScale( NULL ),
185 mPinchGestureDetector(),
186 mPanGestureDetector(),
187 mTapGestureDetector(),
188 mLongPressGestureDetector(),
189 mFlags( Control::ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ),
190 mIsKeyboardNavigationSupported( false ),
191 mIsKeyboardFocusGroup( false ),
192 mAddRemoveBackgroundChild( false )
198 // All gesture detectors will be destroyed so no need to disconnect.
199 delete mStartingPinchScale;
202 // Gesture Detection Methods
204 void PinchDetected(Actor actor, const PinchGesture& pinch)
206 mControlImpl.OnPinch(pinch);
209 void PanDetected(Actor actor, const PanGesture& pan)
211 mControlImpl.OnPan(pan);
214 void TapDetected(Actor actor, const TapGesture& tap)
216 mControlImpl.OnTap(tap);
219 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
221 mControlImpl.OnLongPress(longPress);
227 * Called when a property of an object of this type is set.
228 * @param[in] object The object whose property is set.
229 * @param[in] index The property index.
230 * @param[in] value The new property value.
232 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
234 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
238 Control& controlImpl( GetImplementation( control ) );
242 case Toolkit::Control::Property::STYLE_NAME:
244 controlImpl.SetStyleName( value.Get< std::string >() );
247 case Toolkit::Control::Property::BACKGROUND:
249 Image image = Scripting::NewImage( value );
252 controlImpl.SetBackgroundImage( image );
255 const Property::Map* map = value.GetMap();
258 controlImpl.SetBackground( *map );
262 // The background is neither a valid image nor a property map, so it is no longer required
263 controlImpl.ClearBackground();
267 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
269 if ( value.Get< bool >() )
271 controlImpl.SetKeyInputFocus();
275 controlImpl.ClearKeyInputFocus();
284 * Called to retrieve a property of an object of this type.
285 * @param[in] object The object whose property is to be retrieved.
286 * @param[in] index The property index.
287 * @return The current value of the property.
289 static Property::Value GetProperty( BaseObject* object, Property::Index index )
291 Property::Value value;
293 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
297 Control& controlImpl( GetImplementation( control ) );
301 case Toolkit::Control::Property::STYLE_NAME:
303 value = controlImpl.GetStyleName();
307 case Toolkit::Control::Property::BACKGROUND:
310 if( controlImpl.mImpl->mBackgroundRenderer )
312 (controlImpl.mImpl->mBackgroundRenderer).CreatePropertyMap( map );
319 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
321 value = controlImpl.HasKeyInputFocus();
332 Control& mControlImpl;
333 std::string mStyleName;
334 Toolkit::ControlRenderer mBackgroundRenderer; ///< The control renderer to render the background
335 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
336 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
337 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
338 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
341 PinchGestureDetector mPinchGestureDetector;
342 PanGestureDetector mPanGestureDetector;
343 TapGestureDetector mTapGestureDetector;
344 LongPressGestureDetector mLongPressGestureDetector;
346 ControlBehaviour mFlags :CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
347 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
348 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
349 bool mAddRemoveBackgroundChild:1; ///< Flag to know when we are adding or removing our own actor to avoid call to OnControlChildAdd
351 // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
352 static PropertyRegistration PROPERTY_1;
353 static PropertyRegistration PROPERTY_2;
354 static PropertyRegistration PROPERTY_3;
357 // Properties registered without macro to use specific member variables.
358 PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "style-name", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
359 PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
360 PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "key-input-focus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
362 Toolkit::Control Control::New()
364 // Create the implementation, temporarily owned on stack
365 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) );
367 // Pass ownership to handle
368 Toolkit::Control handle( *controlImpl );
370 // Second-phase init of the implementation
371 // This can only be done after the CustomActor connection has been made...
372 controlImpl->Initialize();
382 void Control::SetStyleName( const std::string& styleName )
384 if( styleName != mImpl->mStyleName )
386 mImpl->mStyleName = styleName;
388 // Apply new style, if stylemanager is available
389 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
392 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
397 const std::string& Control::GetStyleName() const
399 return mImpl->mStyleName;
402 void Control::SetBackgroundColor( const Vector4& color )
404 Actor self( Self() );
405 Toolkit::RendererFactory factory = Toolkit::RendererFactory::Get();
407 if( mImpl->mBackgroundRenderer )
409 Toolkit::ControlRenderer currentRenderer( mImpl->mBackgroundRenderer );
410 // if ResetRenderer returns false, we continue to use the current renderer with a new color set to it.
411 if( ! factory.ResetRenderer( mImpl->mBackgroundRenderer, color ) )
415 // ResetRenderer returns true, a new renderer is created. Remove the current renderer and reset.
416 currentRenderer.RemoveAndReset( self );
420 mImpl->mBackgroundRenderer = factory.GetControlRenderer( color );
425 mImpl->mBackgroundRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX );
426 mImpl->mBackgroundRenderer.SetOnStage( self );
430 Vector4 Control::GetBackgroundColor() const
432 return Color::TRANSPARENT;
435 void Control::SetBackground(const Property::Map& map)
437 const Property::Value* colorValue = map.Find( BACKGROUND_COLOR_NAME );
439 if( colorValue && colorValue->Get(color))
441 SetBackgroundColor( color );
445 Actor self( Self() );
446 mImpl->mBackgroundRenderer.RemoveAndReset( self );
448 Toolkit::RendererFactory factory = Toolkit::RendererFactory::Get();
449 mImpl->mBackgroundRenderer = factory.GetControlRenderer( map );
451 // mBackgroundRenderer might be empty, if an invalid map is provided, no background.
452 if( self.OnStage() && mImpl->mBackgroundRenderer)
454 mImpl->mBackgroundRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX );
455 mImpl->mBackgroundRenderer.SetOnStage( self );
459 void Control::SetBackgroundImage( Image image )
461 Actor self( Self() );
462 Toolkit::RendererFactory factory = Toolkit::RendererFactory::Get();
464 if( mImpl->mBackgroundRenderer )
466 Toolkit::ControlRenderer currentRenderer( mImpl->mBackgroundRenderer );
467 // if ResetRenderer returns false, we continue to use the current renderer with a new image set to it.
468 if( ! factory.ResetRenderer( mImpl->mBackgroundRenderer, image ) )
472 // ResetRenderer returns true, a new renderer is created. Remove the current renderer and reset.
473 currentRenderer.RemoveAndReset( self );
477 mImpl->mBackgroundRenderer = factory.GetControlRenderer( image );
482 mImpl->mBackgroundRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX );
483 mImpl->mBackgroundRenderer.SetOnStage( self );
487 void Control::ClearBackground()
490 mImpl->mBackgroundRenderer.RemoveAndReset( self );
493 void Control::EnableGestureDetection(Gesture::Type type)
495 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
497 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
498 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
499 mImpl->mPinchGestureDetector.Attach(Self());
502 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
504 mImpl->mPanGestureDetector = PanGestureDetector::New();
505 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
506 mImpl->mPanGestureDetector.Attach(Self());
509 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
511 mImpl->mTapGestureDetector = TapGestureDetector::New();
512 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
513 mImpl->mTapGestureDetector.Attach(Self());
516 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
518 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
519 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
520 mImpl->mLongPressGestureDetector.Attach(Self());
524 void Control::DisableGestureDetection(Gesture::Type type)
526 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
528 mImpl->mPinchGestureDetector.Detach(Self());
529 mImpl->mPinchGestureDetector.Reset();
532 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
534 mImpl->mPanGestureDetector.Detach(Self());
535 mImpl->mPanGestureDetector.Reset();
538 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
540 mImpl->mTapGestureDetector.Detach(Self());
541 mImpl->mTapGestureDetector.Reset();
544 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
546 mImpl->mLongPressGestureDetector.Detach(Self());
547 mImpl->mLongPressGestureDetector.Reset();
551 PinchGestureDetector Control::GetPinchGestureDetector() const
553 return mImpl->mPinchGestureDetector;
556 PanGestureDetector Control::GetPanGestureDetector() const
558 return mImpl->mPanGestureDetector;
561 TapGestureDetector Control::GetTapGestureDetector() const
563 return mImpl->mTapGestureDetector;
566 LongPressGestureDetector Control::GetLongPressGestureDetector() const
568 return mImpl->mLongPressGestureDetector;
571 void Control::SetKeyboardNavigationSupport(bool isSupported)
573 mImpl->mIsKeyboardNavigationSupported = isSupported;
576 bool Control::IsKeyboardNavigationSupported()
578 return mImpl->mIsKeyboardNavigationSupported;
581 void Control::SetKeyInputFocus()
583 if( Self().OnStage() )
585 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
589 bool Control::HasKeyInputFocus()
592 if( Self().OnStage() )
594 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
599 void Control::ClearKeyInputFocus()
601 if( Self().OnStage() )
603 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
607 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
609 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
611 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
612 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
615 bool Control::IsKeyboardFocusGroup()
617 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
620 void Control::AccessibilityActivate()
622 // Inform deriving classes
623 OnAccessibilityActivated();
626 void Control::KeyboardEnter()
628 // Inform deriving classes
632 bool Control::OnAccessibilityActivated()
634 return false; // Accessibility activation is not handled by default
637 bool Control::OnKeyboardEnter()
639 return false; // Keyboard enter is not handled by default
642 bool Control::OnAccessibilityPan(PanGesture gesture)
644 return false; // Accessibility pan gesture is not handled by default
647 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
649 return false; // Accessibility touch event is not handled by default
652 bool Control::OnAccessibilityValueChange(bool isIncrease)
654 return false; // Accessibility value change action is not handled by default
657 bool Control::OnAccessibilityZoom()
659 return false; // Accessibility zoom action is not handled by default
662 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
667 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
671 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
673 return mImpl->mKeyEventSignal;
676 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusGainedSignal()
678 return mImpl->mKeyInputFocusGainedSignal;
681 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusLostSignal()
683 return mImpl->mKeyInputFocusLostSignal;
686 bool Control::EmitKeyEventSignal( const KeyEvent& event )
688 // Guard against destruction during signal emission
689 Dali::Toolkit::Control handle( GetOwner() );
691 bool consumed = false;
693 // signals are allocated dynamically when someone connects
694 if ( !mImpl->mKeyEventSignal.Empty() )
696 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
701 // Notification for derived classes
702 consumed = OnKeyEvent(event);
708 Control::Control( ControlBehaviour behaviourFlags )
709 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
710 mImpl(new Impl(*this))
712 mImpl->mFlags = behaviourFlags;
715 void Control::Initialize()
717 // Call deriving classes so initialised before styling is applied to them.
720 if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
722 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
723 // if stylemanager is available
726 // Register for style changes
727 styleManager.StyleChangeSignal().Connect( this, &Control::OnStyleChange );
729 // Apply the current style
730 GetImpl( styleManager ).ApplyThemeStyleAtInit( Toolkit::Control( GetOwner() ) );
734 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
736 SetKeyboardNavigationSupport( true );
740 void Control::OnInitialize()
744 void Control::OnControlChildAdd( Actor& child )
748 void Control::OnControlChildRemove( Actor& child )
752 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
754 // By default the control is only interested in theme (not font) changes
755 if( styleManager && change == StyleChange::THEME_CHANGE )
757 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
761 void Control::OnPinch(const PinchGesture& pinch)
763 if( !( mImpl->mStartingPinchScale ) )
766 mImpl->mStartingPinchScale = new Vector3;
769 if( pinch.state == Gesture::Started )
771 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
774 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
777 void Control::OnPan( const PanGesture& pan )
781 void Control::OnTap(const TapGesture& tap)
785 void Control::OnLongPress( const LongPressGesture& longPress )
789 void Control::EmitKeyInputFocusSignal( bool focusGained )
791 Dali::Toolkit::Control handle( GetOwner() );
795 // signals are allocated dynamically when someone connects
796 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
798 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
803 // signals are allocated dynamically when someone connects
804 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
806 mImpl->mKeyInputFocusLostSignal.Emit( handle );
811 void Control::OnStageConnection( int depth )
813 unsigned int controlRendererCount = Self().GetRendererCount();
814 for( unsigned int i(0); i<controlRendererCount; ++i )
816 Renderer controlRenderer = Self().GetRendererAt(i);
817 if( controlRenderer )
819 controlRenderer.SetDepthIndex( CONTENT_DEPTH_INDEX+depth );
823 if( mImpl->mBackgroundRenderer)
825 mImpl->mBackgroundRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX );
827 mImpl->mBackgroundRenderer.SetOnStage( self );
831 void Control::OnStageDisconnection()
833 if( mImpl->mBackgroundRenderer)
836 mImpl->mBackgroundRenderer.SetOffStage( self );
840 void Control::OnKeyInputFocusGained()
842 EmitKeyInputFocusSignal( true );
845 void Control::OnKeyInputFocusLost()
847 EmitKeyInputFocusSignal( false );
850 void Control::OnChildAdd(Actor& child)
852 // If this is the background actor, then we do not want to inform deriving classes
853 if ( mImpl->mAddRemoveBackgroundChild )
858 // Notify derived classes.
859 OnControlChildAdd( child );
862 void Control::OnChildRemove(Actor& child)
864 // If this is the background actor, then we do not want to inform deriving classes
865 if ( mImpl->mAddRemoveBackgroundChild )
870 // Notify derived classes.
871 OnControlChildRemove( child );
874 void Control::OnSizeSet(const Vector3& targetSize)
876 // Background is resized through size negotiation
879 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
881 // @todo size negotiate background to new size, animate as well?
884 bool Control::OnTouchEvent(const TouchEvent& event)
886 return false; // Do not consume
889 bool Control::OnHoverEvent(const HoverEvent& event)
891 return false; // Do not consume
894 bool Control::OnKeyEvent(const KeyEvent& event)
896 return false; // Do not consume
899 bool Control::OnWheelEvent(const WheelEvent& event)
901 return false; // Do not consume
904 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
906 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
908 container.Add( Self().GetChildAt( i ), size );
912 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
916 Vector3 Control::GetNaturalSize()
918 if( mImpl->mBackgroundRenderer )
921 mImpl->mBackgroundRenderer.GetNaturalSize(naturalSize);
922 return Vector3(naturalSize);
924 return Vector3::ZERO;
927 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
929 return CalculateChildSizeBase( child, dimension );
932 float Control::GetHeightForWidth( float width )
934 return GetHeightForWidthBase( width );
937 float Control::GetWidthForHeight( float height )
939 return GetWidthForHeightBase( height );
942 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
944 return RelayoutDependentOnChildrenBase( dimension );
947 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
951 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
955 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
957 mImpl->SignalConnected( slotObserver, callback );
960 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
962 mImpl->SignalDisconnected( slotObserver, callback );
965 Control& GetImplementation( Dali::Toolkit::Control& handle )
967 CustomActorImpl& customInterface = handle.GetImplementation();
968 // downcast to control
969 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
973 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
975 const CustomActorImpl& customInterface = handle.GetImplementation();
976 // downcast to control
977 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
981 } // namespace Internal
983 } // namespace Toolkit