[NUI] Add SelectionChanged Event (#3397) (#3449)
authorBowon Ryu <bowon.ryu@samsung.com>
Mon, 23 Aug 2021 08:39:31 +0000 (17:39 +0900)
committerJunsuChoi <junduru019@gmail.com>
Tue, 24 Aug 2021 05:09:56 +0000 (14:09 +0900)
Add SelectionChanged event, which will be called every time the selection has changed.

editor.SelectionChanged += (s, e) =>
{
    e.OldSelectionStart; // selection before the change
    e.OldSelectionEnd;  // selection before the change
};

This reverts commit 3cdf1f2609b3dd00a4ca2fee04927e7cd0cba070.

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/TextEvent.cs
src/Tizen.NUI/src/public/BaseComponents/TextField.cs
src/Tizen.NUI/src/public/BaseComponents/TextFieldEvent.cs

index 549f594256cdebe9de11c1c3f82c8274ac7d34d5..53fb762a54ee4b904882eb9b170b4a6bda265cbc 100755 (executable)
@@ -186,6 +186,9 @@ namespace Tizen.NUI
             [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);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextEditor_SelectionChangedSignal")]
+            public static extern global::System.IntPtr SelectionChangedSignal(global::System.Runtime.InteropServices.HandleRef jarg1);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextEditorSignal_Empty")]
             [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)]
             public static extern bool TextEditorSignalEmpty(global::System.Runtime.InteropServices.HandleRef jarg1);
index b8643385bbe105378a8431f1712ff1440d01c65d..86b32dab6954187f66ea737a7afff141f77128f5 100755 (executable)
@@ -201,6 +201,9 @@ namespace Tizen.NUI
             [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);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextField_SelectionChangedSignal")]
+            public static extern global::System.IntPtr SelectionChangedSignal(global::System.Runtime.InteropServices.HandleRef jarg1);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextFieldSignal_Empty")]
             [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)]
             public static extern bool TextFieldSignalEmpty(global::System.Runtime.InteropServices.HandleRef jarg1);
index 45de3e8edea8b52c0d38ebb8b4375782670dfe2e..b20b0ea7c0f98266faa1800ade2ea162c0604574 100755 (executable)
@@ -1948,6 +1948,11 @@ namespace Tizen.NUI.BaseComponents
                 {
                     this.CursorPositionChangedSignal().Disconnect(textEditorCursorPositionChangedCallbackDelegate);
                 }
+
+                if (textEditorSelectionChangedCallbackDelegate != null)
+                {
+                    this.SelectionChangedSignal().Disconnect(textEditorSelectionChangedCallbackDelegate);
+                }
             }
 
             base.Dispose(type);
index 369891750eefde140de9759421f998424dfaac57..33999740bee503030ded12b52febae7a7b925cce 100755 (executable)
@@ -42,6 +42,9 @@ namespace Tizen.NUI.BaseComponents
         private EventHandler<AnchorClickedEventArgs> textEditorAnchorClickedEventHandler;
         private AnchorClickedCallbackDelegate textEditorAnchorClickedCallbackDelegate;
 
+        private EventHandler<SelectionChangedEventArgs> textEditorSelectionChangedEventHandler;
+        private SelectionChangedCallbackDelegate textEditorSelectionChangedCallbackDelegate;
+
         private EventHandler<InputFilteredEventArgs> textEditorInputFilteredEventHandler;
         private InputFilteredCallbackDelegate textEditorInputFilteredCallbackDelegate;
 
@@ -60,6 +63,9 @@ namespace Tizen.NUI.BaseComponents
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void AnchorClickedCallbackDelegate(IntPtr textEditor, IntPtr href, uint hrefLength);
 
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        private delegate void SelectionChangedCallbackDelegate(IntPtr textEditor, uint oldStart, uint oldEnd);
+
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void InputFilteredCallbackDelegate(IntPtr textEditor, InputFilterType type);
 
