[NUI] Add InheritedVisibilityChanged Event
authorSeungho Baek <sbsh.baek@samsung.com>
Tue, 16 Jul 2024 07:18:41 +0000 (16:18 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Wed, 7 Aug 2024 07:02:39 +0000 (16:02 +0900)
Signed-off-by: Seungho Baek <sbsh.baek@samsung.com>
src/Tizen.NUI/src/internal/Interop/Interop.ActorSignal.cs
src/Tizen.NUI/src/public/BaseComponents/ViewEvent.cs
src/Tizen.NUI/src/public/Common/AggregatedVisibilityChangedEventArgs.cs [new file with mode: 0644]
src/Tizen.NUI/src/public/Common/Layer.cs

index 97e527c1bd914dca00bd3c91950e5b98bb52e258..ca88e612a3cc14172247a0d29693b373241a6df8 100755 (executable)
@@ -82,6 +82,12 @@ namespace Tizen.NUI
             [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Actor_VisibilityChangedSignal_Disconnect")]
             public static extern void VisibilityChangedDisconnect(HandleRef actor, HandleRef handler);
 
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Actor_InheritedVisibilityChangedSignal_Connect")]
+            public static extern void AggregatedVisibilityChangedConnect(HandleRef actor, HandleRef handler);
+
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Actor_InheritedVisibilityChangedSignal_Disconnect")]
+            public static extern void AggregatedVisibilityChangedDisconnect(HandleRef actor, HandleRef handler);
+
             [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Actor_LayoutDirectionChangedSignal_Connect")]
             public static extern void LayoutDirectionChangedConnect(HandleRef actor, HandleRef handler);
 
index 0b082de31f75cfce42b7e4c33534a63b1512730f..8234b1a1c66b7eb49af5d0040b77b0518fcdf86d 100755 (executable)
@@ -43,11 +43,12 @@ namespace Tizen.NUI.BaseComponents
         private HoverEventCallbackType hoverEventCallback;
         private EventHandler<VisibilityChangedEventArgs> visibilityChangedEventHandler;
         private VisibilityChangedEventCallbackType visibilityChangedEventCallback;
+        private EventHandler<AggregatedVisibilityChangedEventArgs> aggregatedVisibilityChangedEventHandler;
+        private AggregatedVisibilityChangedEventCallbackType aggregatedVisibilityChangedEventCallback;
         private EventHandler keyInputFocusGainedEventHandler;
-
         private KeyInputFocusGainedCallbackType keyInputFocusGainedCallback;
-        private EventHandler keyInputFocusLostEventHandler;
 
+        private EventHandler keyInputFocusLostEventHandler;
         private KeyInputFocusLostCallbackType keyInputFocusLostCallback;
         private EventHandler onRelayoutEventHandler;
         private OnRelayoutEventCallbackType onRelayoutEventCallback;
@@ -64,30 +65,43 @@ namespace Tizen.NUI.BaseComponents
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate void OffWindowEventCallbackType(IntPtr control);
+
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate bool WheelEventCallbackType(IntPtr view, IntPtr wheelEvent);
+
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate bool KeyCallbackType(IntPtr control, IntPtr keyEvent);
+
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate bool TouchDataCallbackType(IntPtr view, IntPtr touchData);
+
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate bool HoverEventCallbackType(IntPtr view, IntPtr hoverEvent);
+
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate void VisibilityChangedEventCallbackType(IntPtr data, bool visibility, VisibilityChangeType type);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        private delegate void AggregatedVisibilityChangedEventCallbackType(IntPtr data, bool visibility);
+
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate void ResourcesLoadedCallbackType(IntPtr control);
+
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate void _backgroundResourceLoadedCallbackType(IntPtr view);
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate void KeyInputFocusGainedCallbackType(IntPtr control);
+
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate void KeyInputFocusLostCallbackType(IntPtr control);
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate void OnRelayoutEventCallbackType(IntPtr control);
+
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate void OnWindowEventCallbackType(IntPtr control);
+
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate void LayoutDirectionChangedEventCallbackType(IntPtr data, ViewLayoutDirectionType type);
 
@@ -477,6 +491,7 @@ namespace Tizen.NUI.BaseComponents
                 }
             }
         }
