[NUI] Remove [Obsolete()] attribute
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Rectangle.cs
index db2bc69..1036e9c 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright(c) 2017 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.
@@ -14,8 +14,9 @@
  * limitations under the License.
  *
  */
- using System;
- using Tizen.NUI.Binding;
+using System;
+using System.ComponentModel;
+using Tizen.NUI.Binding;
 
 namespace Tizen.NUI
 {
@@ -23,31 +24,14 @@ namespace Tizen.NUI
     /// The Rectangle class.
     /// </summary>
     /// <since_tizen> 3 </since_tizen>
-    [TypeConverter(typeof(RectangleTypeConverter))]
-    public class Rectangle : global::System.IDisposable
+    [Binding.TypeConverter(typeof(RectangleTypeConverter))]
+    public class Rectangle : 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;
-
-        /// <summary>
         /// The constructor.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
-        public Rectangle() : this(NDalicPINVOKE.new_Rectangle__SWIG_0(), true)
+        public Rectangle() : this(Interop.Rectangle.new_Rectangle__SWIG_0(), true)
         {
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
@@ -60,39 +44,72 @@ namespace Tizen.NUI
         /// <param name="width">The width (or bottom).</param>
         /// <param name="height">The height (or top).</param>
         /// <since_tizen> 3 </since_tizen>
-        public Rectangle(int x, int y, int width, int height) : this(NDalicPINVOKE.new_Rectangle__SWIG_1(x, y, width, height), true)
+        public Rectangle(int x, int y, int width, int height) : this(Interop.Rectangle.new_Rectangle__SWIG_1(x, y, width, height), true)
+        {
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        internal Rectangle(Rectangle other) : this(other.x, other.y, other.width, other.height)
+        {
+        }
+
+        internal Rectangle(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
+        {
+        }
+
+        internal Rectangle(RectangleChangedCallback cb, int x, int y, int width, int height) : this(Interop.Rectangle.new_Rectangle__SWIG_1(x, y, width, height), true)
         {
+            callback = cb;
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
-        internal Rectangle(global::System.IntPtr cPtr, bool cMemoryOwn)
+        internal Rectangle(RectangleChangedCallback cb) : this()
+        {
+            callback = cb;
+        }
+
+        internal Rectangle(RectangleChangedCallback cb, Rectangle other) : this(cb, other.x, other.y, other.width, other.height)
         {
-            swigCMemOwn = cMemoryOwn;
-            swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
         }
 
         /// <summary>
-        /// Dispose.
+        /// The type cast operator, int to Rectangle.
         /// </summary>
-        /// <since_tizen> 3 </since_tizen>
-        ~Rectangle()
+        /// <param name="value">A value of int type.</param>
+        /// <returns>return a Extents instance</returns>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static implicit operator Rectangle(int value)
         {
-            if (!isDisposeQueued)
-            {
-                isDisposeQueued = true;
-                DisposeQueue.Instance.Add(this);
-            }
+            return new Rectangle(value, value, value, value);
         }
 
+        internal delegate void RectangleChangedCallback(int x, int y, int width, int height);
+        private RectangleChangedCallback callback = null;
+
         /// <summary>
         /// The x position of the rectangle.
         /// </summary>
+        /// <remarks>
+        /// The setter is deprecated in API8 and will be removed in API10. Please use new Rectangle(...) constructor.
+        /// </remarks>
+        /// <code>
+        /// // DO NOT use like the followings!
+        /// Rectangle rectangle = new Rectangle();
+        /// rectangle.X = 1; 
+        /// // Please USE like this
+        /// int x = 1, y = 2, width = 3, height = 4;
+        /// Rectangle rectangle = new Rectangle(x, y, width, height);
+        /// </code>
         /// <since_tizen> 3 </since_tizen>
         public int X
         {
             set
             {
+                Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor");
+
                 x = (value);
+
+                callback?.Invoke(X, Y, Width, Height);
             }
             get
             {
@@ -103,12 +120,27 @@ namespace Tizen.NUI
         /// <summary>
         /// The Y position of the rectangle.
         /// </summary>
+        /// <remarks>
+        /// The setter is deprecated in API8 and will be removed in API10. Please use new Rectangle(...) constructor.
+        /// </remarks>
+        /// <code>
+        /// // DO NOT use like the followings!
+        /// Rectangle rectangle = new Rectangle();
+        /// rectangle.Y = 2; 
+        /// // Please USE like this
+        /// int x = 1, y = 2, width = 3, height = 4;
+        /// Rectangle rectangle = new Rectangle(x, y, width, height);
+        /// </code>
         /// <since_tizen> 3 </since_tizen>
         public int Y
         {
             set
             {
+                Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor");
+
                 y = (value);
+
+                callback?.Invoke(X, Y, Width, Height);
             }
             get
             {
@@ -119,12 +151,27 @@ namespace Tizen.NUI
         /// <summary>
         /// The width of the rectangle.
         /// </summary>
+        /// <remarks>
+        /// The setter is deprecated in API8 and will be removed in API10. Please use new Rectangle(...) constructor.
+        /// </remarks>
+        /// <code>
+        /// // DO NOT use like the followings!
+        /// Rectangle rectangle = new Rectangle();
+        /// rectangle.Width = 3; 
+        /// // Please USE like this
+        /// int x = 1, y = 2, width = 3, height = 4;
+        /// Rectangle rectangle = new Rectangle(x, y, width, height);
+        /// </code>
         /// <since_tizen> 3 </since_tizen>
         public int Width
         {
             set
             {
+                Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor");
+
                 width = (value);
+
+                callback?.Invoke(X, Y, Width, Height);
             }
             get
             {
@@ -135,12 +182,27 @@ namespace Tizen.NUI
         /// <summary>
         /// The height of the rectangle.
         /// </summary>
+        /// <remarks>
+        /// The setter is deprecated in API8 and will be removed in API10. Please use new Rectangle(...) constructor.
+        /// </remarks>
+        /// <code>
+        /// // DO NOT use like the followings!
+        /// Rectangle rectangle = new Rectangle();
+        /// rectangle.Height = 4; 
+        /// // Please USE like this
+        /// int x = 1, y = 2, width = 3, height = 4;
+        /// Rectangle rectangle = new Rectangle(x, y, width, height);
+        /// </code>
         /// <since_tizen> 3 </since_tizen>
         public int Height
         {
             set
             {
+                Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor");
+
                 height = (value);
+
+                callback?.Invoke(X, Y, Width, Height);
             }
             get
             {
@@ -152,12 +214,12 @@ namespace Tizen.NUI
         {
             set
             {
-                NDalicPINVOKE.Rectangle_x_set(swigCPtr, value);
+                Interop.Rectangle.Rectangle_x_set(swigCPtr, value);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             }
             get
             {
-                int ret = NDalicPINVOKE.Rectangle_x_get(swigCPtr);
+                int ret = Interop.Rectangle.Rectangle_x_get(swigCPtr);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                 return ret;
             }
@@ -167,12 +229,12 @@ namespace Tizen.NUI
         {
             set
             {
-                NDalicPINVOKE.Rectangle_left_set(swigCPtr, value);
+                Interop.Rectangle.Rectangle_left_set(swigCPtr, value);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             }
             get
             {
-                int ret = NDalicPINVOKE.Rectangle_left_get(swigCPtr);
+                int ret = Interop.Rectangle.Rectangle_left_get(swigCPtr);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                 return ret;
             }
@@ -182,12 +244,12 @@ namespace Tizen.NUI
         {
             set
             {
-                NDalicPINVOKE.Rectangle_y_set(swigCPtr, value);
+                Interop.Rectangle.Rectangle_y_set(swigCPtr, value);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             }
             get
             {
-                int ret = NDalicPINVOKE.Rectangle_y_get(swigCPtr);
+                int ret = Interop.Rectangle.Rectangle_y_get(swigCPtr);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                 return ret;
             }
@@ -197,12 +259,12 @@ namespace Tizen.NUI
         {
             set
             {
-                NDalicPINVOKE.Rectangle_right_set(swigCPtr, value);
+                Interop.Rectangle.Rectangle_right_set(swigCPtr, value);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             }
             get
             {
-                int ret = NDalicPINVOKE.Rectangle_right_get(swigCPtr);
+                int ret = Interop.Rectangle.Rectangle_right_get(swigCPtr);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                 return ret;
             }
@@ -212,12 +274,12 @@ namespace Tizen.NUI
         {
             set
             {
-                NDalicPINVOKE.Rectangle_width_set(swigCPtr, value);
+                Interop.Rectangle.Rectangle_width_set(swigCPtr, value);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             }
             get
             {
-                int ret = NDalicPINVOKE.Rectangle_width_get(swigCPtr);
+                int ret = Interop.Rectangle.Rectangle_width_get(swigCPtr);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                 return ret;
             }
@@ -227,12 +289,12 @@ namespace Tizen.NUI
         {
             set
             {
-                NDalicPINVOKE.Rectangle_bottom_set(swigCPtr, value);
+                Interop.Rectangle.Rectangle_bottom_set(swigCPtr, value);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             }
             get
             {
-                int ret = NDalicPINVOKE.Rectangle_bottom_get(swigCPtr);
+                int ret = Interop.Rectangle.Rectangle_bottom_get(swigCPtr);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                 return ret;
             }
@@ -242,12 +304,12 @@ namespace Tizen.NUI
         {
             set
             {
-                NDalicPINVOKE.Rectangle_height_set(swigCPtr, value);
+                Interop.Rectangle.Rectangle_height_set(swigCPtr, value);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             }
             get
             {
-                int ret = NDalicPINVOKE.Rectangle_height_get(swigCPtr);
+                int ret = Interop.Rectangle.Rectangle_height_get(swigCPtr);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                 return ret;
             }
@@ -257,12 +319,12 @@ namespace Tizen.NUI
         {
             set
             {
-                NDalicPINVOKE.Rectangle_top_set(swigCPtr, value);
+                Interop.Rectangle.Rectangle_top_set(swigCPtr, value);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             }
             get
             {
-                int ret = NDalicPINVOKE.Rectangle_top_get(swigCPtr);
+                int ret = Interop.Rectangle.Rectangle_top_get(swigCPtr);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                 return ret;
             }
@@ -306,29 +368,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>
         /// Equality operator.
         /// </summary>
         /// <param name="o">The object to compare with the current object.</param>
@@ -336,11 +375,11 @@ namespace Tizen.NUI
         /// <since_tizen> 4 </since_tizen>
         public override bool Equals(object o)
         {
-            if(o == null)
+            if (o == null)
             {
                 return false;
             }
-            if(!(o is Rectangle))
+            if (!(o is Rectangle))
             {
                 return false;
             }
@@ -370,7 +409,7 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public void Set(int newX, int newY, int newWidth, int newHeight)
         {
-            NDalicPINVOKE.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
+            Interop.Rectangle.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -381,7 +420,7 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public bool IsEmpty()
         {
-            bool ret = NDalicPINVOKE.Rectangle_IsEmpty(swigCPtr);
+            bool ret = Interop.Rectangle.Rectangle_IsEmpty(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -393,7 +432,7 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public int Left()
         {
-            int ret = NDalicPINVOKE.Rectangle_Left(swigCPtr);
+            int ret = Interop.Rectangle.Rectangle_Left(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -405,7 +444,7 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public int Right()
         {
-            int ret = NDalicPINVOKE.Rectangle_Right(swigCPtr);
+            int ret = Interop.Rectangle.Rectangle_Right(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -417,7 +456,7 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public int Top()
         {
-            int ret = NDalicPINVOKE.Rectangle_Top(swigCPtr);
+            int ret = Interop.Rectangle.Rectangle_Top(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -429,7 +468,7 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public int Bottom()
         {
-            int ret = NDalicPINVOKE.Rectangle_Bottom(swigCPtr);
+            int ret = Interop.Rectangle.Rectangle_Bottom(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -441,7 +480,7 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public int Area()
         {
-            int ret = NDalicPINVOKE.Rectangle_Area(swigCPtr);
+            int ret = Interop.Rectangle.Rectangle_Area(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -454,7 +493,7 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public bool Intersects(Rectangle other)
         {
-            bool ret = NDalicPINVOKE.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
+            bool ret = Interop.Rectangle.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -467,48 +506,30 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public bool Contains(Rectangle other)
         {
-            bool ret = NDalicPINVOKE.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other));
+            bool ret = Interop.Rectangle.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
+        /// <inheritdoc/>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public object Clone() => new Rectangle(this);
+
         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rectangle obj)
         {
             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
         }
 
-        /// <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;
-                    NDalicPINVOKE.delete_Rectangle(swigCPtr);
-                }
-                swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
-            }
-            disposed = true;
+            Interop.Rectangle.delete_Rectangle(swigCPtr);
         }
+
+        /// <summary>
+        /// Determines whether the reference is null or the Rectangle has all 0 properties.
+        /// </summary>
+        internal static bool IsNullOrZero(Rectangle rectangle) => (rectangle == null || (rectangle.top == 0 && rectangle.right == 0 && rectangle.bottom == 0 && rectangle.left == 0));
     }
 }
\ No newline at end of file