a8f2386042686a1e60eb1d3574276bd66adce6c4
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / PropertyNotification.cs
1 /*
2  * Copyright(c) 2017 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 namespace Tizen.NUI
19 {
20
21     using System;
22     using System.Runtime.InteropServices;
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         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
32
33         private DaliEventHandler<object, NotifyEventArgs> _propertyNotificationNotifyEventHandler;
34         private NotifyEventCallbackDelegate _propertyNotificationNotifyEventCallbackDelegate;
35
36         /// <summary>
37         /// Create a instance of PropertyNotification.
38         /// </summary>
39         /// <since_tizen> 4 </since_tizen>
40         public PropertyNotification() : this(NDalicPINVOKE.new_PropertyNotification__SWIG_0(), true)
41         {
42             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
43         }
44
45         /// <summary>
46         /// Create a instance of PropertyNotification.
47         /// </summary>
48         /// <since_tizen> 4 </since_tizen>
49         public PropertyNotification(PropertyNotification handle) : this(NDalicPINVOKE.new_PropertyNotification__SWIG_1(PropertyNotification.getCPtr(handle)), true)
50         {
51             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
52         }
53
54         internal PropertyNotification(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.PropertyNotification_SWIGUpcast(cPtr), cMemoryOwn)
55         {
56             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
57         }
58
59         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
60         private delegate void NotifyEventCallbackDelegate(IntPtr propertyNotification);
61
62         ///<summary>
63         /// Event for Notified signal which can be used to subscribe/unsubscribe the event handler
64         /// Notified signal is emitted when the notification upon a condition of the property being met, has occurred.
65         ///</summary>
66         /// <since_tizen> 4 </since_tizen>
67         public event DaliEventHandler<object, NotifyEventArgs> Notified
68         {
69             add
70             {
71                 lock (this)
72                 {
73                     // Restricted to only one listener
74                     if (_propertyNotificationNotifyEventHandler == null)
75                     {
76                         _propertyNotificationNotifyEventHandler += value;
77
78                         _propertyNotificationNotifyEventCallbackDelegate = new NotifyEventCallbackDelegate(OnPropertyNotificationNotify);
79                         this.NotifySignal().Connect(_propertyNotificationNotifyEventCallbackDelegate);
80                     }
81                 }
82             }
83
84             remove
85             {
86                 lock (this)
87                 {
88                     if (_propertyNotificationNotifyEventHandler != null)
89                     {
90                         this.NotifySignal().Disconnect(_propertyNotificationNotifyEventCallbackDelegate);
91                     }
92
93                     _propertyNotificationNotifyEventHandler -= value;
94                 }
95             }
96         }
97
98         /// <summary>
99         /// Enumeration for description of how to check condition.
100         /// </summary>
101         /// <since_tizen> 3 </since_tizen>
102         public enum NotifyMode
103         {
104             /// <summary>
105             /// Don't notify, regardless of result of Condition
106             /// </summary>
107             /// <since_tizen> 3 </since_tizen>
108             Disabled,
109             /// <summary>
110             /// Notify whenever condition changes from false to true.
111             /// </summary>
112             /// <since_tizen> 3 </since_tizen>
113             NotifyOnTrue,
114             /// <summary>
115             /// Notify whenever condition changes from true to false.
116             /// </summary>
117             /// <since_tizen> 3 </since_tizen>
118             NotifyOnFalse,
119             /// <summary>
120             /// Notify whenever condition changes (false to true, and true to false)
121             /// </summary>
122             /// <since_tizen> 3 </since_tizen>
123             NotifyOnChanged
124         }
125
126         /// <summary>
127         /// Get property notification from Intptr.<br/>
128         /// This should be internal, please do not use.
129         /// </summary>
130         /// <param name="cPtr">An object of IntPtr type.</param>
131         /// <returns>An object of the PropertyNotification type.</returns>
132         /// <since_tizen> 4 </since_tizen>
133         public static PropertyNotification GetPropertyNotificationFromPtr(global::System.IntPtr cPtr)
134         {
135             PropertyNotification ret = new PropertyNotification(cPtr, false);
136             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
137             return ret;
138         }
139
140         /// <summary>
141         /// Downcast a PropertyNotification instance.
142         /// </summary>
143         /// <param name="handle">Handle to an object of BaseHandle type.</param>
144         /// <returns>Handle to an object of the PropertyNotification type.</returns>
145         /// <since_tizen> 4 </since_tizen>
146         public static PropertyNotification DownCast(BaseHandle handle)
147         {
148             PropertyNotification ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as PropertyNotification;
149             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
150             return ret;
151         }
152
153         /// <summary>
154         /// Assign.
155         /// </summary>
156         /// <param name="rhs">A reference to the copied handle.</param>
157         /// <returns>A reference to this.</returns>
158         /// <since_tizen> 4 </since_tizen>
159         public PropertyNotification Assign(PropertyNotification rhs)
160         {
161             PropertyNotification ret = new PropertyNotification(NDalicPINVOKE.PropertyNotification_Assign(swigCPtr, PropertyNotification.getCPtr(rhs)), false);
162             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
163             return ret;
164         }
165
166         /// <summary>
167         /// Gets the condition of this notification.
168         /// </summary>
169         /// <returns>The condition is returned.</returns>
170         /// <since_tizen> 4 </since_tizen>
171         public PropertyCondition GetCondition()
172         {
173             PropertyCondition ret = new PropertyCondition(NDalicPINVOKE.PropertyNotification_GetCondition__SWIG_0(swigCPtr), true);
174             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
175             return ret;
176         }
177
178         /// <summary>
179         /// Gets the target handle that this notification is observing.
180         /// </summary>
181         /// <since_tizen> 4 </since_tizen>
182         public Animatable GetTarget()
183         {
184             Animatable ret = new Animatable(NDalicPINVOKE.PropertyNotification_GetTarget(swigCPtr), true);
185             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
186             return ret;
187         }
188
189         /// <summary>
190         /// Gets the target handle's property index that this notification.
191         /// </summary>
192         /// <returns>The target property index.</returns>
193         /// <since_tizen> 4 </since_tizen>
194         public int GetTargetProperty()
195         {
196             int ret = NDalicPINVOKE.PropertyNotification_GetTargetProperty(swigCPtr);
197             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
198             return ret;
199         }
200
201         /// <summary>
202         /// Sets the Notification mode.
203         /// </summary>
204         /// <param name="mode">mode Notification mode (Default is PropertyNotification::NotifyOnTrue).</param>
205         /// <since_tizen> 4 </since_tizen>
206         public void SetNotifyMode(PropertyNotification.NotifyMode mode)
207         {
208             NDalicPINVOKE.PropertyNotification_SetNotifyMode(swigCPtr, (int)mode);
209             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
210         }
211
212         /// <summary>
213         /// Retrieves the current Notification mode.
214         /// </summary>
215         /// <returns>Notification mode.</returns>
216         /// <since_tizen> 4 </since_tizen>
217         public PropertyNotification.NotifyMode GetNotifyMode()
218         {
219             PropertyNotification.NotifyMode ret = (PropertyNotification.NotifyMode)NDalicPINVOKE.PropertyNotification_GetNotifyMode(swigCPtr);
220             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
221             return ret;
222         }
223
224         /// <summary>
225         /// Gets the result of the last condition check that caused a signal emit,
226         /// useful when using NotifyOnChanged mode and need to know what it changed to.
227         /// </summary>
228         /// <since_tizen> 4 </since_tizen>
229         public bool GetNotifyResult()
230         {
231             bool ret = NDalicPINVOKE.PropertyNotification_GetNotifyResult(swigCPtr);
232             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
233             return ret;
234         }
235
236         /// <summary>
237         /// Connects to this signal to be notified when the notification has occurred.
238         /// </summary>
239         /// <returns>A signal object to Connect() with</returns>
240         /// <since_tizen> 4 </since_tizen>
241         public PropertyNotifySignal NotifySignal()
242         {
243             PropertyNotifySignal ret = new PropertyNotifySignal(NDalicPINVOKE.PropertyNotification_NotifySignal(swigCPtr), false);
244             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
245             return ret;
246         }
247
248         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PropertyNotification obj)
249         {
250             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
251         }
252
253         /// <summary>
254         /// Dispose.
255         /// </summary>
256         /// <since_tizen> 4 </since_tizen>
257         protected override void Dispose(DisposeTypes type)
258         {
259             if (disposed)
260             {
261                 return;
262             }
263
264             if (type == DisposeTypes.Explicit)
265             {
266                 //Called by User
267                 //Release your own managed resources here.
268                 //You should release all of your own disposable objects here.
269
270             }
271
272             //Release your own unmanaged resources here.
273             //You should not access any managed member here except static instance.
274             //because the execution order of Finalizes is non-deterministic.
275
276             if (swigCPtr.Handle != global::System.IntPtr.Zero)
277             {
278                 if (swigCMemOwn)
279                 {
280                     swigCMemOwn = false;
281                     NDalicPINVOKE.delete_PropertyNotification(swigCPtr);
282                 }
283                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
284             }
285
286             base.Dispose(type);
287         }
288
289         // Callback for PropertyNotification NotifySignal
290         private void OnPropertyNotificationNotify(IntPtr propertyNotification)
291         {
292             NotifyEventArgs e = new NotifyEventArgs();
293             e.PropertyNotification = GetPropertyNotificationFromPtr(propertyNotification);
294
295             if (_propertyNotificationNotifyEventHandler != null)
296             {
297                 //here we send all data to user event handlers
298                 _propertyNotificationNotifyEventHandler(this, e);
299             }
300         }
301
302         ///<summary>
303         /// Event arguments that passed via Notify signal
304         ///</summary>
305         /// <since_tizen> 3 </since_tizen>
306         public class NotifyEventArgs : EventArgs
307         {
308             private PropertyNotification _propertyNotification;
309
310             ///<summary>
311             /// PropertyNotification - is the PropertyNotification handle that has the notification properties.
312             ///</summary>
313             /// <since_tizen> 3 </since_tizen>
314             public PropertyNotification PropertyNotification
315             {
316                 get
317                 {
318                     return _propertyNotification;
319                 }
320                 set
321                 {
322                     _propertyNotification = value;
323                 }
324             }
325         }
326
327     }
328
329 }