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>
32 namespace Dali DALI_IMPORT_API
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 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 * @copydoc Dali::BaseHandle::operator=
112 using BaseHandle::operator=;
115 * @brief Downcast to a handle.
117 * If not the returned handle is left uninitialized.
118 * @param[in] handle to An object
119 * @return handle or an uninitialized handle
121 static Handle DownCast( BaseHandle handle );
126 * @brief Query whether an handle supports a given capability.
128 * @param[in] capability The queried capability.
129 * @return True if the capability is supported.
131 bool Supports(Capability capability) const;
134 * @brief Query how many properties are provided by an handle.
136 * This may vary between instances of a class, if dynamic properties are supported.
137 * @return The number of properties.
139 unsigned int GetPropertyCount() const;
142 * @brief Query the name of a property.
144 * @param [in] index The index of the property.
145 * @return The name of the property.
147 const std::string& GetPropertyName(Property::Index index) const;
150 * @brief Query the index of a property.
152 * @param [in] name The name of the property.
153 * @return The index of the property, or Property::INVALID_INDEX if no property exists with the given name.
155 Property::Index GetPropertyIndex(std::string name) const;
158 * @brief Query whether a property can be set using SetProperty().
160 * @pre Property::INVALID_INDEX < index.
161 * @param [in] index The index of the property.
162 * @return True if the property is writable.
164 bool IsPropertyWritable(Property::Index index) const;
167 * @brief Query whether a writable property can be the target of an animation or constraint.
169 * @param [in] index The index of the property.
170 * @return True if the property is animatable.
172 bool IsPropertyAnimatable(Property::Index index) const;
175 * @brief Query whether a property can be used as in input to a constraint.
177 * @param [in] index The index of the property.
178 * @return True if the property can be used as a constraint input.
180 bool IsPropertyAConstraintInput(Property::Index index) const;
183 * @brief Query the type of a property.
185 * @param [in] index The index of the property.
186 * @return The type of the property.
188 Property::Type GetPropertyType(Property::Index index) const;
191 * @brief Set the value of an existing property.
193 * @pre Handle::IsPropertyWritable(index) returns true.
194 * @pre The property types match i.e. propertyValue.GetType() is equal to GetPropertyType(index).
195 * @param [in] index The index of the property.
196 * @param [in] propertyValue The new value of the property.
198 void SetProperty(Property::Index index, Property::Value propertyValue);
201 * @brief Register a new property.
203 * @pre The handle supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
204 * @pre name is unused i.e. GetPropertyIndex(name) returns PropertyIndex::INVALID.
205 * @param [in] name The name of the property.
206 * @param [in] propertyValue The new value of the property.
207 * @return The index of the property
209 Property::Index RegisterProperty(std::string name, Property::Value propertyValue);
212 * @brief Register a new property.
214 * Properties can be set as non animatable using property attributes.
215 * @pre The handle supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
216 * @pre name is unused i.e. GetPropertyIndex(name) returns PropertyIndex::INVALID.
217 * @param [in] name The name of the property.
218 * @param [in] propertyValue The new value of the property.
219 * @param [in] accessMode The property access mode (writable, animatable etc).
220 * @return The index of the property
222 Property::Index RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode);
225 * @brief Retrieve a property value.
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 The property types match i.e. PropertyTypes::Get<T>() is equal to GetPropertyType(index).
236 * @param [in] index The index of the property.
237 * @return The property value.
239 template <typename T>
240 T GetProperty(Property::Index index) const
242 Property::Value value = GetProperty(index);
244 return T( value.Get<T>() );
248 * @brief Retrieve all the property indices for this object (including custom properties).
250 * @param[out] indices A container of property indices for this object.
251 * @note the added container is cleared
253 void GetPropertyIndices( Property::IndexContainer& indices ) const;
256 * @brief Add a property notification to this object.
258 * @param [in] index The index of the property.
259 * @param [in] condition The notification will be triggered when this condition is satisfied.
261 * @return A handle to the newly created PropertyNotification
263 PropertyNotification AddPropertyNotification(Property::Index index,
264 const PropertyCondition& condition);
267 * @brief Add a property notification to this object.
269 * @param [in] index The index of the property.
270 * @param [in] componentIndex Index to the component of a complex property such as a Vector
271 * @param [in] condition The notification will be triggered when this condition is satisfied.
273 * @return A handle to the newly created PropertyNotification
275 PropertyNotification AddPropertyNotification(Property::Index index,
277 const PropertyCondition& condition);
280 * @brief Remove a property notification from this object.
282 * @param [in] propertyNotification The propertyNotification to be removed.
284 void RemovePropertyNotification(Dali::PropertyNotification propertyNotification);
287 * @brief Remove all property notifications from this object.
289 void RemovePropertyNotifications();
295 #endif // __DALI_HANDLE_H__