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