From 9d84bd190aa572f905638a56605998468ed5f896 Mon Sep 17 00:00:00 2001 From: abdullehghujeh <35222943+abdullehghujeh@users.noreply.github.com> Date: Fri, 27 Aug 2021 05:00:59 +0300 Subject: [PATCH] [NUI] Add SelectionCleared Event (#3446) * Add SelectionCleared Event * [NUI] rename parameters + rebase * [NUI] remove unnecessary if statement * [NUI] remove unnecessary use of EventArgs 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 | 45 ++++++++++++++++++++++ .../src/public/BaseComponents/TextField.cs | 5 +++ .../src/public/BaseComponents/TextFieldEvent.cs | 44 +++++++++++++++++++++ 6 files changed, 105 insertions(+) diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.TextEditor.cs b/src/Tizen.NUI/src/internal/Interop/Interop.TextEditor.cs index 9e0f572..f8e6a7f 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_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); diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.TextField.cs b/src/Tizen.NUI/src/internal/Interop/Interop.TextField.cs index 4333c8c..a035ba2 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_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); diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs b/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs index b20b0ea..a426e81 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs @@ -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); diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextEditorEvent.cs b/src/Tizen.NUI/src/public/BaseComponents/TextEditorEvent.cs index c238807..808c4c4 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextEditorEvent.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextEditorEvent.cs @@ -42,6 +42,9 @@ namespace Tizen.NUI.BaseComponents private EventHandler 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 } /// + /// The SelectionCleared signal is emitted when selection is cleared. + /// + /// 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; + } + } + + /// /// The SelectionChanged event. /// /// 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) diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextField.cs b/src/Tizen.NUI/src/public/BaseComponents/TextField.cs index 0bf2ad0..9dc82c7 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextField.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextField.cs @@ -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); diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextFieldEvent.cs b/src/Tizen.NUI/src/public/BaseComponents/TextFieldEvent.cs index bb4cd6d..f89533d 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextFieldEvent.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextFieldEvent.cs @@ -41,6 +41,8 @@ namespace Tizen.NUI.BaseComponents private EventHandler 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); + /// /// The TextChanged event. /// @@ -137,6 +142,32 @@ namespace Tizen.NUI.BaseComponents } /// + /// The SelectionCleared signal is emitted when selection is cleared. + /// + /// 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; + } + } + + /// /// The AnchorClicked signal is emitted when the anchor is clicked. /// /// 9 @@ -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) -- 2.7.4