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/common/owner-container.h>
32 #include <dali/devel-api/scripting/scripting.h>
33 #include <dali/integration-api/debug.h>
36 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
37 #include <dali-toolkit/public-api/controls/control.h>
38 #include <dali-toolkit/public-api/styling/style-manager.h>
39 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
40 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
41 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
42 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
43 #include <dali-toolkit/internal/styling/style-manager-impl.h>
44 #include <dali-toolkit/internal/visuals/color/color-visual.h>
56 * Struct used to store Visual within the control, index is a unique key for each visual.
58 struct RegisteredVisual
60 Property::Index index;
61 Toolkit::Visual::Base visual;
65 RegisteredVisual( Property::Index aIndex, Toolkit::Visual::Base &aVisual, Actor &aPlacementActor, bool aEnabled) :
66 index(aIndex), visual(aVisual), placementActor(aPlacementActor), enabled(aEnabled) {}
69 typedef Dali::OwnerContainer< RegisteredVisual* > RegisteredVisualContainer;
72 * Finds visual in given array, returning true if found along with the iterator for that visual as a out parameter
74 bool FindVisual( Property::Index targetIndex, RegisteredVisualContainer& visuals, RegisteredVisualContainer::Iterator& iter )
76 for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
78 if ( (*iter)->index == targetIndex )
87 * Creates control through type registry
91 return Internal::Control::New();
95 * Performs actions as requested using the action name.
96 * @param[in] object The object on which to perform the action.
97 * @param[in] actionName The action to perform.
98 * @param[in] attributes The attributes with which to perfrom this action.
99 * @return true if action has been accepted by this control
101 const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibilityActivated";
102 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
106 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ) )
108 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
111 // if cast succeeds there is an implementation so no need to check
112 ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
120 * Connects a callback function with the object's signals.
121 * @param[in] object The object providing the signal.
122 * @param[in] tracker Used to disconnect the signal.
123 * @param[in] signalName The signal to connect to.
124 * @param[in] functor A newly allocated FunctorDelegate.
125 * @return True if the signal was connected.
126 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
128 const char* SIGNAL_KEY_EVENT = "keyEvent";
129 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "keyInputFocusGained";
130 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "keyInputFocusLost";
131 const char* SIGNAL_TAPPED = "tapped";
132 const char* SIGNAL_PANNED = "panned";
133 const char* SIGNAL_PINCHED = "pinched";
134 const char* SIGNAL_LONG_PRESSED = "longPressed";
135 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
137 Dali::BaseHandle handle( object );
139 bool connected( false );
140 Toolkit::Control control = Toolkit::Control::DownCast( handle );
143 Internal::Control& controlImpl( Internal::GetImplementation( control ) );
146 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
148 controlImpl.KeyEventSignal().Connect( tracker, functor );
150 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
152 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
154 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
156 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
158 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
160 controlImpl.EnableGestureDetection( Gesture::Tap );
161 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
163 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
165 controlImpl.EnableGestureDetection( Gesture::Pan );
166 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
168 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
170 controlImpl.EnableGestureDetection( Gesture::Pinch );
171 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
173 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
175 controlImpl.EnableGestureDetection( Gesture::LongPress );
176 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
182 // Setup signals and actions using the type-registry.
183 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
185 // Note: Properties are registered separately below.
187 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
188 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
189 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
190 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
191 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
192 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
193 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
195 TypeAction registerAction( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &DoAction );
197 DALI_TYPE_REGISTRATION_END()
199 } // unnamed namespace
204 class Control::Impl : public ConnectionTracker
208 // Construction & Destruction
209 Impl(Control& controlImpl)
210 : mControlImpl( controlImpl ),
213 mBackgroundColor(Color::TRANSPARENT),
214 mStartingPinchScale( NULL ),
216 mPinchGestureDetector(),
217 mPanGestureDetector(),
218 mTapGestureDetector(),
219 mLongPressGestureDetector(),
220 mFlags( Control::ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
221 mIsKeyboardNavigationSupported( false ),
222 mIsKeyboardFocusGroup( false )
228 // All gesture detectors will be destroyed so no need to disconnect.
229 delete mStartingPinchScale;
232 // Gesture Detection Methods
234 void PinchDetected(Actor actor, const PinchGesture& pinch)
236 mControlImpl.OnPinch(pinch);
239 void PanDetected(Actor actor, const PanGesture& pan)
241 mControlImpl.OnPan(pan);
244 void TapDetected(Actor actor, const TapGesture& tap)
246 mControlImpl.OnTap(tap);
249 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
251 mControlImpl.OnLongPress(longPress);
257 * Called when a property of an object of this type is set.
258 * @param[in] object The object whose property is set.
259 * @param[in] index The property index.
260 * @param[in] value The new property value.
262 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
264 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
268 Control& controlImpl( GetImplementation( control ) );
272 case Toolkit::Control::Property::STYLE_NAME:
274 controlImpl.SetStyleName( value.Get< std::string >() );
278 case Toolkit::Control::Property::BACKGROUND_COLOR:
280 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
281 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
285 case Toolkit::Control::Property::BACKGROUND_IMAGE:
287 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
288 Image image = Scripting::NewImage( value );
291 controlImpl.SetBackgroundImage( image );
295 // An empty map means the background is no longer required
296 controlImpl.ClearBackground();
301 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
303 if ( value.Get< bool >() )
305 controlImpl.SetKeyInputFocus();
309 controlImpl.ClearKeyInputFocus();
314 case Toolkit::Control::Property::BACKGROUND:
316 const Property::Map* map = value.GetMap();
319 controlImpl.SetBackground( *map );
323 // The background is not a property map, so we should clear the background
324 controlImpl.ClearBackground();
333 * Called to retrieve a property of an object of this type.
334 * @param[in] object The object whose property is to be retrieved.
335 * @param[in] index The property index.
336 * @return The current value of the property.
338 static Property::Value GetProperty( BaseObject* object, Property::Index index )
340 Property::Value value;
342 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
346 Control& controlImpl( GetImplementation( control ) );
350 case Toolkit::Control::Property::STYLE_NAME:
352 value = controlImpl.GetStyleName();
356 case Toolkit::Control::Property::BACKGROUND_COLOR:
358 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
359 value = controlImpl.GetBackgroundColor();
363 case Toolkit::Control::Property::BACKGROUND_IMAGE:
365 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
367 if( controlImpl.mImpl->mBackgroundVisual )
369 controlImpl.mImpl->mBackgroundVisual.CreatePropertyMap( map );
375 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
377 value = controlImpl.HasKeyInputFocus();
381 case Toolkit::Control::Property::BACKGROUND:
384 if( controlImpl.mImpl->mBackgroundVisual )
386 (controlImpl.mImpl->mBackgroundVisual).CreatePropertyMap( map );
401 Control& mControlImpl;
402 RegisteredVisualContainer mVisuals; // Stores visuals needed by the control, non trivial type so std::vector used.
403 std::string mStyleName;
404 Toolkit::Visual::Base mBackgroundVisual; ///< The visual to render the background
405 Vector4 mBackgroundColor; ///< The color of the background visual
406 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
407 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
408 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
409 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
412 PinchGestureDetector mPinchGestureDetector;
413 PanGestureDetector mPanGestureDetector;
414 TapGestureDetector mTapGestureDetector;
415 LongPressGestureDetector mLongPressGestureDetector;
417 ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
418 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
419 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
421 // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
422 static const PropertyRegistration PROPERTY_1;
423 static const PropertyRegistration PROPERTY_2;
424 static const PropertyRegistration PROPERTY_3;
425 static const PropertyRegistration PROPERTY_4;
426 static const PropertyRegistration PROPERTY_5;
429 // Properties registered without macro to use specific member variables.
430 const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
431 const PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "backgroundColor", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
432 const PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "backgroundImage", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
433 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
434 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
436 Toolkit::Control Control::New()
438 // Create the implementation, temporarily owned on stack
439 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) );
441 // Pass ownership to handle
442 Toolkit::Control handle( *controlImpl );
444 // Second-phase init of the implementation
445 // This can only be done after the CustomActor connection has been made...
446 controlImpl->Initialize();
456 void Control::SetStyleName( const std::string& styleName )
458 if( styleName != mImpl->mStyleName )
460 mImpl->mStyleName = styleName;
462 // Apply new style, if stylemanager is available
463 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
466 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
471 const std::string& Control::GetStyleName() const
473 return mImpl->mStyleName;
476 void Control::SetBackgroundColor( const Vector4& color )
478 Actor self( Self() );
479 mImpl->mBackgroundColor = color;
481 map[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::COLOR;
482 map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color;
483 mImpl->mBackgroundVisual = Toolkit::VisualFactory::Get().CreateVisual( map );
484 RegisterVisual( Toolkit::Control::Property::BACKGROUND, self, mImpl->mBackgroundVisual );
485 if( mImpl->mBackgroundVisual )
487 mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND );
491 Vector4 Control::GetBackgroundColor() const
493 return mImpl->mBackgroundColor;
496 void Control::SetBackground( const Property::Map& map )
498 Actor self( Self() );
499 mImpl->mBackgroundVisual = Toolkit::VisualFactory::Get().CreateVisual( map );
500 RegisterVisual( Toolkit::Control::Property::BACKGROUND, self, mImpl->mBackgroundVisual );
501 if( mImpl->mBackgroundVisual )
503 mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND );
507 void Control::SetBackgroundImage( Image image )
509 Actor self( Self() );
510 mImpl->mBackgroundVisual = Toolkit::VisualFactory::Get().CreateVisual( image );
511 RegisterVisual( Toolkit::Control::Property::BACKGROUND, self, mImpl->mBackgroundVisual );
512 if( mImpl->mBackgroundVisual )
514 mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND );
518 void Control::ClearBackground()
520 Actor self( Self() );
521 mImpl->mBackgroundVisual.RemoveAndReset( self );
522 mImpl->mBackgroundColor = Color::TRANSPARENT;
525 void Control::EnableGestureDetection(Gesture::Type type)
527 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
529 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
530 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
531 mImpl->mPinchGestureDetector.Attach(Self());
534 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
536 mImpl->mPanGestureDetector = PanGestureDetector::New();
537 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
538 mImpl->mPanGestureDetector.Attach(Self());
541 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
543 mImpl->mTapGestureDetector = TapGestureDetector::New();
544 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
545 mImpl->mTapGestureDetector.Attach(Self());
548 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
550 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
551 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
552 mImpl->mLongPressGestureDetector.Attach(Self());
556 void Control::DisableGestureDetection(Gesture::Type type)
558 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
560 mImpl->mPinchGestureDetector.Detach(Self());
561 mImpl->mPinchGestureDetector.Reset();
564 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
566 mImpl->mPanGestureDetector.Detach(Self());
567 mImpl->mPanGestureDetector.Reset();
570 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
572 mImpl->mTapGestureDetector.Detach(Self());
573 mImpl->mTapGestureDetector.Reset();
576 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
578 mImpl->mLongPressGestureDetector.Detach(Self());
579 mImpl->mLongPressGestureDetector.Reset();
583 PinchGestureDetector Control::GetPinchGestureDetector() const
585 return mImpl->mPinchGestureDetector;
588 PanGestureDetector Control::GetPanGestureDetector() const
590 return mImpl->mPanGestureDetector;
593 TapGestureDetector Control::GetTapGestureDetector() const
595 return mImpl->mTapGestureDetector;
598 LongPressGestureDetector Control::GetLongPressGestureDetector() const
600 return mImpl->mLongPressGestureDetector;
603 void Control::SetKeyboardNavigationSupport(bool isSupported)
605 mImpl->mIsKeyboardNavigationSupported = isSupported;
608 bool Control::IsKeyboardNavigationSupported()
610 return mImpl->mIsKeyboardNavigationSupported;
613 void Control::SetKeyInputFocus()
615 if( Self().OnStage() )
617 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
621 bool Control::HasKeyInputFocus()
624 if( Self().OnStage() )
626 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
631 void Control::ClearKeyInputFocus()
633 if( Self().OnStage() )
635 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
639 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
641 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
643 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
644 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
647 bool Control::IsKeyboardFocusGroup()
649 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
652 void Control::AccessibilityActivate()
654 // Inform deriving classes
655 OnAccessibilityActivated();
658 void Control::KeyboardEnter()
660 // Inform deriving classes
664 void Control::RegisterVisual( Property::Index index, Actor& placementActor, Toolkit::Visual::Base& visual )
666 RegisterVisual( index, placementActor, visual, true );
669 void Control::RegisterVisual( Property::Index index, Actor& placementActor, Toolkit::Visual::Base& visual, bool enabled )
671 bool visualReplaced ( false );
672 Actor actorToRegister; // Null actor, replaced if placement actor not Self
675 if ( placementActor != self ) // Prevent increasing ref count if actor self
677 actorToRegister = placementActor;
680 if ( !mImpl->mVisuals.Empty() )
682 RegisteredVisualContainer::Iterator iter;
683 // Check if visual (index) is already registered. Replace if so.
684 if ( FindVisual( index, mImpl->mVisuals, iter ) )
686 if( (*iter)->visual && self.OnStage() )
688 if( (*iter)->placementActor )
690 (*iter)->visual.SetOffStage( (*iter)->placementActor );
694 (*iter)->visual.SetOffStage( self );
697 (*iter)->visual = visual;
698 (*iter)->placementActor = actorToRegister;
699 visualReplaced = true;
703 if ( !visualReplaced ) // New registration entry
705 mImpl->mVisuals.PushBack( new RegisteredVisual( index, visual, actorToRegister, enabled ) );
708 if( visual && self.OnStage() && enabled )
710 visual.SetOnStage( placementActor );
714 void Control::UnregisterVisual( Property::Index index )
716 RegisteredVisualContainer::Iterator iter;
717 if ( FindVisual( index, mImpl->mVisuals, iter ) )
719 mImpl->mVisuals.Erase( iter );
723 Toolkit::Visual::Base Control::GetVisual( Property::Index index ) const
725 RegisteredVisualContainer::Iterator iter;
726 if ( FindVisual( index, mImpl->mVisuals, iter ) )
728 return (*iter)->visual;
731 return Toolkit::Visual::Base();
734 void Control::EnableVisual( Property::Index index, bool enable )
736 RegisteredVisualContainer::Iterator iter;
737 if ( FindVisual( index, mImpl->mVisuals, iter ) )
739 if ( (*iter)->enabled == enable )
744 (*iter)->enabled = enable;
745 Actor parentActor = Self();
746 if ( (*iter)->placementActor )
748 parentActor = (*iter)->placementActor;
751 if ( Self().OnStage() ) // If control not on Stage then Visual will be added when StageConnection is called.
756 (*iter)->visual.SetOnStage( parentActor );
760 (*iter)->visual.SetOffStage( parentActor ); // No need to call if control not staged.
766 bool Control::IsVisualEnabled( Property::Index index ) const
768 RegisteredVisualContainer::Iterator iter;
769 if ( FindVisual( index, mImpl->mVisuals, iter ) )
771 return (*iter)->enabled;
776 Actor Control::GetPlacementActor( Property::Index index ) const
778 RegisteredVisualContainer::Iterator iter;
779 if ( FindVisual( index, mImpl->mVisuals, iter ) )
781 if( (*iter)->placementActor )
783 return (*iter)->placementActor;
794 bool Control::OnAccessibilityActivated()
796 return false; // Accessibility activation is not handled by default
799 bool Control::OnKeyboardEnter()
801 return false; // Keyboard enter is not handled by default
804 bool Control::OnAccessibilityPan(PanGesture gesture)
806 return false; // Accessibility pan gesture is not handled by default
809 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
811 return false; // Accessibility touch event is not handled by default
814 bool Control::OnAccessibilityValueChange(bool isIncrease)
816 return false; // Accessibility value change action is not handled by default
819 bool Control::OnAccessibilityZoom()
821 return false; // Accessibility zoom action is not handled by default
824 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
829 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
833 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
835 return mImpl->mKeyEventSignal;
838 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusGainedSignal()
840 return mImpl->mKeyInputFocusGainedSignal;
843 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusLostSignal()
845 return mImpl->mKeyInputFocusLostSignal;
848 bool Control::EmitKeyEventSignal( const KeyEvent& event )
850 // Guard against destruction during signal emission
851 Dali::Toolkit::Control handle( GetOwner() );
853 bool consumed = false;
855 // signals are allocated dynamically when someone connects
856 if ( !mImpl->mKeyEventSignal.Empty() )
858 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
863 // Notification for derived classes
864 consumed = OnKeyEvent(event);
870 Control::Control( ControlBehaviour behaviourFlags )
871 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
872 mImpl(new Impl(*this))
874 mImpl->mFlags = behaviourFlags;
877 void Control::Initialize()
879 // Call deriving classes so initialised before styling is applied to them.
882 if( (mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS) ||
883 !(mImpl->mFlags & DISABLE_STYLE_CHANGE_SIGNALS) )
885 Toolkit::StyleManager styleManager = StyleManager::Get();
887 // if stylemanager is available
890 StyleManager& styleManagerImpl = GetImpl( styleManager );
892 // Register for style changes
893 styleManagerImpl.ControlStyleChangeSignal().Connect( this, &Control::OnStyleChange );
895 // Apply the current style
896 styleManagerImpl.ApplyThemeStyleAtInit( Toolkit::Control( GetOwner() ) );
900 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
902 SetKeyboardNavigationSupport( true );
906 void Control::OnInitialize()
910 void Control::OnControlChildAdd( Actor& child )
914 void Control::OnControlChildRemove( Actor& child )
918 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
920 // By default the control is only interested in theme (not font) changes
921 if( styleManager && change == StyleChange::THEME_CHANGE )
923 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
928 void Control::OnPinch(const PinchGesture& pinch)
930 if( !( mImpl->mStartingPinchScale ) )
933 mImpl->mStartingPinchScale = new Vector3;
936 if( pinch.state == Gesture::Started )
938 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
941 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
944 void Control::OnPan( const PanGesture& pan )
948 void Control::OnTap(const TapGesture& tap)
952 void Control::OnLongPress( const LongPressGesture& longPress )
956 void Control::EmitKeyInputFocusSignal( bool focusGained )
958 Dali::Toolkit::Control handle( GetOwner() );
962 // signals are allocated dynamically when someone connects
963 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
965 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
970 // signals are allocated dynamically when someone connects
971 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
973 mImpl->mKeyInputFocusLostSignal.Emit( handle );
978 void Control::OnStageConnection( int depth )
980 for(RegisteredVisualContainer::Iterator iter = mImpl->mVisuals.Begin(); iter!= mImpl->mVisuals.End(); iter++)
982 // Check whether the visual is empty, as it is allowed to register a placement actor without visual.
983 if( (*iter)->visual && (*iter)->enabled )
985 if( (*iter)->placementActor )
987 (*iter)->visual.SetOnStage( (*iter)->placementActor );
991 Actor self( Self() );
992 (*iter)->visual.SetOnStage( self );
998 void Control::OnStageDisconnection()
1000 for(RegisteredVisualContainer::Iterator iter = mImpl->mVisuals.Begin(); iter!= mImpl->mVisuals.End(); iter++)
1002 // Check whether the visual is empty, as it is allowed to register a placement actor without visual.
1003 if( (*iter)->visual )
1005 if( (*iter)->placementActor )
1007 (*iter)->visual.SetOffStage( (*iter)->placementActor );
1011 Actor self( Self() );
1012 (*iter)->visual.SetOffStage( self );
1018 void Control::OnKeyInputFocusGained()
1020 EmitKeyInputFocusSignal( true );
1023 void Control::OnKeyInputFocusLost()
1025 EmitKeyInputFocusSignal( false );
1028 void Control::OnChildAdd(Actor& child)
1030 // Notify derived classes.
1031 OnControlChildAdd( child );
1034 void Control::OnChildRemove(Actor& child)
1036 // Notify derived classes.
1037 OnControlChildRemove( child );
1040 void Control::OnSizeSet(const Vector3& targetSize)
1042 if( mImpl->mBackgroundVisual )
1044 Vector2 size( targetSize );
1045 mImpl->mBackgroundVisual.SetSize( size );
1049 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1051 // @todo size negotiate background to new size, animate as well?
1054 bool Control::OnTouchEvent(const TouchEvent& event)
1056 return false; // Do not consume
1059 bool Control::OnHoverEvent(const HoverEvent& event)
1061 return false; // Do not consume
1064 bool Control::OnKeyEvent(const KeyEvent& event)
1066 return false; // Do not consume
1069 bool Control::OnWheelEvent(const WheelEvent& event)
1071 return false; // Do not consume
1074 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
1076 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
1078 container.Add( Self().GetChildAt( i ), size );
1082 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
1086 Vector3 Control::GetNaturalSize()
1088 if( mImpl->mBackgroundVisual )
1090 Vector2 naturalSize;
1091 mImpl->mBackgroundVisual.GetNaturalSize(naturalSize);
1092 return Vector3(naturalSize);
1094 return Vector3::ZERO;
1097 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
1099 return CalculateChildSizeBase( child, dimension );
1102 float Control::GetHeightForWidth( float width )
1104 return GetHeightForWidthBase( width );
1107 float Control::GetWidthForHeight( float height )
1109 return GetWidthForHeightBase( height );
1112 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
1114 return RelayoutDependentOnChildrenBase( dimension );
1117 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
1121 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
1125 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1127 mImpl->SignalConnected( slotObserver, callback );
1130 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1132 mImpl->SignalDisconnected( slotObserver, callback );
1135 Control& GetImplementation( Dali::Toolkit::Control& handle )
1137 CustomActorImpl& customInterface = handle.GetImplementation();
1138 // downcast to control
1139 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
1143 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
1145 const CustomActorImpl& customInterface = handle.GetImplementation();
1146 // downcast to control
1147 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
1151 } // namespace Internal
1153 } // namespace Toolkit