[NUI] Apply SiblingOrder 42/168342/7
authorhuiyu,eun <huiyu.eun@samsung.com>
Fri, 26 Jan 2018 02:13:23 +0000 (11:13 +0900)
committerhuiyu,eun <huiyu.eun@samsung.com>
Fri, 26 Jan 2018 11:39:43 +0000 (20:39 +0900)
Change-Id: I8a44269bd4bb6a23db33bad05763e3e4e250c8b4
Signed-off-by: huiyu,eun <huiyu.eun@samsung.com>
src/Tizen.NUI/src/public/BaseComponents/View.cs
src/Tizen.NUI/src/public/Layer.cs

index 4f02f46..762bc29 100755 (executable)
@@ -49,11 +49,18 @@ namespace Tizen.NUI.BaseComponents
         /// <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);
+            Container oldParent = child.GetParent();
+            if(oldParent != this)
+            {
+                if (oldParent != null)
+                {
+                    oldParent.Remove(child);
+                }
+                NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child));
+                if (NDalicPINVOKE.SWIGPendingException.Pending)
+                    throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                Children.Add(child);
+            }
         }
 
         /// <summary>
@@ -2239,7 +2246,7 @@ namespace Tizen.NUI.BaseComponents
         /// Sets the sibling order of the view so the depth position can be defined within the same parent.
         /// </summary>
         /// <remarks>
-        /// Note the initial value is 0.
+        /// Note the initial value is 0. SiblingOrder should be bigger than 0 or equal to 0.
         /// Raise, Lower, RaiseToTop, LowerToBottom, RaiseAbove, and LowerBelow will override the sibling order.
         /// The values set by this property will likely change.
         /// </remarks>
@@ -2248,7 +2255,7 @@ namespace Tizen.NUI.BaseComponents
         {
             get
             {
-                var parentChildren = Parent?.Children;
+                var parentChildren = GetParent()?.Children;
                 int currentOrder = 0;
                 if (parentChildren != null)
                 {
@@ -2268,7 +2275,38 @@ namespace Tizen.NUI.BaseComponents
             }
             set
             {
-                SetProperty(View.Property.SIBLING_ORDER, new Tizen.NUI.PropertyValue(value));
+                if(value < 0)
+                {
+                    NUILog.Error("SiblingOrder should be bigger than 0 or equal to 0.");
+                    return;
+                }
+                var siblings = GetParent()?.Children;
+                if (siblings != null)
+                {
+                    int currentOrder = siblings.IndexOf(this);
+                    if (value != currentOrder)
+                    {
+                        if (value == 0)
+                        {
+                            LowerToBottom();
+                        }
+                        else if (value < siblings.Count - 1)
+                        {
+                            if (value > currentOrder)
+                            {
+                                RaiseAbove(siblings[value]);
+                            }
+                            else
+                            {
+                                LowerBelow(siblings[value]);
+                            }
+                        }
+                        else
+                        {
+                            RaiseToTop();
+                        }
+                    }
+                }
             }
         }
 
@@ -2344,46 +2382,47 @@ namespace Tizen.NUI.BaseComponents
 
         internal void Raise()
         {
-            var parentChildren = Parent?.Children;
+            var parentChildren = GetParent()?.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)
+                if (currentIndex >= 0 && 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();
                 }
             }
 
