[NUI] Add SelectionCleared Event (#3446)
authorabdullehghujeh <35222943+abdullehghujeh@users.noreply.github.com>
Fri, 27 Aug 2021 02:00:59 +0000 (05:00 +0300)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Fri, 27 Aug 2021 05:29:50 +0000 (14:29 +0900)
* Add SelectionCleared Event

* [NUI] rename parameters + rebase

* [NUI] remove unnecessary if statement

* [NUI] remove unnecessary use of EventArgs

Co-authored-by: abdullah <abdullahhasan10@gmail.com>
src/Tizen.NUI/src/internal/Interop/Interop.TextEditor.cs
src/Tizen.NUI/src/internal/Interop/Interop.TextField.cs
src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs
src/Tizen.NUI/src/public/BaseComponents/TextEditorEvent.cs
src/Tizen.NUI/src/public/BaseComponents/TextField.cs
src/Tizen.NUI/src/public/BaseComponents/TextFieldEvent.cs

index 9e0f572..f8e6a7f 100755 (executable)
@@ -183,6 +183,9 @@ namespace Tizen.NUI
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextEditor_MaxLengthReachedSignal")]
             public static extern global::System.IntPtr MaxLengthReachedSignal(global::System.Runtime.InteropServices.HandleRef jarg1);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextEditor_SelectionClearedSignal")]
+            public static extern global::System.IntPtr SelectionClearedSignal(global::System.Runtime.InteropServices.HandleRef pTextEditor);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextEditor_AnchorClickedSignal")]
             public static extern global::System.IntPtr AnchorClickedSignal(global::System.Runtime.InteropServices.HandleRef jarg1);
 
index 4333c8c..a035ba2 100755 (executable)
@@ -198,6 +198,9 @@ namespace Tizen.NUI
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextField_InputStyleChangedSignal")]
             public static extern global::System.IntPtr InputStyleChangedSignal(global::System.Runtime.InteropServices.HandleRef jarg1);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextField_SelectionClearedSignal")]
+            public static extern global::System.IntPtr SelectionClearedSignal(global::System.Runtime.InteropServices.HandleRef pTextField);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextField_AnchorClickedSignal")]
             public static extern global::System.IntPtr AnchorClickedSignal(global::System.Runtime.InteropServices.HandleRef jarg1);
 
index b20b0ea..a426e81 100755 (executable)
@@ -1944,6 +1944,11 @@ namespace Tizen.NUI.BaseComponents
                     this.MaxLengthReachedSignal().Disconnect(textEditorMaxLengthReachedCallbackDelegate);
                 }
 
