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