[NUI] Modify GetWindowList for getting Native Ptr (#1037)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Window.cs
index 356406c..bf6af72 100755 (executable)
@@ -1,3 +1,5 @@
+
+
 /*
  * Copyright(c) 2019 Samsung Electronics Co., Ltd.
  *
@@ -31,11 +33,8 @@ namespace Tizen.NUI
     {
         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
         private global::System.Runtime.InteropServices.HandleRef stageCPtr;
-        private readonly global::System.Runtime.InteropServices.HandleRef rootLayoutCPtr;
         private Layer _rootLayer;
         private string _windowTitle;
-        private readonly LayoutItem rootLayoutItem;
-
         private List<Layer> _childLayers = new List<Layer>();
         private WindowFocusChangedEventCallbackType _windowFocusChangedEventCallback;
         private RootLayerTouchDataCallbackType _rootLayerTouchDataCallback;
@@ -62,44 +61,36 @@ namespace Tizen.NUI
             {
                 stageCPtr = new global::System.Runtime.InteropServices.HandleRef(this, Interop.Stage.Stage_GetCurrent());
 
-                localController = new LayoutController();
+                localController = new LayoutController(this);
                 NUILog.Debug("layoutController id:" + localController.GetId() );
-
-                // Create a root layout (AbsoluteLayout) that is invisible to the user but enables layouts added to the Window
-                // Enables layouts added to the Window to have a parent layout.  As parent layout is needed to store measure spec properties.
-                // Currently without these measure specs the new layout added will always be the size of the window.
-                global::System.IntPtr rootLayoutIntPtr = Interop.Window.Window_NewRootLayout();
-                // Store HandleRef used by Add()
-                rootLayoutCPtr = new global::System.Runtime.InteropServices.HandleRef(this, rootLayoutIntPtr);
-                Layer rootLayer = GetRootLayer();
-                // Add the root layout created above to the root layer.
-                Interop.Actor.Actor_Add(  Layer.getCPtr(rootLayer), rootLayoutCPtr );
-                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-
-                global::System.IntPtr rootControlLayoutIntPtr = Interop.Layout.GetLayout__SWIG_1(rootLayoutCPtr);
-                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-
-                rootLayoutItem = new LayoutItem(rootControlLayoutIntPtr, true);
             }
         }
 
-        internal Window(Rectangle windowPosition, string name, bool isTransparent) : this(Interop.Window.Window_New__SWIG_0(Rectangle.getCPtr(windowPosition), name, isTransparent), true)
-        {
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-        }
-
-        internal Window(Rectangle windowPosition, string name) : this(Interop.Window.Window_New__SWIG_1(Rectangle.getCPtr(windowPosition), name), true)
-        {
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-        }
-
-        internal Window(Rectangle windowPosition, string name, string className, bool isTransparent) : this(Interop.Window.Window_New__SWIG_2(Rectangle.getCPtr(windowPosition), name, className, isTransparent), true)
+        /// <summary>
+        /// Creates a new Window.<br />
+        /// This creates an extra window in addition to the default main window<br />
+        /// </summary>
+        /// <param name="windowPosition">The position and size of the Window.</param>
+        /// <param name="isTranslucent">Whether Window is translucent.</param>
+        /// <returns>A new Window.</returns>
+        /// <since_tizen> 6 </since_tizen>
+        public Window(Rectangle windowPosition = null , bool isTranslucent = false) : this(Interop.Window.Window_New__SWIG_0(Rectangle.getCPtr(windowPosition), "", isTranslucent), true)
         {
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
-        internal Window(Rectangle windowPosition, string name, string className) : this(Interop.Window.Window_New__SWIG_3(Rectangle.getCPtr(windowPosition), name, className), true)
+        /// <summary>
+        /// Creates a new Window.<br />
+        /// This creates an extra window in addition to the default main window<br />
+        /// </summary>
+        /// <param name="name">The name for extra window. </param>
+        /// <param name="windowPosition">The position and size of the Window.</param>
+        /// <param name="isTranslucent">Whether Window is translucent.</param>
+        /// <returns>A new Window.</returns>
+        /// <since_tizen> 6 </since_tizen>
+        public Window(string name, Rectangle windowPosition = null, bool isTranslucent = false) : this(Interop.Window.Window_New__SWIG_0(Rectangle.getCPtr(windowPosition), name, isTranslucent), true)
         {
+            this._windowTitle = name;
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -640,6 +631,14 @@ namespace Tizen.NUI
             }
         }
 
+        internal LayoutController LayoutController
+        {
+            get
+            {
+                return localController;
+            }
+        }
+
         /// <summary>
         /// Feed a key-event into the window.
         /// </summary>
@@ -974,7 +973,7 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public void Add(View view)
         {
-            Interop.Actor.Actor_Add(rootLayoutCPtr, View.getCPtr(view));
+            Interop.Actor.Actor_Add(Layer.getCPtr(GetRootLayer()), 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();
@@ -987,7 +986,7 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public void Remove(View view)
         {
-            Interop.Actor.Actor_Remove(rootLayoutCPtr, View.getCPtr(view));
+            Interop.Actor.Actor_Remove(Layer.getCPtr(GetRootLayer()), View.getCPtr(view));
             this.GetRootLayer().RemoveViewFromLayerList(view); // Maintain the children list in the Layer
             view.InternalParent = null;
         }
@@ -1012,6 +1011,15 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// Destroy the window immediately.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void Destroy()
+        {
+            this.Dispose();
+        }
+
+        /// <summary>
         /// Keep rendering for at least the given amount of time.
         /// </summary>
         /// <param name="durationSeconds">Time to keep rendering, 0 means render at least one more frame.</param>
@@ -1118,10 +1126,11 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public void AddLayer(Layer layer)
         {
-            Interop.Stage.Stage_Add(stageCPtr, Layer.getCPtr(layer));
+            Interop.Window.Add(swigCPtr, Layer.getCPtr(layer));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
             LayersChildren?.Add(layer);
+            layer.SetWindow(this);
         }
 
         /// <summary>
@@ -1131,10 +1140,11 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public void RemoveLayer(Layer layer)
         {
-            Interop.Stage.Stage_Remove(stageCPtr, Layer.getCPtr(layer));
+            Interop.Window.Remove(swigCPtr, Layer.getCPtr(layer));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
             LayersChildren?.Remove(layer);
+            layer.SetWindow(null);
         }
 
         /// <summary>
@@ -1203,34 +1213,47 @@ namespace Tizen.NUI
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
-        internal void AddAvailableOrientation(Window.WindowOrientation orientation)
-        {
-            Interop.WindowInternal.Window_AddAvailableOrientation(swigCPtr, (int)orientation);
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-        }
-
-        internal void RemoveAvailableOrientation(Window.WindowOrientation orientation)
+        /// <summary>
+        /// Adds an orientation to the list of available orientations.
+        /// </summary>
+        /// <param name="orientation">The available orientation to add</param>
+        /// <since_tizen> 6 </since_tizen>
+        public void AddAvailableOrientation(Window.WindowOrientation orientation)
         {
-            Interop.WindowInternal.Window_RemoveAvailableOrientation(swigCPtr, (int)orientation);
+            Interop.Window.Window_AddAvailableOrientation(swigCPtr, (int)orientation);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
-        internal void SetPreferredOrientation(Window.WindowOrientation orientation)
+        /// <summary>
+        /// Removes an orientation from the list of available orientations.
+        /// </summary>
+        /// <param name="orientation">The available orientation to remove.</param>
+        /// <since_tizen> 6 </since_tizen>
+        public void RemoveAvailableOrientation(Window.WindowOrientation orientation)
         {
-            Interop.WindowInternal.Window_SetPreferredOrientation(swigCPtr, (int)orientation);
+            Interop.Window.Window_RemoveAvailableOrientation(swigCPtr, (int)orientation);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
-        internal Window.WindowOrientation GetPreferredOrientation()
+        /// <summary>
+        /// Sets a preferred orientation.
+        /// </summary>
+        /// <param name="orientation">The preferred orientation.</param>
+        /// <since_tizen> 6 </since_tizen>
+        public void SetPreferredOrientation(Window.WindowOrientation orientation)
         {
-            Window.WindowOrientation ret = (Window.WindowOrientation)Interop.WindowInternal.Window_GetPreferredOrientation(swigCPtr);
+            Interop.Window.Window_SetPreferredOrientation(swigCPtr, (int)orientation);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret;
         }
 
-        internal DragAndDropDetector GetDragAndDropDetector()
+        /// <summary>
+        /// Gets the preferred orientation.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        /// <returns>The preferred orientation if previously set, or none.</returns>
+        public Window.WindowOrientation GetPreferredOrientation()
         {
-            DragAndDropDetector ret = new DragAndDropDetector(Interop.WindowInternal.Window_GetDragAndDropDetector(swigCPtr), true);
+            Window.WindowOrientation ret = (Window.WindowOrientation)Interop.Window.Window_GetPreferredOrientation(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -1251,23 +1274,26 @@ namespace Tizen.NUI
 
         internal void Add(Layer layer)
         {
-            Interop.Stage.Stage_Add(stageCPtr, Layer.getCPtr(layer));
+            Interop.Window.Add(swigCPtr, Layer.getCPtr(layer));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
             LayersChildren?.Add(layer);
+            layer.SetWindow(this);
         }
 
         internal void Remove(Layer layer)
         {
-            Interop.Stage.Stage_Remove(stageCPtr, Layer.getCPtr(layer));
+            Interop.Window.Remove(swigCPtr, Layer.getCPtr(layer));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
             LayersChildren?.Remove(layer);
+            layer.SetWindow(null);
         }
 
         internal Vector2 GetSize()
         {
-            Vector2 ret = new Vector2(Interop.Stage.Stage_GetSize(stageCPtr), true);
+            var val = new Uint16Pair(Interop.Window.GetSize(swigCPtr), false);
+            Vector2 ret = new Vector2(val.GetWidth(), val.GetHeight());
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -1298,22 +1324,23 @@ namespace Tizen.NUI
             // Core has been initialized, not when Stage is ready.
             if (_rootLayer == null && Window.IsInstalled())
             {
-                _rootLayer = new Layer(Interop.Stage.Stage_GetRootLayer(stageCPtr), true);
+                _rootLayer = new Layer(Interop.Window.GetRootLayer(swigCPtr), true);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                 LayersChildren?.Add(_rootLayer);
+                _rootLayer.SetWindow(this);
             }
             return _rootLayer;
         }
 
         internal void SetBackgroundColor(Vector4 color)
         {
-            Interop.Stage.Stage_SetBackgroundColor(stageCPtr, Vector4.getCPtr(color));
+            Interop.Window.SetBackgroundColor(swigCPtr, Vector4.getCPtr(color));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         internal Vector4 GetBackgroundColor()
         {
-            Vector4 ret = new Vector4(Interop.Stage.Stage_GetBackgroundColor(stageCPtr), true);
+            Vector4 ret = new Vector4(Interop.Window.GetBackgroundColor(swigCPtr), true);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -1348,7 +1375,7 @@ namespace Tizen.NUI
 
         internal KeyEventSignal KeyEventSignal()
         {
-            KeyEventSignal ret = new KeyEventSignal(Interop.StageSignal.Stage_KeyEventSignal(stageCPtr), false);
+            KeyEventSignal ret = new KeyEventSignal(Interop.Window.KeyEventSignal(swigCPtr), false);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -1362,7 +1389,7 @@ namespace Tizen.NUI
 
         internal TouchSignal TouchSignal()
         {
-            TouchSignal ret = new TouchSignal(Interop.StageSignal.Stage_TouchSignal(stageCPtr), false);
+            TouchSignal ret = new TouchSignal(Interop.Window.TouchSignal(swigCPtr), false);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -1410,10 +1437,7 @@ namespace Tizen.NUI
 
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
-            if(rootLayoutItem != null)
-            {
-                rootLayoutItem.RequestLayout();
-            }
+            // Resetting Window size should request a relayout of the tree.
         }
 
         internal Size2D GetWindowSize()
@@ -1432,10 +1456,8 @@ namespace Tizen.NUI
 
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
-            if(rootLayoutItem != null)
-            {
-                rootLayoutItem.RequestLayout();
-            }
+            // Setting Position of the window should request a relayout of the tree.
+
         }
 
         internal Position2D GetPosition()
@@ -1453,10 +1475,8 @@ namespace Tizen.NUI
 
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
-            if(rootLayoutItem != null)
-            {
-                rootLayoutItem.RequestLayout();
-            }
+            // Setting Position of the window should request a relayout of the tree.
+
         }
 
         /// <summary>
@@ -1468,10 +1488,88 @@ namespace Tizen.NUI
             Interop.Window.SetTransparency(swigCPtr, transparent);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
-            if(rootLayoutItem != null)
+            // Setting transparency of the window should request a relayout of the tree in the case the window changes from fully transparent.
+
+        }
+
+        /// <summary>
+        /// Sets parent window of the window.
+        /// After setting that, these windows do together when raise-up, lower and iconified/deiconified.
+        /// Initially, the window is located on top of the parent. The window can go below parent by calling Lower().
+        /// If parent's window stack is changed by calling Raise() or Lower(), child windows are located on top of the parent again.
+        /// </summary>
+        /// <param name="parent">The parent window.</param>
+        /// <since_tizen> 6 </since_tizen>
+        public void SetParent(Window parent) {
+            Interop.Window.SetParent(swigCPtr, Window.getCPtr(parent));
+            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>
+        /// <since_tizen> 6 </since_tizen>
+        public void Unparent() {
+            Interop.Window.Unparent(swigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
+        /// Gets parent window of the window.
+        /// </summary>
+        /// <returns>The parent window of the window.</returns>
+        /// <since_tizen> 6 </since_tizen>
+        public Window GetParent() {
+            Window ret = new Window(Interop.Window.GetParent(swigCPtr), true);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        /// <summary>
+        /// Dispose for Window
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected override void Dispose(DisposeTypes type)
+        {
+            if (disposed)
             {
-                rootLayoutItem.RequestLayout();
+                return;
             }
+
+            if (type == DisposeTypes.Explicit)
+            {
+                //Called by User
+                //Release your own managed resources here.
+                //You should release all of your own disposable objects here.
+
+                _rootLayer.Dispose();
+                localController.Dispose();
+
+                foreach(var layer in _childLayers)
+                {
+                    layer.Dispose();
+                }
+                _childLayers.Clear();
+            }
+
+            this.DisconnectNativeSignals();
+
+            //Release your own unmanaged resources here.
+            //You should not access any managed member here except static instance.
+            //because the execution order of Finalizes is non-deterministic.
+
+            if (swigCPtr.Handle != global::System.IntPtr.Zero)
+            {
+                if (swigCMemOwn)
+                {
+                    swigCMemOwn = false;
+                    Interop.Window.delete_Window(swigCPtr);
+                }
+                swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            }
+
+            base.Dispose(type);
         }
 
         internal System.IntPtr GetNativeWindowHandler()