[NUI] Add window auixiliary message event
authorWonsik Jung <sidein@samsung.com>
Fri, 19 Nov 2021 07:28:59 +0000 (16:28 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Mon, 22 Nov 2021 10:54:11 +0000 (19:54 +0900)
src/Tizen.NUI/src/internal/Interop/Interop.WindowAuxiliaryMessageSignal.cs [new file with mode: 0644]
src/Tizen.NUI/src/internal/Window/WindowAuxiliaryMessageSignal.cs [new file with mode: 0644]
src/Tizen.NUI/src/public/Window/WindowAuxiliaryMessageEvent.cs [new file with mode: 0644]
src/Tizen.NUI/src/public/Window/WindowEvent.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/WindowEventsTest.cs

diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.WindowAuxiliaryMessageSignal.cs b/src/Tizen.NUI/src/internal/Interop/Interop.WindowAuxiliaryMessageSignal.cs
new file mode 100644 (file)
index 0000000..b72fc1c
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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 WindowAuxiliaryMessageSignalType
+        {
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Window_Auxiliary_Message_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_Window_Auxiliary_Message_Signal_GetConnectionCount")]
+            public static extern uint GetConnectionCount(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Window_Auxiliary_Message_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_Dali_Window_Auxiliary_Message_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_Window_Auxiliary_Message_Signal")]
+            public static extern global::System.IntPtr Get(global::System.Runtime.InteropServices.HandleRef window);
+        }
+    }
+}
diff --git a/src/Tizen.NUI/src/internal/Window/WindowAuxiliaryMessageSignal.cs b/src/Tizen.NUI/src/internal/Window/WindowAuxiliaryMessageSignal.cs
new file mode 100644 (file)
index 0000000..f7a681b
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * 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 WindowAuxiliaryMessageSignal : Disposable
+    {
+        internal WindowAuxiliaryMessageSignal(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
+        {
+        }
+
+        public WindowAuxiliaryMessageSignal(Window window) : this(Interop.WindowAuxiliaryMessageSignalType.Get(Window.getCPtr(window)), false)
+        {
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        public bool Empty()
+        {
+            bool ret = Interop.WindowAuxiliaryMessageSignalType.Empty(SwigCPtr);
+
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        public uint GetConnectionCount()
+        {
+            uint ret = Interop.WindowAuxiliaryMessageSignalType.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.WindowAuxiliaryMessageSignalType.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.WindowAuxiliaryMessageSignalType.Disconnect(SwigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            }
+        }
+    }
+}
diff --git a/src/Tizen.NUI/src/public/Window/WindowAuxiliaryMessageEvent.cs b/src/Tizen.NUI/src/public/Window/WindowAuxiliaryMessageEvent.cs
new file mode 100644 (file)
index 0000000..f289330
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ *
+ */
+
+using System;
+using System.ComponentModel;
+using System.Collections.Generic;
+
+namespace Tizen.NUI
+{
+    /// <summary>
+    /// Auxiliary Message Event arguments
+    /// This has the three members as key, value and options.
+    /// Options has the list of string
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class AuxiliaryMessageEventArgs : EventArgs
+    {
+        private string key;
+        private string val;
+        private List<string> options;
+
+        public string Key
+        {
+            get => key;
+            internal set => key = value;
+        }
+
+        public string Value
+        {
+            get => val;
+            internal set => val = value;
+        }
+
+        public List<string> Options
+        {
+            get => options;
+            internal set => options = value;
+        }
+    }
+}
index 0c45ab6..6bb01cc 100755 (executable)
@@ -19,6 +19,7 @@ using System;
 using System.ComponentModel;
 using System.Runtime.InteropServices;
 using Tizen.NUI.BaseComponents;
+using System.Collections.Generic;
 
 namespace Tizen.NUI
 {
@@ -58,6 +59,7 @@ namespace Tizen.NUI
         private VoidSignal eventProcessingFinishedSignal;
         private VoidSignal contextLostSignal;
         private VoidSignal contextRegainedSignal;
+        private AuxiliaryMessageEventCallbackType auxiliaryMessageEventCallback;
 
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void WindowFocusChangedEventCallbackType(IntPtr window, bool focusGained);
@@ -73,6 +75,8 @@ namespace Tizen.NUI
         private delegate void TransitionEffectEventCallbackType(IntPtr window, int state, int type);
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void KeyboardRepeatSettingsChangedEventCallbackType();
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        private delegate void AuxiliaryMessageEventCallbackType(IntPtr kData, IntPtr vData, IntPtr optionsArray);
 
         /// <summary>
         /// FocusChanged event.
@@ -327,6 +331,7 @@ namespace Tizen.NUI
         private event EventHandler<FocusChangedEventArgs> windowFocusChangedEventHandler2;
         private event EventHandler<TransitionEffectEventArgs> transitionEffectHandler;
         private event EventHandler keyboardRepeatSettingsChangedHandler;
+        private event EventHandler<AuxiliaryMessageEventArgs> auxiliaryMessageEventHandler;
 
         internal void SendViewAdded(View view)
         {
@@ -570,6 +575,14 @@ namespace Tizen.NUI
             {
                 KeyboardRepeatSettingsChangedEventSignal().Disconnect(keyboardRepeatSettingsChangedEventCallback);
             }
+
+            if (auxiliaryMessageEventCallback != null)
+            {
+                using var signal = new WindowAuxiliaryMessageSignal(this);
+                signal.Disconnect(auxiliaryMessageEventCallback);
+                auxiliaryMessageEventHandler= null;
+                auxiliaryMessageEventCallback = null;
+            }
         }
 
         private StageWheelSignal StageWheelEventSignal()
@@ -1082,5 +1095,74 @@ namespace Tizen.NUI
             }
             VisibilityChangedEventSignal.Emit(this, visibility);
         }
+
+        private void OnAuxiliaryMessage(IntPtr kData, IntPtr vData, IntPtr optionsArray)
+        {
+            if(kData == IntPtr.Zero || vData == IntPtr.Zero)
+            {
+                return;
+            }
+
+            using var tmp = new PropertyArray(optionsArray, false);
+            var size = tmp.Size();
+
+            List<string> tmpList = new List<string>();
+
+            for (int i = 0; i < size; i++)
+            {
+                string option = "none";
+                tmp.GetElementAt((uint)i).Get(out option);
+                tmpList.Add(option);
+            }
+
+            tmp.Dispose();
+
+            AuxiliaryMessageEventArgs e = new AuxiliaryMessageEventArgs();
+            e.Key = StringToVoidSignal.GetResult(kData);
+            e.Value = StringToVoidSignal.GetResult(vData);;
+            e.Options = tmpList;
+
+            auxiliaryMessageEventHandler?.Invoke(this, e);
+        }
+
+        /// <summary>
+        /// Auxiliary message is sent by displayer server when window's auxiliary was changed then display server sent the message.
+        /// When client application added the window's auxiliary hint and if the auxiliary is changed,
+        /// display server send the auxiliary message.
+        /// Auxiliary message has the key, value and options.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler<AuxiliaryMessageEventArgs> AuxiliaryMessage
+        {
+            add
+            {
+                if (auxiliaryMessageEventHandler == null)
+                {
+                    auxiliaryMessageEventCallback = OnAuxiliaryMessage;
+                    using var signal = new WindowAuxiliaryMessageSignal(this);
+                    signal.Connect(auxiliaryMessageEventCallback);
+                }
+                auxiliaryMessageEventHandler += value;
+            }
+            remove
+            {
+                auxiliaryMessageEventHandler -= value;
+                if (auxiliaryMessageEventHandler == null)
+                {
+                    if (auxiliaryMessageEventCallback != null)
+                    {
+                        using var signal = new WindowAuxiliaryMessageSignal(this);
+                        signal.Disconnect(auxiliaryMessageEventCallback);
+
+                        if (signal.Empty())
+                        {
+                            auxiliaryMessageEventCallback = null;
+                        }
+                    }
+                }
+            }
+        }
+
+
     }
 }
