[NUI] Fixing the emtpy finalizers(CA1821)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / PropertyNotification.cs
1 /*
2  * Copyright(c) 2019 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 using System;
19 using System.Runtime.InteropServices;
20 using System.ComponentModel;
21
22 namespace Tizen.NUI
23 {
24     ///<summary>
25     /// Issues a notification upon a condition of the property being met.
26     /// See PropertyCondition for available defined conditions.
27     ///</summary>
28     /// <since_tizen> 4 </since_tizen>
29     public class PropertyNotification : BaseHandle
30     {
31
32         private DaliEventHandler<object, NotifyEventArgs> _propertyNotificationNotifyEventHandler;
33         private NotifyEventCallbackDelegate _propertyNotificationNotifyEventCallbackDelegate;
34
35         /// <summary>
36         /// Create a instance of PropertyNotification.
37         /// </summary>
38         /// <since_tizen> 4 </since_tizen>
39         public PropertyNotification() : this(Interop.PropertyNotification.NewPropertyNotification(), true)
40         {
41             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
42         }
43
44         /// <summary>
45         /// Create a instance of PropertyNotification.
46         /// </summary>
47         /// <since_tizen> 4 </since_tizen>
48         public PropertyNotification(PropertyNotification handle) : this(Interop.PropertyNotification.NewPropertyNotification(PropertyNotification.getCPtr(handle)), true)
49         {
50             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
51         }
52
53         internal PropertyNotification(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.PropertyNotification.Upcast(cPtr), cMemoryOwn)
54         {
55         }
56
57         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
58         private delegate void NotifyEventCallbackDelegate(IntPtr propertyNotification);
59
60         ///<summary>
61         /// Event for Notified signal which can be used to subscribe/unsubscribe the event handler
62         /// Notified signal is emitted when the notification upon a condition of the property being met, has occurred.
63         ///</summary>
64         /// <since_tizen> 4 </since_tizen>
65         public event DaliEventHandler<object, NotifyEventArgs> Notified
66         {
67             add
68             {
69                 lock (this)
70                 {
71                     // Restricted to only one listener
72                     if (_propertyNotificationNotifyEventHandler == null)
73                     {
74                         _propertyNotificationNotifyEventHandler += value;
75
76                         _propertyNotificationNotifyEventCallbackDelegate = new NotifyEventCallbackDelegate(OnPropertyNotificationNotify);
77                         this.NotifySignal().Connect(_propertyNotificationNotifyEventCallbackDelegate);
78                     }
79                 }
80             }
81
82             remove
83             {
84                 lock (this)
85                 {
86                     if (_propertyNotificationNotifyEventHandler != null)
87                     {
88                         this.NotifySignal().Disconnect(_propertyNotificationNotifyEventCallbackDelegate);
89                     }
90
91                     _propertyNotificationNotifyEventHandler -= value;
92                 }
93             }
94         }
95
96         /// <summary>
97         /// Enumeration for description of how to check condition.
98         /// </summary>
99         /// <since_tizen> 3 </since_tizen>
100         public enum NotifyMode
101         {
102             /// <summary>
103             /// Don't notify, regardless of result of Condition
104             /// </summary>
105             /// <since_tizen> 3 </since_tizen>
106             Disabled,
107             /// <summary>
108             /// Notify whenever condition changes from false to true.
109             /// </summary>
110             /// <since_tizen> 3 </since_tizen>
111             NotifyOnTrue,
112             /// <summary>
113             /// Notify whenever condition changes from true to false.
114             /// </summary>
115             /// <since_tizen> 3 </since_tizen>
116             NotifyOnFalse,
117             /// <summary>
118             /// Notify whenever condition changes (false to true, and true to false)
119             /// </summary>
120             /// <since_tizen> 3 </since_tizen>
121             NotifyOnChanged
122         }
123
124         /// <summary>
125         /// Get property notification from Intptr.<br/>
126         /// This should be internal, please do not use.
127         /// </summary>
128         /// <param name="cPtr">An object of IntPtr type.</param>
129         /// <returns>An object of the PropertyNotification type.</returns>
130         /// <since_tizen> 4 </since_tizen>
131         [Obsolete("Deprecated in API6, Will be removed in API9, " +
132             "Please use Notified event instead!" +
133             "IntPtr(native integer pointer) is supposed to be not used in Application!")]
134         [EditorBrowsable(EditorBrowsableState.Never)]
135         public static PropertyNotification GetPropertyNotificationFromPtr(global::System.IntPtr cPtr)
136         {
137             PropertyNotification ret = new PropertyNotification(cPtr, false);
138             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
139             return ret;
140         }
141
142         /// <summary>
143         /// Downcast a PropertyNotification instance.
144         /// </summary>
145         /// <param name="handle">Handle to an object of BaseHandle type.</param>
146         /// <returns>Handle to an object of the PropertyNotification type.</returns>
147         /// <exception cref="ArgumentNullException"> Thrown when handle is null. </exception>
148         /// <since_tizen> 4 </since_tizen>
149         public static PropertyNotification DownCast(BaseHandle handle)
150         {
151             if (null == handle)
152             {
153                 throw new ArgumentNullException(nameof(handle));
154             }
155             PropertyNotification ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as PropertyNotification;
156             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
157             return ret;
158         }
159
160         /// <summary>
161         /// Assign.
162         /// </summary>
163         /// <param name="rhs">A reference to the copied handle.</param>
164         /// <returns>A reference to this.</returns>
165         /// <since_tizen> 4 </since_tizen>
166         [Obsolete("Deprecated in API6, Will be removed in API9, " +
167             "Please use PropertyNotification() constructor instead!")]
168         [EditorBrowsable(EditorBrowsableState.Never)]
169         public PropertyNotification Assign(PropertyNotification rhs)
170         {
171             PropertyNotification ret = new PropertyNotification(Interop.PropertyNotification.Assign(SwigCPtr, PropertyNotification.getCPtr(rhs)), false);
172             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
173             return ret;
174         }
175
176         /// <summary>
177         /// Gets the condition of this notification.
178         /// </summary>
179         /// <returns>The condition is returned.</returns>
180         /// <since_tizen> 4 </since_tizen>
181         public PropertyCondition GetCondition()
182         {
183             PropertyCondition ret = new PropertyCondition(Interop.PropertyNotification.GetCondition(SwigCPtr), true);
184             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
185             return ret;
186         }
187
188         /// <summary>
189         /// Gets the target handle that this notification is observing.
190         /// </summary>
191         /// <since_tizen> 4 </since_tizen>
192         public Animatable GetTarget()
193         {
194             BaseHandle ret = Registry.GetManagedBaseHandleFromNativePtr(Interop.PropertyNotification.GetTarget(SwigCPtr));
195             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
196             return ret as Animatable;
197         }
198
199         /// <summary>
200         /// Gets the target handle's property index that this notification.
201         /// </summary>
202         /// <returns>The target property index.</returns>
203         /// <since_tizen> 4 </since_tizen>
204         public int GetTargetProperty()
205         {
206             int ret = Interop.PropertyNotification.GetTargetProperty(SwigCPtr);
207             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
208             return ret;
209         }
210
211         /// <summary>
212         /// Sets the Notification mode.
213         /// </summary>
214         /// <param name="mode">mode Notification mode (Default is PropertyNotification::NotifyOnTrue).</param>
215         /// <since_tizen> 4 </since_tizen>
216         public void SetNotifyMode(PropertyNotification.NotifyMode mode)
217         {
218             Interop.PropertyNotification.SetNotifyMode(SwigCPtr, (int)mode);
219             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
220         }
221
222         /// <summary>
223         /// Retrieves the current Notification mode.
224         /// </summary>
225         /// <returns>Notification mode.</returns>
226         /// <since_tizen> 4 </since_tizen>
227         public PropertyNotification.NotifyMode GetNotifyMode()
228         {
229             PropertyNotification.NotifyMode ret = (PropertyNotification.NotifyMode)Interop.PropertyNotification.GetNotifyMode(SwigCPtr);
230             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
231             return ret;
232         }
233
234         /// <summary>
235         /// Gets the result of the last condition check that caused a signal emit,
236         /// useful when using NotifyOnChanged mode and need to know what it changed to.
237         /// </summary>
238         /// <since_tizen> 4 </since_tizen>
239         public bool GetNotifyResult()
240         {
241             bool ret = Interop.PropertyNotification.GetNotifyResult(SwigCPtr);
242             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
243             return ret;
244         }
245
246         /// <summary>
247         /// Connects to this signal to be notified when the notification has occurred.
248         /// </summary>
249         /// <returns>A signal object to Connect() with</returns>
250         /// <since_tizen> 4 </since_tizen>
251         [Obsolete("Deprecated in API6, Will be removed in API9, " +
252             "Please use Notified event instead!")]
253         [EditorBrowsable(EditorBrowsableState.Never)]
254         public PropertyNotifySignal NotifySignal()
255         {
256             PropertyNotifySignal ret = new PropertyNotifySignal(Interop.PropertyNotification.NotifySignal(SwigCPtr), false);
257             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258             return ret;
259         }
260
261         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PropertyNotification obj)
262         {
263             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
264         }
265
266         /// This will not be public opened.
267         [EditorBrowsable(EditorBrowsableState.Never)]
268         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
269         {
270             Interop.PropertyNotification.DeletePropertyNotification(swigCPtr);
271         }
272
273         // Callback for PropertyNotification NotifySignal
274         private void OnPropertyNotificationNotify(IntPtr propertyNotification)
275         {
276             NotifyEventArgs e = new NotifyEventArgs();
277             e.PropertyNotification = GetPropertyNotificationFromPtr(propertyNotification);
278
279             if (_propertyNotificationNotifyEventHandler != null)
280             {
281                 //here we send all data to user event handlers
282                 _propertyNotificationNotifyEventHandler(this, e);
283             }
284         }
285
286         ///<summary>
287         /// Event arguments that passed via Notify signal
288         ///</summary>
289         /// <since_tizen> 3 </since_tizen>
290         public class NotifyEventArgs : EventArgs
291         {
292             private PropertyNotification _propertyNotification;
293
294             ///<summary>
295             /// PropertyNotification - is the PropertyNotification handle that has the notification properties.
296             ///</summary>
297             /// <since_tizen> 3 </since_tizen>
298             public PropertyNotification PropertyNotification
299             {
300                 get
301                 {
302                     return _propertyNotification;
303                 }
304                 set
305                 {
306                     _propertyNotification = value;
307                 }
308             }
309         }
310     }
311 }