[NUI] Add new SetParent in Window
authorWonsik Jung <sidein@samsung.com>
Mon, 13 Sep 2021 04:04:09 +0000 (13:04 +0900)
committerSeoyeon2Kim <34738918+Seoyeon2Kim@users.noreply.github.com>
Mon, 13 Sep 2021 07:33:23 +0000 (16:33 +0900)
Add new SetParent in Window.
This method has the input flag is whether the child is located above or below of the parent.

src/Tizen.NUI/src/internal/Interop/Interop.Window.cs
src/Tizen.NUI/src/public/Window/Window.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/SubWindowTest.cs
test/Tizen.NUI.Tests/Tizen.NUI.TCT/testcase/public/Window/TSWindow.cs

index 8c379aa..b11bb3a 100755 (executable)
@@ -236,6 +236,9 @@ namespace Tizen.NUI
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Window_SetParent")]
             public static extern void SetParent(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Window_SetParent_With_Stack")]
+            public static extern void SetParentWithStack(global::System.Runtime.InteropServices.HandleRef child, global::System.Runtime.InteropServices.HandleRef parent, bool belowParent);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Window_Unparent")]
             public static extern void Unparent(global::System.Runtime.InteropServices.HandleRef jarg1);
 
index 6c36f1e..a975583 100644 (file)
@@ -1125,6 +1125,26 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// Sets parent window of the window.
+        /// After setting that, these windows do together when raise-up, lower and iconified/deiconified.
+        /// This function has the additional flag whether the child is located above or below of the parent.
+        /// </summary>
+        /// <param name="parent">The parent window.</param>
+        /// <param name="belowParent">The flag is whether the child is located above or below of the parent.</param>
+        /// <feature> http://tizen.org/feature/opengles.surfaceless_context </feature>
+        /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SetParent(Window parent, bool belowParent)
+        {
+            if (IsSupportedMultiWindow() == false)
+            {
+                NUILog.Error("This device does not support surfaceless_context. So Window cannot be created. ");
+            }
+            Interop.Window.SetParentWithStack(SwigCPtr, Window.getCPtr(parent), belowParent);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
         /// Unsets parent window of the window.
         /// After unsetting, the window is disconnected his parent window.
         /// </summary>
index 8e3ac6a..c94e666 100755 (executable)
@@ -13,13 +13,17 @@ namespace Tizen.NUI.Samples
         Window mainWin;
         Window subWin1;
         Window subWin2;
+        Window subWin3;
         Timer tm;
+        bool belowParent;
         void Initialize()
         {
             mainWin = NUIApplication.GetDefaultWindow();
             mainWin.KeyEvent += OnKeyEvent;
             mainWin.BackgroundColor = Color.Cyan;
             mainWin.WindowSize = new Size2D(500, 500);
+            mainWin.TouchEvent += WinTouchEvent;
+            belowParent = false;
 
             TextLabel text = new TextLabel("Hello Tizen NUI World");
             text.HorizontalAlignment = HorizontalAlignment.Center;
@@ -39,6 +43,72 @@ namespace Tizen.NUI.Samples
             log.Fatal(tag, "animation play!");
         }
 
+        void CreateSubWin3()
+        {
+            if(subWin3)
+            {
+                log.Fatal(tag, $"Sub Window3 is already created");
+                return;
+            }
+            subWin3 = new Window("subWin3", new Rectangle(0, 0, 300, 300), false);
+            subWin3.BackgroundColor = Color.Blue;
+            View dummy = new View()
+            {
+                Size = new Size(100, 100),
+                Position = new Position(50, 50),
+                BackgroundColor = Color.Yellow,
+            };
+            subWin3.Add(dummy);
+            subWin3.KeyEvent += subWin3_KeyEvent;
+        }
+
+        void SetParentAbove()
+        {
+            CreateSubWin3();
+            subWin3.SetParent(mainWin, false);
+        }
+
+        void SetParentBelow()
+        {
+            CreateSubWin3();
+            subWin3.SetParent(mainWin, true);
+        }
+
+        public void subWin3_KeyEvent(object sender, Window.KeyEventArgs e)
+        {
+            if (e.Key.State == Key.StateType.Down)
+            {
+                log.Fatal(tag, $"key down! key={e.Key.KeyPressedName}");
+
+                switch (e.Key.KeyPressedName)
+                {
+                    case "6":
+                        SetParentAbove();
+                        break;
+                    case "7":
+                        SetParentBelow();
+                        break;
+                }
+            }
+        }
+
+        public void WinTouchEvent(object sender, Window.TouchEventArgs e)
+        {
+            if (e.Touch.GetState(0) == PointStateType.Up)
+            {
+                if(belowParent == false)
+                {
+                    SetParentBelow();
+                    belowParent = true;
+                }
+                else
+                {
+                    SetParentAbove();
+                    belowParent = false;
+                }
+            }
+        }
+
         public void OnKeyEvent(object sender, Window.KeyEventArgs e)
         {
             if (e.Key.State == Key.StateType.Down)
@@ -72,6 +142,14 @@ namespace Tizen.NUI.Samples
                         TestCase5();
                         break;
 
+                    case "6":
+                        SetParentAbove();
+                        break;
+
+                    case "7":
+                        SetParentBelow();
+                        break;
+
                     default:
                         log.Fatal(tag, $"no test!");
                         break;
index 11a5a94..2c0f29d 100755 (executable)
@@ -509,5 +509,103 @@ namespace Tizen.NUI.Devel.Tests
             tlog.Debug(tag, $"WindowAddFramePresentedCallback END (OK)");
             Assert.Pass("WindowAddFramePresentedCallback");
         }
+
+        [Test]
+        [Category("P1")]
+        [Description("Window SetParent Test")]
+        [Property("SPEC", "Tizen.NUI.Window.SetParent M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        public void WindowSetParentTest()
+        {
+            tlog.Debug(tag, $"WindowSetParentTest START");
+            try
+            {
+                Window subWin = new Window("subWin", new Rectangle(0, 0, 300, 300), false);
+                subWin.BackgroundColor = Color.Blue;
+                View dummy = new View()
+                {
+                    Size = new Size(100, 100),
+                    Position = new Position(50, 50),
+                    BackgroundColor = Color.Yellow,
+                };
+                subWin.Add(dummy);
+
+                SetParent(myWin);
+            }
+            catch (Exception e)
+            {
+                Tizen.Log.Error(tag, "Caught Exception" + e.ToString());
+
+                Assert.Fail("Caught Exception" + e.ToString());
+            }
+            tlog.Debug(tag, $"WindowSetParentTest END (OK)");
+            Assert.Pass("WindowSetParentTest");
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Window SetParent Below Test")]
+        [Property("SPEC", "Tizen.NUI.Window.SetParent M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        public void WindowSetParentBelowTest()
+        {
+            tlog.Debug(tag, $"WindowSetParentBelowTest START");
+            try
+            {
+                Window subWin = new Window("subWin", new Rectangle(0, 0, 300, 300), false);
+                subWin.BackgroundColor = Color.Blue;
+                View dummy = new View()
+                {
+                    Size = new Size(100, 100),
+                    Position = new Position(50, 50),
+                    BackgroundColor = Color.Yellow,
+                };
+                subWin.Add(dummy);
+
+                SetParent(myWin, true);
+            }
+            catch (Exception e)
+            {
+                Tizen.Log.Error(tag, "Caught Exception" + e.ToString());
+
+                Assert.Fail("Caught Exception" + e.ToString());
+            }
+            tlog.Debug(tag, $"WindowSetParentBelowTest END (OK)");
+            Assert.Pass("WindowSetParentBelowTest");
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Window SetParent Above Test")]
+        [Property("SPEC", "Tizen.NUI.Window.SetParent M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        public void WindowSetParentAboveTest()
+        {
+            tlog.Debug(tag, $"WindowSetParentAboveTest START");
+            try
+            {
+                Window subWin = new Window("subWin", new Rectangle(0, 0, 300, 300), false);
+                subWin.BackgroundColor = Color.Blue;
+                View dummy = new View()
+                {
+                    Size = new Size(100, 100),
+                    Position = new Position(50, 50),
+                    BackgroundColor = Color.Yellow,
+                };
+                subWin.Add(dummy);
+
+                SetParent(myWin, false);
+            }
+            catch (Exception e)
+            {
+                Tizen.Log.Error(tag, "Caught Exception" + e.ToString());
+
+                Assert.Fail("Caught Exception" + e.ToString());
+            }
+            tlog.Debug(tag, $"WindowSetParentAboveTest END (OK)");
+           
     }
 }
\ No newline at end of file