License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-core.git] / capi / dali / public-api / object / handle.h
1 #ifndef __DALI_HANDLE_H__
2 #define __DALI_HANDLE_H__
3
4 /*
5  * Copyright (c) 2014 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 /**
22  * @addtogroup CAPI_DALI_OBJECT_MODULE
23  * @{
24  */
25
26 // EXTERNAL INCLUDES
27 #include <string>
28
29 // INTERNAL INCLUDES
30 #include <dali/public-api/common/dali-common.h>
31 #include <dali/public-api/object/base-handle.h>
32 #include <dali/public-api/object/property-types.h>
33 #include <dali/public-api/object/property-value.h>
34 #include <dali/public-api/object/property-notification-declarations.h>
35 #include <dali/public-api/object/ref-object.h>
36
37 namespace Dali DALI_IMPORT_API
38 {
39
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.
50  */
51 class 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 Dali::Handle is intended as a base class.
94    *
95    */
96   virtual ~Handle();
97
98   /**
99    * @brief This copy constructor is required for (smart) pointer semantics.
100    *
101    * @param [in] handle A reference to the copied handle
102    */
103   Handle(const Handle& handle);
104
105   /**
106    * @brief This assignment operator is required for (smart) pointer semantics.
107    *
108    * @param [in] rhs  A reference to the copied handle
109    * @return A reference to this
110    */
111   Handle& operator=(const Handle& rhs);
112
113   /**
114    * @copydoc Dali::BaseHandle::operator=
115    */
116   using BaseHandle::operator=;
117
118   /**
119    * @brief Downcast to a handle.
120    *
121    * If not the returned handle is left uninitialized.
122    * @param[in] handle to An object
123    * @return handle or an uninitialized handle
124    */
125   static Handle DownCast( BaseHandle handle );
126
127 public:
128
129   /**
130    * @brief Query whether an handle supports a given capability.
131    *
132    * @param[in] capability The queried capability.
133    * @return True if the capability is supported.
134    */
135   bool Supports(Capability capability) const;
136
137   /**
138    * @brief Query how many properties are provided by an handle.
139    *
140    * This may vary between instances of a class, if dynamic properties are supported.
141    * @return The number of properties.
142    */
143   unsigned int GetPropertyCount() const;
144
145   /**
146    * @brief Query the name of a property.
147    *
148    * @param [in] index The index of the property.
149    * @return The name of the property.
150    */
151   const std::string& GetPropertyName(Property::Index index) const;
152
153   /**
154    * @brief Query the index of a property.
155    *
156    * @param [in] name The name of the property.
157    * @return The index of the property, or Property::INVALID_INDEX if no property exists with the given name.
158    */
159   Property::Index GetPropertyIndex(std::string name) const;
160
161   /**
162    * @brief Query whether a property can be set using SetProperty().
163    *
164    * @pre Property::INVALID_INDEX < index.
165    * @param [in] index The index of the property.
166    * @return True if the property is writable.
167    */
168   bool IsPropertyWritable(Property::Index index) const;
169
170   /**
171    * @brief Query whether a writable property can be the target of an animation or constraint.
172    *
173    * @param [in] index The index of the property.
174    * @return True if the property is animatable.
175    */
176   bool IsPropertyAnimatable(Property::Index index) const;
177
178   /**
179    * @brief Query whether a property can be used as in input to a constraint.
180    *
181    * @param [in] index The index of the property.
182    * @return True if the property can be used as a constraint input.
183    */
184   bool IsPropertyAConstraintInput(Property::Index index) const;
185
186   /**
187    * @brief Query the type of a property.
188    *
189    * @param [in] index The index of the property.
190    * @return The type of the property.
191    */
192   Property::Type GetPropertyType(Property::Index index) const;
193
194   /**
195    * @brief Set the value of an existing property.
196    *
197    * @pre Handle::IsPropertyWritable(index) returns true.
198    * @pre The property types match i.e. propertyValue.GetType() is equal to GetPropertyType(index).
199    * @param [in] index The index of the property.
200    * @param [in] propertyValue The new value of the property.
201    */
202   void SetProperty(Property::Index index, Property::Value propertyValue);
203
204   /**
205    * @brief Register a new property.
206    *
207    * @pre The handle supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
208    * @pre name is unused i.e. GetPropertyIndex(name) returns PropertyIndex::INVALID.
209    * @param [in] name The name of the property.
210    * @param [in] propertyValue The new value of the property.
211    * @return The index of the property
212    */
213   Property::Index RegisterProperty(std::string name, Property::Value propertyValue);
214
215   /**
216    * @brief Register a new property.
217    *
218    * Properties can be set as non animatable using property attributes.
219    * @pre The handle supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
220    * @pre name is unused i.e. GetPropertyIndex(name) returns PropertyIndex::INVALID.
221    * @param [in] name The name of the property.
222    * @param [in] propertyValue The new value of the property.
223    * @param [in] accessMode The property access mode (writable, animatable etc).
224    * @return The index of the property
225    */
226   Property::Index RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode);
227
228   /**
229    * @brief Retrieve a property value.
230    *
231    * @param [in] index The index of the property.
232    * @return The property value.
233    */
234   Property::Value GetProperty(Property::Index index) const;
235
236   /**
237    * @brief Convenience function for obtaining a property of a known type.
238    *
239    * @pre The property types match i.e. PropertyTypes::Get<T>() is equal to GetPropertyType(index).
240    * @param [in] index The index of the property.
241    * @return The property value.
242    */
243   template <typename T>
244   T GetProperty(Property::Index index) const
245   {
246     Property::Value value = GetProperty(index);
247
248     return T( value.Get<T>() );
249   }
250
251   /**
252    * @brief Retrieve all the property indices for this object (including custom properties).
253    *
254    * @param[out] indices A container of property indices for this object.
255    * @note the added container is cleared
256    */
257   void GetPropertyIndices( Property::IndexContainer& indices ) const;
258
259   /**
260    * @brief Add a property notification to this object.
261    *
262    * @param [in] index The index of the property.
263    * @param [in] condition The notification will be triggered when this condition is satisfied.
264    *
265    * @return A handle to the newly created PropertyNotification
266    */
267   PropertyNotification AddPropertyNotification(Property::Index index,
268                                                const PropertyCondition& condition);
269
270   /**
271    * @brief Add a property notification to this object.
272    *
273    * @param [in] index The index of the property.
274    * @param [in] componentIndex Index to the component of a complex property such as a Vector
275    * @param [in] condition The notification will be triggered when this condition is satisfied.
276    *
277    * @return A handle to the newly created PropertyNotification
278    */
279   PropertyNotification AddPropertyNotification(Property::Index index,
280                                                int componentIndex,
281                                                const PropertyCondition& condition);
282
283   /**
284    * @brief Remove a property notification from this object.
285    *
286    * @param [in] propertyNotification The propertyNotification to be removed.
287    */
288   void RemovePropertyNotification(Dali::PropertyNotification propertyNotification);
289
290   /**
291    * @brief Remove all property notifications from this object.
292    */
293   void RemovePropertyNotifications();
294
295 };
296
297 } // namespace Dali
298
299 /**
300  * @}
301  */
302 #endif // __DALI_HANDLE_H__