1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* |
4 |
|
|
* This program and the accompanying materials are made available under the |
5 |
|
|
* terms of the MIT License which is available at |
6 |
|
|
* https://opensource.org/licenses/MIT. |
7 |
|
|
* |
8 |
|
|
* SPDX-License-Identifier: MIT |
9 |
|
|
**************************************************************************/ |
10 |
|
|
|
11 |
|
|
|
12 |
|
|
/**************************************************************************/ |
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/** */ |
15 |
|
|
/** GUIX Component */ |
16 |
|
|
/** */ |
17 |
|
|
/** Single Line Text Input Managment (Single Line Text Input) */ |
18 |
|
|
/** */ |
19 |
|
|
/**************************************************************************/ |
20 |
|
|
|
21 |
|
|
#define GX_SOURCE_CODE |
22 |
|
|
|
23 |
|
|
|
24 |
|
|
/* Include necessary system files. */ |
25 |
|
|
|
26 |
|
|
#include "gx_api.h" |
27 |
|
|
#include "gx_system.h" |
28 |
|
|
#include "gx_single_line_text_input.h" |
29 |
|
|
#include "gx_utility.h" |
30 |
|
|
|
31 |
|
|
/**************************************************************************/ |
32 |
|
|
/* */ |
33 |
|
|
/* FUNCTION RELEASE */ |
34 |
|
|
/* */ |
35 |
|
|
/* _gx_single_line_text_input_text_set PORTABLE C */ |
36 |
|
|
/* 6.1 */ |
37 |
|
|
/* AUTHOR */ |
38 |
|
|
/* */ |
39 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
40 |
|
|
/* */ |
41 |
|
|
/* DESCRIPTION (deprecated) */ |
42 |
|
|
/* */ |
43 |
|
|
/* This function assigns a text string to a single line text input */ |
44 |
|
|
/* widget. */ |
45 |
|
|
/* */ |
46 |
|
|
/* INPUT */ |
47 |
|
|
/* */ |
48 |
|
|
/* text_input Single-line text input widget */ |
49 |
|
|
/* control block */ |
50 |
|
|
/* text Null-terminated text string */ |
51 |
|
|
/* */ |
52 |
|
|
/* OUTPUT */ |
53 |
|
|
/* */ |
54 |
|
|
/* status Completion status */ |
55 |
|
|
/* */ |
56 |
|
|
/* CALLS */ |
57 |
|
|
/* */ |
58 |
|
|
/* _gx_utility_string_length_check Test string length */ |
59 |
|
|
/* _gx_single_line_text_input_text_set_ext */ |
60 |
|
|
/* New text set function */ |
61 |
|
|
/* */ |
62 |
|
|
/* CALLED BY */ |
63 |
|
|
/* */ |
64 |
|
|
/* Application Code */ |
65 |
|
|
/* */ |
66 |
|
|
/* RELEASE HISTORY */ |
67 |
|
|
/* */ |
68 |
|
|
/* DATE NAME DESCRIPTION */ |
69 |
|
|
/* */ |
70 |
|
|
/* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ |
71 |
|
|
/* 09-30-2020 Kenneth Maxwell Modified comment(s), */ |
72 |
|
|
/* resulting in version 6.1 */ |
73 |
|
|
/* */ |
74 |
|
|
/**************************************************************************/ |
75 |
|
|
#if defined(GX_ENABLE_DEPRECATED_STRING_API) |
76 |
|
312 |
UINT _gx_single_line_text_input_text_set(GX_SINGLE_LINE_TEXT_INPUT *text_input, GX_CONST GX_CHAR *text) |
77 |
|
|
{ |
78 |
|
312 |
UINT status = GX_SUCCESS; |
79 |
|
|
GX_STRING string; |
80 |
|
|
|
81 |
|
312 |
string.gx_string_ptr = text; |
82 |
|
|
|
83 |
✓✓ |
312 |
if (text) |
84 |
|
|
{ |
85 |
|
311 |
status = _gx_utility_string_length_check(text, &string.gx_string_length, GX_MAX_STRING_LENGTH); |
86 |
|
|
} |
87 |
|
|
else |
88 |
|
|
{ |
89 |
|
1 |
string.gx_string_length = 0; |
90 |
|
|
} |
91 |
|
|
|
92 |
✓✓ |
312 |
if (status == GX_SUCCESS) |
93 |
|
|
{ |
94 |
|
311 |
status = _gx_single_line_text_input_text_set_ext(text_input, &string); |
95 |
|
|
} |
96 |
|
|
|
97 |
|
312 |
return(status); |
98 |
|
|
} |
99 |
|
|
#endif |
100 |
|
|
|
101 |
|
|
/**************************************************************************/ |
102 |
|
|
/* */ |
103 |
|
|
/* FUNCTION RELEASE */ |
104 |
|
|
/* */ |
105 |
|
|
/* _gx_single_line_text_input_text_set_ext PORTABLE C */ |
106 |
|
|
/* 6.1 */ |
107 |
|
|
/* AUTHOR */ |
108 |
|
|
/* */ |
109 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
110 |
|
|
/* */ |
111 |
|
|
/* DESCRIPTION */ |
112 |
|
|
/* */ |
113 |
|
|
/* This function assigns a text string to a single line text input */ |
114 |
|
|
/* widget. */ |
115 |
|
|
/* */ |
116 |
|
|
/* INPUT */ |
117 |
|
|
/* */ |
118 |
|
|
/* text_input Single-line text input widget */ |
119 |
|
|
/* control block */ |
120 |
|
|
/* text GX_STRING type text string */ |
121 |
|
|
/* */ |
122 |
|
|
/* OUTPUT */ |
123 |
|
|
/* */ |
124 |
|
|
/* status Completion status */ |
125 |
|
|
/* */ |
126 |
|
|
/* CALLS */ |
127 |
|
|
/* */ |
128 |
|
|
/* _gx_utility_string_length_check Test string length */ |
129 |
|
|
/* memcpy Copy block of memory */ |
130 |
|
|
/* _gx_utility_utf8_string_character_get Retrieve glyph code and length*/ |
131 |
|
|
/* _gx_single_line_text_input_position_update */ |
132 |
|
|
/* Update cursor position */ |
133 |
|
|
/* _gx_system_dirty_mark Mark the widget dirty */ |
134 |
|
|
/* */ |
135 |
|
|
/* CALLED BY */ |
136 |
|
|
/* */ |
137 |
|
|
/* Application Code */ |
138 |
|
|
/* */ |
139 |
|
|
/* RELEASE HISTORY */ |
140 |
|
|
/* */ |
141 |
|
|
/* DATE NAME DESCRIPTION */ |
142 |
|
|
/* */ |
143 |
|
|
/* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ |
144 |
|
|
/* 09-30-2020 Kenneth Maxwell Modified comment(s), */ |
145 |
|
|
/* resulting in version 6.1 */ |
146 |
|
|
/* */ |
147 |
|
|
/**************************************************************************/ |
148 |
|
547 |
UINT _gx_single_line_text_input_text_set_ext(GX_SINGLE_LINE_TEXT_INPUT *text_input, GX_CONST GX_STRING *text) |
149 |
|
|
{ |
150 |
|
|
UINT copy_size; |
151 |
|
|
|
152 |
|
|
#if defined GX_UTF8_SUPPORT |
153 |
|
|
GX_STRING string; |
154 |
|
|
UINT index; |
155 |
|
547 |
UINT glyph_len = 0; |
156 |
|
|
#endif |
157 |
|
|
|
158 |
✓✓✓✓
|
547 |
if (text && text -> gx_string_ptr) |
159 |
|
|
{ |
160 |
|
|
|
161 |
|
545 |
copy_size = text_input -> gx_single_line_text_input_buffer_size - 1; |
162 |
|
|
|
163 |
✓✓ |
545 |
if (text -> gx_string_length > copy_size) |
164 |
|
|
{ |
165 |
|
|
#if defined(GX_UTF8_SUPPORT) |
166 |
|
2 |
string.gx_string_ptr = text -> gx_string_ptr; |
167 |
|
2 |
string.gx_string_length = copy_size; |
168 |
|
2 |
index = 0; |
169 |
|
|
|
170 |
|
|
/* Calculate maximum bytes that can be copied. */ |
171 |
✓✓ |
37 |
while (_gx_utility_utf8_string_character_get(&string, GX_NULL, &glyph_len) == GX_SUCCESS) |
172 |
|
|
{ |
173 |
|
35 |
index += glyph_len; |
174 |
|
|
} |
175 |
|
2 |
copy_size = index; |
176 |
|
|
#endif |
177 |
|
|
} |
178 |
|
|
else |
179 |
|
|
{ |
180 |
|
543 |
copy_size = text -> gx_string_length; |
181 |
|
|
} |
182 |
|
|
|
183 |
|
545 |
memcpy((GX_CHAR *)text_input -> gx_single_line_text_input_buffer, text -> gx_string_ptr, copy_size); /* Use case of memcpy is verified. */ |
184 |
|
|
} |
185 |
|
|
else |
186 |
|
|
{ |
187 |
|
2 |
copy_size = 0; |
188 |
|
|
} |
189 |
|
|
|
190 |
|
547 |
((GX_CHAR *)text_input -> gx_single_line_text_input_buffer)[copy_size] = '\0'; |
191 |
|
|
|
192 |
|
547 |
text_input -> gx_single_line_text_input_string_size = copy_size; |
193 |
|
547 |
text_input -> gx_single_line_text_input_insert_pos = copy_size; |
194 |
|
|
|
195 |
|
|
/* Update cursor position. */ |
196 |
|
547 |
_gx_single_line_text_input_position_update(text_input); |
197 |
|
|
|
198 |
✓✓ |
547 |
if (text_input -> gx_widget_status & GX_STATUS_VISIBLE) |
199 |
|
|
{ |
200 |
|
310 |
_gx_system_dirty_mark((GX_WIDGET *)text_input); |
201 |
|
|
} |
202 |
|
|
|
203 |
|
547 |
return(GX_SUCCESS); |
204 |
|
|
} |
205 |
|
|
|