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 textEditorSelectionStartedEventHandler;
49 private SelectionStartedCallbackDelegate textEditorSelectionStartedCallbackDelegate;
51 private EventHandler textEditorSelectionChangedEventHandler;
52 private SelectionChangedCallbackDelegate textEditorSelectionChangedCallbackDelegate;
54 private EventHandler<InputFilteredEventArgs> textEditorInputFilteredEventHandler;
55 private InputFilteredCallbackDelegate textEditorInputFilteredCallbackDelegate;
57 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
58 private delegate void TextChangedCallbackDelegate(IntPtr textEditor);
60 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
61 private delegate void ScrollStateChangedCallbackDelegate(IntPtr textEditor, ScrollState state);
63 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
64 private delegate void CursorPositionChangedCallbackDelegate(IntPtr textEditor, uint oldPosition);
66 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
67 private delegate void MaxLengthReachedCallbackDelegate(IntPtr textEditor);
69 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
70 private delegate void SelectionClearedCallbackDelegate(IntPtr textEditor);
72 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
73 private delegate void SelectionStartedCallbackDelegate(IntPtr textEditor);
75 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
76 private delegate void AnchorClickedCallbackDelegate(IntPtr textEditor, IntPtr href, uint hrefLength);
78 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
79 private delegate void SelectionChangedCallbackDelegate(IntPtr textEditor, uint oldStart, uint oldEnd);
81 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
82 private delegate void InputFilteredCallbackDelegate(IntPtr textEditor, InputFilterType type);
84 private bool invokeTextChanged = true;
87 /// An event for the TextChanged signal which can be used to subscribe or unsubscribe the event handler
88 /// provided by the user. The TextChanged signal is emitted when the text changes.<br />
90 /// <since_tizen> 3 </since_tizen>
91 public event EventHandler<TextChangedEventArgs> TextChanged
95 if (textEditorTextChangedEventHandler == null)
97 textEditorTextChangedCallbackDelegate = (OnTextChanged);
98 TextChangedSignal().Connect(textEditorTextChangedCallbackDelegate);
100 textEditorTextChangedEventHandler += value;
104 textEditorTextChangedEventHandler -= value;
105 if (textEditorTextChangedEventHandler == null && TextChangedSignal().Empty() == false)
107 TextChangedSignal().Disconnect(textEditorTextChangedCallbackDelegate);
113 /// Event for the ScrollStateChanged signal which can be used to subscribe or unsubscribe the event handler
114 /// provided by the user. The ScrollStateChanged signal is emitted when the scroll state changes.<br />
116 /// <since_tizen> 3 </since_tizen>
117 public event EventHandler<ScrollStateChangedEventArgs> ScrollStateChanged
121 if (textEditorScrollStateChangedEventHandler == null)
123 textEditorScrollStateChangedCallbackDelegate = OnScrollStateChanged;
124 ScrollStateChangedSignal(this).Connect(textEditorScrollStateChangedCallbackDelegate);
126 textEditorScrollStateChangedEventHandler += value;
130 textEditorScrollStateChangedEventHandler -= value;
131 if (textEditorScrollStateChangedEventHandler == null && ScrollStateChangedSignal(this).Empty() == false)
133 ScrollStateChangedSignal(this).Disconnect(textEditorScrollStateChangedCallbackDelegate);
139 /// The CursorPositionChanged event is emitted whenever the primary cursor position changed.
141 /// <since_tizen> 9 </since_tizen>
142 public event EventHandler CursorPositionChanged
146 if (textEditorCursorPositionChangedEventHandler == null)
148 textEditorCursorPositionChangedCallbackDelegate = (OnCursorPositionChanged);
149 CursorPositionChangedSignal().Connect(textEditorCursorPositionChangedCallbackDelegate);
151 textEditorCursorPositionChangedEventHandler += value;
155 if (textEditorCursorPositionChangedEventHandler == null && CursorPositionChangedSignal().Empty() == false)
157 this.CursorPositionChangedSignal().Disconnect(textEditorCursorPositionChangedCallbackDelegate);
159 textEditorCursorPositionChangedEventHandler -= value;
164 /// The MaxLengthReached event.
166 /// This will be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API.
167 [EditorBrowsable(EditorBrowsableState.Never)]
168 public event EventHandler<MaxLengthReachedEventArgs> MaxLengthReached
172 if (textEditorMaxLengthReachedEventHandler == null)
174 textEditorMaxLengthReachedCallbackDelegate = (OnMaxLengthReached);
175 MaxLengthReachedSignal().Connect(textEditorMaxLengthReachedCallbackDelegate);
177 textEditorMaxLengthReachedEventHandler += value;
181 if (textEditorMaxLengthReachedEventHandler == null && MaxLengthReachedSignal().Empty() == false)
183 this.MaxLengthReachedSignal().Disconnect(textEditorMaxLengthReachedCallbackDelegate);
185 textEditorMaxLengthReachedEventHandler -= value;
190 /// The AnchorClicked signal is emitted when the anchor is clicked.
192 /// <since_tizen> 9 </since_tizen>
193 public event EventHandler<AnchorClickedEventArgs> AnchorClicked
197 if (textEditorAnchorClickedEventHandler == null)
199 textEditorAnchorClickedCallbackDelegate = (OnAnchorClicked);
200 AnchorClickedSignal().Connect(textEditorAnchorClickedCallbackDelegate);
202 textEditorAnchorClickedEventHandler += value;
206 textEditorAnchorClickedEventHandler -= value;
207 if (textEditorAnchorClickedEventHandler == null && AnchorClickedSignal().Empty() == false)
209 AnchorClickedSignal().Disconnect(textEditorAnchorClickedCallbackDelegate);
215 /// The SelectionStarted event is emitted when the selection has been started.
217 /// <since_tizen> 10 </since_tizen>
218 public event EventHandler SelectionStarted
222 if (textEditorSelectionStartedEventHandler == null)
224 textEditorSelectionStartedCallbackDelegate = (OnSelectionStarted);
225 SelectionStartedSignal().Connect(textEditorSelectionStartedCallbackDelegate);
227 textEditorSelectionStartedEventHandler += value;
231 if (textEditorSelectionStartedEventHandler == null && SelectionStartedSignal().Empty() == false)
233 this.SelectionStartedSignal().Disconnect(textEditorSelectionStartedCallbackDelegate);
235 textEditorSelectionStartedEventHandler -= value;
240 /// The SelectionCleared signal is emitted when selection is cleared.
242 /// <since_tizen> 9 </since_tizen>
243 public event EventHandler SelectionCleared
247 if (textEditorSelectionClearedEventHandler == null)
249 textEditorSelectionClearedCallbackDelegate = (OnSelectionCleared);
250 SelectionClearedSignal().Connect(textEditorSelectionClearedCallbackDelegate);
252 textEditorSelectionClearedEventHandler += value;
256 if (textEditorSelectionClearedEventHandler == null && SelectionClearedSignal().Empty() == false)
258 this.SelectionClearedSignal().Disconnect(textEditorSelectionClearedCallbackDelegate);
260 textEditorSelectionClearedEventHandler -= value;
265 /// The SelectionChanged event is emitted whenever the selected text is changed.
267 /// <since_tizen> 9 </since_tizen>
268 public event EventHandler SelectionChanged
272 if (textEditorSelectionChangedEventHandler == null)
274 textEditorSelectionChangedCallbackDelegate = (OnSelectionChanged);
275 SelectionChangedSignal().Connect(textEditorSelectionChangedCallbackDelegate);
277 textEditorSelectionChangedEventHandler += value;
281 if (textEditorSelectionChangedEventHandler == null && SelectionChangedSignal().Empty() == false)
283 this.SelectionChangedSignal().Disconnect(textEditorSelectionChangedCallbackDelegate);
285 textEditorSelectionChangedEventHandler -= value;
290 /// The InputFiltered signal is emitted when the input is filtered by InputFilter. <br />
293 /// See <see cref="InputFilterType"/> and <see cref="InputFilteredEventArgs"/> for a detailed description. <br />
296 /// The following example demonstrates how to use the InputFiltered event.
298 /// editor.InputFiltered += (s, e) =>
300 /// if (e.Type == InputFilterType.Accept)
302 /// // If input is filtered by InputFilter of Accept type.
304 /// else if (e.Type == InputFilterType.Reject)
306 /// // If input is filtered by InputFilter of Reject type.
311 /// <since_tizen> 9 </since_tizen>
312 public event EventHandler<InputFilteredEventArgs> InputFiltered
316 if (textEditorInputFilteredEventHandler == null)
318 textEditorInputFilteredCallbackDelegate = (OnInputFiltered);
319 InputFilteredSignal().Connect(textEditorInputFilteredCallbackDelegate);
321 textEditorInputFilteredEventHandler += value;
325 textEditorInputFilteredEventHandler -= value;
326 if (textEditorInputFilteredEventHandler == null && InputFilteredSignal().Empty() == false)
328 InputFilteredSignal().Disconnect(textEditorInputFilteredCallbackDelegate);
333 internal TextEditorSignal SelectionStartedSignal()
335 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.SelectionStartedSignal(SwigCPtr), false);
336 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
340 internal TextEditorSignal SelectionClearedSignal()
342 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.SelectionClearedSignal(SwigCPtr), false);
343 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
347 internal TextEditorSignal TextChangedSignal()
349 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.TextChangedSignal(SwigCPtr), false);
350 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
354 internal ScrollStateChangedSignal ScrollStateChangedSignal(TextEditor textEditor)
356 ScrollStateChangedSignal ret = new ScrollStateChangedSignal(Interop.TextEditor.ScrollStateChangedSignal(TextEditor.getCPtr(textEditor)), false);
357 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
361 internal TextEditorSignal CursorPositionChangedSignal()
363 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.CursorPositionChangedSignal(SwigCPtr), false);
364 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
368 internal TextEditorSignal MaxLengthReachedSignal()
370 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.MaxLengthReachedSignal(SwigCPtr), false);
371 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
375 internal TextEditorSignal AnchorClickedSignal()
377 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.AnchorClickedSignal(SwigCPtr), false);
378 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
382 internal TextEditorSignal SelectionChangedSignal()
384 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.SelectionChangedSignal(SwigCPtr), false);
385 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
389 internal TextEditorSignal InputFilteredSignal()
391 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.InputFilteredSignal(SwigCPtr), false);
392 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
396 private void OnTextChanged(IntPtr textEditor)
398 if (textEditorTextChangedEventHandler != null && invokeTextChanged)
400 TextChangedEventArgs e = new TextChangedEventArgs();
402 // Populate all members of "e" (TextChangedEventArgs) with real data
403 e.TextEditor = Registry.GetManagedBaseHandleFromNativePtr(textEditor) as TextEditor;
404 //here we send all data to user event handlers
405 textEditorTextChangedEventHandler(this, e);
409 private void OnSelectionStarted(IntPtr textEditor)
411 //no data to be sent to the user
412 textEditorSelectionStartedEventHandler?.Invoke(this, EventArgs.Empty);
415 private void OnSelectionCleared(IntPtr textEditor)
417 //no data to be sent to the user
418 textEditorSelectionClearedEventHandler?.Invoke(this, EventArgs.Empty);
421 private void OnScrollStateChanged(IntPtr textEditor, ScrollState state)
423 if (textEditorScrollStateChangedEventHandler != null)
425 ScrollStateChangedEventArgs e = new ScrollStateChangedEventArgs();
427 if (textEditor != global::System.IntPtr.Zero)
429 // Populate all members of "e" (ScrollStateChangedEventArgs) with real data
430 e.TextEditor = Registry.GetManagedBaseHandleFromNativePtr(textEditor) as TextEditor;
431 e.ScrollState = state;
433 //here we send all data to user event handlers
434 textEditorScrollStateChangedEventHandler(this, e);
438 private void OnCursorPositionChanged(IntPtr textEditor, uint oldPosition)
440 // no data to be sent to the user, as in NUI there is no event provide old values.
441 textEditorCursorPositionChangedEventHandler?.Invoke(this, EventArgs.Empty);
444 private void OnMaxLengthReached(IntPtr textEditor)
446 if (textEditorMaxLengthReachedEventHandler != null)
448 MaxLengthReachedEventArgs e = new MaxLengthReachedEventArgs();
450 // Populate all members of "e" (MaxLengthReachedEventArgs) with real data
451 e.TextEditor = Registry.GetManagedBaseHandleFromNativePtr(textEditor) as TextEditor;
452 //here we send all data to user event handlers
453 textEditorMaxLengthReachedEventHandler(this, e);
457 private void OnAnchorClicked(IntPtr textEditor, IntPtr href, uint hrefLength)
459 // Note: hrefLength is useful for get the length of a const char* (href) in dali-toolkit.
460 // But NUI can get the length of string (href), so hrefLength is not necessary in NUI.
461 AnchorClickedEventArgs e = new AnchorClickedEventArgs();
463 // Populate all members of "e" (AnchorClickedEventArgs) with real data
464 e.Href = Marshal.PtrToStringAnsi(href);
465 //here we send all data to user event handlers
466 textEditorAnchorClickedEventHandler?.Invoke(this, e);
469 private void OnSelectionChanged(IntPtr textEditor, uint oldStart, uint oldEnd)
471 // no data to be sent to the user, as in NUI there is no event provide old values.
472 textEditorSelectionChangedEventHandler?.Invoke(this, EventArgs.Empty);
475 private void OnInputFiltered(IntPtr textEditor, InputFilterType type)
477 InputFilteredEventArgs e = new InputFilteredEventArgs();
479 // Populate all members of "e" (InputFilteredEventArgs) with real data
481 //here we send all data to user event handlers
482 textEditorInputFilteredEventHandler?.Invoke(this, e);
486 /// Event arguments that passed via the TextChanged signal.
488 /// <since_tizen> 3 </since_tizen>
489 public class TextChangedEventArgs : EventArgs
491 private TextEditor textEditor;
494 /// TextEditor - is the texteditor control which has the text contents changed.
496 /// <since_tizen> 3 </since_tizen>
497 public TextEditor TextEditor
511 /// Event arguments that passed via the ScrollStateChanged signal.
513 /// <since_tizen> 3 </since_tizen>
514 public class ScrollStateChangedEventArgs : EventArgs
516 private TextEditor textEditor;
517 private ScrollState scrollState;
520 /// TextEditor - is the texteditor control which has the scroll state changed.
522 /// <since_tizen> 3 </since_tizen>
523 public TextEditor TextEditor
536 /// ScrollState - is the texteditor control scroll state.
538 /// <since_tizen> 3 </since_tizen>
539 public ScrollState ScrollState
553 /// The MaxLengthReached event arguments.
555 /// This will be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API.
556 [EditorBrowsable(EditorBrowsableState.Never)]
557 public class MaxLengthReachedEventArgs : EventArgs
559 private TextEditor textEditor;
564 /// This will be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API.
565 [EditorBrowsable(EditorBrowsableState.Never)]
566 public TextEditor TextEditor