2 * Copyright(c) 2019 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.Runtime.InteropServices;
21 namespace Tizen.NUI.BaseComponents
24 /// A control which provides a multi-line editable text editor.
26 /// <since_tizen> 3 </since_tizen>
27 public partial class TextEditor
29 private EventHandler<TextChangedEventArgs> _textEditorTextChangedEventHandler;
30 private TextChangedCallbackDelegate _textEditorTextChangedCallbackDelegate;
32 private EventHandler<ScrollStateChangedEventArgs> _textEditorScrollStateChangedEventHandler;
33 private ScrollStateChangedCallbackDelegate _textEditorScrollStateChangedCallbackDelegate;
35 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
36 private delegate void TextChangedCallbackDelegate(IntPtr textEditor);
38 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
39 private delegate void ScrollStateChangedCallbackDelegate(IntPtr textEditor, ScrollState state);
42 /// An event for the TextChanged signal which can be used to subscribe or unsubscribe the event handler
43 /// provided by the user. The TextChanged signal is emitted when the text changes.<br />
45 /// <since_tizen> 3 </since_tizen>
46 public event EventHandler<TextChangedEventArgs> TextChanged
50 if (_textEditorTextChangedEventHandler == null)
52 _textEditorTextChangedCallbackDelegate = (OnTextChanged);
53 TextChangedSignal().Connect(_textEditorTextChangedCallbackDelegate);
55 _textEditorTextChangedEventHandler += value;
59 _textEditorTextChangedEventHandler -= value;
60 if (_textEditorTextChangedEventHandler == null && TextChangedSignal().Empty() == false)
62 TextChangedSignal().Disconnect(_textEditorTextChangedCallbackDelegate);
68 /// Event for the ScrollStateChanged signal which can be used to subscribe or unsubscribe the event handler
69 /// provided by the user. The ScrollStateChanged signal is emitted when the scroll state changes.<br />
71 /// <since_tizen> 3 </since_tizen>
72 public event EventHandler<ScrollStateChangedEventArgs> ScrollStateChanged
76 if (_textEditorScrollStateChangedEventHandler == null)
78 _textEditorScrollStateChangedCallbackDelegate = OnScrollStateChanged;
79 ScrollStateChangedSignal(this).Connect(_textEditorScrollStateChangedCallbackDelegate);
81 _textEditorScrollStateChangedEventHandler += value;
85 _textEditorScrollStateChangedEventHandler -= value;
86 if (_textEditorScrollStateChangedEventHandler == null && ScrollStateChangedSignal(this).Empty() == false)
88 ScrollStateChangedSignal(this).Disconnect(_textEditorScrollStateChangedCallbackDelegate);
93 internal TextEditorSignal TextChangedSignal()
95 TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.TextEditor_TextChangedSignal(swigCPtr), false);
96 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
100 internal ScrollStateChangedSignal ScrollStateChangedSignal(TextEditor textEditor)
102 ScrollStateChangedSignal ret = new ScrollStateChangedSignal(Interop.TextEditor.TextEditor_ScrollStateChangedSignal(TextEditor.getCPtr(textEditor)), false);
103 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
107 private void OnTextChanged(IntPtr textEditor)
109 TextChangedEventArgs e = new TextChangedEventArgs();
111 // Populate all members of "e" (TextChangedEventArgs) with real data
112 e.TextEditor = Registry.GetManagedBaseHandleFromNativePtr(textEditor) as TextEditor;
114 if (_textEditorTextChangedEventHandler != null)
116 //here we send all data to user event handlers
117 _textEditorTextChangedEventHandler(this, e);
121 private void OnScrollStateChanged(IntPtr textEditor, ScrollState state)
123 ScrollStateChangedEventArgs e = new ScrollStateChangedEventArgs();
125 if (textEditor != global::System.IntPtr.Zero)
127 // Populate all members of "e" (ScrollStateChangedEventArgs) with real data
128 e.TextEditor = Registry.GetManagedBaseHandleFromNativePtr(textEditor) as TextEditor;
129 e.ScrollState = state;
132 if (_textEditorScrollStateChangedEventHandler != null)
134 //here we send all data to user event handlers
135 _textEditorScrollStateChangedEventHandler(this, e);
140 /// Event arguments that passed via the TextChanged signal.
142 /// <since_tizen> 3 </since_tizen>
143 public class TextChangedEventArgs : EventArgs
145 private TextEditor _textEditor;
148 /// TextEditor - is the texteditor control which has the text contents changed.
150 /// <since_tizen> 3 </since_tizen>
151 public TextEditor TextEditor
165 /// Event arguments that passed via the ScrollStateChanged signal.
167 /// <since_tizen> 3 </since_tizen>
168 public class ScrollStateChangedEventArgs : EventArgs
170 private TextEditor _textEditor;
171 private ScrollState _scrollState;
174 /// TextEditor - is the texteditor control which has the scroll state changed.
176 /// <since_tizen> 3 </since_tizen>
177 public TextEditor TextEditor
190 /// ScrollState - is the texteditor control scroll state.
192 /// <since_tizen> 3 </since_tizen>
193 public ScrollState ScrollState
201 _scrollState = value;