Remove unused functions
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / builder / builder-impl.cpp
index f11b9b3..23ea9f8 100644 (file)
@@ -1,24 +1,26 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.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://floralicense.org/license/
-//
-// 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.
-//
+/*
+ * Copyright (c) 2014 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 <dali-toolkit/internal/builder/builder-impl.h>
 
 // EXTERNAL INCLUDES
 #include <sys/stat.h>
+#include <boost/function.hpp>
 #include <sstream>
 
 // INTERNAL INCLUDES
@@ -48,9 +50,9 @@ extern bool SetPropertyFromNode( const TreeNode& node, Property::Value& value );
 extern bool SetPropertyFromNode( const TreeNode& node, Property::Value& value, const Replacement& replacements );
 extern bool SetPropertyFromNode( const TreeNode& node, Property::Type type, Property::Value& value );
 extern bool SetPropertyFromNode( const TreeNode& node, Property::Type type, Property::Value& value, const Replacement& replacements );
-extern Actor SetupSignalAction(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor);
-extern Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor);
-extern Actor SetupActor( const TreeNode& node, Actor& actor );
+extern Actor SetupSignalAction(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor, boost::function<void (void)> quitAction);
+extern Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor, boost::function<void (void)> quitAction);
+extern Actor SetupActor( const TreeNode& node, Actor& actor, const Replacement& constant );
 
 #if defined(DEBUG_ENABLED)
 Integration::Log::Filter* gFilterScript  = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_SCRIPT");
@@ -85,98 +87,6 @@ std::string ToString(const Rect<int>& value)
   return ss.str();
 }
 
-
-std::string PropertyValueToString( const Property::Value& value )
-{
-  std::string ret;
-
-  switch( value.GetType() )
-  {
-    case Property::NONE:
-    {
-      ret = "NONE";
-      break;
-    }            ///< No type
-    case Property::BOOLEAN:
-    {
-      ret = value.Get<bool>() ? "True" : "False";
-      break;
-    }
-    case Property::FLOAT:
-    {
-
-      ret = ToString( value.Get<float>() );
-      break;
-    }
-    case Property::INTEGER:
-    {
-      ret = ToString( value.Get<int>() );
-      break;
-    }
-    case Property::UNSIGNED_INTEGER:
-    {
-      ret = ToString( value.Get<unsigned int>() );
-      break;
-    }
-    case Property::VECTOR2:
-    {
-      ret = ToString( value.Get<Vector2>() );
-      break;
-    }
-    case Property::VECTOR3:
-    {
-      ret = ToString( value.Get<Vector3>() );
-      break;
-    }
-    case Property::VECTOR4:
-    {
-      ret = ToString( value.Get<Vector4>() );
-      break;
-    }
-    case Property::MATRIX3:
-    {
-      ret = ToString( value.Get<Matrix3>() );
-      break;
-    }
-    case Property::MATRIX:
-    {
-      ret = ToString( value.Get<Matrix>() );
-      break;
-    }
-    case Property::RECTANGLE:
-    {
-      ret = ToString( value.Get< Rect<int> >() );
-      break;
-    }
-    case Property::ROTATION:
-    {
-      break;
-    }
-    case Property::STRING:
-    {
-      ret = value.Get<std::string>();
-      break;
-    }
-    case Property::ARRAY:
-    {
-      ret = std::string("Array Size=") + ToString( value.Get<Property::Array>().size() );
-      break;
-    }
-    case Property::MAP:
-    {
-      ret = std::string("Map Size=") + ToString( value.Get<Property::Map>().size() );
-      break;
-    }
-    case Property::TYPE_COUNT:
-    {
-      ret = "";
-      break;
-    }
-  }
-
-  return ret;
-}
-
 /*
  * Recursively collects all stylesin a node (An array of style names).
  *
@@ -207,6 +117,23 @@ void CollectAllStyles( const TreeNode& stylesCollection, const TreeNode& style,
   }
 }
 
+struct QuitAction
+{
+public:
+  QuitAction( Builder& builder )
+  : mBuilder( builder )
+  {
+  }
+
+  void operator()(void)
+  {
+    mBuilder.EmitQuitSignal();
+  }
+
+private:
+  Builder& mBuilder;
+};
+
 } // namespace anon
 
 /*
@@ -222,7 +149,7 @@ void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replace
 
       std::string key( keyChild.first );
 
-      // ignore special fields; type,actors,signals
+      // ignore special fields; type,actors,signals,styles
       if(key == KEYNAME_TYPE || key == KEYNAME_ACTORS || key == KEYNAME_SIGNALS || key == KEYNAME_STYLES)
       {
         continue;
@@ -252,12 +179,15 @@ void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replace
       // special field 'effect' references the shader effect instances
       if(key == "effect")
       {
-        Actor actor = Actor::DownCast(handle);
-        OptionalString s = constant.IsString( keyChild.second );
-        if(actor && s)
+        RenderableActor actor = RenderableActor::DownCast(handle);
+        if( actor )
         {
-          ShaderEffect e = GetShaderEffect(*s, constant);
-          actor.SetShaderEffect(e);
+          OptionalString str = constant.IsString( keyChild.second );
+          if( str )
+          {
+            ShaderEffect effect = GetShaderEffect( *str, constant );
+            actor.SetShaderEffect(effect);
+          }
         }
         else
         {
@@ -273,7 +203,7 @@ void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replace
 
       if( Property::INVALID_INDEX == index )
       {
-        Actor actor = Actor::DownCast(propertyObject);
+        RenderableActor actor = RenderableActor::DownCast(handle);
         if( actor )
         {
           if( ShaderEffect effect = actor.GetShaderEffect() )
@@ -328,12 +258,12 @@ void Builder::ApplyProperties( const TreeNode& root, const TreeNode& node,
 
     if( actor )
     {
-      SetupActor( node, actor );
+      SetupActor( node, actor, constant );
 
       // add signals
-      SetupSignalAction( mSlotDelegate.GetConnectionTracker(), root, node, actor );
-
-      SetupPropertyNotification( mSlotDelegate.GetConnectionTracker(), root, node, actor );
+      QuitAction quitAction( *this );
+      SetupSignalAction( mSlotDelegate.GetConnectionTracker(), root, node, actor, quitAction );
+      SetupPropertyNotification( mSlotDelegate.GetConnectionTracker(), root, node, actor, quitAction );
    }
   }
   else
@@ -503,9 +433,7 @@ BaseHandle Builder::DoCreate( const TreeNode& root, const TreeNode& node,
         }
       }
 
-      ApplyProperties( root, node, handle, replacements );
-
-      if( actor)
+      if( actor )
       {
         // add children of all the styles
         if( OptionalChild actors = IsChild( node, KEYNAME_ACTORS ) )
@@ -525,7 +453,10 @@ BaseHandle Builder::DoCreate( const TreeNode& root, const TreeNode& node,
           parent.Add( actor );
         }
       }
-
+      else
+      {
+        ApplyProperties( root, node, handle, replacements );
+      }
     }
     else
     {
@@ -536,19 +467,6 @@ BaseHandle Builder::DoCreate( const TreeNode& root, const TreeNode& node,
   return baseHandle;
 }
 
-
-ActorContainer Builder::GetTopLevelActors() const
-{
-  // deprecated function.
-  return ActorContainer();
-}
-
-Animation Builder::GetAnimation( const std::string &name ) const
-{
-  // deprecated
-  return Animation();
-}
-
 void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replacement& constant )
 {
   const Stage& stage = Stage::GetCurrent();
@@ -724,7 +642,7 @@ FrameBufferImage Builder::GetFrameBufferImage( const std::string &name, const Re
         if( SetPropertyFromNode( *image, Property::MAP, propertyMap, constant ) )
         {
           propertyMap.SetValue(KEYNAME_TYPE, Property::Value(std::string("FrameBufferImage")));
-          ret = Dali::Scripting::NewImage( propertyMap );
+          ret = FrameBufferImage::DownCast( Dali::Scripting::NewImage( propertyMap ) );
           mFrameBufferImageLut[ name ] = ret;
         }
       }
@@ -734,29 +652,14 @@ FrameBufferImage Builder::GetFrameBufferImage( const std::string &name, const Re
   return ret;
 }
 
-Font Builder::GetFont( const std::string& name ) const
+Toolkit::Builder::Signal& Builder::QuitSignal()
 {
-  // deprecated function.
-  Font font;
-  return font;
+  return mQuitSignal;
 }
 
-TextStyle Builder::GetTextStyle( const std::string& name ) const
+void Builder::EmitQuitSignal()
 {
-  // deprecated
-  return TextStyle();
-}
-
-Image Builder::GetImage( const std::string& name) const
-{
-  // deprecated function.
-  return Image();
-}
-
-Actor Builder::GetActor( const std::string &name ) const
-{
-  // deprecated function.
-  return Actor();
+  mQuitSignal.Emit();
 }
 
 void Builder::AddActors( Actor toActor )
@@ -1015,7 +918,6 @@ bool Builder::ApplyStyle( const std::string& styleName, Handle& handle, const Re
   }
   else
   {
-    DALI_SCRIPT_WARNING("No styles section to create style '%s'\n", styleName.c_str());
     return false;
   }
 }
@@ -1063,6 +965,44 @@ BaseHandle Builder::Create( const std::string& templateName, const Replacement&
   return baseHandle;
 }
 
+BaseHandle Builder::CreateFromJson( const std::string& json )
+{
+  BaseHandle ret;
+
+  // merge in new template, hoping no one else has one named '@temp@'
+  std::string newTemplate =
+    std::string("{\"templates\":{\"@temp@\":") +                      \
+    json +                                                            \
+    std::string("}}");
+
+  if( mParser.Parse(newTemplate) )
+  {
+    Replacement replacement( mReplacementMap );
+    ret = Create( "@temp@", replacement );
+  }
+
+  return ret;
+}
+
+bool Builder::ApplyFromJson(  Handle& handle, const std::string& json )
+{
+  bool ret = false;
+
+  // merge new style, hoping no one else has one named '@temp@'
+  std::string newStyle =
+    std::string("{\"styles\":{\"@temp@\":") +                           \
+    json +                                                              \
+    std::string("}}");
+
+  if( mParser.Parse(newStyle) )
+  {
+    Replacement replacement( mReplacementMap );
+    ret = ApplyStyle( "@temp@", handle, replacement );
+  }
+
+  return ret;
+}
+
 
 BaseHandle Builder::Create( const std::string& templateName )
 {