2 * Copyright (c) 2017 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
26 #include <dali/public-api/animation/constraint.h>
27 #include <dali/public-api/animation/constraints.h>
28 #include <dali/public-api/object/type-registry.h>
29 #include <dali/public-api/object/type-registry-helper.h>
30 #include <dali/public-api/rendering/renderer.h>
31 #include <dali/public-api/size-negotiation/relayout-container.h>
32 #include <dali/devel-api/common/owner-container.h>
33 #include <dali/devel-api/object/handle-devel.h>
34 #include <dali/devel-api/scripting/enum-helper.h>
35 #include <dali/devel-api/scripting/scripting.h>
36 #include <dali/integration-api/debug.h>
39 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
40 #include <dali-toolkit/public-api/controls/control.h>
41 #include <dali-toolkit/public-api/styling/style-manager.h>
42 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
43 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
44 #include <dali-toolkit/devel-api/controls/control-devel.h>
45 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
46 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
47 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
48 #include <dali-toolkit/internal/styling/style-manager-impl.h>
49 #include <dali-toolkit/internal/visuals/color/color-visual.h>
50 #include <dali-toolkit/internal/visuals/transition-data-impl.h>
51 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
52 #include <dali-toolkit/devel-api/align-enums.h>
53 #include <dali-toolkit/internal/controls/tooltip/tooltip.h>
57 extern bool CaseInsensitiveStringCompare( const std::string& a, const std::string& b );
65 #if defined(DEBUG_ENABLED)
66 Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_CONTROL_VISUALS");
69 DALI_ENUM_TO_STRING_TABLE_BEGIN( CLIPPING_MODE )
70 DALI_ENUM_TO_STRING_WITH_SCOPE( ClippingMode, DISABLED )
71 DALI_ENUM_TO_STRING_WITH_SCOPE( ClippingMode, CLIP_CHILDREN )
72 DALI_ENUM_TO_STRING_TABLE_END( CLIPPING_MODE )
75 * Struct used to store Visual within the control, index is a unique key for each visual.
77 struct RegisteredVisual
79 Property::Index index;
80 Toolkit::Visual::Base visual;
83 RegisteredVisual( Property::Index aIndex, Toolkit::Visual::Base &aVisual, bool aEnabled)
84 : index(aIndex), visual(aVisual), enabled(aEnabled)
89 typedef Dali::OwnerContainer< RegisteredVisual* > RegisteredVisualContainer;
92 * Finds visual in given array, returning true if found along with the iterator for that visual as a out parameter
94 bool FindVisual( Property::Index targetIndex, RegisteredVisualContainer& visuals, RegisteredVisualContainer::Iterator& iter )
96 for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
98 if ( (*iter)->index == targetIndex )
106 Toolkit::Visual::Base GetVisualByName(
107 RegisteredVisualContainer& visuals,
108 const std::string& visualName )
110 Toolkit::Visual::Base visualHandle;
112 RegisteredVisualContainer::Iterator iter;
113 for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
115 Toolkit::Visual::Base visual = (*iter)->visual;
116 if( visual && visual.GetName() == visualName )
118 visualHandle = visual;
126 * Creates control through type registry
130 return Internal::Control::New();
134 * Performs actions as requested using the action name.
135 * @param[in] object The object on which to perform the action.
136 * @param[in] actionName The action to perform.
137 * @param[in] attributes The attributes with which to perfrom this action.
138 * @return true if action has been accepted by this control
140 const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibilityActivated";
141 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
145 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ) )
147 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
150 // if cast succeeds there is an implementation so no need to check
151 ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
159 * Connects a callback function with the object's signals.
160 * @param[in] object The object providing the signal.
161 * @param[in] tracker Used to disconnect the signal.
162 * @param[in] signalName The signal to connect to.
163 * @param[in] functor A newly allocated FunctorDelegate.
164 * @return True if the signal was connected.
165 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
167 const char* SIGNAL_KEY_EVENT = "keyEvent";
168 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "keyInputFocusGained";
169 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "keyInputFocusLost";
170 const char* SIGNAL_TAPPED = "tapped";
171 const char* SIGNAL_PANNED = "panned";
172 const char* SIGNAL_PINCHED = "pinched";
173 const char* SIGNAL_LONG_PRESSED = "longPressed";
174 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
176 Dali::BaseHandle handle( object );
178 bool connected( false );
179 Toolkit::Control control = Toolkit::Control::DownCast( handle );
182 Internal::Control& controlImpl( Internal::GetImplementation( control ) );
185 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
187 controlImpl.KeyEventSignal().Connect( tracker, functor );
189 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
191 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
193 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
195 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
197 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
199 controlImpl.EnableGestureDetection( Gesture::Tap );
200 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
202 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
204 controlImpl.EnableGestureDetection( Gesture::Pan );
205 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
207 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
209 controlImpl.EnableGestureDetection( Gesture::Pinch );
210 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
212 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
214 controlImpl.EnableGestureDetection( Gesture::LongPress );
215 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
221 const Scripting::StringEnum ControlStateTable[] = {
222 { "NORMAL", Toolkit::DevelControl::NORMAL },
223 { "FOCUSED", Toolkit::DevelControl::FOCUSED },
224 { "DISABLED", Toolkit::DevelControl::DISABLED },
225 }; const unsigned int ControlStateTableCount = sizeof( ControlStateTable ) / sizeof( ControlStateTable[0] );
227 // Setup signals and actions using the type-registry.
228 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
230 // Note: Properties are registered separately below.
232 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
233 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
234 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
235 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
236 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
237 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
238 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
240 TypeAction registerAction( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &DoAction );
242 DALI_TYPE_REGISTRATION_END()
244 } // unnamed namespace
249 class Control::Impl : public ConnectionTracker
253 // Construction & Destruction
254 Impl(Control& controlImpl)
255 : mControlImpl( controlImpl ),
256 mState( Toolkit::DevelControl::NORMAL ),
259 mBackgroundColor(Color::TRANSPARENT),
260 mStartingPinchScale( NULL ),
262 mPinchGestureDetector(),
263 mPanGestureDetector(),
264 mTapGestureDetector(),
265 mLongPressGestureDetector(),
266 mFlags( Control::ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
267 mIsKeyboardNavigationSupported( false ),
268 mIsKeyboardFocusGroup( false )
274 // All gesture detectors will be destroyed so no need to disconnect.
275 delete mStartingPinchScale;
278 // Gesture Detection Methods
280 void PinchDetected(Actor actor, const PinchGesture& pinch)
282 mControlImpl.OnPinch(pinch);
285 void PanDetected(Actor actor, const PanGesture& pan)
287 mControlImpl.OnPan(pan);
290 void TapDetected(Actor actor, const TapGesture& tap)
292 mControlImpl.OnTap(tap);
295 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
297 mControlImpl.OnLongPress(longPress);
303 * Called when a property of an object of this type is set.
304 * @param[in] object The object whose property is set.
305 * @param[in] index The property index.
306 * @param[in] value The new property value.
308 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
310 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
314 Control& controlImpl( GetImplementation( control ) );
318 case Toolkit::Control::Property::STYLE_NAME:
320 controlImpl.SetStyleName( value.Get< std::string >() );
324 case Toolkit::DevelControl::Property::STATE:
326 Toolkit::DevelControl::State state( controlImpl.mImpl->mState );
328 if( Scripting::GetEnumerationProperty< Toolkit::DevelControl::State >( value, ControlStateTable, ControlStateTableCount, state ) )
330 controlImpl.mImpl->SetState( state );
335 case Toolkit::DevelControl::Property::SUB_STATE:
337 std::string subState;
338 if( value.Get( subState ) )
340 controlImpl.mImpl->SetSubState( subState );
345 case Toolkit::Control::Property::BACKGROUND_COLOR:
347 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
348 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
352 case Toolkit::Control::Property::BACKGROUND_IMAGE:
354 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
355 Image image = Scripting::NewImage( value );
358 controlImpl.SetBackgroundImage( image );
362 // An empty image means the background is no longer required
363 controlImpl.ClearBackground();
368 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
370 if ( value.Get< bool >() )
372 controlImpl.SetKeyInputFocus();
376 controlImpl.ClearKeyInputFocus();
381 case Toolkit::Control::Property::BACKGROUND:
384 const Property::Map* map = value.GetMap();
385 if( map && !map->Empty() )
387 controlImpl.SetBackground( *map );
389 else if( value.Get( url ) )
391 // don't know the size to load
392 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( url, ImageDimensions() );
395 controlImpl.RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual );
396 visual.SetDepthIndex( DepthIndex::BACKGROUND );
401 // The background is an empty property map, so we should clear the background
402 controlImpl.ClearBackground();
407 case Toolkit::DevelControl::Property::TOOLTIP:
409 TooltipPtr& tooltipPtr = controlImpl.mImpl->mTooltip;
412 tooltipPtr = Tooltip::New( control );
414 tooltipPtr->SetProperties( value );
421 * Called to retrieve a property of an object of this type.
422 * @param[in] object The object whose property is to be retrieved.
423 * @param[in] index The property index.
424 * @return The current value of the property.
426 static Property::Value GetProperty( BaseObject* object, Property::Index index )
428 Property::Value value;
430 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
434 Control& controlImpl( GetImplementation( control ) );
438 case Toolkit::Control::Property::STYLE_NAME:
440 value = controlImpl.GetStyleName();
444 case Toolkit::DevelControl::Property::STATE:
446 value = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( controlImpl.mImpl->mState, ControlStateTable, ControlStateTableCount );
450 case Toolkit::Control::Property::BACKGROUND_COLOR:
452 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
453 value = controlImpl.GetBackgroundColor();
457 case Toolkit::Control::Property::BACKGROUND_IMAGE:
459 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
461 Toolkit::Visual::Base visual = controlImpl.GetVisual( Toolkit::Control::Property::BACKGROUND );
464 visual.CreatePropertyMap( map );
470 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
472 value = controlImpl.HasKeyInputFocus();
476 case Toolkit::Control::Property::BACKGROUND:
479 Toolkit::Visual::Base visual = controlImpl.GetVisual( Toolkit::Control::Property::BACKGROUND );
482 visual.CreatePropertyMap( map );
489 case Toolkit::DevelControl::Property::TOOLTIP:
492 if( controlImpl.mImpl->mTooltip )
494 controlImpl.mImpl->mTooltip->CreatePropertyMap( map );
506 void SetState( DevelControl::State state )
508 if( mState != state )
510 // If mState was Disabled, and new state is Focused, should probably
511 // store that fact, e.g. in another property that FocusManager can access.
514 // Trigger state change and transitions
515 // Apply new style, if stylemanager is available
516 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
519 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
522 for( int i=mVisuals.Count()-1; i >= 0; i-- )
524 mControlImpl.UnregisterVisual( mVisuals[i]->index );
527 Dali::CustomActor handle( mControlImpl.GetOwner() );
528 stylePtr->ApplyVisualsAndPropertiesRecursively( handle );
534 void SetSubState( const std::string& state )
536 if( mSubState != state )
539 // Trigger transitions
546 Control& mControlImpl;
547 DevelControl::State mState;
548 std::string mSubState;
550 RegisteredVisualContainer mVisuals; // Stores visuals needed by the control, non trivial type so std::vector used.
551 std::string mStyleName;
552 Vector4 mBackgroundColor; ///< The color of the background visual
553 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
554 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
555 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
556 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
559 PinchGestureDetector mPinchGestureDetector;
560 PanGestureDetector mPanGestureDetector;
561 TapGestureDetector mTapGestureDetector;
562 LongPressGestureDetector mLongPressGestureDetector;
567 ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
568 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
569 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
571 // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
572 static const PropertyRegistration PROPERTY_1;
573 static const PropertyRegistration PROPERTY_2;
574 static const PropertyRegistration PROPERTY_3;
575 static const PropertyRegistration PROPERTY_4;
576 static const PropertyRegistration PROPERTY_5;
577 static const PropertyRegistration PROPERTY_6;
578 static const PropertyRegistration PROPERTY_7;
579 static const PropertyRegistration PROPERTY_8;
582 // Properties registered without macro to use specific member variables.
583 const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
584 const PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "backgroundColor", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
585 const PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "backgroundImage", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
586 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
587 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
588 const PropertyRegistration Control::Impl::PROPERTY_6( typeRegistration, "tooltip", Toolkit::DevelControl::Property::TOOLTIP, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
589 const PropertyRegistration Control::Impl::PROPERTY_7( typeRegistration, "state", Toolkit::DevelControl::Property::STATE, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
590 const PropertyRegistration Control::Impl::PROPERTY_8( typeRegistration, "subState", Toolkit::DevelControl::Property::SUB_STATE, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
592 Toolkit::Control Control::New()
594 // Create the implementation, temporarily owned on stack
595 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) );
597 // Pass ownership to handle
598 Toolkit::Control handle( *controlImpl );
600 // Second-phase init of the implementation
601 // This can only be done after the CustomActor connection has been made...
602 controlImpl->Initialize();
607 void Control::SetStyleName( const std::string& styleName )
609 if( styleName != mImpl->mStyleName )
611 mImpl->mStyleName = styleName;
613 // Apply new style, if stylemanager is available
614 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
617 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
622 const std::string& Control::GetStyleName() const
624 return mImpl->mStyleName;
627 void Control::SetBackgroundColor( const Vector4& color )
629 mImpl->mBackgroundColor = color;
631 map[ Toolkit::DevelVisual::Property::TYPE ] = Toolkit::Visual::COLOR;
632 map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color;
634 SetBackground( map );
637 Vector4 Control::GetBackgroundColor() const
639 return mImpl->mBackgroundColor;
642 void Control::SetBackground( const Property::Map& map )
644 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( map );
647 RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual );
648 visual.SetDepthIndex( DepthIndex::BACKGROUND );
650 // Trigger a size negotiation request that may be needed by the new visual to relayout its contents.
655 void Control::SetBackgroundImage( Image image )
657 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( image );
660 RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual );
661 visual.SetDepthIndex( DepthIndex::BACKGROUND );
665 void Control::ClearBackground()
667 UnregisterVisual( Toolkit::Control::Property::BACKGROUND );
668 mImpl->mBackgroundColor = Color::TRANSPARENT;
670 // Trigger a size negotiation request that may be needed when unregistering a visual.
674 void Control::EnableGestureDetection(Gesture::Type type)
676 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
678 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
679 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
680 mImpl->mPinchGestureDetector.Attach(Self());
683 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
685 mImpl->mPanGestureDetector = PanGestureDetector::New();
686 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
687 mImpl->mPanGestureDetector.Attach(Self());
690 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
692 mImpl->mTapGestureDetector = TapGestureDetector::New();
693 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
694 mImpl->mTapGestureDetector.Attach(Self());
697 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
699 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
700 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
701 mImpl->mLongPressGestureDetector.Attach(Self());
705 void Control::DisableGestureDetection(Gesture::Type type)
707 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
709 mImpl->mPinchGestureDetector.Detach(Self());
710 mImpl->mPinchGestureDetector.Reset();
713 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
715 mImpl->mPanGestureDetector.Detach(Self());
716 mImpl->mPanGestureDetector.Reset();
719 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
721 mImpl->mTapGestureDetector.Detach(Self());
722 mImpl->mTapGestureDetector.Reset();
725 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
727 mImpl->mLongPressGestureDetector.Detach(Self());
728 mImpl->mLongPressGestureDetector.Reset();
732 PinchGestureDetector Control::GetPinchGestureDetector() const
734 return mImpl->mPinchGestureDetector;
737 PanGestureDetector Control::GetPanGestureDetector() const
739 return mImpl->mPanGestureDetector;
742 TapGestureDetector Control::GetTapGestureDetector() const
744 return mImpl->mTapGestureDetector;
747 LongPressGestureDetector Control::GetLongPressGestureDetector() const
749 return mImpl->mLongPressGestureDetector;
752 void Control::SetKeyboardNavigationSupport(bool isSupported)
754 mImpl->mIsKeyboardNavigationSupported = isSupported;
757 bool Control::IsKeyboardNavigationSupported()
759 return mImpl->mIsKeyboardNavigationSupported;
762 void Control::SetKeyInputFocus()
764 if( Self().OnStage() )
766 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
770 bool Control::HasKeyInputFocus()
773 if( Self().OnStage() )
775 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
780 void Control::ClearKeyInputFocus()
782 if( Self().OnStage() )
784 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
788 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
790 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
792 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
793 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
796 bool Control::IsKeyboardFocusGroup()
798 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
801 void Control::AccessibilityActivate()
803 // Inform deriving classes
804 OnAccessibilityActivated();
807 void Control::KeyboardEnter()
809 // Inform deriving classes
813 void Control::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual )
815 RegisterVisual( index, visual, true );
818 void Control::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled )
820 bool visualReplaced ( false );
823 if( !mImpl->mVisuals.Empty() )
825 RegisteredVisualContainer::Iterator iter;
826 // Check if visual (index) is already registered. Replace if so.
827 if ( FindVisual( index, mImpl->mVisuals, iter ) )
829 if( (*iter)->visual && self.OnStage() )
831 Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
833 (*iter)->visual = visual;
834 visualReplaced = true;
838 // If not set, set the name of the visual to the same name as the control's property.
839 // ( If the control has been type registered )
840 if( visual.GetName().empty() )
842 // Check if the control has been type registered:
843 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(*this) );
846 // Check if the property index has been registered:
847 Property::IndexContainer indices;
848 typeInfo.GetPropertyIndices( indices );
849 Property::IndexContainer::Iterator iter = std::find( indices.Begin(), indices.End(), index );
850 if( iter != indices.End() )
852 // If it has, then get it's name and use that for the visual
853 std::string visualName = typeInfo.GetPropertyName( index );
854 visual.SetName( visualName );
859 if( !visualReplaced ) // New registration entry
861 mImpl->mVisuals.PushBack( new RegisteredVisual( index, visual, enabled ) );
864 if( visual && self.OnStage() && enabled )
866 Toolkit::GetImplementation(visual).SetOnStage( self );
869 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::RegisterVisual() Registered %s(%d), enabled:%s\n", visual.GetName().c_str(), index, enabled?"T":"F" );
872 void Control::UnregisterVisual( Property::Index index )
874 RegisteredVisualContainer::Iterator iter;
875 if ( FindVisual( index, mImpl->mVisuals, iter ) )
877 Actor self( Self() );
878 Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
879 (*iter)->visual.Reset();
880 mImpl->mVisuals.Erase( iter );
884 Toolkit::Visual::Base Control::GetVisual( Property::Index index ) const
886 RegisteredVisualContainer::Iterator iter;
887 if ( FindVisual( index, mImpl->mVisuals, iter ) )
889 return (*iter)->visual;
892 return Toolkit::Visual::Base();
895 void Control::EnableVisual( Property::Index index, bool enable )
897 RegisteredVisualContainer::Iterator iter;
898 if ( FindVisual( index, mImpl->mVisuals, iter ) )
900 if ( (*iter)->enabled == enable )
902 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Visual %s(%d) already %s\n", (*iter)->visual.GetName().c_str(), index, enable?"enabled":"disabled");
906 (*iter)->enabled = enable;
907 Actor parentActor = Self();
908 if ( Self().OnStage() ) // If control not on Stage then Visual will be added when StageConnection is called.
912 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) on stage \n", (*iter)->visual.GetName().c_str(), index );
913 Toolkit::GetImplementation((*iter)->visual).SetOnStage( parentActor );
917 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) off stage \n", (*iter)->visual.GetName().c_str(), index );
918 Toolkit::GetImplementation((*iter)->visual).SetOffStage( parentActor ); // No need to call if control not staged.
924 bool Control::IsVisualEnabled( Property::Index index ) const
926 RegisteredVisualContainer::Iterator iter;
927 if ( FindVisual( index, mImpl->mVisuals, iter ) )
929 return (*iter)->enabled;
934 Dali::Animation Control::CreateTransition( const Toolkit::TransitionData& handle )
936 Dali::Animation transition;
937 const Internal::TransitionData& transitionData = Toolkit::GetImplementation( handle );
939 if( transitionData.Count() > 0 )
941 // Setup a Transition from TransitionData.
942 TransitionData::Iterator end = transitionData.End();
943 for( TransitionData::Iterator iter = transitionData.Begin() ;
944 iter != end; ++iter )
946 TransitionData::Animator* animator = (*iter);
948 Toolkit::Visual::Base visual = GetVisualByName( mImpl->mVisuals, animator->objectName );
952 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
953 visualImpl.AnimateProperty( transition, *animator );
957 // Otherwise, try any actor children of control (Including the control)
958 Actor child = Self().FindChildByName( animator->objectName );
961 Property::Index propertyIndex = DevelHandle::GetPropertyIndex( child, animator->propertyKey );
962 if( propertyIndex != Property::INVALID_INDEX )
964 if( animator->animate == false )
966 if( animator->targetValue.GetType() != Property::NONE )
968 child.SetProperty( propertyIndex, animator->targetValue );
971 else // animate the property
973 if( animator->initialValue.GetType() != Property::NONE )
975 child.SetProperty( propertyIndex, animator->initialValue );
980 transition = Dali::Animation::New( 0.1f );
983 transition.AnimateTo( Property( child, propertyIndex ),
984 animator->targetValue,
985 animator->alphaFunction,
986 TimePeriod( animator->timePeriodDelay,
987 animator->timePeriodDuration ) );
998 bool Control::OnAccessibilityActivated()
1000 return false; // Accessibility activation is not handled by default
1003 bool Control::OnKeyboardEnter()
1005 return false; // Keyboard enter is not handled by default
1008 bool Control::OnAccessibilityPan(PanGesture gesture)
1010 return false; // Accessibility pan gesture is not handled by default
1013 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
1015 return false; // Accessibility touch event is not handled by default
1018 bool Control::OnAccessibilityValueChange(bool isIncrease)
1020 return false; // Accessibility value change action is not handled by default
1023 bool Control::OnAccessibilityZoom()
1025 return false; // Accessibility zoom action is not handled by default
1028 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
1033 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
1037 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
1039 return mImpl->mKeyEventSignal;
1042 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusGainedSignal()
1044 return mImpl->mKeyInputFocusGainedSignal;
1047 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusLostSignal()
1049 return mImpl->mKeyInputFocusLostSignal;
1052 bool Control::EmitKeyEventSignal( const KeyEvent& event )
1054 // Guard against destruction during signal emission
1055 Dali::Toolkit::Control handle( GetOwner() );
1057 bool consumed = false;
1059 // signals are allocated dynamically when someone connects
1060 if ( !mImpl->mKeyEventSignal.Empty() )
1062 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
1067 // Notification for derived classes
1068 consumed = OnKeyEvent(event);
1074 Control::Control( ControlBehaviour behaviourFlags )
1075 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
1076 mImpl(new Impl(*this))
1078 mImpl->mFlags = behaviourFlags;
1086 void Control::Initialize()
1088 // Call deriving classes so initialised before styling is applied to them.
1091 if( (mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS) ||
1092 !(mImpl->mFlags & DISABLE_STYLE_CHANGE_SIGNALS) )
1094 Toolkit::StyleManager styleManager = StyleManager::Get();
1096 // if stylemanager is available
1099 StyleManager& styleManagerImpl = GetImpl( styleManager );
1101 // Register for style changes
1102 styleManagerImpl.ControlStyleChangeSignal().Connect( this, &Control::OnStyleChange );
1104 // Apply the current style
1105 styleManagerImpl.ApplyThemeStyleAtInit( Toolkit::Control( GetOwner() ) );
1109 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
1111 SetKeyboardNavigationSupport( true );
1115 void Control::OnInitialize()
1119 void Control::OnControlChildAdd( Actor& child )
1123 void Control::OnControlChildRemove( Actor& child )
1127 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1129 // By default the control is only interested in theme (not font) changes
1130 if( styleManager && change == StyleChange::THEME_CHANGE )
1132 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1137 void Control::OnPinch(const PinchGesture& pinch)
1139 if( !( mImpl->mStartingPinchScale ) )
1142 mImpl->mStartingPinchScale = new Vector3;
1145 if( pinch.state == Gesture::Started )
1147 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
1150 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
1153 void Control::OnPan( const PanGesture& pan )
1157 void Control::OnTap(const TapGesture& tap)
1161 void Control::OnLongPress( const LongPressGesture& longPress )
1165 void Control::EmitKeyInputFocusSignal( bool focusGained )
1167 Dali::Toolkit::Control handle( GetOwner() );
1171 // signals are allocated dynamically when someone connects
1172 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
1174 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
1179 // signals are allocated dynamically when someone connects
1180 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
1182 mImpl->mKeyInputFocusLostSignal.Emit( handle );
1187 void Control::OnStageConnection( int depth )
1189 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::OnStageConnection number of registered visuals(%d)\n", mImpl->mVisuals.Size() );
1191 Actor self( Self() );
1193 for(RegisteredVisualContainer::Iterator iter = mImpl->mVisuals.Begin(); iter!= mImpl->mVisuals.End(); iter++)
1195 // Check whether the visual is empty and enabled
1196 if( (*iter)->visual && (*iter)->enabled )
1198 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::OnStageConnection Setting visual(%d) on stage\n", (*iter)->index );
1199 Toolkit::GetImplementation((*iter)->visual).SetOnStage( self );
1203 if( mImpl->mVisuals.Empty() && ! self.GetRendererCount() )
1205 Property::Value clippingValue = self.GetProperty( Actor::Property::CLIPPING_MODE );
1206 int clippingMode = ClippingMode::DISABLED;
1207 if( clippingValue.Get( clippingMode ) )
1209 // Add a transparent background if we do not have any renderers or visuals so we clip our children
1211 if( clippingMode == ClippingMode::CLIP_CHILDREN )
1213 // Create a transparent background visual which will also get staged.
1214 SetBackgroundColor( Color::TRANSPARENT );
1220 void Control::OnStageDisconnection()
1222 for(RegisteredVisualContainer::Iterator iter = mImpl->mVisuals.Begin(); iter!= mImpl->mVisuals.End(); iter++)
1224 // Check whether the visual is empty
1225 if( (*iter)->visual )
1227 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::OnStageDisconnection Setting visual(%d) off stage\n", (*iter)->index );
1228 Actor self( Self() );
1229 Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
1234 void Control::OnKeyInputFocusGained()
1236 EmitKeyInputFocusSignal( true );
1239 void Control::OnKeyInputFocusLost()
1241 EmitKeyInputFocusSignal( false );
1244 void Control::OnChildAdd(Actor& child)
1246 // Notify derived classes.
1247 OnControlChildAdd( child );
1250 void Control::OnChildRemove(Actor& child)
1252 // Notify derived classes.
1253 OnControlChildRemove( child );
1256 void Control::OnPropertySet( Property::Index index, Property::Value propertyValue )
1258 Actor self( Self() );
1259 if( index == Actor::Property::CLIPPING_MODE )
1261 // Only set the background if we're already on the stage and have no renderers or visuals
1263 if( mImpl->mVisuals.Empty() && ! self.GetRendererCount() && self.OnStage() )
1265 ClippingMode::Type clippingMode = ClippingMode::DISABLED;
1266 if( Scripting::GetEnumerationProperty< ClippingMode::Type >( propertyValue, CLIPPING_MODE_TABLE, CLIPPING_MODE_TABLE_COUNT, clippingMode ) )
1268 // Add a transparent background if we do not have one so we clip children
1270 if( clippingMode == ClippingMode::CLIP_CHILDREN )
1272 SetBackgroundColor( Color::TRANSPARENT );
1279 void Control::OnSizeSet(const Vector3& targetSize)
1281 Toolkit::Visual::Base visual = GetVisual( Toolkit::Control::Property::BACKGROUND );
1284 Vector2 size( targetSize );
1285 visual.SetTransformAndSize( Property::Map(), size ); // Send an empty map as we do not want to modify the visual's set transform
1289 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1291 // @todo size negotiate background to new size, animate as well?
1294 bool Control::OnTouchEvent(const TouchEvent& event)
1296 return false; // Do not consume
1299 bool Control::OnHoverEvent(const HoverEvent& event)
1301 return false; // Do not consume
1304 bool Control::OnKeyEvent(const KeyEvent& event)
1306 return false; // Do not consume
1309 bool Control::OnWheelEvent(const WheelEvent& event)
1311 return false; // Do not consume
1314 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
1316 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
1318 container.Add( Self().GetChildAt( i ), size );
1321 Toolkit::Visual::Base visual = GetVisual( Toolkit::Control::Property::BACKGROUND );
1324 visual.SetTransformAndSize( Property::Map(), size ); // Send an empty map as we do not want to modify the visual's set transform
1328 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
1332 Vector3 Control::GetNaturalSize()
1334 Toolkit::Visual::Base visual = GetVisual( Toolkit::Control::Property::BACKGROUND );
1337 Vector2 naturalSize;
1338 visual.GetNaturalSize( naturalSize );
1339 return Vector3( naturalSize );
1341 return Vector3::ZERO;
1344 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
1346 return CalculateChildSizeBase( child, dimension );
1349 float Control::GetHeightForWidth( float width )
1351 return GetHeightForWidthBase( width );
1354 float Control::GetWidthForHeight( float height )
1356 return GetWidthForHeightBase( height );
1359 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
1361 return RelayoutDependentOnChildrenBase( dimension );
1364 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
1368 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
1372 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1374 mImpl->SignalConnected( slotObserver, callback );
1377 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1379 mImpl->SignalDisconnected( slotObserver, callback );
1382 Control& GetImplementation( Dali::Toolkit::Control& handle )
1384 CustomActorImpl& customInterface = handle.GetImplementation();
1385 // downcast to control
1386 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
1390 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
1392 const CustomActorImpl& customInterface = handle.GetImplementation();
1393 // downcast to control
1394 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
1398 } // namespace Internal
1400 } // namespace Toolkit