-            NDalicPINVOKE.Raise(swigCPtr);
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         internal void Lower()
         {
-            var parentChildren = Parent?.Children;
+            var parentChildren = GetParent()?.Children;
 
             if (parentChildren != null)
             {
                 int currentIndex = parentChildren.IndexOf(this);
 
                 // If the view is not already the first item in the list.
-                if (currentIndex > 0)
+                if (currentIndex > 0 && currentIndex < parentChildren.Count)
                 {
                     View temp = parentChildren[currentIndex - 1];
                     parentChildren[currentIndex - 1] = this;
                     parentChildren[currentIndex] = temp;
+
+                    NDalicPINVOKE.Lower(swigCPtr);
+                    if (NDalicPINVOKE.SWIGPendingException.Pending)
+                        throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                 }
             }
-
-            NDalicPINVOKE.Lower(swigCPtr);
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         /// <summary>
@@ -2396,17 +2435,18 @@ namespace Tizen.NUI.BaseComponents
         /// <since_tizen> 3 </since_tizen>
         public void RaiseToTop()
         {
-            var parentChildren = Parent?.Children;
+            var parentChildren = GetParent()?.Children;
 
             if (parentChildren != null)
             {
                 parentChildren.Remove(this);
                 parentChildren.Add(this);
+
+                NDalicPINVOKE.RaiseToTop(swigCPtr);
+                if (NDalicPINVOKE.SWIGPendingException.Pending)
+                    throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             }
 
-            NDalicPINVOKE.RaiseToTop(swigCPtr);
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         /// <summary>
@@ -2419,17 +2459,17 @@ namespace Tizen.NUI.BaseComponents
         /// <since_tizen> 3 </since_tizen>
         public void LowerToBottom()
         {
-            var parentChildren = Parent?.Children;
+            var parentChildren = GetParent()?.Children;
 
             if (parentChildren != null)
             {
                 parentChildren.Remove(this);
                 parentChildren.Insert(0, this);
-            }
 
-            NDalicPINVOKE.LowerToBottom(swigCPtr);
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                NDalicPINVOKE.LowerToBottom(swigCPtr);
+                if (NDalicPINVOKE.SWIGPendingException.Pending)
+                    throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            }
         }
 
         /// <summary>
@@ -2456,24 +2496,31 @@ namespace Tizen.NUI.BaseComponents
         /// <param name="target">Will be raised above this view.</param>
         internal void RaiseAbove(View target)
         {
-            var parentChildren = Parent?.Children;
+            var parentChildren = GetParent()?.Children;
 
             if (parentChildren != null)
             {
                 int currentIndex = parentChildren.IndexOf(this);
                 int targetIndex = parentChildren.IndexOf(target);
 
+                if(currentIndex < 0 || targetIndex < 0 ||
+                    currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count)
+                {
+                    NUILog.Error("index should be bigger than 0 and less than children of layer count");
+                    return;
+                }
                 // 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();
                 }
             }
 
-            NDalicPINVOKE.RaiseAbove(swigCPtr, View.getCPtr(target));
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         /// <summary>
@@ -2486,12 +2533,18 @@ namespace Tizen.NUI.BaseComponents
         /// <param name="target">Will be lowered below this view.</param>
         internal void LowerBelow(View target)
         {
-            var parentChildren = Parent?.Children;
+            var parentChildren = GetParent()?.Children;
 
             if (parentChildren != null)
             {
                 int currentIndex = parentChildren.IndexOf(this);
                 int targetIndex = parentChildren.IndexOf(target);
+                if(currentIndex < 0 || targetIndex < 0 ||
+                   currentIndex >= parentChildren.Count ||targetIndex >= parentChildren.Count)
+                {
+                    NUILog.Error("index should be bigger than 0 and less than children of layer count");
+                    return;
+                }
 
                 // If the currentIndex is not already the 0th index and the target has the same parent.
                 if ((currentIndex != 0) && (targetIndex != -1) &&
@@ -2499,12 +2552,13 @@ namespace Tizen.NUI.BaseComponents
                 {
                     parentChildren.Remove(this);
                     parentChildren.Insert(targetIndex, this);
+
+                    NDalicPINVOKE.LowerBelow(swigCPtr, View.getCPtr(target));
+                    if (NDalicPINVOKE.SWIGPendingException.Pending)
+                        throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                 }
             }
 
-            NDalicPINVOKE.LowerBelow(swigCPtr, View.getCPtr(target));
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         internal string GetName()
index 8fee27b..37efd13 100755 (executable)
@@ -50,11 +50,18 @@ namespace Tizen.NUI
         /// <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);
+            Container oldParent = child.GetParent();
+            if (oldParent != this)
+            {
+                if (oldParent != null)
+                {
+                    oldParent.Remove(child);
+                }
+                NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child));
+                if (NDalicPINVOKE.SWIGPendingException.Pending)
+                    throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                Children.Add(child);
+            }
         }
 
         /// <summary>
