[NUI] replace NUI.ISelectorItem with System.ICloneable (#1965)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Size.cs
index 2175653..72a1014 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.
@@ -26,20 +26,20 @@ namespace Tizen.NUI
     /// </summary>
     /// <since_tizen> 5 </since_tizen>
     [Tizen.NUI.Binding.TypeConverter(typeof(SizeTypeConverter))]
-    public class Size : Disposable
+    public class Size : Disposable, ICloneable
     {
-        /// <summary>swigCMemOwn.</summary>
-        /// <since_tizen> 5 </since_tizen>
-        protected bool swigCMemOwn;
-
-        private global::System.Runtime.InteropServices.HandleRef swigCPtr;
-
-        //A Flag to check who called Dispose(). (By User or DisposeQueue)
-        private bool isDisposeQueued = false;
 
         /// <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> 5 </since_tizen>
         public Size() : this(Interop.Vector3.new_Vector3__SWIG_0(), true)
         {
@@ -49,11 +49,19 @@ 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="z">The z (or depth) component(optional).</param>
+        /// <param name="width">The width component.</param>
+        /// <param name="height">The height component.</param>
+        /// <param name="depth">The depth component(optional).</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> 5 </since_tizen>
-        public Size(float x, float y, float z = 0.0f) : this(Interop.Vector3.new_Vector3__SWIG_1(x, y, z), true)
+        public Size(float width, float height, float depth = 0.0f) : this(Interop.Vector3.new_Vector3__SWIG_1(width, height, depth), true)
         {
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
@@ -61,7 +69,7 @@ namespace Tizen.NUI
         /// <summary>
         /// The constructor.
         /// </summary>
-        /// <param name="size2d">Size2D with x (width) and y (height).</param>
+        /// <param name="size2d">Size2D with width and height.</param>
         /// <since_tizen> 5 </since_tizen>
         public Size(Size2D size2d) : this(Interop.Vector3.new_Vector3__SWIG_3(Size2D.getCPtr(size2d)), true)
         {
@@ -94,7 +102,7 @@ namespace Tizen.NUI
                 Interop.Vector3.Vector3_Width_set(swigCPtr, value);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
-                callback?.Invoke(Width, Height, Depth);
+                callback?.Invoke(value, null, null);
             }
             get
             {
@@ -115,7 +123,7 @@ namespace Tizen.NUI
                 Interop.Vector3.Vector3_Height_set(swigCPtr, value);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
-                callback?.Invoke(Width, Height, Depth);
+                callback?.Invoke(null, value, null);
             }
             get
             {
@@ -136,7 +144,7 @@ namespace Tizen.NUI
                 Interop.Vector3.Vector3_Depth_set(swigCPtr, value);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
-                callback?.Invoke(Width, Height, Depth);
+                callback?.Invoke(null, null, value);
             }
             get
             {
@@ -297,6 +305,10 @@ namespace Tizen.NUI
             return ret;
         }
 
+        /// <inheritdoc/>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public object Clone() => new Size(Width, Height, Depth);
+
         /// <summary>
         /// The type cast operator, Size to Vector3.
         /// </summary>
@@ -317,6 +329,19 @@ namespace Tizen.NUI
             return new Size(vec.Width, vec.Height, vec.Depth);
         }
 
+        /// <summary>
+        /// Implicit type cast operator, Size2D to Size
+        /// </summary>
+        /// <param name="size2d">The object of Size2D type.</param>
+        /// <since_tizen> none </since_tizen>
+        /// This will be public opened in tizen_next by ACR.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static implicit operator Size(Size2D size2d)
+        {
+            return new Size(size2d.Width, size2d.Height, 0);
+        }
+        
+
         internal static Size GetSizeFromPtr(global::System.IntPtr cPtr)
         {
             Size ret = new Size(cPtr, false);
@@ -329,38 +354,15 @@ namespace Tizen.NUI
             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
         }
 
-        internal Size(global::System.IntPtr cPtr, bool cMemoryOwn)
+        internal Size(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> 5 </since_tizen>
-        protected override 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;
-            }
-
-            //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.Vector3.delete_Vector3(swigCPtr);
-                }
-                swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
-            }
-
-            base.Dispose(type);
+            Interop.Vector3.delete_Vector3(swigCPtr);
         }
 
         private Size Add(Size rhs)
@@ -419,7 +421,7 @@ namespace Tizen.NUI
             return ret;
         }
 
-        internal delegate void SizeChangedCallback(float width, float height, float depth);
+        internal delegate void SizeChangedCallback(float? width, float? height, float? depth);
 
         internal Size(SizeChangedCallback cb, float w, float h, float d) : this(Interop.Vector3.new_Vector3__SWIG_1(w, h, d), true)
         {
@@ -427,6 +429,10 @@ namespace Tizen.NUI
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
+        internal Size(SizeChangedCallback cb, Size other) : this(cb, other.Width, other.Height, other.Depth)
+        {
+        }
+
         private SizeChangedCallback callback = null;
     }
 }