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_CONTROL_ACTIVATED = "control-activated";
68 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
72 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_CONTROL_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_CONTROL_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 )
192 struct VertexWithTexture
198 VertexWithTexture gQuadWithTexture[] = {
199 { Vector2( -0.5f, -0.5f ), Vector2( 0.0f, 0.0f ) },
200 { Vector2( 0.5f, -0.5f ), Vector2( 1.0f, 0.0f ) },
201 { Vector2( -0.5f, 0.5f ), Vector2( 0.0f, 1.0f ) },
202 { Vector2( 0.5f, 0.5f ), Vector2( 1.0f, 1.0f ) }
205 const char* VERTEX_SHADER_COLOR = DALI_COMPOSE_SHADER(
206 attribute mediump vec2 aPosition;\n
207 uniform mediump mat4 uMvpMatrix;\n
210 gl_Position = uMvpMatrix * vec4( aPosition, 0.0, 1.0 );\n
214 const char* FRAGMENT_SHADER_COLOR = DALI_COMPOSE_SHADER(
215 uniform lowp vec4 uBackgroundColor;\n
216 uniform lowp vec4 uColor;\n
219 gl_FragColor = uBackgroundColor * uColor;\n
223 const char* VERTEX_SHADER_TEXTURE = DALI_COMPOSE_SHADER(
224 attribute mediump vec2 aPosition;\n
225 attribute mediump vec2 aTexCoord;\n
226 uniform mediump mat4 uMvpMatrix;\n
227 varying mediump vec2 vTexCoord;\n
230 gl_Position = uMvpMatrix * vec4( aPosition, 0.0, 1.0 );\n
231 vTexCoord = aTexCoord;\n
235 const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER(
236 uniform lowp vec4 uBackgroundColor;\n
237 uniform lowp vec4 uColor;\n
238 uniform sampler2D sTexture;\n
239 varying mediump vec2 vTexCoord;\n
243 gl_FragColor = texture2D( sTexture, vTexCoord ) * uBackgroundColor * uColor;\n
248 * @brief Create the background actor for the control.
250 * @param[in] actor The parent actor of the background
251 * @param[in] color The background color
252 * @param[in] image If a valid image is supplied this will be the texture used by the background
254 * @return An actor which will render the background
257 Actor CreateBackground( Actor parent, const Vector4& color, Image image = Image() )
259 PropertyBuffer vertexBuffer;
264 Property::Map vertexFormat;
265 vertexFormat["aPosition"] = Property::VECTOR2;
266 vertexFormat["aTexCoord"] = Property::VECTOR2;
268 //Create a vertex buffer for vertex positions and texture coordinates
269 vertexBuffer = PropertyBuffer::New( vertexFormat, 4u );
270 vertexBuffer.SetData( gQuadWithTexture );
272 shader = Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE );
273 Sampler textureSampler = Sampler::New( image, "sTexture" );
274 material = Material::New( shader );
275 material.AddSampler(textureSampler);
279 Property::Map vertexFormat;
280 vertexFormat["aPosition"] = Property::VECTOR2;
282 //Create a vertex buffer for vertex positions
283 vertexBuffer = PropertyBuffer::New( vertexFormat, 4u );
284 vertexBuffer.SetData( gQuad );
286 shader = Shader::New( VERTEX_SHADER_COLOR, FRAGMENT_SHADER_COLOR );
287 material = Material::New( shader );
290 //Create the index buffer
291 Property::Map indexFormat;
292 indexFormat["indices"] = Property::UNSIGNED_INTEGER;
293 PropertyBuffer indexBuffer = PropertyBuffer::New( indexFormat, 6u );
294 indexBuffer.SetData(gQuadIndex);
296 //Create the geometry
297 Geometry mesh = Geometry::New();
298 mesh.AddVertexBuffer( vertexBuffer );
299 mesh.SetIndexBuffer( indexBuffer );
301 //Add uniforms to the shader
302 shader.RegisterProperty( "uBackgroundColor", color );
304 //Create the renderer
305 Renderer renderer = Renderer::New( mesh, material );
306 renderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX );
309 Actor meshActor = Actor::New();
310 meshActor.SetSize( Vector3::ONE );
311 meshActor.AddRenderer( renderer );
312 meshActor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
313 meshActor.SetColorMode( USE_PARENT_COLOR );
315 //Constraint scale of the mesh actor to the size of the control
316 Constraint constraint = Constraint::New<Vector3>( meshActor,
317 Actor::Property::SCALE,
318 EqualToConstraint() );
319 constraint.AddSource( ParentSource( Actor::Property::SIZE ) );
325 } // unnamed namespace
330 class Control::Impl : public ConnectionTracker
334 // Construction & Destruction
335 Impl(Control& controlImpl)
336 : mControlImpl( controlImpl ),
339 mStartingPinchScale( NULL ),
341 mPinchGestureDetector(),
342 mPanGestureDetector(),
343 mTapGestureDetector(),
344 mLongPressGestureDetector(),
345 mFlags( Control::ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ),
346 mIsKeyboardNavigationSupported( false ),
347 mIsKeyboardFocusGroup( false ),
348 mAddRemoveBackgroundChild( false )
354 // All gesture detectors will be destroyed so no need to disconnect.
356 delete mStartingPinchScale;
359 // Gesture Detection Methods
361 void PinchDetected(Actor actor, const PinchGesture& pinch)
363 mControlImpl.OnPinch(pinch);
366 void PanDetected(Actor actor, const PanGesture& pan)
368 mControlImpl.OnPan(pan);
371 void TapDetected(Actor actor, const TapGesture& tap)
373 mControlImpl.OnTap(tap);
376 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
378 mControlImpl.OnLongPress(longPress);
381 // Background Methods
384 * Only creates an instance of the background if we actually use it.
385 * @return A reference to the Background structure.
387 Background& GetBackground()
391 mBackground = new Background;
399 * Called when a property of an object of this type is set.
400 * @param[in] object The object whose property is set.
401 * @param[in] index The property index.
402 * @param[in] value The new property value.
404 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
406 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
410 Control& controlImpl( GetImplementation( control ) );
414 case Toolkit::Control::Property::STYLE_NAME:
416 controlImpl.SetStyleName( value.Get< std::string >() );
420 case Toolkit::Control::Property::BACKGROUND_COLOR:
422 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
426 case Toolkit::Control::Property::BACKGROUND_IMAGE:
428 Image image = Scripting::NewImage( value );
431 controlImpl.SetBackgroundImage( image );
435 // An empty map means the background is no longer required
436 controlImpl.ClearBackground();
441 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
443 if ( value.Get< bool >() )
445 controlImpl.SetKeyInputFocus();
449 controlImpl.ClearKeyInputFocus();
458 * Called to retrieve a property of an object of this type.
459 * @param[in] object The object whose property is to be retrieved.
460 * @param[in] index The property index.
461 * @return The current value of the property.
463 static Property::Value GetProperty( BaseObject* object, Property::Index index )
465 Property::Value value;
467 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
471 Control& controlImpl( GetImplementation( control ) );
475 case Toolkit::Control::Property::STYLE_NAME:
477 value = controlImpl.GetStyleName();
481 case Toolkit::Control::Property::BACKGROUND_COLOR:
483 value = controlImpl.GetBackgroundColor();
487 case Toolkit::Control::Property::BACKGROUND_IMAGE:
491 Background* back = controlImpl.mImpl->mBackground;
492 if ( back && back->actor && back->actor.GetRendererAt(0).GetMaterial().GetNumberOfSamplers() > 0)
494 Image image = back->actor.GetRendererAt(0).GetMaterial().GetSamplerAt(0).GetImage();
497 Scripting::CreatePropertyMap( image, map );
505 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
507 value = controlImpl.HasKeyInputFocus();
518 Control& mControlImpl;
519 std::string mStyleName;
520 Background* mBackground; ///< Only create the background if we use it
521 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
522 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
523 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
524 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
527 PinchGestureDetector mPinchGestureDetector;
528 PanGestureDetector mPanGestureDetector;
529 TapGestureDetector mTapGestureDetector;
530 LongPressGestureDetector mLongPressGestureDetector;
532 ControlBehaviour mFlags :CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
533 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
534 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
535 bool mAddRemoveBackgroundChild:1; ///< Flag to know when we are adding or removing our own actor to avoid call to OnControlChildAdd
537 // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
538 static PropertyRegistration PROPERTY_1;
539 static PropertyRegistration PROPERTY_2;
540 static PropertyRegistration PROPERTY_3;
541 static PropertyRegistration PROPERTY_4;
544 // Properties registered without macro to use specific member variables.
545 PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "style-name", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
546 PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "background-color", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
547 PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "background-image", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
548 PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "key-input-focus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
550 Toolkit::Control Control::New()
552 // Create the implementation, temporarily owned on stack
553 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) );
555 // Pass ownership to handle
556 Toolkit::Control handle( *controlImpl );
558 // Second-phase init of the implementation
559 // This can only be done after the CustomActor connection has been made...
560 controlImpl->Initialize();
570 void Control::SetStyleName( const std::string& styleName )
572 if( styleName != mImpl->mStyleName )
574 mImpl->mStyleName = styleName;
577 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
578 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
582 const std::string& Control::GetStyleName() const
584 return mImpl->mStyleName;
587 void Control::SetBackgroundColor( const Vector4& color )
589 Background& background( mImpl->GetBackground() );
591 if ( background.actor )
593 Shader shader = background.actor.GetRendererAt(0).GetMaterial().GetShader();
594 shader.SetProperty( shader.GetPropertyIndex("uBackgroundColor"), color );
599 Actor actor = CreateBackground(Self(), color );
600 background.actor = actor;
601 mImpl->mAddRemoveBackgroundChild = true;
602 // use insert to guarantee its the first child (so that OVERLAY mode works)
603 Self().Insert( 0, actor );
604 mImpl->mAddRemoveBackgroundChild = false;
607 background.color = color;
610 Vector4 Control::GetBackgroundColor() const
612 if ( mImpl->mBackground )
614 return mImpl->mBackground->color;
616 return Color::TRANSPARENT;
619 void Control::SetBackgroundImage( Image image )
621 Background& background( mImpl->GetBackground() );
622 if( !background.actor || background.actor.GetRendererAt(0).GetMaterial().GetNumberOfSamplers() == 0)
624 // Remove current actor as it has not texture coordinates
625 if( background.actor )
627 mImpl->mAddRemoveBackgroundChild = true;
628 Self().Remove( background.actor );
629 mImpl->mAddRemoveBackgroundChild = false;
630 background.actor.Reset();
633 //Create a new actor with texture coordinates
634 Actor actor = CreateBackground(Self(), background.color, image);
635 mImpl->mAddRemoveBackgroundChild = true;
636 // use insert to guarantee its the first child (so that OVERLAY mode works)
637 Self().Insert( 0, actor );
638 mImpl->mAddRemoveBackgroundChild = false;
639 background.actor = actor;
643 //Change sampler image
644 Sampler sampler = background.actor.GetRendererAt(0).GetMaterial().GetSamplerAt(0);
645 sampler.SetImage(image);
649 void Control::ClearBackground()
651 if ( mImpl->mBackground )
653 Background& background( mImpl->GetBackground() );
654 mImpl->mAddRemoveBackgroundChild = true;
655 Self().Remove( background.actor );
656 mImpl->mAddRemoveBackgroundChild = false;
658 delete mImpl->mBackground;
659 mImpl->mBackground = NULL;
663 void Control::EnableGestureDetection(Gesture::Type type)
665 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
667 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
668 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
669 mImpl->mPinchGestureDetector.Attach(Self());
672 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
674 mImpl->mPanGestureDetector = PanGestureDetector::New();
675 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
676 mImpl->mPanGestureDetector.Attach(Self());
679 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
681 mImpl->mTapGestureDetector = TapGestureDetector::New();
682 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
683 mImpl->mTapGestureDetector.Attach(Self());
686 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
688 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
689 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
690 mImpl->mLongPressGestureDetector.Attach(Self());
694 void Control::DisableGestureDetection(Gesture::Type type)
696 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
698 mImpl->mPinchGestureDetector.Detach(Self());
699 mImpl->mPinchGestureDetector.Reset();
702 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
704 mImpl->mPanGestureDetector.Detach(Self());
705 mImpl->mPanGestureDetector.Reset();
708 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
710 mImpl->mTapGestureDetector.Detach(Self());
711 mImpl->mTapGestureDetector.Reset();
714 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
716 mImpl->mLongPressGestureDetector.Detach(Self());
717 mImpl->mLongPressGestureDetector.Reset();
721 PinchGestureDetector Control::GetPinchGestureDetector() const
723 return mImpl->mPinchGestureDetector;
726 PanGestureDetector Control::GetPanGestureDetector() const
728 return mImpl->mPanGestureDetector;
731 TapGestureDetector Control::GetTapGestureDetector() const
733 return mImpl->mTapGestureDetector;
736 LongPressGestureDetector Control::GetLongPressGestureDetector() const
738 return mImpl->mLongPressGestureDetector;
741 void Control::SetKeyboardNavigationSupport(bool isSupported)
743 mImpl->mIsKeyboardNavigationSupported = isSupported;
746 bool Control::IsKeyboardNavigationSupported()
748 return mImpl->mIsKeyboardNavigationSupported;
751 void Control::SetKeyInputFocus()
753 if( Self().OnStage() )
755 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
759 bool Control::HasKeyInputFocus()
762 if( Self().OnStage() )
764 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
769 void Control::ClearKeyInputFocus()
771 if( Self().OnStage() )
773 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
777 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
779 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
781 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
782 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
785 bool Control::IsKeyboardFocusGroup()
787 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
790 void Control::AccessibilityActivate()
792 // Inform deriving classes
793 OnAccessibilityActivated();
796 bool Control::OnAccessibilityActivated()
798 return false; // Accessibility activation is not handled by default
801 bool Control::OnAccessibilityPan(PanGesture gesture)
803 return false; // Accessibility pan gesture is not handled by default
806 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
808 return false; // Accessibility touch event is not handled by default
811 bool Control::OnAccessibilityValueChange(bool isIncrease)
813 return false; // Accessibility value change action is not handled by default
816 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
821 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
825 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
827 return mImpl->mKeyEventSignal;
830 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusGainedSignal()
832 return mImpl->mKeyInputFocusGainedSignal;
835 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusLostSignal()
837 return mImpl->mKeyInputFocusLostSignal;
840 bool Control::EmitKeyEventSignal( const KeyEvent& event )
842 // Guard against destruction during signal emission
843 Dali::Toolkit::Control handle( GetOwner() );
845 bool consumed = false;
847 // signals are allocated dynamically when someone connects
848 if ( !mImpl->mKeyEventSignal.Empty() )
850 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
855 // Notification for derived classes
856 consumed = OnKeyEvent(event);
862 Control::Control( ControlBehaviour behaviourFlags )
863 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
864 mImpl(new Impl(*this))
866 mImpl->mFlags = behaviourFlags;
869 void Control::Initialize()
871 // Call deriving classes so initialised before styling is applied to them.
874 if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
876 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
878 // Register for style changes
879 styleManager.StyleChangeSignal().Connect( this, &Control::OnStyleChange );
881 // Apply the current style
882 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
885 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
887 SetKeyboardNavigationSupport( true );
891 void Control::OnInitialize()
895 void Control::OnControlChildAdd( Actor& child )
899 void Control::OnControlChildRemove( Actor& child )
903 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
905 // By default the control is only interested in theme (not font) changes
906 if( change == StyleChange::THEME_CHANGE )
908 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
912 void Control::OnPinch(const PinchGesture& pinch)
914 if( !( mImpl->mStartingPinchScale ) )
917 mImpl->mStartingPinchScale = new Vector3;
920 if( pinch.state == Gesture::Started )
922 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
925 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
928 void Control::OnPan( const PanGesture& pan )
932 void Control::OnTap(const TapGesture& tap)
936 void Control::OnLongPress( const LongPressGesture& longPress )
940 void Control::EmitKeyInputFocusSignal( bool focusGained )
942 Dali::Toolkit::Control handle( GetOwner() );
946 // signals are allocated dynamically when someone connects
947 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
949 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
954 // signals are allocated dynamically when someone connects
955 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
957 mImpl->mKeyInputFocusLostSignal.Emit( handle );
962 void Control::OnStageConnection( unsigned int depth )
964 unsigned int controlRendererCount = Self().GetRendererCount();
965 for( unsigned int i(0); i<controlRendererCount; ++i )
967 Renderer controlRenderer = Self().GetRendererAt(i);
968 if( controlRenderer )
970 controlRenderer.SetDepthIndex( CONTENT_DEPTH_INDEX+depth );
974 if( mImpl->mBackground )
976 Renderer backgroundRenderer = mImpl->mBackground->actor.GetRendererAt( 0 );
977 if(backgroundRenderer)
979 backgroundRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX+depth );
984 void Control::OnStageDisconnection()
988 void Control::OnKeyInputFocusGained()
990 EmitKeyInputFocusSignal( true );
993 void Control::OnKeyInputFocusLost()
995 EmitKeyInputFocusSignal( false );
998 void Control::OnChildAdd(Actor& child)
1000 // If this is the background actor, then we do not want to inform deriving classes
1001 if ( mImpl->mAddRemoveBackgroundChild )
1006 // Notify derived classes.
1007 OnControlChildAdd( child );
1010 void Control::OnChildRemove(Actor& child)
1012 // If this is the background actor, then we do not want to inform deriving classes
1013 if ( mImpl->mAddRemoveBackgroundChild )
1018 // Notify derived classes.
1019 OnControlChildRemove( child );
1022 void Control::OnSizeSet(const Vector3& targetSize)
1024 // Background is resized through size negotiation
1027 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1029 // @todo size negotiate background to new size, animate as well?
1032 bool Control::OnTouchEvent(const TouchEvent& event)
1034 return false; // Do not consume
1037 bool Control::OnHoverEvent(const HoverEvent& event)
1039 return false; // Do not consume
1042 bool Control::OnKeyEvent(const KeyEvent& event)
1044 return false; // Do not consume
1047 bool Control::OnWheelEvent(const WheelEvent& event)
1049 return false; // Do not consume
1052 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
1054 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
1056 container.Add( Self().GetChildAt( i ), size );
1060 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
1064 Vector3 Control::GetNaturalSize()
1066 //Control's natural size is the size of its background image if it has been set, or ZERO otherwise
1067 Vector3 naturalSize = Vector3::ZERO;
1068 if( mImpl->mBackground )
1070 Material backgroundMaterial = mImpl->mBackground->actor.GetRendererAt(0).GetMaterial();
1071 if( backgroundMaterial.GetNumberOfSamplers() > 0 )
1073 Image backgroundImage = backgroundMaterial.GetSamplerAt(0).GetImage();
1074 if( backgroundImage )
1076 naturalSize.x = backgroundImage.GetWidth();
1077 naturalSize.y = backgroundImage.GetHeight();
1085 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
1087 return CalculateChildSizeBase( child, dimension );
1090 float Control::GetHeightForWidth( float width )
1092 if( mImpl->mBackground )
1094 Actor actor = mImpl->mBackground->actor;
1097 return actor.GetHeightForWidth( width );
1100 return GetHeightForWidthBase( width );
1103 float Control::GetWidthForHeight( float height )
1105 if( mImpl->mBackground )
1107 Actor actor = mImpl->mBackground->actor;
1110 return actor.GetWidthForHeight( height );
1113 return GetWidthForHeightBase( height );
1116 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
1118 return RelayoutDependentOnChildrenBase( dimension );
1121 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
1125 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
1129 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1131 mImpl->SignalConnected( slotObserver, callback );
1134 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1136 mImpl->SignalDisconnected( slotObserver, callback );
1139 Control& GetImplementation( Dali::Toolkit::Control& handle )
1141 CustomActorImpl& customInterface = handle.GetImplementation();
1142 // downcast to control
1143 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
1147 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
1149 const CustomActorImpl& customInterface = handle.GetImplementation();
1150 // downcast to control
1151 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
1155 } // namespace Internal
1157 } // namespace Toolkit