[NUI] Fix RaiseToTop error (#413)
authordongsug-song <35130733+dongsug-song@users.noreply.github.com>
Fri, 24 Aug 2018 04:41:41 +0000 (13:41 +0900)
committerGitHub <noreply@github.com>
Fri, 24 Aug 2018 04:41:41 +0000 (13:41 +0900)
src/Tizen.NUI/src/public/BaseComponents/View.cs
src/Tizen.NUI/src/public/Container.cs
src/Tizen.NUI/src/public/Layer.cs
src/Tizen.NUI/src/public/Window.cs [changed mode: 0644->0755]
test/NUITestSample/NUITestSample/examples/RaiseToTopTest.cs [new file with mode: 0755]

index 3c6b82e..59ee3cb 100755 (executable)
@@ -1275,13 +1275,17 @@ namespace Tizen.NUI.BaseComponents
                 return;
             }
 
-            Container oldParent = child.Parent;
+            Container oldParent = child.GetParent();
             if (oldParent != this)
             {
                 if (oldParent != null)
                 {
                     oldParent.Remove(child);
                 }
+                else
+                {
+                    child.InternalParent = this;
+                }
 
                 if (layoutSet == true && child.Layout == null) // Only give children a layout if parent an explicit container
                 {
@@ -1346,6 +1350,8 @@ namespace Tizen.NUI.BaseComponents
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
             Children.Remove(child);
+            child.InternalParent = null;
+
             if (Layout)
             {
                 if(child.Layout)
@@ -1398,17 +1404,7 @@ namespace Tizen.NUI.BaseComponents
         /// <since_tizen> 4 </since_tizen>
         public override Container GetParent()
         {
-            //to fix memory leak issue, match the handle count with native side.
-            IntPtr cPtr = NDalicPINVOKE.Actor_GetParent(swigCPtr);
-            HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
-            BaseHandle basehandle = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle);
-            NDalicPINVOKE.delete_BaseHandle(CPtr);
-            CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
-
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-
-            return basehandle as Container;
+            return this.InternalParent as Container;
         }
 
         internal bool IsTopLevelView()
index 20f6e89..648d5bb 100755 (executable)
@@ -30,6 +30,7 @@ namespace Tizen.NUI
     {
 
         private List<View> _childViews = new List<View>();
+        internal BaseHandle InternalParent;
 
         /// <summary>
         /// List of children of Container.
index 4316d50..18222c1 100755 (executable)
@@ -59,13 +59,18 @@ namespace Tizen.NUI
         /// <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)
                 {
                     oldParent.Remove(child);
                 }
+                else
+                {
+                    child.InternalParent = this;
+                }
+
                 NDalicPINVOKE.Actor_Add( rootLayoutCPtr , View.getCPtr(child));
                 if (NDalicPINVOKE.SWIGPendingException.Pending)
                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -86,6 +91,7 @@ namespace Tizen.NUI
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
             Children.Remove(child);
+            child.InternalParent = null;
         }
 
         /// <summary>
@@ -272,14 +278,8 @@ namespace Tizen.NUI
 
                 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();
+                    var upper = parentChildren[currentIdx + 1];
+                    RaiseAbove(upper);
                 }
             }
         }
@@ -297,14 +297,8 @@ namespace Tizen.NUI
 
                 if (currentIdx > 0 && currentIdx < parentChildren.Count)
                 {
-                    LowerBelow(parentChildren[currentIdx - 1]);
-
-                    Layer temp = parentChildren[currentIdx - 1];
-                    parentChildren[currentIdx - 1] = this;
-                    parentChildren[currentIdx] = temp;
-
-                    NDalicPINVOKE.Layer_Lower(swigCPtr);
-                    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                    var low = parentChildren[currentIdx - 1];
+                    LowerBelow(low);
                 }
             }
         }
@@ -330,7 +324,7 @@ namespace Tizen.NUI
                     parentChildren.Remove(this);
                     parentChildren.Insert(targetIndex, this);
 
-                    NDalicPINVOKE.Layer_RaiseAbove(swigCPtr, Layer.getCPtr(target));
+                    NDalicPINVOKE.Layer_MoveAbove(swigCPtr, Layer.getCPtr(target));
                     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                 }
             }
@@ -359,7 +353,7 @@ namespace Tizen.NUI
                     parentChildren.Remove(this);
                     parentChildren.Insert(targetIndex, this);
 
-                    NDalicPINVOKE.Layer_LowerBelow(swigCPtr, Layer.getCPtr(target));
+                    NDalicPINVOKE.Layer_MoveBelow(swigCPtr, Layer.getCPtr(target));
                     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                 }
             }
old mode 100644 (file)
new mode 100755 (executable)
index 34ff667..b690242
@@ -611,6 +611,7 @@ namespace Tizen.NUI
             NDalicPINVOKE.Actor_Add( rootLayoutCPtr, View.getCPtr(view) );
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             this.GetRootLayer().AddViewToLayerList(view); // Maintain the children list in the Layer
+            view.InternalParent = this.GetRootLayer();
         }
 
         /// <summary>
@@ -622,6 +623,7 @@ namespace Tizen.NUI
         {
             NDalicPINVOKE.Actor_Remove( rootLayoutCPtr, View.getCPtr(view) );
             this.GetRootLayer().RemoveViewFromLayerList(view); // Maintain the children list in the Layer
+            view.InternalParent = null;
         }
 
         internal Vector2 GetSize()
