[NUI] Add MaxLength property and signal to TextEditor (#1901)
authorSeoyeon2Kim <34738918+Seoyeon2Kim@users.noreply.github.com>
Wed, 12 Aug 2020 05:41:47 +0000 (14:41 +0900)
committerGitHub <noreply@github.com>
Wed, 12 Aug 2020 05:41:47 +0000 (14:41 +0900)
- To limit input to maximum characters in TextEditor,
 added MaxLength property and MaxLengthReached signal

Signed-off-by: Seoyeon Kim <seoyeon2.kim@samsung.com>
src/Tizen.NUI/src/internal/Interop/Interop.TextEditor.cs
src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs
src/Tizen.NUI/src/public/BaseComponents/TextEditorBindableProperty.cs
src/Tizen.NUI/src/public/BaseComponents/TextEditorEvent.cs
test/NUITestSample/NUITestSample/examples/text-test.cs

index 530ac18..516d17f 100755 (executable)
@@ -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);
index 6141b05..4e1f190 100755 (executable)
@@ -1075,6 +1075,24 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        /// <summary>
+        /// The MaxLength property.
+        /// </summary>
+        /// 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
index c05183b..0d6c851 100755 (executable)
@@ -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;
+        });
     }
 }
index 9df9299..dc85666 100755 (executable)
@@ -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<ScrollStateChangedEventArgs> _textEditorScrollStateChangedEventHandler;
         private ScrollStateChangedCallbackDelegate _textEditorScrollStateChangedCallbackDelegate;
 
+        private EventHandler<MaxLengthReachedEventArgs> _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);
+
         /// <summary>
         /// 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.<br />
@@ -90,6 +97,32 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        /// <summary>
+        /// The MaxLengthReached event.
+        /// </summary>
+        /// 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<MaxLengthReachedEventArgs> 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);
+            }
+        }
+
         /// <summary>
         /// Event arguments that passed via the TextChanged signal.
         /// </summary>
@@ -202,5 +256,32 @@ namespace Tizen.NUI.BaseComponents
                 }
             }
         }
+
+        /// <summary>
+        /// The MaxLengthReached event arguments.
+        /// </summary>
+        /// 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;
+
+            /// <summary>
+            /// TextEditor.
+            /// </summary>
+            /// 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;
+                }
+            }
+        }
     }
 }
index 40fcb22..a4d48c2 100755 (executable)
@@ -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);