index 80bd154..cd0813a 100755 (executable)
@@ -78,6 +78,8 @@ namespace Tizen.NUI.Samples
 
             if (childViewWindow != null)
             {
+                
+                childViewWindow.AddAuxiliaryHint("wm.policy.win.msg.use", "1");
                 childViewWindow.VisibilityChanged += OnChildViewWindowVisibilityChanged;
                 childViewWindow.Resized += OnChildViewWindowResized;
 
@@ -88,6 +90,7 @@ namespace Tizen.NUI.Samples
                 childViewWindow.TransitionEffect += OnChildViewWindowTransitionEffect;
                 childViewWindow.KeyboardRepeatSettingsChanged += OnChildViewWindowKeyboardRepeatSettingsChanged;
                 childViewWindow.ViewAdded += OnChildViewWindowViewAdded;
+                childViewWindow.AuxiliaryMessage += OnAuxiliaryMessageEvent;
             }
         }
 
@@ -105,7 +108,7 @@ namespace Tizen.NUI.Samples
                 childViewWindow.TransitionEffect -= OnChildViewWindowTransitionEffect;
                 childViewWindow.KeyboardRepeatSettingsChanged -= OnChildViewWindowKeyboardRepeatSettingsChanged;
                 childViewWindow.ViewAdded -= OnChildViewWindowViewAdded;
-
+                childViewWindow.AuxiliaryMessage -= OnAuxiliaryMessageEvent;
                 childViewWindow = null;
             }
         }
@@ -155,6 +158,23 @@ namespace Tizen.NUI.Samples
             log.Fatal(tag, $"OnChildViewWindowFocusChanged() called!");
         }
 
+        private void OnAuxiliaryMessageEvent(object sender, AuxiliaryMessageEventArgs e)
+        {
+            log.Fatal(tag, $"OnAuxiliaryMessageEvent() called!");
+            if(e != null)
+            {
+                Console.WriteLine($"Key={e.Key} Value={e.Value}");
+                log.Fatal(tag, $"Key={e.Key} Value={e.Value}");
+                var cnt = 0;
+                foreach(var option in e.Options)
+                {
+                    cnt++;
+                    Console.WriteLine($"option[{cnt}]={option}");
+                    log.Fatal(tag, $"option[{cnt}]={option}");
+                }
+            }
+        }
+
         public void Deactivate()
         {
             if (child)