[NUI] remove "_" and refactoring naming to pascal case.
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Size2D.cs
index 6512742..b9ce5a6 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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.
@@ -15,7 +15,9 @@
  *
  */
 using System;
+using System.ComponentModel;
 using Tizen.NUI.Binding;
+using System;
 
 namespace Tizen.NUI
 {
@@ -24,32 +26,24 @@ namespace Tizen.NUI
     /// </summary>
     /// <since_tizen> 3 </since_tizen>
     [Tizen.NUI.Binding.TypeConverter(typeof(Size2DTypeConverter))]
-    public class Size2D : global::System.IDisposable
+    public class Size2D : Disposable, ICloneable
     {
-        /// <summary>
-        /// swigCMemOwn
-        /// </summary>
-        /// <since_tizen> 3 </since_tizen>
-        protected bool swigCMemOwn;
-
-        /// <summary>
-        /// A Flat to check if it is already disposed.
-        /// </summary>
-        /// <since_tizen> 3 </since_tizen>
-        protected bool disposed = false;
-
-        private global::System.Runtime.InteropServices.HandleRef swigCPtr;
-
-        //A Flag to check who called Dispose(). (By User or DisposeQueue)
-        private bool isDisposeQueued = false;
 
         private Size2DChangedCallback callback = null;
 
         /// <summary>
         /// The constructor.
         /// </summary>
+        /// <remarks>
+        /// Size2D and Size are implicitly converted to each other, so these are compatible and can be replaced without any type casting. <br />
+        /// For example, the followings are possible. <br />
+        /// view.Size2D = new Size(10.0f, 10.0f, 10.0f); // be aware that here the depth value(10.0f) will be lost. <br />
+        /// view.Size = new Size2D(10, 10); // be aware that here the depth value is 0.0f by default. <br />
+        /// view.MinimumSize = new Size(10, 10, 0); <br />
+        /// Size Tmp = view.MaximumSize; //here Tmp.Depth will be 0.0f. <br />
+        /// </remarks>
         /// <since_tizen> 3 </since_tizen>
-        public Size2D() : this(Interop.Vector2.new_Vector2__SWIG_0(), true)
+        public Size2D() : this(Interop.Vector2.NewVector2(), true)
         {
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
@@ -57,45 +51,53 @@ namespace Tizen.NUI
         /// <summary>
         /// The constructor.
         /// </summary>
-        /// <param name="x">The x (or width) component.</param>
-        /// <param name="y">The y (or height) component.</param>
+        /// <param name="width">The width component.</param>
+        /// <param name="height">The height component.</param>
+        /// <remarks>
+        /// Size2D and Size are implicitly converted to each other, so these are compatible and can be replaced without any type casting. <br />
+        /// For example, the followings are possible. <br />
+        /// view.Size2D = new Size(10.0f, 10.0f, 10.0f); // be aware that here the depth value(10.0f) will be lost. <br />
+        /// view.Size = new Size2D(10, 10); // be aware that here the depth value is 0.0f by default. <br />
+        /// view.MinimumSize = new Size(10, 10, 0); <br />
+        /// Size Tmp = view.MaximumSize; //here Tmp.Depth will be 0.0f. <br />
+        /// </remarks>
         /// <since_tizen> 3 </since_tizen>
-        public Size2D(int x, int y) : this(Interop.Vector2.new_Vector2__SWIG_1((float)x, (float)y), true)
+        public Size2D(int width, int height) : this(Interop.Vector2.NewVector2((float)width, (float)height), true)
         {
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
-        /// <summary>
-        /// Dispose.
-        /// </summary>
-        /// <since_tizen> 3 </since_tizen>
-        ~Size2D()
-        {
-            if (!isDisposeQueued)
-            {
-                isDisposeQueued = true;
-                DisposeQueue.Instance.Add(this);
-            }
-        }
-
-        internal delegate void Size2DChangedCallback(int width, int height);
+        internal delegate void Size2DChangedCallback(int? width, int? height);
 
         /// <summary>
         /// The property for the width component of a size.
         /// </summary>
+        /// <remarks>
+        /// The setter is deprecated in API8 and will be removed in API10. Please use new Size2D(...) constructor.
+        /// </remarks>
+        /// <code>
+        /// // DO NOT use like the followings!
+        /// Size2D size2d = new Size2D();
+        /// size2d.Width = 1; 
+        /// // Please USE like this
+        /// int width = 1, height = 2;
+        /// Size2D size2d = new Size2D(width, height);
+        /// </code>
         /// <since_tizen> 3 </since_tizen>
         public int Width
         {
             set
             {
-                Interop.Vector2.Vector2_Width_set(swigCPtr, (float)value);
+                Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size2D(...) constructor");
+
+                Interop.Vector2.WidthSet(swigCPtr, (float)value);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
-                callback?.Invoke(Width, Height);
+                callback?.Invoke(value, null);
             }
             get
             {
-                float ret = Interop.Vector2.Vector2_Width_get(swigCPtr);
+                float ret = Interop.Vector2.WidthGet(swigCPtr);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                 return (int)ret;
             }
@@ -104,19 +106,32 @@ namespace Tizen.NUI
         /// <summary>
         /// The property for the height component of a size.
         /// </summary>
+        /// <remarks>
+        /// The setter is deprecated in API8 and will be removed in API10. Please use new Size2D(...) constructor.
+        /// </remarks>
+        /// <code>
+        /// // DO NOT use like the followings!
+        /// Size2D size2d = new Size2D();
+        /// size2d.Height = 2; 
+        /// // Please USE like this
+        /// int width = 1, height = 2;
+        /// Size2D size2d = new Size2D(width, height);
+        /// </code>
         /// <since_tizen> 3 </since_tizen>
         public int Height
         {
             set
             {
-                Interop.Vector2.Vector2_Height_set(swigCPtr, (float)value);
+                Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size2D(...) constructor");
+
+                Interop.Vector2.HeightSet(swigCPtr, (float)value);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
-                callback?.Invoke(Width, Height);
+                callback?.Invoke(null, value);
             }
             get
             {
-                float ret = Interop.Vector2.Vector2_Height_get(swigCPtr);
+                float ret = Interop.Vector2.HeightGet(swigCPtr);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                 return (int)ret;
             }
@@ -131,7 +146,7 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public static Size2D operator +(Size2D arg1, Size2D arg2)
         {
-            return arg1.Add(arg2);
+            return arg1?.Add(arg2);
         }
 
         /// <summary>
@@ -143,7 +158,7 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public static Size2D operator -(Size2D arg1, Size2D arg2)
         {
-            return arg1.Subtract(arg2);
+            return arg1?.Subtract(arg2);
         }
 
         /// <summary>
@@ -154,7 +169,7 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public static Size2D operator -(Size2D arg1)
         {
-            return arg1.Subtract();
+            return arg1?.Subtract();
         }
 
         /// <summary>
@@ -166,7 +181,7 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public static Size2D operator *(Size2D arg1, Size2D arg2)
         {
-            return arg1.Multiply(arg2);
+            return arg1?.Multiply(arg2);
         }
 
         /// <summary>
@@ -179,7 +194,7 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public static Size2D operator *(Size2D arg1, int arg2)
         {
-            return arg1.Multiply(arg2);
+            return arg1?.Multiply(arg2);
         }
 
         /// <summary>
@@ -191,7 +206,7 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public static Size2D operator /(Size2D arg1, Size2D arg2)
         {
-            return arg1.Divide(arg2);
+            return arg1?.Divide(arg2);
         }
 
         /// <summary>
@@ -203,7 +218,7 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public static Size2D operator /(Size2D arg1, int arg2)
         {
-            return arg1.Divide(arg2);
+            return arg1?.Divide(arg2);
         }
 
         /// <summary>
@@ -214,7 +229,7 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public static implicit operator Vector2(Size2D size)
         {
-            return new Vector2((float)size.Width, (float)size.Height);
+            return new Vector2((float)size?.Width, (float)size.Height);
         }
 
         /// <summary>
@@ -225,10 +240,23 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public static implicit operator Size2D(Vector2 vector2)
         {
-            return new Size2D((int)vector2.X, (int)vector2.Y);
+            return new Size2D((int)vector2?.X, (int)vector2.Y);
         }
 
         /// <summary>
+        /// Implicit type cast operator, Size to Size2D
+        /// </summary>
+        /// <param name="size">The object of Size type.</param>
+        /// <since_tizen> none </since_tizen>
+        /// This will be public opened in tizen_next by ACR.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static implicit operator Size2D(Size size)
+        {
+            return new Size2D((int)size?.Width, (int)size.Height);
+        }
+
+
+        /// <summary>
         /// The array subscript operator.
         /// </summary>
         /// <param name="index">The subscript index.</param>
@@ -243,29 +271,6 @@ namespace Tizen.NUI
         }
 
         /// <summary>
-        /// Dispose.
-        /// </summary>
-        /// <since_tizen> 3 </since_tizen>
-        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);
-            }
-        }
-
-        /// <summary>
         /// Determines whether the specified object is equal to the current object.
         /// </summary>
         /// <param name="obj">The object to compare with the current object.</param>
@@ -300,7 +305,7 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public bool EqualTo(Size2D rhs)
         {
-            bool ret = Interop.Vector2.Vector2_EqualTo(swigCPtr, Size2D.getCPtr(rhs));
+            bool ret = Interop.Vector2.EqualTo(swigCPtr, Size2D.getCPtr(rhs));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -314,11 +319,15 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public bool NotEqualTo(Size2D rhs)
         {
-            bool ret = Interop.Vector2.Vector2_NotEqualTo(swigCPtr, Size2D.getCPtr(rhs));
+            bool ret = Interop.Vector2.NotEqualTo(swigCPtr, Size2D.getCPtr(rhs));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
+        /// <inheritdoc/>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public object Clone() => new Size2D(Width, Height);
+
         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size2D obj)
         {
             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
@@ -336,104 +345,75 @@ namespace Tizen.NUI
             return ret;
         }
 
-        internal Size2D(Size2DChangedCallback cb, int x, int y) : this(Interop.Vector2.new_Vector2__SWIG_1((float)x, (float)y), true)
+        internal Size2D(Size2DChangedCallback cb, int x, int y) : this(Interop.Vector2.NewVector2((float)x, (float)y), true)
         {
             callback = cb;
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
-        internal Size2D(global::System.IntPtr cPtr, bool cMemoryOwn)
+        internal Size2D(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
         {
-            swigCMemOwn = cMemoryOwn;
-            swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
         }
 
-        /// <summary>
-        /// Dispose.
-        /// </summary>
-        /// <since_tizen> 3 </since_tizen>
-        protected virtual void Dispose(DisposeTypes type)
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
         {
-            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;
-                    Interop.Vector2.delete_Vector2(swigCPtr);
-                }
-                swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
-            }
-            disposed = true;
+            Interop.Vector2.DeleteVector2(swigCPtr);
         }
 
         private Size2D Add(Size2D rhs)
         {
-            Size2D ret = new Size2D(Interop.Vector2.Vector2_Add(swigCPtr, Size2D.getCPtr(rhs)), true);
+            Size2D ret = new Size2D(Interop.Vector2.Add(swigCPtr, Size2D.getCPtr(rhs)), true);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
         private Size2D Subtract(Size2D rhs)
         {
-            Size2D ret = new Size2D(Interop.Vector2.Vector2_Subtract__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
+            Size2D ret = new Size2D(Interop.Vector2.Subtract(swigCPtr, Size2D.getCPtr(rhs)), true);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
         private Size2D Multiply(Size2D rhs)
         {
-            Size2D ret = new Size2D(Interop.Vector2.Vector2_Multiply__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
+            Size2D ret = new Size2D(Interop.Vector2.Multiply(swigCPtr, Size2D.getCPtr(rhs)), true);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
         private Size2D Multiply(int rhs)
         {
-            Size2D ret = new Size2D(Interop.Vector2.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
+            Size2D ret = new Size2D(Interop.Vector2.Multiply(swigCPtr, (float)rhs), true);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
         private Size2D Divide(Size2D rhs)
         {
-            Size2D ret = new Size2D(Interop.Vector2.Vector2_Divide__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
+            Size2D ret = new Size2D(Interop.Vector2.Divide(swigCPtr, Size2D.getCPtr(rhs)), true);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
         private Size2D Divide(int rhs)
         {
-            Size2D ret = new Size2D(Interop.Vector2.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
+            Size2D ret = new Size2D(Interop.Vector2.Divide(swigCPtr, (float)rhs), true);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
         private Size2D Subtract()
         {
-            Size2D ret = new Size2D(Interop.Vector2.Vector2_Subtract__SWIG_1(swigCPtr), true);
+            Size2D ret = new Size2D(Interop.Vector2.Subtract(swigCPtr), true);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
         private int ValueOfIndex(uint index)
         {
-            int ret = (int)Interop.Vector2.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
+            int ret = (int)Interop.Vector2.ValueOfIndex(swigCPtr, index);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }