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
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/scripting.h>
35 #include <dali/integration-api/debug.h>
38 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
39 #include <dali-toolkit/public-api/controls/control.h>
40 #include <dali-toolkit/public-api/styling/style-manager.h>
41 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
42 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
43 #include <dali-toolkit/devel-api/controls/control-devel.h>
44 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
45 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
46 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
47 #include <dali-toolkit/internal/styling/style-manager-impl.h>
48 #include <dali-toolkit/internal/visuals/color/color-visual.h>
49 #include <dali-toolkit/internal/visuals/transition-data-impl.h>
50 #include <dali-toolkit/devel-api/align-enums.h>
51 #include <dali-toolkit/internal/controls/tooltip/tooltip.h>
62 #if defined(DEBUG_ENABLED)
63 Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_CONTROL_VISUALS");
67 * Struct used to store Visual within the control, index is a unique key for each visual.
69 struct RegisteredVisual
71 Property::Index index;
72 Toolkit::Visual::Base visual;
75 RegisteredVisual( Property::Index aIndex, Toolkit::Visual::Base &aVisual, bool aEnabled) :
76 index(aIndex), visual(aVisual), enabled(aEnabled) {}
81 Handle handle; ///< a handle to the target object
82 Property::Index index; ///< The index of a property provided by the referenced object
86 index( Property::INVALID_INDEX )
90 HandleIndex( Handle& handle, Property::Index index )
98 typedef Dali::OwnerContainer< RegisteredVisual* > RegisteredVisualContainer;
101 * Finds visual in given array, returning true if found along with the iterator for that visual as a out parameter
103 bool FindVisual( Property::Index targetIndex, RegisteredVisualContainer& visuals, RegisteredVisualContainer::Iterator& iter )
105 for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
107 if ( (*iter)->index == targetIndex )
115 HandleIndex GetVisualProperty(
116 Internal::Control& controlImpl,
117 RegisteredVisualContainer& visuals,
118 const std::string& visualName,
119 Property::Key propertyKey )
121 #if defined(DEBUG_ENABLED)
122 std::ostringstream oss;
123 oss << "Control::GetVisualProperty(" << visualName << ", " << propertyKey << ")" << std::endl;
124 DALI_LOG_INFO( gLogFilter, Debug::General, oss.str().c_str() );
127 // Find visualName in the control
128 RegisteredVisualContainer::Iterator iter;
129 for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
131 Toolkit::Visual::Base visual = (*iter)->visual;
132 if( visual && visual.GetName() == visualName )
134 Internal::Visual::Base& visualImpl = GetImplementation(visual);
135 Renderer renderer = visualImpl.GetRenderer();
138 Property::Index index = DevelHandle::GetPropertyIndex( renderer, propertyKey );
139 if( index != Property::INVALID_INDEX )
141 return HandleIndex( renderer, index );
147 std::ostringstream noRenderers;
148 noRenderers << propertyKey;
149 DALI_LOG_WARNING( "Control::GetVisualProperty(%s, %s) No renderers\n", visualName.c_str(), noRenderers.str().c_str() );
151 return HandleIndex( handle, Property::INVALID_INDEX );
154 void SetDefaultTransform( Property::Map& propertyMap )
158 .Add( Toolkit::DevelVisual::Transform::Property::OFFSET, Vector2(0.0f, 0.0f) )
159 .Add( Toolkit::DevelVisual::Transform::Property::SIZE, Vector2(1.0f, 1.0f) )
160 .Add( Toolkit::DevelVisual::Transform::Property::ORIGIN, Toolkit::Align::CENTER )
161 .Add( Toolkit::DevelVisual::Transform::Property::ANCHOR_POINT, Toolkit::Align::CENTER )
162 .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_SIZE_MODE, Vector4::ZERO );
166 * Creates control through type registry
170 return Internal::Control::New();
174 * Performs actions as requested using the action name.
175 * @param[in] object The object on which to perform the action.
176 * @param[in] actionName The action to perform.
177 * @param[in] attributes The attributes with which to perfrom this action.
178 * @return true if action has been accepted by this control
180 const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibilityActivated";
181 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
185 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ) )
187 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
190 // if cast succeeds there is an implementation so no need to check
191 ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
199 * Connects a callback function with the object's signals.
200 * @param[in] object The object providing the signal.
201 * @param[in] tracker Used to disconnect the signal.
202 * @param[in] signalName The signal to connect to.
203 * @param[in] functor A newly allocated FunctorDelegate.
204 * @return True if the signal was connected.
205 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
207 const char* SIGNAL_KEY_EVENT = "keyEvent";
208 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "keyInputFocusGained";
209 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "keyInputFocusLost";
210 const char* SIGNAL_TAPPED = "tapped";
211 const char* SIGNAL_PANNED = "panned";
212 const char* SIGNAL_PINCHED = "pinched";
213 const char* SIGNAL_LONG_PRESSED = "longPressed";
214 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
216 Dali::BaseHandle handle( object );
218 bool connected( false );
219 Toolkit::Control control = Toolkit::Control::DownCast( handle );
222 Internal::Control& controlImpl( Internal::GetImplementation( control ) );
225 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
227 controlImpl.KeyEventSignal().Connect( tracker, functor );
229 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
231 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
233 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
235 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
237 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
239 controlImpl.EnableGestureDetection( Gesture::Tap );
240 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
242 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
244 controlImpl.EnableGestureDetection( Gesture::Pan );
245 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
247 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
249 controlImpl.EnableGestureDetection( Gesture::Pinch );
250 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
252 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
254 controlImpl.EnableGestureDetection( Gesture::LongPress );
255 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
261 // Setup signals and actions using the type-registry.
262 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
264 // Note: Properties are registered separately below.
266 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
267 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
268 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
269 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
270 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
271 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
272 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
274 TypeAction registerAction( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &DoAction );
276 DALI_TYPE_REGISTRATION_END()
278 } // unnamed namespace
283 class Control::Impl : public ConnectionTracker
287 // Construction & Destruction
288 Impl(Control& controlImpl)
289 : mControlImpl( controlImpl ),
291 mBackgroundColor(Color::TRANSPARENT),
292 mStartingPinchScale( NULL ),
294 mPinchGestureDetector(),
295 mPanGestureDetector(),
296 mTapGestureDetector(),
297 mLongPressGestureDetector(),
298 mFlags( Control::ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
299 mIsKeyboardNavigationSupported( false ),
300 mIsKeyboardFocusGroup( false )
306 // All gesture detectors will be destroyed so no need to disconnect.
307 delete mStartingPinchScale;
310 // Gesture Detection Methods
312 void PinchDetected(Actor actor, const PinchGesture& pinch)
314 mControlImpl.OnPinch(pinch);
317 void PanDetected(Actor actor, const PanGesture& pan)
319 mControlImpl.OnPan(pan);
322 void TapDetected(Actor actor, const TapGesture& tap)
324 mControlImpl.OnTap(tap);
327 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
329 mControlImpl.OnLongPress(longPress);
335 * Called when a property of an object of this type is set.
336 * @param[in] object The object whose property is set.
337 * @param[in] index The property index.
338 * @param[in] value The new property value.
340 static void SetProperty( BaseObject* object, Property::Index index, const 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 controlImpl.SetStyleName( value.Get< std::string >() );
356 case Toolkit::Control::Property::BACKGROUND_COLOR:
358 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
359 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
363 case Toolkit::Control::Property::BACKGROUND_IMAGE:
365 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
366 Image image = Scripting::NewImage( value );
369 controlImpl.SetBackgroundImage( image );
373 // An empty image means the background is no longer required
374 controlImpl.ClearBackground();
379 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
381 if ( value.Get< bool >() )
383 controlImpl.SetKeyInputFocus();
387 controlImpl.ClearKeyInputFocus();
392 case Toolkit::Control::Property::BACKGROUND:
395 const Property::Map* map = value.GetMap();
396 if( map && !map->Empty() )
398 controlImpl.SetBackground( *map );
400 else if( value.Get( url ) )
402 // don't know the size to load
403 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( url, ImageDimensions() );
406 controlImpl.RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual );
407 visual.SetDepthIndex( DepthIndex::BACKGROUND );
412 // The background is an empty property map, so we should clear the background
413 controlImpl.ClearBackground();
418 case Toolkit::DevelControl::Property::TOOLTIP:
420 TooltipPtr& tooltipPtr = controlImpl.mImpl->mTooltip;
423 tooltipPtr = Tooltip::New( control );
425 tooltipPtr->SetProperties( value );
432 * Called to retrieve a property of an object of this type.
433 * @param[in] object The object whose property is to be retrieved.
434 * @param[in] index The property index.
435 * @return The current value of the property.
437 static Property::Value GetProperty( BaseObject* object, Property::Index index )
439 Property::Value value;
441 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
445 Control& controlImpl( GetImplementation( control ) );
449 case Toolkit::Control::Property::STYLE_NAME:
451 value = controlImpl.GetStyleName();
455 case Toolkit::Control::Property::BACKGROUND_COLOR:
457 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
458 value = controlImpl.GetBackgroundColor();
462 case Toolkit::Control::Property::BACKGROUND_IMAGE:
464 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
466 Toolkit::Visual::Base visual = controlImpl.GetVisual( Toolkit::Control::Property::BACKGROUND );
469 visual.CreatePropertyMap( map );
475 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
477 value = controlImpl.HasKeyInputFocus();
481 case Toolkit::Control::Property::BACKGROUND:
484 Toolkit::Visual::Base visual = controlImpl.GetVisual( Toolkit::Control::Property::BACKGROUND );
487 visual.CreatePropertyMap( map );
494 case Toolkit::DevelControl::Property::TOOLTIP:
497 if( controlImpl.mImpl->mTooltip )
499 controlImpl.mImpl->mTooltip->CreatePropertyMap( map );
513 Control& mControlImpl;
514 RegisteredVisualContainer mVisuals; // Stores visuals needed by the control, non trivial type so std::vector used.
515 std::string mStyleName;
516 Vector4 mBackgroundColor; ///< The color of the background visual
517 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
518 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
519 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
520 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
523 PinchGestureDetector mPinchGestureDetector;
524 PanGestureDetector mPanGestureDetector;
525 TapGestureDetector mTapGestureDetector;
526 LongPressGestureDetector mLongPressGestureDetector;
531 ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
532 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
533 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
535 // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
536 static const PropertyRegistration PROPERTY_1;
537 static const PropertyRegistration PROPERTY_2;
538 static const PropertyRegistration PROPERTY_3;
539 static const PropertyRegistration PROPERTY_4;
540 static const PropertyRegistration PROPERTY_5;
541 static const PropertyRegistration PROPERTY_6;
544 // Properties registered without macro to use specific member variables.
545 const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
546 const PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "backgroundColor", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
547 const PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "backgroundImage", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
548 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
549 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
550 const PropertyRegistration Control::Impl::PROPERTY_6( typeRegistration, "tooltip", Toolkit::DevelControl::Property::TOOLTIP, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
552 Toolkit::Control Control::New()
554 // Create the implementation, temporarily owned on stack
555 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) );
557 // Pass ownership to handle
558 Toolkit::Control handle( *controlImpl );
560 // Second-phase init of the implementation
561 // This can only be done after the CustomActor connection has been made...
562 controlImpl->Initialize();
567 void Control::SetStyleName( const std::string& styleName )
569 if( styleName != mImpl->mStyleName )
571 mImpl->mStyleName = styleName;
573 // Apply new style, if stylemanager is available
574 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
577 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
582 const std::string& Control::GetStyleName() const
584 return mImpl->mStyleName;
587 void Control::SetBackgroundColor( const Vector4& color )
589 mImpl->mBackgroundColor = color;
591 map[ Toolkit::DevelVisual::Property::TYPE ] = Toolkit::Visual::COLOR;
592 map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color;
594 SetBackground( map );
597 Vector4 Control::GetBackgroundColor() const
599 return mImpl->mBackgroundColor;
602 void Control::SetBackground( const Property::Map& map )
604 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( map );
607 RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual );
608 visual.SetDepthIndex( DepthIndex::BACKGROUND );
610 // Trigger a size negotiation request that may be needed by the new visual to relayout its contents.
615 void Control::SetBackgroundImage( Image image )
617 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( image );
620 RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual );
621 visual.SetDepthIndex( DepthIndex::BACKGROUND );
625 void Control::ClearBackground()
627 UnregisterVisual( Toolkit::Control::Property::BACKGROUND );
628 mImpl->mBackgroundColor = Color::TRANSPARENT;
630 // Trigger a size negotiation request that may be needed when unregistering a visual.
634 void Control::EnableGestureDetection(Gesture::Type type)
636 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
638 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
639 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
640 mImpl->mPinchGestureDetector.Attach(Self());
643 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
645 mImpl->mPanGestureDetector = PanGestureDetector::New();
646 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
647 mImpl->mPanGestureDetector.Attach(Self());
650 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
652 mImpl->mTapGestureDetector = TapGestureDetector::New();
653 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
654 mImpl->mTapGestureDetector.Attach(Self());
657 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
659 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
660 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
661 mImpl->mLongPressGestureDetector.Attach(Self());
665 void Control::DisableGestureDetection(Gesture::Type type)
667 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
669 mImpl->mPinchGestureDetector.Detach(Self());
670 mImpl->mPinchGestureDetector.Reset();
673 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
675 mImpl->mPanGestureDetector.Detach(Self());
676 mImpl->mPanGestureDetector.Reset();
679 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
681 mImpl->mTapGestureDetector.Detach(Self());
682 mImpl->mTapGestureDetector.Reset();
685 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
687 mImpl->mLongPressGestureDetector.Detach(Self());
688 mImpl->mLongPressGestureDetector.Reset();
692 PinchGestureDetector Control::GetPinchGestureDetector() const
694 return mImpl->mPinchGestureDetector;
697 PanGestureDetector Control::GetPanGestureDetector() const
699 return mImpl->mPanGestureDetector;
702 TapGestureDetector Control::GetTapGestureDetector() const
704 return mImpl->mTapGestureDetector;
707 LongPressGestureDetector Control::GetLongPressGestureDetector() const
709 return mImpl->mLongPressGestureDetector;
712 void Control::SetKeyboardNavigationSupport(bool isSupported)
714 mImpl->mIsKeyboardNavigationSupported = isSupported;
717 bool Control::IsKeyboardNavigationSupported()
719 return mImpl->mIsKeyboardNavigationSupported;
722 void Control::SetKeyInputFocus()
724 if( Self().OnStage() )
726 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
730 bool Control::HasKeyInputFocus()
733 if( Self().OnStage() )
735 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
740 void Control::ClearKeyInputFocus()
742 if( Self().OnStage() )
744 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
748 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
750 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
752 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
753 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
756 bool Control::IsKeyboardFocusGroup()
758 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
761 void Control::AccessibilityActivate()
763 // Inform deriving classes
764 OnAccessibilityActivated();
767 void Control::KeyboardEnter()
769 // Inform deriving classes
773 void Control::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual )
775 RegisterVisual( index, visual, true );
778 void Control::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled )
780 bool visualReplaced ( false );
783 if( !mImpl->mVisuals.Empty() )
785 RegisteredVisualContainer::Iterator iter;
786 // Check if visual (index) is already registered. Replace if so.
787 if ( FindVisual( index, mImpl->mVisuals, iter ) )
789 if( (*iter)->visual && self.OnStage() )
791 Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
793 (*iter)->visual = visual;
794 visualReplaced = true;
798 // If not set, set the name of the visual to the same name as the control's property.
799 // ( If the control has been type registered )
800 if( visual.GetName().empty() )
802 // Check if the control has been type registered:
803 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(*this) );
806 // Check if the property index has been registered:
807 Property::IndexContainer indices;
808 typeInfo.GetPropertyIndices( indices );
809 Property::IndexContainer::Iterator iter = std::find( indices.Begin(), indices.End(), index );
810 if( iter != indices.End() )
812 // If it has, then get it's name and use that for the visual
813 std::string visualName = typeInfo.GetPropertyName( index );
814 visual.SetName( visualName );
819 if( !visualReplaced ) // New registration entry
821 mImpl->mVisuals.PushBack( new RegisteredVisual( index, visual, enabled ) );
824 if( visual && self.OnStage() && enabled )
826 Toolkit::GetImplementation(visual).SetOnStage( self );
828 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::RegisterVisual number of registered visuals(%d)\n", mImpl->mVisuals.Size() );
832 void Control::UnregisterVisual( Property::Index index )
834 RegisteredVisualContainer::Iterator iter;
835 if ( FindVisual( index, mImpl->mVisuals, iter ) )
837 Actor self( Self() );
838 Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
839 (*iter)->visual.Reset();
840 mImpl->mVisuals.Erase( iter );
844 Toolkit::Visual::Base Control::GetVisual( Property::Index index ) const
846 RegisteredVisualContainer::Iterator iter;
847 if ( FindVisual( index, mImpl->mVisuals, iter ) )
849 return (*iter)->visual;
852 return Toolkit::Visual::Base();
855 void Control::EnableVisual( Property::Index index, bool enable )
857 RegisteredVisualContainer::Iterator iter;
858 if ( FindVisual( index, mImpl->mVisuals, iter ) )
860 if ( (*iter)->enabled == enable )
862 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Visual Already enabled set (%s) \n", enable?"enabled":"disabled");
866 (*iter)->enabled = enable;
867 Actor parentActor = Self();
868 if ( Self().OnStage() ) // If control not on Stage then Visual will be added when StageConnection is called.
872 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting Visual(%d) on stage \n", index );
873 Toolkit::GetImplementation((*iter)->visual).SetOnStage( parentActor );
877 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting Visual(%d) off stage \n", index );
878 Toolkit::GetImplementation((*iter)->visual).SetOffStage( parentActor ); // No need to call if control not staged.
884 bool Control::IsVisualEnabled( Property::Index index ) const
886 RegisteredVisualContainer::Iterator iter;
887 if ( FindVisual( index, mImpl->mVisuals, iter ) )
889 return (*iter)->enabled;
894 Dali::Animation Control::CreateTransition( const Toolkit::TransitionData& handle )
896 Dali::Animation transition;
897 const Internal::TransitionData& transitionData = Toolkit::GetImplementation( handle );
899 if( transitionData.Count() > 0 )
901 // Setup a Transition from TransitionData.
902 TransitionData::Iterator end = transitionData.End();
903 for( TransitionData::Iterator iter = transitionData.Begin() ;
904 iter != end; ++iter )
906 TransitionData::Animator* animator = (*iter);
907 HandleIndex handleIndex;
909 // Attempt to find the object name as a child actor
910 Actor child = Self().FindChildByName( animator->objectName );
913 Property::Index propertyIndex = DevelHandle::GetPropertyIndex( child, animator->propertyKey );
914 handleIndex = HandleIndex( child, propertyIndex );
918 handleIndex = GetVisualProperty( *this, mImpl->mVisuals,
919 animator->objectName,
920 animator->propertyKey );
923 if( handleIndex.handle && handleIndex.index != Property::INVALID_INDEX )
925 if( animator->animate == false )
927 if( animator->targetValue.GetType() != Property::NONE )
929 handleIndex.handle.SetProperty( handleIndex.index, animator->targetValue );
934 if( animator->initialValue.GetType() != Property::NONE )
936 handleIndex.handle.SetProperty( handleIndex.index, animator->initialValue );
941 // Create an animation with a default .1 second duration - the animators
942 // will automatically force it to the 'right' duration.
943 transition = Dali::Animation::New( 0.1f );
946 transition.AnimateTo( Property( handleIndex.handle, handleIndex.index ),
947 animator->targetValue,
948 animator->alphaFunction,
949 TimePeriod( animator->timePeriodDelay,
950 animator->timePeriodDuration ) );
959 bool Control::OnAccessibilityActivated()
961 return false; // Accessibility activation is not handled by default
964 bool Control::OnKeyboardEnter()
966 return false; // Keyboard enter is not handled by default
969 bool Control::OnAccessibilityPan(PanGesture gesture)
971 return false; // Accessibility pan gesture is not handled by default
974 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
976 return false; // Accessibility touch event is not handled by default
979 bool Control::OnAccessibilityValueChange(bool isIncrease)
981 return false; // Accessibility value change action is not handled by default
984 bool Control::OnAccessibilityZoom()
986 return false; // Accessibility zoom action is not handled by default
989 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
994 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
998 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
1000 return mImpl->mKeyEventSignal;
1003 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusGainedSignal()
1005 return mImpl->mKeyInputFocusGainedSignal;
1008 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusLostSignal()
1010 return mImpl->mKeyInputFocusLostSignal;
1013 bool Control::EmitKeyEventSignal( const KeyEvent& event )
1015 // Guard against destruction during signal emission
1016 Dali::Toolkit::Control handle( GetOwner() );
1018 bool consumed = false;
1020 // signals are allocated dynamically when someone connects
1021 if ( !mImpl->mKeyEventSignal.Empty() )
1023 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
1028 // Notification for derived classes
1029 consumed = OnKeyEvent(event);
1035 Control::Control( ControlBehaviour behaviourFlags )
1036 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
1037 mImpl(new Impl(*this))
1039 mImpl->mFlags = behaviourFlags;
1047 void Control::Initialize()
1049 // Call deriving classes so initialised before styling is applied to them.
1052 if( (mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS) ||
1053 !(mImpl->mFlags & DISABLE_STYLE_CHANGE_SIGNALS) )
1055 Toolkit::StyleManager styleManager = StyleManager::Get();
1057 // if stylemanager is available
1060 StyleManager& styleManagerImpl = GetImpl( styleManager );
1062 // Register for style changes
1063 styleManagerImpl.ControlStyleChangeSignal().Connect( this, &Control::OnStyleChange );
1065 // Apply the current style
1066 styleManagerImpl.ApplyThemeStyleAtInit( Toolkit::Control( GetOwner() ) );
1070 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
1072 SetKeyboardNavigationSupport( true );
1076 void Control::OnInitialize()
1080 void Control::OnControlChildAdd( Actor& child )
1084 void Control::OnControlChildRemove( Actor& child )
1088 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1090 // By default the control is only interested in theme (not font) changes
1091 if( styleManager && change == StyleChange::THEME_CHANGE )
1093 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1098 void Control::OnPinch(const PinchGesture& pinch)
1100 if( !( mImpl->mStartingPinchScale ) )
1103 mImpl->mStartingPinchScale = new Vector3;
1106 if( pinch.state == Gesture::Started )
1108 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
1111 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
1114 void Control::OnPan( const PanGesture& pan )
1118 void Control::OnTap(const TapGesture& tap)
1122 void Control::OnLongPress( const LongPressGesture& longPress )
1126 void Control::EmitKeyInputFocusSignal( bool focusGained )
1128 Dali::Toolkit::Control handle( GetOwner() );
1132 // signals are allocated dynamically when someone connects
1133 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
1135 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
1140 // signals are allocated dynamically when someone connects
1141 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
1143 mImpl->mKeyInputFocusLostSignal.Emit( handle );
1148 void Control::OnStageConnection( int depth )
1150 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::OnStageConnection number of registered visuals(%d)\n", mImpl->mVisuals.Size() );
1152 for(RegisteredVisualContainer::Iterator iter = mImpl->mVisuals.Begin(); iter!= mImpl->mVisuals.End(); iter++)
1154 // Check whether the visual is empty and enabled
1155 if( (*iter)->visual && (*iter)->enabled )
1157 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::OnStageConnection Setting visual(%d) on stage\n", (*iter)->index );
1158 Actor self( Self() );
1159 Toolkit::GetImplementation((*iter)->visual).SetOnStage( self );
1164 void Control::OnStageDisconnection()
1166 for(RegisteredVisualContainer::Iterator iter = mImpl->mVisuals.Begin(); iter!= mImpl->mVisuals.End(); iter++)
1168 // Check whether the visual is empty
1169 if( (*iter)->visual )
1171 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::OnStageDisconnection Setting visual(%d) off stage\n", (*iter)->index );
1172 Actor self( Self() );
1173 Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
1178 void Control::OnKeyInputFocusGained()
1180 EmitKeyInputFocusSignal( true );
1183 void Control::OnKeyInputFocusLost()
1185 EmitKeyInputFocusSignal( false );
1188 void Control::OnChildAdd(Actor& child)
1190 // Notify derived classes.
1191 OnControlChildAdd( child );
1194 void Control::OnChildRemove(Actor& child)
1196 // Notify derived classes.
1197 OnControlChildRemove( child );
1200 void Control::OnSizeSet(const Vector3& targetSize)
1202 Toolkit::Visual::Base visual = GetVisual( Toolkit::Control::Property::BACKGROUND );
1205 Vector2 size( targetSize );
1206 Property::Map transformMap;
1207 SetDefaultTransform( transformMap );
1208 visual.SetTransformAndSize( transformMap, size );
1212 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1214 // @todo size negotiate background to new size, animate as well?
1217 bool Control::OnTouchEvent(const TouchEvent& event)
1219 return false; // Do not consume
1222 bool Control::OnHoverEvent(const HoverEvent& event)
1224 return false; // Do not consume
1227 bool Control::OnKeyEvent(const KeyEvent& event)
1229 return false; // Do not consume
1232 bool Control::OnWheelEvent(const WheelEvent& event)
1234 return false; // Do not consume
1237 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
1239 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
1241 container.Add( Self().GetChildAt( i ), size );
1244 Toolkit::Visual::Base visual = GetVisual( Toolkit::Control::Property::BACKGROUND );
1247 Vector2 controlSize( size );
1248 Property::Map transformMap;
1249 SetDefaultTransform( transformMap );
1250 visual.SetTransformAndSize( transformMap, controlSize );
1254 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
1258 Vector3 Control::GetNaturalSize()
1260 Toolkit::Visual::Base visual = GetVisual( Toolkit::Control::Property::BACKGROUND );
1263 Vector2 naturalSize;
1264 visual.GetNaturalSize( naturalSize );
1265 return Vector3( naturalSize );
1267 return Vector3::ZERO;
1270 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
1272 return CalculateChildSizeBase( child, dimension );
1275 float Control::GetHeightForWidth( float width )
1277 return GetHeightForWidthBase( width );
1280 float Control::GetWidthForHeight( float height )
1282 return GetWidthForHeightBase( height );
1285 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
1287 return RelayoutDependentOnChildrenBase( dimension );
1290 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
1294 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
1298 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1300 mImpl->SignalConnected( slotObserver, callback );
1303 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1305 mImpl->SignalDisconnected( slotObserver, callback );
1308 Control& GetImplementation( Dali::Toolkit::Control& handle )
1310 CustomActorImpl& customInterface = handle.GetImplementation();
1311 // downcast to control
1312 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
1316 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
1318 const CustomActorImpl& customInterface = handle.GetImplementation();
1319 // downcast to control
1320 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
1324 } // namespace Internal
1326 } // namespace Toolkit