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 );
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_CONTROL_ACTIVATED = "control-activated";
70 static bool DoAction( BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes )
74 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_CONTROL_ACTIVATED ) ) )
76 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
79 // if cast succeeds there is an implementation so no need to check
80 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 );
148 // signalName does not match any signal
155 // Setup signals and actions using the type-registry.
156 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
158 // Note: Properties are registered separately below.
160 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
161 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
162 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
163 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
164 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
165 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
166 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
168 TypeAction registerAction( typeRegistration, ACTION_CONTROL_ACTIVATED, &DoAction );
170 DALI_TYPE_REGISTRATION_END()
173 * Structure which holds information about the background of a control
177 Actor actor; ///< Either a MeshActor or an ImageActor
178 Vector4 color; ///< The color of the actor.
185 color( Color::WHITE )
191 * Creates a white coloured Mesh.
195 Vector3 white( Color::WHITE );
199 // Create vertices with a white color (actual color is set by actor color)
200 MeshData::VertexContainer vertices(4);
201 vertices[ 0 ] = MeshData::Vertex( Vector3( -0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
202 vertices[ 1 ] = MeshData::Vertex( Vector3( 0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
203 vertices[ 2 ] = MeshData::Vertex( Vector3( -0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
204 vertices[ 3 ] = MeshData::Vertex( Vector3( 0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
206 // Specify all the faces
207 MeshData::FaceIndices faces;
208 faces.reserve( 6 ); // 2 triangles in Quad
209 faces.push_back( 0 ); faces.push_back( 3 ); faces.push_back( 1 );
210 faces.push_back( 0 ); faces.push_back( 2 ); faces.push_back( 3 );
212 // Create the mesh data from the vertices and faces
213 meshData.SetMaterial( Material::New( "ControlMaterial" ) );
214 meshData.SetVertices( vertices );
215 meshData.SetFaceIndices( faces );
216 meshData.SetHasColor( true );
218 return Mesh::New( meshData );
222 * Sets all the required properties for the background actor.
224 * @param[in] actor The actor to set the properties on.
225 * @param[in] color The required color of the actor.
227 void SetupBackgroundActor( Actor actor, const Vector4& color )
229 actor.SetColor( color );
230 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
231 actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
232 actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
233 actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
237 * Sets all the required properties for the background actor.
239 * @param[in] actor The actor to set the properties on.
240 * @param[in] constrainingIndex The property index to constrain the parent's size on.
241 * @param[in] color The required color of the actor.
243 void SetupBackgroundActorConstrained( Actor actor, Property::Index constrainingIndex, const Vector4& color )
245 actor.SetColor( color );
246 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
247 actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
248 actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
250 Constraint constraint = Constraint::New<Vector3>( actor,
252 EqualToConstraint() );
253 constraint.AddSource( ParentSource( Actor::Property::SIZE ) );
257 } // unnamed namespace
262 class Control::Impl : public ConnectionTracker
266 // Construction & Destruction
267 Impl(Control& controlImpl)
268 : mControlImpl( controlImpl ),
271 mStartingPinchScale( NULL ),
273 mPinchGestureDetector(),
274 mPanGestureDetector(),
275 mTapGestureDetector(),
276 mLongPressGestureDetector(),
277 mFlags( Control::ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ),
278 mIsKeyboardNavigationSupported( false ),
279 mIsKeyboardFocusGroup( false )
285 // All gesture detectors will be destroyed so no need to disconnect.
287 delete mStartingPinchScale;
290 // Gesture Detection Methods
292 void PinchDetected(Actor actor, const PinchGesture& pinch)
294 mControlImpl.OnPinch(pinch);
297 void PanDetected(Actor actor, const PanGesture& pan)
299 mControlImpl.OnPan(pan);
302 void TapDetected(Actor actor, const TapGesture& tap)
304 mControlImpl.OnTap(tap);
307 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
309 mControlImpl.OnLongPress(longPress);
312 // Background Methods
315 * Only creates an instance of the background if we actually use it.
316 * @return A reference to the Background structure.
318 Background& GetBackground()
322 mBackground = new Background;
330 * Called when a property of an object of this type is set.
331 * @param[in] object The object whose property is set.
332 * @param[in] index The property index.
333 * @param[in] value The new property value.
335 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
337 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
341 Control& controlImpl( GetImplementation( control ) );
345 case Toolkit::Control::Property::STYLE_NAME:
347 controlImpl.SetStyleName( value.Get< std::string >() );
351 case Toolkit::Control::Property::BACKGROUND_COLOR:
353 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
357 case Toolkit::Control::Property::BACKGROUND_IMAGE:
359 if ( value.HasKey( "image" ) )
361 Property::Map imageMap = value.GetValue( "image" ).Get< Property::Map >();
362 Image image = Scripting::NewImage( imageMap );
366 controlImpl.SetBackgroundImage( image );
369 else if ( value.Get< Property::Map >().Empty() )
371 // An empty map means the background is no longer required
372 controlImpl.ClearBackground();
377 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
379 if ( value.Get< bool >() )
381 controlImpl.SetKeyInputFocus();
385 controlImpl.ClearKeyInputFocus();
394 * Called to retrieve a property of an object of this type.
395 * @param[in] object The object whose property is to be retrieved.
396 * @param[in] index The property index.
397 * @return The current value of the property.
399 static Property::Value GetProperty( BaseObject* object, Property::Index index )
401 Property::Value value;
403 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
407 Control& controlImpl( GetImplementation( control ) );
411 case Toolkit::Control::Property::STYLE_NAME:
413 value = controlImpl.GetStyleName();
417 case Toolkit::Control::Property::BACKGROUND_COLOR:
419 value = controlImpl.GetBackgroundColor();
423 case Toolkit::Control::Property::BACKGROUND_IMAGE:
427 Background* back = controlImpl.mImpl->mBackground;
430 ImageActor imageActor = ImageActor::DownCast( back->actor );
433 Image image = imageActor.GetImage();
434 Property::Map imageMap;
435 Scripting::CreatePropertyMap( image, imageMap );
436 map[ "image" ] = imageMap;
444 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
446 value = controlImpl.HasKeyInputFocus();
457 Control& mControlImpl;
458 std::string mStyleName;
459 Background* mBackground; ///< Only create the background if we use it
460 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
461 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
462 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
463 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
466 PinchGestureDetector mPinchGestureDetector;
467 PanGestureDetector mPanGestureDetector;
468 TapGestureDetector mTapGestureDetector;
469 LongPressGestureDetector mLongPressGestureDetector;
471 ControlBehaviour mFlags :CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
472 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
473 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
475 // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
476 static PropertyRegistration PROPERTY_1;
477 static PropertyRegistration PROPERTY_2;
478 static PropertyRegistration PROPERTY_3;
479 static PropertyRegistration PROPERTY_4;
482 // Properties registered without macro to use specific member variables.
483 PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "style-name", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
484 PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "background-color", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
485 PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "background-image", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
486 PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "key-input-focus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
488 Toolkit::Control Control::New()
490 // Create the implementation, temporarily owned on stack
491 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) );
493 // Pass ownership to handle
494 Toolkit::Control handle( *controlImpl );
496 // Second-phase init of the implementation
497 // This can only be done after the CustomActor connection has been made...
498 controlImpl->Initialize();
508 void Control::SetStyleName( const std::string& styleName )
510 if( styleName != mImpl->mStyleName )
512 mImpl->mStyleName = styleName;
515 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
516 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
520 const std::string& Control::GetStyleName() const
522 return mImpl->mStyleName;
525 void Control::SetBackgroundColor( const Vector4& color )
527 Background& background( mImpl->GetBackground() );
529 if ( background.actor )
531 // Just set the actor color
532 background.actor.SetColor( color );
537 MeshActor meshActor = MeshActor::New( CreateMesh() );
539 SetupBackgroundActorConstrained( meshActor, Actor::Property::SCALE, color );
541 // Set the background actor before adding so that we do not inform deriving classes
542 background.actor = meshActor;
543 Self().Add( meshActor );
546 background.color = color;
549 Vector4 Control::GetBackgroundColor() const
551 if ( mImpl->mBackground )
553 return mImpl->mBackground->color;
555 return Color::TRANSPARENT;
558 void Control::SetBackgroundImage( Image image )
560 Background& background( mImpl->GetBackground() );
562 if ( background.actor )
564 // Remove Current actor, unset AFTER removal so that we do not inform deriving classes
565 Self().Remove( background.actor );
566 background.actor.Reset();
569 ImageActor imageActor = ImageActor::New( image );
570 SetupBackgroundActor( imageActor, background.color );
572 // Set the background actor before adding so that we do not inform derived classes
573 background.actor = imageActor;
574 Self().Add( imageActor );
577 void Control::ClearBackground()
579 if ( mImpl->mBackground )
581 Background& background( mImpl->GetBackground() );
582 Self().Remove( background.actor );
584 delete mImpl->mBackground;
585 mImpl->mBackground = NULL;
589 void Control::EnableGestureDetection(Gesture::Type type)
591 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
593 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
594 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
595 mImpl->mPinchGestureDetector.Attach(Self());
598 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
600 mImpl->mPanGestureDetector = PanGestureDetector::New();
601 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
602 mImpl->mPanGestureDetector.Attach(Self());
605 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
607 mImpl->mTapGestureDetector = TapGestureDetector::New();
608 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
609 mImpl->mTapGestureDetector.Attach(Self());
612 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
614 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
615 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
616 mImpl->mLongPressGestureDetector.Attach(Self());
620 void Control::DisableGestureDetection(Gesture::Type type)
622 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
624 mImpl->mPinchGestureDetector.Detach(Self());
625 mImpl->mPinchGestureDetector.Reset();
628 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
630 mImpl->mPanGestureDetector.Detach(Self());
631 mImpl->mPanGestureDetector.Reset();
634 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
636 mImpl->mTapGestureDetector.Detach(Self());
637 mImpl->mTapGestureDetector.Reset();
640 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
642 mImpl->mLongPressGestureDetector.Detach(Self());
643 mImpl->mLongPressGestureDetector.Reset();
647 PinchGestureDetector Control::GetPinchGestureDetector() const
649 return mImpl->mPinchGestureDetector;
652 PanGestureDetector Control::GetPanGestureDetector() const
654 return mImpl->mPanGestureDetector;
657 TapGestureDetector Control::GetTapGestureDetector() const
659 return mImpl->mTapGestureDetector;
662 LongPressGestureDetector Control::GetLongPressGestureDetector() const
664 return mImpl->mLongPressGestureDetector;
667 void Control::SetKeyboardNavigationSupport(bool isSupported)
669 mImpl->mIsKeyboardNavigationSupported = isSupported;
672 bool Control::IsKeyboardNavigationSupported()
674 return mImpl->mIsKeyboardNavigationSupported;
677 void Control::SetKeyInputFocus()
679 if( Self().OnStage() )
681 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
685 bool Control::HasKeyInputFocus()
688 if( Self().OnStage() )
690 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
695 void Control::ClearKeyInputFocus()
697 if( Self().OnStage() )
699 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
703 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
705 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
707 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
708 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
711 bool Control::IsKeyboardFocusGroup()
713 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
716 void Control::AccessibilityActivate()
718 // Inform deriving classes
719 OnAccessibilityActivated();
722 void Control::OnAccessibilityActivated()
726 bool Control::OnAccessibilityPan(PanGesture gesture)
728 return false; // Accessibility pan gesture is not handled by default
731 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
733 return false; // Accessibility touch event is not handled by default
736 bool Control::OnAccessibilityValueChange(bool isIncrease)
738 return false; // Accessibility value change action is not handled by default
741 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
746 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
750 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
752 return mImpl->mKeyEventSignal;
755 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusGainedSignal()
757 return mImpl->mKeyInputFocusGainedSignal;
760 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusLostSignal()
762 return mImpl->mKeyInputFocusLostSignal;
765 bool Control::EmitKeyEventSignal( const KeyEvent& event )
767 // Guard against destruction during signal emission
768 Dali::Toolkit::Control handle( GetOwner() );
770 bool consumed = false;
772 // signals are allocated dynamically when someone connects
773 if ( !mImpl->mKeyEventSignal.Empty() )
775 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
780 // Notification for derived classes
781 consumed = OnKeyEvent(event);
787 Control::Control( ControlBehaviour behaviourFlags )
788 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
789 mImpl(new Impl(*this))
791 mImpl->mFlags = behaviourFlags;
794 void Control::Initialize()
796 if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
798 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
800 // Register for style changes
801 styleManager.StyleChangeSignal().Connect( this, &Control::OnStyleChange );
804 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
807 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
809 SetKeyboardNavigationSupport( true );
812 // Calling deriving classes
816 void Control::OnInitialize()
820 void Control::OnControlChildAdd( Actor& child )
824 void Control::OnControlChildRemove( Actor& child )
828 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
830 // By default the control is only interested in theme (not font) changes
831 if( change == StyleChange::THEME_CHANGE )
833 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
837 void Control::OnPinch(const PinchGesture& pinch)
839 if( !( mImpl->mStartingPinchScale ) )
842 mImpl->mStartingPinchScale = new Vector3;
845 if( pinch.state == Gesture::Started )
847 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
850 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
853 void Control::OnPan( const PanGesture& pan )
857 void Control::OnTap(const TapGesture& tap)
861 void Control::OnLongPress( const LongPressGesture& longPress )
865 void Control::EmitKeyInputFocusSignal( bool focusGained )
867 Dali::Toolkit::Control handle( GetOwner() );
871 // signals are allocated dynamically when someone connects
872 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
874 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
879 // signals are allocated dynamically when someone connects
880 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
882 mImpl->mKeyInputFocusLostSignal.Emit( handle );
887 void Control::OnStageConnection()
891 void Control::OnStageDisconnection()
895 void Control::OnKeyInputFocusGained()
897 EmitKeyInputFocusSignal( true );
900 void Control::OnKeyInputFocusLost()
902 EmitKeyInputFocusSignal( false );
905 void Control::OnChildAdd(Actor& child)
907 // If this is the background actor, then we do not want to relayout or inform deriving classes
908 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
913 // Notify derived classes.
914 OnControlChildAdd( child );
917 void Control::OnChildRemove(Actor& child)
919 // If this is the background actor, then we do not want to relayout or inform deriving classes
920 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
925 // Notify derived classes.
926 OnControlChildRemove( child );
929 void Control::OnSizeSet(const Vector3& targetSize)
931 // Background is resized through size negotiation
934 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
936 // @todo size negotiate background to new size, animate as well?
939 bool Control::OnTouchEvent(const TouchEvent& event)
941 return false; // Do not consume
944 bool Control::OnHoverEvent(const HoverEvent& event)
946 return false; // Do not consume
949 bool Control::OnKeyEvent(const KeyEvent& event)
951 return false; // Do not consume
954 bool Control::OnMouseWheelEvent(const MouseWheelEvent& event)
956 return false; // Do not consume
959 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
961 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
963 container.Add( Self().GetChildAt( i ), size );
967 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
971 Vector3 Control::GetNaturalSize()
973 if( mImpl->mBackground )
975 Actor actor = mImpl->mBackground->actor;
978 return actor.GetNaturalSize();
984 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
986 return CalculateChildSizeBase( child, dimension );
989 float Control::GetHeightForWidth( float width )
991 if( mImpl->mBackground )
993 Actor actor = mImpl->mBackground->actor;
996 return actor.GetHeightForWidth( width );
999 return GetHeightForWidthBase( width );
1002 float Control::GetWidthForHeight( float height )
1004 if( mImpl->mBackground )
1006 Actor actor = mImpl->mBackground->actor;
1009 return actor.GetWidthForHeight( height );
1012 return GetWidthForHeightBase( height );
1015 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
1017 return RelayoutDependentOnChildrenBase( dimension );
1020 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
1024 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
1028 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1030 mImpl->SignalConnected( slotObserver, callback );
1033 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1035 mImpl->SignalDisconnected( slotObserver, callback );
1038 Control& GetImplementation( Dali::Toolkit::Control& handle )
1040 CustomActorImpl& customInterface = handle.GetImplementation();
1041 // downcast to control
1042 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
1046 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
1048 const CustomActorImpl& customInterface = handle.GetImplementation();
1049 // downcast to control
1050 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
1054 } // namespace Internal
1056 } // namespace Toolkit