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/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>
53 * Creates control through type registry
57 return Internal::Control::New();
61 * Performs actions as requested using the action name.
62 * @param[in] object The object on which to perform the action.
63 * @param[in] actionName The action to perform.
64 * @param[in] attributes The attributes with which to perfrom this action.
65 * @return true if action has been accepted by this control
67 const char* ACTION_CONTROL_ACTIVATED = "control-activated";
68 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
72 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_CONTROL_ACTIVATED ) ) )
74 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
77 // if cast succeeds there is an implementation so no need to check
78 ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
86 * Connects a callback function with the object's signals.
87 * @param[in] object The object providing the signal.
88 * @param[in] tracker Used to disconnect the signal.
89 * @param[in] signalName The signal to connect to.
90 * @param[in] functor A newly allocated FunctorDelegate.
91 * @return True if the signal was connected.
92 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
94 const char* SIGNAL_KEY_EVENT = "key-event";
95 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "key-input-focus-gained";
96 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "key-input-focus-lost";
97 const char* SIGNAL_TAPPED = "tapped";
98 const char* SIGNAL_PANNED = "panned";
99 const char* SIGNAL_PINCHED = "pinched";
100 const char* SIGNAL_LONG_PRESSED = "long-pressed";
101 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
103 Dali::BaseHandle handle( object );
105 bool connected( false );
106 Toolkit::Control control = Toolkit::Control::DownCast( handle );
109 Internal::Control& controlImpl( Internal::GetImplementation( control ) );
112 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
114 controlImpl.KeyEventSignal().Connect( tracker, functor );
116 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
118 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
120 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
122 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
124 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
126 controlImpl.EnableGestureDetection( Gesture::Tap );
127 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
129 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
131 controlImpl.EnableGestureDetection( Gesture::Pan );
132 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
134 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
136 controlImpl.EnableGestureDetection( Gesture::Pinch );
137 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
139 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
141 controlImpl.EnableGestureDetection( Gesture::LongPress );
142 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
148 // Setup signals and actions using the type-registry.
149 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
151 // Note: Properties are registered separately below.
153 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
154 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
155 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
156 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
157 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
158 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
159 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
161 TypeAction registerAction( typeRegistration, ACTION_CONTROL_ACTIVATED, &DoAction );
163 DALI_TYPE_REGISTRATION_END()
166 * Structure which holds information about the background of a control
170 Actor actor; ///< Either a MeshActor or an ImageActor
171 Vector4 color; ///< The color of the actor.
178 color( Color::WHITE )
184 * Creates a white coloured Mesh.
188 Vector3 white( Color::WHITE );
192 // Create vertices with a white color (actual color is set by actor color)
193 MeshData::VertexContainer vertices(4);
194 vertices[ 0 ] = MeshData::Vertex( Vector3( -0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
195 vertices[ 1 ] = MeshData::Vertex( Vector3( 0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
196 vertices[ 2 ] = MeshData::Vertex( Vector3( -0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
197 vertices[ 3 ] = MeshData::Vertex( Vector3( 0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
199 // Specify all the faces
200 MeshData::FaceIndices faces;
201 faces.reserve( 6 ); // 2 triangles in Quad
202 faces.push_back( 0 ); faces.push_back( 3 ); faces.push_back( 1 );
203 faces.push_back( 0 ); faces.push_back( 2 ); faces.push_back( 3 );
205 // Create the mesh data from the vertices and faces
206 meshData.SetMaterial( Material::New( "ControlMaterial" ) );
207 meshData.SetVertices( vertices );
208 meshData.SetFaceIndices( faces );
209 meshData.SetHasColor( true );
211 return Mesh::New( meshData );
215 * Sets all the required properties for the background actor.
217 * @param[in] actor The actor to set the properties on.
218 * @param[in] color The required color of the actor.
220 void SetupBackgroundActor( Actor actor, const Vector4& color )
222 actor.SetColor( color );
223 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
224 actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
225 actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
229 * Sets all the required properties for the background actor.
231 * @param[in] actor The actor to set the properties on.
232 * @param[in] constrainingIndex The property index to constrain the parent's size on.
233 * @param[in] color The required color of the actor.
235 void SetupBackgroundActorConstrained( Actor actor, Property::Index constrainingIndex, const Vector4& color )
237 actor.SetColor( color );
238 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
239 actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
241 Constraint constraint = Constraint::New<Vector3>( actor,
243 EqualToConstraint() );
244 constraint.AddSource( ParentSource( Actor::Property::SIZE ) );
248 } // unnamed namespace
253 class Control::Impl : public ConnectionTracker
257 // Construction & Destruction
258 Impl(Control& controlImpl)
259 : mControlImpl( controlImpl ),
262 mStartingPinchScale( NULL ),
264 mPinchGestureDetector(),
265 mPanGestureDetector(),
266 mTapGestureDetector(),
267 mLongPressGestureDetector(),
268 mFlags( Control::ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ),
269 mIsKeyboardNavigationSupported( false ),
270 mIsKeyboardFocusGroup( false ),
271 mAddRemoveBackgroundChild( false )
277 // All gesture detectors will be destroyed so no need to disconnect.
279 delete mStartingPinchScale;
282 // Gesture Detection Methods
284 void PinchDetected(Actor actor, const PinchGesture& pinch)
286 mControlImpl.OnPinch(pinch);
289 void PanDetected(Actor actor, const PanGesture& pan)
291 mControlImpl.OnPan(pan);
294 void TapDetected(Actor actor, const TapGesture& tap)
296 mControlImpl.OnTap(tap);
299 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
301 mControlImpl.OnLongPress(longPress);
304 // Background Methods
307 * Only creates an instance of the background if we actually use it.
308 * @return A reference to the Background structure.
310 Background& GetBackground()
314 mBackground = new Background;
322 * Called when a property of an object of this type is set.
323 * @param[in] object The object whose property is set.
324 * @param[in] index The property index.
325 * @param[in] value The new property value.
327 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
329 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
333 Control& controlImpl( GetImplementation( control ) );
337 case Toolkit::Control::Property::STYLE_NAME:
339 controlImpl.SetStyleName( value.Get< std::string >() );
343 case Toolkit::Control::Property::BACKGROUND_COLOR:
345 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
349 case Toolkit::Control::Property::BACKGROUND_IMAGE:
351 Image image = Scripting::NewImage( value );
354 controlImpl.SetBackgroundImage( image );
358 // An empty map means the background is no longer required
359 controlImpl.ClearBackground();
364 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
366 if ( value.Get< bool >() )
368 controlImpl.SetKeyInputFocus();
372 controlImpl.ClearKeyInputFocus();
381 * Called to retrieve a property of an object of this type.
382 * @param[in] object The object whose property is to be retrieved.
383 * @param[in] index The property index.
384 * @return The current value of the property.
386 static Property::Value GetProperty( BaseObject* object, Property::Index index )
388 Property::Value value;
390 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
394 Control& controlImpl( GetImplementation( control ) );
398 case Toolkit::Control::Property::STYLE_NAME:
400 value = controlImpl.GetStyleName();
404 case Toolkit::Control::Property::BACKGROUND_COLOR:
406 value = controlImpl.GetBackgroundColor();
410 case Toolkit::Control::Property::BACKGROUND_IMAGE:
414 Background* back = controlImpl.mImpl->mBackground;
417 ImageActor imageActor = ImageActor::DownCast( back->actor );
420 Image image = imageActor.GetImage();
421 Scripting::CreatePropertyMap( image, map );
429 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
431 value = controlImpl.HasKeyInputFocus();
442 Control& mControlImpl;
443 std::string mStyleName;
444 Background* mBackground; ///< Only create the background if we use it
445 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
446 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
447 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
448 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
451 PinchGestureDetector mPinchGestureDetector;
452 PanGestureDetector mPanGestureDetector;
453 TapGestureDetector mTapGestureDetector;
454 LongPressGestureDetector mLongPressGestureDetector;
456 ControlBehaviour mFlags :CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
457 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
458 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
459 bool mAddRemoveBackgroundChild:1; ///< Flag to know when we are adding or removing our own actor to avoid call to OnControlChildAdd
461 // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
462 static PropertyRegistration PROPERTY_1;
463 static PropertyRegistration PROPERTY_2;
464 static PropertyRegistration PROPERTY_3;
465 static PropertyRegistration PROPERTY_4;
468 // Properties registered without macro to use specific member variables.
469 PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "style-name", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
470 PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "background-color", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
471 PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "background-image", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
472 PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "key-input-focus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
474 Toolkit::Control Control::New()
476 // Create the implementation, temporarily owned on stack
477 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) );
479 // Pass ownership to handle
480 Toolkit::Control handle( *controlImpl );
482 // Second-phase init of the implementation
483 // This can only be done after the CustomActor connection has been made...
484 controlImpl->Initialize();
494 void Control::SetStyleName( const std::string& styleName )
496 if( styleName != mImpl->mStyleName )
498 mImpl->mStyleName = styleName;
501 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
502 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
506 const std::string& Control::GetStyleName() const
508 return mImpl->mStyleName;
511 void Control::SetBackgroundColor( const Vector4& color )
513 Background& background( mImpl->GetBackground() );
515 if ( background.actor )
517 // Just set the actor color
518 background.actor.SetColor( color );
523 MeshActor meshActor = MeshActor::New( CreateMesh() );
525 SetupBackgroundActorConstrained( meshActor, Actor::Property::SCALE, color );
527 background.actor = meshActor;
528 // Set the flag to avoid notifying children
529 mImpl->mAddRemoveBackgroundChild = true;
530 // use insert to guarantee its the first child (so that OVERLAY mode works)
531 Self().Insert( 0, meshActor );
532 mImpl->mAddRemoveBackgroundChild = false;
535 background.color = color;
538 Vector4 Control::GetBackgroundColor() const
540 if ( mImpl->mBackground )
542 return mImpl->mBackground->color;
544 return Color::TRANSPARENT;
547 void Control::SetBackgroundImage( Image image )
549 Background& background( mImpl->GetBackground() );
551 if ( background.actor )
553 // Remove Current actor, unset AFTER removal
554 mImpl->mAddRemoveBackgroundChild = true;
555 Self().Remove( background.actor );
556 mImpl->mAddRemoveBackgroundChild = false;
557 background.actor.Reset();
560 ImageActor imageActor = ImageActor::New( image );
561 SetupBackgroundActor( imageActor, background.color );
563 // Set the background actor before adding so that we do not inform derived classes
564 background.actor = imageActor;
565 mImpl->mAddRemoveBackgroundChild = true;
566 // use insert to guarantee its the first child (so that OVERLAY mode works)
567 Self().Insert( 0, imageActor );
568 mImpl->mAddRemoveBackgroundChild = false;
571 void Control::ClearBackground()
573 if ( mImpl->mBackground )
575 Background& background( mImpl->GetBackground() );
576 mImpl->mAddRemoveBackgroundChild = true;
577 Self().Remove( background.actor );
578 mImpl->mAddRemoveBackgroundChild = false;
580 delete mImpl->mBackground;
581 mImpl->mBackground = NULL;
585 void Control::EnableGestureDetection(Gesture::Type type)
587 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
589 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
590 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
591 mImpl->mPinchGestureDetector.Attach(Self());
594 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
596 mImpl->mPanGestureDetector = PanGestureDetector::New();
597 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
598 mImpl->mPanGestureDetector.Attach(Self());
601 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
603 mImpl->mTapGestureDetector = TapGestureDetector::New();
604 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
605 mImpl->mTapGestureDetector.Attach(Self());
608 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
610 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
611 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
612 mImpl->mLongPressGestureDetector.Attach(Self());
616 void Control::DisableGestureDetection(Gesture::Type type)
618 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
620 mImpl->mPinchGestureDetector.Detach(Self());
621 mImpl->mPinchGestureDetector.Reset();
624 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
626 mImpl->mPanGestureDetector.Detach(Self());
627 mImpl->mPanGestureDetector.Reset();
630 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
632 mImpl->mTapGestureDetector.Detach(Self());
633 mImpl->mTapGestureDetector.Reset();
636 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
638 mImpl->mLongPressGestureDetector.Detach(Self());
639 mImpl->mLongPressGestureDetector.Reset();
643 PinchGestureDetector Control::GetPinchGestureDetector() const
645 return mImpl->mPinchGestureDetector;
648 PanGestureDetector Control::GetPanGestureDetector() const
650 return mImpl->mPanGestureDetector;
653 TapGestureDetector Control::GetTapGestureDetector() const
655 return mImpl->mTapGestureDetector;
658 LongPressGestureDetector Control::GetLongPressGestureDetector() const
660 return mImpl->mLongPressGestureDetector;
663 void Control::SetKeyboardNavigationSupport(bool isSupported)
665 mImpl->mIsKeyboardNavigationSupported = isSupported;
668 bool Control::IsKeyboardNavigationSupported()
670 return mImpl->mIsKeyboardNavigationSupported;
673 void Control::SetKeyInputFocus()
675 if( Self().OnStage() )
677 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
681 bool Control::HasKeyInputFocus()
684 if( Self().OnStage() )
686 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
691 void Control::ClearKeyInputFocus()
693 if( Self().OnStage() )
695 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
699 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
701 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
703 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
704 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
707 bool Control::IsKeyboardFocusGroup()
709 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
712 void Control::AccessibilityActivate()
714 // Inform deriving classes
715 OnAccessibilityActivated();
718 bool Control::OnAccessibilityActivated()
720 return false; // Accessibility activation is not handled by default
723 bool Control::OnAccessibilityPan(PanGesture gesture)
725 return false; // Accessibility pan gesture is not handled by default
728 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
730 return false; // Accessibility touch event is not handled by default
733 bool Control::OnAccessibilityValueChange(bool isIncrease)
735 return false; // Accessibility value change action is not handled by default
738 bool Control::OnAccessibilityZoom()
740 return false; // Accessibility zoom action is not handled by default
743 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
748 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
752 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
754 return mImpl->mKeyEventSignal;
757 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusGainedSignal()
759 return mImpl->mKeyInputFocusGainedSignal;
762 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusLostSignal()
764 return mImpl->mKeyInputFocusLostSignal;
767 bool Control::EmitKeyEventSignal( const KeyEvent& event )
769 // Guard against destruction during signal emission
770 Dali::Toolkit::Control handle( GetOwner() );
772 bool consumed = false;
774 // signals are allocated dynamically when someone connects
775 if ( !mImpl->mKeyEventSignal.Empty() )
777 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
782 // Notification for derived classes
783 consumed = OnKeyEvent(event);
789 Control::Control( ControlBehaviour behaviourFlags )
790 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
791 mImpl(new Impl(*this))
793 mImpl->mFlags = behaviourFlags;
796 void Control::Initialize()
798 // Call deriving classes so initialised before styling is applied to them.
801 if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
803 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
805 // Register for style changes
806 styleManager.StyleChangeSignal().Connect( this, &Control::OnStyleChange );
808 // Apply the current style
809 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
812 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
814 SetKeyboardNavigationSupport( true );
818 void Control::OnInitialize()
822 void Control::OnControlChildAdd( Actor& child )
826 void Control::OnControlChildRemove( Actor& child )
830 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
832 // By default the control is only interested in theme (not font) changes
833 if( change == StyleChange::THEME_CHANGE )
835 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
839 void Control::OnPinch(const PinchGesture& pinch)
841 if( !( mImpl->mStartingPinchScale ) )
844 mImpl->mStartingPinchScale = new Vector3;
847 if( pinch.state == Gesture::Started )
849 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
852 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
855 void Control::OnPan( const PanGesture& pan )
859 void Control::OnTap(const TapGesture& tap)
863 void Control::OnLongPress( const LongPressGesture& longPress )
867 void Control::EmitKeyInputFocusSignal( bool focusGained )
869 Dali::Toolkit::Control handle( GetOwner() );
873 // signals are allocated dynamically when someone connects
874 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
876 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
881 // signals are allocated dynamically when someone connects
882 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
884 mImpl->mKeyInputFocusLostSignal.Emit( handle );
889 void Control::OnStageConnection()
893 void Control::OnStageDisconnection()
897 void Control::OnKeyInputFocusGained()
899 EmitKeyInputFocusSignal( true );
902 void Control::OnKeyInputFocusLost()
904 EmitKeyInputFocusSignal( false );
907 void Control::OnChildAdd(Actor& child)
909 // If this is the background actor, then we do not want to inform deriving classes
910 if ( mImpl->mAddRemoveBackgroundChild )
915 // Notify derived classes.
916 OnControlChildAdd( child );
919 void Control::OnChildRemove(Actor& child)
921 // If this is the background actor, then we do not want to inform deriving classes
922 if ( mImpl->mAddRemoveBackgroundChild )
927 // Notify derived classes.
928 OnControlChildRemove( child );
931 void Control::OnSizeSet(const Vector3& targetSize)
933 // Background is resized through size negotiation
936 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
938 // @todo size negotiate background to new size, animate as well?
941 bool Control::OnTouchEvent(const TouchEvent& event)
943 return false; // Do not consume
946 bool Control::OnHoverEvent(const HoverEvent& event)
948 return false; // Do not consume
951 bool Control::OnKeyEvent(const KeyEvent& event)
953 return false; // Do not consume
956 bool Control::OnWheelEvent(const WheelEvent& event)
958 return false; // Do not consume
961 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
963 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
965 container.Add( Self().GetChildAt( i ), size );
969 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
973 Vector3 Control::GetNaturalSize()
975 if( mImpl->mBackground )
977 Actor actor = mImpl->mBackground->actor;
980 return actor.GetNaturalSize();
986 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
988 return CalculateChildSizeBase( child, dimension );
991 float Control::GetHeightForWidth( float width )
993 if( mImpl->mBackground )
995 Actor actor = mImpl->mBackground->actor;
998 return actor.GetHeightForWidth( width );
1001 return GetHeightForWidthBase( width );
1004 float Control::GetWidthForHeight( float height )
1006 if( mImpl->mBackground )
1008 Actor actor = mImpl->mBackground->actor;
1011 return actor.GetWidthForHeight( height );
1014 return GetWidthForHeightBase( height );
1017 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
1019 return RelayoutDependentOnChildrenBase( dimension );
1022 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
1026 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
1030 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1032 mImpl->SignalConnected( slotObserver, callback );
1035 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1037 mImpl->SignalDisconnected( slotObserver, callback );
1040 Control& GetImplementation( Dali::Toolkit::Control& handle )
1042 CustomActorImpl& customInterface = handle.GetImplementation();
1043 // downcast to control
1044 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
1048 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
1050 const CustomActorImpl& customInterface = handle.GetImplementation();
1051 // downcast to control
1052 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
1056 } // namespace Internal
1058 } // namespace Toolkit