[NUI] Fix comments according to document review
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Common / 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(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                 // Restricted to only one listener
70                 if (propertyNotificationNotifyEventHandler == null)
71                 {
72                     propertyNotificationNotifyEventHandler += value;
73
74                     propertyNotificationNotifyEventCallbackDelegate = new NotifyEventCallbackDelegate(OnPropertyNotificationNotify);
75                     this.NotifySignal().Connect(propertyNotificationNotifyEventCallbackDelegate);
76                 }
77             }
78
79             remove
80             {
81                 if (propertyNotificationNotifyEventHandler != null)
82                 {
83                     this.NotifySignal().Disconnect(propertyNotificationNotifyEventCallbackDelegate);
84                 }
85
86                 propertyNotificationNotifyEventHandler -= value;
87             }
88         }
89
90         /// <summary>
91         /// Enumeration for description of how to check condition.
92         /// </summary>
93         /// <since_tizen> 3 </since_tizen>
94         public enum NotifyMode
95         {
96             /// <summary>
97             /// Don't notify, regardless of result of Condition
98             /// </summary>
99             /// <since_tizen> 3 </since_tizen>
100             Disabled,
101             /// <summary>
102             /// Notify whenever condition changes from false to true.
103             /// </summary>
104             /// <since_tizen> 3 </since_tizen>
105             NotifyOnTrue,
106             /// <summary>
107             /// Notify whenever condition changes from true to false.
108             /// </summary>
109             /// <since_tizen> 3 </since_tizen>
110             NotifyOnFalse,
111             /// <summary>
112             /// Notify whenever condition changes (false to true, and true to false)
113             /// </summary>
114             /// <since_tizen> 3 </since_tizen>
115             NotifyOnChanged
116         }
117
118         /// <summary>
119         /// Get property notification from Intptr.<br/>
120         /// This should be internal, do not use.
121         /// </summary>
122         /// <param name="cPtr">An object of IntPtr type.</param>
123         /// <returns>An object of the PropertyNotification type.</returns>
124         internal static PropertyNotification GetPropertyNotificationFromPtr(global::System.IntPtr cPtr)
125         {
126             PropertyNotification ret = new PropertyNotification(cPtr, false);
127             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
128             return ret;
129         }
130
131         /// <summary>
132         /// Downcast a PropertyNotification instance.
133         /// </summary>
134         /// <param name="handle">Handle to an object of BaseHandle type.</param>
135         /// <returns>Handle to an object of the PropertyNotification type.</returns>
136         /// <exception cref="ArgumentNullException"> Thrown when handle is null. </exception>
137         /// <since_tizen> 4 </since_tizen>
138         public static PropertyNotification DownCast(BaseHandle handle)
139         {
140             if (null == handle)
141             {
142                 throw new ArgumentNullException(nameof(handle));
143             }
144             PropertyNotification ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as PropertyNotification;
145             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
146             return ret;
147         }
148
149         /// <summary>
150         /// Assign.
151         /// </summary>
152         /// <param name="rhs">A reference to the copied handle.</param>
153         /// <returns>A reference to this.</returns>
154         internal PropertyNotification Assign(PropertyNotification rhs)
155         {
156             PropertyNotification ret = new PropertyNotification(Interop.PropertyNotification.Assign(SwigCPtr, PropertyNotification.getCPtr(rhs)), false);
157             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
158             return ret;
159         }
160
161         /// <summary>
162         /// Gets the condition of this notification.
163         /// </summary>
164         /// <returns>The condition is returned.</returns>
165         /// <since_tizen> 4 </since_tizen>
166         public PropertyCondition GetCondition()
167         {
168             PropertyCondition ret = new PropertyCondition(Interop.PropertyNotification.GetCondition(SwigCPtr), true);
169             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
170             return ret;
171         }
172
173         /// <summary>
174         /// Gets the target handle that this notification is observing.
175         /// </summary>
176         /// <since_tizen> 4 </since_tizen>
177         public Animatable GetTarget()
178         {
179             BaseHandle ret = Registry.GetManagedBaseHandleFromNativePtr(Interop.PropertyNotification.GetTarget(SwigCPtr));
180             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
181             return ret as Animatable;
182         }
183
184         /// <summary>
185         /// Gets the target handle's property index that this notification.
186         /// </summary>
187         /// <returns>The target property index.</returns>
188         /// <since_tizen> 4 </since_tizen>
189         public int GetTargetProperty()
190         {
191             int ret = Interop.PropertyNotification.GetTargetProperty(SwigCPtr);
192             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193             return ret;
194         }
195
196         /// <summary>
197         /// Sets the Notification mode.
198         /// </summary>
199         /// <param name="mode">mode Notification mode (Default is PropertyNotification::NotifyOnTrue).</param>
200         /// <since_tizen> 4 </since_tizen>
201         public void SetNotifyMode(PropertyNotification.NotifyMode mode)
202         {
203             Interop.PropertyNotification.SetNotifyMode(SwigCPtr, (int)mode);
204             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
205         }
206
207         /// <summary>
208         /// Retrieves the current Notification mode.
209         /// </summary>
210         /// <returns>Notification mode.</returns>
211         /// <since_tizen> 4 </since_tizen>
212         public PropertyNotification.NotifyMode GetNotifyMode()
213         {
214             PropertyNotification.NotifyMode ret = (PropertyNotification.NotifyMode)Interop.PropertyNotification.GetNotifyMode(SwigCPtr);
215             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
216             return ret;
217         }
218
219         /// <summary>
220         /// Gets the result of the last condition check that caused a signal emit,
221         /// useful when using NotifyOnChanged mode and need to know what it changed to.
222         /// </summary>
223         /// <since_tizen> 4 </since_tizen>
224         public bool GetNotifyResult()
225         {
226             bool ret = Interop.PropertyNotification.GetNotifyResult(SwigCPtr);
227             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
228             return ret;
229         }
230
231         /// <summary>
232         /// Connects to this signal to be notified when the notification has occurred.
233         /// </summary>
234         /// <returns>A signal object to Connect() with</returns>
235         internal PropertyNotifySignal NotifySignal()
236         {
237             PropertyNotifySignal ret = new PropertyNotifySignal(Interop.PropertyNotification.NotifySignal(SwigCPtr), false);
238             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239             return ret;
240         }
241
242         /// This will not be public opened.
243         [EditorBrowsable(EditorBrowsableState.Never)]
244         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
245         {
246             Interop.PropertyNotification.DeletePropertyNotification(swigCPtr);
247         }
248
249         // Callback for PropertyNotification NotifySignal
250         private void OnPropertyNotificationNotify(IntPtr propertyNotification)
251         {
252             NotifyEventArgs e = new NotifyEventArgs();
253             e.PropertyNotification = GetPropertyNotificationFromPtr(propertyNotification);
254
255             if (propertyNotificationNotifyEventHandler != null)
256             {
257                 //here we send all data to user event handlers
258                 propertyNotificationNotifyEventHandler(this, e);
259             }
260         }
261
262         ///<summary>
263         /// Event arguments that passed via Notify signal
264         ///</summary>
265         /// <since_tizen> 3 </since_tizen>
266         public class NotifyEventArgs : EventArgs
267         {
268             private PropertyNotification propertyNotification;
269
270             ///<summary>
271             /// PropertyNotification - is the PropertyNotification handle that has the notification properties.
272             ///</summary>
273             /// <since_tizen> 3 </since_tizen>
274             public PropertyNotification PropertyNotification
275             {
276                 get
277                 {
278                     return propertyNotification;
279                 }
280                 set
281                 {
282                     propertyNotification = value;
283                 }
284             }
285         }
286     }
287 }