Control not always rendering background image depending on add order
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / control-impl.cpp
index 771114b..649946c 100644 (file)
@@ -66,7 +66,7 @@ BaseHandle Create()
  * @param[in] attributes The attributes with which to perfrom this action.
  * @return true if action has been accepted by this control
  */
-const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibility-activated";
+const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibilityActivated";
 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
 {
   bool ret = false;
@@ -93,13 +93,13 @@ static bool DoAction( BaseObject* object, const std::string& actionName, const P
  * @return True if the signal was connected.
  * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
  */
-const char* SIGNAL_KEY_EVENT = "key-event";
-const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "key-input-focus-gained";
-const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "key-input-focus-lost";
+const char* SIGNAL_KEY_EVENT = "keyEvent";
+const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "keyInputFocusGained";
+const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "keyInputFocusLost";
 const char* SIGNAL_TAPPED = "tapped";
 const char* SIGNAL_PANNED = "panned";
 const char* SIGNAL_PINCHED = "pinched";
-const char* SIGNAL_LONG_PRESSED = "long-pressed";
+const char* SIGNAL_LONG_PRESSED = "longPressed";
 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
 {
   Dali::BaseHandle handle( object );
@@ -355,9 +355,9 @@ public:
 };
 
 // Properties registered without macro to use specific member variables.
-PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "style-name",      Toolkit::Control::Property::STYLE_NAME,      Property::STRING,  &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName",       Toolkit::Control::Property::STYLE_NAME,      Property::STRING,  &Control::Impl::SetProperty, &Control::Impl::GetProperty );
 PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "background",      Toolkit::Control::Property::BACKGROUND,      Property::MAP,     &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "key-input-focus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "keyInputFocus",   Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
 
 Toolkit::Control Control::New()
 {
@@ -399,6 +399,23 @@ const std::string& Control::GetStyleName() const
   return mImpl->mStyleName;
 }
 
+void Control::UpdateBackgroundState()
+{
+  // Set the depth of the background renderer after creating/modifying it.
+  // We do this regardless of whether or not it is on stage as the index
+  // is relative and still valid if this control is re-parented.
+  if( mImpl->mBackgroundRenderer )
+  {
+    mImpl->mBackgroundRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX );
+
+    Actor self( Self() );
+    if( self.OnStage() )
+    {
+      mImpl->mBackgroundRenderer.SetOnStage( self );
+    }
+  }
+}
+
 void Control::SetBackgroundColor( const Vector4& color )
 {
   Actor self( Self() );
@@ -411,13 +428,9 @@ void Control::SetBackgroundColor( const Vector4& color )
   else
   {
     mImpl->mBackgroundRenderer = factory.GetControlRenderer( color );
-
-    if( self.OnStage() )
-    {
-      mImpl->mBackgroundRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX );
-      mImpl->mBackgroundRenderer.SetOnStage( self );
-    }
   }
+
+  UpdateBackgroundState();
 }
 
 Vector4 Control::GetBackgroundColor() const
@@ -441,12 +454,7 @@ void Control::SetBackground(const Property::Map& map)
   Toolkit::RendererFactory factory = Toolkit::RendererFactory::Get();
   mImpl->mBackgroundRenderer = factory.GetControlRenderer( map );
 
-  // mBackgroundRenderer might be empty, if an invalid map is provided, no background.
-  if( self.OnStage() && mImpl->mBackgroundRenderer)
-  {
-    mImpl->mBackgroundRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX );
-    mImpl->mBackgroundRenderer.SetOnStage( self );
-  }
+  UpdateBackgroundState();
 }
 
 void Control::SetBackgroundImage( Image image )
@@ -461,13 +469,9 @@ void Control::SetBackgroundImage( Image image )
   else
   {
     mImpl->mBackgroundRenderer = factory.GetControlRenderer( image );
-
-    if( self.OnStage() )
-    {
-      mImpl->mBackgroundRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX );
-      mImpl->mBackgroundRenderer.SetOnStage( self );
-    }
   }
+
+  UpdateBackgroundState();
 }
 
 void Control::ClearBackground()
@@ -798,17 +802,16 @@ void Control::OnStageConnection( int depth )
 {
   if( mImpl->mBackgroundRenderer)
   {
-    mImpl->mBackgroundRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX );
-    Actor self(Self());
+    Actor self( Self() );
     mImpl->mBackgroundRenderer.SetOnStage( self );
   }
 }
 
 void Control::OnStageDisconnection()
 {
-  if( mImpl->mBackgroundRenderer)
+  if( mImpl->mBackgroundRenderer )
   {
-    Actor self(Self());
+    Actor self( Self() );
     mImpl->mBackgroundRenderer.SetOffStage( self );
   }
 }