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] constrainingIndex The property index to constrain the parent's size on.
134 * @param[in] color The required color of the actor.
136 void SetupBackgroundActor( Actor actor, Property::Index constrainingIndex, 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.SetRelayoutEnabled( false );
144 Constraint constraint = Constraint::New<Vector3>( actor,
146 EqualToConstraint() );
147 constraint.AddSource( ParentSource( Actor::Property::SIZE ) );
151 } // unnamed namespace
156 class Control::Impl : public ConnectionTracker
161 * Size indices for mMinMaxSize array
170 // Construction & Destruction
171 Impl(Control& controlImpl)
172 : mControlImpl( controlImpl ),
175 mStartingPinchScale( NULL ),
177 mPinchGestureDetector(),
178 mPanGestureDetector(),
179 mTapGestureDetector(),
180 mLongPressGestureDetector(),
183 mFlags( Control::CONTROL_BEHAVIOUR_NONE ),
184 mIsKeyboardNavigationSupported( false ),
185 mIsKeyboardFocusGroup( false ),
186 mInitialized( false )
192 // All gesture detectors will be destroyed so no need to disconnect.
194 delete mStartingPinchScale;
197 // Gesture Detection Methods
199 void PinchDetected(Actor actor, const PinchGesture& pinch)
201 mControlImpl.OnPinch(pinch);
204 void PanDetected(Actor actor, const PanGesture& pan)
206 mControlImpl.OnPan(pan);
209 void TapDetected(Actor actor, const TapGesture& tap)
211 mControlImpl.OnTap(tap);
214 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
216 mControlImpl.OnLongPress(longPress);
219 // Background Methods
222 * Only creates an instance of the background if we actually use it.
223 * @return A reference to the Background structure.
225 Background& GetBackground()
229 mBackground = new Background;
237 * Called when a property of an object of this type is set.
238 * @param[in] object The object whose property is set.
239 * @param[in] index The property index.
240 * @param[in] value The new property value.
242 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
244 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
248 Control& controlImpl( control.GetImplementation() );
252 case Toolkit::Control::Property::STYLE_NAME:
254 controlImpl.SetStyleName( value.Get< std::string >() );
258 case Toolkit::Control::Property::BACKGROUND_COLOR:
260 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
264 case Toolkit::Control::Property::BACKGROUND_IMAGE:
266 if ( value.HasKey( "image" ) )
268 Property::Map imageMap = value.GetValue( "image" ).Get< Property::Map >();
269 Image image = Scripting::NewImage( imageMap );
273 controlImpl.SetBackgroundImage( image );
276 else if ( value.Get< Property::Map >().Empty() )
278 // An empty map means the background is no longer required
279 controlImpl.ClearBackground();
284 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
286 if ( value.Get< bool >() )
288 controlImpl.SetKeyInputFocus();
292 controlImpl.ClearKeyInputFocus();
301 * Called to retrieve a property of an object of this type.
302 * @param[in] object The object whose property is to be retrieved.
303 * @param[in] index The property index.
304 * @return The current value of the property.
306 static Property::Value GetProperty( BaseObject* object, Property::Index index )
308 Property::Value value;
310 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
314 Control& controlImpl( control.GetImplementation() );
318 case Toolkit::Control::Property::STYLE_NAME:
320 value = controlImpl.GetStyleName();
324 case Toolkit::Control::Property::BACKGROUND_COLOR:
326 value = controlImpl.GetBackgroundColor();
330 case Toolkit::Control::Property::BACKGROUND_IMAGE:
334 Actor actor = controlImpl.GetBackgroundActor();
337 ImageActor imageActor = ImageActor::DownCast( actor );
340 Image image = imageActor.GetImage();
341 Property::Map imageMap;
342 Scripting::CreatePropertyMap( image, imageMap );
343 map[ "image" ] = imageMap;
351 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
353 value = controlImpl.HasKeyInputFocus();
364 Control& mControlImpl;
365 std::string mStyleName;
366 Background* mBackground; ///< Only create the background if we use it
367 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
368 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
371 PinchGestureDetector mPinchGestureDetector;
372 PanGestureDetector mPanGestureDetector;
373 TapGestureDetector mTapGestureDetector;
374 LongPressGestureDetector mLongPressGestureDetector;
375 // @todo change all these to Vector2 when we have a chance to sanitize the public API as well
376 Vector3 mCurrentSize; ///< Stores the current control's size, this is the negotiated size
377 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.
379 ControlBehaviour mFlags :6; ///< Flags passed in from constructor. Need to increase this size when new enums are added
380 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
381 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
382 bool mInitialized :1;
384 // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
385 static PropertyRegistration PROPERTY_1;
386 static PropertyRegistration PROPERTY_2;
387 static PropertyRegistration PROPERTY_3;
388 static PropertyRegistration PROPERTY_4;
391 // Properties registered without macro to use specific member variables.
392 PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "style-name", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
393 PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "background-color", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
394 PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "background-image", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
395 PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "key-input-focus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
397 Toolkit::Control Control::New()
399 // Create the implementation, temporarily owned on stack
400 IntrusivePtr<Control> controlImpl = new Control( CONTROL_BEHAVIOUR_NONE );
402 // Pass ownership to handle
403 Toolkit::Control handle( *controlImpl );
405 // Second-phase init of the implementation
406 // This can only be done after the CustomActor connection has been made...
407 controlImpl->Initialize();
417 Vector3 Control::GetNaturalSize()
419 // could be overridden in derived classes.
420 return mImpl->mNaturalSize;
423 float Control::CalculateChildSize( const Dali::Actor& child, Dimension dimension )
425 // Could be overridden in derived classes.
426 return CalculateChildSizeBase( child, dimension );
429 bool Control::RelayoutDependentOnChildren( Dimension dimension )
431 return RelayoutDependentOnChildrenBase( dimension );
434 float Control::GetHeightForWidth( float width )
436 // could be overridden in derived classes.
437 float height( 0.0f );
438 if ( mImpl->mNaturalSize.width > 0.0f )
440 height = mImpl->mNaturalSize.height * width / mImpl->mNaturalSize.width;
445 float Control::GetWidthForHeight( float height )
447 // could be overridden in derived classes.
449 if ( mImpl->mNaturalSize.height > 0.0f )
451 width = mImpl->mNaturalSize.width * height / mImpl->mNaturalSize.height;
456 const Vector3& Control::GetControlSize() const
458 return mImpl->mCurrentSize;
461 const Vector3& Control::GetSizeSet() const
463 return mImpl->mNaturalSize;
466 void Control::SetKeyInputFocus()
468 if( Self().OnStage() )
470 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
474 bool Control::HasKeyInputFocus()
477 if( Self().OnStage() )
479 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
484 void Control::ClearKeyInputFocus()
486 if( Self().OnStage() )
488 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
492 PinchGestureDetector Control::GetPinchGestureDetector() const
494 return mImpl->mPinchGestureDetector;
497 PanGestureDetector Control::GetPanGestureDetector() const
499 return mImpl->mPanGestureDetector;
502 TapGestureDetector Control::GetTapGestureDetector() const
504 return mImpl->mTapGestureDetector;
507 LongPressGestureDetector Control::GetLongPressGestureDetector() const
509 return mImpl->mLongPressGestureDetector;
512 void Control::SetStyleName( const std::string& styleName )
514 if( styleName != mImpl->mStyleName )
516 mImpl->mStyleName = styleName;
519 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
520 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
524 const std::string& Control::GetStyleName() const
526 return mImpl->mStyleName;
529 void Control::SetBackgroundColor( const Vector4& color )
531 Background& background( mImpl->GetBackground() );
533 if ( background.actor )
535 // Just set the actor color
536 background.actor.SetColor( color );
541 MeshActor meshActor = MeshActor::New( CreateMesh() );
543 SetupBackgroundActor( meshActor, Actor::Property::SCALE, color );
545 // Set the background actor before adding so that we do not inform deriving classes
546 background.actor = meshActor;
547 Self().Add( meshActor );
550 background.color = color;
553 Vector4 Control::GetBackgroundColor() const
555 if ( mImpl->mBackground )
557 return mImpl->mBackground->color;
559 return Color::TRANSPARENT;
562 void Control::SetBackgroundImage( Image image )
564 Background& background( mImpl->GetBackground() );
566 if ( background.actor )
568 // Remove Current actor, unset AFTER removal so that we do not inform deriving classes
569 Self().Remove( background.actor );
570 background.actor.Reset();
573 ImageActor imageActor = ImageActor::New( image );
574 SetupBackgroundActor( imageActor, Actor::Property::SIZE, background.color );
576 // Set the background actor before adding so that we do not inform derived classes
577 background.actor = imageActor;
578 Self().Add( imageActor );
581 void Control::ClearBackground()
583 if ( mImpl->mBackground )
585 Background& background( mImpl->GetBackground() );
586 Self().Remove( background.actor );
588 delete mImpl->mBackground;
589 mImpl->mBackground = NULL;
593 Actor Control::GetBackgroundActor() const
595 if ( mImpl->mBackground )
597 return mImpl->mBackground->actor;
603 void Control::SetKeyboardNavigationSupport(bool isSupported)
605 mImpl->mIsKeyboardNavigationSupported = isSupported;
608 bool Control::IsKeyboardNavigationSupported()
610 return mImpl->mIsKeyboardNavigationSupported;
613 void Control::Activate()
615 // Inform deriving classes
619 bool Control::OnAccessibilityPan(PanGesture gesture)
621 return false; // Accessibility pan gesture is not handled by default
624 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
626 return false; // Accessibility touch event is not handled by default
629 bool Control::OnAccessibilityValueChange(bool isIncrease)
631 return false; // Accessibility value change action is not handled by default
634 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
636 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
638 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
639 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
642 bool Control::IsKeyboardFocusGroup()
644 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
647 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
652 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
656 bool Control::DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes)
660 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_CONTROL_ACTIVATED ) ) )
662 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
665 // if cast succeeds there is an implementation so no need to check
666 control.GetImplementation().OnActivated();
673 bool Control::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
675 Dali::BaseHandle handle( object );
677 bool connected( false );
678 Toolkit::Control control = Toolkit::Control::DownCast( handle );
681 Control& controlImpl( control.GetImplementation() );
684 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
686 controlImpl.KeyEventSignal().Connect( tracker, functor );
688 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
690 controlImpl.EnableGestureDetection( Gesture::Tap );
691 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
693 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
695 controlImpl.EnableGestureDetection( Gesture::Pan );
696 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
698 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
700 controlImpl.EnableGestureDetection( Gesture::Pinch );
701 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
703 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
705 controlImpl.EnableGestureDetection( Gesture::LongPress );
706 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
710 // signalName does not match any signal
717 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
719 return mImpl->mKeyEventSignal;
722 bool Control::EmitKeyEventSignal( const KeyEvent& event )
724 // Guard against destruction during signal emission
725 Dali::Toolkit::Control handle( GetOwner() );
727 bool consumed = false;
729 // signals are allocated dynamically when someone connects
730 if ( !mImpl->mKeyEventSignal.Empty() )
732 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
737 // Notification for derived classes
738 consumed = OnKeyEvent(event);
744 Control::Control( ControlBehaviour behaviourFlags )
745 : CustomActorImpl( behaviourFlags & REQUIRES_TOUCH_EVENTS ),
746 mImpl(new Impl(*this))
748 mImpl->mFlags = behaviourFlags;
751 void Control::Initialize()
753 // Calling deriving classes
756 // Test if the no size negotiation flag is not set
757 if( ( mImpl->mFlags & NO_SIZE_NEGOTIATION ) == 0 )
759 // Size negotiate disabled by default, so turn it on for this actor
760 Self().SetRelayoutEnabled( true );
763 if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
765 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
767 // Register for style changes
768 styleManager.StyleChangeSignal().Connect( this, &Control::OnStyleChange );
771 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
774 SetRequiresHoverEvents(mImpl->mFlags & REQUIRES_HOVER_EVENTS);
775 SetRequiresMouseWheelEvents(mImpl->mFlags & REQUIRES_MOUSE_WHEEL_EVENTS);
777 mImpl->mInitialized = true;
780 void Control::EnableGestureDetection(Gesture::Type type)
782 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
784 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
785 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
786 mImpl->mPinchGestureDetector.Attach(Self());
789 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
791 mImpl->mPanGestureDetector = PanGestureDetector::New();
792 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
793 mImpl->mPanGestureDetector.Attach(Self());
796 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
798 mImpl->mTapGestureDetector = TapGestureDetector::New();
799 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
800 mImpl->mTapGestureDetector.Attach(Self());
803 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
805 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
806 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
807 mImpl->mLongPressGestureDetector.Attach(Self());
811 void Control::DisableGestureDetection(Gesture::Type type)
813 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
815 mImpl->mPinchGestureDetector.Detach(Self());
816 mImpl->mPinchGestureDetector.Reset();
819 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
821 mImpl->mPanGestureDetector.Detach(Self());
822 mImpl->mPanGestureDetector.Reset();
825 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
827 mImpl->mTapGestureDetector.Detach(Self());
828 mImpl->mTapGestureDetector.Reset();
831 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
833 mImpl->mLongPressGestureDetector.Detach(Self());
834 mImpl->mLongPressGestureDetector.Reset();
838 void Control::OnInitialize()
842 void Control::OnActivated()
846 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange change )
848 // By default the control is only interested in theme (not font) changes
849 if( change.themeChange )
851 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
855 void Control::OnPinch(const PinchGesture& pinch)
857 if( !( mImpl->mStartingPinchScale ) )
860 mImpl->mStartingPinchScale = new Vector3;
863 if( pinch.state == Gesture::Started )
865 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
868 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
871 void Control::OnPan( const PanGesture& pan )
875 void Control::OnTap(const TapGesture& tap)
879 void Control::OnLongPress( const LongPressGesture& longPress )
883 void Control::OnControlStageConnection()
887 void Control::OnControlStageDisconnection()
891 void Control::OnControlChildAdd( Actor& child )
895 void Control::OnControlChildRemove( Actor& child )
899 void Control::OnControlSizeSet( const Vector3& size )
903 void Control::OnCalculateRelayoutSize( Dimension dimension )
907 void Control::OnLayoutNegotiated( float size, Dimension dimension )
911 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
913 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
915 container.Add( Self().GetChildAt( i ), size );
919 void Control::OnSetResizePolicy( ResizePolicy policy, Dimension dimension )
923 void Control::OnKeyInputFocusGained()
928 void Control::OnKeyInputFocusLost()
933 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
935 // @todo consider animating negotiated child sizes to target size
938 bool Control::OnTouchEvent(const TouchEvent& event)
940 return false; // Do not consume
943 bool Control::OnHoverEvent(const HoverEvent& event)
945 return false; // Do not consume
948 bool Control::OnKeyEvent(const KeyEvent& event)
950 return false; // Do not consume
953 bool Control::OnMouseWheelEvent(const MouseWheelEvent& event)
955 return false; // Do not consume
958 void Control::OnStageConnection()
960 // Notify derived classes.
961 OnControlStageConnection();
964 void Control::OnStageDisconnection()
966 // Notify derived classes
967 OnControlStageDisconnection();
970 void Control::OnChildAdd(Actor& child)
972 // If this is the background actor, then we do not want to relayout or inform deriving classes
973 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
978 // Notify derived classes.
979 OnControlChildAdd( child );
982 void Control::OnChildRemove(Actor& child)
984 // If this is the background actor, then we do not want to relayout or inform deriving classes
985 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
990 // Notify derived classes.
991 OnControlChildRemove( child );
994 void Control::OnSizeSet(const Vector3& targetSize)
996 if( targetSize != mImpl->mNaturalSize )
998 // Only updates size if set through Actor's API
999 mImpl->mNaturalSize = targetSize;
1002 if( targetSize != mImpl->mCurrentSize )
1004 // Update control size.
1005 mImpl->mCurrentSize = targetSize;
1007 // Notify derived classes.
1008 OnControlSizeSet( targetSize );
1012 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1014 mImpl->SignalConnected( slotObserver, callback );
1017 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1019 mImpl->SignalDisconnected( slotObserver, callback );
1022 } // namespace Internal
1024 } // namespace Toolkit