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/internal/styling/style-manager-impl.h>
43 #include <dali-toolkit/internal/visuals/color/color-visual.h>
55 * Struct used to store Visual within the control, index is a unique key for each visual.
57 struct RegisteredVisual
59 Property::Index index;
60 Toolkit::Visual::Base visual;
63 RegisteredVisual( Property::Index aIndex, Toolkit::Visual::Base &aVisual, Actor &aPlacementActor) : index(aIndex), visual(aVisual), placementActor(aPlacementActor) {}
67 * Finds visual in given array, returning true if found along with the iterator for that visual as a out parameter
69 bool FindVisual( Property::Index targetIndex, std::vector<RegisteredVisual>& visuals, std::vector<RegisteredVisual>::iterator& iter )
71 for ( iter = visuals.begin(); iter != visuals.end(); iter++ )
73 if ( (*iter).index == targetIndex )
82 * Creates control through type registry
86 return Internal::Control::New();
90 * Performs actions as requested using the action name.
91 * @param[in] object The object on which to perform the action.
92 * @param[in] actionName The action to perform.
93 * @param[in] attributes The attributes with which to perfrom this action.
94 * @return true if action has been accepted by this control
96 const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibilityActivated";
97 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
101 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ) )
103 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
106 // if cast succeeds there is an implementation so no need to check
107 ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
115 * Connects a callback function with the object's signals.
116 * @param[in] object The object providing the signal.
117 * @param[in] tracker Used to disconnect the signal.
118 * @param[in] signalName The signal to connect to.
119 * @param[in] functor A newly allocated FunctorDelegate.
120 * @return True if the signal was connected.
121 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
123 const char* SIGNAL_KEY_EVENT = "keyEvent";
124 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "keyInputFocusGained";
125 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "keyInputFocusLost";
126 const char* SIGNAL_TAPPED = "tapped";
127 const char* SIGNAL_PANNED = "panned";
128 const char* SIGNAL_PINCHED = "pinched";
129 const char* SIGNAL_LONG_PRESSED = "longPressed";
130 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
132 Dali::BaseHandle handle( object );
134 bool connected( false );
135 Toolkit::Control control = Toolkit::Control::DownCast( handle );
138 Internal::Control& controlImpl( Internal::GetImplementation( control ) );
141 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
143 controlImpl.KeyEventSignal().Connect( tracker, functor );
145 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
147 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
149 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
151 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
153 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
155 controlImpl.EnableGestureDetection( Gesture::Tap );
156 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
158 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
160 controlImpl.EnableGestureDetection( Gesture::Pan );
161 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
163 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
165 controlImpl.EnableGestureDetection( Gesture::Pinch );
166 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
168 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
170 controlImpl.EnableGestureDetection( Gesture::LongPress );
171 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
177 // Setup signals and actions using the type-registry.
178 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
180 // Note: Properties are registered separately below.
182 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
183 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
184 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
185 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
186 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
187 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
188 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
190 TypeAction registerAction( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &DoAction );
192 DALI_TYPE_REGISTRATION_END()
194 } // unnamed namespace
199 class Control::Impl : public ConnectionTracker
203 // Construction & Destruction
204 Impl(Control& controlImpl)
205 : mControlImpl( controlImpl ),
208 mBackgroundColor(Color::TRANSPARENT),
209 mStartingPinchScale( NULL ),
211 mPinchGestureDetector(),
212 mPanGestureDetector(),
213 mTapGestureDetector(),
214 mLongPressGestureDetector(),
215 mFlags( Control::ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ),
216 mIsKeyboardNavigationSupported( false ),
217 mIsKeyboardFocusGroup( false )
223 // All gesture detectors will be destroyed so no need to disconnect.
224 delete mStartingPinchScale;
227 // Gesture Detection Methods
229 void PinchDetected(Actor actor, const PinchGesture& pinch)
231 mControlImpl.OnPinch(pinch);
234 void PanDetected(Actor actor, const PanGesture& pan)
236 mControlImpl.OnPan(pan);
239 void TapDetected(Actor actor, const TapGesture& tap)
241 mControlImpl.OnTap(tap);
244 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
246 mControlImpl.OnLongPress(longPress);
252 * Called when a property of an object of this type is set.
253 * @param[in] object The object whose property is set.
254 * @param[in] index The property index.
255 * @param[in] value The new property value.
257 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
259 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
263 Control& controlImpl( GetImplementation( control ) );
267 case Toolkit::Control::Property::STYLE_NAME:
269 controlImpl.SetStyleName( value.Get< std::string >() );
273 case Toolkit::Control::Property::BACKGROUND_COLOR:
275 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
276 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
280 case Toolkit::Control::Property::BACKGROUND_IMAGE:
282 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
283 Image image = Scripting::NewImage( value );
286 controlImpl.SetBackgroundImage( image );
290 // An empty map means the background is no longer required
291 controlImpl.ClearBackground();
296 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
298 if ( value.Get< bool >() )
300 controlImpl.SetKeyInputFocus();
304 controlImpl.ClearKeyInputFocus();
309 case Toolkit::Control::Property::BACKGROUND:
311 const Property::Map* map = value.GetMap();
314 controlImpl.SetBackground( *map );
318 // The background is not a property map, so we should clear the background
319 controlImpl.ClearBackground();
328 * Called to retrieve a property of an object of this type.
329 * @param[in] object The object whose property is to be retrieved.
330 * @param[in] index The property index.
331 * @return The current value of the property.
333 static Property::Value GetProperty( BaseObject* object, Property::Index index )
335 Property::Value value;
337 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
341 Control& controlImpl( GetImplementation( control ) );
345 case Toolkit::Control::Property::STYLE_NAME:
347 value = controlImpl.GetStyleName();
351 case Toolkit::Control::Property::BACKGROUND_COLOR:
353 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
354 value = controlImpl.GetBackgroundColor();
358 case Toolkit::Control::Property::BACKGROUND_IMAGE:
360 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
362 if( controlImpl.mImpl->mBackgroundVisual )
364 controlImpl.mImpl->mBackgroundVisual.CreatePropertyMap( map );
370 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
372 value = controlImpl.HasKeyInputFocus();
376 case Toolkit::Control::Property::BACKGROUND:
379 if( controlImpl.mImpl->mBackgroundVisual )
381 (controlImpl.mImpl->mBackgroundVisual).CreatePropertyMap( map );
396 Control& mControlImpl;
397 std::vector<RegisteredVisual> mVisuals; // Stores visuals needed by the control, non trivial type so std::vector used.
398 std::string mStyleName;
399 Toolkit::Visual::Base mBackgroundVisual; ///< The visual to render the background
400 Vector4 mBackgroundColor; ///< The color of the background visual
401 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
402 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
403 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
404 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
407 PinchGestureDetector mPinchGestureDetector;
408 PanGestureDetector mPanGestureDetector;
409 TapGestureDetector mTapGestureDetector;
410 LongPressGestureDetector mLongPressGestureDetector;
412 ControlBehaviour mFlags :CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
413 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
414 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
416 // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
417 static const PropertyRegistration PROPERTY_1;
418 static const PropertyRegistration PROPERTY_2;
419 static const PropertyRegistration PROPERTY_3;
420 static const PropertyRegistration PROPERTY_4;
421 static const PropertyRegistration PROPERTY_5;
424 // Properties registered without macro to use specific member variables.
425 const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
426 const PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "backgroundColor", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
427 const PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "backgroundImage", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
428 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
429 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
431 Toolkit::Control Control::New()
433 // Create the implementation, temporarily owned on stack
434 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) );
436 // Pass ownership to handle
437 Toolkit::Control handle( *controlImpl );
439 // Second-phase init of the implementation
440 // This can only be done after the CustomActor connection has been made...
441 controlImpl->Initialize();
451 void Control::SetStyleName( const std::string& styleName )
453 if( styleName != mImpl->mStyleName )
455 mImpl->mStyleName = styleName;
457 // Apply new style, if stylemanager is available
458 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
461 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
466 const std::string& Control::GetStyleName() const
468 return mImpl->mStyleName;
471 void Control::SetBackgroundColor( const Vector4& color )
473 Actor self( Self() );
474 mImpl->mBackgroundColor = color;
476 map[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::COLOR;
477 map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color;
478 InitializeVisual( self, mImpl->mBackgroundVisual, map );
479 if( mImpl->mBackgroundVisual )
481 mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND );
485 Vector4 Control::GetBackgroundColor() const
487 return mImpl->mBackgroundColor;
490 void Control::SetBackground( const Property::Map& map )
492 Actor self( Self() );
493 InitializeVisual( self, mImpl->mBackgroundVisual, map );
494 if( mImpl->mBackgroundVisual )
496 mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND );
500 void Control::SetBackgroundImage( Image image )
502 Actor self( Self() );
503 InitializeVisual( self, mImpl->mBackgroundVisual, image );
504 if( mImpl->mBackgroundVisual )
506 mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND );
510 void Control::ClearBackground()
512 Actor self( Self() );
513 mImpl->mBackgroundVisual.RemoveAndReset( self );
514 mImpl->mBackgroundColor = Color::TRANSPARENT;
517 void Control::EnableGestureDetection(Gesture::Type type)
519 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
521 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
522 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
523 mImpl->mPinchGestureDetector.Attach(Self());
526 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
528 mImpl->mPanGestureDetector = PanGestureDetector::New();
529 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
530 mImpl->mPanGestureDetector.Attach(Self());
533 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
535 mImpl->mTapGestureDetector = TapGestureDetector::New();
536 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
537 mImpl->mTapGestureDetector.Attach(Self());
540 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
542 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
543 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
544 mImpl->mLongPressGestureDetector.Attach(Self());
548 void Control::DisableGestureDetection(Gesture::Type type)
550 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
552 mImpl->mPinchGestureDetector.Detach(Self());
553 mImpl->mPinchGestureDetector.Reset();
556 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
558 mImpl->mPanGestureDetector.Detach(Self());
559 mImpl->mPanGestureDetector.Reset();
562 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
564 mImpl->mTapGestureDetector.Detach(Self());
565 mImpl->mTapGestureDetector.Reset();
568 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
570 mImpl->mLongPressGestureDetector.Detach(Self());
571 mImpl->mLongPressGestureDetector.Reset();
575 PinchGestureDetector Control::GetPinchGestureDetector() const
577 return mImpl->mPinchGestureDetector;
580 PanGestureDetector Control::GetPanGestureDetector() const
582 return mImpl->mPanGestureDetector;
585 TapGestureDetector Control::GetTapGestureDetector() const
587 return mImpl->mTapGestureDetector;
590 LongPressGestureDetector Control::GetLongPressGestureDetector() const
592 return mImpl->mLongPressGestureDetector;
595 void Control::SetKeyboardNavigationSupport(bool isSupported)
597 mImpl->mIsKeyboardNavigationSupported = isSupported;
600 bool Control::IsKeyboardNavigationSupported()
602 return mImpl->mIsKeyboardNavigationSupported;
605 void Control::SetKeyInputFocus()
607 if( Self().OnStage() )
609 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
613 bool Control::HasKeyInputFocus()
616 if( Self().OnStage() )
618 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
623 void Control::ClearKeyInputFocus()
625 if( Self().OnStage() )
627 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
631 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
633 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
635 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
636 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
639 bool Control::IsKeyboardFocusGroup()
641 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
644 void Control::AccessibilityActivate()
646 // Inform deriving classes
647 OnAccessibilityActivated();
650 void Control::KeyboardEnter()
652 // Inform deriving classes
656 void Control::RegisterVisual( Property::Index index, Actor placementActor, Toolkit::Visual::Base visual )
658 bool visualReplaced ( false );
659 Actor actorToRegister; // Null actor, replaced if placement actor not Self
661 if ( placementActor != Self() ) // Prevent increasing ref count if actor self
663 actorToRegister = placementActor;
666 if ( !mImpl->mVisuals.empty() )
668 std::vector<RegisteredVisual>::iterator iter;
669 // Check if visual (index) is already registered. Replace if so.
670 if ( FindVisual( index, mImpl->mVisuals, iter ) )
672 (*iter).visual = visual;
673 (*iter).placementActor = actorToRegister;
674 visualReplaced = true;
678 if ( !visualReplaced ) // New registration entry
680 RegisteredVisual newVisual = RegisteredVisual( index, visual, actorToRegister );
681 mImpl->mVisuals.push_back( newVisual );
685 void Control::UnregisterVisual( Property::Index index )
687 std::vector< RegisteredVisual >::iterator iter;
688 if ( FindVisual( index, mImpl->mVisuals, iter ) )
690 mImpl->mVisuals.erase( iter );
694 bool Control::OnAccessibilityActivated()
696 return false; // Accessibility activation is not handled by default
699 bool Control::OnKeyboardEnter()
701 return false; // Keyboard enter is not handled by default
704 bool Control::OnAccessibilityPan(PanGesture gesture)
706 return false; // Accessibility pan gesture is not handled by default
709 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
711 return false; // Accessibility touch event is not handled by default
714 bool Control::OnAccessibilityValueChange(bool isIncrease)
716 return false; // Accessibility value change action is not handled by default
719 bool Control::OnAccessibilityZoom()
721 return false; // Accessibility zoom action is not handled by default
724 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
729 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
733 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
735 return mImpl->mKeyEventSignal;
738 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusGainedSignal()
740 return mImpl->mKeyInputFocusGainedSignal;
743 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusLostSignal()
745 return mImpl->mKeyInputFocusLostSignal;
748 bool Control::EmitKeyEventSignal( const KeyEvent& event )
750 // Guard against destruction during signal emission
751 Dali::Toolkit::Control handle( GetOwner() );
753 bool consumed = false;
755 // signals are allocated dynamically when someone connects
756 if ( !mImpl->mKeyEventSignal.Empty() )
758 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
763 // Notification for derived classes
764 consumed = OnKeyEvent(event);
770 Control::Control( ControlBehaviour behaviourFlags )
771 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
772 mImpl(new Impl(*this))
774 mImpl->mFlags = behaviourFlags;
777 void Control::Initialize()
779 // Call deriving classes so initialised before styling is applied to them.
782 if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
784 Toolkit::StyleManager styleManager = StyleManager::Get();
786 // if stylemanager is available
789 StyleManager& styleManagerImpl = GetImpl( styleManager );
791 // Register for style changes
792 styleManagerImpl.ControlStyleChangeSignal().Connect( this, &Control::OnStyleChange );
794 // Apply the current style
795 styleManagerImpl.ApplyThemeStyleAtInit( Toolkit::Control( GetOwner() ) );
799 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
801 SetKeyboardNavigationSupport( true );
805 void Control::OnInitialize()
809 void Control::OnControlChildAdd( Actor& child )
813 void Control::OnControlChildRemove( Actor& child )
817 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
819 // By default the control is only interested in theme (not font) changes
820 if( styleManager && change == StyleChange::THEME_CHANGE )
822 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
827 void Control::OnPinch(const PinchGesture& pinch)
829 if( !( mImpl->mStartingPinchScale ) )
832 mImpl->mStartingPinchScale = new Vector3;
835 if( pinch.state == Gesture::Started )
837 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
840 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
843 void Control::OnPan( const PanGesture& pan )
847 void Control::OnTap(const TapGesture& tap)
851 void Control::OnLongPress( const LongPressGesture& longPress )
855 void Control::EmitKeyInputFocusSignal( bool focusGained )
857 Dali::Toolkit::Control handle( GetOwner() );
861 // signals are allocated dynamically when someone connects
862 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
864 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
869 // signals are allocated dynamically when someone connects
870 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
872 mImpl->mKeyInputFocusLostSignal.Emit( handle );
877 void Control::OnStageConnection( int depth )
879 if( mImpl->mBackgroundVisual)
881 Actor self( Self() );
882 mImpl->mBackgroundVisual.SetOnStage( self );
886 void Control::OnStageDisconnection()
888 if( mImpl->mBackgroundVisual )
890 Actor self( Self() );
891 mImpl->mBackgroundVisual.SetOffStage( self );
895 void Control::OnKeyInputFocusGained()
897 EmitKeyInputFocusSignal( true );
900 void Control::OnKeyInputFocusLost()
902 EmitKeyInputFocusSignal( false );
905 void Control::OnChildAdd(Actor& child)
907 // Notify derived classes.
908 OnControlChildAdd( child );
911 void Control::OnChildRemove(Actor& child)
913 // Notify derived classes.
914 OnControlChildRemove( child );
917 void Control::OnSizeSet(const Vector3& targetSize)
919 if( mImpl->mBackgroundVisual )
921 Vector2 size( targetSize );
922 mImpl->mBackgroundVisual.SetSize( size );
926 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
928 // @todo size negotiate background to new size, animate as well?
931 bool Control::OnTouchEvent(const TouchEvent& event)
933 return false; // Do not consume
936 bool Control::OnHoverEvent(const HoverEvent& event)
938 return false; // Do not consume
941 bool Control::OnKeyEvent(const KeyEvent& event)
943 return false; // Do not consume
946 bool Control::OnWheelEvent(const WheelEvent& event)
948 return false; // Do not consume
951 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
953 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
955 container.Add( Self().GetChildAt( i ), size );
959 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
963 Vector3 Control::GetNaturalSize()
965 if( mImpl->mBackgroundVisual )
968 mImpl->mBackgroundVisual.GetNaturalSize(naturalSize);
969 return Vector3(naturalSize);
971 return Vector3::ZERO;
974 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
976 return CalculateChildSizeBase( child, dimension );
979 float Control::GetHeightForWidth( float width )
981 return GetHeightForWidthBase( width );
984 float Control::GetWidthForHeight( float height )
986 return GetWidthForHeightBase( height );
989 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
991 return RelayoutDependentOnChildrenBase( dimension );
994 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
998 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
1002 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1004 mImpl->SignalConnected( slotObserver, callback );
1007 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1009 mImpl->SignalDisconnected( slotObserver, callback );
1012 Control& GetImplementation( Dali::Toolkit::Control& handle )
1014 CustomActorImpl& customInterface = handle.GetImplementation();
1015 // downcast to control
1016 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
1020 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
1022 const CustomActorImpl& customInterface = handle.GetImplementation();
1023 // downcast to control
1024 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
1028 } // namespace Internal
1030 } // namespace Toolkit