diff --git a/test/NUITestSample/NUITestSample/examples/RaiseToTopTest.cs b/test/NUITestSample/NUITestSample/examples/RaiseToTopTest.cs
new file mode 100755 (executable)
index 0000000..0c4988f
--- /dev/null
@@ -0,0 +1,135 @@
+using System;
+using Tizen.NUI;
+using Tizen.NUI.BaseComponents;
+
+namespace MyRaiseToTopTest
+{
+    class Example : NUIApplication
+    {
+        TextLabel layer1Text, layer2Text, rootLayerText;
+        Window window;
+        View[] layer1Views = new View[3];
+        View[] layer2Views = new View[3];
+        View[] rootLayerViews = new View[3];
+        Layer layer1, layer2, rootLayer;
+
+        protected override void OnCreate()
+        {
+            base.OnCreate();
+            Initialize();
+        }
+        public void Initialize()
+        {
+            window = Window.Instance;
+            window.KeyEvent += OnWindowKeyEvent;
+            window.BackgroundColor = Color.Yellow;
+
+            const int viewSize = 80;
+            const int startPos = 30;
+
+            //rootLayer
+            rootLayer = window.GetDefaultLayer();
+            for(int i = 0; i < 3; i++)
+            {
+                rootLayerViews[i] = new View();
+                rootLayerViews[i].Size2D = new Size2D(viewSize, viewSize);
+                rootLayerViews[i].Position2D = new Position2D(1 + i*viewSize/3, startPos + i*viewSize/3);
+                rootLayerViews[i].BackgroundColor = new Color( (255.0f - i*85.0f)/255.0f, 0.0f, 0.0f, 1.0f);
+                rootLayer.Add(rootLayerViews[i]);
+            }
+            rootLayerText = new TextLabel(rootLayer.Name);
+            rootLayerText.PointSize = 10;
+            rootLayerText.Position2D = new Position2D(1, 1);
+            rootLayerText.BackgroundColor = new Color(1.0f, 0.0f, 0.0f, 1.0f);
+            rootLayer.Add(rootLayerText);
+
+            //layer1
+            layer1 = new Layer();
+            layer1.Name = "Layer1";
+            for(int i = 0; i < 3; i++)
+            {
+                layer1Views[i] = new View();
+                layer1Views[i].Size2D = new Size2D(viewSize, viewSize);
+                layer1Views[i].Position2D = new Position2D(startPos + i*viewSize/3, startPos + i*viewSize/3);
+                layer1Views[i].BackgroundColor = new Color( 0.0f, (255.0f - i*85.0f)/255.0f, 0.0f, 1.0f);
+                layer1.Add(layer1Views[i]);
+            }
+            layer1Text = new TextLabel(layer1.Name);
+            layer1Text.PointSize = 10;
+            layer1Text.Position2D = new Position2D(2, 1);
+            layer1Text.BackgroundColor = new Color(0.0f, 1.0f, 0.0f, 1.0f);
+            layer1.Add(layer1Text);
+            window.AddLayer(layer1);
+
+            //layer2
+            layer2 = new Layer();
+            layer2.Name = "Layer2";
+            for(int i = 0; i < 3; i++)
+            {
+                layer2Views[i] = new View();
+                layer2Views[i].Size2D = new Size2D(viewSize, viewSize);
+                layer2Views[i].Position2D = new Position2D(startPos*2 + i*viewSize/3, startPos + i*viewSize/3);
+                layer2Views[i].BackgroundColor = new Color( 0.0f, 0.0f, (255.0f - i*85.0f)/255.0f, 1.0f);
+                layer2.Add(layer2Views[i]);
+            }
+            layer2Text = new TextLabel(layer2.Name);
+            layer2Text.PointSize = 10;
+            layer2Text.Position2D = new Position2D(3, 1);
+            layer2Text.BackgroundColor = new Color(0.0f, 0.0f, 1.0f, 1.0f);
+            layer2.Add(layer2Text);
+            window.AddLayer(layer2);
+
+        }
+
+        int win_test;
+        public void OnWindowKeyEvent(object sender, Window.KeyEventArgs e)
+        {
+            if (e.Key.State == Key.StateType.Down)
+            {
+                if (e.Key.KeyPressedName == "Up")
+                {
+                    layer1.Raise();
+                }
+                else if (e.Key.KeyPressedName == "Down")
+                {
+                    layer1.Lower();
+                }
+                else if (e.Key.KeyPressedName == "Right")
+                {
+                    layer1.RaiseToTop();
+                }
+                else if (e.Key.KeyPressedName == "Left")
+                {
+                    layer1.LowerToBottom();
+                }
+                else if (e.Key.KeyPressedName == "Return")
+                {
+                }
+                else if (e.Key.KeyPressedName == "1")
+                {
+                    layer1Views[0].RaiseToTop();
+                }
+                else if (e.Key.KeyPressedName == "2")
+                {
+                    layer1Views[0].Raise();
+                }
+                else if (e.Key.KeyPressedName == "3")
+                {
+                    layer1Views[0].Lower();
+                }
+                else if (e.Key.KeyPressedName == "4")
+                {
+                    layer1Views[0].LowerToBottom();
+                }
+            }
+        }
+
+        [STAThread]
+        static void _Main(string[] args)
+        {
+            Example example = new Example();
+            example.Run(args);
+        }
+    }
+}
+