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