X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Fpublic-api%2Fcontrols%2Fcontrol-impl.cpp;h=cc3546c0705fb4da9047c70a5b54a9a0de1ab631;hb=8318ee011aae9d2a56018ea7da82b601e8250279;hp=6eec362438e3e4d900827f08d8d1cc65667be224;hpb=e14d00568eab69d46e78db427d91e33513fd662b;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/public-api/controls/control-impl.cpp b/dali-toolkit/public-api/controls/control-impl.cpp index 6eec362..cc3546c 100644 --- a/dali-toolkit/public-api/controls/control-impl.cpp +++ b/dali-toolkit/public-api/controls/control-impl.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -63,14 +64,16 @@ struct RegisteredVisual RegisteredVisual( Property::Index aIndex, Toolkit::Visual::Base &aVisual, Actor &aPlacementActor) : index(aIndex), visual(aVisual), placementActor(aPlacementActor) {} }; +typedef Dali::OwnerContainer< RegisteredVisual* > RegisteredVisuals; + /** * Finds visual in given array, returning true if found along with the iterator for that visual as a out parameter */ -bool FindVisual( Property::Index targetIndex, std::vector& visuals, std::vector::iterator& iter ) +bool FindVisual( Property::Index targetIndex, RegisteredVisuals& visuals, RegisteredVisuals::Iterator& iter ) { - for ( iter = visuals.begin(); iter != visuals.end(); iter++ ) + for ( iter = visuals.Begin(); iter != visuals.End(); iter++ ) { - if ( (*iter).index == targetIndex ) + if ( (*iter)->index == targetIndex ) { return true; } @@ -394,7 +397,7 @@ public: // Data Control& mControlImpl; - std::vector mVisuals; // Stores visuals needed by the control, non trivial type so std::vector used. + RegisteredVisuals mVisuals; // Stores visuals needed by the control, non trivial type so std::vector used. std::string mStyleName; Toolkit::Visual::Base mBackgroundVisual; ///< The visual to render the background Vector4 mBackgroundColor; ///< The color of the background visual @@ -475,7 +478,8 @@ void Control::SetBackgroundColor( const Vector4& color ) Property::Map map; map[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::COLOR; map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color; - InitializeVisual( self, mImpl->mBackgroundVisual, map ); + mImpl->mBackgroundVisual = Toolkit::VisualFactory::Get().CreateVisual( map ); + RegisterVisual( Toolkit::Control::Property::BACKGROUND, self, mImpl->mBackgroundVisual ); if( mImpl->mBackgroundVisual ) { mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND ); @@ -490,7 +494,8 @@ Vector4 Control::GetBackgroundColor() const void Control::SetBackground( const Property::Map& map ) { Actor self( Self() ); - InitializeVisual( self, mImpl->mBackgroundVisual, map ); + mImpl->mBackgroundVisual = Toolkit::VisualFactory::Get().CreateVisual( map ); + RegisterVisual( Toolkit::Control::Property::BACKGROUND, self, mImpl->mBackgroundVisual ); if( mImpl->mBackgroundVisual ) { mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND ); @@ -500,7 +505,8 @@ void Control::SetBackground( const Property::Map& map ) void Control::SetBackgroundImage( Image image ) { Actor self( Self() ); - InitializeVisual( self, mImpl->mBackgroundVisual, image ); + mImpl->mBackgroundVisual = Toolkit::VisualFactory::Get().CreateVisual( image ); + RegisterVisual( Toolkit::Control::Property::BACKGROUND, self, mImpl->mBackgroundVisual ); if( mImpl->mBackgroundVisual ) { mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND ); @@ -511,6 +517,7 @@ void Control::ClearBackground() { Actor self( Self() ); mImpl->mBackgroundVisual.RemoveAndReset( self ); + mImpl->mBackgroundColor = Color::TRANSPARENT; } void Control::EnableGestureDetection(Gesture::Type type) @@ -652,44 +659,89 @@ void Control::KeyboardEnter() OnKeyboardEnter(); } -void Control::RegisterVisual( Property::Index index, Actor placementActor, Toolkit::Visual::Base visual ) +void Control::RegisterVisual( Property::Index index, Actor& placementActor, Toolkit::Visual::Base& visual ) { 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 + if ( placementActor != self ) // Prevent increasing ref count if actor self { actorToRegister = placementActor; } - if ( !mImpl->mVisuals.empty() ) + if ( !mImpl->mVisuals.Empty() ) { - std::vector::iterator iter; + RegisteredVisuals::Iterator iter; // Check if visual (index) is already registered. Replace if so. if ( FindVisual( index, mImpl->mVisuals, iter ) ) { - (*iter).visual = visual; - (*iter).placementActor = actorToRegister; + 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 { - RegisteredVisual newVisual = RegisteredVisual( index, visual, actorToRegister ); - mImpl->mVisuals.push_back( newVisual ); + mImpl->mVisuals.PushBack( new RegisteredVisual( index, visual, actorToRegister ) ); + } + + if( visual && self.OnStage() ) + { + visual.SetOnStage( placementActor ); } } void Control::UnregisterVisual( Property::Index index ) { - std::vector< RegisteredVisual >::iterator iter; + RegisteredVisuals::Iterator iter; if ( FindVisual( index, mImpl->mVisuals, iter ) ) { - mImpl->mVisuals.erase( iter ); + mImpl->mVisuals.Erase( iter ); } } +Toolkit::Visual::Base Control::GetVisual( Property::Index index ) const +{ + RegisteredVisuals::Iterator iter; + if ( FindVisual( index, mImpl->mVisuals, iter ) ) + { + return (*iter)->visual; + } + + return Toolkit::Visual::Base(); +} + +Actor Control::GetPlacementActor( Property::Index index ) const +{ + RegisteredVisuals::Iterator iter; + if ( FindVisual( index, mImpl->mVisuals, iter ) ) + { + if( (*iter)->placementActor ) + { + return (*iter)->placementActor; + } + else + { + return Self(); + } + } + + return Actor(); +} + bool Control::OnAccessibilityActivated() { return false; // Accessibility activation is not handled by default @@ -820,6 +872,7 @@ void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Ty { GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) ); } + RelayoutRequest(); } void Control::OnPinch(const PinchGesture& pinch) @@ -874,19 +927,41 @@ void Control::EmitKeyInputFocusSignal( bool focusGained ) void Control::OnStageConnection( int depth ) { - if( mImpl->mBackgroundVisual) + for(RegisteredVisuals::Iterator iter = mImpl->mVisuals.Begin(); iter!= mImpl->mVisuals.End(); iter++) { - Actor self( Self() ); - mImpl->mBackgroundVisual.SetOnStage( self ); + // Check whether the visual is empty, as it is allowed to register a placement actor without visual. + if( (*iter)->visual ) + { + if( (*iter)->placementActor ) + { + (*iter)->visual.SetOnStage( (*iter)->placementActor ); + } + else + { + Actor self( Self() ); + (*iter)->visual.SetOnStage( self ); + } + } } } void Control::OnStageDisconnection() { - if( mImpl->mBackgroundVisual ) + for(RegisteredVisuals::Iterator iter = mImpl->mVisuals.Begin(); iter!= mImpl->mVisuals.End(); iter++) { - Actor self( Self() ); - mImpl->mBackgroundVisual.SetOffStage( self ); + // Check whether the visual is empty, as it is allowed to register a placement actor without visual. + if( (*iter)->visual ) + { + if( (*iter)->placementActor ) + { + (*iter)->visual.SetOffStage( (*iter)->placementActor ); + } + else + { + Actor self( Self() ); + (*iter)->visual.SetOffStage( self ); + } + } } }