Revert "[Tizen] Fix build errors in adaptor-uv by ecore wayland"
[platform/core/uifw/dali-adaptor.git] / adaptors / emscripten / wrappers / handle-wrapper.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include "handle-wrapper.h"
19
20 // EXTERNAL INCLUDES
21 #include <sstream>
22 #include <dali/devel-api/scripting/scripting.h>
23
24 // INTERNAL INCLUDES
25 #include "type-info-wrapper.h"
26 #include "property-value-wrapper.h"
27
28 namespace Dali
29 {
30 namespace Internal
31 {
32 namespace Emscripten
33 {
34
35 bool BaseHandleOk(Dali::BaseHandle& self)
36 {
37   return self;
38 }
39
40 void SetSelf(Dali::Handle& self, Dali::Handle& other)
41 {
42   self = other;
43 }
44
45 void SetProperty(Dali::Handle& self, const std::string& name, const Dali::Property::Value& value)
46 {
47   DALI_ASSERT_ALWAYS(self);
48   if( self )
49   {
50     Dali::Property::Index index = self.GetPropertyIndex(name);
51
52     if( Dali::Property::INVALID_INDEX != index )
53     {
54       self.SetProperty(index, value);
55     }
56     else
57     {
58       printf("ERR Invalid property name:%s", name.c_str());
59       EM_ASM( throw "Invalid property name (HandleWrapper::SetProperty)" );
60     }
61   }
62   else
63   {
64     EM_ASM( throw "ActorWrapper has no actor" );
65   }
66
67 }
68
69 Dali::Property::Value GetProperty(Dali::Handle& self, const std::string& name)
70 {
71   DALI_ASSERT_ALWAYS(self);
72   Dali::Property::Value ret;
73   if( self )
74   {
75     Dali::Property::Index index = self.GetPropertyIndex(name);
76
77     if( Dali::Property::INVALID_INDEX != index )
78     {
79       ret = self.GetProperty(index);
80     }
81     else
82     {
83       printf("ERR Invalid property name:%s", name.c_str());
84       EM_ASM( throw new Error("Invalid property name (HandleWrapper::GetProperty)") );
85     }
86   }
87   else
88   {
89     EM_ASM( throw new Error("ActorWrapper has no actor") );
90   }
91
92   return ret;
93 }
94
95 int GetPropertyIndex(Dali::Handle& self, const std::string& name)
96 {
97   if( self )
98   {
99     Dali::Property::Index index = self.GetPropertyIndex(name);
100
101     return (int)index; // self.GetPropertyIndex(name);
102   }
103
104   return -1;
105 }
106
107 std::vector<std::string> GetProperties(Dali::Handle& self)
108 {
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)
113   {
114     std::string name = self.GetPropertyName( *iter );
115
116     names.push_back(name);
117   }
118   return names;
119 }
120
121 std::string GetPropertyTypeName(Dali::Handle& self, const std::string& name)
122 {
123   if(self)
124   {
125     Dali::Property::Index index = self.GetPropertyIndex(name);
126     if(Dali::Property::INVALID_INDEX != index)
127     {
128       return Dali::PropertyTypes::GetName(self.GetPropertyType(index));
129     }
130   }
131
132   // if we got here
133   return Dali::PropertyTypes::GetName(Dali::Property::NONE);
134 }
135
136 Dali::Property::Type GetPropertyTypeFromName(Dali::Handle& self, const std::string& name)
137 {
138   Dali::Property::Type type = Dali::Property::NONE;
139
140   if(self)
141   {
142     Dali::Property::Index index = self.GetPropertyIndex(name);
143     if(Dali::Property::INVALID_INDEX != index)
144     {
145       type = self.GetPropertyType(index);
146     }
147   }
148
149   return type;
150 }
151
152 Dali::Property::Index RegisterProperty(Dali::Handle& self, const std::string& name, const Dali::Property::Value& propertyValue)
153 {
154   Dali::Property::Index ret = Dali::Property::INVALID_INDEX;
155
156   Dali::Property::Type type = propertyValue.GetType();
157   if(Dali::Property::ARRAY == type || Dali::Property::MAP == type)
158   {
159     // these types would need support in the javascript side of the wrapper
160     EM_ASM( throw "Property type not supported" );
161   }
162
163   if(self)
164   {
165     ret = self.RegisterProperty(name, propertyValue, Dali::Property::AccessMode::READ_WRITE);
166   }
167   return ret;
168 }
169
170 Dali::TypeInfo GetTypeInfo(Dali::Handle& self)
171 {
172   Dali::TypeInfo ret;
173   if( self )
174   {
175     self.GetTypeInfo(ret);
176   }
177   return ret;
178 }
179
180 Dali::Property::Index RegisterAnimatedProperty(Dali::Handle& self, const std::string& name, const Dali::Property::Value& propertyValue)
181 {
182   Dali::Property::Index ret = Dali::Property::INVALID_INDEX;
183
184   Dali::Property::Type type = propertyValue.GetType();
185   if(Dali::Property::ARRAY == type || Dali::Property::MAP == type)
186   {
187     // these types would need support in the javascript side of the wrapper
188     EM_ASM( throw "Property type not supported" );
189   }
190
191   if(self)
192   {
193     ret = self.RegisterProperty(name, propertyValue,  Dali::Property::AccessMode::ANIMATABLE);
194   }
195   return ret;
196 }
197
198
199 }; // namespace Emscripten
200 }; // namespace Internal
201 }; // namespace Dali