Merge remote-tracking branch 'origin/master' into tizen
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / ViewPublicMethods.cs
index 0760e9e..f78edcb 100755 (executable)
@@ -1,5 +1,5 @@
-/*
- * Copyright(c) 2020 Samsung Electronics Co., Ltd.
+/*
+ * Copyright(c) 2022 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.
@@ -151,12 +151,14 @@ namespace Tizen.NUI.BaseComponents
                     oldParent.Remove(child);
                 }
                 child.InternalParent = this;
+                LayoutCount += child.LayoutCount;
 
                 Interop.Actor.Add(SwigCPtr, View.getCPtr(child));
 
                 if (NDalicPINVOKE.SWIGPendingException.Pending)
                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                 Children.Add(child);
+                OnChildAdded(child);
 
                 if (ChildAdded != null)
                 {
@@ -166,7 +168,6 @@ namespace Tizen.NUI.BaseComponents
                     };
                     ChildAdded(this, e);
                 }
-                BindableObject.SetInheritedBindingContext(child, this?.BindingContext);
             }
         }
 
@@ -185,6 +186,7 @@ namespace Tizen.NUI.BaseComponents
             {
                 //throw new System.InvalidOperationException("You have deleted a view that is not a child of this view.");
                 Tizen.Log.Error("NUI", "You have deleted a view that is not a child of this view.");
+                return;
             }
 
             bool hasLayout = (layout != null);
@@ -235,7 +237,7 @@ namespace Tizen.NUI.BaseComponents
         /// <since_tizen> 4 </since_tizen>
         public override Container GetParent()
         {
-            return this.InternalParent as Container;
+            return InternalParent as Container;
         }
 
         /// <summary>
@@ -302,10 +304,17 @@ namespace Tizen.NUI.BaseComponents
         /// <since_tizen> 3 </since_tizen>
         public void Show()
         {
-            if (AccessibilityCalculateStates().Get(AccessibilityState.Modal))
-                AddPopup();
-
             SetVisible(true);
+
+            if (GetAccessibilityStates()[AccessibilityState.Modal])
+            {
+                RegisterDefaultLabel();
+
+                if (Accessibility.Accessibility.IsEnabled)
+                {
+                    EmitAccessibilityStateChangedEvent(AccessibilityState.Showing, true);
+                }
+            }
         }
 
         /// <summary>
@@ -321,8 +330,15 @@ namespace Tizen.NUI.BaseComponents
         {
             SetVisible(false);
 
-            if (AccessibilityCalculateStates().Get(AccessibilityState.Modal))
-                RemovePopup();
+            if (GetAccessibilityStates()[AccessibilityState.Modal])
+            {
+                UnregisterDefaultLabel();
+
+                if (Accessibility.Accessibility.IsEnabled)
+                {
+                    EmitAccessibilityStateChangedEvent(AccessibilityState.Showing, false);
+                }
+            }
         }
 
         /// <summary>
@@ -475,7 +491,6 @@ namespace Tizen.NUI.BaseComponents
         /// <param name="width">The width to use.</param>
         /// <returns>The height based on the width.</returns>
         /// <since_tizen> 3 </since_tizen>
-        [Obsolete("Deprecated in API9, will be removed in API11. Please use HeightForWidth property instead!")]
         public float GetHeightForWidth(float width)
         {
             float ret = Interop.Actor.GetHeightForWidth(SwigCPtr, width);
@@ -492,7 +507,6 @@ namespace Tizen.NUI.BaseComponents
         /// <param name="height">The height to use.</param>
         /// <returns>The width based on the height.</returns>
         /// <since_tizen> 3 </since_tizen>
-        [Obsolete("Deprecated in API9, will be removed in API11. Please use WidthForHeight property instead!")]
         public float GetWidthForHeight(float height)
         {
             float ret = Interop.Actor.GetWidthForHeight(SwigCPtr, height);
@@ -633,17 +647,6 @@ namespace Tizen.NUI.BaseComponents
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
-
-
-        /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public Transition GetTransition(string transitionName)
-        {
-            Transition trans = null;
-            transDictionary.TryGetValue(transitionName, out trans);
-            return trans;
-        }
-
         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
         [EditorBrowsable(EditorBrowsableState.Never)]
         public void ObjectDump()
@@ -675,6 +678,7 @@ namespace Tizen.NUI.BaseComponents
         /// <param name="id">The ID of the View to find</param>
         /// <returns>A View if found or a null if not</returns>
         [EditorBrowsable(EditorBrowsableState.Never)]
+        [Obsolete("This will be removed at API11! please use FindDescendantByID(uint id) instead!")]
         public View FindChildByID(uint id)
         {
             IntPtr cPtr = Interop.Actor.FindChildById(SwigCPtr, id);
@@ -683,5 +687,144 @@ namespace Tizen.NUI.BaseComponents
             return ret;
         }
 
+        /// <summary>
+        /// Search through this View's hierarchy for a View with the given unique ID.
+        /// </summary>
+        /// <param name="id">The ID of the View to find.</param>
+        /// <returns>A handle to the View if found, or an empty handle if not.</returns>
+        /// <since_tizen> 9 </since_tizen>
+        public View FindDescendantByID(uint id)
+        {
+            return FindChildById(id);
+        }
+
+        /// <summary>
+        /// Raise view above the next sibling view.
+        /// </summary>
+        /// <since_tizen> 9 </since_tizen>
+        public void Raise()
+        {
+            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 >= 0 && currentIndex < parentChildren.Count - 1)
+                {
+                    View temp = parentChildren[currentIndex + 1];
+                    parentChildren[currentIndex + 1] = this;
+                    parentChildren[currentIndex] = temp;
+
+                    Interop.NDalic.Raise(SwigCPtr);
+                    if (NDalicPINVOKE.SWIGPendingException.Pending)
+                        throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                }
+            }
+        }
+
+        /// <summary>
+        /// Lower the view below the previous sibling view.
+        /// </summary>
+        /// <since_tizen> 9 </since_tizen>
+        public void Lower()
+        {
+            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 && currentIndex < parentChildren.Count)
+                {
+                    View temp = parentChildren[currentIndex - 1];
+                    parentChildren[currentIndex - 1] = this;
+                    parentChildren[currentIndex] = temp;
+
+                    Interop.NDalic.Lower(SwigCPtr);
+                    if (NDalicPINVOKE.SWIGPendingException.Pending)
+                        throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                }
+            }
+        }
+
+        /// <summary>
+        /// Raises the view to above the target view.
+        /// </summary>
+        /// <remarks>The sibling order of views within the parent will be updated automatically.
+        /// Views on the level above the target view will still be shown above this view.
+        /// Once a raise or lower API is used then that view will have an exclusive sibling order independent of insertion.
+        /// </remarks>
+        /// <param name="target">Will be raised above this view.</param>
+        /// <since_tizen> 9 </since_tizen>
+        public void RaiseAbove(View target)
+        {
+            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);
+
+                    Interop.NDalic.RaiseAbove(SwigCPtr, View.getCPtr(target));
+                    if (NDalicPINVOKE.SWIGPendingException.Pending)
+                        throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                }
+            }
+
+        }
+
+        /// <summary>
+        /// Lowers the view to below the target view.
+        /// </summary>
+        /// <remarks>The sibling order of views within the parent will be updated automatically.
+        /// Once a raise or lower API is used then that view will have an exclusive sibling order independent of insertion.
+        /// </remarks>
+        /// <param name="target">Will be lowered below this view.</param>
+        /// <since_tizen> 9 </since_tizen>
+        public void LowerBelow(View target)
+        {
+            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) &&
+                    (currentIndex > targetIndex))
+                {
+                    parentChildren.Remove(this);
+                    parentChildren.Insert(targetIndex, this);
+
+                    Interop.NDalic.LowerBelow(SwigCPtr, View.getCPtr(target));
+                    if (NDalicPINVOKE.SWIGPendingException.Pending)
+                        throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                }
+            }
+
+        }
+
     }
 }