1 #ifndef __DALI_HANDLE_H__
2 #define __DALI_HANDLE_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
21 * @addtogroup CAPI_DALI_OBJECT_MODULE
29 #include <dali/public-api/common/dali-common.h>
30 #include <dali/public-api/object/base-handle.h>
31 #include <dali/public-api/object/property-types.h>
32 #include <dali/public-api/object/property-value.h>
33 #include <dali/public-api/object/property-notification-declarations.h>
34 #include <dali/public-api/object/ref-object.h>
36 namespace Dali DALI_IMPORT_API
39 class PropertyNotification;
40 class PropertyCondition;
42 namespace Internal DALI_INTERNAL
48 * @brief Dali::Handle is a handle to an internal property owning Dali object.
50 class Handle : public BaseHandle
55 * @brief An Handle's capabilities can be queried using Handle::Supports()
60 * @brief Some objects support dynamic property creation at run-time.
62 * New properties are registered by calling RegisterProperty() with an unused property name.
64 DYNAMIC_PROPERTIES = 0x01,
70 * @brief This constructor is used by Dali New() methods.
72 * @param [in] handle A pointer to a newly allocated Dali resource
74 Handle(Dali::Internal::Object* handle);
77 * @brief This constructor provides an uninitialized Dali::Handle.
79 * This should be initialized with a Dali New() method before use.
80 * Methods called on an uninitialized Dali::Handle will assert.
82 * Handle handle; // uninitialized
83 * handle.SomeMethod(); // unsafe! This will assert
85 * handle = SomeClass::New(); // now initialized
86 * handle.SomeMethod(); // safe
92 * @brief Dali::Handle is intended as a base class.
98 * @brief This copy constructor is required for (smart) pointer semantics.
100 * @param [in] handle A reference to the copied handle
102 Handle(const Handle& handle);
105 * @brief This assignment operator is required for (smart) pointer semantics.
107 * @param [in] rhs A reference to the copied handle
108 * @return A reference to this
110 Handle& operator=(const Handle& rhs);
113 * @copydoc Dali::BaseHandle::operator=
115 using BaseHandle::operator=;
118 * @brief Downcast to a handle.
120 * If not the returned handle is left uninitialized.
121 * @param[in] handle to An object
122 * @return handle or an uninitialized handle
124 static Handle DownCast( BaseHandle handle );
129 * @brief Query whether an handle supports a given capability.
131 * @param[in] capability The queried capability.
132 * @return True if the capability is supported.
134 bool Supports(Capability capability) const;
137 * @brief Query how many properties are provided by an handle.
139 * This may vary between instances of a class, if dynamic properties are supported.
140 * @return The number of properties.
142 unsigned int GetPropertyCount() const;
145 * @brief Query the name of a property.
147 * @pre Property::INVALID_INDEX < index < GetPropertyCount().
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 < GetPropertyCount().
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 * @pre Property::INVALID_INDEX < index < GetPropertyCount().
174 * @param [in] index The index of the property.
175 * @return True if the property is animatable.
177 bool IsPropertyAnimatable(Property::Index index) const;
180 * @brief Query the type of a property.
182 * @pre Property::INVALID_INDEX < index < GetPropertyCount().
183 * @param [in] index The index of the property.
184 * @return The type of the property.
186 Property::Type GetPropertyType(Property::Index index) const;
189 * @brief Set the value of an existing property.
191 * @pre Handle::IsPropertyWritable(index) returns true.
192 * @pre Property::INVALID_INDEX < index < GetPropertyCount().
193 * @pre The property types match i.e. propertyValue.GetType() is equal to GetPropertyType(index).
194 * @param [in] index The index of the property.
195 * @param [in] propertyValue The new value of the property.
197 void SetProperty(Property::Index index, Property::Value propertyValue);
200 * @brief Register a new property.
202 * @pre The handle supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
203 * @pre name is unused i.e. GetPropertyIndex(name) returns PropertyIndex::INVALID.
204 * @param [in] name The name of the property.
205 * @param [in] propertyValue The new value of the property.
206 * @return The index of the property
208 Property::Index RegisterProperty(std::string name, Property::Value propertyValue);
211 * @brief Register a new property.
213 * Properties can be set as non animatable using property attributes.
214 * @pre The handle supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
215 * @pre name is unused i.e. GetPropertyIndex(name) returns PropertyIndex::INVALID.
216 * @param [in] name The name of the property.
217 * @param [in] propertyValue The new value of the property.
218 * @param [in] accessMode The property access mode (writable, animatable etc).
219 * @return The index of the property
221 Property::Index RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode);
224 * @brief Retrieve a property value.
226 * @pre Property::INVALID_INDEX < index < GetPropertyCount().
227 * @param [in] index The index of the property.
228 * @return The property value.
230 Property::Value GetProperty(Property::Index index) const;
233 * @brief Convenience function for obtaining a property of a known type.
235 * @pre Property::INVALID_INDEX < index < GetPropertyCount().
236 * @pre The property types match i.e. PropertyTypes::Get<T>() is equal to GetPropertyType(index).
237 * @param [in] index The index of the property.
238 * @return The property value.
240 template <typename T>
241 T GetProperty(Property::Index index) const
243 Property::Value value = GetProperty(index);
245 return T( value.Get<T>() );
249 * @brief Retrieve all the property indices for this object (including custom properties).
251 * @param[out] indices A container of property indices for this object.
252 * @note the added container is cleared
254 void GetPropertyIndices( Property::IndexContainer& indices ) const;
257 * @brief Add a property notification to this object.
259 * @pre Property::INVALID_INDEX < index < GetPropertyCount().
260 * @param [in] index The index of the property.
261 * @param [in] condition The notification will be triggered when this condition is satisfied.
263 * @return A handle to the newly created PropertyNotification
265 PropertyNotification AddPropertyNotification(Property::Index index,
266 const PropertyCondition& condition);
269 * @brief Add a property notification to this object.
271 * @pre Property::INVALID_INDEX < index < GetPropertyCount().
272 * @param [in] index The index of the property.
273 * @param [in] componentIndex Index to the component of a complex property such as a Vector
274 * @param [in] condition The notification will be triggered when this condition is satisfied.
276 * @return A handle to the newly created PropertyNotification
278 PropertyNotification AddPropertyNotification(Property::Index index,
280 const PropertyCondition& condition);
283 * @brief Remove a property notification from this object.
285 * @param [in] propertyNotification The propertyNotification to be removed.
287 void RemovePropertyNotification(Dali::PropertyNotification propertyNotification);
290 * @brief Remove all property notifications from this object.
292 void RemovePropertyNotifications();
301 #endif // __DALI_HANDLE_H__