2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/public-api/controls/control-impl.h>
22 #include <cstring> // for strcmp
25 #include <dali/public-api/actors/image-actor.h>
26 #include <dali/devel-api/actors/mesh-actor.h>
27 #include <dali/public-api/animation/constraint.h>
28 #include <dali/public-api/animation/constraints.h>
29 #include <dali/devel-api/geometry/mesh.h>
30 #include <dali/public-api/object/type-registry.h>
31 #include <dali/devel-api/object/type-registry-helper.h>
32 #include <dali/devel-api/scripting/scripting.h>
33 #include <dali/public-api/size-negotiation/relayout-container.h>
34 #include <dali/integration-api/debug.h>
37 #include <dali-toolkit/public-api/focus-manager/keyinput-focus-manager.h>
38 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
39 #include <dali-toolkit/public-api/controls/control.h>
40 #include <dali-toolkit/devel-api/styling/style-manager.h>
41 #include <dali-toolkit/internal/styling/style-manager-impl.h>
52 const float BACKGROUND_ACTOR_Z_POSITION( -0.1f );
55 * Creates control through type registry
59 return Internal::Control::New();
63 * Performs actions as requested using the action name.
64 * @param[in] object The object on which to perform the action.
65 * @param[in] actionName The action to perform.
66 * @param[in] attributes The attributes with which to perfrom this action.
67 * @return true if action has been accepted by this control
69 const char* ACTION_CONTROL_ACTIVATED = "control-activated";
70 static bool DoAction( BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes )
74 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_CONTROL_ACTIVATED ) ) )
76 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
79 // if cast succeeds there is an implementation so no need to check
80 ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
88 * Connects a callback function with the object's signals.
89 * @param[in] object The object providing the signal.
90 * @param[in] tracker Used to disconnect the signal.
91 * @param[in] signalName The signal to connect to.
92 * @param[in] functor A newly allocated FunctorDelegate.
93 * @return True if the signal was connected.
94 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
96 const char* SIGNAL_KEY_EVENT = "key-event";
97 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "key-input-focus-gained";
98 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "key-input-focus-lost";
99 const char* SIGNAL_TAPPED = "tapped";
100 const char* SIGNAL_PANNED = "panned";
101 const char* SIGNAL_PINCHED = "pinched";
102 const char* SIGNAL_LONG_PRESSED = "long-pressed";
103 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
105 Dali::BaseHandle handle( object );
107 bool connected( false );
108 Toolkit::Control control = Toolkit::Control::DownCast( handle );
111 Internal::Control& controlImpl( Internal::GetImplementation( control ) );
114 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
116 controlImpl.KeyEventSignal().Connect( tracker, functor );
118 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
120 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
122 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
124 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
126 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
128 controlImpl.EnableGestureDetection( Gesture::Tap );
129 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
131 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
133 controlImpl.EnableGestureDetection( Gesture::Pan );
134 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
136 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
138 controlImpl.EnableGestureDetection( Gesture::Pinch );
139 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
141 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
143 controlImpl.EnableGestureDetection( Gesture::LongPress );
144 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
150 // Setup signals and actions using the type-registry.
151 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
153 // Note: Properties are registered separately below.
155 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
156 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
157 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
158 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
159 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
160 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
161 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
163 TypeAction registerAction( typeRegistration, ACTION_CONTROL_ACTIVATED, &DoAction );
165 DALI_TYPE_REGISTRATION_END()
168 * Structure which holds information about the background of a control
172 Actor actor; ///< Either a MeshActor or an ImageActor
173 Vector4 color; ///< The color of the actor.
180 color( Color::WHITE )
186 * Creates a white coloured Mesh.
190 Vector3 white( Color::WHITE );
194 // Create vertices with a white color (actual color is set by actor color)
195 MeshData::VertexContainer vertices(4);
196 vertices[ 0 ] = MeshData::Vertex( Vector3( -0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
197 vertices[ 1 ] = MeshData::Vertex( Vector3( 0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
198 vertices[ 2 ] = MeshData::Vertex( Vector3( -0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
199 vertices[ 3 ] = MeshData::Vertex( Vector3( 0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
201 // Specify all the faces
202 MeshData::FaceIndices faces;
203 faces.reserve( 6 ); // 2 triangles in Quad
204 faces.push_back( 0 ); faces.push_back( 3 ); faces.push_back( 1 );
205 faces.push_back( 0 ); faces.push_back( 2 ); faces.push_back( 3 );
207 // Create the mesh data from the vertices and faces
208 meshData.SetMaterial( Material::New( "ControlMaterial" ) );
209 meshData.SetVertices( vertices );
210 meshData.SetFaceIndices( faces );
211 meshData.SetHasColor( true );
213 return Mesh::New( meshData );
217 * Sets all the required properties for the background actor.
219 * @param[in] actor The actor to set the properties on.
220 * @param[in] color The required color of the actor.
222 void SetupBackgroundActor( Actor actor, const Vector4& color )
224 actor.SetColor( color );
225 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
226 actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
227 actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
228 actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
232 * Sets all the required properties for the background actor.
234 * @param[in] actor The actor to set the properties on.
235 * @param[in] constrainingIndex The property index to constrain the parent's size on.
236 * @param[in] color The required color of the actor.
238 void SetupBackgroundActorConstrained( Actor actor, Property::Index constrainingIndex, const Vector4& color )
240 actor.SetColor( color );
241 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
242 actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
243 actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
245 Constraint constraint = Constraint::New<Vector3>( actor,
247 EqualToConstraint() );
248 constraint.AddSource( ParentSource( Actor::Property::SIZE ) );
252 } // unnamed namespace
257 class Control::Impl : public ConnectionTracker
261 // Construction & Destruction
262 Impl(Control& controlImpl)
263 : mControlImpl( controlImpl ),
266 mStartingPinchScale( NULL ),
268 mPinchGestureDetector(),
269 mPanGestureDetector(),
270 mTapGestureDetector(),
271 mLongPressGestureDetector(),
272 mFlags( Control::ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ),
273 mIsKeyboardNavigationSupported( false ),
274 mIsKeyboardFocusGroup( false )
280 // All gesture detectors will be destroyed so no need to disconnect.
282 delete mStartingPinchScale;
285 // Gesture Detection Methods
287 void PinchDetected(Actor actor, const PinchGesture& pinch)
289 mControlImpl.OnPinch(pinch);
292 void PanDetected(Actor actor, const PanGesture& pan)
294 mControlImpl.OnPan(pan);
297 void TapDetected(Actor actor, const TapGesture& tap)
299 mControlImpl.OnTap(tap);
302 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
304 mControlImpl.OnLongPress(longPress);
307 // Background Methods
310 * Only creates an instance of the background if we actually use it.
311 * @return A reference to the Background structure.
313 Background& GetBackground()
317 mBackground = new Background;
325 * Called when a property of an object of this type is set.
326 * @param[in] object The object whose property is set.
327 * @param[in] index The property index.
328 * @param[in] value The new property value.
330 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
332 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
336 Control& controlImpl( GetImplementation( control ) );
340 case Toolkit::Control::Property::STYLE_NAME:
342 controlImpl.SetStyleName( value.Get< std::string >() );
346 case Toolkit::Control::Property::BACKGROUND_COLOR:
348 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
352 case Toolkit::Control::Property::BACKGROUND_IMAGE:
354 if ( value.HasKey( "image" ) )
356 Property::Map imageMap = value.GetValue( "image" ).Get< Property::Map >();
357 Image image = Scripting::NewImage( imageMap );
361 controlImpl.SetBackgroundImage( image );
364 else if ( value.Get< Property::Map >().Empty() )
366 // An empty map means the background is no longer required
367 controlImpl.ClearBackground();
372 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
374 if ( value.Get< bool >() )
376 controlImpl.SetKeyInputFocus();
380 controlImpl.ClearKeyInputFocus();
389 * Called to retrieve a property of an object of this type.
390 * @param[in] object The object whose property is to be retrieved.
391 * @param[in] index The property index.
392 * @return The current value of the property.
394 static Property::Value GetProperty( BaseObject* object, Property::Index index )
396 Property::Value value;
398 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
402 Control& controlImpl( GetImplementation( control ) );
406 case Toolkit::Control::Property::STYLE_NAME:
408 value = controlImpl.GetStyleName();
412 case Toolkit::Control::Property::BACKGROUND_COLOR:
414 value = controlImpl.GetBackgroundColor();
418 case Toolkit::Control::Property::BACKGROUND_IMAGE:
422 Background* back = controlImpl.mImpl->mBackground;
425 ImageActor imageActor = ImageActor::DownCast( back->actor );
428 Image image = imageActor.GetImage();
429 Property::Map imageMap;
430 Scripting::CreatePropertyMap( image, imageMap );
431 map[ "image" ] = imageMap;
439 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
441 value = controlImpl.HasKeyInputFocus();
452 Control& mControlImpl;
453 std::string mStyleName;
454 Background* mBackground; ///< Only create the background if we use it
455 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
456 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
457 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
458 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
461 PinchGestureDetector mPinchGestureDetector;
462 PanGestureDetector mPanGestureDetector;
463 TapGestureDetector mTapGestureDetector;
464 LongPressGestureDetector mLongPressGestureDetector;
466 ControlBehaviour mFlags :CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
467 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
468 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
470 // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
471 static PropertyRegistration PROPERTY_1;
472 static PropertyRegistration PROPERTY_2;
473 static PropertyRegistration PROPERTY_3;
474 static PropertyRegistration PROPERTY_4;
477 // Properties registered without macro to use specific member variables.
478 PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "style-name", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
479 PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "background-color", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
480 PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "background-image", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
481 PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "key-input-focus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
483 Toolkit::Control Control::New()
485 // Create the implementation, temporarily owned on stack
486 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) );
488 // Pass ownership to handle
489 Toolkit::Control handle( *controlImpl );
491 // Second-phase init of the implementation
492 // This can only be done after the CustomActor connection has been made...
493 controlImpl->Initialize();
503 void Control::SetStyleName( const std::string& styleName )
505 if( styleName != mImpl->mStyleName )
507 mImpl->mStyleName = styleName;
510 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
511 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
515 const std::string& Control::GetStyleName() const
517 return mImpl->mStyleName;
520 void Control::SetBackgroundColor( const Vector4& color )
522 Background& background( mImpl->GetBackground() );
524 if ( background.actor )
526 // Just set the actor color
527 background.actor.SetColor( color );
532 MeshActor meshActor = MeshActor::New( CreateMesh() );
534 SetupBackgroundActorConstrained( meshActor, Actor::Property::SCALE, color );
536 // Set the background actor before adding so that we do not inform deriving classes
537 background.actor = meshActor;
538 Self().Add( meshActor );
541 background.color = color;
544 Vector4 Control::GetBackgroundColor() const
546 if ( mImpl->mBackground )
548 return mImpl->mBackground->color;
550 return Color::TRANSPARENT;
553 void Control::SetBackgroundImage( Image image )
555 Background& background( mImpl->GetBackground() );
557 if ( background.actor )
559 // Remove Current actor, unset AFTER removal so that we do not inform deriving classes
560 Self().Remove( background.actor );
561 background.actor.Reset();
564 ImageActor imageActor = ImageActor::New( image );
565 SetupBackgroundActor( imageActor, background.color );
567 // Set the background actor before adding so that we do not inform derived classes
568 background.actor = imageActor;
569 Self().Add( imageActor );
572 void Control::ClearBackground()
574 if ( mImpl->mBackground )
576 Background& background( mImpl->GetBackground() );
577 Self().Remove( background.actor );
579 delete mImpl->mBackground;
580 mImpl->mBackground = NULL;
584 void Control::EnableGestureDetection(Gesture::Type type)
586 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
588 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
589 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
590 mImpl->mPinchGestureDetector.Attach(Self());
593 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
595 mImpl->mPanGestureDetector = PanGestureDetector::New();
596 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
597 mImpl->mPanGestureDetector.Attach(Self());
600 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
602 mImpl->mTapGestureDetector = TapGestureDetector::New();
603 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
604 mImpl->mTapGestureDetector.Attach(Self());
607 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
609 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
610 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
611 mImpl->mLongPressGestureDetector.Attach(Self());
615 void Control::DisableGestureDetection(Gesture::Type type)
617 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
619 mImpl->mPinchGestureDetector.Detach(Self());
620 mImpl->mPinchGestureDetector.Reset();
623 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
625 mImpl->mPanGestureDetector.Detach(Self());
626 mImpl->mPanGestureDetector.Reset();
629 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
631 mImpl->mTapGestureDetector.Detach(Self());
632 mImpl->mTapGestureDetector.Reset();
635 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
637 mImpl->mLongPressGestureDetector.Detach(Self());
638 mImpl->mLongPressGestureDetector.Reset();
642 PinchGestureDetector Control::GetPinchGestureDetector() const
644 return mImpl->mPinchGestureDetector;
647 PanGestureDetector Control::GetPanGestureDetector() const
649 return mImpl->mPanGestureDetector;
652 TapGestureDetector Control::GetTapGestureDetector() const
654 return mImpl->mTapGestureDetector;
657 LongPressGestureDetector Control::GetLongPressGestureDetector() const
659 return mImpl->mLongPressGestureDetector;
662 void Control::SetKeyboardNavigationSupport(bool isSupported)
664 mImpl->mIsKeyboardNavigationSupported = isSupported;
667 bool Control::IsKeyboardNavigationSupported()
669 return mImpl->mIsKeyboardNavigationSupported;
672 void Control::SetKeyInputFocus()
674 if( Self().OnStage() )
676 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
680 bool Control::HasKeyInputFocus()
683 if( Self().OnStage() )
685 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
690 void Control::ClearKeyInputFocus()
692 if( Self().OnStage() )
694 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
698 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
700 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
702 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
703 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
706 bool Control::IsKeyboardFocusGroup()
708 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
711 void Control::AccessibilityActivate()
713 // Inform deriving classes
714 OnAccessibilityActivated();
717 bool Control::OnAccessibilityActivated()
719 return false; // Accessibility activation is not handled by default
722 bool Control::OnAccessibilityPan(PanGesture gesture)
724 return false; // Accessibility pan gesture is not handled by default
727 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
729 return false; // Accessibility touch event is not handled by default
732 bool Control::OnAccessibilityValueChange(bool isIncrease)
734 return false; // Accessibility value change action is not handled by default
737 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
742 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
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 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 // Calling deriving classes
812 void Control::OnInitialize()
816 void Control::OnControlChildAdd( Actor& child )
820 void Control::OnControlChildRemove( Actor& child )
824 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
826 // By default the control is only interested in theme (not font) changes
827 if( change == StyleChange::THEME_CHANGE )
829 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
833 void Control::OnPinch(const PinchGesture& pinch)
835 if( !( mImpl->mStartingPinchScale ) )
838 mImpl->mStartingPinchScale = new Vector3;
841 if( pinch.state == Gesture::Started )
843 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
846 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
849 void Control::OnPan( const PanGesture& pan )
853 void Control::OnTap(const TapGesture& tap)
857 void Control::OnLongPress( const LongPressGesture& longPress )
861 void Control::EmitKeyInputFocusSignal( bool focusGained )
863 Dali::Toolkit::Control handle( GetOwner() );
867 // signals are allocated dynamically when someone connects
868 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
870 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
875 // signals are allocated dynamically when someone connects
876 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
878 mImpl->mKeyInputFocusLostSignal.Emit( handle );
883 void Control::OnStageConnection()
887 void Control::OnStageDisconnection()
891 void Control::OnKeyInputFocusGained()
893 EmitKeyInputFocusSignal( true );
896 void Control::OnKeyInputFocusLost()
898 EmitKeyInputFocusSignal( false );
901 void Control::OnChildAdd(Actor& child)
903 // If this is the background actor, then we do not want to relayout or inform deriving classes
904 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
909 // Notify derived classes.
910 OnControlChildAdd( child );
913 void Control::OnChildRemove(Actor& child)
915 // If this is the background actor, then we do not want to relayout or inform deriving classes
916 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
921 // Notify derived classes.
922 OnControlChildRemove( child );
925 void Control::OnSizeSet(const Vector3& targetSize)
927 // Background is resized through size negotiation
930 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
932 // @todo size negotiate background to new size, animate as well?
935 bool Control::OnTouchEvent(const TouchEvent& event)
937 return false; // Do not consume
940 bool Control::OnHoverEvent(const HoverEvent& event)
942 return false; // Do not consume
945 bool Control::OnKeyEvent(const KeyEvent& event)
947 return false; // Do not consume
950 bool Control::OnWheelEvent(const WheelEvent& event)
952 return false; // Do not consume
955 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
957 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
959 container.Add( Self().GetChildAt( i ), size );
963 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
967 Vector3 Control::GetNaturalSize()
969 if( mImpl->mBackground )
971 Actor actor = mImpl->mBackground->actor;
974 return actor.GetNaturalSize();
980 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
982 return CalculateChildSizeBase( child, dimension );
985 float Control::GetHeightForWidth( float width )
987 if( mImpl->mBackground )
989 Actor actor = mImpl->mBackground->actor;
992 return actor.GetHeightForWidth( width );
995 return GetHeightForWidthBase( width );
998 float Control::GetWidthForHeight( float height )
1000 if( mImpl->mBackground )
1002 Actor actor = mImpl->mBackground->actor;
1005 return actor.GetWidthForHeight( height );
1008 return GetWidthForHeightBase( height );
1011 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
1013 return RelayoutDependentOnChildrenBase( dimension );
1016 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
1020 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
1024 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1026 mImpl->SignalConnected( slotObserver, callback );
1029 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1031 mImpl->SignalDisconnected( slotObserver, callback );
1034 Control& GetImplementation( Dali::Toolkit::Control& handle )
1036 CustomActorImpl& customInterface = handle.GetImplementation();
1037 // downcast to control
1038 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
1042 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
1044 const CustomActorImpl& customInterface = handle.GetImplementation();
1045 // downcast to control
1046 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
1050 } // namespace Internal
1052 } // namespace Toolkit