2 * Copyright (c) 2016 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/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>
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/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/visuals/color/color-visual.h>
43 #include <dali-toolkit/internal/visuals/visual-string-constants.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 = "accessibilityActivated";
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 = "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 )
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 } // unnamed namespace
172 class Control::Impl : public ConnectionTracker
176 // Construction & Destruction
177 Impl(Control& controlImpl)
178 : mControlImpl( controlImpl ),
180 mBackgroundRenderer(),
181 mBackgroundColor(Color::TRANSPARENT),
182 mStartingPinchScale( NULL ),
184 mPinchGestureDetector(),
185 mPanGestureDetector(),
186 mTapGestureDetector(),
187 mLongPressGestureDetector(),
188 mFlags( Control::ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ),
189 mIsKeyboardNavigationSupported( false ),
190 mIsKeyboardFocusGroup( false )
196 // All gesture detectors will be destroyed so no need to disconnect.
197 delete mStartingPinchScale;
200 // Gesture Detection Methods
202 void PinchDetected(Actor actor, const PinchGesture& pinch)
204 mControlImpl.OnPinch(pinch);
207 void PanDetected(Actor actor, const PanGesture& pan)
209 mControlImpl.OnPan(pan);
212 void TapDetected(Actor actor, const TapGesture& tap)
214 mControlImpl.OnTap(tap);
217 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
219 mControlImpl.OnLongPress(longPress);
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.
230 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
232 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
236 Control& controlImpl( GetImplementation( control ) );
240 case Toolkit::Control::Property::STYLE_NAME:
242 controlImpl.SetStyleName( value.Get< std::string >() );
246 case Toolkit::Control::Property::BACKGROUND_COLOR:
248 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
249 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
253 case Toolkit::Control::Property::BACKGROUND_IMAGE:
255 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
256 Image image = Scripting::NewImage( value );
259 controlImpl.SetBackgroundImage( image );
263 // An empty map means the background is no longer required
264 controlImpl.ClearBackground();
269 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
271 if ( value.Get< bool >() )
273 controlImpl.SetKeyInputFocus();
277 controlImpl.ClearKeyInputFocus();
282 case Toolkit::Control::Property::BACKGROUND:
284 const Property::Map* map = value.GetMap();
287 controlImpl.SetBackground( *map );
291 // The background is not a property map, so we should clear the background
292 controlImpl.ClearBackground();
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.
306 static Property::Value GetProperty( BaseObject* object, Property::Index index )
308 Property::Value value;
310 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
314 Control& controlImpl( GetImplementation( control ) );
318 case Toolkit::Control::Property::STYLE_NAME:
320 value = controlImpl.GetStyleName();
324 case Toolkit::Control::Property::BACKGROUND_COLOR:
326 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
327 value = controlImpl.GetBackgroundColor();
331 case Toolkit::Control::Property::BACKGROUND_IMAGE:
333 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
335 if( controlImpl.mImpl->mBackgroundRenderer )
337 controlImpl.mImpl->mBackgroundRenderer.CreatePropertyMap( map );
343 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
345 value = controlImpl.HasKeyInputFocus();
349 case Toolkit::Control::Property::BACKGROUND:
352 if( controlImpl.mImpl->mBackgroundRenderer )
354 (controlImpl.mImpl->mBackgroundRenderer).CreatePropertyMap( map );
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;
379 PinchGestureDetector mPinchGestureDetector;
380 PanGestureDetector mPanGestureDetector;
381 TapGestureDetector mTapGestureDetector;
382 LongPressGestureDetector mLongPressGestureDetector;
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.
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;
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 );
403 Toolkit::Control Control::New()
405 // Create the implementation, temporarily owned on stack
406 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) );
408 // Pass ownership to handle
409 Toolkit::Control handle( *controlImpl );
411 // Second-phase init of the implementation
412 // This can only be done after the CustomActor connection has been made...
413 controlImpl->Initialize();
423 void Control::SetStyleName( const std::string& styleName )
425 if( styleName != mImpl->mStyleName )
427 mImpl->mStyleName = styleName;
429 // Apply new style, if stylemanager is available
430 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
433 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
438 const std::string& Control::GetStyleName() const
440 return mImpl->mStyleName;
443 void Control::SetBackgroundColor( const Vector4& color )
445 Actor self( Self() );
446 mImpl->mBackgroundColor = color;
448 map[ RENDERER_TYPE ] = COLOR_RENDERER;
449 map[ "mixColor" ] = color;
450 InitializeVisual( self, mImpl->mBackgroundRenderer, map );
451 if( mImpl->mBackgroundRenderer )
453 mImpl->mBackgroundRenderer.SetDepthIndex( DepthIndex::BACKGROUND );
457 Vector4 Control::GetBackgroundColor() const
459 return mImpl->mBackgroundColor;
462 void Control::SetBackground( const Property::Map& map )
464 Actor self( Self() );
465 InitializeVisual( self, mImpl->mBackgroundRenderer, map );
466 if( mImpl->mBackgroundRenderer )
468 mImpl->mBackgroundRenderer.SetDepthIndex( DepthIndex::BACKGROUND );
472 void Control::SetBackgroundImage( Image image )
474 Actor self( Self() );
475 InitializeVisual( self, mImpl->mBackgroundRenderer, image );
476 if( mImpl->mBackgroundRenderer )
478 mImpl->mBackgroundRenderer.SetDepthIndex( DepthIndex::BACKGROUND );
482 void Control::ClearBackground()
484 Actor self( Self() );
485 mImpl->mBackgroundRenderer.RemoveAndReset( self );
488 void Control::EnableGestureDetection(Gesture::Type type)
490 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
492 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
493 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
494 mImpl->mPinchGestureDetector.Attach(Self());
497 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
499 mImpl->mPanGestureDetector = PanGestureDetector::New();
500 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
501 mImpl->mPanGestureDetector.Attach(Self());
504 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
506 mImpl->mTapGestureDetector = TapGestureDetector::New();
507 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
508 mImpl->mTapGestureDetector.Attach(Self());
511 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
513 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
514 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
515 mImpl->mLongPressGestureDetector.Attach(Self());
519 void Control::DisableGestureDetection(Gesture::Type type)
521 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
523 mImpl->mPinchGestureDetector.Detach(Self());
524 mImpl->mPinchGestureDetector.Reset();
527 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
529 mImpl->mPanGestureDetector.Detach(Self());
530 mImpl->mPanGestureDetector.Reset();
533 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
535 mImpl->mTapGestureDetector.Detach(Self());
536 mImpl->mTapGestureDetector.Reset();
539 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
541 mImpl->mLongPressGestureDetector.Detach(Self());
542 mImpl->mLongPressGestureDetector.Reset();
546 PinchGestureDetector Control::GetPinchGestureDetector() const
548 return mImpl->mPinchGestureDetector;
551 PanGestureDetector Control::GetPanGestureDetector() const
553 return mImpl->mPanGestureDetector;
556 TapGestureDetector Control::GetTapGestureDetector() const
558 return mImpl->mTapGestureDetector;
561 LongPressGestureDetector Control::GetLongPressGestureDetector() const
563 return mImpl->mLongPressGestureDetector;
566 void Control::SetKeyboardNavigationSupport(bool isSupported)
568 mImpl->mIsKeyboardNavigationSupported = isSupported;
571 bool Control::IsKeyboardNavigationSupported()
573 return mImpl->mIsKeyboardNavigationSupported;
576 void Control::SetKeyInputFocus()
578 if( Self().OnStage() )
580 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
584 bool Control::HasKeyInputFocus()
587 if( Self().OnStage() )
589 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
594 void Control::ClearKeyInputFocus()
596 if( Self().OnStage() )
598 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
602 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
604 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
606 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
607 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
610 bool Control::IsKeyboardFocusGroup()
612 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
615 void Control::AccessibilityActivate()
617 // Inform deriving classes
618 OnAccessibilityActivated();
621 void Control::KeyboardEnter()
623 // Inform deriving classes
627 bool Control::OnAccessibilityActivated()
629 return false; // Accessibility activation is not handled by default
632 bool Control::OnKeyboardEnter()
634 return false; // Keyboard enter is not handled by default
637 bool Control::OnAccessibilityPan(PanGesture gesture)
639 return false; // Accessibility pan gesture is not handled by default
642 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
644 return false; // Accessibility touch event is not handled by default
647 bool Control::OnAccessibilityValueChange(bool isIncrease)
649 return false; // Accessibility value change action is not handled by default
652 bool Control::OnAccessibilityZoom()
654 return false; // Accessibility zoom action is not handled by default
657 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
662 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
666 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
668 return mImpl->mKeyEventSignal;
671 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusGainedSignal()
673 return mImpl->mKeyInputFocusGainedSignal;
676 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusLostSignal()
678 return mImpl->mKeyInputFocusLostSignal;
681 bool Control::EmitKeyEventSignal( const KeyEvent& event )
683 // Guard against destruction during signal emission
684 Dali::Toolkit::Control handle( GetOwner() );
686 bool consumed = false;
688 // signals are allocated dynamically when someone connects
689 if ( !mImpl->mKeyEventSignal.Empty() )
691 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
696 // Notification for derived classes
697 consumed = OnKeyEvent(event);
703 Control::Control( ControlBehaviour behaviourFlags )
704 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
705 mImpl(new Impl(*this))
707 mImpl->mFlags = behaviourFlags;
710 void Control::Initialize()
712 // Call deriving classes so initialised before styling is applied to them.
715 if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
717 Toolkit::StyleManager styleManager = StyleManager::Get();
719 // if stylemanager is available
722 StyleManager& styleManagerImpl = GetImpl( styleManager );
724 // Register for style changes
725 styleManagerImpl.ControlStyleChangeSignal().Connect( this, &Control::OnStyleChange );
727 // Apply the current style
728 styleManagerImpl.ApplyThemeStyleAtInit( Toolkit::Control( GetOwner() ) );
732 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
734 SetKeyboardNavigationSupport( true );
738 void Control::OnInitialize()
742 void Control::OnControlChildAdd( Actor& child )
746 void Control::OnControlChildRemove( Actor& child )
750 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
752 // By default the control is only interested in theme (not font) changes
753 if( styleManager && change == StyleChange::THEME_CHANGE )
755 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
759 void Control::OnPinch(const PinchGesture& pinch)
761 if( !( mImpl->mStartingPinchScale ) )
764 mImpl->mStartingPinchScale = new Vector3;
767 if( pinch.state == Gesture::Started )
769 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
772 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
775 void Control::OnPan( const PanGesture& pan )
779 void Control::OnTap(const TapGesture& tap)
783 void Control::OnLongPress( const LongPressGesture& longPress )
787 void Control::EmitKeyInputFocusSignal( bool focusGained )
789 Dali::Toolkit::Control handle( GetOwner() );
793 // signals are allocated dynamically when someone connects
794 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
796 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
801 // signals are allocated dynamically when someone connects
802 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
804 mImpl->mKeyInputFocusLostSignal.Emit( handle );
809 void Control::OnStageConnection( int depth )
811 if( mImpl->mBackgroundRenderer)
813 Actor self( Self() );
814 mImpl->mBackgroundRenderer.SetOnStage( self );
818 void Control::OnStageDisconnection()
820 if( mImpl->mBackgroundRenderer )
822 Actor self( Self() );
823 mImpl->mBackgroundRenderer.SetOffStage( self );
827 void Control::OnKeyInputFocusGained()
829 EmitKeyInputFocusSignal( true );
832 void Control::OnKeyInputFocusLost()
834 EmitKeyInputFocusSignal( false );
837 void Control::OnChildAdd(Actor& child)
839 // Notify derived classes.
840 OnControlChildAdd( child );
843 void Control::OnChildRemove(Actor& child)
845 // Notify derived classes.
846 OnControlChildRemove( child );
849 void Control::OnSizeSet(const Vector3& targetSize)
851 if( mImpl->mBackgroundRenderer )
853 Vector2 size( targetSize );
854 mImpl->mBackgroundRenderer.SetSize( size );
858 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
860 // @todo size negotiate background to new size, animate as well?
863 bool Control::OnTouchEvent(const TouchEvent& event)
865 return false; // Do not consume
868 bool Control::OnHoverEvent(const HoverEvent& event)
870 return false; // Do not consume
873 bool Control::OnKeyEvent(const KeyEvent& event)
875 return false; // Do not consume
878 bool Control::OnWheelEvent(const WheelEvent& event)
880 return false; // Do not consume
883 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
885 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
887 container.Add( Self().GetChildAt( i ), size );
891 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
895 Vector3 Control::GetNaturalSize()
897 if( mImpl->mBackgroundRenderer )
900 mImpl->mBackgroundRenderer.GetNaturalSize(naturalSize);
901 return Vector3(naturalSize);
903 return Vector3::ZERO;
906 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
908 return CalculateChildSizeBase( child, dimension );
911 float Control::GetHeightForWidth( float width )
913 return GetHeightForWidthBase( width );
916 float Control::GetWidthForHeight( float height )
918 return GetWidthForHeightBase( height );
921 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
923 return RelayoutDependentOnChildrenBase( dimension );
926 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
930 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
934 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
936 mImpl->SignalConnected( slotObserver, callback );
939 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
941 mImpl->SignalDisconnected( slotObserver, callback );
944 Control& GetImplementation( Dali::Toolkit::Control& handle )
946 CustomActorImpl& customInterface = handle.GetImplementation();
947 // downcast to control
948 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
952 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
954 const CustomActorImpl& customInterface = handle.GetImplementation();
955 // downcast to control
956 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
960 } // namespace Internal
962 } // namespace Toolkit