+                if (textEditorSelectionClearedCallbackDelegate != null)
+                {
+                    this.SelectionClearedSignal().Disconnect(textEditorSelectionClearedCallbackDelegate);
+                }
+
                 if (textEditorCursorPositionChangedCallbackDelegate != null)
                 {
                     this.CursorPositionChangedSignal().Disconnect(textEditorCursorPositionChangedCallbackDelegate);
index c238807..808c4c4 100755 (executable)
@@ -42,6 +42,9 @@ namespace Tizen.NUI.BaseComponents
         private EventHandler<AnchorClickedEventArgs> textEditorAnchorClickedEventHandler;
         private AnchorClickedCallbackDelegate textEditorAnchorClickedCallbackDelegate;
 
+        private EventHandler textEditorSelectionClearedEventHandler;
+        private SelectionClearedCallbackDelegate textEditorSelectionClearedCallbackDelegate;
+
         private EventHandler textEditorSelectionChangedEventHandler;
         private SelectionChangedCallbackDelegate textEditorSelectionChangedCallbackDelegate;
 
@@ -61,6 +64,9 @@ namespace Tizen.NUI.BaseComponents
         private delegate void MaxLengthReachedCallbackDelegate(IntPtr textEditor);
 
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        private delegate void SelectionClearedCallbackDelegate(IntPtr textEditor);
+
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void AnchorClickedCallbackDelegate(IntPtr textEditor, IntPtr href, uint hrefLength);
 
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
@@ -199,6 +205,32 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
+        /// The SelectionCleared signal is emitted when selection is cleared.
+        /// </summary>
+        /// This will be public opened after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler SelectionCleared
+        {
+            add
+            {
+                if (textEditorSelectionClearedEventHandler == null)
+                {
+                    textEditorSelectionClearedCallbackDelegate = (OnSelectionCleared);
+                    SelectionClearedSignal().Connect(textEditorSelectionClearedCallbackDelegate);
+                }
+                textEditorSelectionClearedEventHandler += value;
+            }
+            remove
+            {
+                if (textEditorSelectionClearedEventHandler == null && SelectionClearedSignal().Empty() == false)
+                {
+                    this.SelectionClearedSignal().Disconnect(textEditorSelectionClearedCallbackDelegate);
+                }
+                textEditorSelectionClearedEventHandler -= value;
+            }
+        }
+
+        /// <summary>
         /// The SelectionChanged event.
         /// </summary>
         /// This will be public opened after ACR done. Before ACR, need to be hidden as inhouse API.
@@ -268,6 +300,13 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        internal TextEditorSignal SelectionClearedSignal()
+        {
+            TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.SelectionClearedSignal(SwigCPtr), false);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
         internal TextEditorSignal TextChangedSignal()
         {
             TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.TextChangedSignal(SwigCPtr), false);
@@ -330,6 +369,12 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        private void OnSelectionCleared(IntPtr textEditor)
+        {
+            //no data to be sent to the user
+            textEditorSelectionClearedEventHandler?.Invoke(this, EventArgs.Empty);
+        }
+
         private void OnScrollStateChanged(IntPtr textEditor, ScrollState state)
         {
             if (textEditorScrollStateChangedEventHandler != null)
index 0bf2ad0..9dc82c7 100755 (executable)
@@ -1954,6 +1954,11 @@ namespace Tizen.NUI.BaseComponents
                     this.MaxLengthReachedSignal().Disconnect(textFieldMaxLengthReachedCallbackDelegate);
                 }
 
+                if (textFieldSelectionClearedCallbackDelegate != null)
+                {
+                    this.SelectionClearedSignal().Disconnect(textFieldSelectionClearedCallbackDelegate);
+                }
+
                 if (textFieldSelectionChangedCallbackDelegate != null)
                 {
                     this.SelectionChangedSignal().Disconnect(textFieldSelectionChangedCallbackDelegate);
index bb4cd6d..f89533d 100755 (executable)
@@ -41,6 +41,8 @@ namespace Tizen.NUI.BaseComponents
 
         private EventHandler<InputFilteredEventArgs> textFieldInputFilteredEventHandler;
         private InputFilteredCallbackDelegate textFieldInputFilteredCallbackDelegate;
+        private EventHandler textFieldSelectionClearedEventHandler;
+        private SelectionClearedCallbackDelegate textFieldSelectionClearedCallbackDelegate;
 
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void TextChangedCallbackDelegate(IntPtr textField);
@@ -60,6 +62,9 @@ namespace Tizen.NUI.BaseComponents
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void InputFilteredCallbackDelegate(IntPtr textField, InputFilterType type);
 
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        private delegate void SelectionClearedCallbackDelegate(IntPtr textField);
+
         /// <summary>
         /// The TextChanged event.
         /// </summary>
@@ -137,6 +142,32 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
+        /// The SelectionCleared signal is emitted when selection is cleared.
+        /// </summary>
+        /// This will be public opened after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler SelectionCleared
+        {
+            add
+            {
+                if (textFieldSelectionClearedEventHandler == null)
+                {
+                    textFieldSelectionClearedCallbackDelegate = (OnSelectionCleared);
+                    SelectionClearedSignal().Connect(textFieldSelectionClearedCallbackDelegate);
+                }
+                textFieldSelectionClearedEventHandler += value;
+            }
+            remove
+            {
+                if (textFieldSelectionClearedEventHandler == null && SelectionClearedSignal().Empty() == false)
+                {
+                    this.SelectionClearedSignal().Disconnect(textFieldSelectionClearedCallbackDelegate);
+                }
+                textFieldSelectionClearedEventHandler -= value;
+            }
+        }
+
+        /// <summary>
         /// The AnchorClicked signal is emitted when the anchor is clicked.
         /// </summary>
         /// <since_tizen> 9 </since_tizen>
@@ -231,6 +262,13 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        internal TextFieldSignal SelectionClearedSignal()
+        {
+            TextFieldSignal ret = new TextFieldSignal(Interop.TextField.SelectionClearedSignal(SwigCPtr), false);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
         internal TextFieldSignal TextChangedSignal()
         {
             TextFieldSignal ret = new TextFieldSignal(Interop.TextField.TextChangedSignal(SwigCPtr), false);
@@ -273,6 +311,12 @@ namespace Tizen.NUI.BaseComponents
             return ret;
         }
 
+        private void OnSelectionCleared(IntPtr textField)
+        {
+            //no data to be sent to the user
+            textFieldSelectionClearedEventHandler?.Invoke(this, EventArgs.Empty);
+        }
+
         private void OnTextChanged(IntPtr textField)
         {
             if (textFieldTextChangedEventHandler != null)