2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Runtime.InteropServices;
21 namespace Tizen.NUI.BaseComponents
24 /// A control which provides a single line editable text field.
26 /// <since_tizen> 3 </since_tizen>
27 public partial class TextField
29 private EventHandler<TextChangedEventArgs> _textFieldTextChangedEventHandler;
30 private TextChangedCallbackDelegate _textFieldTextChangedCallbackDelegate;
31 private EventHandler<MaxLengthReachedEventArgs> _textFieldMaxLengthReachedEventHandler;
32 private MaxLengthReachedCallbackDelegate _textFieldMaxLengthReachedCallbackDelegate;
34 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
35 private delegate void TextChangedCallbackDelegate(IntPtr textField);
37 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
38 private delegate void MaxLengthReachedCallbackDelegate(IntPtr textField);
41 /// The TextChanged event.
43 /// <since_tizen> 3 </since_tizen>
44 public event EventHandler<TextChangedEventArgs> TextChanged
48 if (_textFieldTextChangedEventHandler == null)
50 _textFieldTextChangedCallbackDelegate = (OnTextChanged);
51 TextChangedSignal().Connect(_textFieldTextChangedCallbackDelegate);
53 _textFieldTextChangedEventHandler += value;
57 _textFieldTextChangedEventHandler -= value;
58 if (_textFieldTextChangedEventHandler == null && TextChangedSignal().Empty() == false)
60 TextChangedSignal().Disconnect(_textFieldTextChangedCallbackDelegate);
66 /// The MaxLengthReached event.
68 /// <since_tizen> 3 </since_tizen>
69 public event EventHandler<MaxLengthReachedEventArgs> MaxLengthReached
73 if (_textFieldMaxLengthReachedEventHandler == null)
75 _textFieldMaxLengthReachedCallbackDelegate = (OnMaxLengthReached);
76 MaxLengthReachedSignal().Connect(_textFieldMaxLengthReachedCallbackDelegate);
78 _textFieldMaxLengthReachedEventHandler += value;
82 if (_textFieldMaxLengthReachedEventHandler == null && MaxLengthReachedSignal().Empty() == false)
84 this.MaxLengthReachedSignal().Disconnect(_textFieldMaxLengthReachedCallbackDelegate);
86 _textFieldMaxLengthReachedEventHandler -= value;
90 internal TextFieldSignal TextChangedSignal()
92 TextFieldSignal ret = new TextFieldSignal(Interop.TextField.TextChangedSignal(SwigCPtr), false);
93 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
97 internal TextFieldSignal MaxLengthReachedSignal()
99 TextFieldSignal ret = new TextFieldSignal(Interop.TextField.MaxLengthReachedSignal(SwigCPtr), false);
100 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
104 private void OnTextChanged(IntPtr textField)
106 TextChangedEventArgs e = new TextChangedEventArgs();
108 // Populate all members of "e" (TextChangedEventArgs) with real data
109 e.TextField = Registry.GetManagedBaseHandleFromNativePtr(textField) as TextField;
111 if (_textFieldTextChangedEventHandler != null)
113 //here we send all data to user event handlers
114 _textFieldTextChangedEventHandler(this, e);
118 private void OnMaxLengthReached(IntPtr textField)
120 MaxLengthReachedEventArgs e = new MaxLengthReachedEventArgs();
122 // Populate all members of "e" (MaxLengthReachedEventArgs) with real data
123 e.TextField = Registry.GetManagedBaseHandleFromNativePtr(textField) as TextField;
125 if (_textFieldMaxLengthReachedEventHandler != null)
127 //here we send all data to user event handlers
128 _textFieldMaxLengthReachedEventHandler(this, e);
133 /// The TextChanged event arguments.
135 /// <since_tizen> 3 </since_tizen>
136 public class TextChangedEventArgs : EventArgs
138 private TextField _textField;
143 /// <since_tizen> 3 </since_tizen>
144 public TextField TextField
158 /// The MaxLengthReached event arguments.
160 /// <since_tizen> 3 </since_tizen>
161 public class MaxLengthReachedEventArgs : EventArgs
163 private TextField _textField;
168 /// <since_tizen> 3 </since_tizen>
169 public TextField TextField