From d8414fc36a9e7e093f259572401fa00a96096e89 Mon Sep 17 00:00:00 2001 From: abdullehghujeh <35222943+abdullehghujeh@users.noreply.github.com> Date: Fri, 20 Aug 2021 09:49:31 +0300 Subject: [PATCH] [NUI] Add SelectionChanged Event (#3397) * Add SelectionChanged Event * Update TextEditorEvent.cs fix SelectionChangedEventArgs comments * Update TextFieldEvent.cs fix SelectionChangedEventArgs comments * remove sender from selection event arg and make it common * Remove new selection start/end event args * replace event handler with invoke * rename event arg property to Old Co-authored-by: abdullah --- .../src/internal/Interop/Interop.TextEditor.cs | 3 ++ .../src/internal/Interop/Interop.TextField.cs | 3 ++ .../src/public/BaseComponents/TextEditor.cs | 5 ++ .../src/public/BaseComponents/TextEditorEvent.cs | 54 +++++++++++++++++++++ .../src/public/BaseComponents/TextEvent.cs | 20 ++++++++ .../src/public/BaseComponents/TextField.cs | 5 ++ .../src/public/BaseComponents/TextFieldEvent.cs | 55 ++++++++++++++++++++++ 7 files changed, 145 insertions(+) diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.TextEditor.cs b/src/Tizen.NUI/src/internal/Interop/Interop.TextEditor.cs index 1a0040d..027fdde 100755 --- a/src/Tizen.NUI/src/internal/Interop/Interop.TextEditor.cs +++ b/src/Tizen.NUI/src/internal/Interop/Interop.TextEditor.cs @@ -183,6 +183,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); diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.TextField.cs b/src/Tizen.NUI/src/internal/Interop/Interop.TextField.cs index 6362419..d2f4d8a 100755 --- a/src/Tizen.NUI/src/internal/Interop/Interop.TextField.cs +++ b/src/Tizen.NUI/src/internal/Interop/Interop.TextField.cs @@ -198,6 +198,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); diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs b/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs index b1621c3..65574d4 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs @@ -1943,6 +1943,11 @@ namespace Tizen.NUI.BaseComponents { this.MaxLengthReachedSignal().Disconnect(textEditorMaxLengthReachedCallbackDelegate); } + + if (textEditorSelectionChangedCallbackDelegate != null) + { + this.SelectionChangedSignal().Disconnect(textEditorSelectionChangedCallbackDelegate); + } } base.Dispose(type); diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextEditorEvent.cs b/src/Tizen.NUI/src/public/BaseComponents/TextEditorEvent.cs index d073412..86ad374 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextEditorEvent.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextEditorEvent.cs @@ -39,6 +39,9 @@ namespace Tizen.NUI.BaseComponents private EventHandler textEditorAnchorClickedEventHandler; private AnchorClickedCallbackDelegate textEditorAnchorClickedCallbackDelegate; + private EventHandler textEditorSelectionChangedEventHandler; + private SelectionChangedCallbackDelegate textEditorSelectionChangedCallbackDelegate; + private EventHandler textEditorInputFilteredEventHandler; private InputFilteredCallbackDelegate textEditorInputFilteredCallbackDelegate; @@ -55,6 +58,9 @@ namespace Tizen.NUI.BaseComponents 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); /// @@ -161,6 +167,32 @@ namespace Tizen.NUI.BaseComponents } /// + /// The SelectionChanged event. + /// + /// This will be public opened after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler 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; + } + } + + /// /// The InputFiltered signal is emitted when the input is filtered by InputFilter.
///
/// @@ -232,6 +264,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); @@ -294,6 +333,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(); diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextEvent.cs b/src/Tizen.NUI/src/public/BaseComponents/TextEvent.cs index 7aa5e99..4669bce 100644 --- a/src/Tizen.NUI/src/public/BaseComponents/TextEvent.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextEvent.cs @@ -47,4 +47,24 @@ namespace Tizen.NUI.BaseComponents [EditorBrowsable(EditorBrowsableState.Never)] public InputFilterType Type { get; set; } } + + /// + /// The SelectionChanged event arguments. + /// + /// This will be public opened after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public class SelectionChangedEventArgs : EventArgs + { + /// + /// selection start before the change. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public uint OldSelectionStart { get; set; } + + /// + /// selection end before the change. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public uint OldSelectionEnd { get; set; } + } } \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextField.cs b/src/Tizen.NUI/src/public/BaseComponents/TextField.cs index 65b24b5..f7ae572 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextField.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextField.cs @@ -1949,6 +1949,11 @@ namespace Tizen.NUI.BaseComponents this.MaxLengthReachedSignal().Disconnect(textFieldMaxLengthReachedCallbackDelegate); } + if (textFieldSelectionChangedCallbackDelegate != null) + { + this.SelectionChangedSignal().Disconnect(textFieldSelectionChangedCallbackDelegate); + } + if (textFieldTextChangedCallbackDelegate != null) { TextChangedSignal().Disconnect(textFieldTextChangedCallbackDelegate); diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextFieldEvent.cs b/src/Tizen.NUI/src/public/BaseComponents/TextFieldEvent.cs index add2d50..9e50e02 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextFieldEvent.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextFieldEvent.cs @@ -33,6 +33,10 @@ namespace Tizen.NUI.BaseComponents private MaxLengthReachedCallbackDelegate textFieldMaxLengthReachedCallbackDelegate; private EventHandler textFieldAnchorClickedEventHandler; private AnchorClickedCallbackDelegate textFieldAnchorClickedCallbackDelegate; + + private EventHandler textFieldSelectionChangedEventHandler; + private SelectionChangedCallbackDelegate textFieldSelectionChangedCallbackDelegate; + private EventHandler textFieldInputFilteredEventHandler; private InputFilteredCallbackDelegate textFieldInputFilteredCallbackDelegate; @@ -46,6 +50,9 @@ namespace Tizen.NUI.BaseComponents 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); /// @@ -124,6 +131,32 @@ namespace Tizen.NUI.BaseComponents } /// + /// The SelectionChanged event. + /// + /// This will be public opened after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler 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; + } + } + + /// /// The InputFiltered signal is emitted when the input is filtered by InputFilter.
///
/// @@ -188,6 +221,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); @@ -233,6 +273,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(); -- 2.7.4