[NUI] Add SelectionStarted event (#3912)
authorabdullehghujeh <35222943+abdullehghujeh@users.noreply.github.com>
Fri, 4 Feb 2022 06:17:40 +0000 (08:17 +0200)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 8 Feb 2022 04:41:28 +0000 (13:41 +0900)
* [NUI] Add SelectionStart event

* update testing code

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
test/Tizen.NUI.Tests/Tizen.NUI.Devel.Tests/testcase/public/BaseComponents/TSTextEditorEvent.cs
test/Tizen.NUI.Tests/Tizen.NUI.Devel.Tests/testcase/public/BaseComponents/TSTextFieldEvent.cs

index 50379c7..6f47e28 100755 (executable)
@@ -186,6 +186,9 @@ namespace Tizen.NUI
             [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_SelectionStartedSignal")]
+            public static extern global::System.IntPtr SelectionStartedSignal(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 cb5aeae..5806501 100755 (executable)
@@ -201,6 +201,9 @@ namespace Tizen.NUI
             [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_SelectionStartedSignal")]
+            public static extern global::System.IntPtr SelectionStartedSignal(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 b824b29..8105cd5 100755 (executable)
@@ -2377,6 +2377,11 @@ namespace Tizen.NUI.BaseComponents
                     this.MaxLengthReachedSignal().Disconnect(textEditorMaxLengthReachedCallbackDelegate);
                 }
 
+                if (textEditorSelectionStartedCallbackDelegate != null)
+                {
+                    this.SelectionStartedSignal().Disconnect(textEditorSelectionStartedCallbackDelegate);
+                }
+
                 if (textEditorSelectionClearedCallbackDelegate != null)
                 {
                     this.SelectionClearedSignal().Disconnect(textEditorSelectionClearedCallbackDelegate);
index 38ab071..930184b 100755 (executable)
@@ -45,6 +45,9 @@ namespace Tizen.NUI.BaseComponents
         private EventHandler textEditorSelectionClearedEventHandler;
         private SelectionClearedCallbackDelegate textEditorSelectionClearedCallbackDelegate;
 
+        private EventHandler textEditorSelectionStartedEventHandler;
+        private SelectionStartedCallbackDelegate textEditorSelectionStartedCallbackDelegate;
+
         private EventHandler textEditorSelectionChangedEventHandler;
         private SelectionChangedCallbackDelegate textEditorSelectionChangedCallbackDelegate;
 
@@ -67,6 +70,9 @@ namespace Tizen.NUI.BaseComponents
         private delegate void SelectionClearedCallbackDelegate(IntPtr textEditor);
 
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        private delegate void SelectionStartedCallbackDelegate(IntPtr textEditor);
+
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void AnchorClickedCallbackDelegate(IntPtr textEditor, IntPtr href, uint hrefLength);
 
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
@@ -206,6 +212,32 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
+        /// The SelectionStarted event is emitted when the selection start.
+        /// </summary>
+        /// This will be public opened in after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler SelectionStarted
+        {
+            add
+            {
+                if (textEditorSelectionStartedEventHandler == null)
+                {
+                    textEditorSelectionStartedCallbackDelegate = (OnSelectionStarted);
+                    SelectionStartedSignal().Connect(textEditorSelectionStartedCallbackDelegate);
+                }
+                textEditorSelectionStartedEventHandler += value;
+            }
+            remove
+            {
+                if (textEditorSelectionStartedEventHandler == null && SelectionStartedSignal().Empty() == false)
+                {
+                    this.SelectionStartedSignal().Disconnect(textEditorSelectionStartedCallbackDelegate);
+                }
+                textEditorSelectionStartedEventHandler -= value;
+            }
+        }
+
+        /// <summary>
         /// The SelectionCleared signal is emitted when selection is cleared.
         /// </summary>
         /// <since_tizen> 9 </since_tizen>
@@ -299,6 +331,13 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        internal TextEditorSignal SelectionStartedSignal()
+        {
+            TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.SelectionStartedSignal(SwigCPtr), false);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
         internal TextEditorSignal SelectionClearedSignal()
         {
             TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.SelectionClearedSignal(SwigCPtr), false);
@@ -368,6 +407,12 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        private void OnSelectionStarted(IntPtr textEditor)
+        {
+            //no data to be sent to the user
+            textEditorSelectionStartedEventHandler?.Invoke(this, EventArgs.Empty);
+        }
+
         private void OnSelectionCleared(IntPtr textEditor)
         {
             //no data to be sent to the user
index 384bcdd..0a2c48f 100755 (executable)
@@ -2416,6 +2416,11 @@ namespace Tizen.NUI.BaseComponents
                     this.MaxLengthReachedSignal().Disconnect(textFieldMaxLengthReachedCallbackDelegate);
                 }
 
+                if (textFieldSelectionStartedCallbackDelegate != null)
+                {
+                    this.SelectionStartedSignal().Disconnect(textFieldSelectionStartedCallbackDelegate);
+                }
+
                 if (textFieldSelectionClearedCallbackDelegate != null)
                 {
                     this.SelectionClearedSignal().Disconnect(textFieldSelectionClearedCallbackDelegate);
index 2e9dd2b..fc8b5a7 100755 (executable)
@@ -44,6 +44,9 @@ namespace Tizen.NUI.BaseComponents
         private EventHandler textFieldSelectionClearedEventHandler;
         private SelectionClearedCallbackDelegate textFieldSelectionClearedCallbackDelegate;
 
+        private EventHandler textFieldSelectionStartedEventHandler;
+        private SelectionStartedCallbackDelegate textFieldSelectionStartedCallbackDelegate;
+
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void TextChangedCallbackDelegate(IntPtr textField);
 
@@ -65,6 +68,9 @@ namespace Tizen.NUI.BaseComponents
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void SelectionClearedCallbackDelegate(IntPtr textField);
 
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        private delegate void SelectionStartedCallbackDelegate(IntPtr textField);
+
         private bool invokeTextChanged = true;
 
         /// <summary>
@@ -143,6 +149,32 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
+        /// The SelectionStarted event is emitted when the selection start.
+        /// </summary>
+        /// This will be public opened in after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler SelectionStarted
+        {
+            add
+            {
+                if (textFieldSelectionStartedEventHandler == null)
+                {
+                    textFieldSelectionStartedCallbackDelegate = (OnSelectionStarted);
+                    SelectionStartedSignal().Connect(textFieldSelectionStartedCallbackDelegate);
+                }
+                textFieldSelectionStartedEventHandler += value;
+            }
+            remove
+            {
+                if (textFieldSelectionStartedEventHandler == null && SelectionStartedSignal().Empty() == false)
+                {
+                    this.SelectionStartedSignal().Disconnect(textFieldSelectionStartedCallbackDelegate);
+                }
+                textFieldSelectionStartedEventHandler -= value;
+            }
+        }
+
+        /// <summary>
         /// The SelectionCleared signal is emitted when selection is cleared.
         /// </summary>
         /// <since_tizen> 9 </since_tizen>
@@ -261,6 +293,13 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        internal TextFieldSignal SelectionStartedSignal()
+        {
+            TextFieldSignal ret = new TextFieldSignal(Interop.TextField.SelectionStartedSignal(SwigCPtr), false);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
         internal TextFieldSignal SelectionClearedSignal()
         {
             TextFieldSignal ret = new TextFieldSignal(Interop.TextField.SelectionClearedSignal(SwigCPtr), false);
@@ -310,6 +349,12 @@ namespace Tizen.NUI.BaseComponents
             return ret;
         }
 
+        private void OnSelectionStarted(IntPtr textField)
+        {
+            //no data to be sent to the user
+            textFieldSelectionStartedEventHandler?.Invoke(this, EventArgs.Empty);
+        }
+
         private void OnSelectionCleared(IntPtr textField)
         {
             //no data to be sent to the user
index e0212a7..eca92c8 100755 (executable)
@@ -4,6 +4,7 @@ using NUnit.Framework.TUnit;
 using Tizen.NUI.Components;
 using Tizen.NUI.BaseComponents;
 using System.Collections.Generic;
+using System.Threading.Tasks;
 
 namespace Tizen.NUI.Devel.Tests
 {
@@ -14,6 +15,7 @@ namespace Tizen.NUI.Devel.Tests
     public class PublicTextEditorEventTest
     {
         private const string tag = "NUITEST";
+        private bool selectionStartedFlag = false;
 
         [SetUp]
         public void Init()
@@ -51,10 +53,57 @@ namespace Tizen.NUI.Devel.Tests
             testingTarget.AnchorClicked += OnAnchorClicked;
             testingTarget.AnchorClicked -= OnAnchorClicked;
 
+            testingTarget.SelectionStarted += OnSelectionStarted;
+            testingTarget.SelectionStarted -= OnSelectionStarted;
+                        
             testingTarget.Dispose();
             tlog.Debug(tag, $"TextEditorEventEvents END (OK)");
         }
 
+        [Test]
+        [Category("P1")]
+        [Description("TextEditorEvent SelectionStarted.")]
+        [Property("SPEC", "Tizen.NUI.TextEditor.SelectionStarted A")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "PRW")]
+        [Property("AUTHOR", "a.ghujeh@samsung.com")]
+        async public Task TextEditorSelectionStarted()
+        {
+            tlog.Debug(tag, $"SelectionStarted START");
+
+            var testingTarget = new TextEditor()
+            {
+                Text = "texteditor",
+            };
+
+            Window.Instance.GetDefaultLayer().Add(testingTarget);
+
+            Assert.IsNotNull(testingTarget, "Can't create success object TextEditor");
+            Assert.IsInstanceOf<TextEditor>(testingTarget, "Should be an instance of TextEditor type.");
+
+            try
+            {
+                testingTarget.SelectionStarted += OnSelectionStarted;
+
+                testingTarget.SelectWholeText();
+                await Task.Delay(500);
+
+                testingTarget.SelectionStarted -= OnSelectionStarted;
+            }
+            catch (Exception e)
+            {
+                tlog.Info(tag, e.Message.ToString());
+                Assert.Fail("Caught Exception : Failed!");
+            }
+
+            testingTarget.Dispose();
+
+            if(selectionStartedFlag == true)
+                tlog.Debug(tag, $"SelectionStarted END (OK)");
+            else
+                Assert.Fail("SelectionStarted : Failed!");
+        }
+
         private void OnAnchorClicked(object sender, AnchorClickedEventArgs e)
         {
         }
@@ -66,5 +115,10 @@ namespace Tizen.NUI.Devel.Tests
         private void OnTextChanged(object sender, TextEditor.TextChangedEventArgs e)
         {
         }
+        
+        private void OnSelectionStarted(object sender, EventArgs e) 
+        {
+            selectionStartedFlag = true;
+        }
     }
 }
index 6f43e99..116149d 100755 (executable)
@@ -17,6 +17,7 @@ namespace Tizen.NUI.Devel.Tests
         private const string tag = "NUITEST";
         private bool textChangedFlag = false;
         private bool maxLengthFlag = false;
+        private bool selectionStartedFlag = false;
 
         private void OnTextChanged(object sender, TextField.TextChangedEventArgs e) { }
         private void OnMaxLengthReached(object sender, TextField.MaxLengthReachedEventArgs e) { }
@@ -25,6 +26,11 @@ namespace Tizen.NUI.Devel.Tests
         private void OnSelectionCleared(object sender, EventArgs e) { }
         private void OnInputFiltered(object sender, InputFilteredEventArgs e) { }
 
+        private void OnSelectionStarted(object sender, EventArgs e) 
+        { 
+            selectionStartedFlag = true;
+        }
+
         [SetUp]
         public void Init()
         {
@@ -81,5 +87,49 @@ namespace Tizen.NUI.Devel.Tests
             testingTarget.Dispose();
             tlog.Debug(tag, $"TextFieldMaxLengthReached END (OK)");
         }
+
+        [Test]
+        [Category("P1")]
+        [Description("TextFieldEvent SelectionStarted.")]
+        [Property("SPEC", "Tizen.NUI.TextField.SelectionStarted A")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "PRW")]
+        [Property("AUTHOR", "a.ghujeh@samsung.com")]
+        async public Task TextFieldSelectionStarted()
+        {
+            tlog.Debug(tag, $"SelectionStarted START");
+
+            var testingTarget = new TextField()
+            {
+                Text = "textfield",
+            };
+
+            Window.Instance.GetDefaultLayer().Add(testingTarget);
+
+            Assert.IsNotNull(testingTarget, "Can't create success object TextField");
+            Assert.IsInstanceOf<TextField>(testingTarget, "Should be an instance of TextField type.");
+
+            try
+            {
+                testingTarget.SelectionStarted += OnSelectionStarted;
+
+                testingTarget.SelectWholeText();
+                await Task.Delay(500);
+
+                testingTarget.SelectionStarted -= OnSelectionStarted;
+            }
+            catch (Exception e)
+            {
+                tlog.Info(tag, e.Message.ToString());
+                Assert.Fail("Caught Exception : Failed!");
+            }
+
+            testingTarget.Dispose();
+
+            if(selectionStartedFlag == true)
+                tlog.Debug(tag, $"SelectionStarted END (OK)");
+            else
+                Assert.Fail("SelectionStarted : Failed!");
+        }
     }
 }