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