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