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/devel-api/controls/control-depth-index-ranges.h>
38 #include <dali-toolkit/devel-api/controls/renderer-factory/renderer-factory.h>
39 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.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 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 ),
191 mAddRemoveBackgroundChild( false )
197 // All gesture detectors will be destroyed so no need to disconnect.
198 delete mStartingPinchScale;
201 // Gesture Detection Methods
203 void PinchDetected(Actor actor, const PinchGesture& pinch)
205 mControlImpl.OnPinch(pinch);
208 void PanDetected(Actor actor, const PanGesture& pan)
210 mControlImpl.OnPan(pan);
213 void TapDetected(Actor actor, const TapGesture& tap)
215 mControlImpl.OnTap(tap);
218 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
220 mControlImpl.OnLongPress(longPress);
226 * Called when a property of an object of this type is set.
227 * @param[in] object The object whose property is set.
228 * @param[in] index The property index.
229 * @param[in] value The new property value.
231 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
233 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
237 Control& controlImpl( GetImplementation( control ) );
241 case Toolkit::Control::Property::STYLE_NAME:
243 controlImpl.SetStyleName( value.Get< std::string >() );
247 case Toolkit::Control::Property::BACKGROUND_COLOR:
249 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
250 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
254 case Toolkit::Control::Property::BACKGROUND_IMAGE:
256 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
257 Image image = Scripting::NewImage( value );
260 controlImpl.SetBackgroundImage( image );
264 // An empty map means the background is no longer required
265 controlImpl.ClearBackground();
270 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
272 if ( value.Get< bool >() )
274 controlImpl.SetKeyInputFocus();
278 controlImpl.ClearKeyInputFocus();
283 case Toolkit::Control::Property::BACKGROUND:
285 const Property::Map* map = value.GetMap();
288 controlImpl.SetBackground( *map );
292 // The background is not a property map, so we should clear the background
293 controlImpl.ClearBackground();
302 * Called to retrieve a property of an object of this type.
303 * @param[in] object The object whose property is to be retrieved.
304 * @param[in] index The property index.
305 * @return The current value of the property.
307 static Property::Value GetProperty( BaseObject* object, Property::Index index )
309 Property::Value value;
311 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
315 Control& controlImpl( GetImplementation( control ) );
319 case Toolkit::Control::Property::STYLE_NAME:
321 value = controlImpl.GetStyleName();
325 case Toolkit::Control::Property::BACKGROUND_COLOR:
327 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
328 value = controlImpl.GetBackgroundColor();
332 case Toolkit::Control::Property::BACKGROUND_IMAGE:
334 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
336 if( controlImpl.mImpl->mBackgroundRenderer )
338 controlImpl.mImpl->mBackgroundRenderer.CreatePropertyMap( map );
344 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
346 value = controlImpl.HasKeyInputFocus();
350 case Toolkit::Control::Property::BACKGROUND:
353 if( controlImpl.mImpl->mBackgroundRenderer )
355 (controlImpl.mImpl->mBackgroundRenderer).CreatePropertyMap( map );
370 Control& mControlImpl;
371 std::string mStyleName;
372 Toolkit::ControlRenderer mBackgroundRenderer; ///< The control renderer to render the background
373 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
374 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
375 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
376 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
379 PinchGestureDetector mPinchGestureDetector;
380 PanGestureDetector mPanGestureDetector;
381 TapGestureDetector mTapGestureDetector;
382 LongPressGestureDetector mLongPressGestureDetector;
384 ControlBehaviour mFlags :CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
385 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
386 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
387 bool mAddRemoveBackgroundChild:1; ///< Flag to know when we are adding or removing our own actor to avoid call to OnControlChildAdd
389 // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
390 static const PropertyRegistration PROPERTY_1;
391 static const PropertyRegistration PROPERTY_2;
392 static const PropertyRegistration PROPERTY_3;
393 static const PropertyRegistration PROPERTY_4;
394 static const PropertyRegistration PROPERTY_5;
397 // Properties registered without macro to use specific member variables.
398 const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
399 const PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "backgroundColor", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
400 const PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "backgroundImage", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
401 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
402 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
404 Toolkit::Control Control::New()
406 // Create the implementation, temporarily owned on stack
407 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) );
409 // Pass ownership to handle
410 Toolkit::Control handle( *controlImpl );
412 // Second-phase init of the implementation
413 // This can only be done after the CustomActor connection has been made...
414 controlImpl->Initialize();
424 void Control::SetStyleName( const std::string& styleName )
426 if( styleName != mImpl->mStyleName )
428 mImpl->mStyleName = styleName;
430 // Apply new style, if stylemanager is available
431 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
434 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
439 const std::string& Control::GetStyleName() const
441 return mImpl->mStyleName;
444 void Control::SetBackgroundColor( const Vector4& color )
446 Actor self( Self() );
447 Toolkit::RendererFactory factory = Toolkit::RendererFactory::Get();
448 factory.ResetRenderer( mImpl->mBackgroundRenderer, self, color );
449 mImpl->mBackgroundRenderer.SetDepthIndex( DepthIndex::BACKGROUND );
452 Vector4 Control::GetBackgroundColor() const
454 if( mImpl->mBackgroundRenderer && ( &typeid( GetImplementation(mImpl->mBackgroundRenderer) ) == &typeid( ColorRenderer ) ) )
457 mImpl->mBackgroundRenderer.CreatePropertyMap( map );
458 const Property::Value* colorValue = map.Find( COLOR_RENDERER_COLOR_NAME );
460 if( colorValue && colorValue->Get(color))
466 return Color::TRANSPARENT;
469 void Control::SetBackground(const Property::Map& map)
471 Actor self( Self() );
472 mImpl->mBackgroundRenderer.RemoveAndReset( self );
473 Toolkit::RendererFactory factory = Toolkit::RendererFactory::Get();
474 mImpl->mBackgroundRenderer = factory.GetControlRenderer( map );
475 if( mImpl->mBackgroundRenderer && self.OnStage() ) // Request control renderer with a property map might return an empty handle
477 mImpl->mBackgroundRenderer.SetDepthIndex( DepthIndex::BACKGROUND );
478 mImpl->mBackgroundRenderer.SetOnStage( self );
482 void Control::SetBackgroundImage( Image image )
484 Actor self( Self() );
485 Toolkit::RendererFactory factory = Toolkit::RendererFactory::Get();
486 factory.ResetRenderer( mImpl->mBackgroundRenderer, self, image );
487 mImpl->mBackgroundRenderer.SetDepthIndex( DepthIndex::BACKGROUND );
490 void Control::ClearBackground()
492 Actor self( Self() );
493 mImpl->mBackgroundRenderer.RemoveAndReset( self );
496 void Control::EnableGestureDetection(Gesture::Type type)
498 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
500 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
501 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
502 mImpl->mPinchGestureDetector.Attach(Self());
505 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
507 mImpl->mPanGestureDetector = PanGestureDetector::New();
508 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
509 mImpl->mPanGestureDetector.Attach(Self());
512 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
514 mImpl->mTapGestureDetector = TapGestureDetector::New();
515 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
516 mImpl->mTapGestureDetector.Attach(Self());
519 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
521 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
522 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
523 mImpl->mLongPressGestureDetector.Attach(Self());
527 void Control::DisableGestureDetection(Gesture::Type type)
529 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
531 mImpl->mPinchGestureDetector.Detach(Self());
532 mImpl->mPinchGestureDetector.Reset();
535 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
537 mImpl->mPanGestureDetector.Detach(Self());
538 mImpl->mPanGestureDetector.Reset();
541 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
543 mImpl->mTapGestureDetector.Detach(Self());
544 mImpl->mTapGestureDetector.Reset();
547 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
549 mImpl->mLongPressGestureDetector.Detach(Self());
550 mImpl->mLongPressGestureDetector.Reset();
554 PinchGestureDetector Control::GetPinchGestureDetector() const
556 return mImpl->mPinchGestureDetector;
559 PanGestureDetector Control::GetPanGestureDetector() const
561 return mImpl->mPanGestureDetector;
564 TapGestureDetector Control::GetTapGestureDetector() const
566 return mImpl->mTapGestureDetector;
569 LongPressGestureDetector Control::GetLongPressGestureDetector() const
571 return mImpl->mLongPressGestureDetector;
574 void Control::SetKeyboardNavigationSupport(bool isSupported)
576 mImpl->mIsKeyboardNavigationSupported = isSupported;
579 bool Control::IsKeyboardNavigationSupported()
581 return mImpl->mIsKeyboardNavigationSupported;
584 void Control::SetKeyInputFocus()
586 if( Self().OnStage() )
588 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
592 bool Control::HasKeyInputFocus()
595 if( Self().OnStage() )
597 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
602 void Control::ClearKeyInputFocus()
604 if( Self().OnStage() )
606 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
610 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
612 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
614 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
615 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
618 bool Control::IsKeyboardFocusGroup()
620 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
623 void Control::AccessibilityActivate()
625 // Inform deriving classes
626 OnAccessibilityActivated();
629 void Control::KeyboardEnter()
631 // Inform deriving classes
635 bool Control::OnAccessibilityActivated()
637 return false; // Accessibility activation is not handled by default
640 bool Control::OnKeyboardEnter()
642 return false; // Keyboard enter is not handled by default
645 bool Control::OnAccessibilityPan(PanGesture gesture)
647 return false; // Accessibility pan gesture is not handled by default
650 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
652 return false; // Accessibility touch event is not handled by default
655 bool Control::OnAccessibilityValueChange(bool isIncrease)
657 return false; // Accessibility value change action is not handled by default
660 bool Control::OnAccessibilityZoom()
662 return false; // Accessibility zoom action is not handled by default
665 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
670 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
674 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
676 return mImpl->mKeyEventSignal;
679 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusGainedSignal()
681 return mImpl->mKeyInputFocusGainedSignal;
684 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusLostSignal()
686 return mImpl->mKeyInputFocusLostSignal;
689 bool Control::EmitKeyEventSignal( const KeyEvent& event )
691 // Guard against destruction during signal emission
692 Dali::Toolkit::Control handle( GetOwner() );
694 bool consumed = false;
696 // signals are allocated dynamically when someone connects
697 if ( !mImpl->mKeyEventSignal.Empty() )
699 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
704 // Notification for derived classes
705 consumed = OnKeyEvent(event);
711 Control::Control( ControlBehaviour behaviourFlags )
712 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
713 mImpl(new Impl(*this))
715 mImpl->mFlags = behaviourFlags;
718 void Control::Initialize()
720 // Call deriving classes so initialised before styling is applied to them.
723 if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
725 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
726 // if stylemanager is available
729 // Register for style changes
730 styleManager.StyleChangeSignal().Connect( this, &Control::OnStyleChange );
732 // Apply the current style
733 GetImpl( styleManager ).ApplyThemeStyleAtInit( Toolkit::Control( GetOwner() ) );
737 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
739 SetKeyboardNavigationSupport( true );
743 void Control::OnInitialize()
747 void Control::OnControlChildAdd( Actor& child )
751 void Control::OnControlChildRemove( Actor& child )
755 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
757 // By default the control is only interested in theme (not font) changes
758 if( styleManager && change == StyleChange::THEME_CHANGE )
760 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
764 void Control::OnPinch(const PinchGesture& pinch)
766 if( !( mImpl->mStartingPinchScale ) )
769 mImpl->mStartingPinchScale = new Vector3;
772 if( pinch.state == Gesture::Started )
774 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
777 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
780 void Control::OnPan( const PanGesture& pan )
784 void Control::OnTap(const TapGesture& tap)
788 void Control::OnLongPress( const LongPressGesture& longPress )
792 void Control::EmitKeyInputFocusSignal( bool focusGained )
794 Dali::Toolkit::Control handle( GetOwner() );
798 // signals are allocated dynamically when someone connects
799 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
801 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
806 // signals are allocated dynamically when someone connects
807 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
809 mImpl->mKeyInputFocusLostSignal.Emit( handle );
814 void Control::OnStageConnection( int depth )
816 if( mImpl->mBackgroundRenderer)
818 Actor self( Self() );
819 mImpl->mBackgroundRenderer.SetOnStage( self );
823 void Control::OnStageDisconnection()
825 if( mImpl->mBackgroundRenderer )
827 Actor self( Self() );
828 mImpl->mBackgroundRenderer.SetOffStage( self );
832 void Control::OnKeyInputFocusGained()
834 EmitKeyInputFocusSignal( true );
837 void Control::OnKeyInputFocusLost()
839 EmitKeyInputFocusSignal( false );
842 void Control::OnChildAdd(Actor& child)
844 // If this is the background actor, then we do not want to inform deriving classes
845 if ( mImpl->mAddRemoveBackgroundChild )
850 // Notify derived classes.
851 OnControlChildAdd( child );
854 void Control::OnChildRemove(Actor& child)
856 // If this is the background actor, then we do not want to inform deriving classes
857 if ( mImpl->mAddRemoveBackgroundChild )
862 // Notify derived classes.
863 OnControlChildRemove( child );
866 void Control::OnSizeSet(const Vector3& targetSize)
868 // Background is resized through size negotiation
871 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
873 // @todo size negotiate background to new size, animate as well?
876 bool Control::OnTouchEvent(const TouchEvent& event)
878 return false; // Do not consume
881 bool Control::OnHoverEvent(const HoverEvent& event)
883 return false; // Do not consume
886 bool Control::OnKeyEvent(const KeyEvent& event)
888 return false; // Do not consume
891 bool Control::OnWheelEvent(const WheelEvent& event)
893 return false; // Do not consume
896 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
898 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
900 container.Add( Self().GetChildAt( i ), size );
904 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
908 Vector3 Control::GetNaturalSize()
910 if( mImpl->mBackgroundRenderer )
913 mImpl->mBackgroundRenderer.GetNaturalSize(naturalSize);
914 return Vector3(naturalSize);
916 return Vector3::ZERO;
919 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
921 return CalculateChildSizeBase( child, dimension );
924 float Control::GetHeightForWidth( float width )
926 return GetHeightForWidthBase( width );
929 float Control::GetWidthForHeight( float height )
931 return GetWidthForHeightBase( height );
934 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
936 return RelayoutDependentOnChildrenBase( dimension );
939 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
943 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
947 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
949 mImpl->SignalConnected( slotObserver, callback );
952 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
954 mImpl->SignalDisconnected( slotObserver, callback );
957 Control& GetImplementation( Dali::Toolkit::Control& handle )
959 CustomActorImpl& customInterface = handle.GetImplementation();
960 // downcast to control
961 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
965 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
967 const CustomActorImpl& customInterface = handle.GetImplementation();
968 // downcast to control
969 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
973 } // namespace Internal
975 } // namespace Toolkit