2 * Copyright (c) 2016 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/object/type-registry-helper.h>
29 #include <dali/public-api/rendering/renderer.h>
30 #include <dali/public-api/size-negotiation/relayout-container.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/public-api/visuals/color-visual-properties.h>
39 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
40 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
41 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
42 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
43 #include <dali-toolkit/internal/styling/style-manager-impl.h>
44 #include <dali-toolkit/internal/visuals/color/color-visual.h>
45 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
46 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
58 * Creates control through type registry
62 return Internal::Control::New();
66 * Performs actions as requested using the action name.
67 * @param[in] object The object on which to perform the action.
68 * @param[in] actionName The action to perform.
69 * @param[in] attributes The attributes with which to perfrom this action.
70 * @return true if action has been accepted by this control
72 const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibilityActivated";
73 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
77 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ) )
79 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
82 // if cast succeeds there is an implementation so no need to check
83 ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
91 * Connects a callback function with the object's signals.
92 * @param[in] object The object providing the signal.
93 * @param[in] tracker Used to disconnect the signal.
94 * @param[in] signalName The signal to connect to.
95 * @param[in] functor A newly allocated FunctorDelegate.
96 * @return True if the signal was connected.
97 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
99 const char* SIGNAL_KEY_EVENT = "keyEvent";
100 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "keyInputFocusGained";
101 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "keyInputFocusLost";
102 const char* SIGNAL_TAPPED = "tapped";
103 const char* SIGNAL_PANNED = "panned";
104 const char* SIGNAL_PINCHED = "pinched";
105 const char* SIGNAL_LONG_PRESSED = "longPressed";
106 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
108 Dali::BaseHandle handle( object );
110 bool connected( false );
111 Toolkit::Control control = Toolkit::Control::DownCast( handle );
114 Internal::Control& controlImpl( Internal::GetImplementation( control ) );
117 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
119 controlImpl.KeyEventSignal().Connect( tracker, functor );
121 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
123 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
125 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
127 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
129 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
131 controlImpl.EnableGestureDetection( Gesture::Tap );
132 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
134 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
136 controlImpl.EnableGestureDetection( Gesture::Pan );
137 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
139 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
141 controlImpl.EnableGestureDetection( Gesture::Pinch );
142 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
144 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
146 controlImpl.EnableGestureDetection( Gesture::LongPress );
147 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
153 // Setup signals and actions using the type-registry.
154 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
156 // Note: Properties are registered separately below.
158 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
159 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
160 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
161 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
162 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
163 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
164 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
166 TypeAction registerAction( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &DoAction );
168 DALI_TYPE_REGISTRATION_END()
170 } // unnamed namespace
175 class Control::Impl : public ConnectionTracker
179 // Construction & Destruction
180 Impl(Control& controlImpl)
181 : mControlImpl( controlImpl ),
184 mBackgroundColor(Color::TRANSPARENT),
185 mStartingPinchScale( NULL ),
187 mPinchGestureDetector(),
188 mPanGestureDetector(),
189 mTapGestureDetector(),
190 mLongPressGestureDetector(),
191 mFlags( Control::ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
192 mIsKeyboardNavigationSupported( false ),
193 mIsKeyboardFocusGroup( false )
199 // All gesture detectors will be destroyed so no need to disconnect.
200 delete mStartingPinchScale;
203 // Gesture Detection Methods
205 void PinchDetected(Actor actor, const PinchGesture& pinch)
207 mControlImpl.OnPinch(pinch);
210 void PanDetected(Actor actor, const PanGesture& pan)
212 mControlImpl.OnPan(pan);
215 void TapDetected(Actor actor, const TapGesture& tap)
217 mControlImpl.OnTap(tap);
220 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
222 mControlImpl.OnLongPress(longPress);
228 * Called when a property of an object of this type is set.
229 * @param[in] object The object whose property is set.
230 * @param[in] index The property index.
231 * @param[in] value The new property value.
233 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
235 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
239 Control& controlImpl( GetImplementation( control ) );
243 case Toolkit::Control::Property::STYLE_NAME:
245 controlImpl.SetStyleName( value.Get< std::string >() );
249 case Toolkit::Control::Property::BACKGROUND_COLOR:
251 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
252 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
256 case Toolkit::Control::Property::BACKGROUND_IMAGE:
258 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
259 Image image = Scripting::NewImage( value );
262 controlImpl.SetBackgroundImage( image );
266 // An empty map means the background is no longer required
267 controlImpl.ClearBackground();
272 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
274 if ( value.Get< bool >() )
276 controlImpl.SetKeyInputFocus();
280 controlImpl.ClearKeyInputFocus();
285 case Toolkit::Control::Property::BACKGROUND:
287 const Property::Map* map = value.GetMap();
290 controlImpl.SetBackground( *map );
294 // The background is not a property map, so we should clear the background
295 controlImpl.ClearBackground();
304 * Called to retrieve a property of an object of this type.
305 * @param[in] object The object whose property is to be retrieved.
306 * @param[in] index The property index.
307 * @return The current value of the property.
309 static Property::Value GetProperty( BaseObject* object, Property::Index index )
311 Property::Value value;
313 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
317 Control& controlImpl( GetImplementation( control ) );
321 case Toolkit::Control::Property::STYLE_NAME:
323 value = controlImpl.GetStyleName();
327 case Toolkit::Control::Property::BACKGROUND_COLOR:
329 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
330 value = controlImpl.GetBackgroundColor();
334 case Toolkit::Control::Property::BACKGROUND_IMAGE:
336 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
338 if( controlImpl.mImpl->mBackgroundVisual )
340 controlImpl.mImpl->mBackgroundVisual.CreatePropertyMap( map );
346 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
348 value = controlImpl.HasKeyInputFocus();
352 case Toolkit::Control::Property::BACKGROUND:
355 if( controlImpl.mImpl->mBackgroundVisual )
357 (controlImpl.mImpl->mBackgroundVisual).CreatePropertyMap( map );
372 Control& mControlImpl;
373 std::string mStyleName;
374 Toolkit::Visual::Base mBackgroundVisual; ///< The visual to render the background
375 Vector4 mBackgroundColor; ///< The color of the background visual
376 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
377 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
378 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
379 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
382 PinchGestureDetector mPinchGestureDetector;
383 PanGestureDetector mPanGestureDetector;
384 TapGestureDetector mTapGestureDetector;
385 LongPressGestureDetector mLongPressGestureDetector;
387 ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
388 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
389 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
391 // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
392 static const PropertyRegistration PROPERTY_1;
393 static const PropertyRegistration PROPERTY_2;
394 static const PropertyRegistration PROPERTY_3;
395 static const PropertyRegistration PROPERTY_4;
396 static const PropertyRegistration PROPERTY_5;
399 // Properties registered without macro to use specific member variables.
400 const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
401 const PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "backgroundColor", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
402 const PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "backgroundImage", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
403 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
404 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
406 Toolkit::Control Control::New()
408 // Create the implementation, temporarily owned on stack
409 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) );
411 // Pass ownership to handle
412 Toolkit::Control handle( *controlImpl );
414 // Second-phase init of the implementation
415 // This can only be done after the CustomActor connection has been made...
416 controlImpl->Initialize();
421 void Control::SetStyleName( const std::string& styleName )
423 if( styleName != mImpl->mStyleName )
425 mImpl->mStyleName = styleName;
427 // Apply new style, if stylemanager is available
428 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
431 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
436 const std::string& Control::GetStyleName() const
438 return mImpl->mStyleName;
441 void Control::SetBackgroundColor( const Vector4& color )
443 Actor self( Self() );
444 mImpl->mBackgroundColor = color;
446 map[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::COLOR;
447 map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color;
448 InitializeVisual( self, mImpl->mBackgroundVisual, map );
449 if( mImpl->mBackgroundVisual )
451 mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND );
455 Vector4 Control::GetBackgroundColor() const
457 return mImpl->mBackgroundColor;
460 void Control::SetBackground( const Property::Map& map )
462 Actor self( Self() );
463 Toolkit::Visual::Base backgroundVisual = Toolkit::VisualFactory::Get().CreateVisual( map );
465 // if new visual created, replace existing one
466 if( backgroundVisual )
470 mImpl->mBackgroundVisual.RemoveAndReset( self );
471 backgroundVisual.SetOnStage( self );
473 mImpl->mBackgroundVisual = backgroundVisual;
474 mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND );
476 // ...otherwise process map and apply it to the existing visual
477 else if( mImpl->mBackgroundVisual )
479 Property::Value* premultipliedAlpha = map.Find( Toolkit::DevelVisual::Property::PREMULTIPLIED_ALPHA, Toolkit::Internal::PREMULTIPLIED_ALPHA );
480 if( premultipliedAlpha )
482 bool value( premultipliedAlpha->Get<bool>() );
483 Toolkit::GetImplementation( mImpl->mBackgroundVisual ).EnablePreMultipliedAlpha( value );
488 void Control::SetBackgroundImage( Image image )
490 Actor self( Self() );
491 InitializeVisual( self, mImpl->mBackgroundVisual, image );
492 if( mImpl->mBackgroundVisual )
494 mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND );
498 void Control::ClearBackground()
500 Actor self( Self() );
501 mImpl->mBackgroundVisual.RemoveAndReset( self );
502 mImpl->mBackgroundColor = Color::TRANSPARENT;
505 void Control::EnableGestureDetection(Gesture::Type type)
507 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
509 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
510 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
511 mImpl->mPinchGestureDetector.Attach(Self());
514 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
516 mImpl->mPanGestureDetector = PanGestureDetector::New();
517 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
518 mImpl->mPanGestureDetector.Attach(Self());
521 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
523 mImpl->mTapGestureDetector = TapGestureDetector::New();
524 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
525 mImpl->mTapGestureDetector.Attach(Self());
528 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
530 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
531 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
532 mImpl->mLongPressGestureDetector.Attach(Self());
536 void Control::DisableGestureDetection(Gesture::Type type)
538 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
540 mImpl->mPinchGestureDetector.Detach(Self());
541 mImpl->mPinchGestureDetector.Reset();
544 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
546 mImpl->mPanGestureDetector.Detach(Self());
547 mImpl->mPanGestureDetector.Reset();
550 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
552 mImpl->mTapGestureDetector.Detach(Self());
553 mImpl->mTapGestureDetector.Reset();
556 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
558 mImpl->mLongPressGestureDetector.Detach(Self());
559 mImpl->mLongPressGestureDetector.Reset();
563 PinchGestureDetector Control::GetPinchGestureDetector() const
565 return mImpl->mPinchGestureDetector;
568 PanGestureDetector Control::GetPanGestureDetector() const
570 return mImpl->mPanGestureDetector;
573 TapGestureDetector Control::GetTapGestureDetector() const
575 return mImpl->mTapGestureDetector;
578 LongPressGestureDetector Control::GetLongPressGestureDetector() const
580 return mImpl->mLongPressGestureDetector;
583 void Control::SetKeyboardNavigationSupport(bool isSupported)
585 mImpl->mIsKeyboardNavigationSupported = isSupported;
588 bool Control::IsKeyboardNavigationSupported()
590 return mImpl->mIsKeyboardNavigationSupported;
593 void Control::SetKeyInputFocus()
595 if( Self().OnStage() )
597 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
601 bool Control::HasKeyInputFocus()
604 if( Self().OnStage() )
606 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
611 void Control::ClearKeyInputFocus()
613 if( Self().OnStage() )
615 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
619 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
621 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
623 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
624 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
627 bool Control::IsKeyboardFocusGroup()
629 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
632 void Control::AccessibilityActivate()
634 // Inform deriving classes
635 OnAccessibilityActivated();
638 void Control::KeyboardEnter()
640 // Inform deriving classes
644 bool Control::OnAccessibilityActivated()
646 return false; // Accessibility activation is not handled by default
649 bool Control::OnKeyboardEnter()
651 return false; // Keyboard enter is not handled by default
654 bool Control::OnAccessibilityPan(PanGesture gesture)
656 return false; // Accessibility pan gesture is not handled by default
659 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
661 return false; // Accessibility touch event is not handled by default
664 bool Control::OnAccessibilityValueChange(bool isIncrease)
666 return false; // Accessibility value change action is not handled by default
669 bool Control::OnAccessibilityZoom()
671 return false; // Accessibility zoom action is not handled by default
674 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
679 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
683 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
685 return mImpl->mKeyEventSignal;
688 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusGainedSignal()
690 return mImpl->mKeyInputFocusGainedSignal;
693 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusLostSignal()
695 return mImpl->mKeyInputFocusLostSignal;
698 bool Control::EmitKeyEventSignal( const KeyEvent& event )
700 // Guard against destruction during signal emission
701 Dali::Toolkit::Control handle( GetOwner() );
703 bool consumed = false;
705 // signals are allocated dynamically when someone connects
706 if ( !mImpl->mKeyEventSignal.Empty() )
708 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
713 // Notification for derived classes
714 consumed = OnKeyEvent(event);
720 Control::Control( ControlBehaviour behaviourFlags )
721 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
722 mImpl(new Impl(*this))
724 mImpl->mFlags = behaviourFlags;
732 void Control::Initialize()
734 // Call deriving classes so initialised before styling is applied to them.
737 if( (mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS) ||
738 !(mImpl->mFlags & DISABLE_STYLE_CHANGE_SIGNALS) )
740 Toolkit::StyleManager styleManager = StyleManager::Get();
742 // if stylemanager is available
745 StyleManager& styleManagerImpl = GetImpl( styleManager );
747 // Register for style changes
748 styleManagerImpl.ControlStyleChangeSignal().Connect( this, &Control::OnStyleChange );
750 // Apply the current style
751 styleManagerImpl.ApplyThemeStyleAtInit( Toolkit::Control( GetOwner() ) );
755 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
757 SetKeyboardNavigationSupport( true );
761 void Control::OnInitialize()
765 void Control::OnControlChildAdd( Actor& child )
767 DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: OnControlChildAdd() is deprecated and will be removed from next release. Override OnChildAdd instead.\n" );
770 void Control::OnControlChildRemove( Actor& child )
772 DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: OnControlChildRemove() is deprecated and will be removed from next release. Override OnChildRemove instead.\n" );
775 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
777 // By default the control is only interested in theme (not font) changes
778 if( styleManager && change == StyleChange::THEME_CHANGE )
780 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
785 void Control::OnPinch(const PinchGesture& pinch)
787 if( !( mImpl->mStartingPinchScale ) )
790 mImpl->mStartingPinchScale = new Vector3;
793 if( pinch.state == Gesture::Started )
795 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
798 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
801 void Control::OnPan( const PanGesture& pan )
805 void Control::OnTap(const TapGesture& tap)
809 void Control::OnLongPress( const LongPressGesture& longPress )
813 void Control::EmitKeyInputFocusSignal( bool focusGained )
815 Dali::Toolkit::Control handle( GetOwner() );
819 // signals are allocated dynamically when someone connects
820 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
822 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
827 // signals are allocated dynamically when someone connects
828 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
830 mImpl->mKeyInputFocusLostSignal.Emit( handle );
835 void Control::OnStageConnection( int depth )
837 if( mImpl->mBackgroundVisual)
839 Actor self( Self() );
840 mImpl->mBackgroundVisual.SetOnStage( self );
844 void Control::OnStageDisconnection()
846 if( mImpl->mBackgroundVisual )
848 Actor self( Self() );
849 mImpl->mBackgroundVisual.SetOffStage( self );
853 void Control::OnKeyInputFocusGained()
855 EmitKeyInputFocusSignal( true );
858 void Control::OnKeyInputFocusLost()
860 EmitKeyInputFocusSignal( false );
863 void Control::OnChildAdd(Actor& child)
865 // Notify derived classes.
866 OnControlChildAdd( child );
869 void Control::OnChildRemove(Actor& child)
871 // Notify derived classes.
872 OnControlChildRemove( child );
875 void Control::OnSizeSet(const Vector3& targetSize)
877 if( mImpl->mBackgroundVisual )
879 Vector2 size( targetSize );
880 mImpl->mBackgroundVisual.SetSize( size );
884 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
886 // @todo size negotiate background to new size, animate as well?
889 bool Control::OnTouchEvent(const TouchEvent& event)
891 return false; // Do not consume
894 bool Control::OnHoverEvent(const HoverEvent& event)
896 return false; // Do not consume
899 bool Control::OnKeyEvent(const KeyEvent& event)
901 return false; // Do not consume
904 bool Control::OnWheelEvent(const WheelEvent& event)
906 return false; // Do not consume
909 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
911 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
913 container.Add( Self().GetChildAt( i ), size );
917 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
921 Vector3 Control::GetNaturalSize()
923 if( mImpl->mBackgroundVisual )
926 mImpl->mBackgroundVisual.GetNaturalSize(naturalSize);
927 return Vector3(naturalSize);
929 return Vector3::ZERO;
932 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
934 return CalculateChildSizeBase( child, dimension );
937 float Control::GetHeightForWidth( float width )
939 return GetHeightForWidthBase( width );
942 float Control::GetWidthForHeight( float height )
944 return GetWidthForHeightBase( height );
947 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
949 return RelayoutDependentOnChildrenBase( dimension );
952 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
956 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
960 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
962 mImpl->SignalConnected( slotObserver, callback );
965 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
967 mImpl->SignalDisconnected( slotObserver, callback );
970 Control& GetImplementation( Dali::Toolkit::Control& handle )
972 CustomActorImpl& customInterface = handle.GetImplementation();
973 // downcast to control
974 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
978 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
980 const CustomActorImpl& customInterface = handle.GetImplementation();
981 // downcast to control
982 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
986 } // namespace Internal
988 } // namespace Toolkit