2 * Copyright (c) 2014 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, "tapped", SIGNAL_TAPPED )
72 DALI_SIGNAL_REGISTRATION( Control, "panned", SIGNAL_PANNED )
73 DALI_SIGNAL_REGISTRATION( Control, "pinched", SIGNAL_PINCHED )
74 DALI_SIGNAL_REGISTRATION( Control, "long-pressed", SIGNAL_LONG_PRESSED )
76 DALI_ACTION_REGISTRATION( 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 );
126 return Mesh::New( meshData );
130 * Sets all the required properties for the background actor.
132 * @param[in] actor The actor to set the properties on.
133 * @param[in] color The required color of the actor.
135 void SetupBackgroundActor( Actor actor, const Vector4& color )
137 actor.SetColor( color );
138 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
139 actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
140 actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
141 actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
145 * Sets all the required properties for the background actor.
147 * @param[in] actor The actor to set the properties on.
148 * @param[in] constrainingIndex The property index to constrain the parent's size on.
149 * @param[in] color The required color of the actor.
151 void SetupBackgroundActorConstrained( Actor actor, Property::Index constrainingIndex, const Vector4& color )
153 actor.SetColor( color );
154 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
155 actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
156 actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
158 Constraint constraint = Constraint::New<Vector3>( actor,
160 EqualToConstraint() );
161 constraint.AddSource( ParentSource( Actor::Property::SIZE ) );
165 } // unnamed namespace
170 class Control::Impl : public ConnectionTracker
175 * Size indices for mMinMaxSize array
184 // Construction & Destruction
185 Impl(Control& controlImpl)
186 : mControlImpl( controlImpl ),
189 mStartingPinchScale( NULL ),
191 mPinchGestureDetector(),
192 mPanGestureDetector(),
193 mTapGestureDetector(),
194 mLongPressGestureDetector(),
197 mFlags( Control::ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ),
198 mIsKeyboardNavigationSupported( false ),
199 mIsKeyboardFocusGroup( false ),
200 mInitialized( false )
206 // All gesture detectors will be destroyed so no need to disconnect.
208 delete mStartingPinchScale;
211 // Gesture Detection Methods
213 void PinchDetected(Actor actor, const PinchGesture& pinch)
215 mControlImpl.OnPinch(pinch);
218 void PanDetected(Actor actor, const PanGesture& pan)
220 mControlImpl.OnPan(pan);
223 void TapDetected(Actor actor, const TapGesture& tap)
225 mControlImpl.OnTap(tap);
228 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
230 mControlImpl.OnLongPress(longPress);
233 // Background Methods
236 * Only creates an instance of the background if we actually use it.
237 * @return A reference to the Background structure.
239 Background& GetBackground()
243 mBackground = new Background;
251 * Called when a property of an object of this type is set.
252 * @param[in] object The object whose property is set.
253 * @param[in] index The property index.
254 * @param[in] value The new property value.
256 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
258 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
262 Control& controlImpl( control.GetImplementation() );
266 case Toolkit::Control::Property::STYLE_NAME:
268 controlImpl.SetStyleName( value.Get< std::string >() );
272 case Toolkit::Control::Property::BACKGROUND_COLOR:
274 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
278 case Toolkit::Control::Property::BACKGROUND_IMAGE:
280 if ( value.HasKey( "image" ) )
282 Property::Map imageMap = value.GetValue( "image" ).Get< Property::Map >();
283 Image image = Scripting::NewImage( imageMap );
287 controlImpl.SetBackgroundImage( image );
290 else if ( value.Get< Property::Map >().Empty() )
292 // An empty map means the background is no longer required
293 controlImpl.ClearBackground();
298 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
300 if ( value.Get< bool >() )
302 controlImpl.SetKeyInputFocus();
306 controlImpl.ClearKeyInputFocus();
315 * Called to retrieve a property of an object of this type.
316 * @param[in] object The object whose property is to be retrieved.
317 * @param[in] index The property index.
318 * @return The current value of the property.
320 static Property::Value GetProperty( BaseObject* object, Property::Index index )
322 Property::Value value;
324 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
328 Control& controlImpl( control.GetImplementation() );
332 case Toolkit::Control::Property::STYLE_NAME:
334 value = controlImpl.GetStyleName();
338 case Toolkit::Control::Property::BACKGROUND_COLOR:
340 value = controlImpl.GetBackgroundColor();
344 case Toolkit::Control::Property::BACKGROUND_IMAGE:
348 Actor actor = controlImpl.GetBackgroundActor();
351 ImageActor imageActor = ImageActor::DownCast( actor );
354 Image image = imageActor.GetImage();
355 Property::Map imageMap;
356 Scripting::CreatePropertyMap( image, imageMap );
357 map[ "image" ] = imageMap;
365 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
367 value = controlImpl.HasKeyInputFocus();
378 Control& mControlImpl;
379 std::string mStyleName;
380 Background* mBackground; ///< Only create the background if we use it
381 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
382 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
385 PinchGestureDetector mPinchGestureDetector;
386 PanGestureDetector mPanGestureDetector;
387 TapGestureDetector mTapGestureDetector;
388 LongPressGestureDetector mLongPressGestureDetector;
389 // @todo change all these to Vector2 when we have a chance to sanitize the public API as well
390 Vector3 mCurrentSize; ///< Stores the current control's size, this is the negotiated size
391 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.
393 ControlBehaviour mFlags :CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
394 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
395 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
396 bool mInitialized :1;
398 // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
399 static PropertyRegistration PROPERTY_1;
400 static PropertyRegistration PROPERTY_2;
401 static PropertyRegistration PROPERTY_3;
402 static PropertyRegistration PROPERTY_4;
405 // Properties registered without macro to use specific member variables.
406 PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "style-name", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
407 PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "background-color", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
408 PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "background-image", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
409 PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "key-input-focus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
411 Toolkit::Control Control::New()
413 // Create the implementation, temporarily owned on stack
414 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) );
416 // Pass ownership to handle
417 Toolkit::Control handle( *controlImpl );
419 // Second-phase init of the implementation
420 // This can only be done after the CustomActor connection has been made...
421 controlImpl->Initialize();
431 Vector3 Control::GetNaturalSize()
433 // could be overridden in derived classes.
434 return mImpl->mNaturalSize;
437 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
439 // Could be overridden in derived classes.
440 return CalculateChildSizeBase( child, dimension );
443 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
445 return RelayoutDependentOnChildrenBase( dimension );
448 float Control::GetHeightForWidth( float width )
450 // could be overridden in derived classes.
451 float height( 0.0f );
452 if ( mImpl->mNaturalSize.width > 0.0f )
454 height = mImpl->mNaturalSize.height * width / mImpl->mNaturalSize.width;
459 float Control::GetWidthForHeight( float height )
461 // could be overridden in derived classes.
463 if ( mImpl->mNaturalSize.height > 0.0f )
465 width = mImpl->mNaturalSize.width * height / mImpl->mNaturalSize.height;
470 const Vector3& Control::GetControlSize() const
472 return mImpl->mCurrentSize;
475 const Vector3& Control::GetSizeSet() const
477 return mImpl->mNaturalSize;
480 void Control::SetKeyInputFocus()
482 if( Self().OnStage() )
484 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
488 bool Control::HasKeyInputFocus()
491 if( Self().OnStage() )
493 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
498 void Control::ClearKeyInputFocus()
500 if( Self().OnStage() )
502 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
506 PinchGestureDetector Control::GetPinchGestureDetector() const
508 return mImpl->mPinchGestureDetector;
511 PanGestureDetector Control::GetPanGestureDetector() const
513 return mImpl->mPanGestureDetector;
516 TapGestureDetector Control::GetTapGestureDetector() const
518 return mImpl->mTapGestureDetector;
521 LongPressGestureDetector Control::GetLongPressGestureDetector() const
523 return mImpl->mLongPressGestureDetector;
526 void Control::SetStyleName( const std::string& styleName )
528 if( styleName != mImpl->mStyleName )
530 mImpl->mStyleName = styleName;
533 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
534 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
538 const std::string& Control::GetStyleName() const
540 return mImpl->mStyleName;
543 void Control::SetBackgroundColor( const Vector4& color )
545 Background& background( mImpl->GetBackground() );
547 if ( background.actor )
549 // Just set the actor color
550 background.actor.SetColor( color );
555 MeshActor meshActor = MeshActor::New( CreateMesh() );
557 SetupBackgroundActorConstrained( meshActor, Actor::Property::SCALE, color );
559 // Set the background actor before adding so that we do not inform deriving classes
560 background.actor = meshActor;
561 Self().Add( meshActor );
564 background.color = color;
567 Vector4 Control::GetBackgroundColor() const
569 if ( mImpl->mBackground )
571 return mImpl->mBackground->color;
573 return Color::TRANSPARENT;
576 void Control::SetBackgroundImage( Image image )
578 Background& background( mImpl->GetBackground() );
580 if ( background.actor )
582 // Remove Current actor, unset AFTER removal so that we do not inform deriving classes
583 Self().Remove( background.actor );
584 background.actor.Reset();
587 ImageActor imageActor = ImageActor::New( image );
588 SetupBackgroundActor( imageActor, background.color );
590 // Set the background actor before adding so that we do not inform derived classes
591 background.actor = imageActor;
592 Self().Add( imageActor );
595 void Control::ClearBackground()
597 if ( mImpl->mBackground )
599 Background& background( mImpl->GetBackground() );
600 Self().Remove( background.actor );
602 delete mImpl->mBackground;
603 mImpl->mBackground = NULL;
607 Actor Control::GetBackgroundActor() const
609 if ( mImpl->mBackground )
611 return mImpl->mBackground->actor;
617 void Control::SetKeyboardNavigationSupport(bool isSupported)
619 mImpl->mIsKeyboardNavigationSupported = isSupported;
622 bool Control::IsKeyboardNavigationSupported()
624 return mImpl->mIsKeyboardNavigationSupported;
627 void Control::Activate()
629 // Inform deriving classes
633 bool Control::OnAccessibilityPan(PanGesture gesture)
635 return false; // Accessibility pan gesture is not handled by default
638 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
640 return false; // Accessibility touch event is not handled by default
643 bool Control::OnAccessibilityValueChange(bool isIncrease)
645 return false; // Accessibility value change action is not handled by default
648 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
650 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
652 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
653 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
656 bool Control::IsKeyboardFocusGroup()
658 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
661 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
666 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
670 bool Control::DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes)
674 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_CONTROL_ACTIVATED ) ) )
676 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
679 // if cast succeeds there is an implementation so no need to check
680 control.GetImplementation().OnActivated();
687 bool Control::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
689 Dali::BaseHandle handle( object );
691 bool connected( false );
692 Toolkit::Control control = Toolkit::Control::DownCast( handle );
695 Control& controlImpl( control.GetImplementation() );
698 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
700 controlImpl.KeyEventSignal().Connect( tracker, functor );
702 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
704 controlImpl.EnableGestureDetection( Gesture::Tap );
705 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
707 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
709 controlImpl.EnableGestureDetection( Gesture::Pan );
710 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
712 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
714 controlImpl.EnableGestureDetection( Gesture::Pinch );
715 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
717 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
719 controlImpl.EnableGestureDetection( Gesture::LongPress );
720 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
724 // signalName does not match any signal
731 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
733 return mImpl->mKeyEventSignal;
736 bool Control::EmitKeyEventSignal( const KeyEvent& event )
738 // Guard against destruction during signal emission
739 Dali::Toolkit::Control handle( GetOwner() );
741 bool consumed = false;
743 // signals are allocated dynamically when someone connects
744 if ( !mImpl->mKeyEventSignal.Empty() )
746 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
751 // Notification for derived classes
752 consumed = OnKeyEvent(event);
758 Control::Control( ControlBehaviour behaviourFlags )
759 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
760 mImpl(new Impl(*this))
762 mImpl->mFlags = behaviourFlags;
765 void Control::Initialize()
767 // Calling deriving classes
770 if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
772 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
774 // Register for style changes
775 styleManager.StyleChangeSignal().Connect( this, &Control::OnStyleChange );
778 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
781 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
783 SetKeyboardNavigationSupport( true );
786 mImpl->mInitialized = true;
789 void Control::EnableGestureDetection(Gesture::Type type)
791 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
793 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
794 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
795 mImpl->mPinchGestureDetector.Attach(Self());
798 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
800 mImpl->mPanGestureDetector = PanGestureDetector::New();
801 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
802 mImpl->mPanGestureDetector.Attach(Self());
805 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
807 mImpl->mTapGestureDetector = TapGestureDetector::New();
808 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
809 mImpl->mTapGestureDetector.Attach(Self());
812 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
814 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
815 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
816 mImpl->mLongPressGestureDetector.Attach(Self());
820 void Control::DisableGestureDetection(Gesture::Type type)
822 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
824 mImpl->mPinchGestureDetector.Detach(Self());
825 mImpl->mPinchGestureDetector.Reset();
828 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
830 mImpl->mPanGestureDetector.Detach(Self());
831 mImpl->mPanGestureDetector.Reset();
834 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
836 mImpl->mTapGestureDetector.Detach(Self());
837 mImpl->mTapGestureDetector.Reset();
840 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
842 mImpl->mLongPressGestureDetector.Detach(Self());
843 mImpl->mLongPressGestureDetector.Reset();
847 void Control::OnInitialize()
851 void Control::OnActivated()
855 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange change )
857 // By default the control is only interested in theme (not font) changes
858 if( change.themeChange )
860 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
864 void Control::OnPinch(const PinchGesture& pinch)
866 if( !( mImpl->mStartingPinchScale ) )
869 mImpl->mStartingPinchScale = new Vector3;
872 if( pinch.state == Gesture::Started )
874 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
877 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
880 void Control::OnPan( const PanGesture& pan )
884 void Control::OnTap(const TapGesture& tap)
888 void Control::OnLongPress( const LongPressGesture& longPress )
892 void Control::OnControlStageConnection()
896 void Control::OnControlStageDisconnection()
900 void Control::OnControlChildAdd( Actor& child )
904 void Control::OnControlChildRemove( Actor& child )
908 void Control::OnControlSizeSet( const Vector3& size )
912 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
916 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
920 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
922 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
924 container.Add( Self().GetChildAt( i ), size );
928 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
932 void Control::OnKeyInputFocusGained()
937 void Control::OnKeyInputFocusLost()
942 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
944 // @todo consider animating negotiated child sizes to target size
947 bool Control::OnTouchEvent(const TouchEvent& event)
949 return false; // Do not consume
952 bool Control::OnHoverEvent(const HoverEvent& event)
954 return false; // Do not consume
957 bool Control::OnKeyEvent(const KeyEvent& event)
959 return false; // Do not consume
962 bool Control::OnMouseWheelEvent(const MouseWheelEvent& event)
964 return false; // Do not consume
967 void Control::OnStageConnection()
969 // Notify derived classes.
970 OnControlStageConnection();
973 void Control::OnStageDisconnection()
975 // Notify derived classes
976 OnControlStageDisconnection();
979 void Control::OnChildAdd(Actor& child)
981 // If this is the background actor, then we do not want to relayout or inform deriving classes
982 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
987 // Notify derived classes.
988 OnControlChildAdd( child );
991 void Control::OnChildRemove(Actor& child)
993 // If this is the background actor, then we do not want to relayout or inform deriving classes
994 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
999 // Notify derived classes.
1000 OnControlChildRemove( child );
1003 void Control::OnSizeSet(const Vector3& targetSize)
1005 if( targetSize != mImpl->mNaturalSize )
1007 // Only updates size if set through Actor's API
1008 mImpl->mNaturalSize = targetSize;
1011 if( targetSize != mImpl->mCurrentSize )
1013 // Update control size.
1014 mImpl->mCurrentSize = targetSize;
1016 // Notify derived classes.
1017 OnControlSizeSet( targetSize );
1021 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1023 mImpl->SignalConnected( slotObserver, callback );
1026 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1028 mImpl->SignalDisconnected( slotObserver, callback );
1031 } // namespace Internal
1033 } // namespace Toolkit