+void Control::RegisterVisual( Property::Index index, Actor& placementActor, Toolkit::Visual::Base& visual )
+{
+ RegisterVisual( index, placementActor, visual, true );
+}
+
+void Control::RegisterVisual( Property::Index index, Actor& placementActor, Toolkit::Visual::Base& visual, bool enabled )
+{
+ bool visualReplaced ( false );
+ Actor actorToRegister; // Null actor, replaced if placement actor not Self
+ Actor self = Self();
+
+ if ( placementActor != self ) // Prevent increasing ref count if actor self
+ {
+ actorToRegister = placementActor;
+ }
+
+ 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() )
+ {
+ if( (*iter)->placementActor )
+ {
+ (*iter)->visual.SetOffStage( (*iter)->placementActor );
+ }
+ else
+ {
+ (*iter)->visual.SetOffStage( self );
+ }
+ }
+ (*iter)->visual = visual;
+ (*iter)->placementActor = actorToRegister;
+ visualReplaced = true;
+ }
+ }
+
+ if ( !visualReplaced ) // New registration entry
+ {
+ mImpl->mVisuals.PushBack( new RegisteredVisual( index, visual, actorToRegister, enabled ) );
+ }
+
+ if( visual && self.OnStage() && enabled )
+ {
+ visual.SetOnStage( placementActor );
+ }
+}
+
+void Control::UnregisterVisual( Property::Index index )
+{
+ RegisteredVisualContainer::Iterator iter;
+ if ( FindVisual( index, mImpl->mVisuals, iter ) )
+ {
+ mImpl->mVisuals.Erase( iter );
+ }
+}
+
+Toolkit::Visual::Base Control::GetVisual( Property::Index index ) const
+{
+ RegisteredVisualContainer::Iterator iter;
+ if ( FindVisual( index, mImpl->mVisuals, iter ) )
+ {
+ return (*iter)->visual;
+ }
+
+ return Toolkit::Visual::Base();
+}
+
+void Control::EnableVisual( Property::Index index, bool enable )
+{
+ RegisteredVisualContainer::Iterator iter;
+ if ( FindVisual( index, mImpl->mVisuals, iter ) )
+ {
+ if ( (*iter)->enabled == enable )
+ {
+ return;
+ }
+
+ (*iter)->enabled = enable;
+ Actor parentActor = Self();
+ if ( (*iter)->placementActor )
+ {
+ parentActor = (*iter)->placementActor;
+ }
+
+ if ( Self().OnStage() ) // If control not on Stage then Visual will be added when StageConnection is called.
+ {
+ if ( enable )
+ {
+
+ (*iter)->visual.SetOnStage( parentActor );
+ }
+ else
+ {
+ (*iter)->visual.SetOffStage( parentActor ); // No need to call if control not staged.
+ }
+ }
+ }
+}
+
+bool Control::IsVisualEnabled( Property::Index index ) const
+{
+ RegisteredVisualContainer::Iterator iter;
+ if ( FindVisual( index, mImpl->mVisuals, iter ) )
+ {
+ return (*iter)->enabled;
+ }
+ return false;
+}
+
+Actor Control::GetPlacementActor( Property::Index index ) const
+{
+ RegisteredVisualContainer::Iterator iter;
+ if ( FindVisual( index, mImpl->mVisuals, iter ) )
+ {
+ if( (*iter)->placementActor )
+ {
+ return (*iter)->placementActor;
+ }
+ else
+ {
+ return Self();
+ }
+ }
+
+ return Actor();
+}
+