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;
464 InitializeVisual( self, backgroundVisual, map );
466 // if new visual created, replace existing one
467 if( backgroundVisual )
469 mImpl->mBackgroundVisual = backgroundVisual;
470 mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND );
472 // ...otherwise process map and apply it to the existing visual
473 else if( mImpl->mBackgroundVisual )
475 Property::Value* premultipliedAlpha = map.Find( Toolkit::DevelVisual::Property::PREMULTIPLIED_ALPHA, Toolkit::Internal::PREMULTIPLIED_ALPHA );
476 if( premultipliedAlpha )
478 bool value( premultipliedAlpha->Get<bool>() );
479 Toolkit::GetImplementation( mImpl->mBackgroundVisual ).EnablePreMultipliedAlpha( value );
484 void Control::SetBackgroundImage( Image image )
486 Actor self( Self() );
487 InitializeVisual( self, mImpl->mBackgroundVisual, image );
488 if( mImpl->mBackgroundVisual )
490 mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND );
494 void Control::ClearBackground()
496 Actor self( Self() );
497 mImpl->mBackgroundVisual.RemoveAndReset( self );
498 mImpl->mBackgroundColor = Color::TRANSPARENT;
501 void Control::EnableGestureDetection(Gesture::Type type)
503 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
505 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
506 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
507 mImpl->mPinchGestureDetector.Attach(Self());
510 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
512 mImpl->mPanGestureDetector = PanGestureDetector::New();
513 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
514 mImpl->mPanGestureDetector.Attach(Self());
517 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
519 mImpl->mTapGestureDetector = TapGestureDetector::New();
520 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
521 mImpl->mTapGestureDetector.Attach(Self());
524 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
526 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
527 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
528 mImpl->mLongPressGestureDetector.Attach(Self());
532 void Control::DisableGestureDetection(Gesture::Type type)
534 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
536 mImpl->mPinchGestureDetector.Detach(Self());
537 mImpl->mPinchGestureDetector.Reset();
540 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
542 mImpl->mPanGestureDetector.Detach(Self());
543 mImpl->mPanGestureDetector.Reset();
546 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
548 mImpl->mTapGestureDetector.Detach(Self());
549 mImpl->mTapGestureDetector.Reset();
552 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
554 mImpl->mLongPressGestureDetector.Detach(Self());
555 mImpl->mLongPressGestureDetector.Reset();
559 PinchGestureDetector Control::GetPinchGestureDetector() const
561 return mImpl->mPinchGestureDetector;
564 PanGestureDetector Control::GetPanGestureDetector() const
566 return mImpl->mPanGestureDetector;
569 TapGestureDetector Control::GetTapGestureDetector() const
571 return mImpl->mTapGestureDetector;
574 LongPressGestureDetector Control::GetLongPressGestureDetector() const
576 return mImpl->mLongPressGestureDetector;
579 void Control::SetKeyboardNavigationSupport(bool isSupported)
581 mImpl->mIsKeyboardNavigationSupported = isSupported;
584 bool Control::IsKeyboardNavigationSupported()
586 return mImpl->mIsKeyboardNavigationSupported;
589 void Control::SetKeyInputFocus()
591 if( Self().OnStage() )
593 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
597 bool Control::HasKeyInputFocus()
600 if( Self().OnStage() )
602 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
607 void Control::ClearKeyInputFocus()
609 if( Self().OnStage() )
611 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
615 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
617 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
619 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
620 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
623 bool Control::IsKeyboardFocusGroup()
625 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
628 void Control::AccessibilityActivate()
630 // Inform deriving classes
631 OnAccessibilityActivated();
634 void Control::KeyboardEnter()
636 // Inform deriving classes
640 bool Control::OnAccessibilityActivated()
642 return false; // Accessibility activation is not handled by default
645 bool Control::OnKeyboardEnter()
647 return false; // Keyboard enter is not handled by default
650 bool Control::OnAccessibilityPan(PanGesture gesture)
652 return false; // Accessibility pan gesture is not handled by default
655 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
657 return false; // Accessibility touch event is not handled by default
660 bool Control::OnAccessibilityValueChange(bool isIncrease)
662 return false; // Accessibility value change action is not handled by default
665 bool Control::OnAccessibilityZoom()
667 return false; // Accessibility zoom action is not handled by default
670 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
675 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
679 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
681 return mImpl->mKeyEventSignal;
684 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusGainedSignal()
686 return mImpl->mKeyInputFocusGainedSignal;
689 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusLostSignal()
691 return mImpl->mKeyInputFocusLostSignal;
694 bool Control::EmitKeyEventSignal( const KeyEvent& event )
696 // Guard against destruction during signal emission
697 Dali::Toolkit::Control handle( GetOwner() );
699 bool consumed = false;
701 // signals are allocated dynamically when someone connects
702 if ( !mImpl->mKeyEventSignal.Empty() )
704 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
709 // Notification for derived classes
710 consumed = OnKeyEvent(event);
716 Control::Control( ControlBehaviour behaviourFlags )
717 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
718 mImpl(new Impl(*this))
720 mImpl->mFlags = behaviourFlags;
728 void Control::Initialize()
730 // Call deriving classes so initialised before styling is applied to them.
733 if( (mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS) ||
734 !(mImpl->mFlags & DISABLE_STYLE_CHANGE_SIGNALS) )
736 Toolkit::StyleManager styleManager = StyleManager::Get();
738 // if stylemanager is available
741 StyleManager& styleManagerImpl = GetImpl( styleManager );
743 // Register for style changes
744 styleManagerImpl.ControlStyleChangeSignal().Connect( this, &Control::OnStyleChange );
746 // Apply the current style
747 styleManagerImpl.ApplyThemeStyleAtInit( Toolkit::Control( GetOwner() ) );
751 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
753 SetKeyboardNavigationSupport( true );
757 void Control::OnInitialize()
761 void Control::OnControlChildAdd( Actor& child )
763 DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: OnControlChildAdd() is deprecated and will be removed from next release. Override OnChildAdd instead.\n" );
766 void Control::OnControlChildRemove( Actor& child )
768 DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: OnControlChildRemove() is deprecated and will be removed from next release. Override OnChildRemove instead.\n" );
771 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
773 // By default the control is only interested in theme (not font) changes
774 if( styleManager && change == StyleChange::THEME_CHANGE )
776 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
781 void Control::OnPinch(const PinchGesture& pinch)
783 if( !( mImpl->mStartingPinchScale ) )
786 mImpl->mStartingPinchScale = new Vector3;
789 if( pinch.state == Gesture::Started )
791 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
794 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
797 void Control::OnPan( const PanGesture& pan )
801 void Control::OnTap(const TapGesture& tap)
805 void Control::OnLongPress( const LongPressGesture& longPress )
809 void Control::EmitKeyInputFocusSignal( bool focusGained )
811 Dali::Toolkit::Control handle( GetOwner() );
815 // signals are allocated dynamically when someone connects
816 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
818 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
823 // signals are allocated dynamically when someone connects
824 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
826 mImpl->mKeyInputFocusLostSignal.Emit( handle );
831 void Control::OnStageConnection( int depth )
833 if( mImpl->mBackgroundVisual)
835 Actor self( Self() );
836 mImpl->mBackgroundVisual.SetOnStage( self );
840 void Control::OnStageDisconnection()
842 if( mImpl->mBackgroundVisual )
844 Actor self( Self() );
845 mImpl->mBackgroundVisual.SetOffStage( self );
849 void Control::OnKeyInputFocusGained()
851 EmitKeyInputFocusSignal( true );
854 void Control::OnKeyInputFocusLost()
856 EmitKeyInputFocusSignal( false );
859 void Control::OnChildAdd(Actor& child)
861 // Notify derived classes.
862 OnControlChildAdd( child );
865 void Control::OnChildRemove(Actor& child)
867 // Notify derived classes.
868 OnControlChildRemove( child );
871 void Control::OnSizeSet(const Vector3& targetSize)
873 if( mImpl->mBackgroundVisual )
875 Vector2 size( targetSize );
876 mImpl->mBackgroundVisual.SetSize( size );
880 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
882 // @todo size negotiate background to new size, animate as well?
885 bool Control::OnTouchEvent(const TouchEvent& event)
887 return false; // Do not consume
890 bool Control::OnHoverEvent(const HoverEvent& event)
892 return false; // Do not consume
895 bool Control::OnKeyEvent(const KeyEvent& event)
897 return false; // Do not consume
900 bool Control::OnWheelEvent(const WheelEvent& event)
902 return false; // Do not consume
905 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
907 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
909 container.Add( Self().GetChildAt( i ), size );
913 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
917 Vector3 Control::GetNaturalSize()
919 if( mImpl->mBackgroundVisual )
922 mImpl->mBackgroundVisual.GetNaturalSize(naturalSize);
923 return Vector3(naturalSize);
925 return Vector3::ZERO;
928 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
930 return CalculateChildSizeBase( child, dimension );
933 float Control::GetHeightForWidth( float width )
935 return GetHeightForWidthBase( width );
938 float Control::GetWidthForHeight( float height )
940 return GetWidthForHeightBase( height );
943 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
945 return RelayoutDependentOnChildrenBase( dimension );
948 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
952 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
956 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
958 mImpl->SignalConnected( slotObserver, callback );
961 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
963 mImpl->SignalDisconnected( slotObserver, callback );
966 Control& GetImplementation( Dali::Toolkit::Control& handle )
968 CustomActorImpl& customInterface = handle.GetImplementation();
969 // downcast to control
970 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
974 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
976 const CustomActorImpl& customInterface = handle.GetImplementation();
977 // downcast to control
978 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
982 } // namespace Internal
984 } // namespace Toolkit