/*
* 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.
*
*/
using System;
using System.Runtime.InteropServices;
using System.ComponentModel;
namespace Tizen.NUI
{
///
/// Issues a notification upon a condition of the property being met.
/// See PropertyCondition for available defined conditions.
///
/// 4
public class PropertyNotification : BaseHandle
{
private global::System.Runtime.InteropServices.HandleRef swigCPtr;
private DaliEventHandler _propertyNotificationNotifyEventHandler;
private NotifyEventCallbackDelegate _propertyNotificationNotifyEventCallbackDelegate;
///
/// Create a instance of PropertyNotification.
///
/// 4
public PropertyNotification() : this(Interop.PropertyNotification.new_PropertyNotification__SWIG_0(), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Create a instance of PropertyNotification.
///
/// 4
public PropertyNotification(PropertyNotification handle) : this(Interop.PropertyNotification.new_PropertyNotification__SWIG_1(PropertyNotification.getCPtr(handle)), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
internal PropertyNotification(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.PropertyNotification.PropertyNotification_SWIGUpcast(cPtr), cMemoryOwn)
{
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
}
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void NotifyEventCallbackDelegate(IntPtr propertyNotification);
///
/// 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;
}
}
}
///
/// Enumeration for description of how to check condition.
///
/// 3
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
}
///
/// 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
[Obsolete("Deprecated in API6, Will be removed in API9, " +
"Please use Notified event instead!" +
"IntPtr(native integer pointer) is supposed to be not used in Application!")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static PropertyNotification GetPropertyNotificationFromPtr(global::System.IntPtr cPtr)
{
PropertyNotification ret = new PropertyNotification(cPtr, false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// 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;
}
///
/// Assign.
///
/// A reference to the copied handle.
/// A reference to this.
/// 4
[Obsolete("Deprecated in API6, Will be removed in API9, " +
"Please use PropertyNotification() constructor instead!")]
[EditorBrowsable(EditorBrowsableState.Never)]
public PropertyNotification Assign(PropertyNotification rhs)
{
PropertyNotification ret = new PropertyNotification(Interop.PropertyNotification.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(Interop.PropertyNotification.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(Interop.PropertyNotification.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 = Interop.PropertyNotification.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)
{
Interop.PropertyNotification.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)Interop.PropertyNotification.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 = Interop.PropertyNotification.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
/// 4
[Obsolete("Deprecated in API6, Will be removed in API9, " +
"Please use Notified event instead!")]
[EditorBrowsable(EditorBrowsableState.Never)]
public PropertyNotifySignal NotifySignal()
{
PropertyNotifySignal ret = new PropertyNotifySignal(Interop.PropertyNotification.PropertyNotification_NotifySignal(swigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
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.
///
/// 4
protected override void Dispose(DisposeTypes type)
{
if (disposed)
{
return;
}
//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;
Interop.PropertyNotification.delete_PropertyNotification(swigCPtr);
}
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
}
base.Dispose(type);
}
// 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);
}
}
///
/// Event arguments that passed via Notify signal
///
/// 3
public class NotifyEventArgs : EventArgs
{
private PropertyNotification _propertyNotification;
///
/// PropertyNotification - is the PropertyNotification handle that has the notification properties.
///
/// 3
public PropertyNotification PropertyNotification
{
get
{
return _propertyNotification;
}
set
{
_propertyNotification = value;
}
}
}
}
}