4713364ff3e4b83ece64794511f984568ee2969c
[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.
158         /// </summary>
159         /// <since_tizen> 4 </since_tizen>
160         public static PropertyNotification GetPropertyNotificationFromPtr(global::System.IntPtr cPtr)
161         {
162             PropertyNotification ret = new PropertyNotification(cPtr, false);
163             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
164             return ret;
165         }
166
167         /// <summary>
168         /// Create a instance of PropertyNotification.
169         /// </summary>
170         /// <since_tizen> 4 </since_tizen>
171         public PropertyNotification() : this(NDalicPINVOKE.new_PropertyNotification__SWIG_0(), true)
172         {
173             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
174         }
175
176         /// <summary>
177         /// Downcast a PropertyNotification instance.
178         /// </summary>
179         /// <since_tizen> 4 </since_tizen>
180         public static PropertyNotification DownCast(BaseHandle handle)
181         {
182             PropertyNotification ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as PropertyNotification;
183             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
184             return ret;
185         }
186
187         /// <summary>
188         /// Create a instance of PropertyNotification.
189         /// </summary>
190         /// <since_tizen> 4 </since_tizen>
191         public PropertyNotification(PropertyNotification handle) : this(NDalicPINVOKE.new_PropertyNotification__SWIG_1(PropertyNotification.getCPtr(handle)), true)
192         {
193             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194         }
195
196         /// <summary>
197         /// Assign.
198         /// </summary>
199         /// <since_tizen> 4 </since_tizen>
200         public PropertyNotification Assign(PropertyNotification rhs)
201         {
202             PropertyNotification ret = new PropertyNotification(NDalicPINVOKE.PropertyNotification_Assign(swigCPtr, PropertyNotification.getCPtr(rhs)), false);
203             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
204             return ret;
205         }
206
207         /// <summary>
208         /// Gets the condition of this notification.
209         /// </summary>
210         /// <since_tizen> 4 </since_tizen>
211         public PropertyCondition GetCondition()
212         {
213             PropertyCondition ret = new PropertyCondition(NDalicPINVOKE.PropertyNotification_GetCondition__SWIG_0(swigCPtr), true);
214             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
215             return ret;
216         }
217
218         /// <summary>
219         /// Gets the target handle that this notification is observing.
220         /// </summary>
221         /// <since_tizen> 4 </since_tizen>
222         public Animatable GetTarget()
223         {
224             Animatable ret = new Animatable(NDalicPINVOKE.PropertyNotification_GetTarget(swigCPtr), true);
225             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
226             return ret;
227         }
228
229         /// <summary>
230         /// Gets the target handle's property index that this notification.
231         /// </summary>
232         /// <since_tizen> 4 </since_tizen>
233         public int GetTargetProperty()
234         {
235             int ret = NDalicPINVOKE.PropertyNotification_GetTargetProperty(swigCPtr);
236             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237             return ret;
238         }
239
240         /// <summary>
241         /// Sets the Notification mode.
242         /// </summary>
243         /// <since_tizen> 4 </since_tizen>
244         public void SetNotifyMode(PropertyNotification.NotifyMode mode)
245         {
246             NDalicPINVOKE.PropertyNotification_SetNotifyMode(swigCPtr, (int)mode);
247             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
248         }
249
250         /// <summary>
251         /// Retrieves the current Notification mode.
252         /// </summary>
253         /// <since_tizen> 4 </since_tizen>
254         public PropertyNotification.NotifyMode GetNotifyMode()
255         {
256             PropertyNotification.NotifyMode ret = (PropertyNotification.NotifyMode)NDalicPINVOKE.PropertyNotification_GetNotifyMode(swigCPtr);
257             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258             return ret;
259         }
260
261         /// <summary>
262         /// Gets the result of the last condition check that caused a signal emit,
263         /// useful when using NotifyOnChanged mode and need to know what it changed to.
264         /// </summary>
265         /// <since_tizen> 4 </since_tizen>
266         public bool GetNotifyResult()
267         {
268             bool ret = NDalicPINVOKE.PropertyNotification_GetNotifyResult(swigCPtr);
269             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
270             return ret;
271         }
272
273         /// <summary>
274         /// Connects to this signal to be notified when the notification has occurred.
275         /// </summary>
276         /// <returns>A signal object to Connect() with</returns>
277         public PropertyNotifySignal NotifySignal()
278         {
279             PropertyNotifySignal ret = new PropertyNotifySignal(NDalicPINVOKE.PropertyNotification_NotifySignal(swigCPtr), false);
280             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281             return ret;
282         }
283
284         /// <summary>
285         /// Enumeration for description of how to check condition.
286         /// </summary>
287         /// <since_tizen> 4 </since_tizen>
288         public enum NotifyMode
289         {
290             /// <summary>
291             /// Don't notify, regardless of result of Condition
292             /// </summary>
293             /// <since_tizen> 3 </since_tizen>
294             Disabled,
295             /// <summary>
296             /// Notify whenever condition changes from false to true.
297             /// </summary>
298             /// <since_tizen> 3 </since_tizen>
299             NotifyOnTrue,
300             /// <summary>
301             /// Notify whenever condition changes from true to false.
302             /// </summary>
303             /// <since_tizen> 3 </since_tizen>
304             NotifyOnFalse,
305             /// <summary>
306             /// Notify whenever condition changes (false to true, and true to false)
307             /// </summary>
308             /// <since_tizen> 3 </since_tizen>
309             NotifyOnChanged
310         }
311
312     }
313
314 }