@@ -254,13 +261,16 @@ namespace Tizen.NUI
             {
                 int currentIdx = parentChildren.IndexOf(this);
 
-                if (currentIdx != parentChildren.Count - 1)
+                if (currentIdx >= 0 && currentIdx < parentChildren.Count - 1)
                 {
                     RaiseAbove(parentChildren[currentIdx + 1]);
 
                     Layer temp = parentChildren[currentIdx + 1];
                     parentChildren[currentIdx + 1] = this;
                     parentChildren[currentIdx] = temp;
+
+                    NDalicPINVOKE.Layer_Raise(swigCPtr);
+                    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                 }
             }
         }
@@ -276,7 +286,7 @@ namespace Tizen.NUI
             {
                 int currentIdx = parentChildren.IndexOf(this);
 
-                if (currentIdx > 0)
+                if (currentIdx > 0 && currentIdx < parentChildren.Count)
                 {
                     LowerBelow(parentChildren[currentIdx - 1]);
 
@@ -284,20 +294,66 @@ namespace Tizen.NUI
                     parentChildren[currentIdx - 1] = this;
                     parentChildren[currentIdx] = temp;
 
+                    NDalicPINVOKE.Layer_Lower(swigCPtr);
+                    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                 }
             }
         }
 
         internal void RaiseAbove(Layer target)
         {
-            NDalicPINVOKE.Layer_RaiseAbove(swigCPtr, Layer.getCPtr(target));
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            var parentChildren = Window.Instance.LayersChildren;
+            if (parentChildren != null)
+            {
+                int currentIndex = parentChildren.IndexOf(this);
+                int targetIndex = parentChildren.IndexOf(target);
+
+                if(currentIndex < 0 || targetIndex < 0 ||
+                    currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count)
+                {
+                    NUILog.Error("index should be bigger than 0 and less than children of layer count");
+                    return;
+                }
+
+                // 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.Layer_RaiseAbove(swigCPtr, Layer.getCPtr(target));
+                    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                }
+            }
         }
 
         internal void LowerBelow(Layer target)
         {
-            NDalicPINVOKE.Layer_LowerBelow(swigCPtr, Layer.getCPtr(target));
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            var parentChildren = Window.Instance.LayersChildren;
+
+            if (parentChildren != null)
+            {
+                int currentIndex = parentChildren.IndexOf(this);
+                int targetIndex = parentChildren.IndexOf(target);
+
+                if(currentIndex < 0 || targetIndex < 0 ||
+                    currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count)
+                {
+                    NUILog.Error("index should be bigger than 0 and less than children of layer count");
+                    return;
+                }
+
+                // 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.Layer_LowerBelow(swigCPtr, Layer.getCPtr(target));
+                    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                }
+            }
         }
 
         /// <summary>
@@ -312,9 +368,10 @@ namespace Tizen.NUI
             {
                 parentChildren.Remove(this);
                 parentChildren.Add(this);
+
+                NDalicPINVOKE.Layer_RaiseToTop(swigCPtr);
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             }
-            NDalicPINVOKE.Layer_RaiseToTop(swigCPtr);
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         /// <summary>
@@ -329,10 +386,11 @@ namespace Tizen.NUI
             {
                 parentChildren.Remove(this);
                 parentChildren.Insert(0, this);
+
+                NDalicPINVOKE.Layer_LowerToBottom(swigCPtr);
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             }
 
-            NDalicPINVOKE.Layer_LowerToBottom(swigCPtr);
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         /// <summary>