c28330cc88de5c016083a78baf204a695dffced8
[platform/core/uifw/dali-core.git] / dali / public-api / object / handle.cpp
1 /*
2  * Copyright (c) 2020 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 // CLASS HEADER
19 #include <dali/public-api/object/handle.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/animation/constraint.h>
23 #include <dali/public-api/object/property-conditions.h>
24 #include <dali/public-api/object/property-notification.h>
25 #include <dali/internal/event/animation/constraint-impl.h>
26 #include <dali/internal/event/common/object-impl.h>
27 #include <dali/integration-api/debug.h>
28
29 namespace Dali
30 {
31
32
33 Handle::Handle( Dali::Internal::Object* handle )
34 : BaseHandle(handle)
35 {
36 }
37
38 Handle::Handle()
39 {
40 }
41
42 Handle Handle::New()
43 {
44   return Handle( Internal::Object::New().Get() );
45 }
46
47 Handle::~Handle()
48 {
49 }
50
51 Handle::Handle( const Handle& handle ) = default;
52
53 Handle& Handle::operator=( const Handle& rhs ) = default;
54
55 Handle::Handle( Handle&& rhs ) = default;
56
57 Handle& Handle::operator=( Handle&& rhs ) = default;
58
59 Handle Handle::DownCast( BaseHandle handle )
60 {
61   return Handle( dynamic_cast<Dali::Internal::Object*>(handle.GetObjectPtr()) );
62 }
63
64 bool Handle::Supports( Capability capability ) const
65 {
66   return GetImplementation(*this).Supports( capability );
67 }
68
69 uint32_t Handle::GetPropertyCount() const
70 {
71   return GetImplementation(*this).GetPropertyCount();
72 }
73
74 std::string Handle::GetPropertyName( Property::Index index ) const
75 {
76   return GetImplementation(*this).GetPropertyName( index );
77 }
78
79 Property::Index Handle::GetPropertyIndex( Property::Key key ) const
80 {
81   return GetImplementation( *this ).GetPropertyIndex( key );
82 }
83
84 bool Handle::IsPropertyWritable( Property::Index index ) const
85 {
86   return GetImplementation(*this).IsPropertyWritable( index );
87 }
88
89 bool Handle::IsPropertyAnimatable( Property::Index index ) const
90 {
91   return GetImplementation(*this).IsPropertyAnimatable( index );
92 }
93
94 bool Handle::IsPropertyAConstraintInput( Property::Index index ) const
95 {
96   return GetImplementation(*this).IsPropertyAConstraintInput( index );
97 }
98
99 Property::Type Handle::GetPropertyType( Property::Index index ) const
100 {
101   return GetImplementation(*this).GetPropertyType( index );
102 }
103
104 void Handle::SetProperty( Property::Index index, const Property::Value& propertyValue )
105 {
106   GetImplementation(*this).SetProperty( index, propertyValue );
107 }
108
109 Property::Index Handle::RegisterProperty( const std::string& name, const Property::Value& propertyValue )
110 {
111   return GetImplementation(*this).RegisterProperty( name, propertyValue );
112 }
113
114 Property::Index Handle::RegisterProperty( Property::Index key, const std::string& name, const Property::Value& propertyValue )
115 {
116   return GetImplementation( *this ).RegisterProperty( name, key, propertyValue );
117 }
118
119 Property::Index Handle::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode )
120 {
121   return GetImplementation(*this).RegisterProperty( name, propertyValue, accessMode );
122 }
123
124 Property::Value Handle::GetProperty( Property::Index index ) const
125 {
126   return GetImplementation(*this).GetProperty( index );
127 }
128
129 Property::Value Handle::GetCurrentProperty( Property::Index index ) const
130 {
131   return GetImplementation(*this).GetCurrentProperty( index );
132 }
133
134 void Handle::SetProperties( const Property::Map& properties )
135 {
136   GetImplementation( *this ).SetProperties( properties );
137 }
138
139 void Handle::GetProperties( Property::Map& properties )
140 {
141   GetImplementation( *this ).GetProperties( properties );
142 }
143
144 void Handle::GetPropertyIndices( Property::IndexContainer& indices ) const
145 {
146   GetImplementation(*this).GetPropertyIndices( indices );
147 }
148
149 bool Handle::DoesCustomPropertyExist( Property::Index index )
150 {
151   return GetImplementation( *this ).DoesCustomPropertyExist( index );
152 }
153
154 Dali::PropertyNotification Handle::AddPropertyNotification( Property::Index index,
155                                                             const PropertyCondition& condition )
156 {
157   return GetImplementation(*this).AddPropertyNotification( index, -1, condition );
158 }
159
160 Dali::PropertyNotification Handle::AddPropertyNotification( Property::Index index,
161                                                             int componentIndex,
162                                                             const PropertyCondition& condition )
163 {
164   return GetImplementation(*this).AddPropertyNotification( index, componentIndex, condition );
165 }
166
167 void Handle::RemovePropertyNotification( Dali::PropertyNotification propertyNotification )
168 {
169   GetImplementation(*this).RemovePropertyNotification( propertyNotification );
170 }
171
172 void Handle::RemovePropertyNotifications()
173 {
174   GetImplementation(*this).RemovePropertyNotifications();
175 }
176
177 void Handle::RemoveConstraints()
178 {
179   GetImplementation(*this).RemoveConstraints();
180 }
181
182 void Handle::RemoveConstraints( uint32_t tag )
183 {
184   GetImplementation(*this).RemoveConstraints( tag );
185 }
186
187 IndirectValue Handle::operator[]( Property::Index index )
188 {
189   // Will assert on access if handle is empty
190   return IndirectValue(*this, index);
191 }
192
193 IndirectValue Handle::operator[]( const std::string& name )
194 {
195   // Will assert immediately when GetPropertyIndex is called if handle is empty
196   return IndirectValue(*this, GetPropertyIndex(name));
197 }
198
199 Handle::PropertySetSignalType& Handle::PropertySetSignal()
200 {
201   return GetImplementation( *this ).PropertySetSignal();
202 }
203
204
205 namespace WeightObject
206 {
207
208 const Property::Index WEIGHT = PROPERTY_CUSTOM_START_INDEX;
209
210 Handle New()
211 {
212   Handle handle = Handle::New();
213
214   handle.RegisterProperty( "weight", 0.0f );
215
216   return handle;
217 }
218
219 } // namespace WeightObject
220
221 } // namespace Dali