+ bool visualReplaced ( false );
+ Actor self = Self();
+
+ if( !mImpl->mVisuals.Empty() )
+ {
+ RegisteredVisualContainer::Iterator iter;
+ // Check if visual (index) is already registered. Replace if so.
+ if ( FindVisual( index, mImpl->mVisuals, iter ) )
+ {
+ if( (*iter)->visual && self.OnStage() )
+ {
+ Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
+ }
+ (*iter)->visual = visual;
+ visualReplaced = true;
+ }
+ }
+
+ // If not set, set the name of the visual to the same name as the control's property.
+ // ( If the control has been type registered )
+ if( visual.GetName().empty() )
+ {
+ // Check if the control has been type registered:
+ TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(*this) );
+ if( typeInfo )
+ {
+ // Check if the property index has been registered:
+ Property::IndexContainer indices;
+ typeInfo.GetPropertyIndices( indices );
+ Property::IndexContainer::Iterator iter = std::find( indices.Begin(), indices.End(), index );
+ if( iter != indices.End() )
+ {
+ // If it has, then get it's name and use that for the visual
+ std::string visualName = typeInfo.GetPropertyName( index );
+ visual.SetName( visualName );
+ }
+ }
+ }
+
+ if( !visualReplaced ) // New registration entry
+ {
+ mImpl->mVisuals.PushBack( new RegisteredVisual( index, visual, enabled ) );
+ }
+
+ if( visual && self.OnStage() && enabled )
+ {
+ Toolkit::GetImplementation(visual).SetOnStage( self );
+ }
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::RegisterVisual number of registered visuals(%d)\n", mImpl->mVisuals.Size() );
+