1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
10 |
|
|
**************************************************************************/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/**************************************************************************/ |
15 |
|
|
/** */ |
16 |
|
|
/** GUIX Component */ |
17 |
|
|
/** */ |
18 |
|
|
/** Multi Line Text Input Managment (Multi Line Text Input) */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
|
22 |
|
|
#define GX_SOURCE_CODE |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
/* Include necessary system files. */ |
26 |
|
|
|
27 |
|
|
#include "gx_api.h" |
28 |
|
|
#include "gx_system.h" |
29 |
|
|
#include "gx_multi_line_text_view.h" |
30 |
|
|
#include "gx_multi_line_text_input.h" |
31 |
|
|
#include "gx_scrollbar.h" |
32 |
|
|
#include "gx_window.h" |
33 |
|
|
#include "gx_widget.h" |
34 |
|
|
#include "gx_utility.h" |
35 |
|
|
|
36 |
|
|
/**************************************************************************/ |
37 |
|
|
/* */ |
38 |
|
|
/* FUNCTION RELEASE */ |
39 |
|
|
/* */ |
40 |
|
|
/* _gx_multi_line_text_input_new_line_character_get PORTABLE C */ |
41 |
|
|
/* 6.1 */ |
42 |
|
|
/* AUTHOR */ |
43 |
|
|
/* */ |
44 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
45 |
|
|
/* */ |
46 |
|
|
/* DESCRIPTION */ |
47 |
|
|
/* */ |
48 |
|
|
/* Internal helper function to retrieve the new line character of the */ |
49 |
|
|
/* input text. */ |
50 |
|
|
/* */ |
51 |
|
|
/* INPUT */ |
52 |
|
|
/* */ |
53 |
|
|
/* text_view Multi-line text input widget */ |
54 |
|
|
/* control block */ |
55 |
|
|
/* */ |
56 |
|
|
/* OUTPUT */ |
57 |
|
|
/* */ |
58 |
|
|
/* status Completion status */ |
59 |
|
|
/* */ |
60 |
|
|
/* CALLS */ |
61 |
|
|
/* */ |
62 |
|
|
/* memcpy Copy block of memory */ |
63 |
|
|
/* _gx_utility_utf8_string_character_get Parse utf8 string to */ |
64 |
|
|
/* multi-byte glyph */ |
65 |
|
|
/* */ |
66 |
|
|
/* CALLED BY */ |
67 |
|
|
/* */ |
68 |
|
|
/* _gx_multi_line_text_input_text_set */ |
69 |
|
|
/* */ |
70 |
|
|
/**************************************************************************/ |
71 |
|
1109 |
static VOID _gx_multi_line_text_input_new_line_character_get(GX_MULTI_LINE_TEXT_INPUT *text_input) |
72 |
|
|
{ |
73 |
|
|
GX_STRING string; |
74 |
|
|
GX_CONST GX_CHAR *ch; |
75 |
|
|
|
76 |
|
|
#ifdef GX_UTF8_SUPPORT |
77 |
|
|
UINT glyph_len; |
78 |
|
|
#endif |
79 |
|
|
|
80 |
|
1109 |
string = text_input -> gx_multi_line_text_view_text; |
81 |
|
|
|
82 |
✓✓ |
38683 |
while (string.gx_string_length > 0) |
83 |
|
|
{ |
84 |
|
38466 |
ch = string.gx_string_ptr; |
85 |
|
|
|
86 |
|
|
#ifdef GX_UTF8_SUPPORT |
87 |
|
38466 |
_gx_utility_utf8_string_character_get(&string, GX_NULL, &glyph_len); |
88 |
|
|
#else |
89 |
|
|
string.gx_string_ptr++; |
90 |
|
|
string.gx_string_length--; |
91 |
|
|
#endif /* GX_UTF8_SUPPORT */ |
92 |
|
|
|
93 |
✓✓ |
38466 |
if (ch[0] == GX_KEY_CARRIAGE_RETURN) |
94 |
|
|
{ |
95 |
✓✓ |
885 |
if (ch[1] == GX_KEY_LINE_FEED) |
96 |
|
|
{ |
97 |
|
5 |
memcpy(text_input -> gx_multi_line_text_input_new_line_character, "\r\n", 3); /* Use case of memcpy is verified. */ |
98 |
|
5 |
text_input -> gx_multi_line_text_input_new_line_character_size = 2; |
99 |
|
|
} |
100 |
|
|
else |
101 |
|
|
{ |
102 |
|
880 |
memcpy(text_input -> gx_multi_line_text_input_new_line_character, "\r", 2); /* Use case of memcpy is verified. */ |
103 |
|
880 |
text_input -> gx_multi_line_text_input_new_line_character_size = 1; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
885 |
break; |
107 |
|
|
} |
108 |
✓✓ |
37581 |
else if (ch[0] == GX_KEY_LINE_FEED) |
109 |
|
|
{ |
110 |
|
7 |
memcpy(text_input -> gx_multi_line_text_input_new_line_character, "\n", 2); /* Use case of memcpy is verified. */ |
111 |
|
7 |
text_input -> gx_multi_line_text_input_new_line_character_size = 1; |
112 |
|
7 |
break; |
113 |
|
|
} |
114 |
|
|
} |
115 |
|
1109 |
} |
116 |
|
|
|
117 |
|
|
/**************************************************************************/ |
118 |
|
|
/* */ |
119 |
|
|
/* FUNCTION RELEASE */ |
120 |
|
|
/* */ |
121 |
|
|
/* _gx_multi_line_text_input_text_set PORTABLE C */ |
122 |
|
|
/* 6.1 */ |
123 |
|
|
/* AUTHOR */ |
124 |
|
|
/* */ |
125 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
126 |
|
|
/* */ |
127 |
|
|
/* DESCRIPTION (Deprecated) */ |
128 |
|
|
/* */ |
129 |
|
|
/* This function assigns a text string to a multi line text input */ |
130 |
|
|
/* widget. */ |
131 |
|
|
/* */ |
132 |
|
|
/* INPUT */ |
133 |
|
|
/* */ |
134 |
|
|
/* text_view Multi-line text input widget */ |
135 |
|
|
/* control block */ |
136 |
|
|
/* text Null-terminated text string */ |
137 |
|
|
/* */ |
138 |
|
|
/* OUTPUT */ |
139 |
|
|
/* */ |
140 |
|
|
/* status Completion status */ |
141 |
|
|
/* */ |
142 |
|
|
/* CALLS */ |
143 |
|
|
/* */ |
144 |
|
|
/* _gx_utility_string_length_check Calculate string length */ |
145 |
|
|
/* _gx_multi_line_text_input_text_set_ext */ |
146 |
|
|
/* New text set function */ |
147 |
|
|
/* */ |
148 |
|
|
/* CALLED BY */ |
149 |
|
|
/* */ |
150 |
|
|
/* Application Code */ |
151 |
|
|
/* */ |
152 |
|
|
/**************************************************************************/ |
153 |
|
|
#if defined(GX_ENABLE_DEPRECATED_STRING_API) |
154 |
|
928 |
UINT _gx_multi_line_text_input_text_set(GX_MULTI_LINE_TEXT_INPUT *text_input, GX_CONST GX_CHAR *text) |
155 |
|
|
{ |
156 |
|
|
UINT status; |
157 |
|
|
UINT str_len; |
158 |
|
|
GX_STRING new_string; |
159 |
|
|
|
160 |
|
928 |
new_string.gx_string_ptr = text; |
161 |
|
928 |
status = _gx_utility_string_length_check(text, &str_len, GX_MAX_STRING_LENGTH); |
162 |
✓✓ |
928 |
if (status == GX_SUCCESS) |
163 |
|
|
{ |
164 |
|
927 |
new_string.gx_string_length = str_len; |
165 |
|
927 |
status = _gx_multi_line_text_input_text_set_ext(text_input, &new_string); |
166 |
|
|
} |
167 |
|
|
|
168 |
|
928 |
return(status); |
169 |
|
|
} |
170 |
|
|
#endif |
171 |
|
|
|
172 |
|
|
/**************************************************************************/ |
173 |
|
|
/* */ |
174 |
|
|
/* FUNCTION RELEASE */ |
175 |
|
|
/* */ |
176 |
|
|
/* _gx_multi_line_text_input_text_set_ext PORTABLE C */ |
177 |
|
|
/* 6.1 */ |
178 |
|
|
/* AUTHOR */ |
179 |
|
|
/* */ |
180 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
181 |
|
|
/* */ |
182 |
|
|
/* DESCRIPTION */ |
183 |
|
|
/* */ |
184 |
|
|
/* This function assigns a text string to a multi line text input */ |
185 |
|
|
/* widget. */ |
186 |
|
|
/* */ |
187 |
|
|
/* INPUT */ |
188 |
|
|
/* */ |
189 |
|
|
/* text_view Multi-line text input widget */ |
190 |
|
|
/* control block */ |
191 |
|
|
/* text Null-terminated text string */ |
192 |
|
|
/* */ |
193 |
|
|
/* OUTPUT */ |
194 |
|
|
/* */ |
195 |
|
|
/* status Completion status */ |
196 |
|
|
/* */ |
197 |
|
|
/* CALLS */ |
198 |
|
|
/* */ |
199 |
|
|
/* _gx_multi_line_text_input_new_line_character_get */ |
200 |
|
|
/* Get the new line character */ |
201 |
|
|
/* _gx_multi_line_text_view_string_total_rows_compute */ |
202 |
|
|
/* Compute the total rows of */ |
203 |
|
|
/* the input text */ |
204 |
|
|
/* _gx_multi_line_text_view_line_cache_update */ |
205 |
|
|
/* Update line cache */ |
206 |
|
|
/* _gx_window_scrollbar_find Find scrollbar for a window */ |
207 |
|
|
/* _gx_scrollbar_reset Reset scrollbar information */ |
208 |
|
|
/* _gx_system_dirty_mark Mark the widget dirty */ |
209 |
|
|
/* */ |
210 |
|
|
/* CALLED BY */ |
211 |
|
|
/* */ |
212 |
|
|
/* Application Code */ |
213 |
|
|
/* */ |
214 |
|
|
/**************************************************************************/ |
215 |
|
1109 |
UINT _gx_multi_line_text_input_text_set_ext(GX_MULTI_LINE_TEXT_INPUT *text_input, GX_CONST GX_STRING *text) |
216 |
|
|
{ |
217 |
|
|
GX_SCROLLBAR *scroll; |
218 |
|
|
UINT copy_size; |
219 |
|
|
|
220 |
|
|
#if defined GX_UTF8_SUPPORT |
221 |
|
|
GX_STRING string; |
222 |
|
|
UINT index; |
223 |
|
1109 |
UINT glyph_len = 0; |
224 |
|
|
#endif |
225 |
|
|
|
226 |
✓✓✓✓
|
1109 |
if (text && text -> gx_string_ptr) |
227 |
|
|
{ |
228 |
|
1107 |
copy_size = text_input -> gx_multi_line_text_input_buffer_size - 1; |
229 |
|
|
|
230 |
✓✓ |
1107 |
if (text -> gx_string_length > copy_size - 1) |
231 |
|
|
{ |
232 |
|
|
#if defined GX_UTF8_SUPPORT |
233 |
|
4 |
string.gx_string_ptr = text -> gx_string_ptr; |
234 |
|
4 |
string.gx_string_length = copy_size; |
235 |
|
|
|
236 |
|
4 |
index = 0; |
237 |
|
|
|
238 |
|
|
/* Calculate maximum bytes that can be copied. */ |
239 |
✓✓ |
476 |
while (_gx_utility_utf8_string_character_get(&string, GX_NULL, &glyph_len) == GX_SUCCESS) |
240 |
|
|
{ |
241 |
|
472 |
index += glyph_len; |
242 |
|
|
} |
243 |
|
4 |
copy_size = index; |
244 |
|
|
#endif |
245 |
|
|
} |
246 |
|
|
else |
247 |
|
|
{ |
248 |
|
1103 |
copy_size = text -> gx_string_length; |
249 |
|
|
} |
250 |
|
|
|
251 |
|
1107 |
memcpy((GX_CHAR *)text_input -> gx_multi_line_text_view_text.gx_string_ptr, text -> gx_string_ptr, copy_size); /* Use case of memcpy is verified. */ |
252 |
|
1107 |
text_input -> gx_multi_line_text_view_text.gx_string_length = copy_size; |
253 |
|
|
} |
254 |
|
|
else |
255 |
|
|
{ |
256 |
|
2 |
copy_size = 0; |
257 |
|
|
} |
258 |
|
|
|
259 |
|
1109 |
((GX_CHAR *)text_input -> gx_multi_line_text_view_text.gx_string_ptr)[copy_size] = '\0'; |
260 |
|
|
|
261 |
|
1109 |
text_input -> gx_multi_line_text_view_text.gx_string_length = copy_size; |
262 |
|
|
|
263 |
|
|
/* Get new line character. */ |
264 |
|
1109 |
_gx_multi_line_text_input_new_line_character_get(text_input); |
265 |
|
|
|
266 |
✓✓ |
1109 |
if (text_input -> gx_widget_status & GX_STATUS_VISIBLE) |
267 |
|
|
{ |
268 |
|
|
/* Compute the total rows of input string. */ |
269 |
|
893 |
_gx_multi_line_text_view_string_total_rows_compute((GX_MULTI_LINE_TEXT_VIEW *)text_input); |
270 |
|
|
|
271 |
|
893 |
text_input -> gx_multi_line_text_input_text_insert_position = copy_size; |
272 |
|
|
|
273 |
|
893 |
_gx_window_scrollbar_find((GX_WINDOW *)text_input, GX_TYPE_VERTICAL_SCROLL, &scroll); |
274 |
✓✓ |
893 |
if (scroll) |
275 |
|
|
{ |
276 |
|
|
/* Reset scrollbar. */ |
277 |
|
887 |
_gx_scrollbar_reset(scroll, GX_NULL); |
278 |
|
|
} |
279 |
|
|
else |
280 |
|
|
{ |
281 |
|
|
|
282 |
|
6 |
if (text_input -> gx_multi_line_text_view_text_total_rows > |
283 |
✓✓ |
6 |
text_input -> gx_multi_line_text_view_cache_size) |
284 |
|
|
{ |
285 |
|
|
/* Update line cache. */ |
286 |
|
1 |
_gx_multi_line_text_view_line_cache_update((GX_MULTI_LINE_TEXT_VIEW *)text_input); |
287 |
|
|
} |
288 |
|
|
} |
289 |
|
|
|
290 |
|
|
/* Update cursor position. */ |
291 |
|
893 |
_gx_multi_line_text_input_cursor_pos_update(text_input, GX_TRUE); |
292 |
|
|
|
293 |
|
893 |
_gx_system_dirty_mark((GX_WIDGET *)text_input); |
294 |
|
|
} |
295 |
|
|
else |
296 |
|
|
{ |
297 |
|
216 |
text_input -> gx_multi_line_text_view_line_index_old = GX_TRUE; |
298 |
|
216 |
text_input -> gx_multi_line_text_input_text_insert_position = 0; |
299 |
|
|
} |
300 |
|
1109 |
return(GX_SUCCESS); |
301 |
|
|
} |
302 |
|
|
|