[NUI] Append window move event
authorWonsik Jung <sidein@samsung.com>
Fri, 12 Aug 2022 08:49:00 +0000 (17:49 +0900)
committerTaehyub Kim <taehyub.kim@samsung.com>
Tue, 16 Aug 2022 08:26:57 +0000 (17:26 +0900)
Append window move event.
This event occurs when window's position is changed.

src/Tizen.NUI/src/internal/Interop/Interop.WindowMovedSignal.cs [new file with mode: 0644]
src/Tizen.NUI/src/internal/Window/WindowMovedSignal.cs [new file with mode: 0644]
src/Tizen.NUI/src/public/Window/WindowEvent.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/BorderWindowTest.cs

diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.WindowMovedSignal.cs b/src/Tizen.NUI/src/internal/Interop/Interop.WindowMovedSignal.cs
new file mode 100644 (file)
index 0000000..68b7be5
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright(c) 2021 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 WindowMovedSignal
+        {
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Window_Moved_Signal")]
+            public static extern global::System.IntPtr GetSignal(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Moved_Signal_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_Moved_Signal_GetConnectionCount")]
+            public static extern uint GetConnectionCount(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Moved_Signal_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_Moved_Signal_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_Moved_Signal_Emit")]
+            [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)]
+            public static extern bool Emit(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2, global::System.Runtime.InteropServices.HandleRef jarg3);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_Moved_Signal")]
+            public static extern global::System.IntPtr NewSignal();
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_delete_Moved_Signal")]
+            public static extern void DeleteSignal(global::System.Runtime.InteropServices.HandleRef jarg1);
+        }
+    }
+}
diff --git a/src/Tizen.NUI/src/internal/Window/WindowMovedSignal.cs b/src/Tizen.NUI/src/internal/Window/WindowMovedSignal.cs
new file mode 100644 (file)
index 0000000..a6bf9ad
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright(c) 2021 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 WindowMovedSignal : Disposable
+    {
+        internal WindowMovedSignal(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
+        {
+        }
+
+        protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
+        {
+            Interop.WindowMovedSignal.DeleteSignal(swigCPtr);
+        }
+
+        public bool Empty()
+        {
+            bool ret = Interop.WindowMovedSignal.Empty(SwigCPtr);
+
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        public uint GetConnectionCount()
+        {
+            uint ret = Interop.WindowMovedSignal.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.WindowMovedSignal.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.WindowMovedSignal.Disconnect(SwigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            }
+        }
+
+        public bool Emit(Window window, Rectangle positionSize)
+        {
+            bool ret = Interop.WindowMovedSignal.Emit(SwigCPtr, Window.getCPtr(window), Rectangle.getCPtr(positionSize));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        public WindowMovedSignal(Window window) : this(Interop.WindowMovedSignal.GetSignal(Window.getCPtr(window)), false)
+        {
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+    }
+}
index 5a3c7a8..eb67dee 100755 (executable)
@@ -47,6 +47,8 @@ namespace Tizen.NUI
         private WindowFocusChangedEventCallbackType windowFocusChangedEventCallback2;
         private TransitionEffectEventCallbackType transitionEffectEventCallback;
         private WindowTransitionEffectSignal transitionEffectSignal;
+        private MovedEventCallbackType movedEventCallback;
+        private WindowMovedSignal movedSignal;
         private KeyboardRepeatSettingsChangedEventCallbackType keyboardRepeatSettingsChangedEventCallback;
         private KeyboardRepeatSettingsChangedSignal keyboardRepeatSettingsChangedSignal;
         private WindowFocusSignalType windowFocusChangedSignal;
@@ -79,6 +81,8 @@ namespace Tizen.NUI
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void TransitionEffectEventCallbackType(IntPtr window, int state, int type);
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        private delegate void MovedEventCallbackType(IntPtr window, IntPtr position);
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void KeyboardRepeatSettingsChangedEventCallbackType();
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void AuxiliaryMessageEventCallbackType(IntPtr kData, IntPtr vData, IntPtr optionsArray);
@@ -396,6 +400,35 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// MovedEvent
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler<WindowMovedEventArgs> Moved
+        {
+            add
+            {
+                if (movedHandler == null)
+                {
+                    movedEventCallback = OnMoved;
+                    MovedEventSignal().Connect(movedEventCallback);
+                }
+                movedHandler += value;
+            }
+            remove
+            {
+                movedHandler -= value;
+                if (movedHandler == null && MovedEventSignal().Empty() == false)
+                {
+                    MovedEventSignal().Disconnect(movedEventCallback);
+                    if (MovedEventSignal().Empty() == true)
+                    {
+                        movedEventCallback = null;
+                    }
+                }
+            }
+        }
+
+        /// <summary>
         /// Keyboard Repeat Settings Changed
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
@@ -441,6 +474,7 @@ namespace Tizen.NUI
         private event EventHandler<ResizedEventArgs> windowResizeEventHandler;
         private event EventHandler<FocusChangedEventArgs> windowFocusChangedEventHandler2;
         private event EventHandler<TransitionEffectEventArgs> transitionEffectHandler;
+        private event EventHandler<WindowMovedEventArgs> movedHandler;
         private event EventHandler keyboardRepeatSettingsChangedHandler;
         private event EventHandler<AuxiliaryMessageEventArgs> auxiliaryMessageEventHandler;
 
@@ -734,6 +768,12 @@ namespace Tizen.NUI
                 transitionEffectEventCallback = null;
             }
 
+            if (movedSignal != null)
+            {
+                MovedEventSignal().Disconnect(movedEventCallback);
+                movedEventCallback = null;
+            }
+
             if (keyboardRepeatSettingsChangedSignal != null)
             {
                 KeyboardRepeatSettingsChangedEventSignal().Disconnect(keyboardRepeatSettingsChangedEventCallback);
@@ -781,6 +821,17 @@ namespace Tizen.NUI
             return transitionEffectSignal;
         }
 
+        private WindowMovedSignal MovedEventSignal()
+        {
+            if (movedSignal == null)
+            {
+                movedSignal = new WindowMovedSignal(this);
+                if (NDalicPINVOKE.SWIGPendingException.Pending)
+                    throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            }
+            return movedSignal;
+        }
+
         private KeyboardRepeatSettingsChangedSignal KeyboardRepeatSettingsChangedEventSignal()
         {
             if (keyboardRepeatSettingsChangedSignal == null)
@@ -966,6 +1017,22 @@ namespace Tizen.NUI
             return;
         }
 
+        private void OnMoved(IntPtr window, IntPtr position)
+        {
+            if (window == global::System.IntPtr.Zero)
+            {
+                return;
+            }
+
+            if (movedHandler != null)
+            {
+                WindowMovedEventArgs e = new WindowMovedEventArgs();
+                e.WindowPosition = this.WindowPosition;
+                movedHandler(this, e);
+            }
+            return;
+        }
+
         private void OnKeyboardRepeatSettingsChanged()
         {
             keyboardRepeatSettingsChangedHandler?.Invoke(this, null);
@@ -1444,4 +1511,26 @@ namespace Tizen.NUI
             }
         }
     }
