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