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/controls/control-depth-index-ranges.h>
36 #include <dali-toolkit/devel-api/controls/renderer-factory/renderer-factory.h>
37 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
38 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
39 #include <dali-toolkit/public-api/controls/control.h>
40 #include <dali-toolkit/devel-api/styling/style-manager.h>
41 #include <dali-toolkit/internal/styling/style-manager-impl.h>
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 BACKGROUND_COLOR_NAME("color");
167 const char * const COLOR_RENDERER_COLOR_NAME("blendColor");
169 } // unnamed namespace
174 class Control::Impl : public ConnectionTracker
178 // Construction & Destruction
179 Impl(Control& controlImpl)
180 : mControlImpl( controlImpl ),
182 mBackgroundRenderer(),
183 mStartingPinchScale( NULL ),
185 mPinchGestureDetector(),
186 mPanGestureDetector(),
187 mTapGestureDetector(),
188 mLongPressGestureDetector(),
189 mFlags( Control::ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ),
190 mIsKeyboardNavigationSupported( false ),
191 mIsKeyboardFocusGroup( false ),
192 mAddRemoveBackgroundChild( false )
198 // All gesture detectors will be destroyed so no need to disconnect.
199 delete mStartingPinchScale;
202 // Gesture Detection Methods
204 void PinchDetected(Actor actor, const PinchGesture& pinch)
206 mControlImpl.OnPinch(pinch);
209 void PanDetected(Actor actor, const PanGesture& pan)
211 mControlImpl.OnPan(pan);
214 void TapDetected(Actor actor, const TapGesture& tap)
216 mControlImpl.OnTap(tap);
219 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
221 mControlImpl.OnLongPress(longPress);
227 * Called when a property of an object of this type is set.
228 * @param[in] object The object whose property is set.
229 * @param[in] index The property index.
230 * @param[in] value The new property value.
232 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
234 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
238 Control& controlImpl( GetImplementation( control ) );
242 case Toolkit::Control::Property::STYLE_NAME:
244 controlImpl.SetStyleName( value.Get< std::string >() );
248 case Toolkit::Control::Property::BACKGROUND_COLOR:
250 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
251 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
255 case Toolkit::Control::Property::BACKGROUND_IMAGE:
257 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
258 Image image = Scripting::NewImage( value );
261 controlImpl.SetBackgroundImage( image );
265 // An empty map means the background is no longer required
266 controlImpl.ClearBackground();
271 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
273 if ( value.Get< bool >() )
275 controlImpl.SetKeyInputFocus();
279 controlImpl.ClearKeyInputFocus();
284 case Toolkit::Control::Property::BACKGROUND:
286 Image image = Scripting::NewImage( value );
289 controlImpl.SetBackgroundImage( image );
292 const Property::Map* map = value.GetMap();
295 controlImpl.SetBackground( *map );
299 // The background is neither a valid image nor a property map, so it is no longer required
300 controlImpl.ClearBackground();
308 * Called to retrieve a property of an object of this type.
309 * @param[in] object The object whose property is to be retrieved.
310 * @param[in] index The property index.
311 * @return The current value of the property.
313 static Property::Value GetProperty( BaseObject* object, Property::Index index )
315 Property::Value value;
317 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
321 Control& controlImpl( GetImplementation( control ) );
325 case Toolkit::Control::Property::STYLE_NAME:
327 value = controlImpl.GetStyleName();
331 case Toolkit::Control::Property::BACKGROUND_COLOR:
333 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
334 value = controlImpl.GetBackgroundColor();
338 case Toolkit::Control::Property::BACKGROUND_IMAGE:
340 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
342 if( controlImpl.mImpl->mBackgroundRenderer )
344 controlImpl.mImpl->mBackgroundRenderer.CreatePropertyMap( map );
350 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
352 value = controlImpl.HasKeyInputFocus();
356 case Toolkit::Control::Property::BACKGROUND:
359 if( controlImpl.mImpl->mBackgroundRenderer )
361 (controlImpl.mImpl->mBackgroundRenderer).CreatePropertyMap( map );
376 Control& mControlImpl;
377 std::string mStyleName;
378 Toolkit::ControlRenderer mBackgroundRenderer; ///< The control renderer to render the background
379 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
380 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
381 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
382 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
385 PinchGestureDetector mPinchGestureDetector;
386 PanGestureDetector mPanGestureDetector;
387 TapGestureDetector mTapGestureDetector;
388 LongPressGestureDetector mLongPressGestureDetector;
390 ControlBehaviour mFlags :CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
391 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
392 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
393 bool mAddRemoveBackgroundChild:1; ///< Flag to know when we are adding or removing our own actor to avoid call to OnControlChildAdd
395 // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
396 static const PropertyRegistration PROPERTY_1;
397 static const PropertyRegistration PROPERTY_2;
398 static const PropertyRegistration PROPERTY_3;
399 static const PropertyRegistration PROPERTY_4;
400 static const PropertyRegistration PROPERTY_5;
403 // Properties registered without macro to use specific member variables.
404 const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
405 const PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "backgroundColor", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
406 const PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "backgroundImage", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
407 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
408 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
410 Toolkit::Control Control::New()
412 // Create the implementation, temporarily owned on stack
413 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) );
415 // Pass ownership to handle
416 Toolkit::Control handle( *controlImpl );
418 // Second-phase init of the implementation
419 // This can only be done after the CustomActor connection has been made...
420 controlImpl->Initialize();
430 void Control::SetStyleName( const std::string& styleName )
432 if( styleName != mImpl->mStyleName )
434 mImpl->mStyleName = styleName;
436 // Apply new style, if stylemanager is available
437 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
440 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
445 const std::string& Control::GetStyleName() const
447 return mImpl->mStyleName;
450 void Control::SetBackgroundColor( const Vector4& color )
452 Actor self( Self() );
453 Toolkit::RendererFactory factory = Toolkit::RendererFactory::Get();
454 factory.ResetRenderer( mImpl->mBackgroundRenderer, self, color );
455 mImpl->mBackgroundRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX );
458 Vector4 Control::GetBackgroundColor() const
460 if( mImpl->mBackgroundRenderer && ( &typeid( GetImplementation(mImpl->mBackgroundRenderer) ) == &typeid( ColorRenderer ) ) )
463 mImpl->mBackgroundRenderer.CreatePropertyMap( map );
464 const Property::Value* colorValue = map.Find( COLOR_RENDERER_COLOR_NAME );
466 if( colorValue && colorValue->Get(color))
472 return Color::TRANSPARENT;
475 void Control::SetBackground(const Property::Map& map)
477 const Property::Value* colorValue = map.Find( BACKGROUND_COLOR_NAME );
479 if( colorValue && colorValue->Get(color))
481 SetBackgroundColor( color );
485 Actor self( Self() );
486 mImpl->mBackgroundRenderer.RemoveAndReset( self );
487 Toolkit::RendererFactory factory = Toolkit::RendererFactory::Get();
488 mImpl->mBackgroundRenderer = factory.GetControlRenderer( map );
489 if( mImpl->mBackgroundRenderer && self.OnStage() ) // Request control renderer with a property map might return an empty handle
491 mImpl->mBackgroundRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX );
492 mImpl->mBackgroundRenderer.SetOnStage( self );
496 void Control::SetBackgroundImage( Image image )
498 Actor self( Self() );
499 Toolkit::RendererFactory factory = Toolkit::RendererFactory::Get();
500 factory.ResetRenderer( mImpl->mBackgroundRenderer, self, image );
501 mImpl->mBackgroundRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX );
504 void Control::ClearBackground()
506 Actor self( Self() );
507 mImpl->mBackgroundRenderer.RemoveAndReset( self );
510 void Control::EnableGestureDetection(Gesture::Type type)
512 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
514 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
515 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
516 mImpl->mPinchGestureDetector.Attach(Self());
519 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
521 mImpl->mPanGestureDetector = PanGestureDetector::New();
522 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
523 mImpl->mPanGestureDetector.Attach(Self());
526 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
528 mImpl->mTapGestureDetector = TapGestureDetector::New();
529 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
530 mImpl->mTapGestureDetector.Attach(Self());
533 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
535 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
536 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
537 mImpl->mLongPressGestureDetector.Attach(Self());
541 void Control::DisableGestureDetection(Gesture::Type type)
543 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
545 mImpl->mPinchGestureDetector.Detach(Self());
546 mImpl->mPinchGestureDetector.Reset();
549 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
551 mImpl->mPanGestureDetector.Detach(Self());
552 mImpl->mPanGestureDetector.Reset();
555 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
557 mImpl->mTapGestureDetector.Detach(Self());
558 mImpl->mTapGestureDetector.Reset();
561 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
563 mImpl->mLongPressGestureDetector.Detach(Self());
564 mImpl->mLongPressGestureDetector.Reset();
568 PinchGestureDetector Control::GetPinchGestureDetector() const
570 return mImpl->mPinchGestureDetector;
573 PanGestureDetector Control::GetPanGestureDetector() const
575 return mImpl->mPanGestureDetector;
578 TapGestureDetector Control::GetTapGestureDetector() const
580 return mImpl->mTapGestureDetector;
583 LongPressGestureDetector Control::GetLongPressGestureDetector() const
585 return mImpl->mLongPressGestureDetector;
588 void Control::SetKeyboardNavigationSupport(bool isSupported)
590 mImpl->mIsKeyboardNavigationSupported = isSupported;
593 bool Control::IsKeyboardNavigationSupported()
595 return mImpl->mIsKeyboardNavigationSupported;
598 void Control::SetKeyInputFocus()
600 if( Self().OnStage() )
602 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
606 bool Control::HasKeyInputFocus()
609 if( Self().OnStage() )
611 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
616 void Control::ClearKeyInputFocus()
618 if( Self().OnStage() )
620 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
624 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
626 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
628 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
629 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
632 bool Control::IsKeyboardFocusGroup()
634 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
637 void Control::AccessibilityActivate()
639 // Inform deriving classes
640 OnAccessibilityActivated();
643 void Control::KeyboardEnter()
645 // Inform deriving classes
649 bool Control::OnAccessibilityActivated()
651 return false; // Accessibility activation is not handled by default
654 bool Control::OnKeyboardEnter()
656 return false; // Keyboard enter is not handled by default
659 bool Control::OnAccessibilityPan(PanGesture gesture)
661 return false; // Accessibility pan gesture is not handled by default
664 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
666 return false; // Accessibility touch event is not handled by default
669 bool Control::OnAccessibilityValueChange(bool isIncrease)
671 return false; // Accessibility value change action is not handled by default
674 bool Control::OnAccessibilityZoom()
676 return false; // Accessibility zoom action is not handled by default
679 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
684 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
688 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
690 return mImpl->mKeyEventSignal;
693 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusGainedSignal()
695 return mImpl->mKeyInputFocusGainedSignal;
698 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusLostSignal()
700 return mImpl->mKeyInputFocusLostSignal;
703 bool Control::EmitKeyEventSignal( const KeyEvent& event )
705 // Guard against destruction during signal emission
706 Dali::Toolkit::Control handle( GetOwner() );
708 bool consumed = false;
710 // signals are allocated dynamically when someone connects
711 if ( !mImpl->mKeyEventSignal.Empty() )
713 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
718 // Notification for derived classes
719 consumed = OnKeyEvent(event);
725 Control::Control( ControlBehaviour behaviourFlags )
726 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
727 mImpl(new Impl(*this))
729 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 )
739 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
740 // if stylemanager is available
743 // Register for style changes
744 styleManager.StyleChangeSignal().Connect( this, &Control::OnStyleChange );
746 // Apply the current style
747 GetImpl( styleManager ).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 )
765 void Control::OnControlChildRemove( Actor& child )
769 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
771 // By default the control is only interested in theme (not font) changes
772 if( styleManager && change == StyleChange::THEME_CHANGE )
774 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
778 void Control::OnPinch(const PinchGesture& pinch)
780 if( !( mImpl->mStartingPinchScale ) )
783 mImpl->mStartingPinchScale = new Vector3;
786 if( pinch.state == Gesture::Started )
788 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
791 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
794 void Control::OnPan( const PanGesture& pan )
798 void Control::OnTap(const TapGesture& tap)
802 void Control::OnLongPress( const LongPressGesture& longPress )
806 void Control::EmitKeyInputFocusSignal( bool focusGained )
808 Dali::Toolkit::Control handle( GetOwner() );
812 // signals are allocated dynamically when someone connects
813 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
815 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
820 // signals are allocated dynamically when someone connects
821 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
823 mImpl->mKeyInputFocusLostSignal.Emit( handle );
828 void Control::OnStageConnection( int depth )
830 if( mImpl->mBackgroundRenderer)
832 Actor self( Self() );
833 mImpl->mBackgroundRenderer.SetOnStage( self );
837 void Control::OnStageDisconnection()
839 if( mImpl->mBackgroundRenderer )
841 Actor self( Self() );
842 mImpl->mBackgroundRenderer.SetOffStage( self );
846 void Control::OnKeyInputFocusGained()
848 EmitKeyInputFocusSignal( true );
851 void Control::OnKeyInputFocusLost()
853 EmitKeyInputFocusSignal( false );
856 void Control::OnChildAdd(Actor& child)
858 // If this is the background actor, then we do not want to inform deriving classes
859 if ( mImpl->mAddRemoveBackgroundChild )
864 // Notify derived classes.
865 OnControlChildAdd( child );
868 void Control::OnChildRemove(Actor& child)
870 // If this is the background actor, then we do not want to inform deriving classes
871 if ( mImpl->mAddRemoveBackgroundChild )
876 // Notify derived classes.
877 OnControlChildRemove( child );
880 void Control::OnSizeSet(const Vector3& targetSize)
882 // Background is resized through size negotiation
885 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
887 // @todo size negotiate background to new size, animate as well?
890 bool Control::OnTouchEvent(const TouchEvent& event)
892 return false; // Do not consume
895 bool Control::OnHoverEvent(const HoverEvent& event)
897 return false; // Do not consume
900 bool Control::OnKeyEvent(const KeyEvent& event)
902 return false; // Do not consume
905 bool Control::OnWheelEvent(const WheelEvent& event)
907 return false; // Do not consume
910 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
912 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
914 container.Add( Self().GetChildAt( i ), size );
918 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
922 Vector3 Control::GetNaturalSize()
924 if( mImpl->mBackgroundRenderer )
927 mImpl->mBackgroundRenderer.GetNaturalSize(naturalSize);
928 return Vector3(naturalSize);
930 return Vector3::ZERO;
933 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
935 return CalculateChildSizeBase( child, dimension );
938 float Control::GetHeightForWidth( float width )
940 return GetHeightForWidthBase( width );
943 float Control::GetWidthForHeight( float height )
945 return GetWidthForHeightBase( height );
948 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
950 return RelayoutDependentOnChildrenBase( dimension );
953 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
957 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
961 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
963 mImpl->SignalConnected( slotObserver, callback );
966 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
968 mImpl->SignalDisconnected( slotObserver, callback );
971 Control& GetImplementation( Dali::Toolkit::Control& handle )
973 CustomActorImpl& customInterface = handle.GetImplementation();
974 // downcast to control
975 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
979 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
981 const CustomActorImpl& customInterface = handle.GetImplementation();
982 // downcast to control
983 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
987 } // namespace Internal
989 } // namespace Toolkit