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/size-negotiation/relayout-container.h>
30 #include <dali/devel-api/object/type-registry-helper.h>
31 #include <dali/devel-api/rendering/renderer.h>
32 #include <dali/devel-api/scripting/scripting.h>
33 #include <dali/integration-api/debug.h>
36 #include <dali-toolkit/public-api/controls/control-depth-index-ranges.h>
37 #include <dali-toolkit/devel-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>
53 * Creates control through type registry
57 return Internal::Control::New();
61 * Performs actions as requested using the action name.
62 * @param[in] object The object on which to perform the action.
63 * @param[in] actionName The action to perform.
64 * @param[in] attributes The attributes with which to perfrom this action.
65 * @return true if action has been accepted by this control
67 const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibility-activated";
68 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
72 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ) )
74 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
77 // if cast succeeds there is an implementation so no need to check
78 ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
86 * Connects a callback function with the object's signals.
87 * @param[in] object The object providing the signal.
88 * @param[in] tracker Used to disconnect the signal.
89 * @param[in] signalName The signal to connect to.
90 * @param[in] functor A newly allocated FunctorDelegate.
91 * @return True if the signal was connected.
92 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
94 const char* SIGNAL_KEY_EVENT = "key-event";
95 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "key-input-focus-gained";
96 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "key-input-focus-lost";
97 const char* SIGNAL_TAPPED = "tapped";
98 const char* SIGNAL_PANNED = "panned";
99 const char* SIGNAL_PINCHED = "pinched";
100 const char* SIGNAL_LONG_PRESSED = "long-pressed";
101 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
103 Dali::BaseHandle handle( object );
105 bool connected( false );
106 Toolkit::Control control = Toolkit::Control::DownCast( handle );
109 Internal::Control& controlImpl( Internal::GetImplementation( control ) );
112 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
114 controlImpl.KeyEventSignal().Connect( tracker, functor );
116 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
118 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
120 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
122 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
124 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
126 controlImpl.EnableGestureDetection( Gesture::Tap );
127 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
129 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
131 controlImpl.EnableGestureDetection( Gesture::Pan );
132 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
134 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
136 controlImpl.EnableGestureDetection( Gesture::Pinch );
137 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
139 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
141 controlImpl.EnableGestureDetection( Gesture::LongPress );
142 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
148 // Setup signals and actions using the type-registry.
149 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
151 // Note: Properties are registered separately below.
153 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
154 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
155 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
156 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
157 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
158 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
159 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
161 TypeAction registerAction( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &DoAction );
163 DALI_TYPE_REGISTRATION_END()
166 * Structure which holds information about the background of a control
170 Actor actor; ///< Background actor
171 Vector4 color; ///< The color of the actor.
178 color( Color::WHITE )
183 unsigned int gQuadIndex[6] = { 0, 2, 1, 1, 2, 3 };
186 Vector2( -0.5f, -0.5f ),
187 Vector2( 0.5f, -0.5f ),
188 Vector2( -0.5f, 0.5f ),
189 Vector2( 0.5f, 0.5f )
193 const char* VERTEX_SHADER_COLOR = DALI_COMPOSE_SHADER(
194 attribute mediump vec2 aPosition;\n
195 uniform mediump mat4 uMvpMatrix;\n
198 gl_Position = uMvpMatrix * vec4( aPosition, 0.0, 1.0 );\n
202 const char* FRAGMENT_SHADER_COLOR = DALI_COMPOSE_SHADER(
203 uniform lowp vec4 uBackgroundColor;\n
204 uniform lowp vec4 uColor;\n
207 gl_FragColor = uBackgroundColor * uColor;\n
213 * @brief Create the background actor for the control.
215 * @param[in] actor The parent actor of the background
216 * @param[in] color The background color
217 * @param[in] image If a valid image is supplied this will be the texture used by the background
219 * @return An actor which will render the background
222 Actor CreateBackground( Actor parent, const Vector4& color, Image image = Image() )
226 PropertyBuffer vertexBuffer;
230 Property::Map vertexFormat;
231 vertexFormat["aPosition"] = Property::VECTOR2;
233 //Create a vertex buffer for vertex positions
234 vertexBuffer = PropertyBuffer::New( vertexFormat, 4u );
235 vertexBuffer.SetData( gQuad );
237 shader = Shader::New( VERTEX_SHADER_COLOR, FRAGMENT_SHADER_COLOR );
238 material = Material::New( shader );
240 //Create the index buffer
241 Property::Map indexFormat;
242 indexFormat["indices"] = Property::UNSIGNED_INTEGER;
243 PropertyBuffer indexBuffer = PropertyBuffer::New( indexFormat, 6u );
244 indexBuffer.SetData(gQuadIndex);
246 //Create the geometry
247 Geometry mesh = Geometry::New();
248 mesh.AddVertexBuffer( vertexBuffer );
249 mesh.SetIndexBuffer( indexBuffer );
251 //Add uniforms to the shader
252 shader.RegisterProperty( "uBackgroundColor", color );
254 //Create the renderer
255 Renderer renderer = Renderer::New( mesh, material );
256 renderer.SetDepthIndex( parent.GetHierarchyDepth() + BACKGROUND_DEPTH_INDEX );
259 Actor meshActor = Actor::New();
260 meshActor.SetSize( Vector3::ONE );
261 meshActor.AddRenderer( renderer );
262 meshActor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
263 meshActor.SetColorMode( USE_PARENT_COLOR );
265 //Constraint scale of the mesh actor to the size of the control
266 Constraint constraint = Constraint::New<Vector3>( meshActor,
267 Actor::Property::SCALE,
268 EqualToConstraint() );
269 constraint.AddSource( ParentSource( Actor::Property::SIZE ) );
276 ImageActor imageActor = ImageActor::New( image );
277 imageActor.SetColor( color );
278 imageActor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
279 imageActor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
280 imageActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
281 imageActor.SetSortModifier( parent.GetHierarchyDepth() + BACKGROUND_DEPTH_INDEX );
288 } // unnamed namespace
293 class Control::Impl : public ConnectionTracker
297 // Construction & Destruction
298 Impl(Control& controlImpl)
299 : mControlImpl( controlImpl ),
302 mStartingPinchScale( NULL ),
304 mPinchGestureDetector(),
305 mPanGestureDetector(),
306 mTapGestureDetector(),
307 mLongPressGestureDetector(),
308 mFlags( Control::ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ),
309 mIsKeyboardNavigationSupported( false ),
310 mIsKeyboardFocusGroup( false ),
311 mAddRemoveBackgroundChild( false )
317 // All gesture detectors will be destroyed so no need to disconnect.
319 delete mStartingPinchScale;
322 // Gesture Detection Methods
324 void PinchDetected(Actor actor, const PinchGesture& pinch)
326 mControlImpl.OnPinch(pinch);
329 void PanDetected(Actor actor, const PanGesture& pan)
331 mControlImpl.OnPan(pan);
334 void TapDetected(Actor actor, const TapGesture& tap)
336 mControlImpl.OnTap(tap);
339 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
341 mControlImpl.OnLongPress(longPress);
344 // Background Methods
347 * Only creates an instance of the background if we actually use it.
348 * @return A reference to the Background structure.
350 Background& GetBackground()
354 mBackground = new Background;
362 * Called when a property of an object of this type is set.
363 * @param[in] object The object whose property is set.
364 * @param[in] index The property index.
365 * @param[in] value The new property value.
367 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
369 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
373 Control& controlImpl( GetImplementation( control ) );
377 case Toolkit::Control::Property::STYLE_NAME:
379 controlImpl.SetStyleName( value.Get< std::string >() );
383 case Toolkit::Control::Property::BACKGROUND_COLOR:
385 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
389 case Toolkit::Control::Property::BACKGROUND_IMAGE:
391 Image image = Scripting::NewImage( value );
394 controlImpl.SetBackgroundImage( image );
398 // An empty map means the background is no longer required
399 controlImpl.ClearBackground();
404 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
406 if ( value.Get< bool >() )
408 controlImpl.SetKeyInputFocus();
412 controlImpl.ClearKeyInputFocus();
421 * Called to retrieve a property of an object of this type.
422 * @param[in] object The object whose property is to be retrieved.
423 * @param[in] index The property index.
424 * @return The current value of the property.
426 static Property::Value GetProperty( BaseObject* object, Property::Index index )
428 Property::Value value;
430 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
434 Control& controlImpl( GetImplementation( control ) );
438 case Toolkit::Control::Property::STYLE_NAME:
440 value = controlImpl.GetStyleName();
444 case Toolkit::Control::Property::BACKGROUND_COLOR:
446 value = controlImpl.GetBackgroundColor();
450 case Toolkit::Control::Property::BACKGROUND_IMAGE:
454 Background* back = controlImpl.mImpl->mBackground;
455 if ( back && back->actor )
457 if( back->actor.GetRendererCount() > 0 && back->actor.GetRendererAt(0).GetMaterial().GetNumberOfSamplers() > 0 )
459 Image image = back->actor.GetRendererAt(0).GetMaterial().GetSamplerAt(0).GetImage();
462 Scripting::CreatePropertyMap( image, map );
467 ImageActor imageActor = ImageActor::DownCast( back->actor );
470 Image image = imageActor.GetImage();
471 Scripting::CreatePropertyMap( image, map );
480 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
482 value = controlImpl.HasKeyInputFocus();
493 Control& mControlImpl;
494 std::string mStyleName;
495 Background* mBackground; ///< Only create the background if we use it
496 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
497 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
498 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
499 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
502 PinchGestureDetector mPinchGestureDetector;
503 PanGestureDetector mPanGestureDetector;
504 TapGestureDetector mTapGestureDetector;
505 LongPressGestureDetector mLongPressGestureDetector;
507 ControlBehaviour mFlags :CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
508 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
509 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
510 bool mAddRemoveBackgroundChild:1; ///< Flag to know when we are adding or removing our own actor to avoid call to OnControlChildAdd
512 // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
513 static PropertyRegistration PROPERTY_1;
514 static PropertyRegistration PROPERTY_2;
515 static PropertyRegistration PROPERTY_3;
516 static PropertyRegistration PROPERTY_4;
519 // Properties registered without macro to use specific member variables.
520 PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "style-name", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
521 PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "background-color", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
522 PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "background-image", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
523 PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "key-input-focus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
525 Toolkit::Control Control::New()
527 // Create the implementation, temporarily owned on stack
528 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) );
530 // Pass ownership to handle
531 Toolkit::Control handle( *controlImpl );
533 // Second-phase init of the implementation
534 // This can only be done after the CustomActor connection has been made...
535 controlImpl->Initialize();
545 void Control::SetStyleName( const std::string& styleName )
547 if( styleName != mImpl->mStyleName )
549 mImpl->mStyleName = styleName;
552 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
553 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
557 const std::string& Control::GetStyleName() const
559 return mImpl->mStyleName;
562 void Control::SetBackgroundColor( const Vector4& color )
564 Background& background( mImpl->GetBackground() );
566 if ( background.actor )
568 if( background.actor.GetRendererCount() > 0 )
570 Shader shader = background.actor.GetRendererAt(0).GetMaterial().GetShader();
571 shader.SetProperty( shader.GetPropertyIndex("uBackgroundColor"), color );
575 background.actor.SetColor( color );
581 Actor actor = CreateBackground(Self(), color );
582 background.actor = actor;
583 mImpl->mAddRemoveBackgroundChild = true;
584 // use insert to guarantee its the first child (so that OVERLAY mode works)
585 Self().Insert( 0, actor );
586 mImpl->mAddRemoveBackgroundChild = false;
589 background.color = color;
592 Vector4 Control::GetBackgroundColor() const
594 if ( mImpl->mBackground )
596 return mImpl->mBackground->color;
598 return Color::TRANSPARENT;
601 void Control::SetBackgroundImage( Image image )
603 Background& background( mImpl->GetBackground() );
605 if ( background.actor )
607 // Remove Current actor, unset AFTER removal
608 mImpl->mAddRemoveBackgroundChild = true;
609 Self().Remove( background.actor );
610 mImpl->mAddRemoveBackgroundChild = false;
611 background.actor.Reset();
614 Actor actor = CreateBackground(Self(), background.color, image);
616 // Set the background actor before adding so that we do not inform derived classes
617 background.actor = actor;
618 mImpl->mAddRemoveBackgroundChild = true;
619 // use insert to guarantee its the first child (so that OVERLAY mode works)
620 Self().Insert( 0, actor );
621 mImpl->mAddRemoveBackgroundChild = false;
624 void Control::ClearBackground()
626 if ( mImpl->mBackground )
628 Background& background( mImpl->GetBackground() );
629 mImpl->mAddRemoveBackgroundChild = true;
630 Self().Remove( background.actor );
631 mImpl->mAddRemoveBackgroundChild = false;
633 delete mImpl->mBackground;
634 mImpl->mBackground = NULL;
638 void Control::EnableGestureDetection(Gesture::Type type)
640 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
642 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
643 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
644 mImpl->mPinchGestureDetector.Attach(Self());
647 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
649 mImpl->mPanGestureDetector = PanGestureDetector::New();
650 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
651 mImpl->mPanGestureDetector.Attach(Self());
654 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
656 mImpl->mTapGestureDetector = TapGestureDetector::New();
657 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
658 mImpl->mTapGestureDetector.Attach(Self());
661 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
663 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
664 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
665 mImpl->mLongPressGestureDetector.Attach(Self());
669 void Control::DisableGestureDetection(Gesture::Type type)
671 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
673 mImpl->mPinchGestureDetector.Detach(Self());
674 mImpl->mPinchGestureDetector.Reset();
677 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
679 mImpl->mPanGestureDetector.Detach(Self());
680 mImpl->mPanGestureDetector.Reset();
683 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
685 mImpl->mTapGestureDetector.Detach(Self());
686 mImpl->mTapGestureDetector.Reset();
689 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
691 mImpl->mLongPressGestureDetector.Detach(Self());
692 mImpl->mLongPressGestureDetector.Reset();
696 PinchGestureDetector Control::GetPinchGestureDetector() const
698 return mImpl->mPinchGestureDetector;
701 PanGestureDetector Control::GetPanGestureDetector() const
703 return mImpl->mPanGestureDetector;
706 TapGestureDetector Control::GetTapGestureDetector() const
708 return mImpl->mTapGestureDetector;
711 LongPressGestureDetector Control::GetLongPressGestureDetector() const
713 return mImpl->mLongPressGestureDetector;
716 void Control::SetKeyboardNavigationSupport(bool isSupported)
718 mImpl->mIsKeyboardNavigationSupported = isSupported;
721 bool Control::IsKeyboardNavigationSupported()
723 return mImpl->mIsKeyboardNavigationSupported;
726 void Control::SetKeyInputFocus()
728 if( Self().OnStage() )
730 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
734 bool Control::HasKeyInputFocus()
737 if( Self().OnStage() )
739 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
744 void Control::ClearKeyInputFocus()
746 if( Self().OnStage() )
748 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
752 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
754 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
756 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
757 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
760 bool Control::IsKeyboardFocusGroup()
762 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
765 void Control::AccessibilityActivate()
767 // Inform deriving classes
768 OnAccessibilityActivated();
771 void Control::KeyboardEnter()
773 // Inform deriving classes
777 bool Control::OnAccessibilityActivated()
779 return false; // Accessibility activation is not handled by default
782 bool Control::OnKeyboardEnter()
784 return false; // Keyboard enter is not handled by default
787 bool Control::OnAccessibilityPan(PanGesture gesture)
789 return false; // Accessibility pan gesture is not handled by default
792 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
794 return false; // Accessibility touch event is not handled by default
797 bool Control::OnAccessibilityValueChange(bool isIncrease)
799 return false; // Accessibility value change action is not handled by default
802 bool Control::OnAccessibilityZoom()
804 return false; // Accessibility zoom action is not handled by default
807 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
812 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
816 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
818 return mImpl->mKeyEventSignal;
821 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusGainedSignal()
823 return mImpl->mKeyInputFocusGainedSignal;
826 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusLostSignal()
828 return mImpl->mKeyInputFocusLostSignal;
831 bool Control::EmitKeyEventSignal( const KeyEvent& event )
833 // Guard against destruction during signal emission
834 Dali::Toolkit::Control handle( GetOwner() );
836 bool consumed = false;
838 // signals are allocated dynamically when someone connects
839 if ( !mImpl->mKeyEventSignal.Empty() )
841 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
846 // Notification for derived classes
847 consumed = OnKeyEvent(event);
853 Control::Control( ControlBehaviour behaviourFlags )
854 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
855 mImpl(new Impl(*this))
857 mImpl->mFlags = behaviourFlags;
860 void Control::Initialize()
862 // Call deriving classes so initialised before styling is applied to them.
865 if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
867 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
869 // Register for style changes
870 styleManager.StyleChangeSignal().Connect( this, &Control::OnStyleChange );
872 // Apply the current style
873 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
876 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
878 SetKeyboardNavigationSupport( true );
882 void Control::OnInitialize()
886 void Control::OnControlChildAdd( Actor& child )
890 void Control::OnControlChildRemove( Actor& child )
894 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
896 // By default the control is only interested in theme (not font) changes
897 if( change == StyleChange::THEME_CHANGE )
899 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
903 void Control::OnPinch(const PinchGesture& pinch)
905 if( !( mImpl->mStartingPinchScale ) )
908 mImpl->mStartingPinchScale = new Vector3;
911 if( pinch.state == Gesture::Started )
913 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
916 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
919 void Control::OnPan( const PanGesture& pan )
923 void Control::OnTap(const TapGesture& tap)
927 void Control::OnLongPress( const LongPressGesture& longPress )
931 void Control::EmitKeyInputFocusSignal( bool focusGained )
933 Dali::Toolkit::Control handle( GetOwner() );
937 // signals are allocated dynamically when someone connects
938 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
940 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
945 // signals are allocated dynamically when someone connects
946 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
948 mImpl->mKeyInputFocusLostSignal.Emit( handle );
953 void Control::OnStageConnection( int depth )
955 unsigned int controlRendererCount = Self().GetRendererCount();
956 for( unsigned int i(0); i<controlRendererCount; ++i )
958 Renderer controlRenderer = Self().GetRendererAt(i);
959 if( controlRenderer )
961 controlRenderer.SetDepthIndex( CONTENT_DEPTH_INDEX+depth );
965 if( mImpl->mBackground )
967 if(mImpl->mBackground->actor.GetRendererCount() > 0 )
969 Renderer backgroundRenderer = mImpl->mBackground->actor.GetRendererAt( 0 );
970 if(backgroundRenderer)
972 backgroundRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX+depth );
978 ImageActor imageActor = ImageActor::DownCast( mImpl->mBackground->actor );
981 imageActor.SetSortModifier( BACKGROUND_DEPTH_INDEX+depth );
987 void Control::OnStageDisconnection()
991 void Control::OnKeyInputFocusGained()
993 EmitKeyInputFocusSignal( true );
996 void Control::OnKeyInputFocusLost()
998 EmitKeyInputFocusSignal( false );
1001 void Control::OnChildAdd(Actor& child)
1003 // If this is the background actor, then we do not want to inform deriving classes
1004 if ( mImpl->mAddRemoveBackgroundChild )
1009 // Notify derived classes.
1010 OnControlChildAdd( child );
1013 void Control::OnChildRemove(Actor& child)
1015 // If this is the background actor, then we do not want to inform deriving classes
1016 if ( mImpl->mAddRemoveBackgroundChild )
1021 // Notify derived classes.
1022 OnControlChildRemove( child );
1025 void Control::OnSizeSet(const Vector3& targetSize)
1027 // Background is resized through size negotiation
1030 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1032 // @todo size negotiate background to new size, animate as well?
1035 bool Control::OnTouchEvent(const TouchEvent& event)
1037 return false; // Do not consume
1040 bool Control::OnHoverEvent(const HoverEvent& event)
1042 return false; // Do not consume
1045 bool Control::OnKeyEvent(const KeyEvent& event)
1047 return false; // Do not consume
1050 bool Control::OnWheelEvent(const WheelEvent& event)
1052 return false; // Do not consume
1055 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
1057 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
1059 container.Add( Self().GetChildAt( i ), size );
1063 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
1067 Vector3 Control::GetNaturalSize()
1069 //Control's natural size is the size of its background image if it has been set, or ZERO otherwise
1070 Vector3 naturalSize = Vector3::ZERO;
1071 if( mImpl->mBackground )
1073 if( mImpl->mBackground->actor.GetRendererCount() > 0 )
1075 Material backgroundMaterial = mImpl->mBackground->actor.GetRendererAt(0).GetMaterial();
1076 if( backgroundMaterial.GetNumberOfSamplers() > 0 )
1078 Image backgroundImage = backgroundMaterial.GetSamplerAt(0).GetImage();
1079 if( backgroundImage )
1081 naturalSize.x = backgroundImage.GetWidth();
1082 naturalSize.y = backgroundImage.GetHeight();
1088 return mImpl->mBackground->actor.GetNaturalSize();
1095 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
1097 return CalculateChildSizeBase( child, dimension );
1100 float Control::GetHeightForWidth( float width )
1102 if( mImpl->mBackground )
1104 Actor actor = mImpl->mBackground->actor;
1107 return actor.GetHeightForWidth( width );
1110 return GetHeightForWidthBase( width );
1113 float Control::GetWidthForHeight( float height )
1115 if( mImpl->mBackground )
1117 Actor actor = mImpl->mBackground->actor;
1120 return actor.GetWidthForHeight( height );
1123 return GetWidthForHeightBase( height );
1126 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
1128 return RelayoutDependentOnChildrenBase( dimension );
1131 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
1135 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
1139 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1141 mImpl->SignalConnected( slotObserver, callback );
1144 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1146 mImpl->SignalDisconnected( slotObserver, callback );
1149 Control& GetImplementation( Dali::Toolkit::Control& handle )
1151 CustomActorImpl& customInterface = handle.GetImplementation();
1152 // downcast to control
1153 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
1157 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
1159 const CustomActorImpl& customInterface = handle.GetImplementation();
1160 // downcast to control
1161 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
1165 } // namespace Internal
1167 } // namespace Toolkit