Merge "Fix Left/Right/Up/DownFocusableView bug =>If app set the Left/Right/Up/DownFoc...
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / View.cs
index 3cc5f0a..f312226 100755 (executable)
@@ -28,6 +28,7 @@ namespace Tizen.NUI.BaseComponents
     {
         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
 
+
         internal View(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.View_SWIGUpcast(cPtr), cMemoryOwn)
         {
             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
@@ -44,97 +45,76 @@ namespace Tizen.NUI.BaseComponents
         /// <summary>
         /// Adds a child view to this view.
         /// </summary>
-        /// <seealso cref="Container.Add">
-        /// </seealso>
+        /// <seealso cref="Container.Add" />
         /// <since_tizen> 4 </since_tizen>
         public override void Add(View child)
         {
             NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child));
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+
+            Children.Add(child);
         }
 
         /// <summary>
         /// Removes a child view from this View. If the view was not a child of this view, this is a no-op.
         /// </summary>
-        /// <seealso cref="Container.Remove">
-        /// </seealso>
+        /// <seealso cref="Container.Remove" />
         /// <since_tizen> 4 </since_tizen>
         public override void Remove(View child)
         {
             NDalicPINVOKE.Actor_Remove(swigCPtr, View.getCPtr(child));
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+
+            Children.Remove(child);
         }
 
         /// <summary>
         /// Retrieves a child view by index.
         /// </summary>
-        /// <seealso cref="Container.GetChildAt">
-        /// </seealso>
+        /// <seealso cref="Container.GetChildAt" />
         /// <since_tizen> 4 </since_tizen>
         public override View GetChildAt(uint index)
         {
-            IntPtr cPtr = NDalicPINVOKE.Actor_GetChildAt(swigCPtr, index);
-
-            View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View;
-
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret ?? null;
+            if (index < Children.Count)
+            {
+                return Children[Convert.ToInt32(index)];
+            }
+            else
+            {
+                return null;
+            }
         }
 
         /// <summary>
         /// Retrieves the number of children held by the view.
         /// </summary>
-        /// <seealso cref="Container.GetChildCount">
-        /// </seealso>
-        protected override uint GetChildCount()
+        /// <seealso cref="Container.GetChildCount" />
+        public override uint GetChildCount()
         {
-            uint ret = NDalicPINVOKE.Actor_GetChildCount(swigCPtr);
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret;
+            return Convert.ToUInt32(Children.Count);
         }
 
         /// <summary>
         /// Gets the views parent.
         /// </summary>
         /// <seealso cref="Container.GetParent()" />
-        protected override Container GetParent()
+        public override Container GetParent()
         {
-            Container ret;
             IntPtr cPtr = NDalicPINVOKE.Actor_GetParent(swigCPtr);
 
             BaseHandle basehandle = Registry.GetManagedBaseHandleFromNativePtr(cPtr);
 
-            if(basehandle is Layer)
-            {
-                ret = basehandle as Layer;
-            }
-            else
-            {
-                ret = basehandle as View;
-            }
-
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret;
-        }
 
-        /// <summary>
-        /// This is temporal API. Currently Parent returns View but Container class has been introduced so 'View Parent' will be changed 'Container Parent' later soon, then this will be removed
-        /// </summary>
-        /// <since_tizen> 3 </since_tizen>
-        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
-        public Container GetContainerParent()
-        {
-            return this.GetParent();
+            return basehandle as Container;
         }
 
         internal bool IsTopLevelView()
         {
-            if(GetContainerParent() is Layer)
+            if(GetParent() is Layer)
             {
                 return true;
             }
@@ -177,6 +157,13 @@ namespace Tizen.NUI.BaseComponents
             }
 
             base.Dispose(type);
+
+            // Dispose all Children of this View.
+            foreach (View childView in Children)
+            {
+                childView?.Dispose();
+            }
+            Children.Clear();
         }
 
         private void DisConnectFromSignals()
