2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.Runtime.InteropServices;
20 using System.ComponentModel;
25 /// Issues a notification upon a condition of the property being met.
26 /// See PropertyCondition for available defined conditions.
28 /// <since_tizen> 4 </since_tizen>
29 public class PropertyNotification : BaseHandle
32 private DaliEventHandler<object, NotifyEventArgs> propertyNotificationNotifyEventHandler;
33 private NotifyEventCallbackDelegate propertyNotificationNotifyEventCallbackDelegate;
36 /// Create a instance of PropertyNotification.
38 /// <since_tizen> 4 </since_tizen>
39 public PropertyNotification() : this(Interop.PropertyNotification.NewPropertyNotification(), true)
41 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
45 /// Create a instance of PropertyNotification.
47 /// <since_tizen> 4 </since_tizen>
48 public PropertyNotification(PropertyNotification handle) : this(Interop.PropertyNotification.NewPropertyNotification(PropertyNotification.getCPtr(handle)), true)
50 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
53 internal PropertyNotification(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
57 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
58 private delegate void NotifyEventCallbackDelegate(IntPtr propertyNotification);
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.
64 /// <since_tizen> 4 </since_tizen>
65 public event DaliEventHandler<object, NotifyEventArgs> Notified
69 // Restricted to only one listener
70 if (propertyNotificationNotifyEventHandler == null)
72 propertyNotificationNotifyEventHandler += value;
74 propertyNotificationNotifyEventCallbackDelegate = new NotifyEventCallbackDelegate(OnPropertyNotificationNotify);
75 this.NotifySignal().Connect(propertyNotificationNotifyEventCallbackDelegate);
81 if (propertyNotificationNotifyEventHandler != null)
83 this.NotifySignal().Disconnect(propertyNotificationNotifyEventCallbackDelegate);
86 propertyNotificationNotifyEventHandler -= value;
91 /// Enumeration for description of how to check condition.
93 /// <since_tizen> 3 </since_tizen>
94 public enum NotifyMode
97 /// Don't notify, regardless of result of Condition
99 /// <since_tizen> 3 </since_tizen>
102 /// Notify whenever condition changes from false to true.
104 /// <since_tizen> 3 </since_tizen>
107 /// Notify whenever condition changes from true to false.
109 /// <since_tizen> 3 </since_tizen>
112 /// Notify whenever condition changes (false to true, and true to false)
114 /// <since_tizen> 3 </since_tizen>
119 /// Get property notification from Intptr.<br/>
120 /// This should be internal, please do not use.
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)
126 PropertyNotification ret = new PropertyNotification(cPtr, false);
127 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
132 /// Downcast a PropertyNotification instance.
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)
142 throw new ArgumentNullException(nameof(handle));
144 PropertyNotification ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as PropertyNotification;
145 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
152 /// <param name="rhs">A reference to the copied handle.</param>
153 /// <returns>A reference to this.</returns>
154 internal PropertyNotification Assign(PropertyNotification rhs)
156 PropertyNotification ret = new PropertyNotification(Interop.PropertyNotification.Assign(SwigCPtr, PropertyNotification.getCPtr(rhs)), false);
157 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
162 /// Gets the condition of this notification.
164 /// <returns>The condition is returned.</returns>
165 /// <since_tizen> 4 </since_tizen>
166 public PropertyCondition GetCondition()
168 PropertyCondition ret = new PropertyCondition(Interop.PropertyNotification.GetCondition(SwigCPtr), true);
169 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
174 /// Gets the target handle that this notification is observing.
176 /// <since_tizen> 4 </since_tizen>
177 public Animatable GetTarget()
179 BaseHandle ret = Registry.GetManagedBaseHandleFromNativePtr(Interop.PropertyNotification.GetTarget(SwigCPtr));
180 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
181 return ret as Animatable;
185 /// Gets the target handle's property index that this notification.
187 /// <returns>The target property index.</returns>
188 /// <since_tizen> 4 </since_tizen>
189 public int GetTargetProperty()
191 int ret = Interop.PropertyNotification.GetTargetProperty(SwigCPtr);
192 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
197 /// Sets the Notification mode.
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)
203 Interop.PropertyNotification.SetNotifyMode(SwigCPtr, (int)mode);
204 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
208 /// Retrieves the current Notification mode.
210 /// <returns>Notification mode.</returns>
211 /// <since_tizen> 4 </since_tizen>
212 public PropertyNotification.NotifyMode GetNotifyMode()
214 PropertyNotification.NotifyMode ret = (PropertyNotification.NotifyMode)Interop.PropertyNotification.GetNotifyMode(SwigCPtr);
215 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
223 /// <since_tizen> 4 </since_tizen>
224 public bool GetNotifyResult()
226 bool ret = Interop.PropertyNotification.GetNotifyResult(SwigCPtr);
227 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
232 /// Connects to this signal to be notified when the notification has occurred.
234 /// <returns>A signal object to Connect() with</returns>
235 internal PropertyNotifySignal NotifySignal()
237 PropertyNotifySignal ret = new PropertyNotifySignal(Interop.PropertyNotification.NotifySignal(SwigCPtr), false);
238 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
242 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PropertyNotification obj)
244 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
247 /// This will not be public opened.
248 [EditorBrowsable(EditorBrowsableState.Never)]
249 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
251 Interop.PropertyNotification.DeletePropertyNotification(swigCPtr);
254 // Callback for PropertyNotification NotifySignal
255 private void OnPropertyNotificationNotify(IntPtr propertyNotification)
257 NotifyEventArgs e = new NotifyEventArgs();
258 e.PropertyNotification = GetPropertyNotificationFromPtr(propertyNotification);
260 if (propertyNotificationNotifyEventHandler != null)
262 //here we send all data to user event handlers
263 propertyNotificationNotifyEventHandler(this, e);
268 /// Event arguments that passed via Notify signal
270 /// <since_tizen> 3 </since_tizen>
271 public class NotifyEventArgs : EventArgs
273 private PropertyNotification propertyNotification;
276 /// PropertyNotification - is the PropertyNotification handle that has the notification properties.
278 /// <since_tizen> 3 </since_tizen>
279 public PropertyNotification PropertyNotification
283 return propertyNotification;
287 propertyNotification = value;