79ccb0766a1c70d301c4e0aa7f0bab3b3dbf3225
[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) 2019 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
60   /**
61    * RawArgumentContainer provides fast direct access to arguments for condition evaluation.
62    */
63   typedef Dali::Vector<float> RawArgumentContainer;
64
65   /**
66    * Create a new PropertyNotification object.
67    * @param[in] target The target object to inspect
68    * @param[in] componentIndex Index to the component of a complex property such as a Vector
69    * @param[in] condition The condition for this notification.
70    * @return A smart-pointer to the newly allocated PropertyNotification.
71    */
72   static PropertyNotificationPtr New(Property& target,
73                                      int componentIndex,
74                                      const Dali::PropertyCondition& condition);
75
76 public:
77
78   /**
79    * @copydoc Dali::PropertyNotification::NotifySignal()
80    */
81   Dali::PropertyNotifySignalType& NotifySignal();
82
83   /**
84    * Emit the Notify signal
85    */
86   void EmitSignalNotify();
87
88   /**
89    * Enables PropertyNotification
90    */
91   void Enable();
92
93   /**
94    * Disables PropertyNotification
95    */
96   void Disable();
97
98   /**
99    * Sets the result from the property condition test for use by applications that connect to the notification signal
100    *
101    * @param[in] result The result of the property condition test
102    */
103   void SetNotifyResult(bool result);
104
105   /**
106    * @copydoc Dali::PropertyNotification::GetCondition
107    */
108   const Dali::PropertyCondition& GetCondition() const;
109
110   /**
111    * @copydoc Dali::PropertyNotification::GetTarget
112    */
113   Dali::Handle GetTarget() const;
114
115   /**
116    * @copydoc Dali::PropertyNotification::GetTargetProperty
117    */
118   Property::Index GetTargetProperty() const;
119
120   /**
121    * @copydoc Dali::PropertyNotification::SetNotifyMode
122    */
123   void SetNotifyMode( NotifyMode mode );
124
125   /**
126    * @copydoc Dali::PropertyNotification::GetNotifyMode
127    */
128   NotifyMode GetNotifyMode();
129
130   /**
131    * @copydoc Dali::PropertyNotification::GetNotifyResult
132    */
133   bool GetNotifyResult() const;
134
135   /**
136    * Compare the passed sceneObject to the one created by this instance
137    * @param[in] sceneObject The SceneGraph::PropertyNotification pointer to compare
138    * @return true if sceneObject is the same as the one created by this instance
139    */
140    bool CompareSceneObject( const SceneGraph::PropertyNotification* sceneObject );
141
142 protected:
143
144   /**
145    * Construct a new PropertyNotification.
146    * @param[in] updateManager The UpdateManager associated with this PropertyNotification.
147    * @param[in] propertyNotificationManager The property notification manager object.
148    * @param[in] target The target property.
149    * @param[in] componentIndex Index to the component of a complex property such as a Vector
150    * @param[in] condition The condition for this notification.
151    */
152   PropertyNotification(SceneGraph::UpdateManager& updateManager,
153                        PropertyNotificationManager& propertyNotificationManager,
154                        Property& target,
155                        int componentIndex,
156                        const Dali::PropertyCondition& condition);
157
158   /**
159    * Helper to create a scene-graph PropertyNotification
160    */
161   void CreateSceneObject();
162
163   /**
164    * Helper to destroy a scene-graph PropertyNotification
165    */
166   void DestroySceneObject();
167
168   /**
169    * A reference counted object may only be deleted by calling Unreference()
170    */
171   virtual ~PropertyNotification();
172
173 private:
174
175   // Undefined
176   PropertyNotification(const PropertyNotification&);
177
178   // Undefined
179   PropertyNotification& operator=(const PropertyNotification& rhs);
180
181 protected:
182
183   SceneGraph::UpdateManager& mUpdateManager;
184   const SceneGraph::PropertyNotification* mPropertyNotification;
185
186   Dali::PropertyNotifySignalType mNotifySignal;
187
188 private:
189
190   PropertyNotificationManager& mPropertyNotificationManager;  ///< Reference to the property notification manager
191   Object*                      mObject;                       ///< Target object, not owned by PropertyNotification.
192   Property::Index              mObjectPropertyIndex;          ///< Target object's property index of interest.
193   Property::Type               mPropertyType;                 ///< The type of property to evaluate
194   int                          mComponentIndex;               ///< Index to a specific component of a complex property such as a Vector
195   Dali::PropertyCondition      mCondition;                    ///< The PropertyCondition handle.
196   RawArgumentContainer         mRawConditionArgs;             ///< The Raw Condition args. (float type)
197   NotifyMode                   mNotifyMode;                   ///< The current notification mode.
198   bool                         mNotifyResult;                 ///< The result of the last condition check that caused a signal emit
199   bool                         mCompare;                      ///< The flag of comparing previous property's raw value and current.
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