Visual replacements logic updated
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / image-view / image-view-impl.cpp
index 80f1ee4..4183b89 100644 (file)
@@ -1,4 +1,19 @@
-// Copyright (c) 2016 Samsung Electronics Co., Ltd.
+/*
+ * Copyright (c) 2017 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 // CLASS HEADER
 #include "image-view-impl.h"
@@ -11,6 +26,7 @@
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
@@ -71,6 +87,13 @@ Toolkit::ImageView ImageView::New()
 
 /////////////////////////////////////////////////////////////
 
+void ImageView::OnInitialize()
+{
+  // ImageView can relayout in the OnImageReady, alternative to a signal would be to have a upcall from the Control to ImageView
+  Dali::Toolkit::Control handle( GetOwner() );
+  Toolkit::DevelControl::ResourceReadySignal( handle ).Connect( this, &ImageView::OnResourceReady );
+}
+
 void ImageView::SetImage( Image image )
 {
   // Don't bother comparing if we had a visual previously, just drop old visual and create new one
@@ -78,10 +101,13 @@ void ImageView::SetImage( Image image )
   mUrl.clear();
   mPropertyMap.Clear();
 
-  mVisual =  Toolkit::VisualFactory::Get().CreateVisual( image );
-  RegisterVisual( Toolkit::ImageView::Property::IMAGE, mVisual  );
+  Toolkit::Visual::Base visual =  Toolkit::VisualFactory::Get().CreateVisual( image );
+  if (!mVisual)
+  {
+    mVisual = visual;
+  }
 
-  RelayoutRequest();
+  DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual  );
 }
 
 void ImageView::SetImage( const Property::Map& map )
@@ -90,11 +116,14 @@ void ImageView::SetImage( const Property::Map& map )
   mPropertyMap = map;
   mUrl.clear();
   mImage.Reset();
+  Toolkit::Visual::Base visual =  Toolkit::VisualFactory::Get().CreateVisual( mPropertyMap );
+  // Don't set mVisual until it is ready and shown. Getters will still use current visual.
+  if (!mVisual)
+  {
+    mVisual = visual;
+  }
 
-  mVisual =  Toolkit::VisualFactory::Get().CreateVisual( mPropertyMap );
-  RegisterVisual( Toolkit::ImageView::Property::IMAGE, mVisual  );
-
-  RelayoutRequest();
+  DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual  );
 }
 
 void ImageView::SetImage( const std::string& url, ImageDimensions size )
@@ -104,10 +133,14 @@ void ImageView::SetImage( const std::string& url, ImageDimensions size )
   mImage.Reset();
   mPropertyMap.Clear();
 
-  mVisual =  Toolkit::VisualFactory::Get().CreateVisual( url, size );
-  RegisterVisual( Toolkit::ImageView::Property::IMAGE, mVisual );
+  // Don't set mVisual until it is ready and shown. Getters will still use current visual.
+  Toolkit::Visual::Base visual =  Toolkit::VisualFactory::Get().CreateVisual( url, size );
+  if (!mVisual)
+  {
+    mVisual = visual;
+  }
 
-  RelayoutRequest();
+  DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual );
 }
 
 Image ImageView::GetImage() const
@@ -181,6 +214,9 @@ void ImageView::OnRelayout( const Vector2& size, RelayoutContainer& container )
 {
   Control::OnRelayout( size, container );
 
+  // If visual is being replaced then mVisual will be the replacement visual even if not ready.
+  mVisual = DevelControl::GetVisual( *this, Toolkit::ImageView::Property::IMAGE );
+
   if( mVisual )
   {
     // Pass in an empty map which uses default transform values meaning our visual fills the control
@@ -189,6 +225,10 @@ void ImageView::OnRelayout( const Vector2& size, RelayoutContainer& container )
   }
 }
 
+void ImageView::OnResourceReady( Toolkit::Control control )
+{
+}
+
 ///////////////////////////////////////////////////////////
 //
 // Properties