From 4920d2bdb1f7e272979e0661f0b0490a0d7a5f2c Mon Sep 17 00:00:00 2001 From: Seoyeon2Kim <34738918+Seoyeon2Kim@users.noreply.github.com> Date: Wed, 12 Aug 2020 14:41:47 +0900 Subject: [PATCH] [NUI] Add MaxLength property and signal to TextEditor (#1901) - To limit input to maximum characters in TextEditor, added MaxLength property and MaxLengthReached signal Signed-off-by: Seoyeon Kim --- .../src/internal/Interop/Interop.TextEditor.cs | 8 ++- .../src/public/BaseComponents/TextEditor.cs | 31 ++++++++- .../BaseComponents/TextEditorBindableProperty.cs | 17 +++++ .../src/public/BaseComponents/TextEditorEvent.cs | 81 ++++++++++++++++++++++ .../NUITestSample/examples/text-test.cs | 4 ++ 5 files changed, 138 insertions(+), 3 deletions(-) diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.TextEditor.cs b/src/Tizen.NUI/src/internal/Interop/Interop.TextEditor.cs index 530ac18..516d17f 100755 --- a/src/Tizen.NUI/src/internal/Interop/Interop.TextEditor.cs +++ b/src/Tizen.NUI/src/internal/Interop/Interop.TextEditor.cs @@ -164,6 +164,9 @@ namespace Tizen.NUI [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextEditor_InputStyleChangedSignal")] public static extern global::System.IntPtr TextEditor_InputStyleChangedSignal(global::System.Runtime.InteropServices.HandleRef jarg1); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextEditor_MaxLengthReachedSignal")] + public static extern global::System.IntPtr TextEditor_MaxLengthReachedSignal(global::System.Runtime.InteropServices.HandleRef jarg1); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextEditorSignal_Empty")] public static extern bool TextEditorSignal_Empty(global::System.Runtime.InteropServices.HandleRef jarg1); @@ -184,7 +187,7 @@ namespace Tizen.NUI [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_delete_TextEditorSignal")] public static extern void delete_TextEditorSignal(global::System.Runtime.InteropServices.HandleRef jarg1); - + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextEditor_SWIGUpcast")] public static extern global::System.IntPtr TextEditor_SWIGUpcast(global::System.IntPtr jarg1); @@ -230,6 +233,9 @@ namespace Tizen.NUI [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_TextEditor_Property_SCROLL_BAR_FADE_DURATION_get")] public static extern int TextEditor_Property_SCROLL_BAR_FADE_DURATION_get(); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextEditor_Property_MAX_LENGTH_get")] + public static extern int TextEditor_Property_MAX_LENGTH_get(); + //manual pinvoke for text-editor ScrollStateChangedSignal [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TextEditor_ScrollStateChangedSignal")] public static extern global::System.IntPtr TextEditor_ScrollStateChangedSignal(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 6141b05..4e1f190 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs @@ -1075,6 +1075,24 @@ namespace Tizen.NUI.BaseComponents } } + /// + /// The MaxLength property. + /// + /// This will be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public int MaxLength + { + get + { + return (int)GetValue(MaxLengthProperty); + } + set + { + SetValue(MaxLengthProperty, value); + NotifyPropertyChanged(); + } + } + /// Only used by the IL of xaml, will never changed to not hidden. [EditorBrowsable(EditorBrowsableState.Never)] public override bool IsCreateByXaml @@ -1140,9 +1158,17 @@ namespace Tizen.NUI.BaseComponents //You should not access any managed member here except static instance. //because the execution order of Finalizes is non-deterministic. - if (this.HasBody() && _textEditorTextChangedCallbackDelegate != null) + if (this.HasBody()) { - TextChangedSignal().Disconnect(_textEditorTextChangedCallbackDelegate); + if(_textEditorTextChangedCallbackDelegate != null) + { + TextChangedSignal().Disconnect(_textEditorTextChangedCallbackDelegate); + } + + if(_textEditorMaxLengthReachedCallbackDelegate != null) + { + this.MaxLengthReachedSignal().Disconnect(_textEditorMaxLengthReachedCallbackDelegate); + } } base.Dispose(type); @@ -1244,6 +1270,7 @@ namespace Tizen.NUI.BaseComponents internal static readonly int PLACEHOLDER_TEXT_COLOR = Interop.TextEditor.TextEditor_Property_PLACEHOLDER_TEXT_COLOR_get(); internal static readonly int ENABLE_SHIFT_SELECTION = Interop.TextEditor.TextEditor_Property_ENABLE_SHIFT_SELECTION_get(); internal static readonly int MATCH_SYSTEM_LANGUAGE_DIRECTION = Interop.TextEditor.TextEditor_Property_MATCH_SYSTEM_LANGUAGE_DIRECTION_get(); + internal static readonly int MAX_LENGTH = Interop.TextEditor.TextEditor_Property_MAX_LENGTH_get(); } internal class InputStyle diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextEditorBindableProperty.cs b/src/Tizen.NUI/src/public/BaseComponents/TextEditorBindableProperty.cs index c05183b..0d6c851 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextEditorBindableProperty.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextEditorBindableProperty.cs @@ -918,5 +918,22 @@ namespace Tizen.NUI.BaseComponents Tizen.NUI.Object.GetProperty(textEditor.swigCPtr, TextEditor.Property.MATCH_SYSTEM_LANGUAGE_DIRECTION).Get(out temp); return (bool)temp; }); + /// This will be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public static readonly BindableProperty MaxLengthProperty = BindableProperty.Create(nameof(MaxLength), typeof(int), typeof(TextEditor), default(int), propertyChanged: (bindable, oldValue, newValue) => + { + var textEditor = (TextEditor)bindable; + if (newValue != null) + { + Tizen.NUI.Object.SetProperty(textEditor.swigCPtr, TextEditor.Property.MAX_LENGTH, new Tizen.NUI.PropertyValue((int)newValue)); + } + }, + defaultValueCreator: (bindable) => + { + var textEditor = (TextEditor)bindable; + int temp = 0; + Tizen.NUI.Object.GetProperty(textEditor.swigCPtr, TextEditor.Property.MAX_LENGTH).Get(out temp); + return temp; + }); } } diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextEditorEvent.cs b/src/Tizen.NUI/src/public/BaseComponents/TextEditorEvent.cs index 9df9299..dc85666 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextEditorEvent.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextEditorEvent.cs @@ -16,6 +16,7 @@ */ using System; +using System.ComponentModel; using System.Runtime.InteropServices; namespace Tizen.NUI.BaseComponents @@ -32,12 +33,18 @@ namespace Tizen.NUI.BaseComponents private EventHandler _textEditorScrollStateChangedEventHandler; private ScrollStateChangedCallbackDelegate _textEditorScrollStateChangedCallbackDelegate; + private EventHandler _textEditorMaxLengthReachedEventHandler; + private MaxLengthReachedCallbackDelegate _textEditorMaxLengthReachedCallbackDelegate; + [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void TextChangedCallbackDelegate(IntPtr textEditor); [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void ScrollStateChangedCallbackDelegate(IntPtr textEditor, ScrollState state); + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate void MaxLengthReachedCallbackDelegate(IntPtr textEditor); + /// /// An event for the TextChanged signal which can be used to subscribe or unsubscribe the event handler /// provided by the user. The TextChanged signal is emitted when the text changes.
@@ -90,6 +97,32 @@ namespace Tizen.NUI.BaseComponents } } + /// + /// The MaxLengthReached event. + /// + /// This will be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler MaxLengthReached + { + add + { + if (_textEditorMaxLengthReachedEventHandler == null) + { + _textEditorMaxLengthReachedCallbackDelegate = (OnMaxLengthReached); + MaxLengthReachedSignal().Connect(_textEditorMaxLengthReachedCallbackDelegate); + } + _textEditorMaxLengthReachedEventHandler += value; + } + remove + { + if (_textEditorMaxLengthReachedEventHandler == null && MaxLengthReachedSignal().Empty() == false) + { + this.MaxLengthReachedSignal().Disconnect(_textEditorMaxLengthReachedCallbackDelegate); + } + _textEditorMaxLengthReachedEventHandler -= value; + } + } + internal TextEditorSignal TextChangedSignal() { TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.TextEditor_TextChangedSignal(swigCPtr), false); @@ -104,6 +137,13 @@ namespace Tizen.NUI.BaseComponents return ret; } + internal TextEditorSignal MaxLengthReachedSignal() + { + TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.TextEditor_MaxLengthReachedSignal(swigCPtr), false); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + private void OnTextChanged(IntPtr textEditor) { TextChangedEventArgs e = new TextChangedEventArgs(); @@ -136,6 +176,20 @@ namespace Tizen.NUI.BaseComponents } } + private void OnMaxLengthReached(IntPtr textEditor) + { + MaxLengthReachedEventArgs e = new MaxLengthReachedEventArgs(); + + // Populate all members of "e" (MaxLengthReachedEventArgs) with real data + e.TextEditor = Registry.GetManagedBaseHandleFromNativePtr(textEditor) as TextEditor; + + if (_textEditorMaxLengthReachedEventHandler != null) + { + //here we send all data to user event handlers + _textEditorMaxLengthReachedEventHandler(this, e); + } + } + /// /// Event arguments that passed via the TextChanged signal. /// @@ -202,5 +256,32 @@ namespace Tizen.NUI.BaseComponents } } } + + /// + /// The MaxLengthReached event arguments. + /// + /// This will be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public class MaxLengthReachedEventArgs : EventArgs + { + private TextEditor _textEditor; + + /// + /// TextEditor. + /// + /// This will be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public TextEditor TextEditor + { + get + { + return _textEditor; + } + set + { + _textEditor = value; + } + } + } } } diff --git a/test/NUITestSample/NUITestSample/examples/text-test.cs b/test/NUITestSample/NUITestSample/examples/text-test.cs index 40fcb22..a4d48c2 100755 --- a/test/NUITestSample/NUITestSample/examples/text-test.cs +++ b/test/NUITestSample/NUITestSample/examples/text-test.cs @@ -152,6 +152,7 @@ namespace TextTest editor.EnableSelection = true; editor.Focusable = true; editor.Placeholder = propertyMap; + editor.MaxLength = 10; window.Add(editor); editor.TextChanged += (obj, e) => { Tizen.Log.Debug("NUI", "editor line count: " + e.TextEditor.LineCount); @@ -160,6 +161,9 @@ namespace TextTest editor.ScrollStateChanged += (obj, e)=> { Tizen.Log.Debug("NUI", "editor scroll state:" + e.ScrollState); }; + editor.MaxLengthReached += (obj, e)=> { + Tizen.Log.Debug("NUI", "editor max length: "+ e.TextEditor.MaxLength); + }; Tizen.Log.Debug("NUI", "editor id: " + editor.ID); -- 2.7.4