[dali_1.0.31] Merge branch 'tizen'
[platform/core/uifw/dali-core.git] / dali / internal / event / common / property-notification-impl.h
1 #ifndef __DALI_INTERNAL_PROPERTY_NOTIFICATION_H__
2 #define __DALI_INTERNAL_PROPERTY_NOTIFICATION_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 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-vector.h>
23 #include <dali/public-api/object/ref-object.h>
24 #include <dali/public-api/object/property-notification.h>
25 #include <dali/internal/event/common/property-conditions-impl.h>
26
27 namespace Dali
28 {
29
30 class PropertyCondition;
31
32 namespace Internal
33 {
34
35 namespace SceneGraph
36 {
37 class PropertyNotification;
38 class UpdateManager;
39 }
40
41 class Actor;
42 class PropertyNotification;
43 class Object;
44 class PropertyNotificationManager;
45
46 typedef IntrusivePtr<PropertyNotification> PropertyNotificationPtr;
47
48 /**
49  * PropertyNotification is a proxy for a SceneGraph::PropertyNotification object.
50  * The UpdateManager owns the PropertyNotification object, but the lifetime of the PropertyNotification is
51  * indirectly controlled by the PropertyNotification.
52  */
53 class PropertyNotification : public BaseObject
54 {
55 public:
56
57   typedef Dali::PropertyNotification::NotifyMode NotifyMode;
58   typedef PropertyCondition::Type ConditionType;
59   typedef PropertyCondition::ArgumentContainer ArgumentContainer;
60
61   /**
62    * RawArgumentContainer provides fast direct access to arguments for condition evaluation.
63    */
64   typedef Dali::Vector<float> RawArgumentContainer;
65
66   /**
67    * Create a new PropertyNotification object.
68    * @param[in] target The target object to inspect
69    * @param[in] componentIndex Index to the component of a complex property such as a Vector
70    * @param[in] condition The condition for this notification.
71    * @return A smart-pointer to the newly allocated PropertyNotification.
72    */
73   static PropertyNotificationPtr New(Property& target,
74                                      int componentIndex,
75                                      const Dali::PropertyCondition& condition);
76
77 public:
78
79   /**
80    * @copydoc Dali::PropertyNotification::NotifySignal()
81    */
82   Dali::PropertyNotifySignalType& NotifySignal();
83
84   /**
85    * Emit the Notify signal
86    */
87   void EmitSignalNotify();
88
89   /**
90    * Enables PropertyNotification
91    */
92   void Enable();
93
94   /**
95    * Disables PropertyNotification
96    */
97   void Disable();
98
99   /**
100    * Sets the result from the property condition test for use by applications that connect to the notification signal
101    *
102    * @param[in] result The result of the property condition test
103    */
104   void SetNotifyResult(bool result);
105
106   /**
107    * @copydoc Dali::PropertyNotification::GetCondition
108    */
109   const Dali::PropertyCondition& GetCondition() const;
110
111   /**
112    * @copydoc Dali::PropertyNotification::GetTarget
113    */
114   Dali::Handle GetTarget() const;
115
116   /**
117    * @copydoc Dali::PropertyNotification::GetTargetProperty
118    */
119   Property::Index GetTargetProperty() const;
120
121   /**
122    * @copydoc Dali::PropertyNotification::SetNotifyMode
123    */
124   void SetNotifyMode( NotifyMode mode );
125
126   /**
127    * @copydoc Dali::PropertyNotification::GetNotifyMode
128    */
129   NotifyMode GetNotifyMode();
130
131   /**
132    * @copydoc Dali::PropertyNotification::GetNotifyResult
133    */
134   bool GetNotifyResult() const;
135
136   /**
137    * Compare the passed sceneObject to the one created by this instance
138    * @param[in] sceneObject The SceneGraph::PropertyNotification pointer to compare
139    * @return true if sceneObject is the same as the one created by this instance
140    */
141    bool CompareSceneObject( const SceneGraph::PropertyNotification* sceneObject );
142
143 protected:
144
145   /**
146    * Construct a new PropertyNotification.
147    * @param[in] updateManager The UpdateManager associated with this PropertyNotification.
148    * @param[in] propertyNotificationManager The property notification manager object.
149    * @param[in] target The target property.
150    * @param[in] componentIndex Index to the component of a complex property such as a Vector
151    * @param[in] condition The condition for this notification.
152    */
153   PropertyNotification(SceneGraph::UpdateManager& updateManager,
154                        PropertyNotificationManager& propertyNotificationManager,
155                        Property& target,
156                        int componentIndex,
157                        const Dali::PropertyCondition& condition);
158
159   /**
160    * Helper to create a scene-graph PropertyNotification
161    */
162   void CreateSceneObject();
163
164   /**
165    * Helper to destroy a scene-graph PropertyNotification
166    */
167   void DestroySceneObject();
168
169   /**
170    * A reference counted object may only be deleted by calling Unreference()
171    */
172   virtual ~PropertyNotification();
173
174 private:
175
176   // Undefined
177   PropertyNotification(const PropertyNotification&);
178
179   // Undefined
180   PropertyNotification& operator=(const PropertyNotification& rhs);
181
182 protected:
183
184   SceneGraph::UpdateManager& mUpdateManager;
185   const SceneGraph::PropertyNotification* mPropertyNotification;
186
187   Dali::PropertyNotifySignalType mNotifySignal;
188
189 private:
190
191   PropertyNotificationManager& mPropertyNotificationManager;  ///< Reference to the property notification manager
192   Object*                      mObject;                       ///< Target object, not owned by PropertyNotification.
193   Property::Index              mObjectPropertyIndex;          ///< Target object's property index of interest.
194   Property::Type               mPropertyType;                 ///< The type of property to evaluate
195   int                          mComponentIndex;               ///< Index to a specific component of a complex property such as a Vector
196   Dali::PropertyCondition      mCondition;                    ///< The PropertyCondition handle.
197   RawArgumentContainer         mRawConditionArgs;             ///< The Raw Condition args. (float type)
198   NotifyMode                   mNotifyMode;                   ///< The current notification mode.
199   bool                         mNotifyResult;                 ///< The result of the last condition check that caused a signal emit
200 };
201
202 } // namespace Internal
203
204 // Helpers for public-api forwarding methods
205
206 inline Internal::PropertyNotification& GetImplementation(Dali::PropertyNotification& pub)
207 {
208   DALI_ASSERT_ALWAYS( pub && "PropertyNotification handle is empty" );
209
210   BaseObject& handle = pub.GetBaseObject();
211
212   return static_cast<Internal::PropertyNotification&>(handle);
213 }
214
215 inline const Internal::PropertyNotification& GetImplementation(const Dali::PropertyNotification& pub)
216 {
217   DALI_ASSERT_ALWAYS( pub && "PropertyNotification handle is empty" );
218
219   const BaseObject& handle = pub.GetBaseObject();
220
221   return static_cast<const Internal::PropertyNotification&>(handle);
222 }
223
224 } // namespace Dali
225
226 #endif // __DALI_INTERNAL_PROPERTY_NOTIFICATION_H__