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