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_FRAMEWORK
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 * Dali::Handle is a handle to an internal property owning Dali object.
51 class Handle : public BaseHandle
56 * An Handle's capabilities can be queried using Handle::Supports()
61 * 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 * This constructor is used by Dali New() methods.
71 * @param [in] handle A pointer to a newly allocated Dali resource
73 Handle(Dali::Internal::Object* handle);
76 * This constructor provides an uninitialized Dali::Handle.
77 * This should be initialized with a Dali New() method before use.
78 * Methods called on an uninitialized Dali::Handle will assert.
80 * Handle handle; // uninitialized
81 * handle.SomeMethod(); // unsafe! This will assert
83 * handle = SomeClass::New(); // now initialized
84 * handle.SomeMethod(); // safe
90 * Dali::Handle is intended as a base class
95 * This copy constructor is required for (smart) pointer semantics
96 * @param [in] handle A reference to the copied handle
98 Handle(const Handle& handle);
101 * This assignment operator is required for (smart) pointer semantics
102 * @param [in] rhs A reference to the copied handle
104 Handle& operator=(const Handle& rhs);
107 * @copydoc Dali::BaseHandle::operator=
109 using BaseHandle::operator=;
112 * Downcast to a handle. 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 * Query whether an handle supports a given capability.
122 * @param[in] capability The queried capability.
123 * @return True if the capability is supported.
125 bool Supports(Capability capability) const;
128 * Query how many properties are provided by an handle.
129 * This may vary between instances of a class, if dynamic properties are supported.
130 * @return The number of properties.
132 unsigned int GetPropertyCount() const;
135 * Query the name of a property.
136 * @pre Property::INVALID_INDEX < index < GetPropertyCount().
137 * @param [in] index The index of the property.
138 * @return The name of the property.
140 const std::string& GetPropertyName(Property::Index index) const;
143 * Query the index of a property.
144 * @param [in] name The name of the property.
145 * @return The index of the property, or Property::INVALID_INDEX if no property exists with the given name.
147 Property::Index GetPropertyIndex(std::string name) const;
150 * Query whether a property can be set using SetProperty().
151 * @pre Property::INVALID_INDEX < index < GetPropertyCount().
152 * @param [in] index The index of the property.
153 * @return True if the property is writable.
155 bool IsPropertyWritable(Property::Index index) const;
158 * Query whether a writable property can be the target of an animation or constraint.
159 * @pre Property::INVALID_INDEX < index < GetPropertyCount().
160 * @param [in] index The index of the property.
161 * @return True if the property is animatable.
163 bool IsPropertyAnimatable(Property::Index index) const;
166 * Query the type of a property.
167 * @pre Property::INVALID_INDEX < index < GetPropertyCount().
168 * @param [in] index The index of the property.
169 * @return The type of the property.
171 Property::Type GetPropertyType(Property::Index index) const;
174 * Set the value of an existing property.
175 * @pre Handle::IsPropertyWritable(index) returns true.
176 * @pre Property::INVALID_INDEX < index < GetPropertyCount().
177 * @pre The property types match i.e. propertyValue.GetType() is equal to GetPropertyType(index).
178 * @param [in] index The index of the property.
179 * @param [in] propertyValue The new value of the property.
181 void SetProperty(Property::Index index, Property::Value propertyValue);
184 * Register a new property.
185 * @pre The handle supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
186 * @pre name is unused i.e. GetPropertyIndex(name) returns PropertyIndex::INVALID.
187 * @param [in] name The name of the property.
188 * @param [in] propertyValue The new value of the property.
190 Property::Index RegisterProperty(std::string name, Property::Value propertyValue);
193 * Register a new property.
194 * Properties can be set as non animatable using property attributes.
195 * @pre The handle supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
196 * @pre name is unused i.e. GetPropertyIndex(name) returns PropertyIndex::INVALID.
197 * @param [in] name The name of the property.
198 * @param [in] propertyValue The new value of the property.
199 * @param [in] accessMode The property access mode (writable, animatable etc).
201 Property::Index RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode);
204 * Retrieve a property value.
205 * @pre Property::INVALID_INDEX < index < GetPropertyCount().
206 * @param [in] index The index of the property.
207 * @return The property value.
209 Property::Value GetProperty(Property::Index index) const;
212 * Convenience function for obtaining a property of a known type.
213 * @pre Property::INVALID_INDEX < index < GetPropertyCount().
214 * @pre The property types match i.e. PropertyTypes::Get<T>() is equal to GetPropertyType(index).
215 * @param [in] index The index of the property.
216 * @return The property value.
218 template <typename T>
219 T GetProperty(Property::Index index) const
221 Property::Value value = GetProperty(index);
223 return T( value.Get<T>() );
227 * Add a property notification to this object.
228 * @pre Property::INVALID_INDEX < index < GetPropertyCount().
229 * @param [in] index The index of the property.
230 * @param [in] condition The notification will be triggered when this condition is satisfied.
232 PropertyNotification AddPropertyNotification(Property::Index index,
233 const PropertyCondition& condition);
236 * Remove a property notification from this object.
237 * @param [in] propertyNotification The propertyNotification to be removed.
239 void RemovePropertyNotification(Dali::PropertyNotification propertyNotification);
242 * Remove all property notifications from this object.
244 void RemovePropertyNotifications();
253 #endif // __DALI_HANDLE_H__