1 #ifndef __DALI_HANDLE_H__
2 #define __DALI_HANDLE_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 * @addtogroup CAPI_DALI_OBJECT_MODULE
30 #include <dali/public-api/common/dali-common.h>
31 #include <dali/public-api/object/base-handle.h>
32 #include <dali/public-api/object/property-types.h>
33 #include <dali/public-api/object/property-value.h>
34 #include <dali/public-api/object/property-notification-declarations.h>
35 #include <dali/public-api/object/ref-object.h>
37 namespace Dali DALI_IMPORT_API
40 class PropertyNotification;
41 class PropertyCondition;
43 namespace Internal DALI_INTERNAL
49 * @brief Dali::Handle is a handle to an internal property owning Dali object.
51 class Handle : public BaseHandle
56 * @brief An Handle's capabilities can be queried using Handle::Supports()
61 * @brief Some objects support dynamic property creation at run-time.
63 * New properties are registered by calling RegisterProperty() with an unused property name.
65 DYNAMIC_PROPERTIES = 0x01,
71 * @brief This constructor is used by Dali New() methods.
73 * @param [in] handle A pointer to a newly allocated Dali resource
75 Handle(Dali::Internal::Object* handle);
78 * @brief This constructor provides an uninitialized Dali::Handle.
80 * This should be initialized with a Dali New() method before use.
81 * Methods called on an uninitialized Dali::Handle will assert.
83 * Handle handle; // uninitialized
84 * handle.SomeMethod(); // unsafe! This will assert
86 * handle = SomeClass::New(); // now initialized
87 * handle.SomeMethod(); // safe
93 * @brief Dali::Handle is intended as a base class.
99 * @brief This copy constructor is required for (smart) pointer semantics.
101 * @param [in] handle A reference to the copied handle
103 Handle(const Handle& handle);
106 * @brief This assignment operator is required for (smart) pointer semantics.
108 * @param [in] rhs A reference to the copied handle
109 * @return A reference to this
111 Handle& operator=(const Handle& rhs);
114 * @copydoc Dali::BaseHandle::operator=
116 using BaseHandle::operator=;
119 * @brief Downcast to a handle.
121 * If not the returned handle is left uninitialized.
122 * @param[in] handle to An object
123 * @return handle or an uninitialized handle
125 static Handle DownCast( BaseHandle handle );
130 * @brief Query whether an handle supports a given capability.
132 * @param[in] capability The queried capability.
133 * @return True if the capability is supported.
135 bool Supports(Capability capability) const;
138 * @brief Query how many properties are provided by an handle.
140 * This may vary between instances of a class, if dynamic properties are supported.
141 * @return The number of properties.
143 unsigned int GetPropertyCount() const;
146 * @brief Query the name of a property.
148 * @param [in] index The index of the property.
149 * @return The name of the property.
151 const std::string& GetPropertyName(Property::Index index) const;
154 * @brief Query the index of a property.
156 * @param [in] name The name of the property.
157 * @return The index of the property, or Property::INVALID_INDEX if no property exists with the given name.
159 Property::Index GetPropertyIndex(std::string name) const;
162 * @brief Query whether a property can be set using SetProperty().
164 * @pre Property::INVALID_INDEX < index.
165 * @param [in] index The index of the property.
166 * @return True if the property is writable.
168 bool IsPropertyWritable(Property::Index index) const;
171 * @brief Query whether a writable property can be the target of an animation or constraint.
173 * @param [in] index The index of the property.
174 * @return True if the property is animatable.
176 bool IsPropertyAnimatable(Property::Index index) const;
179 * @brief Query whether a property can be used as in input to a constraint.
181 * @param [in] index The index of the property.
182 * @return True if the property can be used as a constraint input.
184 bool IsPropertyAConstraintInput(Property::Index index) const;
187 * @brief Query the type of a property.
189 * @param [in] index The index of the property.
190 * @return The type of the property.
192 Property::Type GetPropertyType(Property::Index index) const;
195 * @brief Set the value of an existing property.
197 * @pre Handle::IsPropertyWritable(index) returns true.
198 * @pre The property types match i.e. propertyValue.GetType() is equal to GetPropertyType(index).
199 * @param [in] index The index of the property.
200 * @param [in] propertyValue The new value of the property.
202 void SetProperty(Property::Index index, Property::Value propertyValue);
205 * @brief Register a new property.
207 * @pre The handle supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
208 * @pre name is unused i.e. GetPropertyIndex(name) returns PropertyIndex::INVALID.
209 * @param [in] name The name of the property.
210 * @param [in] propertyValue The new value of the property.
211 * @return The index of the property
213 Property::Index RegisterProperty(std::string name, Property::Value propertyValue);
216 * @brief Register a new property.
218 * Properties can be set as non animatable using property attributes.
219 * @pre The handle supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
220 * @pre name is unused i.e. GetPropertyIndex(name) returns PropertyIndex::INVALID.
221 * @param [in] name The name of the property.
222 * @param [in] propertyValue The new value of the property.
223 * @param [in] accessMode The property access mode (writable, animatable etc).
224 * @return The index of the property
226 Property::Index RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode);
229 * @brief Retrieve a property value.
231 * @param [in] index The index of the property.
232 * @return The property value.
234 Property::Value GetProperty(Property::Index index) const;
237 * @brief Convenience function for obtaining a property of a known type.
239 * @pre The property types match i.e. PropertyTypes::Get<T>() is equal to GetPropertyType(index).
240 * @param [in] index The index of the property.
241 * @return The property value.
243 template <typename T>
244 T GetProperty(Property::Index index) const
246 Property::Value value = GetProperty(index);
248 return T( value.Get<T>() );
252 * @brief Retrieve all the property indices for this object (including custom properties).
254 * @param[out] indices A container of property indices for this object.
255 * @note the added container is cleared
257 void GetPropertyIndices( Property::IndexContainer& indices ) const;
260 * @brief Add a property notification to this object.
262 * @param [in] index The index of the property.
263 * @param [in] condition The notification will be triggered when this condition is satisfied.
265 * @return A handle to the newly created PropertyNotification
267 PropertyNotification AddPropertyNotification(Property::Index index,
268 const PropertyCondition& condition);
271 * @brief Add a property notification to this object.
273 * @param [in] index The index of the property.
274 * @param [in] componentIndex Index to the component of a complex property such as a Vector
275 * @param [in] condition The notification will be triggered when this condition is satisfied.
277 * @return A handle to the newly created PropertyNotification
279 PropertyNotification AddPropertyNotification(Property::Index index,
281 const PropertyCondition& condition);
284 * @brief Remove a property notification from this object.
286 * @param [in] propertyNotification The propertyNotification to be removed.
288 void RemovePropertyNotification(Dali::PropertyNotification propertyNotification);
291 * @brief Remove all property notifications from this object.
293 void RemovePropertyNotifications();
302 #endif // __DALI_HANDLE_H__