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 "control-data-impl.h"
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/devel-api/object/handle-devel.h>
25 #include <dali/devel-api/scripting/enum-helper.h>
26 #include <dali/devel-api/scripting/scripting.h>
27 #include <dali/integration-api/debug.h>
28 #include <dali/public-api/object/type-registry-helper.h>
32 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
33 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
34 #include <dali-toolkit/internal/styling/style-manager-impl.h>
35 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
36 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
37 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
38 #include <dali-toolkit/devel-api/controls/control-devel.h>
49 extern const Dali::Scripting::StringEnum ControlStateTable[];
50 extern const unsigned int ControlStateTableCount;
53 // Not static or anonymous - shared with other translation units
54 const Scripting::StringEnum ControlStateTable[] = {
55 { "NORMAL", Toolkit::DevelControl::NORMAL },
56 { "FOCUSED", Toolkit::DevelControl::FOCUSED },
57 { "DISABLED", Toolkit::DevelControl::DISABLED },
59 const unsigned int ControlStateTableCount = sizeof( ControlStateTable ) / sizeof( ControlStateTable[0] );
66 #if defined(DEBUG_ENABLED)
67 Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_CONTROL_VISUALS");
72 void Remove( Dictionary<T>& keyValues, const std::string& name )
74 keyValues.Remove(name);
77 void Remove( DictionaryKeys& keys, const std::string& name )
79 DictionaryKeys::iterator iter = std::find( keys.begin(), keys.end(), name );
80 if( iter != keys.end())
86 Toolkit::DevelVisual::Type GetVisualTypeFromMap( const Property::Map& map )
88 Property::Value* typeValue = map.Find( Toolkit::DevelVisual::Property::TYPE, VISUAL_TYPE );
89 Toolkit::DevelVisual::Type type = Toolkit::DevelVisual::IMAGE;
92 Scripting::GetEnumerationProperty( *typeValue, VISUAL_TYPE_TABLE, VISUAL_TYPE_TABLE_COUNT, type );
98 * Finds visual in given array, returning true if found along with the iterator for that visual as a out parameter
100 bool FindVisual( Property::Index targetIndex, const RegisteredVisualContainer& visuals, RegisteredVisualContainer::Iterator& iter )
102 for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
104 if ( (*iter)->index == targetIndex )
112 void FindChangableVisuals( Dictionary<Property::Map>& stateVisualsToAdd,
113 Dictionary<Property::Map>& stateVisualsToChange,
114 DictionaryKeys& stateVisualsToRemove)
116 DictionaryKeys copyOfStateVisualsToRemove = stateVisualsToRemove;
118 for( DictionaryKeys::iterator iter = copyOfStateVisualsToRemove.begin();
119 iter != copyOfStateVisualsToRemove.end(); ++iter )
121 const std::string& visualName = (*iter);
122 Property::Map* toMap = stateVisualsToAdd.Find( visualName );
125 stateVisualsToChange.Add( visualName, *toMap );
126 stateVisualsToAdd.Remove( visualName );
127 Remove( stateVisualsToRemove, visualName );
132 Toolkit::Visual::Base GetVisualByName(
133 const RegisteredVisualContainer& visuals,
134 const std::string& visualName )
136 Toolkit::Visual::Base visualHandle;
138 RegisteredVisualContainer::Iterator iter;
139 for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
141 Toolkit::Visual::Base visual = (*iter)->visual;
142 if( visual && visual.GetName() == visualName )
144 visualHandle = visual;
152 * Performs actions as requested using the action name.
153 * @param[in] object The object on which to perform the action.
154 * @param[in] actionName The action to perform.
155 * @param[in] attributes The attributes with which to perfrom this action.
156 * @return true if action has been accepted by this control
158 const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibilityActivated";
159 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
163 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ) )
165 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
168 // if cast succeeds there is an implementation so no need to check
169 ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
177 * Connects a callback function with the object's signals.
178 * @param[in] object The object providing the signal.
179 * @param[in] tracker Used to disconnect the signal.
180 * @param[in] signalName The signal to connect to.
181 * @param[in] functor A newly allocated FunctorDelegate.
182 * @return True if the signal was connected.
183 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
185 const char* SIGNAL_KEY_EVENT = "keyEvent";
186 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "keyInputFocusGained";
187 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "keyInputFocusLost";
188 const char* SIGNAL_TAPPED = "tapped";
189 const char* SIGNAL_PANNED = "panned";
190 const char* SIGNAL_PINCHED = "pinched";
191 const char* SIGNAL_LONG_PRESSED = "longPressed";
192 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
194 Dali::BaseHandle handle( object );
196 bool connected( false );
197 Toolkit::Control control = Toolkit::Control::DownCast( handle );
200 Internal::Control& controlImpl( Internal::GetImplementation( control ) );
203 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
205 controlImpl.KeyEventSignal().Connect( tracker, functor );
207 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
209 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
211 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
213 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
215 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
217 controlImpl.EnableGestureDetection( Gesture::Tap );
218 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
220 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
222 controlImpl.EnableGestureDetection( Gesture::Pan );
223 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
225 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
227 controlImpl.EnableGestureDetection( Gesture::Pinch );
228 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
230 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
232 controlImpl.EnableGestureDetection( Gesture::LongPress );
233 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
240 * Creates control through type registry
244 return Internal::Control::New();
246 // Setup signals and actions using the type-registry.
247 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
249 // Note: Properties are registered separately below.
251 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
252 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
253 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
254 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
255 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
256 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
257 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
259 TypeAction registerAction( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &DoAction );
261 DALI_TYPE_REGISTRATION_END()
263 } // unnamed namespace
266 // Properties registered without macro to use specific member variables.
267 const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
268 const PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "backgroundColor", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
269 const PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "backgroundImage", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
270 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
271 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
272 const PropertyRegistration Control::Impl::PROPERTY_6( typeRegistration, "tooltip", Toolkit::DevelControl::Property::TOOLTIP, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
273 const PropertyRegistration Control::Impl::PROPERTY_7( typeRegistration, "state", Toolkit::DevelControl::Property::STATE, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
274 const PropertyRegistration Control::Impl::PROPERTY_8( typeRegistration, "subState", Toolkit::DevelControl::Property::SUB_STATE, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
275 const PropertyRegistration Control::Impl::PROPERTY_9( typeRegistration, "leftFocusableActorId", Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
276 const PropertyRegistration Control::Impl::PROPERTY_10( typeRegistration, "rightFocusableActorId", Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID,Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
277 const PropertyRegistration Control::Impl::PROPERTY_11( typeRegistration, "upFocusableActorId", Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
278 const PropertyRegistration Control::Impl::PROPERTY_12( typeRegistration, "downFocusableActorId", Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
282 Control::Impl::Impl( Control& controlImpl )
283 : mControlImpl( controlImpl ),
284 mState( Toolkit::DevelControl::NORMAL ),
286 mLeftFocusableActorId( -1 ),
287 mRightFocusableActorId( -1 ),
288 mUpFocusableActorId( -1 ),
289 mDownFocusableActorId( -1 ),
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 )
305 Control::Impl::~Impl()
307 // All gesture detectors will be destroyed so no need to disconnect.
308 delete mStartingPinchScale;
311 Control::Impl& Control::Impl::Get( Internal::Control& internalControl )
313 return *internalControl.mImpl;
316 const Control::Impl& Control::Impl::Get( const Internal::Control& internalControl )
318 return *internalControl.mImpl;
321 // Gesture Detection Methods
322 void Control::Impl::PinchDetected(Actor actor, const PinchGesture& pinch)
324 mControlImpl.OnPinch(pinch);
327 void Control::Impl::PanDetected(Actor actor, const PanGesture& pan)
329 mControlImpl.OnPan(pan);
332 void Control::Impl::TapDetected(Actor actor, const TapGesture& tap)
334 mControlImpl.OnTap(tap);
337 void Control::Impl::LongPressDetected(Actor actor, const LongPressGesture& longPress)
339 mControlImpl.OnLongPress(longPress);
342 // Called by a Visual when it's resource is ready
343 void Control::Impl::ResourceReady( Visual::Base& object)
346 // go through and check if all the visuals are ready, if they are emit a signal
347 for ( RegisteredVisualContainer::ConstIterator visualIter = mVisuals.Begin();
348 visualIter != mVisuals.End(); ++visualIter )
350 const Toolkit::Visual::Base visual = (*visualIter)->visual;
351 const Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
353 // one of the visuals is not ready
354 if( !visualImpl.IsResourceReady() )
360 // all the visuals are ready
361 Dali::Toolkit::Control handle( mControlImpl.GetOwner() );
362 mResourceReadySignal.Emit( handle );
366 bool Control::Impl::IsResourceReady() const
368 // go through and check all the visuals are ready
369 for ( RegisteredVisualContainer::ConstIterator visualIter = mVisuals.Begin();
370 visualIter != mVisuals.End(); ++visualIter )
372 const Toolkit::Visual::Base visual = (*visualIter)->visual;
373 const Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
375 // one of the visuals is not ready
376 if( !visualImpl.IsResourceReady() )
384 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual )
386 RegisterVisual( index, visual, true );
389 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled )
391 bool visualReplaced ( false );
392 Actor self = mControlImpl.Self();
394 if( !mVisuals.Empty() )
396 RegisteredVisualContainer::Iterator iter;
397 // Check if visual (index) is already registered. Replace if so.
398 if ( FindVisual( index, mVisuals, iter ) )
400 if( (*iter)->visual && self.OnStage() )
402 Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
405 StopObservingVisual( (*iter)->visual );
406 StartObservingVisual( visual );
408 (*iter)->visual = visual;
409 visualReplaced = true;
413 // If not set, set the name of the visual to the same name as the control's property.
414 // ( If the control has been type registered )
415 if( visual.GetName().empty() )
417 // Check if the control has been type registered:
418 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid( mControlImpl ) );
421 // Check if the property index has been registered:
422 Property::IndexContainer indices;
423 typeInfo.GetPropertyIndices( indices );
424 Property::IndexContainer::Iterator iter = std::find( indices.Begin(), indices.End(), index );
425 if( iter != indices.End() )
427 // If it has, then get it's name and use that for the visual
428 std::string visualName = typeInfo.GetPropertyName( index );
429 visual.SetName( visualName );
434 if( !visualReplaced ) // New registration entry
436 mVisuals.PushBack( new RegisteredVisual( index, visual, enabled ) );
438 // monitor when the visuals resources are ready
439 StartObservingVisual( visual );
443 if( visual && self.OnStage() && enabled )
445 Toolkit::GetImplementation(visual).SetOnStage( self );
448 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::RegisterVisual() Registered %s(%d), enabled:%s\n", visual.GetName().c_str(), index, enabled?"T":"F" );
451 void Control::Impl::UnregisterVisual( Property::Index index )
453 RegisteredVisualContainer::Iterator iter;
454 if ( FindVisual( index, mVisuals, iter ) )
456 // stop observing visual
457 StopObservingVisual( (*iter)->visual );
459 Actor self( mControlImpl.Self() );
460 Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
461 (*iter)->visual.Reset();
462 mVisuals.Erase( iter );
466 Toolkit::Visual::Base Control::Impl::GetVisual( Property::Index index ) const
468 RegisteredVisualContainer::Iterator iter;
469 if ( FindVisual( index, mVisuals, iter ) )
471 return (*iter)->visual;
474 return Toolkit::Visual::Base();
477 void Control::Impl::EnableVisual( Property::Index index, bool enable )
479 RegisteredVisualContainer::Iterator iter;
480 if ( FindVisual( index, mVisuals, iter ) )
482 if ( (*iter)->enabled == enable )
484 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Visual %s(%d) already %s\n", (*iter)->visual.GetName().c_str(), index, enable?"enabled":"disabled");
488 (*iter)->enabled = enable;
489 Actor parentActor = mControlImpl.Self();
490 if ( mControlImpl.Self().OnStage() ) // If control not on Stage then Visual will be added when StageConnection is called.
494 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) on stage \n", (*iter)->visual.GetName().c_str(), index );
495 Toolkit::GetImplementation((*iter)->visual).SetOnStage( parentActor );
499 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) off stage \n", (*iter)->visual.GetName().c_str(), index );
500 Toolkit::GetImplementation((*iter)->visual).SetOffStage( parentActor ); // No need to call if control not staged.
506 bool Control::Impl::IsVisualEnabled( Property::Index index ) const
508 RegisteredVisualContainer::Iterator iter;
509 if ( FindVisual( index, mVisuals, iter ) )
511 return (*iter)->enabled;
516 void Control::Impl::StopObservingVisual( Toolkit::Visual::Base& visual )
518 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
520 // Stop observing the visual
521 visualImpl.RemoveResourceObserver( *this );
524 void Control::Impl::StartObservingVisual( Toolkit::Visual::Base& visual)
526 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
528 // start observing the visual for resource ready
529 visualImpl.AddResourceObserver( *this );
532 Dali::Animation Control::Impl::CreateTransition( const Toolkit::TransitionData& handle )
534 Dali::Animation transition;
535 const Internal::TransitionData& transitionData = Toolkit::GetImplementation( handle );
537 if( transitionData.Count() > 0 )
539 // Setup a Transition from TransitionData.
540 TransitionData::Iterator end = transitionData.End();
541 for( TransitionData::Iterator iter = transitionData.Begin() ;
542 iter != end; ++iter )
544 TransitionData::Animator* animator = (*iter);
546 Toolkit::Visual::Base visual = GetVisualByName( mVisuals, animator->objectName );
550 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
551 visualImpl.AnimateProperty( transition, *animator );
555 // Otherwise, try any actor children of control (Including the control)
556 Actor child = mControlImpl.Self().FindChildByName( animator->objectName );
559 Property::Index propertyIndex = DevelHandle::GetPropertyIndex( child, animator->propertyKey );
560 if( propertyIndex != Property::INVALID_INDEX )
562 if( animator->animate == false )
564 if( animator->targetValue.GetType() != Property::NONE )
566 child.SetProperty( propertyIndex, animator->targetValue );
569 else // animate the property
571 if( animator->initialValue.GetType() != Property::NONE )
573 child.SetProperty( propertyIndex, animator->initialValue );
578 transition = Dali::Animation::New( 0.1f );
581 transition.AnimateTo( Property( child, propertyIndex ),
582 animator->targetValue,
583 animator->alphaFunction,
584 TimePeriod( animator->timePeriodDelay,
585 animator->timePeriodDuration ) );
596 void Control::Impl::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
598 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
602 Control& controlImpl( GetImplementation( control ) );
606 case Toolkit::Control::Property::STYLE_NAME:
608 controlImpl.SetStyleName( value.Get< std::string >() );
612 case Toolkit::DevelControl::Property::STATE:
614 bool withTransitions=true;
615 const Property::Value* valuePtr=&value;
616 Property::Map* map = value.GetMap();
619 Property::Value* value2 = map->Find("withTransitions");
622 withTransitions = value2->Get<bool>();
625 valuePtr = map->Find("state");
630 Toolkit::DevelControl::State state( controlImpl.mImpl->mState );
631 if( Scripting::GetEnumerationProperty< Toolkit::DevelControl::State >( *valuePtr, ControlStateTable, ControlStateTableCount, state ) )
633 controlImpl.mImpl->SetState( state, withTransitions );
639 case Toolkit::DevelControl::Property::SUB_STATE:
641 std::string subState;
642 if( value.Get( subState ) )
644 controlImpl.mImpl->SetSubState( subState );
649 case Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID:
652 if( value.Get( focusId ) )
654 controlImpl.mImpl->mLeftFocusableActorId = focusId;
659 case Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID:
662 if( value.Get( focusId ) )
664 controlImpl.mImpl->mRightFocusableActorId = focusId;
669 case Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID:
672 if( value.Get( focusId ) )
674 controlImpl.mImpl->mUpFocusableActorId = focusId;
679 case Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID:
682 if( value.Get( focusId ) )
684 controlImpl.mImpl->mDownFocusableActorId = focusId;
689 case Toolkit::Control::Property::BACKGROUND_COLOR:
691 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
692 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
696 case Toolkit::Control::Property::BACKGROUND_IMAGE:
698 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
699 Image image = Scripting::NewImage( value );
702 controlImpl.SetBackgroundImage( image );
706 // An empty image means the background is no longer required
707 controlImpl.ClearBackground();
712 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
714 if ( value.Get< bool >() )
716 controlImpl.SetKeyInputFocus();
720 controlImpl.ClearKeyInputFocus();
725 case Toolkit::Control::Property::BACKGROUND:
729 const Property::Map* map = value.GetMap();
730 if( map && !map->Empty() )
732 controlImpl.SetBackground( *map );
734 else if( value.Get( url ) )
736 // don't know the size to load
737 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( url, ImageDimensions() );
740 controlImpl.mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual );
741 visual.SetDepthIndex( DepthIndex::BACKGROUND );
744 else if( value.Get( color ) )
746 controlImpl.SetBackgroundColor(color);
750 // The background is an empty property map, so we should clear the background
751 controlImpl.ClearBackground();
756 case Toolkit::DevelControl::Property::TOOLTIP:
758 TooltipPtr& tooltipPtr = controlImpl.mImpl->mTooltip;
761 tooltipPtr = Tooltip::New( control );
763 tooltipPtr->SetProperties( value );
769 Property::Value Control::Impl::GetProperty( BaseObject* object, Property::Index index )
771 Property::Value value;
773 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
777 Control& controlImpl( GetImplementation( control ) );
781 case Toolkit::Control::Property::STYLE_NAME:
783 value = controlImpl.GetStyleName();
787 case Toolkit::DevelControl::Property::STATE:
789 value = controlImpl.mImpl->mState;
793 case Toolkit::DevelControl::Property::SUB_STATE:
795 value = controlImpl.mImpl->mSubStateName;
799 case Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID:
801 value = controlImpl.mImpl->mLeftFocusableActorId;
805 case Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID:
807 value = controlImpl.mImpl->mRightFocusableActorId;
811 case Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID:
813 value = controlImpl.mImpl->mUpFocusableActorId;
817 case Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID:
819 value = controlImpl.mImpl->mDownFocusableActorId;
823 case Toolkit::Control::Property::BACKGROUND_COLOR:
825 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
826 value = controlImpl.GetBackgroundColor();
830 case Toolkit::Control::Property::BACKGROUND_IMAGE:
832 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
834 Toolkit::Visual::Base visual = controlImpl.mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND );
837 visual.CreatePropertyMap( map );
843 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
845 value = controlImpl.HasKeyInputFocus();
849 case Toolkit::Control::Property::BACKGROUND:
852 Toolkit::Visual::Base visual = controlImpl.mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND );
855 visual.CreatePropertyMap( map );
862 case Toolkit::DevelControl::Property::TOOLTIP:
865 if( controlImpl.mImpl->mTooltip )
867 controlImpl.mImpl->mTooltip->CreatePropertyMap( map );
880 void Control::Impl::CopyInstancedProperties( RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties )
882 for(RegisteredVisualContainer::Iterator iter = visuals.Begin(); iter!= visuals.End(); iter++)
884 if( (*iter)->visual )
886 Property::Map instanceMap;
887 Toolkit::GetImplementation((*iter)->visual).CreateInstancePropertyMap(instanceMap);
888 instancedProperties.Add( (*iter)->visual.GetName(), instanceMap );
894 void Control::Impl::RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName )
896 Actor self( mControlImpl.Self() );
898 for ( RegisteredVisualContainer::Iterator visualIter = visuals.Begin();
899 visualIter != visuals.End(); ++visualIter )
901 Toolkit::Visual::Base visual = (*visualIter)->visual;
902 if( visual && visual.GetName() == visualName )
904 Toolkit::GetImplementation(visual).SetOffStage( self );
905 (*visualIter)->visual.Reset();
906 visuals.Erase( visualIter );
912 void Control::Impl::RemoveVisuals( RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals )
914 Actor self( mControlImpl.Self() );
915 for( DictionaryKeys::iterator iter = removeVisuals.begin(); iter != removeVisuals.end(); ++iter )
917 const std::string visualName = *iter;
918 RemoveVisual( visuals, visualName );
922 void Control::Impl::RecreateChangedVisuals( Dictionary<Property::Map>& stateVisualsToChange,
923 Dictionary<Property::Map>& instancedProperties )
925 Dali::CustomActor handle( mControlImpl.GetOwner() );
926 for( Dictionary<Property::Map>::iterator iter = stateVisualsToChange.Begin();
927 iter != stateVisualsToChange.End(); ++iter )
929 const std::string& visualName = (*iter).key;
930 const Property::Map& toMap = (*iter).entry;
932 // is it a candidate for re-creation?
933 bool recreate = false;
935 Toolkit::Visual::Base visual = GetVisualByName( mVisuals, visualName );
938 Property::Map fromMap;
939 visual.CreatePropertyMap( fromMap );
941 Toolkit::DevelVisual::Type fromType = GetVisualTypeFromMap( fromMap );
942 Toolkit::DevelVisual::Type toType = GetVisualTypeFromMap( toMap );
944 if( fromType != toType )
950 if( fromType == Toolkit::DevelVisual::IMAGE || fromType == Toolkit::DevelVisual::N_PATCH
951 || fromType == Toolkit::DevelVisual::SVG || fromType == Toolkit::DevelVisual::ANIMATED_IMAGE )
953 Property::Value* fromUrl = fromMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
954 Property::Value* toUrl = toMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
956 if( fromUrl && toUrl )
958 std::string fromUrlString;
959 std::string toUrlString;
960 fromUrl->Get(fromUrlString);
961 toUrl->Get(toUrlString);
963 if( fromUrlString != toUrlString )
971 const Property::Map* instancedMap = instancedProperties.FindConst( visualName );
972 if( recreate || instancedMap )
974 RemoveVisual( mVisuals, visualName );
975 Style::ApplyVisual( handle, visualName, toMap, instancedMap );
979 // @todo check to see if we can apply toMap without recreating the visual
980 // e.g. by setting only animatable properties
981 // For now, recreate all visuals, but merge in instance data.
982 RemoveVisual( mVisuals, visualName );
983 Style::ApplyVisual( handle, visualName, toMap, instancedMap );
989 void Control::Impl::ReplaceStateVisualsAndProperties( const StylePtr oldState, const StylePtr newState, const std::string& subState )
991 // Collect all old visual names
992 DictionaryKeys stateVisualsToRemove;
995 oldState->visuals.GetKeys( stateVisualsToRemove );
996 if( ! subState.empty() )
998 const StylePtr* oldSubState = oldState->subStates.FindConst(subState);
1001 DictionaryKeys subStateVisualsToRemove;
1002 (*oldSubState)->visuals.GetKeys( subStateVisualsToRemove );
1003 Merge( stateVisualsToRemove, subStateVisualsToRemove );
1008 // Collect all new visual properties
1009 Dictionary<Property::Map> stateVisualsToAdd;
1012 stateVisualsToAdd = newState->visuals;
1013 if( ! subState.empty() )
1015 const StylePtr* newSubState = newState->subStates.FindConst(subState);
1018 stateVisualsToAdd.Merge( (*newSubState)->visuals );
1023 // If a name is in both add/remove, move it to change list.
1024 Dictionary<Property::Map> stateVisualsToChange;
1025 FindChangableVisuals( stateVisualsToAdd, stateVisualsToChange, stateVisualsToRemove);
1027 // Copy instanced properties (e.g. text label) of current visuals
1028 Dictionary<Property::Map> instancedProperties;
1029 CopyInstancedProperties( mVisuals, instancedProperties );
1031 // For each visual in remove list, remove from mVisuals
1032 RemoveVisuals( mVisuals, stateVisualsToRemove );
1034 // For each visual in add list, create and add to mVisuals
1035 Dali::CustomActor handle( mControlImpl.GetOwner() );
1036 Style::ApplyVisuals( handle, stateVisualsToAdd, instancedProperties );
1038 // For each visual in change list, if it requires a new visual,
1039 // remove old visual, create and add to mVisuals
1040 RecreateChangedVisuals( stateVisualsToChange, instancedProperties );
1043 void Control::Impl::SetState( DevelControl::State newState, bool withTransitions )
1045 DevelControl::State oldState = mState;
1046 Dali::CustomActor handle( mControlImpl.GetOwner() );
1047 DALI_LOG_INFO(gLogFilter, Debug::Concise, "Control::Impl::SetState: %s\n",
1048 (mState == DevelControl::NORMAL ? "NORMAL" :(
1049 mState == DevelControl::FOCUSED ?"FOCUSED" : (
1050 mState == DevelControl::DISABLED?"DISABLED":"NONE" ))));
1052 if( mState != newState )
1054 // If mState was Disabled, and new state is Focused, should probably
1055 // store that fact, e.g. in another property that FocusManager can access.
1058 // Trigger state change and transitions
1059 // Apply new style, if stylemanager is available
1060 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
1063 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
1067 std::string oldStateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( oldState, ControlStateTable, ControlStateTableCount );
1068 std::string newStateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( newState, ControlStateTable, ControlStateTableCount );
1070 const StylePtr* newStateStyle = stylePtr->subStates.Find( newStateName );
1071 const StylePtr* oldStateStyle = stylePtr->subStates.Find( oldStateName );
1072 if( oldStateStyle && newStateStyle )
1074 // Only change if both state styles exist
1075 ReplaceStateVisualsAndProperties( *oldStateStyle, *newStateStyle, mSubStateName );
1082 void Control::Impl::SetSubState( const std::string& subStateName, bool withTransitions )
1084 if( mSubStateName != subStateName )
1086 // Get existing sub-state visuals, and unregister them
1087 Dali::CustomActor handle( mControlImpl.GetOwner() );
1089 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
1092 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
1096 std::string stateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( mState, ControlStateTable, ControlStateTableCount );
1098 const StylePtr* state = stylePtr->subStates.Find( stateName );
1101 StylePtr stateStyle(*state);
1103 const StylePtr* newStateStyle = stateStyle->subStates.Find( subStateName );
1104 const StylePtr* oldStateStyle = stateStyle->subStates.Find( mSubStateName );
1105 if( oldStateStyle && newStateStyle )
1108 ReplaceStateVisualsAndProperties( *oldStateStyle, *newStateStyle, empty );
1114 mSubStateName = subStateName;
1118 } // namespace Internal
1120 } // namespace Toolkit