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 |
|
|
/** Text Input Management (Single 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_context.h" |
29 |
|
|
#include "gx_system.h" |
30 |
|
|
#include "gx_widget.h" |
31 |
|
|
#include "gx_single_line_text_input.h" |
32 |
|
|
#include "gx_text_input_cursor.h" |
33 |
|
|
#include "gx_utility.h" |
34 |
|
|
|
35 |
|
|
/**************************************************************************/ |
36 |
|
|
/* */ |
37 |
|
|
/* FUNCTION RELEASE */ |
38 |
|
|
/* */ |
39 |
|
|
/* _gx_single_line_text_input_right_arrow PORTABLE C */ |
40 |
|
|
/* 6.1 */ |
41 |
|
|
/* AUTHOR */ |
42 |
|
|
/* */ |
43 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
44 |
|
|
/* */ |
45 |
|
|
/* DESCRIPTION */ |
46 |
|
|
/* */ |
47 |
|
|
/* This service moves the text input cursor one character position to */ |
48 |
|
|
/* the right. */ |
49 |
|
|
/* */ |
50 |
|
|
/* INPUT */ |
51 |
|
|
/* */ |
52 |
|
|
/* text_input Single-line text input widget */ |
53 |
|
|
/* control block */ |
54 |
|
|
/* */ |
55 |
|
|
/* OUTPUT */ |
56 |
|
|
/* */ |
57 |
|
|
/* None */ |
58 |
|
|
/* */ |
59 |
|
|
/* CALLS */ |
60 |
|
|
/* */ |
61 |
|
|
/* _gx_widget_font_get Get the font of the text */ |
62 |
|
|
/* _gx_widget_border_width_get Get the widget border width */ |
63 |
|
|
/* _gx_widget_client_get Get widget client rectangle */ |
64 |
|
|
/* _gx_system_string_width_get Get the width of a string */ |
65 |
|
|
/* _gx_system_dirty_partial_add Mark the specified area of */ |
66 |
|
|
/* a widget as dirty */ |
67 |
|
|
/* _gx_system_dirty_mark Mark the widget as dirty */ |
68 |
|
|
/* _gx_text_input_cursor_dirty_rectangle_get */ |
69 |
|
|
/* Get cursor rectangle */ |
70 |
|
|
/* _gx_utility_utf8_string_character_get Parse utf8 string to */ |
71 |
|
|
/* multi-byte glyph */ |
72 |
|
|
/* */ |
73 |
|
|
/* CALLED BY */ |
74 |
|
|
/* */ |
75 |
|
|
/* Application Code */ |
76 |
|
|
/* GUIX Internal Code */ |
77 |
|
|
/* */ |
78 |
|
|
/**************************************************************************/ |
79 |
|
6431 |
UINT _gx_single_line_text_input_right_arrow(GX_SINGLE_LINE_TEXT_INPUT *text_input) |
80 |
|
|
{ |
81 |
|
6431 |
GX_TEXT_INPUT_CURSOR *cursor_ptr = &text_input -> gx_single_line_text_input_cursor_instance; |
82 |
|
6431 |
GX_CHAR *string_buffer = text_input -> gx_single_line_text_input_buffer; |
83 |
|
6431 |
UINT string_size = text_input -> gx_single_line_text_input_string_size; |
84 |
|
|
UINT insert_pos; |
85 |
|
|
GX_VALUE new_cursor_pos; |
86 |
|
|
GX_VALUE old_cursor_pos; |
87 |
|
|
GX_VALUE width; |
88 |
|
|
GX_FONT *gx_font; |
89 |
|
|
GX_RECTANGLE client; |
90 |
|
|
GX_RECTANGLE cursor_rect; |
91 |
|
6431 |
UINT glyph_len = 1; |
92 |
|
6431 |
UINT start_mark = text_input -> gx_single_line_text_input_start_mark; |
93 |
|
6431 |
UINT end_mark = text_input -> gx_single_line_text_input_end_mark; |
94 |
|
6431 |
GX_BOOL mark_all = GX_FALSE; |
95 |
|
|
GX_STRING string; |
96 |
|
|
|
97 |
|
|
/* Pick up widget border width. */ |
98 |
|
6431 |
_gx_widget_border_width_get((GX_WIDGET *)text_input, &width); |
99 |
|
|
|
100 |
|
|
/* Get widget client rectangle. */ |
101 |
|
6431 |
_gx_widget_client_get((GX_WIDGET *)text_input, width, &client); |
102 |
|
|
|
103 |
|
6431 |
old_cursor_pos = cursor_ptr -> gx_text_input_cursor_pos.gx_point_x; |
104 |
|
6431 |
new_cursor_pos = cursor_ptr -> gx_text_input_cursor_pos.gx_point_x; |
105 |
|
|
|
106 |
✓✓ |
6431 |
if (start_mark != end_mark) |
107 |
|
|
{ |
108 |
|
69 |
text_input -> gx_single_line_text_input_start_mark = 0; |
109 |
|
69 |
text_input -> gx_single_line_text_input_end_mark = 0; |
110 |
|
|
|
111 |
✓✓ |
69 |
if (end_mark > start_mark) |
112 |
|
|
{ |
113 |
✓✓ |
48 |
if (((new_cursor_pos > client.gx_rectangle_left) && |
114 |
✓✓ |
38 |
(new_cursor_pos < client.gx_rectangle_right)) || |
115 |
✓✓ |
40 |
((text_input -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK) == GX_STYLE_TEXT_CENTER)) |
116 |
|
|
{ |
117 |
|
|
/* No need to update cursor position, just need mark |
118 |
|
|
cursor and highlight area as dirty. */ |
119 |
|
23 |
_gx_text_input_cursor_dirty_rectangle_get(cursor_ptr, &cursor_rect); |
120 |
|
|
|
121 |
|
23 |
_gx_single_line_text_input_text_rectangle_get(text_input, (INT)(start_mark - end_mark), &client); |
122 |
|
|
|
123 |
|
|
/* Combine cursor rect and highlight area. */ |
124 |
|
23 |
_gx_utility_rectangle_combine(&client, &cursor_rect); |
125 |
|
|
|
126 |
|
23 |
return _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &client); |
127 |
|
|
} |
128 |
|
|
} |
129 |
|
|
} |
130 |
|
|
|
131 |
|
6408 |
insert_pos = text_input -> gx_single_line_text_input_insert_pos; |
132 |
|
|
|
133 |
|
|
/* Update cursor position and offset in x-axis. */ |
134 |
✓✓✓✓
|
6408 |
if ((insert_pos < string_size) || |
135 |
|
|
(end_mark > start_mark)) |
136 |
|
|
{ |
137 |
✓✓ |
2638 |
if (start_mark >= end_mark) |
138 |
|
|
{ |
139 |
|
2613 |
string.gx_string_ptr = string_buffer + insert_pos; |
140 |
|
|
|
141 |
|
|
/* Calculate new cursor position. */ |
142 |
✓✓ |
2613 |
if (start_mark != end_mark) |
143 |
|
|
{ |
144 |
|
21 |
glyph_len = start_mark - end_mark; |
145 |
|
|
} |
146 |
|
|
#ifdef GX_UTF8_SUPPORT |
147 |
|
|
else |
148 |
|
|
{ |
149 |
|
2592 |
string.gx_string_length = string_size - insert_pos; |
150 |
|
2592 |
_gx_utility_utf8_string_character_get(&string, GX_NULL, &glyph_len); |
151 |
|
|
} |
152 |
|
|
#endif |
153 |
|
2613 |
text_input -> gx_single_line_text_input_insert_pos += glyph_len; |
154 |
|
|
|
155 |
|
|
/* Calculate cursor position. */ |
156 |
|
2613 |
_gx_widget_font_get((GX_WIDGET *)text_input, text_input -> gx_prompt_font_id, &gx_font); |
157 |
|
2613 |
string.gx_string_ptr = string_buffer + insert_pos; |
158 |
|
2613 |
string.gx_string_length = glyph_len; |
159 |
|
2613 |
_gx_system_string_width_get_ext(gx_font, &string, &width); |
160 |
|
|
|
161 |
|
2613 |
new_cursor_pos = (GX_VALUE)(cursor_ptr -> gx_text_input_cursor_pos.gx_point_x + width); |
162 |
|
|
} |
163 |
|
|
|
164 |
|
|
|
165 |
✓✓ |
2638 |
switch (text_input -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK) |
166 |
|
|
{ |
167 |
|
830 |
case GX_STYLE_TEXT_CENTER: |
168 |
✓✓ |
830 |
if (start_mark == end_mark) |
169 |
|
|
{ |
170 |
|
|
/* No need to update text input x offset, mark old and new cursor position area as dirty. */ |
171 |
|
823 |
_gx_text_input_cursor_dirty_rectangle_get(cursor_ptr, &client); |
172 |
|
823 |
_gx_system_dirty_partial_add((GX_WIDGET *)text_input, &client); |
173 |
|
|
} |
174 |
|
|
|
175 |
|
830 |
cursor_ptr -> gx_text_input_cursor_pos.gx_point_x = new_cursor_pos; |
176 |
|
830 |
_gx_text_input_cursor_dirty_rectangle_get(cursor_ptr, &client); |
177 |
|
830 |
_gx_system_dirty_partial_add((GX_WIDGET *)text_input, &client); |
178 |
|
830 |
break; |
179 |
|
|
|
180 |
|
1808 |
case GX_STYLE_TEXT_RIGHT: |
181 |
|
|
case GX_STYLE_TEXT_LEFT: |
182 |
|
|
default: |
183 |
✓✓ |
1808 |
if (new_cursor_pos > client.gx_rectangle_right - 1) |
184 |
|
|
{ |
185 |
|
|
/* Cursor position is out of client rectangle, update x offset. */ |
186 |
|
287 |
text_input -> gx_single_line_text_input_xoffset = (GX_VALUE)(text_input -> gx_single_line_text_input_xoffset + |
187 |
|
287 |
new_cursor_pos - client.gx_rectangle_right + 1); |
188 |
|
287 |
cursor_ptr -> gx_text_input_cursor_pos.gx_point_x = (GX_VALUE)(client.gx_rectangle_right - 1); |
189 |
|
|
|
190 |
|
|
/* Should mark all widget as dirty. */ |
191 |
|
287 |
mark_all = GX_TRUE; |
192 |
|
|
} |
193 |
✓✓ |
1521 |
else if (new_cursor_pos < client.gx_rectangle_left + 1) |
194 |
|
|
{ |
195 |
|
|
/* Update text input x offset. */ |
196 |
|
8 |
text_input -> gx_single_line_text_input_xoffset = (GX_VALUE)(text_input -> gx_single_line_text_input_xoffset - |
197 |
|
8 |
client.gx_rectangle_left - 1 + new_cursor_pos); |
198 |
|
8 |
cursor_ptr -> gx_text_input_cursor_pos.gx_point_x = (GX_VALUE)(client.gx_rectangle_left + 1); |
199 |
|
|
|
200 |
|
8 |
mark_all = GX_TRUE; |
201 |
|
|
} |
202 |
|
|
else |
203 |
|
|
{ |
204 |
|
|
/* No need to update text input x offset, mark old and new cursor position area as dirty. */ |
205 |
✓✓ |
1513 |
if (start_mark == end_mark) |
206 |
|
|
{ |
207 |
|
1509 |
_gx_text_input_cursor_dirty_rectangle_get(cursor_ptr, &client); |
208 |
|
1509 |
_gx_system_dirty_partial_add((GX_WIDGET *)text_input, &client); |
209 |
|
|
} |
210 |
|
|
|
211 |
|
1513 |
cursor_ptr -> gx_text_input_cursor_pos.gx_point_x = new_cursor_pos; |
212 |
|
1513 |
_gx_text_input_cursor_dirty_rectangle_get(cursor_ptr, &client); |
213 |
|
1513 |
_gx_system_dirty_partial_add((GX_WIDGET *)text_input, &client); |
214 |
|
|
} |
215 |
|
1808 |
break; |
216 |
|
|
} |
217 |
|
|
|
218 |
✓✓✓✓
|
2638 |
if ((!mark_all) && (start_mark != end_mark)) |
219 |
|
|
{ |
220 |
|
|
/* Mark highlight area as dirty. */ |
221 |
|
11 |
client.gx_rectangle_left = old_cursor_pos; |
222 |
|
11 |
client.gx_rectangle_right = (GX_VALUE)(new_cursor_pos - 1); |
223 |
|
|
} |
224 |
|
|
|
225 |
|
2638 |
_gx_system_dirty_partial_add((GX_WIDGET *)text_input, &client); |
226 |
|
|
} |
227 |
|
|
|
228 |
|
6408 |
return GX_SUCCESS; |
229 |
|
|
} |
230 |
|
|
|