X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fcontrol%2Fcontrol-data-impl.cpp;h=958dd2cbab8c77feca92ee6e364be9177aa6a584;hp=5e94e8f4a33aee4daf994133241fc462528fd81c;hb=b1e8521ad77e7b4e62b59613b2edef64429130e9;hpb=3ca7994488b0b5e21bbb0d262c5fa2e4c731308b diff --git a/dali-toolkit/internal/controls/control/control-data-impl.cpp b/dali-toolkit/internal/controls/control/control-data-impl.cpp index 5e94e8f..958dd2c 100755 --- a/dali-toolkit/internal/controls/control/control-data-impl.cpp +++ b/dali-toolkit/internal/controls/control/control-data-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,8 +36,6 @@ #include #include #include -#include -#include #include #include @@ -69,7 +67,6 @@ namespace #if defined(DEBUG_ENABLED) Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_CONTROL_VISUALS"); -Debug::Filter* gLogFilterLayout = Debug::Filter::New( Debug::NoLogging, false, "LOG_LAYOUT"); #endif @@ -279,19 +276,19 @@ TypeAction registerAction( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &Do DALI_TYPE_REGISTRATION_END() /** - * @brief Iterate through given container and setOffStage any visual found + * @brief Iterate through given container and setOffScene any visual found * * @param[in] container Container of visuals * @param[in] parent Parent actor to remove visuals from */ -void SetVisualsOffStage( const RegisteredVisualContainer& container, Actor parent ) +void SetVisualsOffScene( const RegisteredVisualContainer& container, Actor parent ) { for( auto iter = container.Begin(), end = container.End() ; iter!= end; iter++) { if( (*iter)->visual ) { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::SetOffStage Setting visual(%d) off stage\n", (*iter)->index ); - Toolkit::GetImplementation((*iter)->visual).SetOffStage( parent ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::SetOffScene Setting visual(%d) off stage\n", (*iter)->index ); + Toolkit::GetImplementation((*iter)->visual).SetOffScene( parent ); } } } @@ -301,8 +298,6 @@ void SetVisualsOffStage( const RegisteredVisualContainer& container, Actor paren // Properties registered without macro to use specific member variables. const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty ); -const PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "backgroundColor", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty ); -const PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "backgroundImage", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty ); const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty ); const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty ); const PropertyRegistration Control::Impl::PROPERTY_6( typeRegistration, "margin", Toolkit::Control::Property::MARGIN, Property::EXTENTS, &Control::Impl::SetProperty, &Control::Impl::GetProperty ); @@ -314,13 +309,13 @@ const PropertyRegistration Control::Impl::PROPERTY_11( typeRegistration, "leftFo const PropertyRegistration Control::Impl::PROPERTY_12( typeRegistration, "rightFocusableActorId", Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID,Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty ); const PropertyRegistration Control::Impl::PROPERTY_13( typeRegistration, "upFocusableActorId", Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty ); const PropertyRegistration Control::Impl::PROPERTY_14( typeRegistration, "downFocusableActorId", Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty ); +const PropertyRegistration Control::Impl::PROPERTY_15( typeRegistration, "shadow", Toolkit::DevelControl::Property::SHADOW, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty ); Control::Impl::Impl( Control& controlImpl ) : mControlImpl( controlImpl ), mState( Toolkit::DevelControl::NORMAL ), mSubStateName(""), - mLayout( NULL ), mLeftFocusableActorId( -1 ), mRightFocusableActorId( -1 ), mUpFocusableActorId( -1 ), @@ -334,6 +329,7 @@ Control::Impl::Impl( Control& controlImpl ) mKeyInputFocusGainedSignal(), mKeyInputFocusLostSignal(), mResourceReadySignal(), + mVisualEventSignal(), mPinchGestureDetector(), mPanGestureDetector(), mTapGestureDetector(), @@ -342,8 +338,7 @@ Control::Impl::Impl( Control& controlImpl ) mInputMethodContext(), mFlags( Control::ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ), mIsKeyboardNavigationSupported( false ), - mIsKeyboardFocusGroup( false ), - mIsLayoutingRequired( false ) + mIsKeyboardFocusGroup( false ) { } @@ -437,7 +432,7 @@ void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base StopObservingVisual( currentRegisteredVisual ); // If control staged and visual enabled then visuals will be swapped once ready - if( self.OnStage() && enabled ) + if( self.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) && enabled ) { // Check if visual is currently in the process of being replaced ( is in removal container ) RegisteredVisualContainer::Iterator visualQueuedForRemoval; @@ -445,7 +440,7 @@ void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base { // Visual with same index is already in removal container so current visual pending // Only the the last requested visual will be displayed so remove current visual which is staged but not ready. - Toolkit::GetImplementation( currentRegisteredVisual ).SetOffStage( self ); + Toolkit::GetImplementation( currentRegisteredVisual ).SetOffScene( self ); mVisuals.Erase( registeredVisualsiter ); } else @@ -527,9 +522,9 @@ void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual ); // Put on stage if enabled and the control is already on the stage - if( ( enabled == VisualState::ENABLED ) && self.OnStage() ) + if( ( enabled == VisualState::ENABLED ) && self.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) ) { - visualImpl.SetOnStage( self ); + visualImpl.SetOnScene( self ); } else if( visualImpl.IsResourceReady() ) // When not being staged, check if visual already 'ResourceReady' before it was Registered. ( Resource may have been loaded already ) { @@ -550,7 +545,7 @@ void Control::Impl::UnregisterVisual( Property::Index index ) StopObservingVisual( (*iter)->visual ); Actor self( mControlImpl.Self() ); - Toolkit::GetImplementation((*iter)->visual).SetOffStage( self ); + Toolkit::GetImplementation((*iter)->visual).SetOffScene( self ); (*iter)->visual.Reset(); mVisuals.Erase( iter ); } @@ -558,7 +553,7 @@ void Control::Impl::UnregisterVisual( Property::Index index ) if( FindVisual( index, mRemoveVisuals, iter ) ) { Actor self( mControlImpl.Self() ); - Toolkit::GetImplementation( (*iter)->visual ).SetOffStage( self ); + Toolkit::GetImplementation( (*iter)->visual ).SetOffScene( self ); (*iter)->pending = false; (*iter)->visual.Reset(); mRemoveVisuals.Erase( iter ); @@ -591,17 +586,17 @@ void Control::Impl::EnableVisual( Property::Index index, bool enable ) (*iter)->enabled = enable; Actor parentActor = mControlImpl.Self(); - if ( mControlImpl.Self().OnStage() ) // If control not on Stage then Visual will be added when StageConnection is called. + if ( mControlImpl.Self().GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) ) // If control not on Scene then Visual will be added when SceneConnection is called. { if ( enable ) { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) on stage \n", (*iter)->visual.GetName().c_str(), index ); - Toolkit::GetImplementation((*iter)->visual).SetOnStage( parentActor ); + Toolkit::GetImplementation((*iter)->visual).SetOnScene( parentActor ); } else { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) off stage \n", (*iter)->visual.GetName().c_str(), index ); - Toolkit::GetImplementation((*iter)->visual).SetOffStage( parentActor ); // No need to call if control not staged. + Toolkit::GetImplementation((*iter)->visual).SetOffScene( parentActor ); // No need to call if control not staged. } } } @@ -626,15 +621,15 @@ void Control::Impl::StopObservingVisual( Toolkit::Visual::Base& visual ) Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual ); // Stop observing the visual - visualImpl.RemoveResourceObserver( *this ); + visualImpl.RemoveEventObserver( *this ); } void Control::Impl::StartObservingVisual( Toolkit::Visual::Base& visual) { Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual ); - // start observing the visual for resource ready - visualImpl.AddResourceObserver( *this ); + // start observing the visual for events + visualImpl.AddEventObserver( *this ); } // Called by a Visual when it's resource is ready @@ -659,7 +654,7 @@ void Control::Impl::ResourceReady( Visual::Base& object) if( FindVisual( (*registeredIter)->index, mRemoveVisuals, visualToRemoveIter ) ) { (*registeredIter)->pending = false; - Toolkit::GetImplementation( (*visualToRemoveIter)->visual ).SetOffStage( self ); + Toolkit::GetImplementation( (*visualToRemoveIter)->visual ).SetOffScene( self ); mRemoveVisuals.Erase( visualToRemoveIter ); } break; @@ -667,7 +662,7 @@ void Control::Impl::ResourceReady( Visual::Base& object) } // A visual is ready so control may need relayouting if staged - if ( self.OnStage() ) + if ( self.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) ) { mControlImpl.RelayoutRequest(); } @@ -680,6 +675,20 @@ void Control::Impl::ResourceReady( Visual::Base& object) } } +void Control::Impl::NotifyVisualEvent( Visual::Base& object, Property::Index signalId ) +{ + for( auto registeredIter = mVisuals.Begin(), end = mVisuals.End(); registeredIter != end; ++registeredIter ) + { + Internal::Visual::Base& registeredVisualImpl = Toolkit::GetImplementation( (*registeredIter)->visual ); + if( &object == ®isteredVisualImpl ) + { + Dali::Toolkit::Control handle( mControlImpl.GetOwner() ); + mVisualEventSignal.Emit( handle, (*registeredIter)->index, signalId ); + break; + } + } +} + bool Control::Impl::IsResourceReady() const { // Iterate through and check all the enabled visuals are ready @@ -750,7 +759,7 @@ void Control::Impl::AddTransitions( Dali::Animation& animation, Actor child = mControlImpl.Self().FindChildByName( animator->objectName ); if( child ) { - Property::Index propertyIndex = DevelHandle::GetPropertyIndex( child, animator->propertyKey ); + Property::Index propertyIndex = child.GetPropertyIndex( animator->propertyKey ); if( propertyIndex != Property::INVALID_INDEX ) { if( animator->animate == false ) @@ -899,29 +908,6 @@ void Control::Impl::SetProperty( BaseObject* object, Property::Index index, cons } break; - case Toolkit::Control::Property::BACKGROUND_COLOR: - { - DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" ); - controlImpl.SetBackgroundColor( value.Get< Vector4 >() ); - break; - } - - case Toolkit::Control::Property::BACKGROUND_IMAGE: - { - DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" ); - Image image = Scripting::NewImage( value ); - if ( image ) - { - controlImpl.SetBackgroundImage( image ); - } - else - { - // An empty image means the background is no longer required - controlImpl.ClearBackground(); - } - break; - } - case Toolkit::Control::Property::KEY_INPUT_FOCUS: { if ( value.Get< bool >() ) @@ -996,6 +982,21 @@ void Control::Impl::SetProperty( BaseObject* object, Property::Index index, cons break; } + case Toolkit::DevelControl::Property::SHADOW: + { + const Property::Map* map = value.GetMap(); + if( map && !map->Empty() ) + { + controlImpl.mImpl->SetShadow( *map ); + } + else + { + // The shadow is an empty property map, so we should clear the shadow + controlImpl.mImpl->ClearShadow(); + } + break; + } + } } } @@ -1054,26 +1055,6 @@ Property::Value Control::Impl::GetProperty( BaseObject* object, Property::Index break; } - case Toolkit::Control::Property::BACKGROUND_COLOR: - { - DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" ); - value = controlImpl.GetBackgroundColor(); - break; - } - - case Toolkit::Control::Property::BACKGROUND_IMAGE: - { - DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" ); - Property::Map map; - Toolkit::Visual::Base visual = controlImpl.mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND ); - if( visual ) - { - visual.CreatePropertyMap( map ); - } - value = map; - break; - } - case Toolkit::Control::Property::KEY_INPUT_FOCUS: { value = controlImpl.HasKeyInputFocus(); @@ -1115,6 +1096,19 @@ Property::Value Control::Impl::GetProperty( BaseObject* object, Property::Index value = map; break; } + + case Toolkit::DevelControl::Property::SHADOW: + { + Property::Map map; + Toolkit::Visual::Base visual = controlImpl.mImpl->GetVisual( Toolkit::DevelControl::Property::SHADOW ); + if( visual ) + { + visual.CreatePropertyMap( map ); + } + + value = map; + break; + } } } @@ -1146,7 +1140,7 @@ void Control::Impl::RemoveVisual( RegisteredVisualContainer& visuals, const std: Toolkit::Visual::Base visual = (*visualIter)->visual; if( visual && visual.GetName() == visualName ) { - Toolkit::GetImplementation(visual).SetOffStage( self ); + Toolkit::GetImplementation(visual).SetOffScene( self ); (*visualIter)->visual.Reset(); visuals.Erase( visualIter ); break; @@ -1360,22 +1354,22 @@ void Control::Impl::SetSubState( const std::string& subStateName, bool withTrans } } -void Control::Impl::OnStageDisconnection() +void Control::Impl::OnSceneDisconnection() { Actor self = mControlImpl.Self(); // Any visuals set for replacement but not yet ready should still be registered. - // Reason: If a request was made to register a new visual but the control removed from stage before visual was ready + // Reason: If a request was made to register a new visual but the control removed from scene before visual was ready // then when this control appears back on stage it should use that new visual. - // Iterate through all registered visuals and set off stage - SetVisualsOffStage( mVisuals, self ); + // Iterate through all registered visuals and set off scene + SetVisualsOffScene( mVisuals, self ); - // Visuals pending replacement can now be taken out of the removal list and set off stage - // Iterate through all replacement visuals and add to a move queue then set off stage + // Visuals pending replacement can now be taken out of the removal list and set off scene + // Iterate through all replacement visuals and add to a move queue then set off scene for( auto removalIter = mRemoveVisuals.Begin(), end = mRemoveVisuals.End(); removalIter != end; removalIter++ ) { - Toolkit::GetImplementation((*removalIter)->visual).SetOffStage( self ); + Toolkit::GetImplementation((*removalIter)->visual).SetOffScene( self ); } for( auto replacedIter = mVisuals.Begin(), end = mVisuals.End(); replacedIter != end; replacedIter++ ) @@ -1428,65 +1422,30 @@ bool Control::Impl::FilterKeyEvent( const KeyEvent& event ) return consumed; } -Toolkit::Internal::LayoutItemPtr Control::Impl::GetLayout() const +DevelControl::VisualEventSignalType& Control::Impl::VisualEventSignal() { - return mLayout; + return mVisualEventSignal; } -void Control::Impl::SetLayout( Toolkit::Internal::LayoutItem& layout ) +void Control::Impl::SetShadow( const Property::Map& map ) { - DALI_LOG_INFO( gLogFilterLayout, Debug::Verbose, "Control::SetLayout control:%s replacing existing layout:%s\n", - mControlImpl.Self().GetName().c_str(), - mLayout?"true":"false" ); - // Check if layout already has an owner. - auto control = Toolkit::Control::DownCast( layout.GetOwner() ); - if ( control ) - { - // If the owner is not this control then the owning control can no longer own it. - Dali::Toolkit::Control handle( mControlImpl.GetOwner() ); - if( control != handle ) - { - DALI_LOG_INFO( gLogFilterLayout, Debug::Verbose, "Control::SetLayout Layout already in use, %s will now have a BinLayout\n", - control.GetName().c_str() ); - Toolkit::BinLayout binLayout = Toolkit::BinLayout::New(); - // Previous owner of the layout gets a BinLayout instead of the layout. - DevelControl::SetLayout( control, binLayout ) ; - } - else - { - return; // layout is already set to this control. - } - } + Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( map ); + visual.SetName("shadow"); - if( mLayout ) + if( visual ) { - mLayout->Unparent(); - mLayout.Reset(); - } + mControlImpl.mImpl->RegisterVisual( Toolkit::DevelControl::Property::SHADOW, visual, DepthIndex::BACKGROUND_EFFECT ); - mLayout = &layout; - - auto controlHandle = Toolkit::Control::DownCast( mControlImpl.Self() ); // Get a handle of this control implementation without copying internals. - mLayout->Initialize( controlHandle, controlHandle.GetTypeName() ); // LayoutGroup takes ownership of existing children -} - -void Control::Impl::RemoveLayout() -{ - DALI_LOG_INFO( gLogFilterLayout, Debug::Verbose, "Control::Impl::RemoveLayout\n"); - - Toolkit::BinLayout binLayout = Toolkit::BinLayout::New(); - - mControlImpl.mImpl->SetLayout( GetImplementation( binLayout ) ) ; + mControlImpl.RelayoutRequest(); + } } -void Control::Impl::SetLayoutingRequired( bool layoutingRequired ) +void Control::Impl::ClearShadow() { - mControlImpl.mImpl->mIsLayoutingRequired = layoutingRequired; -} + mControlImpl.mImpl->UnregisterVisual( Toolkit::DevelControl::Property::SHADOW ); -bool Control::Impl::IsLayoutingRequired() -{ - return mControlImpl.mImpl->mIsLayoutingRequired; + // Trigger a size negotiation request that may be needed when unregistering a visual. + mControlImpl.RelayoutRequest(); } } // namespace Internal