+
         /// <summary>
         /// An event for visibility change which can be used to subscribe or unsubscribe the event handler.<br />
         /// This event is sent when the visibility of this or a parent view is changed.<br />
@@ -517,6 +532,43 @@ namespace Tizen.NUI.BaseComponents
                 }
             }
         }
+        /// <summary>
+        /// An event for aggregated visibility change which can be used to subscribe or unsubscribe the event handler.<br />
+        /// This event is sent when visible property of this View, any of its parents (right up to the root layer) or Window changes.<br />
+        /// </summary>
+        /// <remarks>
+        /// <para>
+        /// This event is NOT sent if the view becomes transparent (or the reverse), it's ONLY linked with Show() and Hide() of View and Window.
+        /// For reference, a view is only shown if the view, its parents (up to the root view) and Window are also visible,
+        /// they are not transparent, and the view has a non-zero size.
+        /// So if its parent is not visible, the view is not shown.
+        /// </para>
+        /// </remarks>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler<AggregatedVisibilityChangedEventArgs> AggregatedVisibilityChanged
+        {
+            add
+            {
+                if (aggregatedVisibilityChangedEventHandler == null)
+                {
+                    aggregatedVisibilityChangedEventCallback = OnAggregatedVisibilityChanged;
+                    Interop.ActorSignal.AggregatedVisibilityChangedConnect(SwigCPtr, aggregatedVisibilityChangedEventCallback.ToHandleRef(this));
+                    NDalicPINVOKE.ThrowExceptionIfExists();
+                }
+                aggregatedVisibilityChangedEventHandler += value;
+            }
+
+            remove
+            {
+                aggregatedVisibilityChangedEventHandler -= value;
+                if (aggregatedVisibilityChangedEventHandler == null && aggregatedVisibilityChangedEventCallback != null)
+                {
+                    Interop.ActorSignal.AggregatedVisibilityChangedDisconnect(SwigCPtr, aggregatedVisibilityChangedEventCallback.ToHandleRef(this));
+                    NDalicPINVOKE.ThrowExceptionIfExists();
+                    aggregatedVisibilityChangedEventCallback = null;
+                }
+            }
+        }
 
         /// <summary>
         /// Event for layout direction change which can be used to subscribe/unsubscribe the event handler.<br />