@@ -1110,6 +1097,8 @@ namespace Tizen.NUI.BaseComponents
             internal static readonly int CLIPPING_MODE = NDalicPINVOKE.Actor_Property_CLIPPING_MODE_get();
             internal static readonly int INHERIT_LAYOUT_DIRECTION = NDalicManualPINVOKE.Actor_Property_INHERIT_LAYOUT_DIRECTION_get();
             internal static readonly int LAYOUT_DIRECTION = NDalicManualPINVOKE.Actor_Property_LAYOUT_DIRECTION_get();
+            internal static readonly int MARGIN = NDalicPINVOKE.View_Property_MARGIN_get();
+            internal static readonly int PADDINGEX = NDalicPINVOKE.View_Property_PADDING_get();
         }
 
         /// <summary>
@@ -1925,7 +1914,14 @@ namespace Tizen.NUI.BaseComponents
             }
             set
             {
-                LeftFocusableViewId = (int)value.GetId();
+                if(value)
+                {
+                    LeftFocusableViewId = (int)value.GetId();
+                }
+                else
+                {
+                    LeftFocusableViewId = -1;
+                }
             }
         }
 
@@ -1948,7 +1944,14 @@ namespace Tizen.NUI.BaseComponents
             }
             set
             {
-                RightFocusableViewId = (int)value.GetId();
+                if(value)
+                {
+                    RightFocusableViewId = (int)value.GetId();
+                }
+                else
+                {
+                    RightFocusableViewId = -1;
+                }
             }
         }
 
@@ -1971,7 +1974,14 @@ namespace Tizen.NUI.BaseComponents
             }
             set
             {
-                UpFocusableViewId = (int)value.GetId();
+                if(value)
+                {
+                    UpFocusableViewId = (int)value.GetId();
+                }
+                else
+                {
+                    UpFocusableViewId = -1;
+                }
             }
         }
 
@@ -1994,7 +2004,14 @@ namespace Tizen.NUI.BaseComponents
             }
             set
             {
-                DownFocusableViewId = (int)value.GetId();
+                if(value)
+                {
+                    DownFocusableViewId = (int)value.GetId();
+                }
+                else
+                {
+                    DownFocusableViewId = -1;
+                }
             }
         }
 
