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/actors/image-actor.h>
26 #include <dali/devel-api/actors/mesh-actor.h>
27 #include <dali/public-api/animation/constraint.h>
28 #include <dali/public-api/animation/constraints.h>
29 #include <dali/devel-api/geometry/mesh.h>
30 #include <dali/public-api/object/type-registry.h>
31 #include <dali/devel-api/object/type-registry-helper.h>
32 #include <dali/devel-api/scripting/scripting.h>
33 #include <dali/public-api/size-negotiation/relayout-container.h>
34 #include <dali/integration-api/debug.h>
37 #include <dali-toolkit/public-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>
52 const float BACKGROUND_ACTOR_Z_POSITION( -0.1f );
56 return Internal::Control::New();
59 // Setup signals and actions using the type-registry.
60 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
62 // Note: Properties are registered separately below.
64 DALI_SIGNAL_REGISTRATION( Toolkit, Control, "key-event", SIGNAL_KEY_EVENT )
65 DALI_SIGNAL_REGISTRATION( Toolkit, Control, "key-input-focus-gained", SIGNAL_KEY_INPUT_FOCUS_GAINED )
66 DALI_SIGNAL_REGISTRATION( Toolkit, Control, "key-input-focus-lost", SIGNAL_KEY_INPUT_FOCUS_LOST )
67 DALI_SIGNAL_REGISTRATION( Toolkit, Control, "tapped", SIGNAL_TAPPED )
68 DALI_SIGNAL_REGISTRATION( Toolkit, Control, "panned", SIGNAL_PANNED )
69 DALI_SIGNAL_REGISTRATION( Toolkit, Control, "pinched", SIGNAL_PINCHED )
70 DALI_SIGNAL_REGISTRATION( Toolkit, Control, "long-pressed", SIGNAL_LONG_PRESSED )
72 DALI_ACTION_REGISTRATION( Toolkit, Control, "control-activated", ACTION_CONTROL_ACTIVATED )
74 DALI_TYPE_REGISTRATION_END()
77 * Structure which holds information about the background of a control
81 Actor actor; ///< Either a MeshActor or an ImageActor
82 Vector4 color; ///< The color of the actor.
95 * Creates a white coloured Mesh.
99 Vector3 white( Color::WHITE );
103 // Create vertices with a white color (actual color is set by actor color)
104 MeshData::VertexContainer vertices(4);
105 vertices[ 0 ] = MeshData::Vertex( Vector3( -0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
106 vertices[ 1 ] = MeshData::Vertex( Vector3( 0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
107 vertices[ 2 ] = MeshData::Vertex( Vector3( -0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
108 vertices[ 3 ] = MeshData::Vertex( Vector3( 0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
110 // Specify all the faces
111 MeshData::FaceIndices faces;
112 faces.reserve( 6 ); // 2 triangles in Quad
113 faces.push_back( 0 ); faces.push_back( 3 ); faces.push_back( 1 );
114 faces.push_back( 0 ); faces.push_back( 2 ); faces.push_back( 3 );
116 // Create the mesh data from the vertices and faces
117 meshData.SetMaterial( Material::New( "ControlMaterial" ) );
118 meshData.SetVertices( vertices );
119 meshData.SetFaceIndices( faces );
120 meshData.SetHasColor( true );
122 return Mesh::New( meshData );
126 * Sets all the required properties for the background actor.
128 * @param[in] actor The actor to set the properties on.
129 * @param[in] color The required color of the actor.
131 void SetupBackgroundActor( Actor actor, const Vector4& color )
133 actor.SetColor( color );
134 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
135 actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
136 actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
137 actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
141 * Sets all the required properties for the background actor.
143 * @param[in] actor The actor to set the properties on.
144 * @param[in] constrainingIndex The property index to constrain the parent's size on.
145 * @param[in] color The required color of the actor.
147 void SetupBackgroundActorConstrained( Actor actor, Property::Index constrainingIndex, const Vector4& color )
149 actor.SetColor( color );
150 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
151 actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
152 actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
154 Constraint constraint = Constraint::New<Vector3>( actor,
156 EqualToConstraint() );
157 constraint.AddSource( ParentSource( Actor::Property::SIZE ) );
161 } // unnamed namespace
166 class Control::Impl : public ConnectionTracker
170 // Construction & Destruction
171 Impl(Control& controlImpl)
172 : mControlImpl( controlImpl ),
175 mStartingPinchScale( NULL ),
177 mPinchGestureDetector(),
178 mPanGestureDetector(),
179 mTapGestureDetector(),
180 mLongPressGestureDetector(),
181 mFlags( Control::ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ),
182 mIsKeyboardNavigationSupported( false ),
183 mIsKeyboardFocusGroup( false )
189 // All gesture detectors will be destroyed so no need to disconnect.
191 delete mStartingPinchScale;
194 // Gesture Detection Methods
196 void PinchDetected(Actor actor, const PinchGesture& pinch)
198 mControlImpl.OnPinch(pinch);
201 void PanDetected(Actor actor, const PanGesture& pan)
203 mControlImpl.OnPan(pan);
206 void TapDetected(Actor actor, const TapGesture& tap)
208 mControlImpl.OnTap(tap);
211 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
213 mControlImpl.OnLongPress(longPress);
216 // Background Methods
219 * Only creates an instance of the background if we actually use it.
220 * @return A reference to the Background structure.
222 Background& GetBackground()
226 mBackground = new Background;
234 * Called when a property of an object of this type is set.
235 * @param[in] object The object whose property is set.
236 * @param[in] index The property index.
237 * @param[in] value The new property value.
239 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
241 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
245 Control& controlImpl( GetImplementation( control ) );
249 case Toolkit::Control::Property::STYLE_NAME:
251 controlImpl.SetStyleName( value.Get< std::string >() );
255 case Toolkit::Control::Property::BACKGROUND_COLOR:
257 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
261 case Toolkit::Control::Property::BACKGROUND_IMAGE:
263 if ( value.HasKey( "image" ) )
265 Property::Map imageMap = value.GetValue( "image" ).Get< Property::Map >();
266 Image image = Scripting::NewImage( imageMap );
270 controlImpl.SetBackgroundImage( image );
273 else if ( value.Get< Property::Map >().Empty() )
275 // An empty map means the background is no longer required
276 controlImpl.ClearBackground();
281 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
283 if ( value.Get< bool >() )
285 controlImpl.SetKeyInputFocus();
289 controlImpl.ClearKeyInputFocus();
298 * Called to retrieve a property of an object of this type.
299 * @param[in] object The object whose property is to be retrieved.
300 * @param[in] index The property index.
301 * @return The current value of the property.
303 static Property::Value GetProperty( BaseObject* object, Property::Index index )
305 Property::Value value;
307 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
311 Control& controlImpl( GetImplementation( control ) );
315 case Toolkit::Control::Property::STYLE_NAME:
317 value = controlImpl.GetStyleName();
321 case Toolkit::Control::Property::BACKGROUND_COLOR:
323 value = controlImpl.GetBackgroundColor();
327 case Toolkit::Control::Property::BACKGROUND_IMAGE:
331 Background* back = controlImpl.mImpl->mBackground;
334 ImageActor imageActor = ImageActor::DownCast( back->actor );
337 Image image = imageActor.GetImage();
338 Property::Map imageMap;
339 Scripting::CreatePropertyMap( image, imageMap );
340 map[ "image" ] = imageMap;
348 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
350 value = controlImpl.HasKeyInputFocus();
361 Control& mControlImpl;
362 std::string mStyleName;
363 Background* mBackground; ///< Only create the background if we use it
364 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
365 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
366 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
367 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
370 PinchGestureDetector mPinchGestureDetector;
371 PanGestureDetector mPanGestureDetector;
372 TapGestureDetector mTapGestureDetector;
373 LongPressGestureDetector mLongPressGestureDetector;
375 ControlBehaviour mFlags :CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
376 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
377 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
379 // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
380 static PropertyRegistration PROPERTY_1;
381 static PropertyRegistration PROPERTY_2;
382 static PropertyRegistration PROPERTY_3;
383 static PropertyRegistration PROPERTY_4;
386 // Properties registered without macro to use specific member variables.
387 PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "style-name", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
388 PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "background-color", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
389 PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "background-image", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
390 PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "key-input-focus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
392 Toolkit::Control Control::New()
394 // Create the implementation, temporarily owned on stack
395 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) );
397 // Pass ownership to handle
398 Toolkit::Control handle( *controlImpl );
400 // Second-phase init of the implementation
401 // This can only be done after the CustomActor connection has been made...
402 controlImpl->Initialize();
412 void Control::SetKeyInputFocus()
414 if( Self().OnStage() )
416 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
420 bool Control::HasKeyInputFocus()
423 if( Self().OnStage() )
425 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
430 void Control::ClearKeyInputFocus()
432 if( Self().OnStage() )
434 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
438 PinchGestureDetector Control::GetPinchGestureDetector() const
440 return mImpl->mPinchGestureDetector;
443 PanGestureDetector Control::GetPanGestureDetector() const
445 return mImpl->mPanGestureDetector;
448 TapGestureDetector Control::GetTapGestureDetector() const
450 return mImpl->mTapGestureDetector;
453 LongPressGestureDetector Control::GetLongPressGestureDetector() const
455 return mImpl->mLongPressGestureDetector;
458 void Control::SetStyleName( const std::string& styleName )
460 if( styleName != mImpl->mStyleName )
462 mImpl->mStyleName = styleName;
465 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
466 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
470 const std::string& Control::GetStyleName() const
472 return mImpl->mStyleName;
475 void Control::SetBackgroundColor( const Vector4& color )
477 Background& background( mImpl->GetBackground() );
479 if ( background.actor )
481 // Just set the actor color
482 background.actor.SetColor( color );
487 MeshActor meshActor = MeshActor::New( CreateMesh() );
489 SetupBackgroundActorConstrained( meshActor, Actor::Property::SCALE, color );
491 // Set the background actor before adding so that we do not inform deriving classes
492 background.actor = meshActor;
493 Self().Add( meshActor );
496 background.color = color;
499 Vector4 Control::GetBackgroundColor() const
501 if ( mImpl->mBackground )
503 return mImpl->mBackground->color;
505 return Color::TRANSPARENT;
508 void Control::SetBackgroundImage( Image image )
510 Background& background( mImpl->GetBackground() );
512 if ( background.actor )
514 // Remove Current actor, unset AFTER removal so that we do not inform deriving classes
515 Self().Remove( background.actor );
516 background.actor.Reset();
519 ImageActor imageActor = ImageActor::New( image );
520 SetupBackgroundActor( imageActor, background.color );
522 // Set the background actor before adding so that we do not inform derived classes
523 background.actor = imageActor;
524 Self().Add( imageActor );
527 void Control::ClearBackground()
529 if ( mImpl->mBackground )
531 Background& background( mImpl->GetBackground() );
532 Self().Remove( background.actor );
534 delete mImpl->mBackground;
535 mImpl->mBackground = NULL;
539 void Control::SetKeyboardNavigationSupport(bool isSupported)
541 mImpl->mIsKeyboardNavigationSupported = isSupported;
544 bool Control::IsKeyboardNavigationSupported()
546 return mImpl->mIsKeyboardNavigationSupported;
549 void Control::Activate()
551 // Inform deriving classes
552 OnAccessibilityActivated();
555 void Control::OnAccessibilityActivated()
559 bool Control::OnAccessibilityPan(PanGesture gesture)
561 return false; // Accessibility pan gesture is not handled by default
564 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
566 return false; // Accessibility touch event is not handled by default
569 bool Control::OnAccessibilityValueChange(bool isIncrease)
571 return false; // Accessibility value change action is not handled by default
574 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
576 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
578 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
579 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
582 bool Control::IsKeyboardFocusGroup()
584 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
587 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
592 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
596 bool Control::DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes)
600 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_CONTROL_ACTIVATED ) ) )
602 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
605 // if cast succeeds there is an implementation so no need to check
606 GetImplementation( control ).OnAccessibilityActivated();
613 bool Control::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
615 Dali::BaseHandle handle( object );
617 bool connected( false );
618 Toolkit::Control control = Toolkit::Control::DownCast( handle );
621 Control& controlImpl( GetImplementation( control ) );
624 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
626 controlImpl.KeyEventSignal().Connect( tracker, functor );
628 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
630 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
632 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
634 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
636 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
638 controlImpl.EnableGestureDetection( Gesture::Tap );
639 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
641 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
643 controlImpl.EnableGestureDetection( Gesture::Pan );
644 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
646 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
648 controlImpl.EnableGestureDetection( Gesture::Pinch );
649 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
651 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
653 controlImpl.EnableGestureDetection( Gesture::LongPress );
654 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
658 // signalName does not match any signal
665 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
667 return mImpl->mKeyEventSignal;
670 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusGainedSignal()
672 return mImpl->mKeyInputFocusGainedSignal;
675 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusLostSignal()
677 return mImpl->mKeyInputFocusLostSignal;
680 bool Control::EmitKeyEventSignal( const KeyEvent& event )
682 // Guard against destruction during signal emission
683 Dali::Toolkit::Control handle( GetOwner() );
685 bool consumed = false;
687 // signals are allocated dynamically when someone connects
688 if ( !mImpl->mKeyEventSignal.Empty() )
690 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
695 // Notification for derived classes
696 consumed = OnKeyEvent(event);
702 Control::Control( ControlBehaviour behaviourFlags )
703 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
704 mImpl(new Impl(*this))
706 mImpl->mFlags = behaviourFlags;
709 void Control::Initialize()
711 if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
713 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
715 // Register for style changes
716 styleManager.StyleChangeSignal().Connect( this, &Control::OnStyleChange );
719 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
722 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
724 SetKeyboardNavigationSupport( true );
727 // Calling deriving classes
731 void Control::EnableGestureDetection(Gesture::Type type)
733 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
735 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
736 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
737 mImpl->mPinchGestureDetector.Attach(Self());
740 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
742 mImpl->mPanGestureDetector = PanGestureDetector::New();
743 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
744 mImpl->mPanGestureDetector.Attach(Self());
747 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
749 mImpl->mTapGestureDetector = TapGestureDetector::New();
750 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
751 mImpl->mTapGestureDetector.Attach(Self());
754 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
756 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
757 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
758 mImpl->mLongPressGestureDetector.Attach(Self());
762 void Control::DisableGestureDetection(Gesture::Type type)
764 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
766 mImpl->mPinchGestureDetector.Detach(Self());
767 mImpl->mPinchGestureDetector.Reset();
770 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
772 mImpl->mPanGestureDetector.Detach(Self());
773 mImpl->mPanGestureDetector.Reset();
776 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
778 mImpl->mTapGestureDetector.Detach(Self());
779 mImpl->mTapGestureDetector.Reset();
782 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
784 mImpl->mLongPressGestureDetector.Detach(Self());
785 mImpl->mLongPressGestureDetector.Reset();
789 void Control::OnInitialize()
793 void Control::OnControlStageConnection()
797 void Control::OnControlStageDisconnection()
801 void Control::OnControlChildAdd( Actor& child )
805 void Control::OnControlChildRemove( Actor& child )
809 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
811 // By default the control is only interested in theme (not font) changes
812 if( change == StyleChange::THEME_CHANGE )
814 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
818 void Control::OnPinch(const PinchGesture& pinch)
820 if( !( mImpl->mStartingPinchScale ) )
823 mImpl->mStartingPinchScale = new Vector3;
826 if( pinch.state == Gesture::Started )
828 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
831 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
834 void Control::OnPan( const PanGesture& pan )
838 void Control::OnTap(const TapGesture& tap)
842 void Control::OnLongPress( const LongPressGesture& longPress )
846 void Control::OnControlSizeSet( const Vector3& size )
850 void Control::EmitKeyInputFocusSignal( bool focusGained )
852 Dali::Toolkit::Control handle( GetOwner() );
856 // signals are allocated dynamically when someone connects
857 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
859 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
864 // signals are allocated dynamically when someone connects
865 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
867 mImpl->mKeyInputFocusLostSignal.Emit( handle );
872 void Control::OnKeyInputFocusGained()
874 EmitKeyInputFocusSignal( true );
877 void Control::OnKeyInputFocusLost()
879 EmitKeyInputFocusSignal( false );
882 void Control::OnStageConnection()
884 // Notify derived classes.
885 OnControlStageConnection();
888 void Control::OnStageDisconnection()
890 // Notify derived classes
891 OnControlStageDisconnection();
894 void Control::OnChildAdd(Actor& child)
896 // If this is the background actor, then we do not want to relayout or inform deriving classes
897 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
902 // Notify derived classes.
903 OnControlChildAdd( child );
906 void Control::OnChildRemove(Actor& child)
908 // If this is the background actor, then we do not want to relayout or inform deriving classes
909 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
914 // Notify derived classes.
915 OnControlChildRemove( child );
918 void Control::OnSizeSet(const Vector3& targetSize)
920 // Background is resized through size negotiation
922 // Notify derived classes.
923 OnControlSizeSet( targetSize );
926 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
928 // @todo size negotiate background to new size, animate as well?
931 bool Control::OnTouchEvent(const TouchEvent& event)
933 return false; // Do not consume
936 bool Control::OnHoverEvent(const HoverEvent& event)
938 return false; // Do not consume
941 bool Control::OnKeyEvent(const KeyEvent& event)
943 return false; // Do not consume
946 bool Control::OnMouseWheelEvent(const MouseWheelEvent& event)
948 return false; // Do not consume
951 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
953 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
955 container.Add( Self().GetChildAt( i ), size );
959 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
963 Vector3 Control::GetNaturalSize()
965 if( mImpl->mBackground )
967 Actor actor = mImpl->mBackground->actor;
970 return actor.GetNaturalSize();
976 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
978 return CalculateChildSizeBase( child, dimension );
981 float Control::GetHeightForWidth( float width )
983 if( mImpl->mBackground )
985 Actor actor = mImpl->mBackground->actor;
988 return actor.GetHeightForWidth( width );
991 return GetHeightForWidthBase( width );
994 float Control::GetWidthForHeight( float height )
996 if( mImpl->mBackground )
998 Actor actor = mImpl->mBackground->actor;
1001 return actor.GetWidthForHeight( height );
1004 return GetWidthForHeightBase( height );
1007 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
1009 return RelayoutDependentOnChildrenBase( dimension );
1012 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
1016 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
1020 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1022 mImpl->SignalConnected( slotObserver, callback );
1025 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1027 mImpl->SignalDisconnected( slotObserver, callback );
1030 Control& GetImplementation( Dali::Toolkit::Control& handle )
1032 CustomActorImpl& customInterface = handle.GetImplementation();
1033 // downcast to control
1034 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
1038 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
1040 const CustomActorImpl& customInterface = handle.GetImplementation();
1041 // downcast to control
1042 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
1046 } // namespace Internal
1048 } // namespace Toolkit