@@ -192,6 +198,32 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        /// <summary>
+        /// The SelectionChanged event.
+        /// </summary>
+        /// This will be public opened after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler<SelectionChangedEventArgs> SelectionChanged
+        {
+            add
+            {
+                if (textEditorSelectionChangedEventHandler == null)
+                {
+                    textEditorSelectionChangedCallbackDelegate = (OnSelectionChanged);
+                    SelectionChangedSignal().Connect(textEditorSelectionChangedCallbackDelegate);
+                }
+                textEditorSelectionChangedEventHandler += value;
+            }
+            remove
+            {
+                if (textEditorSelectionChangedEventHandler == null && SelectionChangedSignal().Empty() == false)
+                {
+                    this.SelectionChangedSignal().Disconnect(textEditorSelectionChangedCallbackDelegate);
+                }
+                textEditorSelectionChangedEventHandler -= value;
+            }
+        }
+
         /// <summary>
         /// The InputFiltered signal is emitted when the input is filtered by InputFilter. <br />
         /// </summary>
@@ -271,6 +303,13 @@ namespace Tizen.NUI.BaseComponents
             return ret;
         }
 
+        internal TextEditorSignal SelectionChangedSignal()
+        {
+            TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.SelectionChangedSignal(SwigCPtr), false);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
         internal TextEditorSignal InputFilteredSignal()
         {
             TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.InputFilteredSignal(SwigCPtr), false);
@@ -347,6 +386,21 @@ namespace Tizen.NUI.BaseComponents
             textEditorAnchorClickedEventHandler?.Invoke(this, e);
         }
 
+        private void OnSelectionChanged(IntPtr textEditor, uint oldStart, uint oldEnd)
+        {
+            if (textEditorSelectionChangedEventHandler != null)
+            {
+                SelectionChangedEventArgs e = new SelectionChangedEventArgs();
+
+                // Populate all members of "e" (SelectionChangedEventArgs) with real data
+                e.OldSelectionStart = oldStart;
+                e.OldSelectionEnd = oldEnd;
+
+                //here we send all data to user event handlers
+                textEditorSelectionChangedEventHandler?.Invoke(this, e);
+            }
+        }
+
         private void OnInputFiltered(IntPtr textEditor, InputFilterType type)
         {
             InputFilteredEventArgs e = new InputFilteredEventArgs();
index 60175e6d7307dd12df9676ab1e81e6c4c6f2190c..38f590f944bfdaabdfc6a7e048cd70a9687058e5 100644 (file)
@@ -60,4 +60,24 @@ namespace Tizen.NUI.BaseComponents
         [EditorBrowsable(EditorBrowsableState.Never)]
         public uint OldCursorPosition { get; set; }
     }
+
+    /// <summary>
+    /// The SelectionChanged event arguments.
+    /// </summary>
+    /// This will be public opened after ACR done. Before ACR, need to be hidden as inhouse API.
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class SelectionChangedEventArgs : EventArgs
+    {
+        /// <summary>
+        /// selection start before the change.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public uint OldSelectionStart { get; set; }
+
+        /// <summary>
+        /// selection end before the change.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public uint OldSelectionEnd { get; set; }
+    }
 }
\ No newline at end of file
index 4ddee38df53572ae76bb6b58fde5d10e94aecaf2..0bf2ad0524794b85f835b0b99592998f0a07f361 100755 (executable)
@@ -1954,6 +1954,11 @@ namespace Tizen.NUI.BaseComponents
                     this.MaxLengthReachedSignal().Disconnect(textFieldMaxLengthReachedCallbackDelegate);
                 }
 