+
+    /// <summary>
+    /// MovedArgs
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class WindowMovedEventArgs : EventArgs
+    {
+        private Position2D position;
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Position2D WindowPosition
+        {
+            get
+            {
+                return position;
+            }
+            set
+            {
+                position = value;
+            }
+        }
+    }
 }
index 79fd2f7..1196587 100755 (executable)
@@ -8,8 +8,10 @@ using System.Collections.Generic;
 
 namespace Tizen.NUI.Samples
 {
+  using log = Tizen.Log;
   public class BorderWindowTest : IExample
   {
+    string tag = "NUITEST";
     private Window win;
     private Window subWindowOne = null;
     private Window subWindowTwo = null;
@@ -266,6 +268,13 @@ namespace Tizen.NUI.Samples
 
     }
 
+
+    private void OnWindowMoved(object sender, WindowMovedEventArgs e)
+    {
+        Position2D position = e.WindowPosition;
+        log.Fatal(tag, $"OnWindowMoved() called!, x:{position.X}, y:{position.Y}");
+    }
+
     void CreateSubWindowOne()
     {
       if (subWindowOne == null)
@@ -295,6 +304,8 @@ namespace Tizen.NUI.Samples
         animation.AnimateTo(text, "Orientation", new Rotation(new Radian(new Degree(0.0f)), PositionAxis.X), 500, 1000);
         animation.Looping = true;
         animation.Play();
+
+        subWindowOne.Moved += OnWindowMoved;
       }
       else
       {
@@ -302,6 +313,12 @@ namespace Tizen.NUI.Samples
       }
     }
 
+    private void OnWindowMoved2(object sender, WindowMovedEventArgs e)
+    {
+        Position2D position = e.WindowPosition;
+        log.Fatal(tag, $"OnWindowMoved2() called!, x:{position.X}, y:{position.Y}");
+    }
+
     void CreateSubWindowTwo()
     {
       if (subWindowTwo == null)
@@ -337,6 +354,8 @@ namespace Tizen.NUI.Samples
         };
         root.Add(image);
         subWindowTwo.Add(root);
+
+        subWindowTwo.Moved += OnWindowMoved2;
       }
       else
       {