2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "handle-wrapper.h"
22 #include <dali/devel-api/scripting/scripting.h>
25 #include "type-info-wrapper.h"
26 #include "property-value-wrapper.h"
35 bool BaseHandleOk(Dali::BaseHandle& self)
40 void SetSelf(Dali::Handle& self, Dali::Handle& other)
45 void SetProperty(Dali::Handle& self, const std::string& name, const Dali::Property::Value& value)
47 DALI_ASSERT_ALWAYS(self);
50 Dali::Property::Index index = self.GetPropertyIndex(name);
52 if( Dali::Property::INVALID_INDEX != index )
54 self.SetProperty(index, value);
58 printf("ERR Invalid property name:%s", name.c_str());
59 EM_ASM( throw "Invalid property name (HandleWrapper::SetProperty)" );
64 EM_ASM( throw "ActorWrapper has no actor" );
69 Dali::Property::Value GetProperty(Dali::Handle& self, const std::string& name)
71 DALI_ASSERT_ALWAYS(self);
72 Dali::Property::Value ret;
75 Dali::Property::Index index = self.GetPropertyIndex(name);
77 if( Dali::Property::INVALID_INDEX != index )
79 ret = self.GetProperty(index);
83 printf("ERR Invalid property name:%s", name.c_str());
84 EM_ASM( throw new Error("Invalid property name (HandleWrapper::GetProperty)") );
89 EM_ASM( throw new Error("ActorWrapper has no actor") );
95 int GetPropertyIndex(Dali::Handle& self, const std::string& name)
99 Dali::Property::Index index = self.GetPropertyIndex(name);
101 return (int)index; // self.GetPropertyIndex(name);
107 std::vector<std::string> GetProperties(Dali::Handle& self)
109 Dali::Property::IndexContainer indices;
110 self.GetPropertyIndices( indices );
111 std::vector<std::string> names;
112 for(Dali::Property::IndexContainer::Iterator iter(indices.Begin()); iter != indices.End(); ++iter)
114 std::string name = self.GetPropertyName( *iter );
116 names.push_back(name);
121 std::string GetPropertyTypeName(Dali::Handle& self, const std::string& name)
125 Dali::Property::Index index = self.GetPropertyIndex(name);
126 if(Dali::Property::INVALID_INDEX != index)
128 return Dali::PropertyTypes::GetName(self.GetPropertyType(index));
133 return Dali::PropertyTypes::GetName(Dali::Property::NONE);
136 Dali::Property::Type GetPropertyTypeFromName(Dali::Handle& self, const std::string& name)
138 Dali::Property::Type type = Dali::Property::NONE;
142 Dali::Property::Index index = self.GetPropertyIndex(name);
143 if(Dali::Property::INVALID_INDEX != index)
145 type = self.GetPropertyType(index);
152 Dali::Property::Index RegisterProperty(Dali::Handle& self, const std::string& name, const Dali::Property::Value& propertyValue)
154 Dali::Property::Index ret = Dali::Property::INVALID_INDEX;
156 Dali::Property::Type type = propertyValue.GetType();
157 if(Dali::Property::ARRAY == type || Dali::Property::MAP == type)
159 // these types would need support in the javascript side of the wrapper
160 EM_ASM( throw "Property type not supported" );
165 ret = self.RegisterProperty(name, propertyValue, Dali::Property::AccessMode::READ_WRITE);
170 Dali::TypeInfo GetTypeInfo(Dali::Handle& self)
175 self.GetTypeInfo(ret);
180 Dali::Property::Index RegisterAnimatedProperty(Dali::Handle& self, const std::string& name, const Dali::Property::Value& propertyValue)
182 Dali::Property::Index ret = Dali::Property::INVALID_INDEX;
184 Dali::Property::Type type = propertyValue.GetType();
185 if(Dali::Property::ARRAY == type || Dali::Property::MAP == type)
187 // these types would need support in the javascript side of the wrapper
188 EM_ASM( throw "Property type not supported" );
193 ret = self.RegisterProperty(name, propertyValue, Dali::Property::AccessMode::ANIMATABLE);
199 }; // namespace Emscripten
200 }; // namespace Internal