+                if (textFieldSelectionChangedCallbackDelegate != null)
+                {
+                    this.SelectionChangedSignal().Disconnect(textFieldSelectionChangedCallbackDelegate);
+                }
+
                 if (textFieldTextChangedCallbackDelegate != null)
                 {
                     TextChangedSignal().Disconnect(textFieldTextChangedCallbackDelegate);
index cce354dbc684a0aefa3fc9cd7f0015cb085e03f9..55f2f3362ca44c48ff9a2b2b1ea8749d231a8754 100755 (executable)
@@ -35,6 +35,10 @@ namespace Tizen.NUI.BaseComponents
         private MaxLengthReachedCallbackDelegate textFieldMaxLengthReachedCallbackDelegate;
         private EventHandler<AnchorClickedEventArgs> textFieldAnchorClickedEventHandler;
         private AnchorClickedCallbackDelegate textFieldAnchorClickedCallbackDelegate;
+
+        private EventHandler<SelectionChangedEventArgs> textFieldSelectionChangedEventHandler;
+        private SelectionChangedCallbackDelegate textFieldSelectionChangedCallbackDelegate;
+
         private EventHandler<InputFilteredEventArgs> textFieldInputFilteredEventHandler;
         private InputFilteredCallbackDelegate textFieldInputFilteredCallbackDelegate;
 
@@ -50,6 +54,9 @@ namespace Tizen.NUI.BaseComponents
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void AnchorClickedCallbackDelegate(IntPtr textField, IntPtr href, uint hrefLength);
 
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        private delegate void SelectionChangedCallbackDelegate(IntPtr textField, uint oldStart, uint oldEnd);
+
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void InputFilteredCallbackDelegate(IntPtr textField, InputFilterType type);
 
@@ -154,6 +161,32 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        /// <summary>
+        /// The SelectionChanged event.
+        /// </summary>
+        /// This will be public opened after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler<SelectionChangedEventArgs> SelectionChanged
+        {
+            add
+            {
+                if (textFieldSelectionChangedEventHandler == null)
+                {
+                    textFieldSelectionChangedCallbackDelegate = (OnSelectionChanged);
+                    SelectionChangedSignal().Connect(textFieldSelectionChangedCallbackDelegate);
+                }
+                textFieldSelectionChangedEventHandler += value;
+            }
+            remove
+            {
+                if (textFieldSelectionChangedEventHandler == null && SelectionChangedSignal().Empty() == false)
+                {
+                    this.SelectionChangedSignal().Disconnect(textFieldSelectionChangedCallbackDelegate);
+                }
+                textFieldSelectionChangedEventHandler -= value;
+            }
+        }
+
         /// <summary>
         /// The InputFiltered signal is emitted when the input is filtered by InputFilter. <br />
         /// </summary>
@@ -226,6 +259,13 @@ namespace Tizen.NUI.BaseComponents
             return ret;
         }
 
+        internal TextFieldSignal SelectionChangedSignal()
+        {
+            TextFieldSignal ret = new TextFieldSignal(Interop.TextField.SelectionChangedSignal(SwigCPtr), false);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
         internal TextFieldSignal InputFilteredSignal()
         {
             TextFieldSignal ret = new TextFieldSignal(Interop.TextField.InputFilteredSignal(SwigCPtr), false);
@@ -285,6 +325,21 @@ namespace Tizen.NUI.BaseComponents
             textFieldAnchorClickedEventHandler?.Invoke(this, e);
         }
 
+        private void OnSelectionChanged(IntPtr textField, uint oldStart, uint oldEnd)
+        {
+            if (textFieldSelectionChangedEventHandler != null)
+            {
+                SelectionChangedEventArgs e = new SelectionChangedEventArgs();
+
+                // Populate all members of "e" (SelectionChangedEventArgs) with real data
+                e.OldSelectionStart = oldStart;
+                e.OldSelectionEnd = oldEnd;
+
+                //here we send all data to user event handlers
+                textFieldSelectionChangedEventHandler?.Invoke(this, e);
+            }
+        }
+
         private void OnInputFiltered(IntPtr textField, InputFilterType type)
         {
             InputFilteredEventArgs e = new InputFilteredEventArgs();