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.
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/object/base-handle.h>
27 #include <dali/public-api/object/property-types.h>
28 #include <dali/public-api/object/property-value.h>
29 #include <dali/public-api/object/property-notification-declarations.h>
30 #include <dali/public-api/object/ref-object.h>
35 class PropertyNotification;
36 class PropertyCondition;
38 namespace Internal DALI_INTERNAL
44 * @brief Dali::Handle is a handle to an internal property owning Dali object.
46 class DALI_IMPORT_API Handle : public BaseHandle
51 * @brief An Handle's capabilities can be queried using Handle::Supports()
56 * @brief Some objects support dynamic property creation at run-time.
58 * New properties are registered by calling RegisterProperty() with an unused property name.
60 DYNAMIC_PROPERTIES = 0x01,
66 * @brief This constructor is used by Dali New() methods.
68 * @param [in] handle A pointer to a newly allocated Dali resource
70 Handle( Dali::Internal::Object* handle );
73 * @brief This constructor provides an uninitialized Dali::Handle.
75 * This should be initialized with a Dali New() method before use.
76 * Methods called on an uninitialized Dali::Handle will assert.
78 * Handle handle; // uninitialized
79 * handle.SomeMethod(); // unsafe! This will assert
81 * handle = SomeClass::New(); // now initialized
82 * handle.SomeMethod(); // safe
88 * @brief Dali::Handle is intended as a base class
90 * This is non-virtual since derived Handle types must not contain data or virtual methods.
95 * @brief This copy constructor is required for (smart) pointer semantics.
97 * @param [in] handle A reference to the copied handle
99 Handle( const Handle& handle );
102 * @brief This assignment operator is required for (smart) pointer semantics.
104 * @param [in] rhs A reference to the copied handle
105 * @return A reference to this
107 Handle& operator=( const Handle& rhs );
110 * @brief Downcast to a handle.
112 * If not the returned handle is left uninitialized.
113 * @param[in] handle to An object
114 * @return handle or an uninitialized handle
116 static Handle DownCast( BaseHandle handle );
121 * @brief Query whether an handle supports a given capability.
123 * @param[in] capability The queried capability.
124 * @return True if the capability is supported.
126 bool Supports( Capability capability ) const;
129 * @brief Query how many properties are provided by an handle.
131 * This may vary between instances of a class, if dynamic properties are supported.
132 * @return The number of properties.
134 unsigned int GetPropertyCount() const;
137 * @brief Query the name of a property.
139 * @param [in] index The index of the property.
140 * @return The name of the property.
142 std::string GetPropertyName( Property::Index index ) const;
145 * @brief Query the index of a property.
146 * Returns the first property index that matches the given name exactly.
148 * @param [in] name The name of the property.
149 * @return The index of the property, or Property::INVALID_INDEX if no property exists with the given name.
151 Property::Index GetPropertyIndex( const std::string& name ) const;
154 * @brief Query whether a property can be set using SetProperty().
156 * @pre Property::INVALID_INDEX < index.
157 * @param [in] index The index of the property.
158 * @return True if the property is writable.
160 bool IsPropertyWritable( Property::Index index ) const;
163 * @brief Query whether a writable property can be the target of an animation or constraint.
165 * @param [in] index The index of the property.
166 * @return True if the property is animatable.
168 bool IsPropertyAnimatable( Property::Index index ) const;
171 * @brief Query whether a property can be used as in input to a constraint.
173 * @param [in] index The index of the property.
174 * @return True if the property can be used as a constraint input.
176 bool IsPropertyAConstraintInput( Property::Index index ) const;
179 * @brief Query the type of a property.
181 * @param [in] index The index of the property.
182 * @return The type of the property.
184 Property::Type GetPropertyType( Property::Index index ) const;
187 * @brief Set the value of an existing property.
189 * Property should be write-able. Setting a read-only property is a no-op.
190 * @pre The property types match i.e. propertyValue.GetType() is equal to GetPropertyType(index).
191 * @param [in] index The index of the property.
192 * @param [in] propertyValue The new value of the property.
194 void SetProperty( Property::Index index, const Property::Value& propertyValue );
197 * @brief Register a new animatable property.
199 * @pre The object supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
200 * Property names are expected to be unique, but this is not enforced.
201 * Property indices are unique to each registered custom property in a given object.
202 * returns Property::INVALID_INDEX if registration failed. This can happen if you try to register
203 * animatable property on an object that does not have scene graph object.
204 * @note Only the following types can be animated:
205 * - Property::BOOLEAN
207 * - Property::INTEGER
208 * - Property::VECTOR2
209 * - Property::VECTOR3
210 * - Property::VECTOR4
211 * - Property::MATRIX3
213 * - Property::ROTATION
214 * @param [in] name The name of the property.
215 * @param [in] propertyValue The new value of the property.
216 * @return The index of the property or Property::INVALID_INDEX if registration failed
218 Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue );
221 * @brief Register a new property.
223 * Properties can be set as non animatable using property attributes.
224 * @pre The handle supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
225 * @pre name is unused i.e. GetPropertyIndex(name) returns PropertyIndex::INVALID.
226 * @note Only the following types can be animated:
227 * - Property::BOOLEAN
229 * - Property::INTEGER
230 * - Property::VECTOR2
231 * - Property::VECTOR3
232 * - Property::VECTOR4
233 * - Property::MATRIX3
235 * - Property::ROTATION
236 * @param [in] name The name of the property.
237 * @param [in] propertyValue The new value of the property.
238 * @param [in] accessMode The property access mode (writable, animatable etc).
239 * @return The index of the property
241 Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode );
244 * @brief Retrieve a property value.
246 * @param [in] index The index of the property.
247 * @return The property value.
249 Property::Value GetProperty( Property::Index index ) const;
252 * @brief Convenience function for obtaining a property of a known type.
254 * @pre The property types match i.e. PropertyTypes::Get<T>() is equal to GetPropertyType(index).
255 * @param [in] index The index of the property.
256 * @return The property value.
258 template <typename T>
259 T GetProperty( Property::Index index ) const
261 Property::Value value = GetProperty(index);
263 return T( value.Get<T>() );
267 * @brief Retrieve all the property indices for this object (including custom properties).
269 * @param[out] indices A container of property indices for this object.
270 * @note the added container is cleared
272 void GetPropertyIndices( Property::IndexContainer& indices ) const;
275 * @brief Add a property notification to this object.
277 * @param [in] index The index of the property.
278 * @param [in] condition The notification will be triggered when this condition is satisfied.
280 * @return A handle to the newly created PropertyNotification
282 PropertyNotification AddPropertyNotification( Property::Index index,
283 const PropertyCondition& condition );
286 * @brief Add a property notification to this object.
288 * @param [in] index The index of the property.
289 * @param [in] componentIndex Index to the component of a complex property such as a Vector
290 * @param [in] condition The notification will be triggered when this condition is satisfied.
292 * @return A handle to the newly created PropertyNotification
294 PropertyNotification AddPropertyNotification( Property::Index index,
296 const PropertyCondition& condition );
299 * @brief Remove a property notification from this object.
301 * @param [in] propertyNotification The propertyNotification to be removed.
303 void RemovePropertyNotification( Dali::PropertyNotification propertyNotification );
306 * @brief Remove all property notifications from this object.
308 void RemovePropertyNotifications();
314 #endif // __DALI_HANDLE_H__