Merge "Doxygen grouping" into devel/master
[platform/core/uifw/dali-core.git] / dali / public-api / object / handle.h
1 #ifndef __DALI_HANDLE_H__
2 #define __DALI_HANDLE_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <string>
23
24 // INTERNAL INCLUDES
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>
31
32 namespace Dali
33 {
34 /**
35  * @addtogroup dali-core-object
36  * @{
37  */
38
39 class Constraint;
40 class PropertyNotification;
41 class PropertyCondition;
42
43 namespace Internal DALI_INTERNAL
44 {
45 class Object;
46 }
47
48 /**
49  * @brief Dali::Handle is a handle to an internal property owning Dali object that can have constraints applied to it.
50  */
51 class DALI_IMPORT_API Handle : public BaseHandle
52 {
53 public:
54
55   /**
56    * @brief An Handle's capabilities can be queried using Handle::Supports()
57    */
58   enum Capability
59   {
60     /**
61      * @brief Some objects support dynamic property creation at run-time.
62      *
63      * New properties are registered by calling RegisterProperty() with an unused property name.
64      */
65     DYNAMIC_PROPERTIES = 0x01,
66   };
67
68 public:
69
70   /**
71    * @brief This constructor is used by Dali New() methods.
72    *
73    * @param [in] handle A pointer to a newly allocated Dali resource
74    */
75   Handle( Dali::Internal::Object* handle );
76
77   /**
78    * @brief This constructor provides an uninitialized Dali::Handle.
79    *
80    * This should be initialized with a Dali New() method before use.
81    * Methods called on an uninitialized Dali::Handle will assert.
82    * @code
83    * Handle handle; // uninitialized
84    * handle.SomeMethod(); // unsafe! This will assert
85    *
86    * handle = SomeClass::New(); // now initialized
87    * handle.SomeMethod(); // safe
88    * @endcode
89    */
90   Handle();
91
92   /**
93    * @brief Create a new object.
94    *
95    * @return A handle to a newly allocated object.
96    */
97   static Handle New();
98
99   /**
100    * @brief Dali::Handle is intended as a base class
101    *
102    * This is non-virtual since derived Handle types must not contain data or virtual methods.
103    */
104   ~Handle();
105
106   /**
107    * @brief This copy constructor is required for (smart) pointer semantics.
108    *
109    * @param [in] handle A reference to the copied handle
110    */
111   Handle( const Handle& handle );
112
113   /**
114    * @brief This assignment operator is required for (smart) pointer semantics.
115    *
116    * @param [in] rhs  A reference to the copied handle
117    * @return A reference to this
118    */
119   Handle& operator=( const Handle& rhs );
120
121   /**
122    * @brief Downcast to a handle.
123    *
124    * If not the returned handle is left uninitialized.
125    * @param[in] handle to An object
126    * @return handle or an uninitialized handle
127    */
128   static Handle DownCast( BaseHandle handle );
129
130   /**
131    * @brief Query whether an handle supports a given capability.
132    *
133    * @param[in] capability The queried capability.
134    * @return True if the capability is supported.
135    */
136   bool Supports( Capability capability ) const;
137
138   // Properties
139
140   /**
141    * @brief Query how many properties are provided by an handle.
142    *
143    * This may vary between instances of a class, if dynamic properties are supported.
144    * @return The number of properties.
145    */
146   unsigned int GetPropertyCount() const;
147
148   /**
149    * @brief Query the name of a property.
150    *
151    * @param [in] index The index of the property.
152    * @return The name of the property.
153    */
154   std::string GetPropertyName( Property::Index index ) const;
155
156   /**
157    * @brief Query the index of a property.
158    * Returns the first property index that matches the given name exactly.
159    *
160    * @param [in] name The name of the property.
161    * @return The index of the property, or Property::INVALID_INDEX if no property exists with the given name.
162    */
163   Property::Index GetPropertyIndex( const std::string& name ) const;
164
165   /**
166    * @brief Query whether a property can be set using SetProperty().
167    *
168    * @pre Property::INVALID_INDEX < index.
169    * @param [in] index The index of the property.
170    * @return True if the property is writable.
171    */
172   bool IsPropertyWritable( Property::Index index ) const;
173
174   /**
175    * @brief Query whether a writable property can be the target of an animation or constraint.
176    *
177    * @param [in] index The index of the property.
178    * @return True if the property is animatable.
179    */
180   bool IsPropertyAnimatable( Property::Index index ) const;
181
182   /**
183    * @brief Query whether a property can be used as in input to a constraint.
184    *
185    * @param [in] index The index of the property.
186    * @return True if the property can be used as a constraint input.
187    */
188   bool IsPropertyAConstraintInput( Property::Index index ) const;
189
190   /**
191    * @brief Query the type of a property.
192    *
193    * @param [in] index The index of the property.
194    * @return The type of the property.
195    */
196   Property::Type GetPropertyType( Property::Index index ) const;
197
198   /**
199    * @brief Set the value of an existing property.
200    *
201    * Property should be write-able. Setting a read-only property is a no-op.
202    * @pre The property types match i.e. propertyValue.GetType() is equal to GetPropertyType(index).
203    * @param [in] index The index of the property.
204    * @param [in] propertyValue The new value of the property.
205    */
206   void SetProperty( Property::Index index, const Property::Value& propertyValue );
207
208   /**
209    * @brief Register a new animatable property.
210    *
211    * @pre The object supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
212    * Property names are expected to be unique, but this is not enforced.
213    * Property indices are unique to each registered custom property in a given object.
214    * returns Property::INVALID_INDEX if registration failed. This can happen if you try to register
215    * animatable property on an object that does not have scene graph object.
216    * @note Only the following types can be animated:
217    *       - Property::BOOLEAN
218    *       - Property::FLOAT
219    *       - Property::INTEGER
220    *       - Property::VECTOR2
221    *       - Property::VECTOR3
222    *       - Property::VECTOR4
223    *       - Property::MATRIX3
224    *       - Property::MATRIX
225    *       - Property::ROTATION
226    * @param [in] name The name of the property.
227    * @param [in] propertyValue The new value of the property.
228    * @return The index of the property or Property::INVALID_INDEX if registration failed
229    */
230   Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue );
231
232   /**
233    * @brief Register a new property.
234    *
235    * Properties can be set as non animatable using property attributes.
236    * @pre The handle supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
237    * @pre name is unused i.e. GetPropertyIndex(name) returns PropertyIndex::INVALID.
238    * @note Only the following types can be animated:
239    *       - Property::BOOLEAN
240    *       - Property::FLOAT
241    *       - Property::INTEGER
242    *       - Property::VECTOR2
243    *       - Property::VECTOR3
244    *       - Property::VECTOR4
245    *       - Property::MATRIX3
246    *       - Property::MATRIX
247    *       - Property::ROTATION
248    * @param [in] name The name of the property.
249    * @param [in] propertyValue The new value of the property.
250    * @param [in] accessMode The property access mode (writable, animatable etc).
251    * @return The index of the property
252    */
253   Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode );
254
255   /**
256    * @brief Retrieve a property value.
257    *
258    * @param [in] index The index of the property.
259    * @return The property value.
260    */
261   Property::Value GetProperty( Property::Index index ) const;
262
263   /**
264    * @brief Convenience function for obtaining a property of a known type.
265    *
266    * @pre The property types match i.e. PropertyTypes::Get<T>() is equal to GetPropertyType(index).
267    * @param [in] index The index of the property.
268    * @return The property value.
269    */
270   template <typename T>
271   T GetProperty( Property::Index index ) const
272   {
273     Property::Value value = GetProperty(index);
274
275     return T( value.Get<T>() );
276   }
277
278   /**
279    * @brief Retrieve all the property indices for this object (including custom properties).
280    *
281    * @param[out] indices A container of property indices for this object.
282    * @note the added container is cleared
283    */
284   void GetPropertyIndices( Property::IndexContainer& indices ) const;
285
286   /**
287    * @brief Add a property notification to this object.
288    *
289    * @param [in] index The index of the property.
290    * @param [in] condition The notification will be triggered when this condition is satisfied.
291    *
292    * @return A handle to the newly created PropertyNotification
293    */
294   PropertyNotification AddPropertyNotification( Property::Index index,
295                                                 const PropertyCondition& condition );
296
297   /**
298    * @brief Add a property notification to this object.
299    *
300    * @param [in] index The index of the property.
301    * @param [in] componentIndex Index to the component of a complex property such as a Vector
302    * @param [in] condition The notification will be triggered when this condition is satisfied.
303    *
304    * @return A handle to the newly created PropertyNotification
305    */
306   PropertyNotification AddPropertyNotification( Property::Index index,
307                                                 int componentIndex,
308                                                 const PropertyCondition& condition );
309
310   /**
311    * @brief Remove a property notification from this object.
312    *
313    * @param [in] propertyNotification The propertyNotification to be removed.
314    */
315   void RemovePropertyNotification( Dali::PropertyNotification propertyNotification );
316
317   /**
318    * @brief Remove all property notifications from this object.
319    */
320   void RemovePropertyNotifications();
321
322   // Constraints
323
324   /**
325    * @brief Remove all constraints from an Object.
326    *
327    * @pre The object has been initialized.
328    */
329   void RemoveConstraints();
330
331   /**
332    * @brief Remove all the constraint from the Object with a matching tag.
333    *
334    * @pre The Object has been initialized.
335    * @param[in] tag The tag of the constraints which will be removed
336    */
337   void RemoveConstraints( unsigned int tag );
338
339 };
340
341 namespace WeightObject
342 {
343
344 DALI_IMPORT_API extern const Property::Index WEIGHT; ///< name "weight", type FLOAT
345
346 /**
347  * @brief Convenience function to create an object with a custom "weight" property.
348  *
349  * @return A handle to a newly allocated object.
350  */
351 DALI_IMPORT_API Handle New();
352
353 } // namespace WeightObject
354
355 /**
356  * @}
357  */
358 } // namespace Dali
359
360 #endif // __DALI_HANDLE_H__