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/animation/constraint.h>
26 #include <dali/public-api/animation/constraints.h>
27 #include <dali/public-api/object/type-registry.h>
28 #include <dali/public-api/size-negotiation/relayout-container.h>
29 #include <dali/devel-api/object/type-registry-helper.h>
30 #include <dali/devel-api/rendering/renderer.h>
31 #include <dali/devel-api/scripting/scripting.h>
32 #include <dali/integration-api/debug.h>
35 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
36 #include <dali-toolkit/public-api/controls/control.h>
37 #include <dali-toolkit/public-api/styling/style-manager.h>
38 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
39 #include <dali-toolkit/devel-api/controls/renderer-factory/renderer-factory.h>
40 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
41 #include <dali-toolkit/internal/styling/style-manager-impl.h>
42 #include <dali-toolkit/internal/controls/renderers/color/color-renderer.h>
54 * Creates control through type registry
58 return Internal::Control::New();
62 * Performs actions as requested using the action name.
63 * @param[in] object The object on which to perform the action.
64 * @param[in] actionName The action to perform.
65 * @param[in] attributes The attributes with which to perfrom this action.
66 * @return true if action has been accepted by this control
68 const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibilityActivated";
69 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
73 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ) )
75 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
78 // if cast succeeds there is an implementation so no need to check
79 ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
87 * Connects a callback function with the object's signals.
88 * @param[in] object The object providing the signal.
89 * @param[in] tracker Used to disconnect the signal.
90 * @param[in] signalName The signal to connect to.
91 * @param[in] functor A newly allocated FunctorDelegate.
92 * @return True if the signal was connected.
93 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
95 const char* SIGNAL_KEY_EVENT = "keyEvent";
96 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "keyInputFocusGained";
97 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "keyInputFocusLost";
98 const char* SIGNAL_TAPPED = "tapped";
99 const char* SIGNAL_PANNED = "panned";
100 const char* SIGNAL_PINCHED = "pinched";
101 const char* SIGNAL_LONG_PRESSED = "longPressed";
102 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
104 Dali::BaseHandle handle( object );
106 bool connected( false );
107 Toolkit::Control control = Toolkit::Control::DownCast( handle );
110 Internal::Control& controlImpl( Internal::GetImplementation( control ) );
113 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
115 controlImpl.KeyEventSignal().Connect( tracker, functor );
117 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
119 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
121 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
123 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
125 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
127 controlImpl.EnableGestureDetection( Gesture::Tap );
128 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
130 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
132 controlImpl.EnableGestureDetection( Gesture::Pan );
133 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
135 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
137 controlImpl.EnableGestureDetection( Gesture::Pinch );
138 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
140 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
142 controlImpl.EnableGestureDetection( Gesture::LongPress );
143 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
149 // Setup signals and actions using the type-registry.
150 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
152 // Note: Properties are registered separately below.
154 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
155 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
156 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
157 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
158 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
159 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
160 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
162 TypeAction registerAction( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &DoAction );
164 DALI_TYPE_REGISTRATION_END()
166 } // unnamed namespace
171 class Control::Impl : public ConnectionTracker
175 // Construction & Destruction
176 Impl(Control& controlImpl)
177 : mControlImpl( controlImpl ),
179 mBackgroundRenderer(),
180 mBackgroundColor(Color::TRANSPARENT),
181 mStartingPinchScale( NULL ),
183 mPinchGestureDetector(),
184 mPanGestureDetector(),
185 mTapGestureDetector(),
186 mLongPressGestureDetector(),
187 mFlags( Control::ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ),
188 mIsKeyboardNavigationSupported( false ),
189 mIsKeyboardFocusGroup( false )
195 // All gesture detectors will be destroyed so no need to disconnect.
196 delete mStartingPinchScale;
199 // Gesture Detection Methods
201 void PinchDetected(Actor actor, const PinchGesture& pinch)
203 mControlImpl.OnPinch(pinch);
206 void PanDetected(Actor actor, const PanGesture& pan)
208 mControlImpl.OnPan(pan);
211 void TapDetected(Actor actor, const TapGesture& tap)
213 mControlImpl.OnTap(tap);
216 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
218 mControlImpl.OnLongPress(longPress);
224 * Called when a property of an object of this type is set.
225 * @param[in] object The object whose property is set.
226 * @param[in] index The property index.
227 * @param[in] value The new property value.
229 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
231 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
235 Control& controlImpl( GetImplementation( control ) );
239 case Toolkit::Control::Property::STYLE_NAME:
241 controlImpl.SetStyleName( value.Get< std::string >() );
245 case Toolkit::Control::Property::BACKGROUND_COLOR:
247 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
248 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
252 case Toolkit::Control::Property::BACKGROUND_IMAGE:
254 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
255 Image image = Scripting::NewImage( value );
258 controlImpl.SetBackgroundImage( image );
262 // An empty map means the background is no longer required
263 controlImpl.ClearBackground();
268 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
270 if ( value.Get< bool >() )
272 controlImpl.SetKeyInputFocus();
276 controlImpl.ClearKeyInputFocus();
281 case Toolkit::Control::Property::BACKGROUND:
283 const Property::Map* map = value.GetMap();
286 controlImpl.SetBackground( *map );
290 // The background is not a property map, so we should clear the background
291 controlImpl.ClearBackground();
300 * Called to retrieve a property of an object of this type.
301 * @param[in] object The object whose property is to be retrieved.
302 * @param[in] index The property index.
303 * @return The current value of the property.
305 static Property::Value GetProperty( BaseObject* object, Property::Index index )
307 Property::Value value;
309 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
313 Control& controlImpl( GetImplementation( control ) );
317 case Toolkit::Control::Property::STYLE_NAME:
319 value = controlImpl.GetStyleName();
323 case Toolkit::Control::Property::BACKGROUND_COLOR:
325 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
326 value = controlImpl.GetBackgroundColor();
330 case Toolkit::Control::Property::BACKGROUND_IMAGE:
332 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
334 if( controlImpl.mImpl->mBackgroundRenderer )
336 controlImpl.mImpl->mBackgroundRenderer.CreatePropertyMap( map );
342 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
344 value = controlImpl.HasKeyInputFocus();
348 case Toolkit::Control::Property::BACKGROUND:
351 if( controlImpl.mImpl->mBackgroundRenderer )
353 (controlImpl.mImpl->mBackgroundRenderer).CreatePropertyMap( map );
368 Control& mControlImpl;
369 std::string mStyleName;
370 Toolkit::ControlRenderer mBackgroundRenderer; ///< The control renderer to render the background
371 Vector4 mBackgroundColor; ///< The color of the background renderer
372 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
373 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
374 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
375 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
378 PinchGestureDetector mPinchGestureDetector;
379 PanGestureDetector mPanGestureDetector;
380 TapGestureDetector mTapGestureDetector;
381 LongPressGestureDetector mLongPressGestureDetector;
383 ControlBehaviour mFlags :CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
384 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
385 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
387 // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
388 static const PropertyRegistration PROPERTY_1;
389 static const PropertyRegistration PROPERTY_2;
390 static const PropertyRegistration PROPERTY_3;
391 static const PropertyRegistration PROPERTY_4;
392 static const PropertyRegistration PROPERTY_5;
395 // Properties registered without macro to use specific member variables.
396 const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
397 const PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "backgroundColor", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
398 const PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "backgroundImage", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
399 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
400 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
402 Toolkit::Control Control::New()
404 // Create the implementation, temporarily owned on stack
405 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) );
407 // Pass ownership to handle
408 Toolkit::Control handle( *controlImpl );
410 // Second-phase init of the implementation
411 // This can only be done after the CustomActor connection has been made...
412 controlImpl->Initialize();
422 void Control::SetStyleName( const std::string& styleName )
424 if( styleName != mImpl->mStyleName )
426 mImpl->mStyleName = styleName;
428 // Apply new style, if stylemanager is available
429 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
432 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
437 const std::string& Control::GetStyleName() const
439 return mImpl->mStyleName;
442 void Control::SetBackgroundColor( const Vector4& color )
444 mImpl->mBackgroundColor = color;
446 Actor self( Self() );
447 Toolkit::RendererFactory factory = Toolkit::RendererFactory::Get();
448 factory.ResetRenderer( mImpl->mBackgroundRenderer, self, color );
449 mImpl->mBackgroundRenderer.SetDepthIndex( DepthIndex::BACKGROUND );
452 Vector4 Control::GetBackgroundColor() const
454 return mImpl->mBackgroundColor;
457 void Control::SetBackground(const Property::Map& map)
459 Actor self( Self() );
460 mImpl->mBackgroundRenderer.RemoveAndReset( self );
461 Toolkit::RendererFactory factory = Toolkit::RendererFactory::Get();
462 mImpl->mBackgroundRenderer = factory.GetControlRenderer( map );
463 if( mImpl->mBackgroundRenderer && self.OnStage() ) // Request control renderer with a property map might return an empty handle
465 mImpl->mBackgroundRenderer.SetDepthIndex( DepthIndex::BACKGROUND );
466 mImpl->mBackgroundRenderer.SetOnStage( self );
470 void Control::SetBackgroundImage( Image image )
472 Actor self( Self() );
473 Toolkit::RendererFactory factory = Toolkit::RendererFactory::Get();
474 factory.ResetRenderer( mImpl->mBackgroundRenderer, self, image );
475 mImpl->mBackgroundRenderer.SetDepthIndex( DepthIndex::BACKGROUND );
478 void Control::ClearBackground()
480 Actor self( Self() );
481 mImpl->mBackgroundRenderer.RemoveAndReset( self );
484 void Control::EnableGestureDetection(Gesture::Type type)
486 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
488 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
489 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
490 mImpl->mPinchGestureDetector.Attach(Self());
493 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
495 mImpl->mPanGestureDetector = PanGestureDetector::New();
496 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
497 mImpl->mPanGestureDetector.Attach(Self());
500 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
502 mImpl->mTapGestureDetector = TapGestureDetector::New();
503 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
504 mImpl->mTapGestureDetector.Attach(Self());
507 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
509 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
510 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
511 mImpl->mLongPressGestureDetector.Attach(Self());
515 void Control::DisableGestureDetection(Gesture::Type type)
517 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
519 mImpl->mPinchGestureDetector.Detach(Self());
520 mImpl->mPinchGestureDetector.Reset();
523 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
525 mImpl->mPanGestureDetector.Detach(Self());
526 mImpl->mPanGestureDetector.Reset();
529 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
531 mImpl->mTapGestureDetector.Detach(Self());
532 mImpl->mTapGestureDetector.Reset();
535 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
537 mImpl->mLongPressGestureDetector.Detach(Self());
538 mImpl->mLongPressGestureDetector.Reset();
542 PinchGestureDetector Control::GetPinchGestureDetector() const
544 return mImpl->mPinchGestureDetector;
547 PanGestureDetector Control::GetPanGestureDetector() const
549 return mImpl->mPanGestureDetector;
552 TapGestureDetector Control::GetTapGestureDetector() const
554 return mImpl->mTapGestureDetector;
557 LongPressGestureDetector Control::GetLongPressGestureDetector() const
559 return mImpl->mLongPressGestureDetector;
562 void Control::SetKeyboardNavigationSupport(bool isSupported)
564 mImpl->mIsKeyboardNavigationSupported = isSupported;
567 bool Control::IsKeyboardNavigationSupported()
569 return mImpl->mIsKeyboardNavigationSupported;
572 void Control::SetKeyInputFocus()
574 if( Self().OnStage() )
576 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
580 bool Control::HasKeyInputFocus()
583 if( Self().OnStage() )
585 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
590 void Control::ClearKeyInputFocus()
592 if( Self().OnStage() )
594 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
598 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
600 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
602 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
603 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
606 bool Control::IsKeyboardFocusGroup()
608 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
611 void Control::AccessibilityActivate()
613 // Inform deriving classes
614 OnAccessibilityActivated();
617 void Control::KeyboardEnter()
619 // Inform deriving classes
623 bool Control::OnAccessibilityActivated()
625 return false; // Accessibility activation is not handled by default
628 bool Control::OnKeyboardEnter()
630 return false; // Keyboard enter is not handled by default
633 bool Control::OnAccessibilityPan(PanGesture gesture)
635 return false; // Accessibility pan gesture is not handled by default
638 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
640 return false; // Accessibility touch event is not handled by default
643 bool Control::OnAccessibilityValueChange(bool isIncrease)
645 return false; // Accessibility value change action is not handled by default
648 bool Control::OnAccessibilityZoom()
650 return false; // Accessibility zoom action is not handled by default
653 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
658 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
662 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
664 return mImpl->mKeyEventSignal;
667 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusGainedSignal()
669 return mImpl->mKeyInputFocusGainedSignal;
672 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusLostSignal()
674 return mImpl->mKeyInputFocusLostSignal;
677 bool Control::EmitKeyEventSignal( const KeyEvent& event )
679 // Guard against destruction during signal emission
680 Dali::Toolkit::Control handle( GetOwner() );
682 bool consumed = false;
684 // signals are allocated dynamically when someone connects
685 if ( !mImpl->mKeyEventSignal.Empty() )
687 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
692 // Notification for derived classes
693 consumed = OnKeyEvent(event);
699 Control::Control( ControlBehaviour behaviourFlags )
700 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
701 mImpl(new Impl(*this))
703 mImpl->mFlags = behaviourFlags;
706 void Control::Initialize()
708 // Call deriving classes so initialised before styling is applied to them.
711 if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
713 Toolkit::StyleManager styleManager = StyleManager::Get();
715 // if stylemanager is available
718 StyleManager& styleManagerImpl = GetImpl( styleManager );
720 // Register for style changes
721 styleManagerImpl.ControlStyleChangeSignal().Connect( this, &Control::OnStyleChange );
723 // Apply the current style
724 styleManagerImpl.ApplyThemeStyleAtInit( Toolkit::Control( GetOwner() ) );
728 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
730 SetKeyboardNavigationSupport( true );
734 void Control::OnInitialize()
738 void Control::OnControlChildAdd( Actor& child )
742 void Control::OnControlChildRemove( Actor& child )
746 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
748 // By default the control is only interested in theme (not font) changes
749 if( styleManager && change == StyleChange::THEME_CHANGE )
751 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
755 void Control::OnPinch(const PinchGesture& pinch)
757 if( !( mImpl->mStartingPinchScale ) )
760 mImpl->mStartingPinchScale = new Vector3;
763 if( pinch.state == Gesture::Started )
765 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
768 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
771 void Control::OnPan( const PanGesture& pan )
775 void Control::OnTap(const TapGesture& tap)
779 void Control::OnLongPress( const LongPressGesture& longPress )
783 void Control::EmitKeyInputFocusSignal( bool focusGained )
785 Dali::Toolkit::Control handle( GetOwner() );
789 // signals are allocated dynamically when someone connects
790 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
792 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
797 // signals are allocated dynamically when someone connects
798 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
800 mImpl->mKeyInputFocusLostSignal.Emit( handle );
805 void Control::OnStageConnection( int depth )
807 if( mImpl->mBackgroundRenderer)
809 Actor self( Self() );
810 mImpl->mBackgroundRenderer.SetOnStage( self );
814 void Control::OnStageDisconnection()
816 if( mImpl->mBackgroundRenderer )
818 Actor self( Self() );
819 mImpl->mBackgroundRenderer.SetOffStage( self );
823 void Control::OnKeyInputFocusGained()
825 EmitKeyInputFocusSignal( true );
828 void Control::OnKeyInputFocusLost()
830 EmitKeyInputFocusSignal( false );
833 void Control::OnChildAdd(Actor& child)
835 // Notify derived classes.
836 OnControlChildAdd( child );
839 void Control::OnChildRemove(Actor& child)
841 // Notify derived classes.
842 OnControlChildRemove( child );
845 void Control::OnSizeSet(const Vector3& targetSize)
847 if( mImpl->mBackgroundRenderer )
849 Vector2 size( targetSize );
850 mImpl->mBackgroundRenderer.SetSize( size );
854 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
856 // @todo size negotiate background to new size, animate as well?
859 bool Control::OnTouchEvent(const TouchEvent& event)
861 return false; // Do not consume
864 bool Control::OnHoverEvent(const HoverEvent& event)
866 return false; // Do not consume
869 bool Control::OnKeyEvent(const KeyEvent& event)
871 return false; // Do not consume
874 bool Control::OnWheelEvent(const WheelEvent& event)
876 return false; // Do not consume
879 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
881 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
883 container.Add( Self().GetChildAt( i ), size );
887 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
891 Vector3 Control::GetNaturalSize()
893 if( mImpl->mBackgroundRenderer )
896 mImpl->mBackgroundRenderer.GetNaturalSize(naturalSize);
897 return Vector3(naturalSize);
899 return Vector3::ZERO;
902 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
904 return CalculateChildSizeBase( child, dimension );
907 float Control::GetHeightForWidth( float width )
909 return GetHeightForWidthBase( width );
912 float Control::GetWidthForHeight( float height )
914 return GetWidthForHeightBase( height );
917 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
919 return RelayoutDependentOnChildrenBase( dimension );
922 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
926 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
930 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
932 mImpl->SignalConnected( slotObserver, callback );
935 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
937 mImpl->SignalDisconnected( slotObserver, callback );
940 Control& GetImplementation( Dali::Toolkit::Control& handle )
942 CustomActorImpl& customInterface = handle.GetImplementation();
943 // downcast to control
944 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
948 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
950 const CustomActorImpl& customInterface = handle.GetImplementation();
951 // downcast to control
952 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
956 } // namespace Internal
958 } // namespace Toolkit