From: abdullehghujeh <35222943+abdullehghujeh@users.noreply.github.com> Date: Fri, 20 Aug 2021 07:10:26 +0000 (+0300) Subject: [NUI] Add CursorPositionChanged Event (#3400) X-Git-Tag: accepted/tizen/unified/20231205.024657~1580 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=15a19a73a608e586ab62da3e97ad2f893c1e2056;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] Add CursorPositionChanged Event (#3400) * [NUI] Add CursorMoved Event * [NUI] Rename CursorMoved to CursorPositionChanged * [NUI] fix formatting * Remove new cursor position from event args * replace event handler with invoke * rename event arg property to Old Co-authored-by: abdullah --- diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.TextEditor.cs b/src/Tizen.NUI/src/internal/Interop/Interop.TextEditor.cs index 1a0040d..549f594 100755 --- a/src/Tizen.NUI/src/internal/Interop/Interop.TextEditor.cs +++ b/src/Tizen.NUI/src/internal/Interop/Interop.TextEditor.cs @@ -177,6 +177,9 @@ namespace Tizen.NUI [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextEditor_InputStyleChangedSignal")] public static extern global::System.IntPtr InputStyleChangedSignal(global::System.Runtime.InteropServices.HandleRef jarg1); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextEditor_CursorPositionChangedSignal")] + public static extern global::System.IntPtr CursorPositionChangedSignal(global::System.Runtime.InteropServices.HandleRef pTextEditor); + [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); diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.TextField.cs b/src/Tizen.NUI/src/internal/Interop/Interop.TextField.cs index 6362419..b864338 100755 --- a/src/Tizen.NUI/src/internal/Interop/Interop.TextField.cs +++ b/src/Tizen.NUI/src/internal/Interop/Interop.TextField.cs @@ -189,6 +189,9 @@ namespace Tizen.NUI [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextField_TextChangedSignal")] public static extern global::System.IntPtr TextChangedSignal(global::System.Runtime.InteropServices.HandleRef jarg1); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextField_CursorPositionChangedSignal")] + public static extern global::System.IntPtr CursorPositionChangedSignal(global::System.Runtime.InteropServices.HandleRef pTextField); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextField_MaxLengthReachedSignal")] public static extern global::System.IntPtr MaxLengthReachedSignal(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..45de3e8 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 (textEditorCursorPositionChangedCallbackDelegate != null) + { + this.CursorPositionChangedSignal().Disconnect(textEditorCursorPositionChangedCallbackDelegate); + } } 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..3698917 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextEditorEvent.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextEditorEvent.cs @@ -33,6 +33,9 @@ namespace Tizen.NUI.BaseComponents private EventHandler textEditorScrollStateChangedEventHandler; private ScrollStateChangedCallbackDelegate textEditorScrollStateChangedCallbackDelegate; + private EventHandler textEditorCursorPositionChangedEventHandler; + private CursorPositionChangedCallbackDelegate textEditorCursorPositionChangedCallbackDelegate; + private EventHandler textEditorMaxLengthReachedEventHandler; private MaxLengthReachedCallbackDelegate textEditorMaxLengthReachedCallbackDelegate; @@ -49,6 +52,9 @@ namespace Tizen.NUI.BaseComponents private delegate void ScrollStateChangedCallbackDelegate(IntPtr textEditor, ScrollState state); [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate void CursorPositionChangedCallbackDelegate(IntPtr textEditor, uint oldPosition); + + [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void MaxLengthReachedCallbackDelegate(IntPtr textEditor); [UnmanagedFunctionPointer(CallingConvention.StdCall)] @@ -110,6 +116,32 @@ namespace Tizen.NUI.BaseComponents } /// + /// The CursorPositionChanged event. + /// + /// This will be public opened after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler CursorPositionChanged + { + add + { + if (textEditorCursorPositionChangedEventHandler == null) + { + textEditorCursorPositionChangedCallbackDelegate = (OnCursorPositionChanged); + CursorPositionChangedSignal().Connect(textEditorCursorPositionChangedCallbackDelegate); + } + textEditorCursorPositionChangedEventHandler += value; + } + remove + { + if (textEditorCursorPositionChangedEventHandler == null && CursorPositionChangedSignal().Empty() == false) + { + this.CursorPositionChangedSignal().Disconnect(textEditorCursorPositionChangedCallbackDelegate); + } + textEditorCursorPositionChangedEventHandler -= value; + } + } + + /// /// The MaxLengthReached event. /// /// This will be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -218,6 +250,13 @@ namespace Tizen.NUI.BaseComponents return ret; } + internal TextEditorSignal CursorPositionChangedSignal() + { + TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.CursorPositionChangedSignal(SwigCPtr), false); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + internal TextEditorSignal MaxLengthReachedSignal() { TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.MaxLengthReachedSignal(SwigCPtr), false); @@ -269,6 +308,20 @@ namespace Tizen.NUI.BaseComponents } } + private void OnCursorPositionChanged(IntPtr textEditor, uint oldPosition) + { + if (textEditorCursorPositionChangedEventHandler != null) + { + CursorPositionChangedEventArgs e = new CursorPositionChangedEventArgs(); + + // Populate all members of "e" (CursorPositionChangedEventArgs) with real data + e.OldCursorPosition = oldPosition; + + //here we send all data to user event handlers + textEditorCursorPositionChangedEventHandler?.Invoke(this, e); + } + } + private void OnMaxLengthReached(IntPtr textEditor) { if (textEditorMaxLengthReachedEventHandler != null) diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextEvent.cs b/src/Tizen.NUI/src/public/BaseComponents/TextEvent.cs index 7aa5e99..60175e6 100644 --- a/src/Tizen.NUI/src/public/BaseComponents/TextEvent.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextEvent.cs @@ -47,4 +47,17 @@ namespace Tizen.NUI.BaseComponents [EditorBrowsable(EditorBrowsableState.Never)] public InputFilterType Type { get; set; } } + + /// + /// The CursorPositionChanged event arguments. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public class CursorPositionChangedEventArgs : EventArgs + { + /// + /// cursor postion before the change. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public uint OldCursorPosition { 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..4ddee38 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextField.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextField.cs @@ -1944,6 +1944,11 @@ namespace Tizen.NUI.BaseComponents //because the execution order of Finalizes is non-deterministic. if (this.HasBody()) { + if (textFieldCursorPositionChangedCallbackDelegate != null) + { + this.CursorPositionChangedSignal().Disconnect(textFieldCursorPositionChangedCallbackDelegate); + } + if (textFieldMaxLengthReachedCallbackDelegate != null) { this.MaxLengthReachedSignal().Disconnect(textFieldMaxLengthReachedCallbackDelegate); diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextFieldEvent.cs b/src/Tizen.NUI/src/public/BaseComponents/TextFieldEvent.cs index add2d50..cce354d 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextFieldEvent.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextFieldEvent.cs @@ -29,6 +29,8 @@ namespace Tizen.NUI.BaseComponents { private EventHandler textFieldTextChangedEventHandler; private TextChangedCallbackDelegate textFieldTextChangedCallbackDelegate; + private EventHandler textFieldCursorPositionChangedEventHandler; + private CursorPositionChangedCallbackDelegate textFieldCursorPositionChangedCallbackDelegate; private EventHandler textFieldMaxLengthReachedEventHandler; private MaxLengthReachedCallbackDelegate textFieldMaxLengthReachedCallbackDelegate; private EventHandler textFieldAnchorClickedEventHandler; @@ -40,6 +42,9 @@ namespace Tizen.NUI.BaseComponents private delegate void TextChangedCallbackDelegate(IntPtr textField); [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate void CursorPositionChangedCallbackDelegate(IntPtr textField, uint oldPosition); + + [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void MaxLengthReachedCallbackDelegate(IntPtr textField); [UnmanagedFunctionPointer(CallingConvention.StdCall)] @@ -74,6 +79,32 @@ namespace Tizen.NUI.BaseComponents } /// + /// The CursorPositionChanged event. + /// + /// This will be public opened after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler CursorPositionChanged + { + add + { + if (textFieldCursorPositionChangedEventHandler == null) + { + textFieldCursorPositionChangedCallbackDelegate = (OnCursorPositionChanged); + CursorPositionChangedSignal().Connect(textFieldCursorPositionChangedCallbackDelegate); + } + textFieldCursorPositionChangedEventHandler += value; + } + remove + { + if (textFieldCursorPositionChangedEventHandler == null && CursorPositionChangedSignal().Empty() == false) + { + this.CursorPositionChangedSignal().Disconnect(textFieldCursorPositionChangedCallbackDelegate); + } + textFieldCursorPositionChangedEventHandler -= value; + } + } + + /// /// The MaxLengthReached event. /// /// 3 @@ -174,6 +205,13 @@ namespace Tizen.NUI.BaseComponents return ret; } + internal TextFieldSignal CursorPositionChangedSignal() + { + TextFieldSignal ret = new TextFieldSignal(Interop.TextField.CursorPositionChangedSignal(SwigCPtr), false); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + internal TextFieldSignal MaxLengthReachedSignal() { TextFieldSignal ret = new TextFieldSignal(Interop.TextField.MaxLengthReachedSignal(SwigCPtr), false); @@ -208,6 +246,20 @@ namespace Tizen.NUI.BaseComponents } } + private void OnCursorPositionChanged(IntPtr textField, uint oldPosition) + { + if (textFieldCursorPositionChangedEventHandler != null) + { + CursorPositionChangedEventArgs e = new CursorPositionChangedEventArgs(); + + // Populate all members of "e" (CursorPositionChangedEventArgs) with real data + e.OldCursorPosition = oldPosition; + + //here we send all data to user event handlers + textFieldCursorPositionChangedEventHandler?.Invoke(this, e); + } + } + private void OnMaxLengthReached(IntPtr textField) { if (textFieldMaxLengthReachedEventHandler != null)