/* * Copyright(c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ namespace Tizen.NUI { using System; using System.Runtime.InteropServices; /// /// Issues a notification upon a condition of the property being met. /// See PropertyCondition for available defined conditions. /// public class PropertyNotification : BaseHandle { private global::System.Runtime.InteropServices.HandleRef swigCPtr; internal PropertyNotification(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.PropertyNotification_SWIGUpcast(cPtr), cMemoryOwn) { swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); } internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PropertyNotification obj) { return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; } /// /// Dispose. /// /// 3 protected override void Dispose(DisposeTypes type) { if (disposed) { return; } if (type == DisposeTypes.Explicit) { //Called by User //Release your own managed resources here. //You should release all of your own disposable objects here. } //Release your own unmanaged resources here. //You should not access any managed member here except static instance. //because the execution order of Finalizes is non-deterministic. if (swigCPtr.Handle != global::System.IntPtr.Zero) { if (swigCMemOwn) { swigCMemOwn = false; NDalicPINVOKE.delete_PropertyNotification(swigCPtr); } swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } base.Dispose(type); } /// /// Event arguments that passed via Notify signal /// public class NotifyEventArgs : EventArgs { private PropertyNotification _propertyNotification; /// /// PropertyNotification - is the PropertyNotification handle that has the notification properties. /// /// 4 public PropertyNotification PropertyNotification { get { return _propertyNotification; } set { _propertyNotification = value; } } } [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void NotifyEventCallbackDelegate(IntPtr propertyNotification); private DaliEventHandler _propertyNotificationNotifyEventHandler; private NotifyEventCallbackDelegate _propertyNotificationNotifyEventCallbackDelegate; /// /// Event for Notified signal which can be used to subscribe/unsubscribe the event handler /// Notified signal is emitted when the notification upon a condition of the property being met, has occurred. /// /// 4 public event DaliEventHandler Notified { add { lock (this) { // Restricted to only one listener if (_propertyNotificationNotifyEventHandler == null) { _propertyNotificationNotifyEventHandler += value; _propertyNotificationNotifyEventCallbackDelegate = new NotifyEventCallbackDelegate(OnPropertyNotificationNotify); this.NotifySignal().Connect(_propertyNotificationNotifyEventCallbackDelegate); } } } remove { lock (this) { if (_propertyNotificationNotifyEventHandler != null) { this.NotifySignal().Disconnect(_propertyNotificationNotifyEventCallbackDelegate); } _propertyNotificationNotifyEventHandler -= value; } } } // Callback for PropertyNotification NotifySignal private void OnPropertyNotificationNotify(IntPtr propertyNotification) { NotifyEventArgs e = new NotifyEventArgs(); e.PropertyNotification = GetPropertyNotificationFromPtr(propertyNotification); if (_propertyNotificationNotifyEventHandler != null) { //here we send all data to user event handlers _propertyNotificationNotifyEventHandler(this, e); } } /// /// Get property notification from Intptr.
/// This should be internal, please do not use. ///
/// An object of IntPtr type. /// An object of the PropertyNotification type. /// 4 public static PropertyNotification GetPropertyNotificationFromPtr(global::System.IntPtr cPtr) { PropertyNotification ret = new PropertyNotification(cPtr, false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Create a instance of PropertyNotification. /// /// 4 public PropertyNotification() : this(NDalicPINVOKE.new_PropertyNotification__SWIG_0(), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Downcast a PropertyNotification instance. /// /// Handle to an object of BaseHandle type. /// Handle to an object of the PropertyNotification type. /// 4 public static PropertyNotification DownCast(BaseHandle handle) { PropertyNotification ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as PropertyNotification; if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Create a instance of PropertyNotification. /// /// 4 public PropertyNotification(PropertyNotification handle) : this(NDalicPINVOKE.new_PropertyNotification__SWIG_1(PropertyNotification.getCPtr(handle)), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Assign. /// /// A reference to the copied handle. /// A reference to this. /// 4 public PropertyNotification Assign(PropertyNotification rhs) { PropertyNotification ret = new PropertyNotification(NDalicPINVOKE.PropertyNotification_Assign(swigCPtr, PropertyNotification.getCPtr(rhs)), false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Gets the condition of this notification. /// /// The condition is returned. /// 4 public PropertyCondition GetCondition() { PropertyCondition ret = new PropertyCondition(NDalicPINVOKE.PropertyNotification_GetCondition__SWIG_0(swigCPtr), true); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Gets the target handle that this notification is observing. /// /// 4 public Animatable GetTarget() { Animatable ret = new Animatable(NDalicPINVOKE.PropertyNotification_GetTarget(swigCPtr), true); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Gets the target handle's property index that this notification. /// /// The target property index. /// 4 public int GetTargetProperty() { int ret = NDalicPINVOKE.PropertyNotification_GetTargetProperty(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Sets the Notification mode. /// /// mode Notification mode (Default is PropertyNotification::NotifyOnTrue). /// 4 public void SetNotifyMode(PropertyNotification.NotifyMode mode) { NDalicPINVOKE.PropertyNotification_SetNotifyMode(swigCPtr, (int)mode); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Retrieves the current Notification mode. /// /// Notification mode. /// 4 public PropertyNotification.NotifyMode GetNotifyMode() { PropertyNotification.NotifyMode ret = (PropertyNotification.NotifyMode)NDalicPINVOKE.PropertyNotification_GetNotifyMode(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Gets the result of the last condition check that caused a signal emit, /// useful when using NotifyOnChanged mode and need to know what it changed to. /// /// 4 public bool GetNotifyResult() { bool ret = NDalicPINVOKE.PropertyNotification_GetNotifyResult(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Connects to this signal to be notified when the notification has occurred. /// /// A signal object to Connect() with public PropertyNotifySignal NotifySignal() { PropertyNotifySignal ret = new PropertyNotifySignal(NDalicPINVOKE.PropertyNotification_NotifySignal(swigCPtr), false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Enumeration for description of how to check condition. /// /// 4 public enum NotifyMode { /// /// Don't notify, regardless of result of Condition /// /// 3 Disabled, /// /// Notify whenever condition changes from false to true. /// /// 3 NotifyOnTrue, /// /// Notify whenever condition changes from true to false. /// /// 3 NotifyOnFalse, /// /// Notify whenever condition changes (false to true, and true to false) /// /// 3 NotifyOnChanged } } }