/* * 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 { /// /// Event which is occurred when a property is set /// /// 5 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public event PropertyChangedEventHandler PropertySet; internal void NotifyPropertyChanged([CallerMemberName] String propertyName = "") { PropertySet?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } internal static readonly BindablePropertyKey NavigationPropertyKey = BindableProperty.CreateReadOnly("Navigation", typeof(INavigation), typeof(/*VisualElement*/BaseHandle), default(INavigation)); /// /// Backing store for the Navigation property. /// internal static readonly BindableProperty NavigationProperty = NavigationPropertyKey.BindableProperty; private global::System.Runtime.InteropServices.HandleRef swigCPtr; /// /// swigCMemOwn /// /// 3 protected bool swigCMemOwn; private bool _registerMe; 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. swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.new_BaseHandle__SWIG_2(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. swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.new_BaseHandle__SWIG_2(swigCPtr)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); if (_registerMe) { // Register this instance of BaseHandle in the registry. Registry.Register(this); } } 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.swigCPtr; } //A Flag to check who called Dispose(). (By User or DisposeQueue) private bool isDisposeQueued = false; /// /// A Flat to check if it is already disposed. /// /// 3 protected bool disposed = false; /// /// Dispose. /// /// 3 ~BaseHandle() { if (!isDisposeQueued) { isDisposeQueued = true; DisposeQueue.Instance.Add(this); } } /// /// Dispose. /// /// 3 public void Dispose() { //Throw excpetion if Dispose() is called in separate thread. if (!Window.IsInstalled()) { throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread."); } if (isDisposeQueued) { Dispose(DisposeTypes.Implicit); } else { Dispose(DisposeTypes.Explicit); System.GC.SuppressFinalize(this); } } /// /// 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 != global::System.IntPtr.Zero) { swigCMemOwn = false; NDalicPINVOKE.delete_BaseHandle(swigCPtr); swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } disposed = true; } /// /// 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.HasBody()) { return x; } if (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(); } /// /// Create an instance of BaseHandle. /// /// 3 public BaseHandle() : this(NDalicPINVOKE.new_BaseHandle__SWIG_1()) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Create an instance of BaseHandle. /// /// The BaseHandle instance. /// 3 public BaseHandle(BaseHandle handle) : this(NDalicPINVOKE.new_BaseHandle__SWIG_2(BaseHandle.getCPtr(handle))) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// 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 = NDalicPINVOKE.BaseHandle_DoAction(swigCPtr, 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 = NDalicPINVOKE.BaseHandle_GetTypeName(swigCPtr); 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 = NDalicPINVOKE.BaseHandle_GetTypeInfo(swigCPtr, Tizen.NUI.TypeInfo.getCPtr(info)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Resets the handle. /// /// 3 public void Reset() { NDalicPINVOKE.BaseHandle_Reset(swigCPtr); 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 = NDalicPINVOKE.BaseHandle_EqualTo(swigCPtr, 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 = NDalicPINVOKE.BaseHandle_NotEqualTo(swigCPtr, BaseHandle.getCPtr(rhs)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } internal RefObject GetObjectPtr() { global::System.IntPtr cPtr = NDalicPINVOKE.BaseHandle_GetObjectPtr(swigCPtr); RefObject ret = (cPtr == global::System.IntPtr.Zero) ? null : new RefObject(cPtr, false); 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 (disposed == true) { return false; } bool ret = NDalicPINVOKE.BaseHandle_HasBody(swigCPtr); 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 = NDalicPINVOKE.BaseHandle_IsEqual(swigCPtr, BaseHandle.getCPtr(rhs)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } internal global::System.Runtime.InteropServices.HandleRef GetBaseHandleCPtrHandleRef { get { return swigCPtr; } } /// /// For internal use. /// [EditorBrowsable(EditorBrowsableState.Never)] internal NavigationProxy NavigationProxy { get { return Navigation as NavigationProxy; } } /// /// Gets the navigation. /// internal INavigation Navigation { get { return (INavigation)GetValue(NavigationProperty); } set { SetValue(NavigationPropertyKey, value); } } /// /// 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; } } } }