/* * Copyright(c) 2019 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ using System; using System.ComponentModel; using System.Runtime.InteropServices; namespace Tizen.NUI.BaseComponents { /// /// A control which provides a multi-line editable text editor. /// /// 3 public partial class TextEditor { private EventHandler _textEditorTextChangedEventHandler; private TextChangedCallbackDelegate _textEditorTextChangedCallbackDelegate; 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.
///
/// 3 public event EventHandler TextChanged { add { if (_textEditorTextChangedEventHandler == null) { _textEditorTextChangedCallbackDelegate = (OnTextChanged); TextChangedSignal().Connect(_textEditorTextChangedCallbackDelegate); } _textEditorTextChangedEventHandler += value; } remove { _textEditorTextChangedEventHandler -= value; if (_textEditorTextChangedEventHandler == null && TextChangedSignal().Empty() == false) { TextChangedSignal().Disconnect(_textEditorTextChangedCallbackDelegate); } } } /// /// Event for the ScrollStateChanged signal which can be used to subscribe or unsubscribe the event handler /// provided by the user. The ScrollStateChanged signal is emitted when the scroll state changes.
///
/// 3 public event EventHandler ScrollStateChanged { add { if (_textEditorScrollStateChangedEventHandler == null) { _textEditorScrollStateChangedCallbackDelegate = OnScrollStateChanged; ScrollStateChangedSignal(this).Connect(_textEditorScrollStateChangedCallbackDelegate); } _textEditorScrollStateChangedEventHandler += value; } remove { _textEditorScrollStateChangedEventHandler -= value; if (_textEditorScrollStateChangedEventHandler == null && ScrollStateChangedSignal(this).Empty() == false) { ScrollStateChangedSignal(this).Disconnect(_textEditorScrollStateChangedCallbackDelegate); } } } /// /// 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); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } internal ScrollStateChangedSignal ScrollStateChangedSignal(TextEditor textEditor) { ScrollStateChangedSignal ret = new ScrollStateChangedSignal(Interop.TextEditor.TextEditor_ScrollStateChangedSignal(TextEditor.getCPtr(textEditor)), false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); 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(); // Populate all members of "e" (TextChangedEventArgs) with real data e.TextEditor = Registry.GetManagedBaseHandleFromNativePtr(textEditor) as TextEditor; if (_textEditorTextChangedEventHandler != null) { //here we send all data to user event handlers _textEditorTextChangedEventHandler(this, e); } } private void OnScrollStateChanged(IntPtr textEditor, ScrollState state) { ScrollStateChangedEventArgs e = new ScrollStateChangedEventArgs(); if (textEditor != global::System.IntPtr.Zero) { // Populate all members of "e" (ScrollStateChangedEventArgs) with real data e.TextEditor = Registry.GetManagedBaseHandleFromNativePtr(textEditor) as TextEditor; e.ScrollState = state; } if (_textEditorScrollStateChangedEventHandler != null) { //here we send all data to user event handlers _textEditorScrollStateChangedEventHandler(this, e); } } 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. /// /// 3 public class TextChangedEventArgs : EventArgs { private TextEditor _textEditor; /// /// TextEditor - is the texteditor control which has the text contents changed. /// /// 3 public TextEditor TextEditor { get { return _textEditor; } set { _textEditor = value; } } } /// /// Event arguments that passed via the ScrollStateChanged signal. /// /// 3 public class ScrollStateChangedEventArgs : EventArgs { private TextEditor _textEditor; private ScrollState _scrollState; /// /// TextEditor - is the texteditor control which has the scroll state changed. /// /// 3 public TextEditor TextEditor { get { return _textEditor; } set { _textEditor = value; } } /// /// ScrollState - is the texteditor control scroll state. /// /// 3 public ScrollState ScrollState { get { return _scrollState; } set { _scrollState = value; } } } /// /// 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; } } } } }