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(Interop.PropertyNotification.Upcast(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 /// <since_tizen> 4 </since_tizen>
125 [Obsolete("Deprecated in API6, Will be removed in API9, " +
126 "Please use Notified event instead!" +
127 "IntPtr(native integer pointer) is supposed to be not used in Application!")]
128 [EditorBrowsable(EditorBrowsableState.Never)]
129 public static PropertyNotification GetPropertyNotificationFromPtr(global::System.IntPtr cPtr)
131 PropertyNotification ret = new PropertyNotification(cPtr, false);
132 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
137 /// Downcast a PropertyNotification instance.
139 /// <param name="handle">Handle to an object of BaseHandle type.</param>
140 /// <returns>Handle to an object of the PropertyNotification type.</returns>
141 /// <exception cref="ArgumentNullException"> Thrown when handle is null. </exception>
142 /// <since_tizen> 4 </since_tizen>
143 public static PropertyNotification DownCast(BaseHandle handle)
147 throw new ArgumentNullException(nameof(handle));
149 PropertyNotification ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as PropertyNotification;
150 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
157 /// <param name="rhs">A reference to the copied handle.</param>
158 /// <returns>A reference to this.</returns>
159 /// <since_tizen> 4 </since_tizen>
160 [Obsolete("Deprecated in API6, Will be removed in API9, " +
161 "Please use PropertyNotification() constructor instead!")]
162 [EditorBrowsable(EditorBrowsableState.Never)]
163 public PropertyNotification Assign(PropertyNotification rhs)
165 PropertyNotification ret = new PropertyNotification(Interop.PropertyNotification.Assign(SwigCPtr, PropertyNotification.getCPtr(rhs)), false);
166 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
171 /// Gets the condition of this notification.
173 /// <returns>The condition is returned.</returns>
174 /// <since_tizen> 4 </since_tizen>
175 public PropertyCondition GetCondition()
177 PropertyCondition ret = new PropertyCondition(Interop.PropertyNotification.GetCondition(SwigCPtr), true);
178 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
183 /// Gets the target handle that this notification is observing.
185 /// <since_tizen> 4 </since_tizen>
186 public Animatable GetTarget()
188 BaseHandle ret = Registry.GetManagedBaseHandleFromNativePtr(Interop.PropertyNotification.GetTarget(SwigCPtr));
189 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
190 return ret as Animatable;
194 /// Gets the target handle's property index that this notification.
196 /// <returns>The target property index.</returns>
197 /// <since_tizen> 4 </since_tizen>
198 public int GetTargetProperty()
200 int ret = Interop.PropertyNotification.GetTargetProperty(SwigCPtr);
201 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
206 /// Sets the Notification mode.
208 /// <param name="mode">mode Notification mode (Default is PropertyNotification::NotifyOnTrue).</param>
209 /// <since_tizen> 4 </since_tizen>
210 public void SetNotifyMode(PropertyNotification.NotifyMode mode)
212 Interop.PropertyNotification.SetNotifyMode(SwigCPtr, (int)mode);
213 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
217 /// Retrieves the current Notification mode.
219 /// <returns>Notification mode.</returns>
220 /// <since_tizen> 4 </since_tizen>
221 public PropertyNotification.NotifyMode GetNotifyMode()
223 PropertyNotification.NotifyMode ret = (PropertyNotification.NotifyMode)Interop.PropertyNotification.GetNotifyMode(SwigCPtr);
224 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229 /// Gets the result of the last condition check that caused a signal emit,
230 /// useful when using NotifyOnChanged mode and need to know what it changed to.
232 /// <since_tizen> 4 </since_tizen>
233 public bool GetNotifyResult()
235 bool ret = Interop.PropertyNotification.GetNotifyResult(SwigCPtr);
236 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
241 /// Connects to this signal to be notified when the notification has occurred.
243 /// <returns>A signal object to Connect() with</returns>
244 /// <since_tizen> 4 </since_tizen>
245 [Obsolete("Deprecated in API6, Will be removed in API9, " +
246 "Please use Notified event instead!")]
247 [EditorBrowsable(EditorBrowsableState.Never)]
248 public PropertyNotifySignal NotifySignal()
250 PropertyNotifySignal ret = new PropertyNotifySignal(Interop.PropertyNotification.NotifySignal(SwigCPtr), false);
251 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
255 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PropertyNotification obj)
257 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
260 /// This will not be public opened.
261 [EditorBrowsable(EditorBrowsableState.Never)]
262 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
264 Interop.PropertyNotification.DeletePropertyNotification(swigCPtr);
267 // Callback for PropertyNotification NotifySignal
268 private void OnPropertyNotificationNotify(IntPtr propertyNotification)
270 NotifyEventArgs e = new NotifyEventArgs();
271 e.PropertyNotification = GetPropertyNotificationFromPtr(propertyNotification);
273 if (_propertyNotificationNotifyEventHandler != null)
275 //here we send all data to user event handlers
276 _propertyNotificationNotifyEventHandler(this, e);
281 /// Event arguments that passed via Notify signal
283 /// <since_tizen> 3 </since_tizen>
284 public class NotifyEventArgs : EventArgs
286 private PropertyNotification _propertyNotification;
289 /// PropertyNotification - is the PropertyNotification handle that has the notification properties.
291 /// <since_tizen> 3 </since_tizen>
292 public PropertyNotification PropertyNotification
296 return _propertyNotification;
300 _propertyNotification = value;