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 |
|
|
|
34 |
|
|
/**************************************************************************/ |
35 |
|
|
/* */ |
36 |
|
|
/* FUNCTION RELEASE */ |
37 |
|
|
/* */ |
38 |
|
|
/* _gx_single_line_text_input_mark_end PORTABLE C */ |
39 |
|
|
/* 6.1 */ |
40 |
|
|
/* AUTHOR */ |
41 |
|
|
/* */ |
42 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
43 |
|
|
/* */ |
44 |
|
|
/* DESCRIPTION */ |
45 |
|
|
/* */ |
46 |
|
|
/* This service moves the end mark to the end of the input string. */ |
47 |
|
|
/* */ |
48 |
|
|
/* INPUT */ |
49 |
|
|
/* */ |
50 |
|
|
/* text_input Single line text input widget */ |
51 |
|
|
/* control blcok */ |
52 |
|
|
/* */ |
53 |
|
|
/* OUTPUT */ |
54 |
|
|
/* */ |
55 |
|
|
/* status Completion status */ |
56 |
|
|
/* */ |
57 |
|
|
/* CALLS */ |
58 |
|
|
/* */ |
59 |
|
|
/* _gx_widget_font_get Get font by specified ID */ |
60 |
|
|
/* _gx_widget_border_width_get Get the widget border width */ |
61 |
|
|
/* _gx_widget_client_get Retrieves client area of the */ |
62 |
|
|
/* widget */ |
63 |
|
|
/* _gx_system_string_width_get Get the width of a string */ |
64 |
|
|
/* _gx_system_dirty_mark Mart the area of the widget */ |
65 |
|
|
/* dirty */ |
66 |
|
|
/* _gx_system_dirty_partial_add Mark the partial area of a */ |
67 |
|
|
/* widget as dirty */ |
68 |
|
|
/* _gx_single_line_text_input_text_rectangle_get */ |
69 |
|
|
/* Retrieve text rectangle */ |
70 |
|
|
/* */ |
71 |
|
|
/* CALLED BY */ |
72 |
|
|
/* */ |
73 |
|
|
/* GUIX Internal Code */ |
74 |
|
|
/* */ |
75 |
|
|
/**************************************************************************/ |
76 |
|
40 |
UINT _gx_single_line_text_input_mark_end(GX_SINGLE_LINE_TEXT_INPUT *text_input) |
77 |
|
|
{ |
78 |
|
|
GX_TEXT_INPUT_CURSOR *cursor_ptr; |
79 |
|
|
GX_VALUE text_width; |
80 |
|
|
GX_RECTANGLE client; |
81 |
|
|
GX_VALUE new_xoffset; |
82 |
|
|
GX_VALUE new_cursor_pos; |
83 |
|
|
GX_VALUE border_width; |
84 |
|
|
GX_FONT *gx_font; |
85 |
|
40 |
UINT start_mark = text_input -> gx_single_line_text_input_start_mark; |
86 |
|
40 |
UINT end_mark = text_input -> gx_single_line_text_input_end_mark; |
87 |
|
|
GX_STRING string; |
88 |
|
|
|
89 |
✓✓ |
40 |
if (text_input -> gx_single_line_text_input_insert_pos == text_input -> gx_single_line_text_input_string_size) |
90 |
|
|
{ |
91 |
|
2 |
return GX_SUCCESS; |
92 |
|
|
} |
93 |
|
|
|
94 |
|
38 |
cursor_ptr = &text_input -> gx_single_line_text_input_cursor_instance; |
95 |
|
38 |
string.gx_string_ptr = text_input -> gx_single_line_text_input_buffer; |
96 |
|
38 |
string.gx_string_length = text_input -> gx_single_line_text_input_string_size; |
97 |
|
|
|
98 |
✓✓ |
38 |
if (start_mark == end_mark) |
99 |
|
|
{ |
100 |
|
|
/* Set start mark and end mark to current cursor position. */ |
101 |
|
2 |
start_mark = text_input -> gx_single_line_text_input_insert_pos; |
102 |
|
2 |
end_mark = text_input -> gx_single_line_text_input_insert_pos; |
103 |
|
|
|
104 |
|
2 |
text_input -> gx_single_line_text_input_start_mark = start_mark; |
105 |
|
2 |
text_input -> gx_single_line_text_input_end_mark = end_mark; |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
/* Pick up text width. */ |
109 |
|
38 |
_gx_widget_font_get((GX_WIDGET *)text_input, text_input -> gx_prompt_font_id, &gx_font); |
110 |
|
|
|
111 |
|
|
/* Calculate the widget width for showing text. */ |
112 |
|
38 |
_gx_widget_border_width_get((GX_WIDGET *)text_input, &border_width); |
113 |
|
38 |
_gx_widget_client_get((GX_WIDGET *)text_input, border_width, &client); |
114 |
|
|
|
115 |
|
|
/* Update the value of cursor position and xoffset. */ |
116 |
✓✓✓ |
38 |
switch (text_input -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK) |
117 |
|
|
{ |
118 |
|
12 |
case GX_STYLE_TEXT_RIGHT: |
119 |
|
12 |
new_xoffset = 0; |
120 |
|
12 |
new_cursor_pos = (GX_VALUE)(client.gx_rectangle_right - 1); |
121 |
|
12 |
break; |
122 |
|
|
|
123 |
|
12 |
case GX_STYLE_TEXT_CENTER: |
124 |
|
12 |
new_xoffset = 0; |
125 |
|
12 |
new_cursor_pos = (GX_VALUE)(client.gx_rectangle_left + 1 + ((client.gx_rectangle_right - client.gx_rectangle_left + 1) >> 1)); |
126 |
|
12 |
new_cursor_pos = (GX_VALUE)(new_cursor_pos + text_input -> gx_single_line_text_input_xoffset); |
127 |
|
12 |
break; |
128 |
|
|
|
129 |
|
14 |
case GX_STYLE_TEXT_LEFT: |
130 |
|
|
default: |
131 |
|
|
/* Calculate new xoffset. */ |
132 |
|
14 |
_gx_system_string_width_get_ext(gx_font, &string, &text_width); |
133 |
|
14 |
new_xoffset = (GX_VALUE)(client.gx_rectangle_right - client.gx_rectangle_left + 1); |
134 |
|
14 |
new_xoffset = (GX_VALUE)(new_xoffset - 3); |
135 |
|
14 |
new_xoffset = (GX_VALUE)(text_width - new_xoffset); |
136 |
|
|
|
137 |
✓✓ |
14 |
if (new_xoffset < 0) |
138 |
|
|
{ |
139 |
|
2 |
new_xoffset = 0; |
140 |
|
|
} |
141 |
|
|
|
142 |
|
|
/* Calculate new cursor position. */ |
143 |
|
14 |
new_cursor_pos = (GX_VALUE)(client.gx_rectangle_left + 1 - new_xoffset + text_width); |
144 |
|
14 |
break; |
145 |
|
|
} |
146 |
|
|
|
147 |
✓✓ |
38 |
if (text_input -> gx_single_line_text_input_xoffset != new_xoffset) |
148 |
|
|
{ |
149 |
|
|
/* We need to update text xoffset, mark whole dirty area dirty. */ |
150 |
|
30 |
_gx_system_dirty_mark((GX_WIDGET *)text_input); |
151 |
|
|
} |
152 |
|
|
else |
153 |
|
|
{ |
154 |
✓✓ |
8 |
if (start_mark == end_mark) |
155 |
|
|
{ |
156 |
|
|
/* Mark old cursor area as dirty. */ |
157 |
|
2 |
_gx_text_input_cursor_dirty_rectangle_get(cursor_ptr, &client); |
158 |
|
2 |
_gx_system_dirty_partial_add((GX_WIDGET *)text_input, &client); |
159 |
|
|
} |
160 |
|
|
|
161 |
|
|
/* Mark old and new highlight text area as dirty. */ |
162 |
|
8 |
_gx_single_line_text_input_text_rectangle_get(text_input, (INT)(string.gx_string_length - end_mark), &client); |
163 |
|
8 |
_gx_system_dirty_partial_add((GX_WIDGET *)text_input, &client); |
164 |
|
|
} |
165 |
|
|
|
166 |
|
38 |
text_input -> gx_single_line_text_input_end_mark = string.gx_string_length; |
167 |
|
|
|
168 |
|
|
/* Update the value of cursor position. */ |
169 |
|
38 |
cursor_ptr -> gx_text_input_cursor_pos.gx_point_x = new_cursor_pos; |
170 |
|
|
|
171 |
|
|
/* Update character insert position. */ |
172 |
|
38 |
text_input -> gx_single_line_text_input_insert_pos = string.gx_string_length; |
173 |
|
|
|
174 |
|
|
/* Update text inpu x offset. */ |
175 |
|
38 |
text_input -> gx_single_line_text_input_xoffset = new_xoffset; |
176 |
|
|
|
177 |
|
38 |
return GX_SUCCESS; |
178 |
|
|
} |
179 |
|
|
|