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 textEditorSelectionChangedEventHandler;
46 private SelectionChangedCallbackDelegate textEditorSelectionChangedCallbackDelegate;
48 private EventHandler<InputFilteredEventArgs> textEditorInputFilteredEventHandler;
49 private InputFilteredCallbackDelegate textEditorInputFilteredCallbackDelegate;
51 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
52 private delegate void TextChangedCallbackDelegate(IntPtr textEditor);
54 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
55 private delegate void ScrollStateChangedCallbackDelegate(IntPtr textEditor, ScrollState state);
57 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
58 private delegate void CursorPositionChangedCallbackDelegate(IntPtr textEditor, uint oldPosition);
60 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
61 private delegate void MaxLengthReachedCallbackDelegate(IntPtr textEditor);
63 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
64 private delegate void AnchorClickedCallbackDelegate(IntPtr textEditor, IntPtr href, uint hrefLength);
66 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
67 private delegate void SelectionChangedCallbackDelegate(IntPtr textEditor, uint oldStart, uint oldEnd);
69 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
70 private delegate void InputFilteredCallbackDelegate(IntPtr textEditor, InputFilterType type);
73 /// An event for the TextChanged signal which can be used to subscribe or unsubscribe the event handler
74 /// provided by the user. The TextChanged signal is emitted when the text changes.<br />
76 /// <since_tizen> 3 </since_tizen>
77 public event EventHandler<TextChangedEventArgs> TextChanged
81 if (textEditorTextChangedEventHandler == null)
83 textEditorTextChangedCallbackDelegate = (OnTextChanged);
84 TextChangedSignal().Connect(textEditorTextChangedCallbackDelegate);
86 textEditorTextChangedEventHandler += value;
90 textEditorTextChangedEventHandler -= value;
91 if (textEditorTextChangedEventHandler == null && TextChangedSignal().Empty() == false)
93 TextChangedSignal().Disconnect(textEditorTextChangedCallbackDelegate);
99 /// Event for the ScrollStateChanged signal which can be used to subscribe or unsubscribe the event handler
100 /// provided by the user. The ScrollStateChanged signal is emitted when the scroll state changes.<br />
102 /// <since_tizen> 3 </since_tizen>
103 public event EventHandler<ScrollStateChangedEventArgs> ScrollStateChanged
107 if (textEditorScrollStateChangedEventHandler == null)
109 textEditorScrollStateChangedCallbackDelegate = OnScrollStateChanged;
110 ScrollStateChangedSignal(this).Connect(textEditorScrollStateChangedCallbackDelegate);
112 textEditorScrollStateChangedEventHandler += value;
116 textEditorScrollStateChangedEventHandler -= value;
117 if (textEditorScrollStateChangedEventHandler == null && ScrollStateChangedSignal(this).Empty() == false)
119 ScrollStateChangedSignal(this).Disconnect(textEditorScrollStateChangedCallbackDelegate);
125 /// The CursorPositionChanged event.
127 /// This will be public opened after ACR done. Before ACR, need to be hidden as inhouse API.
128 [EditorBrowsable(EditorBrowsableState.Never)]
129 public event EventHandler CursorPositionChanged
133 if (textEditorCursorPositionChangedEventHandler == null)
135 textEditorCursorPositionChangedCallbackDelegate = (OnCursorPositionChanged);
136 CursorPositionChangedSignal().Connect(textEditorCursorPositionChangedCallbackDelegate);
138 textEditorCursorPositionChangedEventHandler += value;
142 if (textEditorCursorPositionChangedEventHandler == null && CursorPositionChangedSignal().Empty() == false)
144 this.CursorPositionChangedSignal().Disconnect(textEditorCursorPositionChangedCallbackDelegate);
146 textEditorCursorPositionChangedEventHandler -= value;
151 /// The MaxLengthReached event.
153 /// This will be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API.
154 [EditorBrowsable(EditorBrowsableState.Never)]
155 public event EventHandler<MaxLengthReachedEventArgs> MaxLengthReached
159 if (textEditorMaxLengthReachedEventHandler == null)
161 textEditorMaxLengthReachedCallbackDelegate = (OnMaxLengthReached);
162 MaxLengthReachedSignal().Connect(textEditorMaxLengthReachedCallbackDelegate);
164 textEditorMaxLengthReachedEventHandler += value;
168 if (textEditorMaxLengthReachedEventHandler == null && MaxLengthReachedSignal().Empty() == false)
170 this.MaxLengthReachedSignal().Disconnect(textEditorMaxLengthReachedCallbackDelegate);
172 textEditorMaxLengthReachedEventHandler -= value;
177 /// The AnchorClicked signal is emitted when the anchor is clicked.
179 /// <since_tizen> 9 </since_tizen>
180 public event EventHandler<AnchorClickedEventArgs> AnchorClicked
184 if (textEditorAnchorClickedEventHandler == null)
186 textEditorAnchorClickedCallbackDelegate = (OnAnchorClicked);
187 AnchorClickedSignal().Connect(textEditorAnchorClickedCallbackDelegate);
189 textEditorAnchorClickedEventHandler += value;
193 textEditorAnchorClickedEventHandler -= value;
194 if (textEditorAnchorClickedEventHandler == null && AnchorClickedSignal().Empty() == false)
196 AnchorClickedSignal().Disconnect(textEditorAnchorClickedCallbackDelegate);
202 /// The SelectionChanged event.
204 /// This will be public opened after ACR done. Before ACR, need to be hidden as inhouse API.
205 [EditorBrowsable(EditorBrowsableState.Never)]
206 public event EventHandler SelectionChanged
210 if (textEditorSelectionChangedEventHandler == null)
212 textEditorSelectionChangedCallbackDelegate = (OnSelectionChanged);
213 SelectionChangedSignal().Connect(textEditorSelectionChangedCallbackDelegate);
215 textEditorSelectionChangedEventHandler += value;
219 if (textEditorSelectionChangedEventHandler == null && SelectionChangedSignal().Empty() == false)
221 this.SelectionChangedSignal().Disconnect(textEditorSelectionChangedCallbackDelegate);
223 textEditorSelectionChangedEventHandler -= value;
228 /// The InputFiltered signal is emitted when the input is filtered by InputFilter. <br />
231 /// See <see cref="InputFilterType"/> and <see cref="InputFilteredEventArgs"/> for a detailed description. <br />
234 /// The following example demonstrates how to use the InputFiltered event.
236 /// editor.InputFiltered += (s, e) =>
238 /// if (e.Type == InputFilterType.Accept)
240 /// // If input is filtered by InputFilter of Accept type.
242 /// else if (e.Type == InputFilterType.Reject)
244 /// // If input is filtered by InputFilter of Reject type.
249 [EditorBrowsable(EditorBrowsableState.Never)]
250 public event EventHandler<InputFilteredEventArgs> InputFiltered
254 if (textEditorInputFilteredEventHandler == null)
256 textEditorInputFilteredCallbackDelegate = (OnInputFiltered);
257 InputFilteredSignal().Connect(textEditorInputFilteredCallbackDelegate);
259 textEditorInputFilteredEventHandler += value;
263 textEditorInputFilteredEventHandler -= value;
264 if (textEditorInputFilteredEventHandler == null && InputFilteredSignal().Empty() == false)
266 InputFilteredSignal().Disconnect(textEditorInputFilteredCallbackDelegate);
271 internal TextEditorSignal TextChangedSignal()
273 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.TextChangedSignal(SwigCPtr), false);
274 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
278 internal ScrollStateChangedSignal ScrollStateChangedSignal(TextEditor textEditor)
280 ScrollStateChangedSignal ret = new ScrollStateChangedSignal(Interop.TextEditor.ScrollStateChangedSignal(TextEditor.getCPtr(textEditor)), false);
281 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
285 internal TextEditorSignal CursorPositionChangedSignal()
287 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.CursorPositionChangedSignal(SwigCPtr), false);
288 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
292 internal TextEditorSignal MaxLengthReachedSignal()
294 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.MaxLengthReachedSignal(SwigCPtr), false);
295 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
299 internal TextEditorSignal AnchorClickedSignal()
301 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.AnchorClickedSignal(SwigCPtr), false);
302 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
306 internal TextEditorSignal SelectionChangedSignal()
308 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.SelectionChangedSignal(SwigCPtr), false);
309 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
313 internal TextEditorSignal InputFilteredSignal()
315 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.InputFilteredSignal(SwigCPtr), false);
316 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320 private void OnTextChanged(IntPtr textEditor)
322 if (textEditorTextChangedEventHandler != null)
324 TextChangedEventArgs e = new TextChangedEventArgs();
326 // Populate all members of "e" (TextChangedEventArgs) with real data
327 e.TextEditor = Registry.GetManagedBaseHandleFromNativePtr(textEditor) as TextEditor;
328 //here we send all data to user event handlers
329 textEditorTextChangedEventHandler(this, e);
333 private void OnScrollStateChanged(IntPtr textEditor, ScrollState state)
335 if (textEditorScrollStateChangedEventHandler != null)
337 ScrollStateChangedEventArgs e = new ScrollStateChangedEventArgs();
339 if (textEditor != global::System.IntPtr.Zero)
341 // Populate all members of "e" (ScrollStateChangedEventArgs) with real data
342 e.TextEditor = Registry.GetManagedBaseHandleFromNativePtr(textEditor) as TextEditor;
343 e.ScrollState = state;
345 //here we send all data to user event handlers
346 textEditorScrollStateChangedEventHandler(this, e);
350 private void OnCursorPositionChanged(IntPtr textEditor, uint oldPosition)
352 // no data to be sent to the user, as in NUI there is no event provide old values.
353 textEditorCursorPositionChangedEventHandler?.Invoke(this, EventArgs.Empty);
356 private void OnMaxLengthReached(IntPtr textEditor)
358 if (textEditorMaxLengthReachedEventHandler != null)
360 MaxLengthReachedEventArgs e = new MaxLengthReachedEventArgs();
362 // Populate all members of "e" (MaxLengthReachedEventArgs) with real data
363 e.TextEditor = Registry.GetManagedBaseHandleFromNativePtr(textEditor) as TextEditor;
364 //here we send all data to user event handlers
365 textEditorMaxLengthReachedEventHandler(this, e);
369 private void OnAnchorClicked(IntPtr textEditor, IntPtr href, uint hrefLength)
371 // Note: hrefLength is useful for get the length of a const char* (href) in dali-toolkit.
372 // But NUI can get the length of string (href), so hrefLength is not necessary in NUI.
373 AnchorClickedEventArgs e = new AnchorClickedEventArgs();
375 // Populate all members of "e" (AnchorClickedEventArgs) with real data
376 e.Href = Marshal.PtrToStringAnsi(href);
377 //here we send all data to user event handlers
378 textEditorAnchorClickedEventHandler?.Invoke(this, e);
381 private void OnSelectionChanged(IntPtr textEditor, uint oldStart, uint oldEnd)
383 // no data to be sent to the user, as in NUI there is no event provide old values.
384 textEditorSelectionChangedEventHandler?.Invoke(this, EventArgs.Empty);
387 private void OnInputFiltered(IntPtr textEditor, InputFilterType type)
389 InputFilteredEventArgs e = new InputFilteredEventArgs();
391 // Populate all members of "e" (InputFilteredEventArgs) with real data
393 //here we send all data to user event handlers
394 textEditorInputFilteredEventHandler?.Invoke(this, e);
398 /// Event arguments that passed via the TextChanged signal.
400 /// <since_tizen> 3 </since_tizen>
401 public class TextChangedEventArgs : EventArgs
403 private TextEditor textEditor;
406 /// TextEditor - is the texteditor control which has the text contents changed.
408 /// <since_tizen> 3 </since_tizen>
409 public TextEditor TextEditor
423 /// Event arguments that passed via the ScrollStateChanged signal.
425 /// <since_tizen> 3 </since_tizen>
426 public class ScrollStateChangedEventArgs : EventArgs
428 private TextEditor textEditor;
429 private ScrollState scrollState;
432 /// TextEditor - is the texteditor control which has the scroll state changed.
434 /// <since_tizen> 3 </since_tizen>
435 public TextEditor TextEditor
448 /// ScrollState - is the texteditor control scroll state.
450 /// <since_tizen> 3 </since_tizen>
451 public ScrollState ScrollState
465 /// The MaxLengthReached event arguments.
467 /// This will be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API.
468 [EditorBrowsable(EditorBrowsableState.Never)]
469 public class MaxLengthReachedEventArgs : EventArgs
471 private TextEditor textEditor;
476 /// This will be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API.
477 [EditorBrowsable(EditorBrowsableState.Never)]
478 public TextEditor TextEditor