2 * Copyright(c) 2021 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.ComponentModel;
20 using System.Runtime.InteropServices;
22 namespace Tizen.NUI.BaseComponents
25 /// A control which provides a multi-line editable text editor.
27 /// <since_tizen> 3 </since_tizen>
28 public partial class TextEditor
30 private EventHandler<TextChangedEventArgs> textEditorTextChangedEventHandler;
31 private TextChangedCallbackDelegate textEditorTextChangedCallbackDelegate;
33 private EventHandler<ScrollStateChangedEventArgs> textEditorScrollStateChangedEventHandler;
34 private ScrollStateChangedCallbackDelegate textEditorScrollStateChangedCallbackDelegate;
36 private EventHandler<MaxLengthReachedEventArgs> textEditorMaxLengthReachedEventHandler;
37 private MaxLengthReachedCallbackDelegate textEditorMaxLengthReachedCallbackDelegate;
39 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
40 private delegate void TextChangedCallbackDelegate(IntPtr textEditor);
42 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
43 private delegate void ScrollStateChangedCallbackDelegate(IntPtr textEditor, ScrollState state);
45 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
46 private delegate void MaxLengthReachedCallbackDelegate(IntPtr textEditor);
49 /// An event for the TextChanged signal which can be used to subscribe or unsubscribe the event handler
50 /// provided by the user. The TextChanged signal is emitted when the text changes.<br />
52 /// <since_tizen> 3 </since_tizen>
53 public event EventHandler<TextChangedEventArgs> TextChanged
57 if (textEditorTextChangedEventHandler == null)
59 textEditorTextChangedCallbackDelegate = (OnTextChanged);
60 TextChangedSignal().Connect(textEditorTextChangedCallbackDelegate);
62 textEditorTextChangedEventHandler += value;
66 textEditorTextChangedEventHandler -= value;
67 if (textEditorTextChangedEventHandler == null && TextChangedSignal().Empty() == false)
69 TextChangedSignal().Disconnect(textEditorTextChangedCallbackDelegate);
75 /// Event for the ScrollStateChanged signal which can be used to subscribe or unsubscribe the event handler
76 /// provided by the user. The ScrollStateChanged signal is emitted when the scroll state changes.<br />
78 /// <since_tizen> 3 </since_tizen>
79 public event EventHandler<ScrollStateChangedEventArgs> ScrollStateChanged
83 if (textEditorScrollStateChangedEventHandler == null)
85 textEditorScrollStateChangedCallbackDelegate = OnScrollStateChanged;
86 ScrollStateChangedSignal(this).Connect(textEditorScrollStateChangedCallbackDelegate);
88 textEditorScrollStateChangedEventHandler += value;
92 textEditorScrollStateChangedEventHandler -= value;
93 if (textEditorScrollStateChangedEventHandler == null && ScrollStateChangedSignal(this).Empty() == false)
95 ScrollStateChangedSignal(this).Disconnect(textEditorScrollStateChangedCallbackDelegate);
101 /// The MaxLengthReached event.
103 /// This will be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API.
104 [EditorBrowsable(EditorBrowsableState.Never)]
105 public event EventHandler<MaxLengthReachedEventArgs> MaxLengthReached
109 if (textEditorMaxLengthReachedEventHandler == null)
111 textEditorMaxLengthReachedCallbackDelegate = (OnMaxLengthReached);
112 MaxLengthReachedSignal().Connect(textEditorMaxLengthReachedCallbackDelegate);
114 textEditorMaxLengthReachedEventHandler += value;
118 if (textEditorMaxLengthReachedEventHandler == null && MaxLengthReachedSignal().Empty() == false)
120 this.MaxLengthReachedSignal().Disconnect(textEditorMaxLengthReachedCallbackDelegate);
122 textEditorMaxLengthReachedEventHandler -= value;
126 internal TextEditorSignal TextChangedSignal()
128 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.TextChangedSignal(SwigCPtr), false);
129 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
133 internal ScrollStateChangedSignal ScrollStateChangedSignal(TextEditor textEditor)
135 ScrollStateChangedSignal ret = new ScrollStateChangedSignal(Interop.TextEditor.ScrollStateChangedSignal(TextEditor.getCPtr(textEditor)), false);
136 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
140 internal TextEditorSignal MaxLengthReachedSignal()
142 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.MaxLengthReachedSignal(SwigCPtr), false);
143 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
147 private void OnTextChanged(IntPtr textEditor)
149 if (textEditorTextChangedEventHandler != null)
151 TextChangedEventArgs e = new TextChangedEventArgs();
153 // Populate all members of "e" (TextChangedEventArgs) with real data
154 e.TextEditor = Registry.GetManagedBaseHandleFromNativePtr(textEditor) as TextEditor;
155 //here we send all data to user event handlers
156 textEditorTextChangedEventHandler(this, e);
160 private void OnScrollStateChanged(IntPtr textEditor, ScrollState state)
162 if (textEditorScrollStateChangedEventHandler != null)
164 ScrollStateChangedEventArgs e = new ScrollStateChangedEventArgs();
166 if (textEditor != global::System.IntPtr.Zero)
168 // Populate all members of "e" (ScrollStateChangedEventArgs) with real data
169 e.TextEditor = Registry.GetManagedBaseHandleFromNativePtr(textEditor) as TextEditor;
170 e.ScrollState = state;
172 //here we send all data to user event handlers
173 textEditorScrollStateChangedEventHandler(this, e);
177 private void OnMaxLengthReached(IntPtr textEditor)
179 if (textEditorMaxLengthReachedEventHandler != null)
181 MaxLengthReachedEventArgs e = new MaxLengthReachedEventArgs();
183 // Populate all members of "e" (MaxLengthReachedEventArgs) with real data
184 e.TextEditor = Registry.GetManagedBaseHandleFromNativePtr(textEditor) as TextEditor;
185 //here we send all data to user event handlers
186 textEditorMaxLengthReachedEventHandler(this, e);
191 /// Event arguments that passed via the TextChanged signal.
193 /// <since_tizen> 3 </since_tizen>
194 public class TextChangedEventArgs : EventArgs
196 private TextEditor textEditor;
199 /// TextEditor - is the texteditor control which has the text contents changed.
201 /// <since_tizen> 3 </since_tizen>
202 public TextEditor TextEditor
216 /// Event arguments that passed via the ScrollStateChanged signal.
218 /// <since_tizen> 3 </since_tizen>
219 public class ScrollStateChangedEventArgs : EventArgs
221 private TextEditor textEditor;
222 private ScrollState scrollState;
225 /// TextEditor - is the texteditor control which has the scroll state changed.
227 /// <since_tizen> 3 </since_tizen>
228 public TextEditor TextEditor
241 /// ScrollState - is the texteditor control scroll state.
243 /// <since_tizen> 3 </since_tizen>
244 public ScrollState ScrollState
258 /// The MaxLengthReached event arguments.
260 /// This will be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API.
261 [EditorBrowsable(EditorBrowsableState.Never)]
262 public class MaxLengthReachedEventArgs : EventArgs
264 private TextEditor textEditor;
269 /// This will be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API.
270 [EditorBrowsable(EditorBrowsableState.Never)]
271 public TextEditor TextEditor