[NUI] Binding PointerConstraintsEvent
authorjoogab.yun <joogab.yun@samsung.com>
Fri, 8 Sep 2023 05:11:44 +0000 (14:11 +0900)
committerJoogabYun <40262755+JoogabYun@users.noreply.github.com>
Mon, 11 Sep 2023 07:30:31 +0000 (16:30 +0900)
src/Tizen.NUI/src/internal/Interop/Interop.PointerConstraints.cs [new file with mode: 0755]
src/Tizen.NUI/src/internal/Interop/Interop.WindowPointerConstraintsSignal.cs [new file with mode: 0755]
src/Tizen.NUI/src/internal/Window/WindowPointerConstraintsSignal.cs [new file with mode: 0755]
src/Tizen.NUI/src/public/Window/PointerConstraints.cs [new file with mode: 0755]
src/Tizen.NUI/src/public/Window/WindowEvent.cs

diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.PointerConstraints.cs b/src/Tizen.NUI/src/internal/Interop/Interop.PointerConstraints.cs
new file mode 100755 (executable)
index 0000000..6766cd5
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright(c) 2023 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+namespace Tizen.NUI
+{
+    internal static partial class Interop
+    {
+        internal static partial class PointerConstraints
+        {
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_PointerConstraintsEvent__SWIG_0")]
+            public static extern global::System.IntPtr NewPointerConstraints(int x, int y, bool locked, bool confined);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_delete_PointerConstraintsEvent")]
+            public static extern void DeletePointerConstraints(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_PointerConstraintsEvent_x_get")]
+            public static extern int XGet(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_PointerConstraintsEvent_y_get")]
+            public static extern int YGet(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_PointerConstraintsEvent_locked_get")]
+            [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)]
+            public static extern bool LockedGet(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_PointerConstraintsEvent_confined_get")]
+            [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)]
+            public static extern bool ConfinedGet(global::System.Runtime.InteropServices.HandleRef jarg1);
+        }
+    }
+}
diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.WindowPointerConstraintsSignal.cs b/src/Tizen.NUI/src/internal/Interop/Interop.WindowPointerConstraintsSignal.cs
new file mode 100755 (executable)
index 0000000..063301a
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright(c) 2023 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+namespace Tizen.NUI
+{
+    internal static partial class Interop
+    {
+        internal static partial class WindowPointerConstraintsSignal
+        {
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WindowPointerConstraintsEventSignal")]
+            public static extern global::System.IntPtr GetSignal(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WindowPointerConstraintsEventSignal_Empty")]
+            [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)]
+            public static extern bool Empty(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WindowPointerConstraintsEventSignal_GetConnectionCount")]
+            public static extern uint GetConnectionCount(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WindowPointerConstraintsEventSignal_Connect")]
+            public static extern void Connect(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WindowPointerConstraintsEventSignal_Disconnect")]
+            public static extern void Disconnect(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WindowPointerConstraintsEventSignal_Emit")]
+            public static extern void Emit(global::System.Runtime.InteropServices.HandleRef signalType, global::System.Runtime.InteropServices.HandleRef window, global::System.Runtime.InteropServices.HandleRef mouseEvent);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_WindowPointerConstraintsEventSignal")]
+            public static extern global::System.IntPtr NewWindowPointerConstraintsSignal();
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_delete_WindowPointerConstraintsEventSignal")]
+            public static extern void DeleteWindowPointerConstraintsSignal(global::System.Runtime.InteropServices.HandleRef jarg1);
+        }
+    }
+}
diff --git a/src/Tizen.NUI/src/internal/Window/WindowPointerConstraintsSignal.cs b/src/Tizen.NUI/src/internal/Window/WindowPointerConstraintsSignal.cs
new file mode 100755 (executable)
index 0000000..8165e46
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Copyright(c) 2023 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+using Tizen.NUI.BaseComponents;
+
+namespace Tizen.NUI
+{
+    internal class WindowPointerConstraintsSignal : Disposable
+    {
+        internal WindowPointerConstraintsSignal(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
+        {
+        }
+
+        /// <summary>
+        /// Dispose
+        /// </summary>
+        protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
+        {
+            Interop.WindowPointerConstraintsSignal.DeleteWindowPointerConstraintsSignal(swigCPtr);
+        }
+
+        /// <summary>
+        /// Queries whether there are any connected slots.
+        /// </summary>
+        /// <returns>True if there are any slots connected to the signal</returns>
+        public bool Empty()
+        {
+            bool ret = Interop.WindowPointerConstraintsSignal.Empty(SwigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        /// <summary>
+        /// Queries the number of slots.
+        /// </summary>
+        /// <returns>The number of slots connected to this signal</returns>
+        public uint GetConnectionCount()
+        {
+            uint ret = Interop.WindowPointerConstraintsSignal.GetConnectionCount(SwigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        /// <summary>
+        /// Connects a function.
+        /// </summary>
+        /// <param name="func">The function to connect</param>
+        public void Connect(System.Delegate func)
+        {
+            System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(func);
+            {
+                Interop.WindowPointerConstraintsSignal.Connect(SwigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            }
+        }
+
+        /// <summary>
+        /// Disconnects a function.
+        /// </summary>
+        /// <param name="func">The function to disconnect</param>
+        public void Disconnect(System.Delegate func)
+        {
+            System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(func);
+            {
+                Interop.WindowPointerConstraintsSignal.Disconnect(SwigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            }
+        }
+
+        /// <summary>
+        /// Emits the signal.
+        /// </summary>
+        /// <param name="window">The first value to pass to callbacks</param>
+        /// <param name="pointerConstraints">The second value to pass to callbacks</param>
+        public void Emit(Window window, PointerConstraints pointerConstraints)
+        {
+            Interop.WindowPointerConstraintsSignal.Emit(SwigCPtr, Window.getCPtr(window), PointerConstraints.getCPtr(pointerConstraints));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
+        /// The constructor.
+        /// </summary>
+        public WindowPointerConstraintsSignal(Window window) : this(Interop.WindowPointerConstraintsSignal.GetSignal(Window.getCPtr(window)), false)
+        {
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+    }
+}
diff --git a/src/Tizen.NUI/src/public/Window/PointerConstraints.cs b/src/Tizen.NUI/src/public/Window/PointerConstraints.cs
new file mode 100755 (executable)
index 0000000..c3b623a
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+ * Copyright(c) 2023 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+using System.ComponentModel;
+using Tizen.NUI.BaseComponents;
+
+namespace Tizen.NUI
+{
+    /// <summary>
+    /// PointerConstraints is used when pointer is locked/unlocked
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class PointerConstraints : Disposable
+    {
+
+        /// <summary>
+        /// The default constructor.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public PointerConstraints() : this(Interop.PointerConstraints.NewPointerConstraints(0, 0, false, false), true)
+        {
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
+        /// The constructor.
+        /// </summary>
+        /// <param name="x">The x coordinate relative to window where event happened.</param>
+        /// <param name="y">The y coordinate relative to window where event happened.</param>
+        /// <param name="locked">The status whether pointer is locked/unlocked.</param>
+        /// <param name="confined">The status whether pointer is confined/unconfined.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public PointerConstraints(int x, int y, bool locked, bool confined): this(Interop.PointerConstraints.NewPointerConstraints(x, y, locked, confined), true)
+        {
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        internal PointerConstraints(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
+        {
+        }
+
+        /// <summary>
+        /// Gets the x, y position,
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Position2D Position
+        {
+            get
+            {
+                return position;
+            }
+        }
+
+        /// <summary>
+        /// Gets the status whether pointer is locked/unlocked.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool Locked
+        {
+            get
+            {
+                return locked;
+            }
+        }
+
+        /// <summary>
+        /// Gets the status whether pointer is confined/unconfined.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool Confined
+        {
+            get
+            {
+                return confined;
+            }
+        }
+
+        private Position2D position
+        {
+            get
+            {
+                Position2D ret = new Position2D(Interop.PointerConstraints.XGet(SwigCPtr), Interop.PointerConstraints.YGet(SwigCPtr));
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                return ret;
+            }
+        }
+
+        private bool locked
+        {
+            get
+            {
+                bool ret = Interop.PointerConstraints.LockedGet(SwigCPtr);
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                return ret;
+            }
+        }
+
+        private bool confined
+        {
+            get
+            {
+                bool ret = Interop.PointerConstraints.ConfinedGet(SwigCPtr);
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                return ret;
+            }
+        }
+
+        internal static PointerConstraints GetPointerConstraintsFromPtr(global::System.IntPtr cPtr)
+        {
+            PointerConstraints ret = new PointerConstraints(cPtr, false);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
+        {
+            Interop.PointerConstraints.DeletePointerConstraints(swigCPtr);
+        }
+    }
+}
index 5fe725e..b278409 100755 (executable)
@@ -56,6 +56,7 @@ namespace Tizen.NUI
         private MoveCompletedEventCallbackType moveCompletedEventCallback;
         private ResizeCompletedEventCallbackType resizeCompletedEventCallback;
         private InsetsChangedEventCallbackType insetsChangedEventCallback;
+        private WindowPointerConstraintsEventCallback windowPointerConstraintsEventCallback;
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate void WindowFocusChangedEventCallbackType(IntPtr window, bool focusGained);
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
@@ -88,6 +89,8 @@ namespace Tizen.NUI
         private delegate void ResizeCompletedEventCallbackType(IntPtr window, IntPtr size);
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate void InsetsChangedEventCallbackType(int partType, int partState, IntPtr extents);
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        private delegate void WindowPointerConstraintsEventCallback(IntPtr window, IntPtr constraintsEvent);
 
 
         /// <summary>
@@ -605,6 +608,34 @@ namespace Tizen.NUI
             }
         }
 
+        /// <summary>
+        /// Emits the event when pointer is locked/unlocked<br />
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler<PointerConstraintsEventArgs> PointerConstraintsEvent
+        {
+            add
+            {
+                if (windowPointerConstraintsEventHandler == null)
+                {
+                    windowPointerConstraintsEventCallback = OnWindowPointerConstraintsEvent;
+                    using WindowPointerConstraintsSignal signal = new WindowPointerConstraintsSignal(Interop.WindowPointerConstraintsSignal.GetSignal(SwigCPtr), false);
+                    signal?.Connect(windowPointerConstraintsEventCallback);
+                }
+                windowPointerConstraintsEventHandler += value;
+            }
+            remove
+            {
+                windowPointerConstraintsEventHandler -= value;
+                if (windowPointerConstraintsEventHandler == null && windowPointerConstraintsEventCallback != null)
+                {
+                    using WindowPointerConstraintsSignal signal = new WindowPointerConstraintsSignal(Interop.WindowPointerConstraintsSignal.GetSignal(SwigCPtr), false);
+                    signal?.Disconnect(windowMouseRelativeEventCallback);
+                    windowPointerConstraintsEventCallback = null;
+                }
+            }
+        }
+
         private event EventHandler<FocusChangedEventArgs> windowFocusChangedEventHandler;
         private event EventHandler<TouchEventArgs> rootLayerTouchDataEventHandler;
         private ReturnTypeEventHandler<object, TouchEventArgs, bool> rootLayerInterceptTouchDataEventHandler;
@@ -625,6 +656,7 @@ namespace Tizen.NUI
         private event EventHandler<WindowMoveCompletedEventArgs> moveCompletedHandler;
         private event EventHandler<WindowResizeCompletedEventArgs> resizeCompletedHandler;
         private event EventHandler<InsetsChangedEventArgs> insetsChangedEventHandler;
+        private event EventHandler<PointerConstraintsEventArgs> windowPointerConstraintsEventHandler;
 
 
         internal event EventHandler EventProcessingFinished
@@ -916,6 +948,13 @@ namespace Tizen.NUI
                 signal?.Disconnect(insetsChangedEventCallback);
                 insetsChangedEventCallback = null;
             }
+
+            if (windowPointerConstraintsEventCallback != null)
+            {
+                using WindowPointerConstraintsSignal signal = new WindowPointerConstraintsSignal(Interop.WindowPointerConstraintsSignal.GetSignal(GetBaseHandleCPtrHandleRef), false);
+                signal?.Disconnect(windowPointerConstraintsEventCallback);
+                windowPointerConstraintsEventCallback = null;
+            }
         }
 
         private void OnWindowFocusedChanged(IntPtr window, bool focusGained)
@@ -1210,6 +1249,22 @@ namespace Tizen.NUI
             }
         }
 
+        private void OnWindowPointerConstraintsEvent(IntPtr view, IntPtr constraintsEvent)
+        {
+            if (constraintsEvent == global::System.IntPtr.Zero)
+            {
+                NUILog.Error("constraintsEvent should not be null!");
+                return;
+            }
+
+            if (windowPointerConstraintsEventHandler != null)
+            {
+                PointerConstraintsEventArgs e = new PointerConstraintsEventArgs();
+                e.PointerConstraints = Tizen.NUI.PointerConstraints.GetPointerConstraintsFromPtr(constraintsEvent);
+                windowPointerConstraintsEventHandler(this, e);
+            }
+        }
+
         /// <summary>
         /// The focus changed event argument.
         /// </summary>
@@ -1378,6 +1433,32 @@ namespace Tizen.NUI
             }
         }
 
+
+        /// <summary>
+        /// PointerConstraints evnet arguments.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public class PointerConstraintsEventArgs : EventArgs
+        {
+            private PointerConstraints constraintsEvent;
+
+            /// <summary>
+            /// PointerConstraints event.
+            /// </summary>
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            public PointerConstraints PointerConstraints
+            {
+                get
+                {
+                    return constraintsEvent;
+                }
+                set
+                {
+                    constraintsEvent = value;
+                }
+            }
+        }
+
         /// <summary>
         /// Do not use this, that will be deprecated.
         /// </summary>