[NUI] Add InsetsChanged event to Window
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Thu, 14 Jul 2022 10:13:28 +0000 (19:13 +0900)
committerSeoyeon2Kim <34738918+Seoyeon2Kim@users.noreply.github.com>
Tue, 22 Aug 2023 06:52:05 +0000 (15:52 +0900)
Window insets are the inner size between window content and window edge.

Window insets are required when status bar, virtual keyboard, or
clipboard appears on window to avoid window content obscured by them.

To notify the window insets changes, InsetsChanged event is added to
Window.

src/Tizen.NUI/src/internal/Interop/Interop.WindowInsetsChangedSignal.cs [new file with mode: 0755]
src/Tizen.NUI/src/internal/Window/WindowInsetsChangedSignal.cs [new file with mode: 0755]
src/Tizen.NUI/src/public/Window/WindowEvent.cs

diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.WindowInsetsChangedSignal.cs b/src/Tizen.NUI/src/internal/Interop/Interop.WindowInsetsChangedSignal.cs
new file mode 100755 (executable)
index 0000000..3e385f1
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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.Runtime.InteropServices;
+
+namespace Tizen.NUI
+{
+    internal static partial class Interop
+    {
+        internal static partial class WindowInsetsChangedSignalType
+        {
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Window_InsetsChanged_Signal_Empty")]
+            [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)]
+            public static extern bool Empty(HandleRef jarg1);
+
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Window_InsetsChanged_Signal_GetConnectionCount")]
+            public static extern uint GetConnectionCount(HandleRef jarg1);
+
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Window_InsetsChanged_Signal_Connect")]
+            public static extern void Connect(HandleRef jarg1, HandleRef jarg2);
+
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Window_InsetsChanged_Signal_Disconnect")]
+            public static extern void Disconnect(HandleRef jarg1, HandleRef jarg2);
+
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Window_InsetsChanged_Signal")]
+            public static extern global::System.IntPtr Get(HandleRef window);
+        }
+    }
+}
diff --git a/src/Tizen.NUI/src/internal/Window/WindowInsetsChangedSignal.cs b/src/Tizen.NUI/src/internal/Window/WindowInsetsChangedSignal.cs
new file mode 100755 (executable)
index 0000000..7301298
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * 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 class WindowInsetsChangedSignal : Disposable
+    {
+        internal WindowInsetsChangedSignal(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
+        {
+        }
+
+        public WindowInsetsChangedSignal(Window window) : this(Interop.WindowInsetsChangedSignalType.Get(Window.getCPtr(window)), false)
+        {
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        public bool Empty()
+        {
+            bool ret = Interop.WindowInsetsChangedSignalType.Empty(SwigCPtr);
+
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        public uint GetConnectionCount()
+        {
+            uint ret = Interop.WindowInsetsChangedSignalType.GetConnectionCount(SwigCPtr);
+
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        public void Connect(System.Delegate func)
+        {
+            System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(func);
+            {
+                Interop.WindowInsetsChangedSignalType.Connect(SwigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            }
+        }
+
+        public void Disconnect(System.Delegate func)
+        {
+            System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(func);
+            {
+                Interop.WindowInsetsChangedSignalType.Disconnect(SwigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            }
+        }
+    }
+}
index 05aebbd..5fe725e 100755 (executable)
@@ -55,6 +55,7 @@ namespace Tizen.NUI
         private WindowMouseRelativeEventCallbackType windowMouseRelativeEventCallback;
         private MoveCompletedEventCallbackType moveCompletedEventCallback;
         private ResizeCompletedEventCallbackType resizeCompletedEventCallback;
+        private InsetsChangedEventCallbackType insetsChangedEventCallback;
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate void WindowFocusChangedEventCallbackType(IntPtr window, bool focusGained);
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
@@ -85,6 +86,8 @@ namespace Tizen.NUI
         private delegate void MoveCompletedEventCallbackType(IntPtr window, IntPtr position);
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate void ResizeCompletedEventCallbackType(IntPtr window, IntPtr size);
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        private delegate void InsetsChangedEventCallbackType(int partType, int partState, IntPtr extents);
 
 
         /// <summary>
@@ -621,6 +624,7 @@ namespace Tizen.NUI
         private event EventHandler<MouseRelativeEventArgs> windowMouseRelativeEventHandler;
         private event EventHandler<WindowMoveCompletedEventArgs> moveCompletedHandler;
         private event EventHandler<WindowResizeCompletedEventArgs> resizeCompletedHandler;
+        private event EventHandler<InsetsChangedEventArgs> insetsChangedEventHandler;
 
 
         internal event EventHandler EventProcessingFinished
@@ -905,6 +909,13 @@ namespace Tizen.NUI
                 signal?.Disconnect(resizeCompletedEventCallback);
                 resizeCompletedEventCallback = null;
             }
+
+            if (insetsChangedEventCallback != null)
+            {
+                using WindowInsetsChangedSignal signal = new WindowInsetsChangedSignal(Interop.WindowInsetsChangedSignalType.Get(GetBaseHandleCPtrHandleRef), false);
+                signal?.Disconnect(insetsChangedEventCallback);
+                insetsChangedEventCallback = null;
+            }
         }
 
         private void OnWindowFocusedChanged(IntPtr window, bool focusGained)
@@ -1632,6 +1643,120 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// The type of insets part.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public enum InsetsPartType
+        {
+            StatusBar = 0,
+            Keyboard = 1,
+            Clipboard = 2
+        }
+
+        /// <summary>
+        /// The state of insets part.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public enum InsetsPartState
+        {
+            Invisible = 0,
+            Visible = 1
+        }
+
+        /// <summary>
+        /// InsetsChangedEventArgs
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public class InsetsChangedEventArgs : EventArgs
+        {
+            private InsetsPartType partType;
+            private InsetsPartState partState;
+            private Extents insets;
+
+            /// <summary>
+            /// The type of insets part.
+            /// e.g. StatusBar, Keyboard, or Clipboard
+            /// </summary>
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            public InsetsPartType PartType
+            {
+                get => partType;
+                internal set
+                {
+                    partType = value;
+                }
+            }
+
+            /// <summary>
+            /// The state of insets part.
+            /// e.g. Invisible or Visible
+            /// </summary>
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            public InsetsPartState PartState
+            {
+                get => partState;
+                internal set
+                {
+                    partState = value;
+                }
+            }
+
+            /// <summary>
+            /// The extents value of window insets
+            /// </summary>
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            public Extents Insets
+            {
+                get => insets;
+                internal set
+                {
+                    insets = value;
+                }
+            }
+        }
+
+        private void OnInsetsChanged(int partType, int partState, IntPtr extents)
+        {
+            if (insetsChangedEventHandler != null)
+            {
+                InsetsChangedEventArgs e = new InsetsChangedEventArgs();
+                e.PartType = (InsetsPartType)partType;
+                e.PartState = (InsetsPartState)partState;
+                e.Insets = new Extents(extents, false);
+
+                insetsChangedEventHandler.Invoke(this, e);
+            }
+        }
+
+        /// <summary>
+        /// Emits the event when the window insets changes by status bar, virtual keyboard, or clipboard appears and disappears.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler<InsetsChangedEventArgs> InsetsChanged
+        {
+            add
+            {
+                if (insetsChangedEventHandler == null)
+                {
+                    insetsChangedEventCallback = OnInsetsChanged;
+                    using WindowInsetsChangedSignal signal = new WindowInsetsChangedSignal(Interop.WindowInsetsChangedSignalType.Get(SwigCPtr), false);
+                    signal.Ensure()?.Connect(insetsChangedEventCallback);
+                }
+                insetsChangedEventHandler += value;
+            }
+            remove
+            {
+                insetsChangedEventHandler -= value;
+                if (insetsChangedEventHandler == null && insetsChangedEventCallback != null)
+                {
+                    using WindowInsetsChangedSignal signal = new WindowInsetsChangedSignal(Interop.WindowInsetsChangedSignalType.Get(SwigCPtr), false);
+                    signal.Ensure()?.Disconnect(insetsChangedEventCallback);
+                    insetsChangedEventCallback = null;
+                }
+            }
+        }
+
+        /// <summary>
         /// AccessibilityHighlightArgs
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]