+ BaseHandle baseHandle;
+ TypeInfo typeInfo;
+ const TreeNode* templateNode = NULL;
+
+ if( OptionalString typeName = IsString(node, KEYNAME_TYPE) )
+ {
+ typeInfo = TypeRegistry::Get().GetTypeInfo( *typeName );
+
+ if( !typeInfo )
+ {
+ // a template name is also allowed inplace of the type name
+ OptionalChild templates = IsChild( root, KEYNAME_TEMPLATES);
+
+ if( templates )
+ {
+ if( OptionalChild isTemplate = IsChild( *templates, *typeName ) )
+ {
+ templateNode = &(*isTemplate);
+
+ if( OptionalString templateTypeName = IsString(*templateNode, KEYNAME_TYPE) )
+ {
+ typeInfo = TypeRegistry::Get().GetTypeInfo( *templateTypeName );
+ }
+ }
+ }
+ }
+ }
+
+ if(!typeInfo)
+ {
+ DALI_SCRIPT_WARNING("Cannot create Dali type from node '%s'\n", node.GetName());
+ }
+ else
+ {
+ baseHandle = typeInfo.CreateInstance();
+ Handle handle = Handle::DownCast(baseHandle);
+ Actor actor = Actor::DownCast(handle);
+
+ if(handle)
+ {
+
+ DALI_SCRIPT_VERBOSE("Create:%s\n", typeInfo.GetName().c_str());
+
+#if defined(DEBUG_ENABLED)
+ if(handle)
+ {
+ DALI_SCRIPT_VERBOSE(" Is Handle Object=%d\n", (long*)handle.GetObjectPtr());
+ DALI_SCRIPT_VERBOSE(" Is Handle Property Count=%d\n", handle.GetPropertyCount());
+ }
+
+ if(actor)
+ {
+ DALI_SCRIPT_VERBOSE(" Is Actor id=%d\n", actor.GetId());
+ }
+
+ Toolkit::Control control = Toolkit::Control::DownCast(handle);
+ if(control)
+ {
+ DALI_SCRIPT_VERBOSE(" Is Control id=%d\n", actor.GetId());
+ }
+#endif // DEBUG_ENABLED
+
+ if( templateNode )
+ {
+ ApplyProperties( root, *templateNode, handle, replacements );
+
+ if( OptionalChild actors = IsChild( *templateNode, KEYNAME_ACTORS ) )
+ {
+ for( TreeConstIter iter = (*actors).CBegin(); iter != (*actors).CEnd(); ++iter )
+ {
+ DoCreate( root, (*iter).second, actor, replacements );
+ }
+ }
+ }
+
+ if( actor )
+ {
+ // add children of all the styles
+ if( OptionalChild actors = IsChild( node, KEYNAME_ACTORS ) )
+ {
+ for( TreeConstIter iter = (*actors).CBegin(); iter != (*actors).CEnd(); ++iter )
+ {
+ DoCreate( root, (*iter).second, actor, replacements );
+ }
+ }
+
+ // apply style on top as they need the children to exist
+ ApplyAllStyleProperties( root, node, actor, replacements );
+
+ // then add to parent
+ if( parent )
+ {
+ parent.Add( actor );
+ }
+ }
+ else
+ {
+ ApplyProperties( root, node, handle, replacements );
+ }
+ }
+ else
+ {
+ DALI_SCRIPT_WARNING("Cannot create handle from type '%s'\n", typeInfo.GetName().c_str());
+ }
+ }
+
+ return baseHandle;