[NUI] Add LazyFeedHover api for HoverEvent
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Window / Window.cs
index c39da9b..a6c6c42 100755 (executable)
@@ -36,10 +36,14 @@ namespace Tizen.NUI
     {
         private HandleRef stageCPtr;
         private Layer rootLayer;
+        private Layer overlayLayer;
         private Layer borderLayer;
         private string windowTitle;
         private List<Layer> childLayers = new List<Layer>();
         private LayoutController localController;
+        private Key internalLastKeyEvent;
+        private Touch internalLastTouchEvent;
+        private Timer internalHoverTimer;
 
         static internal bool IsSupportedMultiWindow()
         {
@@ -552,7 +556,7 @@ namespace Tizen.NUI
             {
                 Position2D position = GetPosition();
                 Size2D size = GetSize();
-                Rectangle ret = new Rectangle(position.X, position.Y, size.Width, size.Height);
+                Rectangle ret = new Rectangle(position?.X ?? 0, position?.Y ?? 0, size?.Width ?? 0, size?.Height ?? 0);
                 position.Dispose();
                 return ret;
             }
@@ -770,7 +774,7 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public void SetInputRegion(Rectangle inputRegion)
         {
-            Interop.Window.IncludeInputRegion(SwigCPtr, Rectangle.getCPtr(inputRegion));
+            Interop.Window.SetInputRegion(SwigCPtr, Rectangle.getCPtr(inputRegion));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -931,6 +935,25 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// Gets the overlay layer.
+        /// </summary>
+        /// <returns>The overlay layer.</returns>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Layer GetOverlayLayer()
+        {
+            // Window.IsInstalled() is actually true only when called from event thread and
+            // Core has been initialized, not when Stage is ready.
+            if (overlayLayer == null && Window.IsInstalled())
+            {
+                overlayLayer = new Layer(Interop.Window.GetOverlayLayer(SwigCPtr), true);
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                LayersChildren?.Add(overlayLayer);
+                overlayLayer.SetWindow(this);
+            }
+            return overlayLayer;
+        }
+
+        /// <summary>
         /// Add a child view to window.
         /// </summary>
         /// <param name="view">the child should be added to the window.</param>
@@ -985,7 +1008,7 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public void KeepRendering(float durationSeconds)
         {
-            Interop.Stage.KeepRendering(stageCPtr, durationSeconds);
+            Interop.Window.KeepRendering(SwigCPtr, durationSeconds);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -1112,6 +1135,36 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// Feeds a hover event into the window. <br />
+        /// This is feed after a default time of 48 ms. You can also set this time.
+        /// </summary>
+        /// <param name="time">The time of how much later it will be feed (default is 48ms)</param>
+        /// <remarks>If you want to do FeedHover after the UI is updated, it is recommended to set the time to at least 16ms. This will be a good time waiting for the UI to update.<br />
+        /// and LazyFeedHover called within the set time are ignored. Only the last request becomes a FeedHover.
+        /// </remarks>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void LazyFeedHover(uint time = 48)
+        {
+            if (internalHoverTimer == null)
+            {
+                internalHoverTimer = new Timer(time);
+                internalHoverTimer.Tick += (s, e) =>
+                {
+                    FeedHover();
+                    internalHoverTimer?.Stop();
+                    internalHoverTimer?.Dispose();
+                    internalHoverTimer = null;
+                    return false;
+                };
+                internalHoverTimer.Start();
+            }
+            else
+            {
+                internalHoverTimer.Start();
+            }
+        }
+
+        /// <summary>
         /// Feeds a touch point into the window.
         /// </summary>
         /// <param name="touchPoint">The touch point to feed.</param>
@@ -1133,6 +1186,23 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// Feeds a hover event into the window.
+        /// </summary>
+        /// <param name="touchPoint">The touch point to feed hover event. If null is entered, the feed hover event is generated with the last inputed touch point.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        internal void FeedHover(TouchPoint touchPoint = null)
+        {
+            if (touchPoint == null)
+            {
+                using Touch touch = GetLastTouchEvent();
+                using Vector2 screenPosition = touch.GetScreenPosition(0);
+                touchPoint = new TouchPoint(touch.GetDeviceId(0), TouchPoint.StateType.Motion, screenPosition.X, screenPosition.Y);
+            }
+            Interop.Window.FeedHoverEvent(SwigCPtr, TouchPoint.getCPtr(touchPoint));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
         /// Allows at least one more render, even when paused.
         /// The window should be shown, not minimised.
         /// </summary>
@@ -1363,7 +1433,7 @@ namespace Tizen.NUI
 
             if (isBorderWindow)
             {
-                Interop.Actor.Add(GetBorderWindowRootLayer().SwigCPtr, layer.SwigCPtr);
+                Interop.Actor.Add(GetRootLayer().SwigCPtr, layer.SwigCPtr);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) { throw NDalicPINVOKE.SWIGPendingException.Retrieve(); }
             }
             else
@@ -1734,6 +1804,83 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// Sets the layout of the window.
+        /// </summary>
+        /// <param name="numCols">The number of columns in the layout.</param>
+        /// <param name="numRows">The number of rows in the layout.</param>
+        /// <param name="column">The column number of the window within the layout.</param>
+        /// <param name="row">The row number of the window within the layout.</param>
+        /// <param name="colSpan">The number of columns the window should span within the layout.</param>
+        /// <param name="rowSpan">The number of rows the window should span within the layout.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SetLayout(uint numCols, uint numRows, uint column, uint row, uint colSpan, uint rowSpan)
+        {
+            Interop.Window.SetLayout(SwigCPtr, numCols, numRows, column, row, colSpan, rowSpan);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+
+        }
+
+        /// <summary>
+        /// Sets the layout of the window.
+        /// </summary>
+        /// <param name="layoutType">The type of layout to set for the window.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SetLayout(WindowLayoutType layoutType)
+        {
+            switch (layoutType)
+            {
+                case WindowLayoutType.LeftHalf:
+                    Interop.Window.SetLayout(SwigCPtr, 2, 1, 0, 0, 1, 1);
+                    break;
+                case WindowLayoutType.RightHalf:
+                    Interop.Window.SetLayout(SwigCPtr, 2, 1, 1, 0, 1, 1);
+                    break;
+
+                case WindowLayoutType.TopHalf:
+                    Interop.Window.SetLayout(SwigCPtr, 1, 2, 0, 0, 1, 1);
+                    break;
+                case WindowLayoutType.BottomHalf:
+                    Interop.Window.SetLayout(SwigCPtr, 1, 2, 0, 1, 1, 1);
+                    break;
+
+                case WindowLayoutType.UpperLeftQuarter:
+                    Interop.Window.SetLayout(SwigCPtr, 2, 2, 0, 0, 1, 1);
+                    break;
+                case WindowLayoutType.UpperRightQuarter:
+                    Interop.Window.SetLayout(SwigCPtr, 2, 2, 1, 0, 1, 1);
+                    break;
+                case WindowLayoutType.LowerLeftQuarter:
+                    Interop.Window.SetLayout(SwigCPtr, 2, 2, 0, 1, 1, 1);
+                    break;
+                case WindowLayoutType.LowerRightQuarter:
+                    Interop.Window.SetLayout(SwigCPtr, 2, 2, 1, 1, 1, 1);
+                    break;
+
+                case WindowLayoutType.LeftThird:
+                    Interop.Window.SetLayout(SwigCPtr, 3, 1, 0, 0, 1, 1);
+                    break;
+                case WindowLayoutType.CenterThird:
+                    Interop.Window.SetLayout(SwigCPtr, 3, 1, 1, 0, 1, 1);
+                    break;
+                case WindowLayoutType.RightThird:
+                    Interop.Window.SetLayout(SwigCPtr, 3, 1, 2, 0, 1, 1);
+                    break;
+
+                case WindowLayoutType.TopThird:
+                    Interop.Window.SetLayout(SwigCPtr, 1, 3, 0, 0, 1, 1);
+                    break;
+                case WindowLayoutType.MiddleThird:
+                    Interop.Window.SetLayout(SwigCPtr, 1, 3, 0, 1, 1, 1);
+                    break;
+                case WindowLayoutType.BottomThird:
+                    Interop.Window.SetLayout(SwigCPtr, 1, 3, 0, 2, 1, 1);
+                    break;
+            }
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+
+        }
+
+        /// <summary>
         /// Query whether window is rotating or not.
         /// </summary>
         /// <returns>True if window is rotating, false otherwise.</returns>
@@ -1752,9 +1899,13 @@ namespace Tizen.NUI
         [EditorBrowsable(EditorBrowsableState.Never)]
         public Key GetLastKeyEvent()
         {
-            Key ret = new Key(Interop.Window.GetLastKeyEvent(SwigCPtr), false);
+            if(internalLastKeyEvent == null)
+            {
+                internalLastKeyEvent = new Key();
+            }
+            Interop.Window.InternalRetrievingLastKeyEvent(SwigCPtr, internalLastKeyEvent.SwigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret;
+            return internalLastKeyEvent;
         }
 
         /// <summary>
@@ -1764,9 +1915,41 @@ namespace Tizen.NUI
         [EditorBrowsable(EditorBrowsableState.Never)]
         public Touch GetLastTouchEvent()
         {
-            Touch ret = new Touch(Interop.Window.GetLastTouchEvent(SwigCPtr), false);
+            if(internalLastTouchEvent == null)
+            {
+                internalLastTouchEvent = new Touch();
+            }
+            Interop.Window.InternalRetrievingLastTouchEvent(SwigCPtr, internalLastTouchEvent.SwigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return internalLastTouchEvent;
+        }
+
+        /// <summary>
+        /// Sets the necessary for window rotation Acknowledgement.
+        /// After this function called, SendRotationCompletedAcknowledgement() should be called to complete window rotation.
+        ///
+        /// This function is supprot that application has the window rotation acknowledgement's control.
+        /// It means display server waits when application's rotation work is finished.
+        /// It is useful application has the other rendering engine which works asynchronous.
+        /// For instance, GlView.
+        /// </summary>
+        /// <param name="needAcknowledgement">the flag is true if window rotation acknowledge is sent.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement)
+        {
+            Interop.Window.SetNeedsRotationCompletedAcknowledgement(SwigCPtr, needAcknowledgement);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
+        /// send the Acknowledgement to complete window rotation.
+        /// For this function, SetNeedsRotationCompletedAcknowledgement should be already called with true.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SendRotationCompletedAcknowledgement()
+        {
+            Interop.Window.SendRotationCompletedAcknowledgement(SwigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret;
         }
 
         /// <summary>
@@ -1797,7 +1980,7 @@ namespace Tizen.NUI
             {
                 return;
             }
-            
+
             this.DisconnectNativeSignals();
 
             if (type == DisposeTypes.Explicit)
@@ -1822,6 +2005,15 @@ namespace Tizen.NUI
                 childLayers.Clear();
 
                 localController?.Dispose();
+
+                internalLastKeyEvent?.Dispose();
+                internalLastKeyEvent = null;
+                internalLastTouchEvent?.Dispose();
+                internalLastTouchEvent = null;
+
+                internalHoverTimer?.Stop();
+                internalHoverTimer?.Dispose();
+                internalHoverTimer = null;
             }