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 /// <since_tizen> 4 </since_tizen>
148 public static PropertyNotification DownCast(BaseHandle handle)
150 PropertyNotification ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as PropertyNotification;
151 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
158 /// <param name="rhs">A reference to the copied handle.</param>
159 /// <returns>A reference to this.</returns>
160 /// <since_tizen> 4 </since_tizen>
161 [Obsolete("Deprecated in API6, Will be removed in API9, " +
162 "Please use PropertyNotification() constructor instead!")]
163 [EditorBrowsable(EditorBrowsableState.Never)]
164 public PropertyNotification Assign(PropertyNotification rhs)
166 PropertyNotification ret = new PropertyNotification(Interop.PropertyNotification.PropertyNotification_Assign(swigCPtr, PropertyNotification.getCPtr(rhs)), false);
167 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
172 /// Gets the condition of this notification.
174 /// <returns>The condition is returned.</returns>
175 /// <since_tizen> 4 </since_tizen>
176 public PropertyCondition GetCondition()
178 PropertyCondition ret = new PropertyCondition(Interop.PropertyNotification.PropertyNotification_GetCondition__SWIG_0(swigCPtr), true);
179 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
184 /// Gets the target handle that this notification is observing.
186 /// <since_tizen> 4 </since_tizen>
187 public Animatable GetTarget()
189 BaseHandle ret = Registry.GetManagedBaseHandleFromNativePtr(Interop.PropertyNotification.PropertyNotification_GetTarget(swigCPtr));
190 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
191 return ret as Animatable;
195 /// Gets the target handle's property index that this notification.
197 /// <returns>The target property index.</returns>
198 /// <since_tizen> 4 </since_tizen>
199 public int GetTargetProperty()
201 int ret = Interop.PropertyNotification.PropertyNotification_GetTargetProperty(swigCPtr);
202 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
207 /// Sets the Notification mode.
209 /// <param name="mode">mode Notification mode (Default is PropertyNotification::NotifyOnTrue).</param>
210 /// <since_tizen> 4 </since_tizen>
211 public void SetNotifyMode(PropertyNotification.NotifyMode mode)
213 Interop.PropertyNotification.PropertyNotification_SetNotifyMode(swigCPtr, (int)mode);
214 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
218 /// Retrieves the current Notification mode.
220 /// <returns>Notification mode.</returns>
221 /// <since_tizen> 4 </since_tizen>
222 public PropertyNotification.NotifyMode GetNotifyMode()
224 PropertyNotification.NotifyMode ret = (PropertyNotification.NotifyMode)Interop.PropertyNotification.PropertyNotification_GetNotifyMode(swigCPtr);
225 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
230 /// Gets the result of the last condition check that caused a signal emit,
231 /// useful when using NotifyOnChanged mode and need to know what it changed to.
233 /// <since_tizen> 4 </since_tizen>
234 public bool GetNotifyResult()
236 bool ret = Interop.PropertyNotification.PropertyNotification_GetNotifyResult(swigCPtr);
237 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
242 /// Connects to this signal to be notified when the notification has occurred.
244 /// <returns>A signal object to Connect() with</returns>
245 /// <since_tizen> 4 </since_tizen>
246 [Obsolete("Deprecated in API6, Will be removed in API9, " +
247 "Please use Notified event instead!")]
248 [EditorBrowsable(EditorBrowsableState.Never)]
249 public PropertyNotifySignal NotifySignal()
251 PropertyNotifySignal ret = new PropertyNotifySignal(Interop.PropertyNotification.PropertyNotification_NotifySignal(swigCPtr), false);
252 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
256 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PropertyNotification obj)
258 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
261 /// This will not be public opened.
262 [EditorBrowsable(EditorBrowsableState.Never)]
263 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
265 Interop.PropertyNotification.delete_PropertyNotification(swigCPtr);
268 // Callback for PropertyNotification NotifySignal
269 private void OnPropertyNotificationNotify(IntPtr propertyNotification)
271 NotifyEventArgs e = new NotifyEventArgs();
272 e.PropertyNotification = GetPropertyNotificationFromPtr(propertyNotification);
274 if (_propertyNotificationNotifyEventHandler != null)
276 //here we send all data to user event handlers
277 _propertyNotificationNotifyEventHandler(this, e);
282 /// Event arguments that passed via Notify signal
284 /// <since_tizen> 3 </since_tizen>
285 public class NotifyEventArgs : EventArgs
287 private PropertyNotification _propertyNotification;
290 /// PropertyNotification - is the PropertyNotification handle that has the notification properties.
292 /// <since_tizen> 3 </since_tizen>
293 public PropertyNotification PropertyNotification
297 return _propertyNotification;
301 _propertyNotification = value;