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/animation/constraint.h>
27 #include <dali/public-api/animation/constraints.h>
28 #include <dali/public-api/object/type-registry.h>
29 #include <dali/public-api/object/type-registry-helper.h>
30 #include <dali/public-api/scripting/scripting.h>
31 #include <dali/public-api/size-negotiation/relayout-container.h>
32 #include <dali/integration-api/debug.h>
35 #include <dali-toolkit/public-api/focus-manager/keyinput-focus-manager.h>
36 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
37 #include <dali-toolkit/public-api/controls/control.h>
38 #include <dali-toolkit/public-api/styling/style-manager.h>
39 #include <dali-toolkit/internal/styling/style-manager-impl.h>
50 //#if defined(DEBUG_ENABLED)
51 //Integration::Log::Filter* gLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_CONTROL");
54 const float MAX_FLOAT_VALUE( std::numeric_limits<float>::max() );
55 const Vector3 MAX_SIZE( MAX_FLOAT_VALUE, MAX_FLOAT_VALUE, MAX_FLOAT_VALUE );
56 const float BACKGROUND_ACTOR_Z_POSITION( -0.1f );
60 return Internal::Control::New();
63 // Setup signals and actions using the type-registry.
64 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
66 // Note: Properties are registered separately below.
68 DALI_SIGNAL_REGISTRATION( Toolkit, Control, "key-event", SIGNAL_KEY_EVENT )
69 DALI_SIGNAL_REGISTRATION( Toolkit, Control, "key-input-focus-gained", SIGNAL_KEY_INPUT_FOCUS_GAINED )
70 DALI_SIGNAL_REGISTRATION( Toolkit, Control, "key-input-focus-lost", SIGNAL_KEY_INPUT_FOCUS_LOST )
71 DALI_SIGNAL_REGISTRATION( Toolkit, Control, "tapped", SIGNAL_TAPPED )
72 DALI_SIGNAL_REGISTRATION( Toolkit, Control, "panned", SIGNAL_PANNED )
73 DALI_SIGNAL_REGISTRATION( Toolkit, Control, "pinched", SIGNAL_PINCHED )
74 DALI_SIGNAL_REGISTRATION( Toolkit, Control, "long-pressed", SIGNAL_LONG_PRESSED )
76 DALI_ACTION_REGISTRATION( Toolkit, Control, "control-activated", ACTION_CONTROL_ACTIVATED )
78 DALI_TYPE_REGISTRATION_END()
81 * Structure which holds information about the background of a control
85 Actor actor; ///< Either a MeshActor or an ImageActor
86 Vector4 color; ///< The color of the actor.
99 * Creates a white coloured Mesh.
103 Vector3 white( Color::WHITE );
107 // Create vertices with a white color (actual color is set by actor color)
108 MeshData::VertexContainer vertices(4);
109 vertices[ 0 ] = MeshData::Vertex( Vector3( -0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
110 vertices[ 1 ] = MeshData::Vertex( Vector3( 0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
111 vertices[ 2 ] = MeshData::Vertex( Vector3( -0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
112 vertices[ 3 ] = MeshData::Vertex( Vector3( 0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
114 // Specify all the faces
115 MeshData::FaceIndices faces;
116 faces.reserve( 6 ); // 2 triangles in Quad
117 faces.push_back( 0 ); faces.push_back( 3 ); faces.push_back( 1 );
118 faces.push_back( 0 ); faces.push_back( 2 ); faces.push_back( 3 );
120 // Create the mesh data from the vertices and faces
121 meshData.SetMaterial( Material::New( "ControlMaterial" ) );
122 meshData.SetVertices( vertices );
123 meshData.SetFaceIndices( faces );
124 meshData.SetHasColor( true );
127 //return Mesh::New( meshData );
131 * Sets all the required properties for the background actor.
133 * @param[in] actor The actor to set the properties on.
134 * @param[in] color The required color of the actor.
136 void SetupBackgroundActor( Actor actor, const Vector4& color )
138 actor.SetColor( color );
139 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
140 actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
141 actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
142 actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
146 * Sets all the required properties for the background actor.
148 * @param[in] actor The actor to set the properties on.
149 * @param[in] constrainingIndex The property index to constrain the parent's size on.
150 * @param[in] color The required color of the actor.
152 void SetupBackgroundActorConstrained( Actor actor, Property::Index constrainingIndex, const Vector4& color )
154 actor.SetColor( color );
155 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
156 actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
157 actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
159 Constraint constraint = Constraint::New<Vector3>( actor,
161 EqualToConstraint() );
162 constraint.AddSource( ParentSource( Actor::Property::SIZE ) );
166 } // unnamed namespace
171 class Control::Impl : public ConnectionTracker
176 * Size indices for mMinMaxSize array
185 // Construction & Destruction
186 Impl(Control& controlImpl)
187 : mControlImpl( controlImpl ),
190 mStartingPinchScale( NULL ),
192 mPinchGestureDetector(),
193 mPanGestureDetector(),
194 mTapGestureDetector(),
195 mLongPressGestureDetector(),
198 mFlags( Control::ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ),
199 mIsKeyboardNavigationSupported( false ),
200 mIsKeyboardFocusGroup( false ),
201 mInitialized( false )
207 // All gesture detectors will be destroyed so no need to disconnect.
209 delete mStartingPinchScale;
212 // Gesture Detection Methods
214 void PinchDetected(Actor actor, const PinchGesture& pinch)
216 mControlImpl.OnPinch(pinch);
219 void PanDetected(Actor actor, const PanGesture& pan)
221 mControlImpl.OnPan(pan);
224 void TapDetected(Actor actor, const TapGesture& tap)
226 mControlImpl.OnTap(tap);
229 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
231 mControlImpl.OnLongPress(longPress);
234 // Background Methods
237 * Only creates an instance of the background if we actually use it.
238 * @return A reference to the Background structure.
240 Background& GetBackground()
244 mBackground = new Background;
252 * Called when a property of an object of this type is set.
253 * @param[in] object The object whose property is set.
254 * @param[in] index The property index.
255 * @param[in] value The new property value.
257 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
259 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
263 Control& controlImpl( control.GetImplementation() );
267 case Toolkit::Control::Property::STYLE_NAME:
269 controlImpl.SetStyleName( value.Get< std::string >() );
273 case Toolkit::Control::Property::BACKGROUND_COLOR:
275 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
279 case Toolkit::Control::Property::BACKGROUND_IMAGE:
281 if ( value.HasKey( "image" ) )
283 Property::Map imageMap = value.GetValue( "image" ).Get< Property::Map >();
284 Image image = Scripting::NewImage( imageMap );
288 controlImpl.SetBackgroundImage( image );
291 else if ( value.Get< Property::Map >().Empty() )
293 // An empty map means the background is no longer required
294 controlImpl.ClearBackground();
299 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
301 if ( value.Get< bool >() )
303 controlImpl.SetKeyInputFocus();
307 controlImpl.ClearKeyInputFocus();
316 * Called to retrieve a property of an object of this type.
317 * @param[in] object The object whose property is to be retrieved.
318 * @param[in] index The property index.
319 * @return The current value of the property.
321 static Property::Value GetProperty( BaseObject* object, Property::Index index )
323 Property::Value value;
325 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
329 Control& controlImpl( control.GetImplementation() );
333 case Toolkit::Control::Property::STYLE_NAME:
335 value = controlImpl.GetStyleName();
339 case Toolkit::Control::Property::BACKGROUND_COLOR:
341 value = controlImpl.GetBackgroundColor();
345 case Toolkit::Control::Property::BACKGROUND_IMAGE:
349 Actor actor = controlImpl.GetBackgroundActor();
352 ImageActor imageActor = ImageActor::DownCast( actor );
355 Image image = imageActor.GetImage();
356 Property::Map imageMap;
357 Scripting::CreatePropertyMap( image, imageMap );
358 map[ "image" ] = imageMap;
366 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
368 value = controlImpl.HasKeyInputFocus();
379 Control& mControlImpl;
380 std::string mStyleName;
381 Background* mBackground; ///< Only create the background if we use it
382 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
383 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
384 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
385 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
388 PinchGestureDetector mPinchGestureDetector;
389 PanGestureDetector mPanGestureDetector;
390 TapGestureDetector mTapGestureDetector;
391 LongPressGestureDetector mLongPressGestureDetector;
392 // @todo change all these to Vector2 when we have a chance to sanitize the public API as well
393 Vector3 mCurrentSize; ///< Stores the current control's size, this is the negotiated size
394 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.
396 ControlBehaviour mFlags :CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
397 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
398 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
399 bool mInitialized :1;
401 // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
402 static PropertyRegistration PROPERTY_1;
403 static PropertyRegistration PROPERTY_2;
404 static PropertyRegistration PROPERTY_3;
405 static PropertyRegistration PROPERTY_4;
408 // Properties registered without macro to use specific member variables.
409 PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "style-name", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
410 PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "background-color", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
411 PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "background-image", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
412 PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "key-input-focus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
414 Toolkit::Control Control::New()
416 // Create the implementation, temporarily owned on stack
417 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) );
419 // Pass ownership to handle
420 Toolkit::Control handle( *controlImpl );
422 // Second-phase init of the implementation
423 // This can only be done after the CustomActor connection has been made...
424 controlImpl->Initialize();
434 Vector3 Control::GetNaturalSize()
436 // could be overridden in derived classes.
437 return mImpl->mNaturalSize;
440 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
442 // Could be overridden in derived classes.
443 return CalculateChildSizeBase( child, dimension );
446 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
448 return RelayoutDependentOnChildrenBase( dimension );
451 float Control::GetHeightForWidth( float width )
453 // could be overridden in derived classes.
454 float height( 0.0f );
455 if ( mImpl->mNaturalSize.width > 0.0f )
457 height = mImpl->mNaturalSize.height * width / mImpl->mNaturalSize.width;
462 float Control::GetWidthForHeight( float height )
464 // could be overridden in derived classes.
466 if ( mImpl->mNaturalSize.height > 0.0f )
468 width = mImpl->mNaturalSize.width * height / mImpl->mNaturalSize.height;
473 const Vector3& Control::GetControlSize() const
475 return mImpl->mCurrentSize;
478 const Vector3& Control::GetSizeSet() const
480 return mImpl->mNaturalSize;
483 void Control::SetKeyInputFocus()
485 if( Self().OnStage() )
487 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
491 bool Control::HasKeyInputFocus()
494 if( Self().OnStage() )
496 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
501 void Control::ClearKeyInputFocus()
503 if( Self().OnStage() )
505 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
509 PinchGestureDetector Control::GetPinchGestureDetector() const
511 return mImpl->mPinchGestureDetector;
514 PanGestureDetector Control::GetPanGestureDetector() const
516 return mImpl->mPanGestureDetector;
519 TapGestureDetector Control::GetTapGestureDetector() const
521 return mImpl->mTapGestureDetector;
524 LongPressGestureDetector Control::GetLongPressGestureDetector() const
526 return mImpl->mLongPressGestureDetector;
529 void Control::SetStyleName( const std::string& styleName )
531 if( styleName != mImpl->mStyleName )
533 mImpl->mStyleName = styleName;
536 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
537 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
541 const std::string& Control::GetStyleName() const
543 return mImpl->mStyleName;
546 void Control::SetBackgroundColor( const Vector4& color )
548 Background& background( mImpl->GetBackground() );
550 if ( background.actor )
552 // Just set the actor color
553 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 );
569 background.color = color;
572 Vector4 Control::GetBackgroundColor() const
574 if ( mImpl->mBackground )
576 return mImpl->mBackground->color;
578 return Color::TRANSPARENT;
581 void Control::SetBackgroundImage( Image image )
583 Background& background( mImpl->GetBackground() );
585 if ( background.actor )
587 // Remove Current actor, unset AFTER removal so that we do not inform deriving classes
588 Self().Remove( background.actor );
589 background.actor.Reset();
593 ImageActor imageActor = ImageActor::New( image );
594 SetupBackgroundActor( imageActor, Actor::Property::SIZE, background.color );
596 // Set the background actor before adding so that we do not inform derived classes
597 background.actor = imageActor;
598 Self().Add( imageActor );
602 void Control::ClearBackground()
604 if ( mImpl->mBackground )
606 Background& background( mImpl->GetBackground() );
607 Self().Remove( background.actor );
609 delete mImpl->mBackground;
610 mImpl->mBackground = NULL;
614 Actor Control::GetBackgroundActor() const
616 if ( mImpl->mBackground )
618 return mImpl->mBackground->actor;
624 void Control::SetKeyboardNavigationSupport(bool isSupported)
626 mImpl->mIsKeyboardNavigationSupported = isSupported;
629 bool Control::IsKeyboardNavigationSupported()
631 return mImpl->mIsKeyboardNavigationSupported;
634 void Control::Activate()
636 // Inform deriving classes
640 bool Control::OnAccessibilityPan(PanGesture gesture)
642 return false; // Accessibility pan gesture is not handled by default
645 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
647 return false; // Accessibility touch event is not handled by default
650 bool Control::OnAccessibilityValueChange(bool isIncrease)
652 return false; // Accessibility value change action is not handled by default
655 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
657 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
659 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
660 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
663 bool Control::IsKeyboardFocusGroup()
665 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
668 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
673 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
677 bool Control::DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes)
681 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_CONTROL_ACTIVATED ) ) )
683 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
686 // if cast succeeds there is an implementation so no need to check
687 control.GetImplementation().OnActivated();
694 bool Control::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
696 Dali::BaseHandle handle( object );
698 bool connected( false );
699 Toolkit::Control control = Toolkit::Control::DownCast( handle );
702 Control& controlImpl( control.GetImplementation() );
705 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
707 controlImpl.KeyEventSignal().Connect( tracker, functor );
709 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
711 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
713 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
715 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
717 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
719 controlImpl.EnableGestureDetection( Gesture::Tap );
720 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
722 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
724 controlImpl.EnableGestureDetection( Gesture::Pan );
725 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
727 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
729 controlImpl.EnableGestureDetection( Gesture::Pinch );
730 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
732 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
734 controlImpl.EnableGestureDetection( Gesture::LongPress );
735 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
739 // signalName does not match any signal
746 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
748 return mImpl->mKeyEventSignal;
751 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusGainedSignal()
753 return mImpl->mKeyInputFocusGainedSignal;
756 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusLostSignal()
758 return mImpl->mKeyInputFocusLostSignal;
761 bool Control::EmitKeyEventSignal( const KeyEvent& event )
763 // Guard against destruction during signal emission
764 Dali::Toolkit::Control handle( GetOwner() );
766 bool consumed = false;
768 // signals are allocated dynamically when someone connects
769 if ( !mImpl->mKeyEventSignal.Empty() )
771 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
776 // Notification for derived classes
777 consumed = OnKeyEvent(event);
783 Control::Control( ControlBehaviour behaviourFlags )
784 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
785 mImpl(new Impl(*this))
787 mImpl->mFlags = behaviourFlags;
790 void Control::Initialize()
792 // Calling deriving classes
795 if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
797 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
799 // Register for style changes
800 styleManager.StyleChangeSignal().Connect( this, &Control::OnStyleChange );
803 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
806 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
808 SetKeyboardNavigationSupport( true );
811 mImpl->mInitialized = true;
814 void Control::EnableGestureDetection(Gesture::Type type)
816 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
818 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
819 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
820 mImpl->mPinchGestureDetector.Attach(Self());
823 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
825 mImpl->mPanGestureDetector = PanGestureDetector::New();
826 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
827 mImpl->mPanGestureDetector.Attach(Self());
830 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
832 mImpl->mTapGestureDetector = TapGestureDetector::New();
833 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
834 mImpl->mTapGestureDetector.Attach(Self());
837 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
839 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
840 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
841 mImpl->mLongPressGestureDetector.Attach(Self());
845 void Control::DisableGestureDetection(Gesture::Type type)
847 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
849 mImpl->mPinchGestureDetector.Detach(Self());
850 mImpl->mPinchGestureDetector.Reset();
853 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
855 mImpl->mPanGestureDetector.Detach(Self());
856 mImpl->mPanGestureDetector.Reset();
859 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
861 mImpl->mTapGestureDetector.Detach(Self());
862 mImpl->mTapGestureDetector.Reset();
865 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
867 mImpl->mLongPressGestureDetector.Detach(Self());
868 mImpl->mLongPressGestureDetector.Reset();
872 void Control::OnInitialize()
876 void Control::OnActivated()
880 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange change )
882 // By default the control is only interested in theme (not font) changes
883 if( change.themeChange )
885 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
889 void Control::OnPinch(const PinchGesture& pinch)
891 if( !( mImpl->mStartingPinchScale ) )
894 mImpl->mStartingPinchScale = new Vector3;
897 if( pinch.state == Gesture::Started )
899 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
902 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
905 void Control::OnPan( const PanGesture& pan )
909 void Control::OnTap(const TapGesture& tap)
913 void Control::OnLongPress( const LongPressGesture& longPress )
917 void Control::OnControlStageConnection()
921 void Control::OnControlStageDisconnection()
925 void Control::OnControlChildAdd( Actor& child )
929 void Control::OnControlChildRemove( Actor& child )
933 void Control::OnControlSizeSet( const Vector3& size )
937 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
941 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
945 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
947 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
949 container.Add( Self().GetChildAt( i ), size );
953 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
957 void Control::EmitKeyInputFocusSignal( bool focusGained )
959 Dali::Toolkit::Control handle( GetOwner() );
963 // signals are allocated dynamically when someone connects
964 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
966 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
971 // signals are allocated dynamically when someone connects
972 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
974 mImpl->mKeyInputFocusLostSignal.Emit( handle );
979 void Control::OnKeyInputFocusGained()
981 EmitKeyInputFocusSignal( true );
984 void Control::OnKeyInputFocusLost()
986 EmitKeyInputFocusSignal( false );
989 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
991 // @todo consider animating negotiated child sizes to target size
994 bool Control::OnTouchEvent(const TouchEvent& event)
996 return false; // Do not consume
999 bool Control::OnHoverEvent(const HoverEvent& event)
1001 return false; // Do not consume
1004 bool Control::OnKeyEvent(const KeyEvent& event)
1006 return false; // Do not consume
1009 bool Control::OnMouseWheelEvent(const MouseWheelEvent& event)
1011 return false; // Do not consume
1014 void Control::OnStageConnection()
1016 // Notify derived classes.
1017 OnControlStageConnection();
1020 void Control::OnStageDisconnection()
1022 // Notify derived classes
1023 OnControlStageDisconnection();
1026 void Control::OnChildAdd(Actor& child)
1028 // If this is the background actor, then we do not want to relayout or inform deriving classes
1029 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
1034 // Notify derived classes.
1035 OnControlChildAdd( child );
1038 void Control::OnChildRemove(Actor& child)
1040 // If this is the background actor, then we do not want to relayout or inform deriving classes
1041 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
1046 // Notify derived classes.
1047 OnControlChildRemove( child );
1050 void Control::OnSizeSet(const Vector3& targetSize)
1052 if( targetSize != mImpl->mNaturalSize )
1054 // Only updates size if set through Actor's API
1055 mImpl->mNaturalSize = targetSize;
1058 if( targetSize != mImpl->mCurrentSize )
1060 // Update control size.
1061 mImpl->mCurrentSize = targetSize;
1063 // Notify derived classes.
1064 OnControlSizeSet( targetSize );
1068 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1070 mImpl->SignalConnected( slotObserver, callback );
1073 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1075 mImpl->SignalDisconnected( slotObserver, callback );
1078 } // namespace Internal
1080 } // namespace Toolkit