@@ -1024,6 +1076,18 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        // Callback for View aggregated visibility change signal
+        private void OnAggregatedVisibilityChanged(IntPtr data, bool visibility)
+        {
+            AggregatedVisibilityChangedEventArgs e = new AggregatedVisibilityChangedEventArgs();
+            e.Visibility = visibility;
+
+            if (aggregatedVisibilityChangedEventHandler != null)
+            {
+                aggregatedVisibilityChangedEventHandler(this, e);
+            }
+        }
+
         // Callback for View layout direction change signal
         private void OnLayoutDirectionChanged(IntPtr data, ViewLayoutDirectionType type)
         {
diff --git a/src/Tizen.NUI/src/public/Common/AggregatedVisibilityChangedEventArgs.cs b/src/Tizen.NUI/src/public/Common/AggregatedVisibilityChangedEventArgs.cs
new file mode 100644 (file)
index 0000000..3edad7d
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright(c) 2024 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;
+
+namespace Tizen.NUI
+{
+    /// <summary>
+    /// Event arguments of aggregated visibility changed.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class AggregatedVisibilityChangedEventArgs : EventArgs
+    {
+        /// <summary>
+        /// Whether the view is now visible or not.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool Visibility
+        {
+            get; set;
+        }
+    }
+}
index eadf02152ea8704095d0b4086bc52c81dc141297..51e1374bfc9e7d260925091148bbc59197c17362 100755 (executable)
@@ -29,11 +29,19 @@ namespace Tizen.NUI
     {
         private Window window;
         private int layoutCount = 0;
+
         private EventHandler<VisibilityChangedEventArgs> visibilityChangedEventHandler;
         private VisibilityChangedEventCallbackType visibilityChangedEventCallback;
+
+        private EventHandler<AggregatedVisibilityChangedEventArgs> aggregatedVisibilityChangedEventHandler;
+        private AggregatedVisibilityChangedEventCallbackType aggregatedVisibilityChangedEventCallback;
+
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate void VisibilityChangedEventCallbackType(IntPtr data, bool visibility, VisibilityChangeType type);
 
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        private delegate void AggregatedVisibilityChangedEventCallbackType(IntPtr data, bool visibility);
+
         /// <summary>
         /// Creates a Layer object.
         /// </summary>
@@ -69,6 +77,15 @@ namespace Tizen.NUI
                 visibilityChangedEventCallback = null;
             }
 
+            if (aggregatedVisibilityChangedEventCallback != null)
+            {
+                NUILog.Debug($"[Dispose] aggregatedVisibilityChangedEventCallback");
+
+                Interop.ActorSignal.AggregatedVisibilityChangedDisconnect(GetBaseHandleCPtrHandleRef, aggregatedVisibilityChangedEventCallback.ToHandleRef(this));
+                NDalicPINVOKE.ThrowExceptionIfExistsDebug();
+                aggregatedVisibilityChangedEventCallback = null;
+            }
+
             LayoutCount = 0;
 
             base.Dispose(type);
@@ -646,6 +663,35 @@ namespace Tizen.NUI
                 }
             }
         }
+        /// <summary>
+        /// An event for aggregated visibility change which can be used to subscribe or unsubscribe the event handler.<br />
+        /// This event is sent when visible property of this or any of its parents (right up to the root) and Window changes.<br />
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler<AggregatedVisibilityChangedEventArgs> AggregatedVisibilityChanged
+        {
+            add
+            {
+                if (aggregatedVisibilityChangedEventHandler == null)
+                {
+                    aggregatedVisibilityChangedEventCallback = OnAggregatedVisibilityChanged;
+                    Interop.ActorSignal.AggregatedVisibilityChangedConnect(SwigCPtr, aggregatedVisibilityChangedEventCallback.ToHandleRef(this));
+                    NDalicPINVOKE.ThrowExceptionIfExists();
+                }
+                aggregatedVisibilityChangedEventHandler += value;
+            }
+
+            remove
+            {
+                aggregatedVisibilityChangedEventHandler -= value;
+                if (aggregatedVisibilityChangedEventHandler == null && aggregatedVisibilityChangedEventCallback != null)
+                {
+                    Interop.ActorSignal.AggregatedVisibilityChangedDisconnect(SwigCPtr, aggregatedVisibilityChangedEventCallback.ToHandleRef(this));
+                    NDalicPINVOKE.ThrowExceptionIfExists();
+                    aggregatedVisibilityChangedEventCallback = null;
+                }
+            }
+        }
 
         /// <summary>
         /// Event arguments of visibility changed.
@@ -894,5 +940,17 @@ namespace Tizen.NUI
                 visibilityChangedEventHandler(this, e);
             }
         }
+
+        // Callback for Layer aggregated visibility change signal
+        private void OnAggregatedVisibilityChanged(IntPtr data, bool visibility)
+        {
+            AggregatedVisibilityChangedEventArgs e = new AggregatedVisibilityChangedEventArgs();
+            e.Visibility = visibility;
+
+            if (aggregatedVisibilityChangedEventHandler != null)
+            {
+                aggregatedVisibilityChangedEventHandler(this, e);
+            }
+        }
     }
 }