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 textEditorCursorPositionChangedEventHandler;
37 private CursorPositionChangedCallbackDelegate textEditorCursorPositionChangedCallbackDelegate;
39 private EventHandler<MaxLengthReachedEventArgs> textEditorMaxLengthReachedEventHandler;
40 private MaxLengthReachedCallbackDelegate textEditorMaxLengthReachedCallbackDelegate;
42 private EventHandler<AnchorClickedEventArgs> textEditorAnchorClickedEventHandler;
43 private AnchorClickedCallbackDelegate textEditorAnchorClickedCallbackDelegate;
45 private EventHandler textEditorSelectionClearedEventHandler;
46 private SelectionClearedCallbackDelegate textEditorSelectionClearedCallbackDelegate;
48 private EventHandler textEditorSelectionChangedEventHandler;
49 private SelectionChangedCallbackDelegate textEditorSelectionChangedCallbackDelegate;
51 private EventHandler<InputFilteredEventArgs> textEditorInputFilteredEventHandler;
52 private InputFilteredCallbackDelegate textEditorInputFilteredCallbackDelegate;
54 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
55 private delegate void TextChangedCallbackDelegate(IntPtr textEditor);
57 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
58 private delegate void ScrollStateChangedCallbackDelegate(IntPtr textEditor, ScrollState state);
60 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
61 private delegate void CursorPositionChangedCallbackDelegate(IntPtr textEditor, uint oldPosition);
63 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
64 private delegate void MaxLengthReachedCallbackDelegate(IntPtr textEditor);
66 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
67 private delegate void SelectionClearedCallbackDelegate(IntPtr textEditor);
69 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
70 private delegate void AnchorClickedCallbackDelegate(IntPtr textEditor, IntPtr href, uint hrefLength);
72 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
73 private delegate void SelectionChangedCallbackDelegate(IntPtr textEditor, uint oldStart, uint oldEnd);
75 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
76 private delegate void InputFilteredCallbackDelegate(IntPtr textEditor, InputFilterType type);
79 /// An event for the TextChanged signal which can be used to subscribe or unsubscribe the event handler
80 /// provided by the user. The TextChanged signal is emitted when the text changes.<br />
82 /// <since_tizen> 3 </since_tizen>
83 public event EventHandler<TextChangedEventArgs> TextChanged
87 if (textEditorTextChangedEventHandler == null)
89 textEditorTextChangedCallbackDelegate = (OnTextChanged);
90 TextChangedSignal().Connect(textEditorTextChangedCallbackDelegate);
92 textEditorTextChangedEventHandler += value;
96 textEditorTextChangedEventHandler -= value;
97 if (textEditorTextChangedEventHandler == null && TextChangedSignal().Empty() == false)
99 TextChangedSignal().Disconnect(textEditorTextChangedCallbackDelegate);
105 /// Event for the ScrollStateChanged signal which can be used to subscribe or unsubscribe the event handler
106 /// provided by the user. The ScrollStateChanged signal is emitted when the scroll state changes.<br />
108 /// <since_tizen> 3 </since_tizen>
109 public event EventHandler<ScrollStateChangedEventArgs> ScrollStateChanged
113 if (textEditorScrollStateChangedEventHandler == null)
115 textEditorScrollStateChangedCallbackDelegate = OnScrollStateChanged;
116 ScrollStateChangedSignal(this).Connect(textEditorScrollStateChangedCallbackDelegate);
118 textEditorScrollStateChangedEventHandler += value;
122 textEditorScrollStateChangedEventHandler -= value;
123 if (textEditorScrollStateChangedEventHandler == null && ScrollStateChangedSignal(this).Empty() == false)
125 ScrollStateChangedSignal(this).Disconnect(textEditorScrollStateChangedCallbackDelegate);
131 /// The CursorPositionChanged event.
133 /// This will be public opened after ACR done. Before ACR, need to be hidden as inhouse API.
134 [EditorBrowsable(EditorBrowsableState.Never)]
135 public event EventHandler CursorPositionChanged
139 if (textEditorCursorPositionChangedEventHandler == null)
141 textEditorCursorPositionChangedCallbackDelegate = (OnCursorPositionChanged);
142 CursorPositionChangedSignal().Connect(textEditorCursorPositionChangedCallbackDelegate);
144 textEditorCursorPositionChangedEventHandler += value;
148 if (textEditorCursorPositionChangedEventHandler == null && CursorPositionChangedSignal().Empty() == false)
150 this.CursorPositionChangedSignal().Disconnect(textEditorCursorPositionChangedCallbackDelegate);
152 textEditorCursorPositionChangedEventHandler -= value;
157 /// The MaxLengthReached event.
159 /// This will be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API.
160 [EditorBrowsable(EditorBrowsableState.Never)]
161 public event EventHandler<MaxLengthReachedEventArgs> MaxLengthReached
165 if (textEditorMaxLengthReachedEventHandler == null)
167 textEditorMaxLengthReachedCallbackDelegate = (OnMaxLengthReached);
168 MaxLengthReachedSignal().Connect(textEditorMaxLengthReachedCallbackDelegate);
170 textEditorMaxLengthReachedEventHandler += value;
174 if (textEditorMaxLengthReachedEventHandler == null && MaxLengthReachedSignal().Empty() == false)
176 this.MaxLengthReachedSignal().Disconnect(textEditorMaxLengthReachedCallbackDelegate);
178 textEditorMaxLengthReachedEventHandler -= value;
183 /// The AnchorClicked signal is emitted when the anchor is clicked.
185 /// <since_tizen> 9 </since_tizen>
186 public event EventHandler<AnchorClickedEventArgs> AnchorClicked
190 if (textEditorAnchorClickedEventHandler == null)
192 textEditorAnchorClickedCallbackDelegate = (OnAnchorClicked);
193 AnchorClickedSignal().Connect(textEditorAnchorClickedCallbackDelegate);
195 textEditorAnchorClickedEventHandler += value;
199 textEditorAnchorClickedEventHandler -= value;
200 if (textEditorAnchorClickedEventHandler == null && AnchorClickedSignal().Empty() == false)
202 AnchorClickedSignal().Disconnect(textEditorAnchorClickedCallbackDelegate);
208 /// The SelectionCleared signal is emitted when selection is cleared.
210 /// This will be public opened after ACR done. Before ACR, need to be hidden as inhouse API.
211 [EditorBrowsable(EditorBrowsableState.Never)]
212 public event EventHandler SelectionCleared
216 if (textEditorSelectionClearedEventHandler == null)
218 textEditorSelectionClearedCallbackDelegate = (OnSelectionCleared);
219 SelectionClearedSignal().Connect(textEditorSelectionClearedCallbackDelegate);
221 textEditorSelectionClearedEventHandler += value;
225 if (textEditorSelectionClearedEventHandler == null && SelectionClearedSignal().Empty() == false)
227 this.SelectionClearedSignal().Disconnect(textEditorSelectionClearedCallbackDelegate);
229 textEditorSelectionClearedEventHandler -= value;
234 /// The SelectionChanged event.
236 /// This will be public opened after ACR done. Before ACR, need to be hidden as inhouse API.
237 /// <since_tizen> 9 </since_tizen>
238 public event EventHandler SelectionChanged
242 if (textEditorSelectionChangedEventHandler == null)
244 textEditorSelectionChangedCallbackDelegate = (OnSelectionChanged);
245 SelectionChangedSignal().Connect(textEditorSelectionChangedCallbackDelegate);
247 textEditorSelectionChangedEventHandler += value;
251 if (textEditorSelectionChangedEventHandler == null && SelectionChangedSignal().Empty() == false)
253 this.SelectionChangedSignal().Disconnect(textEditorSelectionChangedCallbackDelegate);
255 textEditorSelectionChangedEventHandler -= value;
260 /// The InputFiltered signal is emitted when the input is filtered by InputFilter. <br />
263 /// See <see cref="InputFilterType"/> and <see cref="InputFilteredEventArgs"/> for a detailed description. <br />
266 /// The following example demonstrates how to use the InputFiltered event.
268 /// editor.InputFiltered += (s, e) =>
270 /// if (e.Type == InputFilterType.Accept)
272 /// // If input is filtered by InputFilter of Accept type.
274 /// else if (e.Type == InputFilterType.Reject)
276 /// // If input is filtered by InputFilter of Reject type.
281 [EditorBrowsable(EditorBrowsableState.Never)]
282 public event EventHandler<InputFilteredEventArgs> InputFiltered
286 if (textEditorInputFilteredEventHandler == null)
288 textEditorInputFilteredCallbackDelegate = (OnInputFiltered);
289 InputFilteredSignal().Connect(textEditorInputFilteredCallbackDelegate);
291 textEditorInputFilteredEventHandler += value;
295 textEditorInputFilteredEventHandler -= value;
296 if (textEditorInputFilteredEventHandler == null && InputFilteredSignal().Empty() == false)
298 InputFilteredSignal().Disconnect(textEditorInputFilteredCallbackDelegate);
303 internal TextEditorSignal SelectionClearedSignal()
305 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.SelectionClearedSignal(SwigCPtr), false);
306 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
310 internal TextEditorSignal TextChangedSignal()
312 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.TextChangedSignal(SwigCPtr), false);
313 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317 internal ScrollStateChangedSignal ScrollStateChangedSignal(TextEditor textEditor)
319 ScrollStateChangedSignal ret = new ScrollStateChangedSignal(Interop.TextEditor.ScrollStateChangedSignal(TextEditor.getCPtr(textEditor)), false);
320 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
324 internal TextEditorSignal CursorPositionChangedSignal()
326 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.CursorPositionChangedSignal(SwigCPtr), false);
327 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
331 internal TextEditorSignal MaxLengthReachedSignal()
333 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.MaxLengthReachedSignal(SwigCPtr), false);
334 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338 internal TextEditorSignal AnchorClickedSignal()
340 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.AnchorClickedSignal(SwigCPtr), false);
341 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
345 internal TextEditorSignal SelectionChangedSignal()
347 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.SelectionChangedSignal(SwigCPtr), false);
348 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
352 internal TextEditorSignal InputFilteredSignal()
354 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.InputFilteredSignal(SwigCPtr), false);
355 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
359 private void OnTextChanged(IntPtr textEditor)
361 if (textEditorTextChangedEventHandler != null)
363 TextChangedEventArgs e = new TextChangedEventArgs();
365 // Populate all members of "e" (TextChangedEventArgs) with real data
366 e.TextEditor = Registry.GetManagedBaseHandleFromNativePtr(textEditor) as TextEditor;
367 //here we send all data to user event handlers
368 textEditorTextChangedEventHandler(this, e);
372 private void OnSelectionCleared(IntPtr textEditor)
374 //no data to be sent to the user
375 textEditorSelectionClearedEventHandler?.Invoke(this, EventArgs.Empty);
378 private void OnScrollStateChanged(IntPtr textEditor, ScrollState state)
380 if (textEditorScrollStateChangedEventHandler != null)
382 ScrollStateChangedEventArgs e = new ScrollStateChangedEventArgs();
384 if (textEditor != global::System.IntPtr.Zero)
386 // Populate all members of "e" (ScrollStateChangedEventArgs) with real data
387 e.TextEditor = Registry.GetManagedBaseHandleFromNativePtr(textEditor) as TextEditor;
388 e.ScrollState = state;
390 //here we send all data to user event handlers
391 textEditorScrollStateChangedEventHandler(this, e);
395 private void OnCursorPositionChanged(IntPtr textEditor, uint oldPosition)
397 // no data to be sent to the user, as in NUI there is no event provide old values.
398 textEditorCursorPositionChangedEventHandler?.Invoke(this, EventArgs.Empty);
401 private void OnMaxLengthReached(IntPtr textEditor)
403 if (textEditorMaxLengthReachedEventHandler != null)
405 MaxLengthReachedEventArgs e = new MaxLengthReachedEventArgs();
407 // Populate all members of "e" (MaxLengthReachedEventArgs) with real data
408 e.TextEditor = Registry.GetManagedBaseHandleFromNativePtr(textEditor) as TextEditor;
409 //here we send all data to user event handlers
410 textEditorMaxLengthReachedEventHandler(this, e);
414 private void OnAnchorClicked(IntPtr textEditor, IntPtr href, uint hrefLength)
416 // Note: hrefLength is useful for get the length of a const char* (href) in dali-toolkit.
417 // But NUI can get the length of string (href), so hrefLength is not necessary in NUI.
418 AnchorClickedEventArgs e = new AnchorClickedEventArgs();
420 // Populate all members of "e" (AnchorClickedEventArgs) with real data
421 e.Href = Marshal.PtrToStringAnsi(href);
422 //here we send all data to user event handlers
423 textEditorAnchorClickedEventHandler?.Invoke(this, e);
426 private void OnSelectionChanged(IntPtr textEditor, uint oldStart, uint oldEnd)
428 // no data to be sent to the user, as in NUI there is no event provide old values.
429 textEditorSelectionChangedEventHandler?.Invoke(this, EventArgs.Empty);
432 private void OnInputFiltered(IntPtr textEditor, InputFilterType type)
434 InputFilteredEventArgs e = new InputFilteredEventArgs();
436 // Populate all members of "e" (InputFilteredEventArgs) with real data
438 //here we send all data to user event handlers
439 textEditorInputFilteredEventHandler?.Invoke(this, e);
443 /// Event arguments that passed via the TextChanged signal.
445 /// <since_tizen> 3 </since_tizen>
446 public class TextChangedEventArgs : EventArgs
448 private TextEditor textEditor;
451 /// TextEditor - is the texteditor control which has the text contents changed.
453 /// <since_tizen> 3 </since_tizen>
454 public TextEditor TextEditor
468 /// Event arguments that passed via the ScrollStateChanged signal.
470 /// <since_tizen> 3 </since_tizen>
471 public class ScrollStateChangedEventArgs : EventArgs
473 private TextEditor textEditor;
474 private ScrollState scrollState;
477 /// TextEditor - is the texteditor control which has the scroll state changed.
479 /// <since_tizen> 3 </since_tizen>
480 public TextEditor TextEditor
493 /// ScrollState - is the texteditor control scroll state.
495 /// <since_tizen> 3 </since_tizen>
496 public ScrollState ScrollState
510 /// The MaxLengthReached event arguments.
512 /// This will be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API.
513 [EditorBrowsable(EditorBrowsableState.Never)]
514 public class MaxLengthReachedEventArgs : EventArgs
516 private TextEditor textEditor;
521 /// This will be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API.
522 [EditorBrowsable(EditorBrowsableState.Never)]
523 public TextEditor TextEditor