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/public-api/actors/mesh-actor.h>
27 #include <dali/public-api/animation/constraint.h>
28 #include <dali/public-api/animation/constraints.h>
29 #include <dali/public-api/geometry/mesh.h>
30 #include <dali/public-api/object/type-registry.h>
31 #include <dali/public-api/object/type-registry-helper.h>
32 #include <dali/public-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/public-api/styling/style-manager.h>
41 #include <dali-toolkit/internal/styling/style-manager-impl.h>
52 #if defined(DEBUG_ENABLED)
53 Integration::Log::Filter* gLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_CONTROL");
56 const float MAX_FLOAT_VALUE( std::numeric_limits<float>::max() );
57 const Vector3 MAX_SIZE( MAX_FLOAT_VALUE, MAX_FLOAT_VALUE, MAX_FLOAT_VALUE );
58 const float BACKGROUND_ACTOR_Z_POSITION( -0.1f );
62 return Internal::Control::New();
65 // Setup signals and actions using the type-registry.
66 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
68 // Note: Properties are registered separately below,
70 DALI_SIGNAL_REGISTRATION( Control, "key-event", SIGNAL_KEY_EVENT )
71 DALI_SIGNAL_REGISTRATION( Control, "key-input-focus-gained", SIGNAL_KEY_INPUT_FOCUS_GAINED )
72 DALI_SIGNAL_REGISTRATION( Control, "key-input-focus-lost", SIGNAL_KEY_INPUT_FOCUS_LOST )
73 DALI_SIGNAL_REGISTRATION( Control, "tapped", SIGNAL_TAPPED )
74 DALI_SIGNAL_REGISTRATION( Control, "panned", SIGNAL_PANNED )
75 DALI_SIGNAL_REGISTRATION( Control, "pinched", SIGNAL_PINCHED )
76 DALI_SIGNAL_REGISTRATION( Control, "long-pressed", SIGNAL_LONG_PRESSED )
78 DALI_ACTION_REGISTRATION( Control, "control-activated", ACTION_CONTROL_ACTIVATED )
80 DALI_TYPE_REGISTRATION_END()
83 * Structure which holds information about the background of a control
87 Actor actor; ///< Either a MeshActor or an ImageActor
88 Vector4 color; ///< The color of the actor.
101 * Creates a white coloured Mesh.
105 Vector3 white( Color::WHITE );
109 // Create vertices with a white color (actual color is set by actor color)
110 MeshData::VertexContainer vertices(4);
111 vertices[ 0 ] = MeshData::Vertex( Vector3( -0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
112 vertices[ 1 ] = MeshData::Vertex( Vector3( 0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
113 vertices[ 2 ] = MeshData::Vertex( Vector3( -0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
114 vertices[ 3 ] = MeshData::Vertex( Vector3( 0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
116 // Specify all the faces
117 MeshData::FaceIndices faces;
118 faces.reserve( 6 ); // 2 triangles in Quad
119 faces.push_back( 0 ); faces.push_back( 3 ); faces.push_back( 1 );
120 faces.push_back( 0 ); faces.push_back( 2 ); faces.push_back( 3 );
122 // Create the mesh data from the vertices and faces
123 meshData.SetMaterial( Material::New( "ControlMaterial" ) );
124 meshData.SetVertices( vertices );
125 meshData.SetFaceIndices( faces );
126 meshData.SetHasColor( true );
128 return Mesh::New( meshData );
132 * Sets all the required properties for the background actor.
134 * @param[in] actor The actor to set the properties on.
135 * @param[in] color The required color of the actor.
137 void SetupBackgroundActor( Actor actor, const Vector4& color )
139 actor.SetColor( color );
140 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
141 actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
142 actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
143 actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
147 * Sets all the required properties for the background actor.
149 * @param[in] actor The actor to set the properties on.
150 * @param[in] constrainingIndex The property index to constrain the parent's size on.
151 * @param[in] color The required color of the actor.
153 void SetupBackgroundActorConstrained( Actor actor, Property::Index constrainingIndex, const Vector4& color )
155 actor.SetColor( color );
156 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
157 actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
158 actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
160 Constraint constraint = Constraint::New<Vector3>( actor,
162 EqualToConstraint() );
163 constraint.AddSource( ParentSource( Actor::Property::SIZE ) );
167 } // unnamed namespace
172 class Control::Impl : public ConnectionTracker
177 * Size indices for mMinMaxSize array
186 // Construction & Destruction
187 Impl(Control& controlImpl)
188 : mControlImpl( controlImpl ),
191 mStartingPinchScale( NULL ),
193 mPinchGestureDetector(),
194 mPanGestureDetector(),
195 mTapGestureDetector(),
196 mLongPressGestureDetector(),
199 mFlags( Control::ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ),
200 mIsKeyboardNavigationSupported( false ),
201 mIsKeyboardFocusGroup( false ),
202 mInitialized( false )
208 // All gesture detectors will be destroyed so no need to disconnect.
210 delete mStartingPinchScale;
213 // Gesture Detection Methods
215 void PinchDetected(Actor actor, const PinchGesture& pinch)
217 mControlImpl.OnPinch(pinch);
220 void PanDetected(Actor actor, const PanGesture& pan)
222 mControlImpl.OnPan(pan);
225 void TapDetected(Actor actor, const TapGesture& tap)
227 mControlImpl.OnTap(tap);
230 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
232 mControlImpl.OnLongPress(longPress);
235 // Background Methods
238 * Only creates an instance of the background if we actually use it.
239 * @return A reference to the Background structure.
241 Background& GetBackground()
245 mBackground = new Background;
253 * Called when a property of an object of this type is set.
254 * @param[in] object The object whose property is set.
255 * @param[in] index The property index.
256 * @param[in] value The new property value.
258 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
260 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
264 Control& controlImpl( control.GetImplementation() );
268 case Toolkit::Control::Property::STYLE_NAME:
270 controlImpl.SetStyleName( value.Get< std::string >() );
274 case Toolkit::Control::Property::BACKGROUND_COLOR:
276 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
280 case Toolkit::Control::Property::BACKGROUND_IMAGE:
282 if ( value.HasKey( "image" ) )
284 Property::Map imageMap = value.GetValue( "image" ).Get< Property::Map >();
285 Image image = Scripting::NewImage( imageMap );
289 controlImpl.SetBackgroundImage( image );
292 else if ( value.Get< Property::Map >().Empty() )
294 // An empty map means the background is no longer required
295 controlImpl.ClearBackground();
300 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
302 if ( value.Get< bool >() )
304 controlImpl.SetKeyInputFocus();
308 controlImpl.ClearKeyInputFocus();
317 * Called to retrieve a property of an object of this type.
318 * @param[in] object The object whose property is to be retrieved.
319 * @param[in] index The property index.
320 * @return The current value of the property.
322 static Property::Value GetProperty( BaseObject* object, Property::Index index )
324 Property::Value value;
326 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
330 Control& controlImpl( control.GetImplementation() );
334 case Toolkit::Control::Property::STYLE_NAME:
336 value = controlImpl.GetStyleName();
340 case Toolkit::Control::Property::BACKGROUND_COLOR:
342 value = controlImpl.GetBackgroundColor();
346 case Toolkit::Control::Property::BACKGROUND_IMAGE:
350 Actor actor = controlImpl.GetBackgroundActor();
353 ImageActor imageActor = ImageActor::DownCast( actor );
356 Image image = imageActor.GetImage();
357 Property::Map imageMap;
358 Scripting::CreatePropertyMap( image, imageMap );
359 map[ "image" ] = imageMap;
367 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
369 value = controlImpl.HasKeyInputFocus();
380 Control& mControlImpl;
381 std::string mStyleName;
382 Background* mBackground; ///< Only create the background if we use it
383 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
384 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
385 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
386 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
389 PinchGestureDetector mPinchGestureDetector;
390 PanGestureDetector mPanGestureDetector;
391 TapGestureDetector mTapGestureDetector;
392 LongPressGestureDetector mLongPressGestureDetector;
393 // @todo change all these to Vector2 when we have a chance to sanitize the public API as well
394 Vector3 mCurrentSize; ///< Stores the current control's size, this is the negotiated size
395 Vector3 mNaturalSize; ///< Stores the size set through the Actor's API. This is size the actor wants to be. Useful when reset to the initial size is needed.
397 ControlBehaviour mFlags :CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
398 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
399 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
400 bool mInitialized :1;
402 // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
403 static PropertyRegistration PROPERTY_1;
404 static PropertyRegistration PROPERTY_2;
405 static PropertyRegistration PROPERTY_3;
406 static PropertyRegistration PROPERTY_4;
409 // Properties registered without macro to use specific member variables.
410 PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "style-name", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
411 PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "background-color", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
412 PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "background-image", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
413 PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "key-input-focus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
415 Toolkit::Control Control::New()
417 // Create the implementation, temporarily owned on stack
418 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) );
420 // Pass ownership to handle
421 Toolkit::Control handle( *controlImpl );
423 // Second-phase init of the implementation
424 // This can only be done after the CustomActor connection has been made...
425 controlImpl->Initialize();
435 Vector3 Control::GetNaturalSize()
437 // could be overridden in derived classes.
438 return mImpl->mNaturalSize;
441 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
443 // Could be overridden in derived classes.
444 return CalculateChildSizeBase( child, dimension );
447 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
449 return RelayoutDependentOnChildrenBase( dimension );
452 float Control::GetHeightForWidth( float width )
454 // could be overridden in derived classes.
455 float height( 0.0f );
456 if ( mImpl->mNaturalSize.width > 0.0f )
458 height = mImpl->mNaturalSize.height * width / mImpl->mNaturalSize.width;
463 float Control::GetWidthForHeight( float height )
465 // could be overridden in derived classes.
467 if ( mImpl->mNaturalSize.height > 0.0f )
469 width = mImpl->mNaturalSize.width * height / mImpl->mNaturalSize.height;
474 const Vector3& Control::GetControlSize() const
476 return mImpl->mCurrentSize;
479 const Vector3& Control::GetSizeSet() const
481 return mImpl->mNaturalSize;
484 void Control::SetKeyInputFocus()
486 if( Self().OnStage() )
488 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
492 bool Control::HasKeyInputFocus()
495 if( Self().OnStage() )
497 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
502 void Control::ClearKeyInputFocus()
504 if( Self().OnStage() )
506 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
510 PinchGestureDetector Control::GetPinchGestureDetector() const
512 return mImpl->mPinchGestureDetector;
515 PanGestureDetector Control::GetPanGestureDetector() const
517 return mImpl->mPanGestureDetector;
520 TapGestureDetector Control::GetTapGestureDetector() const
522 return mImpl->mTapGestureDetector;
525 LongPressGestureDetector Control::GetLongPressGestureDetector() const
527 return mImpl->mLongPressGestureDetector;
530 void Control::SetStyleName( const std::string& styleName )
532 if( styleName != mImpl->mStyleName )
534 mImpl->mStyleName = styleName;
537 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
538 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
542 const std::string& Control::GetStyleName() const
544 return mImpl->mStyleName;
547 void Control::SetBackgroundColor( const Vector4& color )
549 Background& background( mImpl->GetBackground() );
551 if ( background.actor )
553 // Just set the actor color
554 background.actor.SetColor( color );
559 MeshActor meshActor = MeshActor::New( CreateMesh() );
561 SetupBackgroundActorConstrained( meshActor, Actor::Property::SCALE, color );
563 // Set the background actor before adding so that we do not inform deriving classes
564 background.actor = meshActor;
565 Self().Add( meshActor );
568 background.color = color;
571 Vector4 Control::GetBackgroundColor() const
573 if ( mImpl->mBackground )
575 return mImpl->mBackground->color;
577 return Color::TRANSPARENT;
580 void Control::SetBackgroundImage( Image image )
582 Background& background( mImpl->GetBackground() );
584 if ( background.actor )
586 // Remove Current actor, unset AFTER removal so that we do not inform deriving classes
587 Self().Remove( background.actor );
588 background.actor.Reset();
591 ImageActor imageActor = ImageActor::New( image );
592 SetupBackgroundActor( imageActor, background.color );
594 // Set the background actor before adding so that we do not inform derived classes
595 background.actor = imageActor;
596 Self().Add( imageActor );
599 void Control::ClearBackground()
601 if ( mImpl->mBackground )
603 Background& background( mImpl->GetBackground() );
604 Self().Remove( background.actor );
606 delete mImpl->mBackground;
607 mImpl->mBackground = NULL;
611 Actor Control::GetBackgroundActor() const
613 if ( mImpl->mBackground )
615 return mImpl->mBackground->actor;
621 void Control::SetKeyboardNavigationSupport(bool isSupported)
623 mImpl->mIsKeyboardNavigationSupported = isSupported;
626 bool Control::IsKeyboardNavigationSupported()
628 return mImpl->mIsKeyboardNavigationSupported;
631 void Control::Activate()
633 // Inform deriving classes
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 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
654 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
656 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
657 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
660 bool Control::IsKeyboardFocusGroup()
662 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
665 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
670 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
674 bool Control::DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes)
678 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_CONTROL_ACTIVATED ) ) )
680 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
683 // if cast succeeds there is an implementation so no need to check
684 control.GetImplementation().OnActivated();
691 bool Control::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
693 Dali::BaseHandle handle( object );
695 bool connected( false );
696 Toolkit::Control control = Toolkit::Control::DownCast( handle );
699 Control& controlImpl( control.GetImplementation() );
702 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
704 controlImpl.KeyEventSignal().Connect( tracker, functor );
706 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
708 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
710 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
712 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
714 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
716 controlImpl.EnableGestureDetection( Gesture::Tap );
717 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
719 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
721 controlImpl.EnableGestureDetection( Gesture::Pan );
722 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
724 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
726 controlImpl.EnableGestureDetection( Gesture::Pinch );
727 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
729 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
731 controlImpl.EnableGestureDetection( Gesture::LongPress );
732 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
736 // signalName does not match any signal
743 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
745 return mImpl->mKeyEventSignal;
748 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusGainedSignal()
750 return mImpl->mKeyInputFocusGainedSignal;
753 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusLostSignal()
755 return mImpl->mKeyInputFocusLostSignal;
758 bool Control::EmitKeyEventSignal( const KeyEvent& event )
760 // Guard against destruction during signal emission
761 Dali::Toolkit::Control handle( GetOwner() );
763 bool consumed = false;
765 // signals are allocated dynamically when someone connects
766 if ( !mImpl->mKeyEventSignal.Empty() )
768 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
773 // Notification for derived classes
774 consumed = OnKeyEvent(event);
780 Control::Control( ControlBehaviour behaviourFlags )
781 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
782 mImpl(new Impl(*this))
784 mImpl->mFlags = behaviourFlags;
787 void Control::Initialize()
789 // Calling deriving classes
792 if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
794 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
796 // Register for style changes
797 styleManager.StyleChangeSignal().Connect( this, &Control::OnStyleChange );
800 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
803 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
805 SetKeyboardNavigationSupport( true );
808 mImpl->mInitialized = true;
811 void Control::EnableGestureDetection(Gesture::Type type)
813 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
815 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
816 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
817 mImpl->mPinchGestureDetector.Attach(Self());
820 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
822 mImpl->mPanGestureDetector = PanGestureDetector::New();
823 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
824 mImpl->mPanGestureDetector.Attach(Self());
827 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
829 mImpl->mTapGestureDetector = TapGestureDetector::New();
830 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
831 mImpl->mTapGestureDetector.Attach(Self());
834 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
836 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
837 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
838 mImpl->mLongPressGestureDetector.Attach(Self());
842 void Control::DisableGestureDetection(Gesture::Type type)
844 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
846 mImpl->mPinchGestureDetector.Detach(Self());
847 mImpl->mPinchGestureDetector.Reset();
850 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
852 mImpl->mPanGestureDetector.Detach(Self());
853 mImpl->mPanGestureDetector.Reset();
856 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
858 mImpl->mTapGestureDetector.Detach(Self());
859 mImpl->mTapGestureDetector.Reset();
862 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
864 mImpl->mLongPressGestureDetector.Detach(Self());
865 mImpl->mLongPressGestureDetector.Reset();
869 void Control::OnInitialize()
873 void Control::OnActivated()
877 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange change )
879 // By default the control is only interested in theme (not font) changes
880 if( change.themeChange )
882 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
886 void Control::OnPinch(const PinchGesture& pinch)
888 if( !( mImpl->mStartingPinchScale ) )
891 mImpl->mStartingPinchScale = new Vector3;
894 if( pinch.state == Gesture::Started )
896 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
899 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
902 void Control::OnPan( const PanGesture& pan )
906 void Control::OnTap(const TapGesture& tap)
910 void Control::OnLongPress( const LongPressGesture& longPress )
914 void Control::OnControlStageConnection()
918 void Control::OnControlStageDisconnection()
922 void Control::OnControlChildAdd( Actor& child )
926 void Control::OnControlChildRemove( Actor& child )
930 void Control::OnControlSizeSet( const Vector3& size )
934 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
938 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
942 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
944 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
946 container.Add( Self().GetChildAt( i ), size );
950 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
954 void Control::EmitKeyInputFocusSignal( bool focusGained )
956 Dali::Toolkit::Control handle( GetOwner() );
960 // signals are allocated dynamically when someone connects
961 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
963 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
968 // signals are allocated dynamically when someone connects
969 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
971 mImpl->mKeyInputFocusLostSignal.Emit( handle );
976 void Control::OnKeyInputFocusGained()
978 EmitKeyInputFocusSignal( true );
981 void Control::OnKeyInputFocusLost()
983 EmitKeyInputFocusSignal( false );
986 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
988 // @todo consider animating negotiated child sizes to target size
991 bool Control::OnTouchEvent(const TouchEvent& event)
993 return false; // Do not consume
996 bool Control::OnHoverEvent(const HoverEvent& event)
998 return false; // Do not consume
1001 bool Control::OnKeyEvent(const KeyEvent& event)
1003 return false; // Do not consume
1006 bool Control::OnMouseWheelEvent(const MouseWheelEvent& event)
1008 return false; // Do not consume
1011 void Control::OnStageConnection()
1013 // Notify derived classes.
1014 OnControlStageConnection();
1017 void Control::OnStageDisconnection()
1019 // Notify derived classes
1020 OnControlStageDisconnection();
1023 void Control::OnChildAdd(Actor& child)
1025 // If this is the background actor, then we do not want to relayout or inform deriving classes
1026 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
1031 // Notify derived classes.
1032 OnControlChildAdd( child );
1035 void Control::OnChildRemove(Actor& child)
1037 // If this is the background actor, then we do not want to relayout or inform deriving classes
1038 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
1043 // Notify derived classes.
1044 OnControlChildRemove( child );
1047 void Control::OnSizeSet(const Vector3& targetSize)
1049 if( targetSize != mImpl->mNaturalSize )
1051 // Only updates size if set through Actor's API
1052 mImpl->mNaturalSize = targetSize;
1055 if( targetSize != mImpl->mCurrentSize )
1057 // Update control size.
1058 mImpl->mCurrentSize = targetSize;
1060 // Notify derived classes.
1061 OnControlSizeSet( targetSize );
1065 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1067 mImpl->SignalConnected( slotObserver, callback );
1070 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1072 mImpl->SignalDisconnected( slotObserver, callback );
1075 } // namespace Internal
1077 } // namespace Toolkit