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 /// <since_tizen> 9 </since_tizen>
237 public event EventHandler SelectionChanged
241 if (textEditorSelectionChangedEventHandler == null)
243 textEditorSelectionChangedCallbackDelegate = (OnSelectionChanged);
244 SelectionChangedSignal().Connect(textEditorSelectionChangedCallbackDelegate);
246 textEditorSelectionChangedEventHandler += value;
250 if (textEditorSelectionChangedEventHandler == null && SelectionChangedSignal().Empty() == false)
252 this.SelectionChangedSignal().Disconnect(textEditorSelectionChangedCallbackDelegate);
254 textEditorSelectionChangedEventHandler -= value;
259 /// The InputFiltered signal is emitted when the input is filtered by InputFilter. <br />
262 /// See <see cref="InputFilterType"/> and <see cref="InputFilteredEventArgs"/> for a detailed description. <br />
265 /// The following example demonstrates how to use the InputFiltered event.
267 /// editor.InputFiltered += (s, e) =>
269 /// if (e.Type == InputFilterType.Accept)
271 /// // If input is filtered by InputFilter of Accept type.
273 /// else if (e.Type == InputFilterType.Reject)
275 /// // If input is filtered by InputFilter of Reject type.
280 [EditorBrowsable(EditorBrowsableState.Never)]
281 public event EventHandler<InputFilteredEventArgs> InputFiltered
285 if (textEditorInputFilteredEventHandler == null)
287 textEditorInputFilteredCallbackDelegate = (OnInputFiltered);
288 InputFilteredSignal().Connect(textEditorInputFilteredCallbackDelegate);
290 textEditorInputFilteredEventHandler += value;
294 textEditorInputFilteredEventHandler -= value;
295 if (textEditorInputFilteredEventHandler == null && InputFilteredSignal().Empty() == false)
297 InputFilteredSignal().Disconnect(textEditorInputFilteredCallbackDelegate);
302 internal TextEditorSignal SelectionClearedSignal()
304 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.SelectionClearedSignal(SwigCPtr), false);
305 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
309 internal TextEditorSignal TextChangedSignal()
311 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.TextChangedSignal(SwigCPtr), false);
312 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
316 internal ScrollStateChangedSignal ScrollStateChangedSignal(TextEditor textEditor)
318 ScrollStateChangedSignal ret = new ScrollStateChangedSignal(Interop.TextEditor.ScrollStateChangedSignal(TextEditor.getCPtr(textEditor)), false);
319 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
323 internal TextEditorSignal CursorPositionChangedSignal()
325 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.CursorPositionChangedSignal(SwigCPtr), false);
326 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
330 internal TextEditorSignal MaxLengthReachedSignal()
332 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.MaxLengthReachedSignal(SwigCPtr), false);
333 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
337 internal TextEditorSignal AnchorClickedSignal()
339 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.AnchorClickedSignal(SwigCPtr), false);
340 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
344 internal TextEditorSignal SelectionChangedSignal()
346 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.SelectionChangedSignal(SwigCPtr), false);
347 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
351 internal TextEditorSignal InputFilteredSignal()
353 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.InputFilteredSignal(SwigCPtr), false);
354 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
358 private void OnTextChanged(IntPtr textEditor)
360 if (textEditorTextChangedEventHandler != null)
362 TextChangedEventArgs e = new TextChangedEventArgs();
364 // Populate all members of "e" (TextChangedEventArgs) with real data
365 e.TextEditor = Registry.GetManagedBaseHandleFromNativePtr(textEditor) as TextEditor;
366 //here we send all data to user event handlers
367 textEditorTextChangedEventHandler(this, e);
371 private void OnSelectionCleared(IntPtr textEditor)
373 //no data to be sent to the user
374 textEditorSelectionClearedEventHandler?.Invoke(this, EventArgs.Empty);
377 private void OnScrollStateChanged(IntPtr textEditor, ScrollState state)
379 if (textEditorScrollStateChangedEventHandler != null)
381 ScrollStateChangedEventArgs e = new ScrollStateChangedEventArgs();
383 if (textEditor != global::System.IntPtr.Zero)
385 // Populate all members of "e" (ScrollStateChangedEventArgs) with real data
386 e.TextEditor = Registry.GetManagedBaseHandleFromNativePtr(textEditor) as TextEditor;
387 e.ScrollState = state;
389 //here we send all data to user event handlers
390 textEditorScrollStateChangedEventHandler(this, e);
394 private void OnCursorPositionChanged(IntPtr textEditor, uint oldPosition)
396 // no data to be sent to the user, as in NUI there is no event provide old values.
397 textEditorCursorPositionChangedEventHandler?.Invoke(this, EventArgs.Empty);
400 private void OnMaxLengthReached(IntPtr textEditor)
402 if (textEditorMaxLengthReachedEventHandler != null)
404 MaxLengthReachedEventArgs e = new MaxLengthReachedEventArgs();
406 // Populate all members of "e" (MaxLengthReachedEventArgs) with real data
407 e.TextEditor = Registry.GetManagedBaseHandleFromNativePtr(textEditor) as TextEditor;
408 //here we send all data to user event handlers
409 textEditorMaxLengthReachedEventHandler(this, e);
413 private void OnAnchorClicked(IntPtr textEditor, IntPtr href, uint hrefLength)
415 // Note: hrefLength is useful for get the length of a const char* (href) in dali-toolkit.
416 // But NUI can get the length of string (href), so hrefLength is not necessary in NUI.
417 AnchorClickedEventArgs e = new AnchorClickedEventArgs();
419 // Populate all members of "e" (AnchorClickedEventArgs) with real data
420 e.Href = Marshal.PtrToStringAnsi(href);
421 //here we send all data to user event handlers
422 textEditorAnchorClickedEventHandler?.Invoke(this, e);
425 private void OnSelectionChanged(IntPtr textEditor, uint oldStart, uint oldEnd)
427 // no data to be sent to the user, as in NUI there is no event provide old values.
428 textEditorSelectionChangedEventHandler?.Invoke(this, EventArgs.Empty);
431 private void OnInputFiltered(IntPtr textEditor, InputFilterType type)
433 InputFilteredEventArgs e = new InputFilteredEventArgs();
435 // Populate all members of "e" (InputFilteredEventArgs) with real data
437 //here we send all data to user event handlers
438 textEditorInputFilteredEventHandler?.Invoke(this, e);
442 /// Event arguments that passed via the TextChanged signal.
444 /// <since_tizen> 3 </since_tizen>
445 public class TextChangedEventArgs : EventArgs
447 private TextEditor textEditor;
450 /// TextEditor - is the texteditor control which has the text contents changed.
452 /// <since_tizen> 3 </since_tizen>
453 public TextEditor TextEditor
467 /// Event arguments that passed via the ScrollStateChanged signal.
469 /// <since_tizen> 3 </since_tizen>
470 public class ScrollStateChangedEventArgs : EventArgs
472 private TextEditor textEditor;
473 private ScrollState scrollState;
476 /// TextEditor - is the texteditor control which has the scroll state changed.
478 /// <since_tizen> 3 </since_tizen>
479 public TextEditor TextEditor
492 /// ScrollState - is the texteditor control scroll state.
494 /// <since_tizen> 3 </since_tizen>
495 public ScrollState ScrollState
509 /// The MaxLengthReached event arguments.
511 /// This will be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API.
512 [EditorBrowsable(EditorBrowsableState.Never)]
513 public class MaxLengthReachedEventArgs : EventArgs
515 private TextEditor textEditor;
520 /// This will be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API.
521 [EditorBrowsable(EditorBrowsableState.Never)]
522 public TextEditor TextEditor