/* * 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.ComponentModel; using System.Runtime.CompilerServices; using Tizen.NUI.Binding; using Tizen.NUI.Binding.Internals; namespace Tizen.NUI { /// /// BaseHandle is a handle to an internal Dali resource. /// /// 3 public class BaseHandle : Element, global::System.IDisposable { /// /// swigCMemOwn /// /// 3 protected bool swigCMemOwn; /// /// A flag to check if it is already disposed. /// /// 3 protected bool disposed = false; /// /// swigCPtr. /// /// 6 /// This will not be public opened. [EditorBrowsable(EditorBrowsableState.Never)] protected global::System.Runtime.InteropServices.HandleRef swigCPtr; private global::System.Runtime.InteropServices.HandleRef swigCPtrCopy; private bool _registerMe; //A Flag to check who called Dispose(). (By User or DisposeQueue) private bool isDisposeQueued = false; /// /// Create an instance of BaseHandle. /// /// 3 public BaseHandle() : this(Interop.BaseHandle.NewBaseHandle()) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Create an instance of BaseHandle. /// /// The BaseHandle instance. /// 3 public BaseHandle(BaseHandle handle) : this(Interop.BaseHandle.NewBaseHandle(BaseHandle.getCPtr(handle))) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } internal BaseHandle(global::System.IntPtr cPtr, bool cMemoryOwn) { //to catch derived classes dali native exceptions if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); _registerMe = swigCMemOwn = cMemoryOwn; swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); // using copy constructor to create another native handle so Registry.Unregister works fine. swigCPtrCopy = new global::System.Runtime.InteropServices.HandleRef(this, Interop.BaseHandle.NewBaseHandle(swigCPtr)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); if (_registerMe) { // Register this instance of BaseHandle in the registry. Registry.Register(this); } } internal BaseHandle(global::System.IntPtr cPtr) { _registerMe = swigCMemOwn = true; swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); // using copy constructor to create another native handle so Registry.Unregister works fine. swigCPtrCopy = new global::System.Runtime.InteropServices.HandleRef(this, Interop.BaseHandle.NewBaseHandle(swigCPtr)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); if (_registerMe) { // Register this instance of BaseHandle in the registry. Registry.Register(this); } } /// /// Dispose. /// /// 3 ~BaseHandle() { if (!isDisposeQueued) { isDisposeQueued = true; DisposeQueue.Instance.Add(this); } } /// /// Event when a property is set. /// /// 5 public event PropertyChangedEventHandler PropertySet; internal global::System.Runtime.InteropServices.HandleRef GetBaseHandleCPtrHandleRef { get { return swigCPtrCopy; } } /// /// Returns the bool value true to indicate that an operand is true and returns false otherwise. /// /// 3 public static bool operator true(BaseHandle handle) { // if the C# object is null, return false if (BaseHandle.ReferenceEquals(handle, null)) { return false; } // returns true if the handle has a body, false otherwise return handle.HasBody(); } /// /// Returns the bool false to indicate that an operand is false and returns true otherwise. /// /// 3 public static bool operator false(BaseHandle handle) { // if the C# object is null, return true if (BaseHandle.ReferenceEquals(handle, null)) { return true; } return !handle.HasBody(); } /// /// Explicit conversion from Handle to bool. /// /// 3 public static explicit operator bool(BaseHandle handle) { // if the C# object is null, return false if (BaseHandle.ReferenceEquals(handle, null)) { return false; } // returns true if the handle has a body, false otherwise return handle.HasBody(); } /// /// Equality operator /// /// 3 public static bool operator ==(BaseHandle x, BaseHandle y) { // if the C# objects are the same return true if (BaseHandle.ReferenceEquals(x, y)) { return true; } if (!BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null)) { // drop into native code to see if both handles point to the same body return x.IsEqual(y); } if (BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null)) { if (y.HasBody()) return false; else return true; } if (!BaseHandle.ReferenceEquals(x, null) && BaseHandle.ReferenceEquals(y, null)) { if (x.HasBody()) return false; else return true; } return false; } /// /// Inequality operator. Returns Null if either operand is Null /// /// 3 public static bool operator !=(BaseHandle x, BaseHandle y) { return !(x == y); } /// /// Logical AND operator.
/// It's possible when doing a operator this function (opBitwiseAnd) is never called due to short circuiting.
///
/// 3 public static BaseHandle operator &(BaseHandle x, BaseHandle y) { if (x == y) { return x; } return null; } /// /// Logical OR operator for ||.
/// It's possible when doing a || this function (opBitwiseOr) is never called due to short circuiting.
///
/// 3 public static BaseHandle operator |(BaseHandle x, BaseHandle y) { if (!BaseHandle.ReferenceEquals(x, null) || !BaseHandle.ReferenceEquals(y, null)) { if (x != null && x.HasBody()) { return x; } if (y != null && y.HasBody()) { return y; } return null; } return null; } /// /// Logical ! operator /// /// 3 public static bool operator !(BaseHandle x) { // if the C# object is null, return true if (BaseHandle.ReferenceEquals(x, null)) { return true; } if (x.HasBody()) { return false; } return true; } /// /// Equals /// /// The object should be compared. /// True if equal. /// 5 public override bool Equals(object o) { return base.Equals(o); } /// /// Gets the the hash code of this baseHandle. /// /// The hash code. /// 5 public override int GetHashCode() { return base.GetHashCode(); } /// /// Dispose. /// /// 3 public void Dispose() { //Throw excpetion if Dispose() is called in separate thread. if (!Window.IsInstalled()) { Tizen.Log.Error("NUI", "This API called from separate thread.This API must be called from MainThread."); return; } if (isDisposeQueued) { Dispose(DisposeTypes.Implicit); } else { Dispose(DisposeTypes.Explicit); System.GC.SuppressFinalize(this); } } /// /// Performs an action on this object with the given action name and attributes. /// /// The command for the action. /// The list of attributes for the action. /// The action is performed by the object or not. /// 3 public bool DoAction(string actionName, PropertyMap attributes) { bool ret = Interop.BaseHandle.DoAction(swigCPtrCopy, actionName, PropertyMap.getCPtr(attributes)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Returns the type name for the Handle.
/// Will return an empty string if the typename does not exist. This will happen for types that /// have not registered with type-registry. ///
/// The type name. Empty string if the typename does not exist. /// 3 public string GetTypeName() { string ret = Interop.BaseHandle.GetTypeName(swigCPtrCopy); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Returns the type info for the Handle.
///
/// The type information. /// True If get the type info. /// 3 public bool GetTypeInfo(Tizen.NUI.TypeInfo info) { bool ret = Interop.BaseHandle.GetTypeInfo(swigCPtrCopy, Tizen.NUI.TypeInfo.getCPtr(info)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Resets the handle. /// /// 3 public void Reset() { Interop.BaseHandle.Reset(swigCPtrCopy); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// To check the BaseHandle instance is equal or not. /// /// The baseHandle instance. /// True If equal. /// 3 public bool EqualTo(BaseHandle rhs) { bool ret = Interop.BaseHandle.EqualTo(swigCPtrCopy, BaseHandle.getCPtr(rhs)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// To check the BaseHandle instance is equal or not. /// /// The baseHandle instance. /// True If not equal. /// 3 public bool NotEqualTo(BaseHandle rhs) { bool ret = Interop.BaseHandle.NotEqualTo(swigCPtrCopy, BaseHandle.getCPtr(rhs)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// To check the BaseHandle instance has body or not. /// /// True If the baseHandle instance has body. /// 3 public bool HasBody() { if (swigCPtrCopy.Handle == IntPtr.Zero) { return false; } if (disposed == true) { return false; } bool ret = Interop.BaseHandle.HasBody(swigCPtrCopy); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// To check the BaseHandle instance is equal or not. /// /// The baseHandle instance. /// True If equal. /// 3 public bool IsEqual(BaseHandle rhs) { if (disposed == true) { return false; } bool ret = Interop.BaseHandle.IsEqual(swigCPtrCopy, BaseHandle.getCPtr(rhs)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } internal static global::System.Runtime.InteropServices.HandleRef getCPtr(BaseHandle obj) { return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtrCopy; } internal void NotifyPropertyChanged([CallerMemberName] String propertyName = "") { PropertySet?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } /// /// Dispose. /// /// 3 protected virtual 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. //Unreference this instance from Registry. if (_registerMe) { Registry.Unregister(this); } if (swigCPtr.Handle != IntPtr.Zero) { if (swigCMemOwn) { swigCMemOwn = false; ReleaseSwigCPtr(swigCPtr); } swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } if (swigCPtrCopy.Handle != global::System.IntPtr.Zero) { swigCMemOwn = false; Interop.BaseHandle.DeleteBaseHandle(swigCPtrCopy); swigCPtrCopy = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } disposed = true; } /// /// Release swigCPtr. /// /// 6 /// This will not be public opened. [EditorBrowsable(EditorBrowsableState.Never)] protected virtual void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr) { } /// /// Contains event arguments for the FocusChangeRequested event. /// public class FocusRequestArgs : EventArgs { /// /// Gets or sets a value that indicates the starting focus state of the element for which a focus change is requested. /// public bool Focus { get; set; } /// /// Gets or sets a value that indicates the ending focus state of the element for which a focus change is requested. /// public bool Result { get; set; } } internal global::System.Runtime.InteropServices.HandleRef SwigCPtr { get => swigCPtr; } } }