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.new_PropertyNotification__SWIG_0(), 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.new_PropertyNotification__SWIG_1(PropertyNotification.getCPtr(handle)), true)
50 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
53 internal PropertyNotification(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.PropertyNotification.PropertyNotification_SWIGUpcast(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
71 // Restricted to only one listener
72 if (_propertyNotificationNotifyEventHandler == null)
74 _propertyNotificationNotifyEventHandler += value;
76 _propertyNotificationNotifyEventCallbackDelegate = new NotifyEventCallbackDelegate(OnPropertyNotificationNotify);
77 this.NotifySignal().Connect(_propertyNotificationNotifyEventCallbackDelegate);
86 if (_propertyNotificationNotifyEventHandler != null)
88 this.NotifySignal().Disconnect(_propertyNotificationNotifyEventCallbackDelegate);
91 _propertyNotificationNotifyEventHandler -= value;
97 /// Enumeration for description of how to check condition.
99 /// <since_tizen> 3 </since_tizen>
100 public enum NotifyMode
103 /// Don't notify, regardless of result of Condition
105 /// <since_tizen> 3 </since_tizen>
108 /// Notify whenever condition changes from false to true.
110 /// <since_tizen> 3 </since_tizen>
113 /// Notify whenever condition changes from true to false.
115 /// <since_tizen> 3 </since_tizen>
118 /// Notify whenever condition changes (false to true, and true to false)
120 /// <since_tizen> 3 </since_tizen>
125 /// Get property notification from Intptr.<br/>
126 /// This should be internal, please do not use.
128 /// <param name="cPtr">An object of IntPtr type.</param>
129 /// <returns>An object of the PropertyNotification type.</returns>
130 /// <since_tizen> 4 </since_tizen>
131 [Obsolete("Deprecated in API6, Will be removed in API9, " +
132 "Please use Notified event instead!" +
133 "IntPtr(native integer pointer) is supposed to be not used in Application!")]
134 [EditorBrowsable(EditorBrowsableState.Never)]
135 public static PropertyNotification GetPropertyNotificationFromPtr(global::System.IntPtr cPtr)
137 PropertyNotification ret = new PropertyNotification(cPtr, false);
138 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
143 /// Downcast a PropertyNotification instance.
145 /// <param name="handle">Handle to an object of BaseHandle type.</param>
146 /// <returns>Handle to an object of the PropertyNotification type.</returns>
147 /// <exception cref="ArgumentNullException"> Thrown when handle is null. </exception>
148 /// <since_tizen> 4 </since_tizen>
149 public static PropertyNotification DownCast(BaseHandle handle)
153 throw new ArgumentNullException(nameof(handle));
155 PropertyNotification ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as PropertyNotification;
156 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
163 /// <param name="rhs">A reference to the copied handle.</param>
164 /// <returns>A reference to this.</returns>
165 /// <since_tizen> 4 </since_tizen>
166 [Obsolete("Deprecated in API6, Will be removed in API9, " +
167 "Please use PropertyNotification() constructor instead!")]
168 [EditorBrowsable(EditorBrowsableState.Never)]
169 public PropertyNotification Assign(PropertyNotification rhs)
171 PropertyNotification ret = new PropertyNotification(Interop.PropertyNotification.PropertyNotification_Assign(swigCPtr, PropertyNotification.getCPtr(rhs)), false);
172 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
177 /// Gets the condition of this notification.
179 /// <returns>The condition is returned.</returns>
180 /// <since_tizen> 4 </since_tizen>
181 public PropertyCondition GetCondition()
183 PropertyCondition ret = new PropertyCondition(Interop.PropertyNotification.PropertyNotification_GetCondition__SWIG_0(swigCPtr), true);
184 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
189 /// Gets the target handle that this notification is observing.
191 /// <since_tizen> 4 </since_tizen>
192 public Animatable GetTarget()
194 BaseHandle ret = Registry.GetManagedBaseHandleFromNativePtr(Interop.PropertyNotification.PropertyNotification_GetTarget(swigCPtr));
195 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
196 return ret as Animatable;
200 /// Gets the target handle's property index that this notification.
202 /// <returns>The target property index.</returns>
203 /// <since_tizen> 4 </since_tizen>
204 public int GetTargetProperty()
206 int ret = Interop.PropertyNotification.PropertyNotification_GetTargetProperty(swigCPtr);
207 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
212 /// Sets the Notification mode.
214 /// <param name="mode">mode Notification mode (Default is PropertyNotification::NotifyOnTrue).</param>
215 /// <since_tizen> 4 </since_tizen>
216 public void SetNotifyMode(PropertyNotification.NotifyMode mode)
218 Interop.PropertyNotification.PropertyNotification_SetNotifyMode(swigCPtr, (int)mode);
219 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223 /// Retrieves the current Notification mode.
225 /// <returns>Notification mode.</returns>
226 /// <since_tizen> 4 </since_tizen>
227 public PropertyNotification.NotifyMode GetNotifyMode()
229 PropertyNotification.NotifyMode ret = (PropertyNotification.NotifyMode)Interop.PropertyNotification.PropertyNotification_GetNotifyMode(swigCPtr);
230 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235 /// Gets the result of the last condition check that caused a signal emit,
236 /// useful when using NotifyOnChanged mode and need to know what it changed to.
238 /// <since_tizen> 4 </since_tizen>
239 public bool GetNotifyResult()
241 bool ret = Interop.PropertyNotification.PropertyNotification_GetNotifyResult(swigCPtr);
242 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
247 /// Connects to this signal to be notified when the notification has occurred.
249 /// <returns>A signal object to Connect() with</returns>
250 /// <since_tizen> 4 </since_tizen>
251 [Obsolete("Deprecated in API6, Will be removed in API9, " +
252 "Please use Notified event instead!")]
253 [EditorBrowsable(EditorBrowsableState.Never)]
254 public PropertyNotifySignal NotifySignal()
256 PropertyNotifySignal ret = new PropertyNotifySignal(Interop.PropertyNotification.PropertyNotification_NotifySignal(swigCPtr), false);
257 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PropertyNotification obj)
263 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
266 /// This will not be public opened.
267 [EditorBrowsable(EditorBrowsableState.Never)]
268 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
270 Interop.PropertyNotification.delete_PropertyNotification(swigCPtr);
273 // Callback for PropertyNotification NotifySignal
274 private void OnPropertyNotificationNotify(IntPtr propertyNotification)
276 NotifyEventArgs e = new NotifyEventArgs();
277 e.PropertyNotification = GetPropertyNotificationFromPtr(propertyNotification);
279 if (_propertyNotificationNotifyEventHandler != null)
281 //here we send all data to user event handlers
282 _propertyNotificationNotifyEventHandler(this, e);
287 /// Event arguments that passed via Notify signal
289 /// <since_tizen> 3 </since_tizen>
290 public class NotifyEventArgs : EventArgs
292 private PropertyNotification _propertyNotification;
295 /// PropertyNotification - is the PropertyNotification handle that has the notification properties.
297 /// <since_tizen> 3 </since_tizen>
298 public PropertyNotification PropertyNotification
302 return _propertyNotification;
306 _propertyNotification = value;