/
TextEditorEvent.cs
executable file
·206 lines (186 loc) · 7.68 KB
/
TextEditorEvent.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
* Copyright(c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using System.Runtime.InteropServices;
namespace Tizen.NUI.BaseComponents
{
/// <summary>
/// A control which provides a multi-line editable text editor.
/// </summary>
/// <since_tizen> 3 </since_tizen>
public partial class TextEditor
{
private EventHandler<TextChangedEventArgs> _textEditorTextChangedEventHandler;
private TextChangedCallbackDelegate _textEditorTextChangedCallbackDelegate;
private EventHandler<ScrollStateChangedEventArgs> _textEditorScrollStateChangedEventHandler;
private ScrollStateChangedCallbackDelegate _textEditorScrollStateChangedCallbackDelegate;
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void TextChangedCallbackDelegate(IntPtr textEditor);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void ScrollStateChangedCallbackDelegate(IntPtr textEditor, ScrollState state);
/// <summary>
/// An event for the TextChanged signal which can be used to subscribe or unsubscribe the event handler
/// provided by the user. The TextChanged signal is emitted when the text changes.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
public event EventHandler<TextChangedEventArgs> TextChanged
{
add
{
if (_textEditorTextChangedEventHandler == null)
{
_textEditorTextChangedCallbackDelegate = (OnTextChanged);
TextChangedSignal().Connect(_textEditorTextChangedCallbackDelegate);
}
_textEditorTextChangedEventHandler += value;
}
remove
{
_textEditorTextChangedEventHandler -= value;
if (_textEditorTextChangedEventHandler == null && TextChangedSignal().Empty() == false)
{
TextChangedSignal().Disconnect(_textEditorTextChangedCallbackDelegate);
}
}
}
/// <summary>
/// Event for the ScrollStateChanged signal which can be used to subscribe or unsubscribe the event handler
/// provided by the user. The ScrollStateChanged signal is emitted when the scroll state changes.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
public event EventHandler<ScrollStateChangedEventArgs> ScrollStateChanged
{
add
{
if (_textEditorScrollStateChangedEventHandler == null)
{
_textEditorScrollStateChangedCallbackDelegate = OnScrollStateChanged;
ScrollStateChangedSignal(this).Connect(_textEditorScrollStateChangedCallbackDelegate);
}
_textEditorScrollStateChangedEventHandler += value;
}
remove
{
_textEditorScrollStateChangedEventHandler -= value;
if (_textEditorScrollStateChangedEventHandler == null && ScrollStateChangedSignal(this).Empty() == false)
{
ScrollStateChangedSignal(this).Disconnect(_textEditorScrollStateChangedCallbackDelegate);
}
}
}
internal TextEditorSignal TextChangedSignal()
{
TextEditorSignal ret = new TextEditorSignal(Interop.TextEditor.TextEditor_TextChangedSignal(swigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal ScrollStateChangedSignal ScrollStateChangedSignal(TextEditor textEditor)
{
ScrollStateChangedSignal ret = new ScrollStateChangedSignal(Interop.TextEditor.TextEditor_ScrollStateChangedSignal(TextEditor.getCPtr(textEditor)), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private void OnTextChanged(IntPtr textEditor)
{
TextChangedEventArgs e = new TextChangedEventArgs();
// Populate all members of "e" (TextChangedEventArgs) with real data
e.TextEditor = Registry.GetManagedBaseHandleFromNativePtr(textEditor) as TextEditor;
if (_textEditorTextChangedEventHandler != null)
{
//here we send all data to user event handlers
_textEditorTextChangedEventHandler(this, e);
}
}
private void OnScrollStateChanged(IntPtr textEditor, ScrollState state)
{
ScrollStateChangedEventArgs e = new ScrollStateChangedEventArgs();
if (textEditor != global::System.IntPtr.Zero)
{
// Populate all members of "e" (ScrollStateChangedEventArgs) with real data
e.TextEditor = Registry.GetManagedBaseHandleFromNativePtr(textEditor) as TextEditor;
e.ScrollState = state;
}
if (_textEditorScrollStateChangedEventHandler != null)
{
//here we send all data to user event handlers
_textEditorScrollStateChangedEventHandler(this, e);
}
}
/// <summary>
/// Event arguments that passed via the TextChanged signal.
/// </summary>
/// <since_tizen> 3 </since_tizen>
public class TextChangedEventArgs : EventArgs
{
private TextEditor _textEditor;
/// <summary>
/// TextEditor - is the texteditor control which has the text contents changed.
/// </summary>
/// <since_tizen> 3 </since_tizen>
public TextEditor TextEditor
{
get
{
return _textEditor;
}
set
{
_textEditor = value;
}
}
}
/// <summary>
/// Event arguments that passed via the ScrollStateChanged signal.
/// </summary>
/// <since_tizen> 3 </since_tizen>
public class ScrollStateChangedEventArgs : EventArgs
{
private TextEditor _textEditor;
private ScrollState _scrollState;
/// <summary>
/// TextEditor - is the texteditor control which has the scroll state changed.
/// </summary>
/// <since_tizen> 3 </since_tizen>
public TextEditor TextEditor
{
get
{
return _textEditor;
}
set
{
_textEditor = value;
}
}
/// <summary>
/// ScrollState - is the texteditor control scroll state.
/// </summary>
/// <since_tizen> 3 </since_tizen>
public ScrollState ScrollState
{
get
{
return _scrollState;
}
set
{
_scrollState = value;
}
}
}
}
}