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 const char * const COLOR_RENDERER_COLOR_NAME("blendColor");
168 } // unnamed namespace
173 class Control::Impl : public ConnectionTracker
177 // Construction & Destruction
178 Impl(Control& controlImpl)
179 : mControlImpl( controlImpl ),
181 mBackgroundRenderer(),
182 mStartingPinchScale( NULL ),
184 mPinchGestureDetector(),
185 mPanGestureDetector(),
186 mTapGestureDetector(),
187 mLongPressGestureDetector(),
188 mFlags( Control::ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ),
189 mIsKeyboardNavigationSupported( false ),
190 mIsKeyboardFocusGroup( false )
196 // All gesture detectors will be destroyed so no need to disconnect.
197 delete mStartingPinchScale;
200 // Gesture Detection Methods
202 void PinchDetected(Actor actor, const PinchGesture& pinch)
204 mControlImpl.OnPinch(pinch);
207 void PanDetected(Actor actor, const PanGesture& pan)
209 mControlImpl.OnPan(pan);
212 void TapDetected(Actor actor, const TapGesture& tap)
214 mControlImpl.OnTap(tap);
217 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
219 mControlImpl.OnLongPress(longPress);
225 * Called when a property of an object of this type is set.
226 * @param[in] object The object whose property is set.
227 * @param[in] index The property index.
228 * @param[in] value The new property value.
230 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
232 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
236 Control& controlImpl( GetImplementation( control ) );
240 case Toolkit::Control::Property::STYLE_NAME:
242 controlImpl.SetStyleName( value.Get< std::string >() );
246 case Toolkit::Control::Property::BACKGROUND_COLOR:
248 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
249 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
253 case Toolkit::Control::Property::BACKGROUND_IMAGE:
255 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
256 Image image = Scripting::NewImage( value );
259 controlImpl.SetBackgroundImage( image );
263 // An empty map means the background is no longer required
264 controlImpl.ClearBackground();
269 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
271 if ( value.Get< bool >() )
273 controlImpl.SetKeyInputFocus();
277 controlImpl.ClearKeyInputFocus();
282 case Toolkit::Control::Property::BACKGROUND:
284 const Property::Map* map = value.GetMap();
287 controlImpl.SetBackground( *map );
291 // The background is not a property map, so we should clear the background
292 controlImpl.ClearBackground();
301 * Called to retrieve a property of an object of this type.
302 * @param[in] object The object whose property is to be retrieved.
303 * @param[in] index The property index.
304 * @return The current value of the property.
306 static Property::Value GetProperty( BaseObject* object, Property::Index index )
308 Property::Value value;
310 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
314 Control& controlImpl( GetImplementation( control ) );
318 case Toolkit::Control::Property::STYLE_NAME:
320 value = controlImpl.GetStyleName();
324 case Toolkit::Control::Property::BACKGROUND_COLOR:
326 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
327 value = controlImpl.GetBackgroundColor();
331 case Toolkit::Control::Property::BACKGROUND_IMAGE:
333 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
335 if( controlImpl.mImpl->mBackgroundRenderer )
337 controlImpl.mImpl->mBackgroundRenderer.CreatePropertyMap( map );
343 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
345 value = controlImpl.HasKeyInputFocus();
349 case Toolkit::Control::Property::BACKGROUND:
352 if( controlImpl.mImpl->mBackgroundRenderer )
354 (controlImpl.mImpl->mBackgroundRenderer).CreatePropertyMap( map );
369 Control& mControlImpl;
370 std::string mStyleName;
371 Toolkit::ControlRenderer mBackgroundRenderer; ///< The control renderer to render the background
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 Actor self( Self() );
445 Toolkit::RendererFactory factory = Toolkit::RendererFactory::Get();
446 factory.ResetRenderer( mImpl->mBackgroundRenderer, self, color );
447 mImpl->mBackgroundRenderer.SetDepthIndex( DepthIndex::BACKGROUND );
450 Vector4 Control::GetBackgroundColor() const
452 if( mImpl->mBackgroundRenderer && ( &typeid( GetImplementation(mImpl->mBackgroundRenderer) ) == &typeid( ColorRenderer ) ) )
455 mImpl->mBackgroundRenderer.CreatePropertyMap( map );
456 const Property::Value* colorValue = map.Find( COLOR_RENDERER_COLOR_NAME );
458 if( colorValue && colorValue->Get(color))
464 return Color::TRANSPARENT;
467 void Control::SetBackground(const Property::Map& map)
469 Actor self( Self() );
470 mImpl->mBackgroundRenderer.RemoveAndReset( self );
471 Toolkit::RendererFactory factory = Toolkit::RendererFactory::Get();
472 mImpl->mBackgroundRenderer = factory.GetControlRenderer( map );
473 if( mImpl->mBackgroundRenderer && self.OnStage() ) // Request control renderer with a property map might return an empty handle
475 mImpl->mBackgroundRenderer.SetDepthIndex( DepthIndex::BACKGROUND );
476 mImpl->mBackgroundRenderer.SetOnStage( self );
480 void Control::SetBackgroundImage( Image image )
482 Actor self( Self() );
483 Toolkit::RendererFactory factory = Toolkit::RendererFactory::Get();
484 factory.ResetRenderer( mImpl->mBackgroundRenderer, self, image );
485 mImpl->mBackgroundRenderer.SetDepthIndex( DepthIndex::BACKGROUND );
488 void Control::ClearBackground()
490 Actor self( Self() );
491 mImpl->mBackgroundRenderer.RemoveAndReset( self );
494 void Control::EnableGestureDetection(Gesture::Type type)
496 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
498 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
499 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
500 mImpl->mPinchGestureDetector.Attach(Self());
503 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
505 mImpl->mPanGestureDetector = PanGestureDetector::New();
506 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
507 mImpl->mPanGestureDetector.Attach(Self());
510 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
512 mImpl->mTapGestureDetector = TapGestureDetector::New();
513 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
514 mImpl->mTapGestureDetector.Attach(Self());
517 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
519 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
520 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
521 mImpl->mLongPressGestureDetector.Attach(Self());
525 void Control::DisableGestureDetection(Gesture::Type type)
527 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
529 mImpl->mPinchGestureDetector.Detach(Self());
530 mImpl->mPinchGestureDetector.Reset();
533 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
535 mImpl->mPanGestureDetector.Detach(Self());
536 mImpl->mPanGestureDetector.Reset();
539 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
541 mImpl->mTapGestureDetector.Detach(Self());
542 mImpl->mTapGestureDetector.Reset();
545 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
547 mImpl->mLongPressGestureDetector.Detach(Self());
548 mImpl->mLongPressGestureDetector.Reset();
552 PinchGestureDetector Control::GetPinchGestureDetector() const
554 return mImpl->mPinchGestureDetector;
557 PanGestureDetector Control::GetPanGestureDetector() const
559 return mImpl->mPanGestureDetector;
562 TapGestureDetector Control::GetTapGestureDetector() const
564 return mImpl->mTapGestureDetector;
567 LongPressGestureDetector Control::GetLongPressGestureDetector() const
569 return mImpl->mLongPressGestureDetector;
572 void Control::SetKeyboardNavigationSupport(bool isSupported)
574 mImpl->mIsKeyboardNavigationSupported = isSupported;
577 bool Control::IsKeyboardNavigationSupported()
579 return mImpl->mIsKeyboardNavigationSupported;
582 void Control::SetKeyInputFocus()
584 if( Self().OnStage() )
586 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
590 bool Control::HasKeyInputFocus()
593 if( Self().OnStage() )
595 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
600 void Control::ClearKeyInputFocus()
602 if( Self().OnStage() )
604 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
608 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
610 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
612 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
613 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
616 bool Control::IsKeyboardFocusGroup()
618 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
621 void Control::AccessibilityActivate()
623 // Inform deriving classes
624 OnAccessibilityActivated();
627 void Control::KeyboardEnter()
629 // Inform deriving classes
633 bool Control::OnAccessibilityActivated()
635 return false; // Accessibility activation is not handled by default
638 bool Control::OnKeyboardEnter()
640 return false; // Keyboard enter is not handled by default
643 bool Control::OnAccessibilityPan(PanGesture gesture)
645 return false; // Accessibility pan gesture is not handled by default
648 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
650 return false; // Accessibility touch event is not handled by default
653 bool Control::OnAccessibilityValueChange(bool isIncrease)
655 return false; // Accessibility value change action is not handled by default
658 bool Control::OnAccessibilityZoom()
660 return false; // Accessibility zoom action is not handled by default
663 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
668 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
672 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
674 return mImpl->mKeyEventSignal;
677 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusGainedSignal()
679 return mImpl->mKeyInputFocusGainedSignal;
682 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusLostSignal()
684 return mImpl->mKeyInputFocusLostSignal;
687 bool Control::EmitKeyEventSignal( const KeyEvent& event )
689 // Guard against destruction during signal emission
690 Dali::Toolkit::Control handle( GetOwner() );
692 bool consumed = false;
694 // signals are allocated dynamically when someone connects
695 if ( !mImpl->mKeyEventSignal.Empty() )
697 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
702 // Notification for derived classes
703 consumed = OnKeyEvent(event);
709 Control::Control( ControlBehaviour behaviourFlags )
710 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
711 mImpl(new Impl(*this))
713 mImpl->mFlags = behaviourFlags;
716 void Control::Initialize()
718 // Call deriving classes so initialised before styling is applied to them.
721 if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
723 Toolkit::StyleManager styleManager = StyleManager::Get();
725 // if stylemanager is available
728 StyleManager& styleManagerImpl = GetImpl( styleManager );
730 // Register for style changes
731 styleManagerImpl.ControlStyleChangeSignal().Connect( this, &Control::OnStyleChange );
733 // Apply the current style
734 styleManagerImpl.ApplyThemeStyleAtInit( Toolkit::Control( GetOwner() ) );
738 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
740 SetKeyboardNavigationSupport( true );
744 void Control::OnInitialize()
748 void Control::OnControlChildAdd( Actor& child )
752 void Control::OnControlChildRemove( Actor& child )
756 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
758 // By default the control is only interested in theme (not font) changes
759 if( styleManager && change == StyleChange::THEME_CHANGE )
761 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
765 void Control::OnPinch(const PinchGesture& pinch)
767 if( !( mImpl->mStartingPinchScale ) )
770 mImpl->mStartingPinchScale = new Vector3;
773 if( pinch.state == Gesture::Started )
775 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
778 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
781 void Control::OnPan( const PanGesture& pan )
785 void Control::OnTap(const TapGesture& tap)
789 void Control::OnLongPress( const LongPressGesture& longPress )
793 void Control::EmitKeyInputFocusSignal( bool focusGained )
795 Dali::Toolkit::Control handle( GetOwner() );
799 // signals are allocated dynamically when someone connects
800 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
802 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
807 // signals are allocated dynamically when someone connects
808 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
810 mImpl->mKeyInputFocusLostSignal.Emit( handle );
815 void Control::OnStageConnection( int depth )
817 if( mImpl->mBackgroundRenderer)
819 Actor self( Self() );
820 mImpl->mBackgroundRenderer.SetOnStage( self );
824 void Control::OnStageDisconnection()
826 if( mImpl->mBackgroundRenderer )
828 Actor self( Self() );
829 mImpl->mBackgroundRenderer.SetOffStage( self );
833 void Control::OnKeyInputFocusGained()
835 EmitKeyInputFocusSignal( true );
838 void Control::OnKeyInputFocusLost()
840 EmitKeyInputFocusSignal( false );
843 void Control::OnChildAdd(Actor& child)
845 // Notify derived classes.
846 OnControlChildAdd( child );
849 void Control::OnChildRemove(Actor& child)
851 // Notify derived classes.
852 OnControlChildRemove( child );
855 void Control::OnSizeSet(const Vector3& targetSize)
857 if( mImpl->mBackgroundRenderer )
859 Vector2 size( targetSize );
860 mImpl->mBackgroundRenderer.SetSize( size );
864 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
866 // @todo size negotiate background to new size, animate as well?
869 bool Control::OnTouchEvent(const TouchEvent& event)
871 return false; // Do not consume
874 bool Control::OnHoverEvent(const HoverEvent& event)
876 return false; // Do not consume
879 bool Control::OnKeyEvent(const KeyEvent& event)
881 return false; // Do not consume
884 bool Control::OnWheelEvent(const WheelEvent& event)
886 return false; // Do not consume
889 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
891 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
893 container.Add( Self().GetChildAt( i ), size );
897 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
901 Vector3 Control::GetNaturalSize()
903 if( mImpl->mBackgroundRenderer )
906 mImpl->mBackgroundRenderer.GetNaturalSize(naturalSize);
907 return Vector3(naturalSize);
909 return Vector3::ZERO;
912 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
914 return CalculateChildSizeBase( child, dimension );
917 float Control::GetHeightForWidth( float width )
919 return GetHeightForWidthBase( width );
922 float Control::GetWidthForHeight( float height )
924 return GetWidthForHeightBase( height );
927 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
929 return RelayoutDependentOnChildrenBase( dimension );
932 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
936 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
940 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
942 mImpl->SignalConnected( slotObserver, callback );
945 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
947 mImpl->SignalDisconnected( slotObserver, callback );
950 Control& GetImplementation( Dali::Toolkit::Control& handle )
952 CustomActorImpl& customInterface = handle.GetImplementation();
953 // downcast to control
954 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
958 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
960 const CustomActorImpl& customInterface = handle.GetImplementation();
961 // downcast to control
962 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
966 } // namespace Internal
968 } // namespace Toolkit