[NUI] Add protected codes for SiblingOrder (#89)
authorhuiyueun <35286162+huiyueun@users.noreply.github.com>
Mon, 29 Jan 2018 02:19:37 +0000 (11:19 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Mon, 29 Jan 2018 02:19:37 +0000 (11:19 +0900)
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 0e3ae04..762bc29 100755 (executable)
@@ -49,7 +49,7 @@ namespace Tizen.NUI.BaseComponents
         /// <since_tizen> 4 </since_tizen>
         public override void Add(View child)
         {
-            Container oldParent = child.Parent;
+            Container oldParent = child.GetParent();
             if(oldParent != this)
             {
                 if (oldParent != null)
@@ -2246,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>
@@ -2255,7 +2255,7 @@ namespace Tizen.NUI.BaseComponents
         {
             get
             {
-                var parentChildren = Parent?.Children;
+                var parentChildren = GetParent()?.Children;
                 int currentOrder = 0;
                 if (parentChildren != null)
                 {
@@ -2275,11 +2275,15 @@ namespace Tizen.NUI.BaseComponents
             }
             set
             {
-                var siblings = Parent?.Children;
+                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)
@@ -2378,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>
@@ -2430,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>
@@ -2453,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>
@@ -2490,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>
@@ -2520,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) &&
@@ -2533,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()
@@ -3744,22 +3764,6 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
-
-        /// <summary>
-        /// [Obsolete("Please do not use! this will be deprecated. Please use Visibility instead.")]
-        /// </summary>
-        /// <since_tizen> 3 </since_tizen>
-        [Obsolete("Please do not use! This will be deprecated! Please use Visibility instead!")]
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public bool Visible
-        {
-            get
-            {
-                return IsVisible();
-            }
-        }
-
-
         /// <summary>
         /// Gets the view's world color.
         /// </summary>
index 9264686..37efd13 100755 (executable)
@@ -261,17 +261,18 @@ 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();
                 }
             }
-            NDalicPINVOKE.Layer_Raise(swigCPtr);
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         /// <summary>
@@ -285,7 +286,7 @@ namespace Tizen.NUI
             {
                 int currentIdx = parentChildren.IndexOf(this);
 
-                if (currentIdx > 0)
+                if (currentIdx > 0 && currentIdx < parentChildren.Count)
                 {
                     LowerBelow(parentChildren[currentIdx - 1]);
 
@@ -293,10 +294,10 @@ namespace Tizen.NUI
                     parentChildren[currentIdx - 1] = this;
                     parentChildren[currentIdx] = temp;
 
+                    NDalicPINVOKE.Layer_Lower(swigCPtr);
+                    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                 }
             }
-            NDalicPINVOKE.Layer_Lower(swigCPtr);
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         internal void RaiseAbove(Layer target)
@@ -307,15 +308,23 @@ namespace Tizen.NUI
                 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();
                 }
             }
-            NDalicPINVOKE.Layer_RaiseAbove(swigCPtr, Layer.getCPtr(target));
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         internal void LowerBelow(Layer target)
@@ -327,16 +336,24 @@ namespace Tizen.NUI
                 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();
                 }
             }
-            NDalicPINVOKE.Layer_LowerBelow(swigCPtr, Layer.getCPtr(target));
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         /// <summary>
@@ -351,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>
@@ -368,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>