@@ -2313,6 +2330,21 @@ namespace Tizen.NUI.BaseComponents
 
         internal void Raise()
         {
+            var parentChildren = Parent?.Children;
+
+            if (parentChildren != null)
+            {
+                int currentIndex = parentChildren.IndexOf(this);
+
+                // If the view is not already the last item in the list.
+                if (currentIndex != parentChildren.Count -1)
+                {
+                    View temp = parentChildren[currentIndex + 1];
+                    parentChildren[currentIndex + 1] = this;
+                    parentChildren[currentIndex] = temp;
+                }
+            }
+
             NDalicPINVOKE.Raise(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -2320,6 +2352,21 @@ namespace Tizen.NUI.BaseComponents
 
         internal void Lower()
         {
+            var parentChildren = Parent?.Children;
+
+            if (parentChildren != null)
+            {
+                int currentIndex = parentChildren.IndexOf(this);
+
+                // If the view is not already the first item in the list.
+                if (currentIndex > 0)
+                {
+                    View temp = parentChildren[currentIndex - 1];
+                    parentChildren[currentIndex - 1] = this;
+                    parentChildren[currentIndex] = temp;
+                }
+            }
+
             NDalicPINVOKE.Lower(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -2335,6 +2382,14 @@ namespace Tizen.NUI.BaseComponents
         /// <since_tizen> 3 </since_tizen>
         public void RaiseToTop()
         {
+            var parentChildren = Parent?.Children;
+
+            if (parentChildren != null)
+            {
+                parentChildren.Remove(this);
+                parentChildren.Add(this);
+            }
+
             NDalicPINVOKE.RaiseToTop(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -2350,6 +2405,14 @@ namespace Tizen.NUI.BaseComponents
         /// <since_tizen> 3 </since_tizen>
         public void LowerToBottom()
         {
+            var parentChildren = Parent?.Children;
+
+            if (parentChildren != null)
+            {
+                parentChildren.Remove(this);
+                parentChildren.Insert(0, this);
+            }
+
             NDalicPINVOKE.LowerToBottom(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -2379,6 +2442,21 @@ namespace Tizen.NUI.BaseComponents
         /// <param name="target">Will be raised above this view.</param>
         internal void RaiseAbove(View target)
         {
+            var parentChildren = Parent?.Children;
+
+            if (parentChildren != null)
+            {
+                int currentIndex = parentChildren.IndexOf(this);
+                int targetIndex = parentChildren.IndexOf(target);
+
+                // If the currentIndex is less than the target index and the target has the same parent.
+                if (currentIndex < targetIndex)
+                {
+                    parentChildren.Remove(this);
+                    parentChildren.Insert(targetIndex, this);
+                }
+            }
+
             NDalicPINVOKE.RaiseAbove(swigCPtr, View.getCPtr(target));
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -2394,7 +2472,23 @@ namespace Tizen.NUI.BaseComponents
         /// <param name="target">Will be lowered below this view.</param>
         internal void LowerBelow(View target)
         {
-            NDalicPINVOKE.RaiseAbove(swigCPtr, View.getCPtr(target));
+            var parentChildren = Parent?.Children;
+
+            if (parentChildren != null)
+            {
+                int currentIndex = parentChildren.IndexOf(this);
+                int targetIndex = parentChildren.IndexOf(target);
+
+                // If the currentIndex is not already the 0th index and the target has the same parent.
+                if ((currentIndex != 0) && (targetIndex != -1) &&
+                    (currentIndex > targetIndex))
+                {
+                    parentChildren.Remove(this);
+                    parentChildren.Insert(targetIndex, this);
+                }
+            }
+
+            NDalicPINVOKE.LowerBelow(swigCPtr, View.getCPtr(target));
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
@@ -2454,9 +2548,7 @@ namespace Tizen.NUI.BaseComponents
         /// <since_tizen> 4 </since_tizen>
         public void Unparent()
         {
-            NDalicPINVOKE.Actor_Unparent(swigCPtr);
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            GetParent()?.Remove(this);
         }
 
         /// <summary>
@@ -4052,6 +4144,8 @@ namespace Tizen.NUI.BaseComponents
                     return ClippingModeType.Disabled;
                     case "CLIP_CHILDREN":
                     return ClippingModeType.ClipChildren;
+                    case "CLIP_TO_BOUNDING_BOX":
+                    return ClippingModeType.ClipToBoundingBox;
                     default:
                     return ClippingModeType.Disabled;
                 }
@@ -4360,6 +4454,40 @@ namespace Tizen.NUI.BaseComponents
                 SetProperty(View.Property.LAYOUT_DIRECTION, new Tizen.NUI.PropertyValue((int)value));
             }
         }
+
+        /// <summary>
+        /// Gets or sets the Margin for use in layout.
+        /// </summary>
+        public Extents Margin
+        {
+            get
+            {
+                Extents temp = new Extents(0, 0, 0, 0);
+                GetProperty(View.Property.MARGIN).Get(temp);
+                return temp;
+            }
+            set
+            {
+                SetProperty(View.Property.MARGIN, new Tizen.NUI.PropertyValue(value));
+            }
+        }
+
+        /// <summary>
+        /// Gets or sets the Padding for use in layout.
+        /// </summary>
+        public Extents PaddingEX
+        {
+            get
+            {
+                Extents temp = new Extents(0, 0, 0, 0);
+                GetProperty(View.Property.PADDINGEX).Get(temp);
+                return temp;
+            }
+            set
+            {
+                SetProperty(View.Property.PADDINGEX, new Tizen.NUI.PropertyValue(value));
+            }
+        }
     }
 
     /// <summary>
@@ -4377,4 +4505,4 @@ namespace Tizen.NUI.BaseComponents
         /// </summary>
         RTL
     }
-}
\ No newline at end of file
+}