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