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 Management (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_widget.h" |
30 |
|
|
#include "gx_window.h" |
31 |
|
|
#include "gx_utility.h" |
32 |
|
|
#include "gx_multi_line_text_input.h" |
33 |
|
|
#include "gx_multi_line_text_view.h" |
34 |
|
|
#include "gx_utility.h" |
35 |
|
|
#include "gx_scrollbar.h" |
36 |
|
|
|
37 |
|
|
/**************************************************************************/ |
38 |
|
|
/* */ |
39 |
|
|
/* FUNCTION RELEASE */ |
40 |
|
|
/* */ |
41 |
|
|
/* _gx_multi_line_text_input_delete PORTABLE C */ |
42 |
|
|
/* 6.1 */ |
43 |
|
|
/* AUTHOR */ |
44 |
|
|
/* */ |
45 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
46 |
|
|
/* */ |
47 |
|
|
/* DESCRIPTION */ |
48 |
|
|
/* */ |
49 |
|
|
/* This function deletes a character after the cursor. */ |
50 |
|
|
/* */ |
51 |
|
|
/* INPUT */ |
52 |
|
|
/* */ |
53 |
|
|
/* text_input Multi line text input */ |
54 |
|
|
/* control block */ |
55 |
|
|
/* */ |
56 |
|
|
/* OUTPUT */ |
57 |
|
|
/* */ |
58 |
|
|
/* None */ |
59 |
|
|
/* */ |
60 |
|
|
/* CALLS */ |
61 |
|
|
/* */ |
62 |
|
|
/* _gx_widget_font_get Retrieve font */ |
63 |
|
|
/* _gx_window_client_width_get Get the client width */ |
64 |
|
|
/* _gx_window_scrollbar_find Find scrollbar for a window */ |
65 |
|
|
/* _gx_scrollbar_reset Reset scrollbar information */ |
66 |
|
|
/* _gx_multi_line_text_input_char_remove Remove characters from input */ |
67 |
|
|
/* string */ |
68 |
|
|
/* _gx_multi_line_text_view_display_info_get */ |
69 |
|
|
/* Get the number of characters */ |
70 |
|
|
/* that a line can display */ |
71 |
|
|
/* _gx_multi_line_text_view_string_total_rows_compute */ |
72 |
|
|
/* Calculate total rows of input */ |
73 |
|
|
/* string */ |
74 |
|
|
/* _gx_multi_line_text_view_line_cache_update */ |
75 |
|
|
/* Update line cache */ |
76 |
|
|
/* _gx_multi_line_text_input_cursor_pos_update */ |
77 |
|
|
/* Update cursor position */ |
78 |
|
|
/* according to insert position*/ |
79 |
|
|
/* _gx_system_dirty_partial_add Add one dirty area to dirty */ |
80 |
|
|
/* list */ |
81 |
|
|
/* _gx_utility_utf8_string_character_get Parses utf8 string to */ |
82 |
|
|
/* multi-byte glyph */ |
83 |
|
|
/* _gx_utility_string_length_check Test string length */ |
84 |
|
|
/* */ |
85 |
|
|
/* CALLED BY */ |
86 |
|
|
/* */ |
87 |
|
|
/* _gx_multi_line_text_input_keydown_process */ |
88 |
|
|
/* */ |
89 |
|
|
/**************************************************************************/ |
90 |
|
440 |
UINT _gx_multi_line_text_input_delete(GX_MULTI_LINE_TEXT_INPUT *text_input) |
91 |
|
|
{ |
92 |
|
440 |
GX_TEXT_INPUT_CURSOR *cursor_ptr = &text_input -> gx_multi_line_text_input_cursor_instance; |
93 |
|
440 |
GX_MULTI_LINE_TEXT_VIEW *view = (GX_MULTI_LINE_TEXT_VIEW *)text_input; |
94 |
|
|
UINT insert_pos; |
95 |
|
|
UINT string_size; |
96 |
|
|
GX_RECTANGLE client; |
97 |
|
|
GX_RECTANGLE dirty_rect; |
98 |
|
|
GX_FONT *font; |
99 |
|
|
GX_VALUE line_height; |
100 |
|
|
UINT old_text_rows; |
101 |
|
|
INT shift; |
102 |
|
|
INT last_visible_line; |
103 |
|
440 |
UINT glyph_len = 1; |
104 |
|
|
GX_SCROLLBAR *scroll; |
105 |
|
|
GX_STRING string; |
106 |
|
440 |
UINT start_mark = text_input -> gx_multi_line_text_input_start_mark; |
107 |
|
440 |
UINT end_mark = text_input -> gx_multi_line_text_input_end_mark; |
108 |
|
|
|
109 |
✓✓ |
440 |
if (end_mark > start_mark) |
110 |
|
|
{ |
111 |
|
36 |
return _gx_multi_line_text_input_backspace(text_input); |
112 |
|
|
} |
113 |
|
|
|
114 |
|
404 |
insert_pos = text_input -> gx_multi_line_text_input_text_insert_position; |
115 |
|
404 |
string_size = text_input -> gx_multi_line_text_view_text.gx_string_length; |
116 |
✓✓ |
404 |
if (insert_pos < string_size) |
117 |
|
|
{ |
118 |
|
|
/* Pickup text font. */ |
119 |
|
403 |
_gx_widget_font_get((GX_WIDGET *)text_input, text_input -> gx_multi_line_text_view_font_id, &font); |
120 |
|
|
|
121 |
✓✓ |
403 |
if (!font) |
122 |
|
|
{ |
123 |
|
2 |
return GX_FAILURE; |
124 |
|
|
} |
125 |
|
|
|
126 |
✓✓ |
401 |
if (start_mark != end_mark) |
127 |
|
|
{ |
128 |
|
170 |
glyph_len = (UINT)GX_ABS((INT)start_mark - (INT)end_mark); |
129 |
|
170 |
text_input -> gx_multi_line_text_input_start_mark = 0; |
130 |
|
170 |
text_input -> gx_multi_line_text_input_end_mark = 0; |
131 |
|
|
} |
132 |
|
|
else |
133 |
|
|
{ |
134 |
|
|
#ifdef GX_UTF8_SUPPORT |
135 |
|
231 |
string.gx_string_ptr = text_input -> gx_multi_line_text_view_text.gx_string_ptr + insert_pos; |
136 |
|
231 |
string.gx_string_length = text_input -> gx_multi_line_text_view_text.gx_string_length - insert_pos; |
137 |
|
231 |
_gx_utility_utf8_string_character_get(&string, GX_NULL, &glyph_len); |
138 |
|
|
#endif |
139 |
|
|
|
140 |
|
231 |
string.gx_string_ptr = text_input -> gx_multi_line_text_view_text.gx_string_ptr + insert_pos; |
141 |
✓✓✓✓
|
231 |
if (string.gx_string_ptr[0] == GX_KEY_CARRIAGE_RETURN || string.gx_string_ptr[0] == GX_KEY_LINE_FEED) |
142 |
|
|
{ |
143 |
|
126 |
glyph_len = text_input -> gx_multi_line_text_input_new_line_character_size; |
144 |
|
|
} |
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
/* Get scroll shift. */ |
148 |
|
401 |
shift = (GX_VALUE)(text_input -> gx_multi_line_text_view_text_scroll_shift); |
149 |
|
|
|
150 |
|
|
/* Remove character after cursor. */ |
151 |
|
401 |
_gx_multi_line_text_input_char_remove(text_input, insert_pos, glyph_len); |
152 |
|
|
|
153 |
|
|
/* Save old text rows. */ |
154 |
|
401 |
old_text_rows = text_input -> gx_multi_line_text_view_text_total_rows; |
155 |
|
|
|
156 |
|
|
/* Calculate new text rows. */ |
157 |
|
401 |
_gx_multi_line_text_view_string_total_rows_compute((GX_MULTI_LINE_TEXT_VIEW *)text_input); |
158 |
|
|
|
159 |
✓✓ |
401 |
if (old_text_rows != text_input -> gx_multi_line_text_view_text_total_rows) |
160 |
|
|
{ |
161 |
|
277 |
_gx_window_scrollbar_find((GX_WINDOW *)text_input, GX_TYPE_VERTICAL_SCROLL, &scroll); |
162 |
✓✓ |
277 |
if (scroll) |
163 |
|
|
{ |
164 |
|
|
/* Reset scrollbar. */ |
165 |
|
156 |
_gx_scrollbar_reset(scroll, GX_NULL); |
166 |
|
|
} |
167 |
|
|
else |
168 |
|
|
{ |
169 |
|
|
|
170 |
|
121 |
if (text_input -> gx_multi_line_text_view_text_total_rows > |
171 |
✓✓ |
121 |
text_input -> gx_multi_line_text_view_cache_size) |
172 |
|
|
{ |
173 |
|
1 |
_gx_multi_line_text_view_line_cache_update((GX_MULTI_LINE_TEXT_VIEW *)text_input); |
174 |
|
|
} |
175 |
|
|
} |
176 |
|
|
} |
177 |
|
|
|
178 |
|
|
/* Recalculate cursor position. */ |
179 |
|
401 |
_gx_multi_line_text_input_cursor_pos_update(text_input, GX_TRUE); |
180 |
|
|
|
181 |
✓✓ |
401 |
if (shift == text_input -> gx_multi_line_text_view_text_scroll_shift) |
182 |
|
|
{ |
183 |
|
|
/* Get text height. */ |
184 |
|
271 |
line_height = (GX_VALUE)(font -> gx_font_line_height + |
185 |
|
271 |
text_input -> gx_multi_line_text_view_line_space); |
186 |
|
|
|
187 |
✓✓ |
271 |
if (line_height) |
188 |
|
|
{ |
189 |
|
270 |
client = text_input -> gx_window_client; |
190 |
|
|
|
191 |
|
|
/* Offset client area by length of whitespace. */ |
192 |
|
270 |
_gx_utility_rectangle_resize(&client, (GX_VALUE)(-text_input -> gx_multi_line_text_view_whitespace)); |
193 |
|
|
|
194 |
|
270 |
dirty_rect = client; |
195 |
|
|
|
196 |
|
|
/* Calculate dirty area. */ |
197 |
|
270 |
dirty_rect.gx_rectangle_top = (GX_VALUE)(cursor_ptr -> gx_text_input_cursor_pos.gx_point_y - line_height - (line_height >> 1)); |
198 |
|
|
|
199 |
|
|
/* Calculate last visible line. */ |
200 |
|
270 |
last_visible_line = (-text_input -> gx_multi_line_text_view_text_scroll_shift) / line_height; |
201 |
|
270 |
last_visible_line = last_visible_line + (INT)view -> gx_multi_line_text_view_text_visible_rows + 1; |
202 |
|
|
|
203 |
✓✓ |
270 |
if (last_visible_line > (INT)text_input -> gx_multi_line_text_view_text_total_rows) |
204 |
|
|
{ |
205 |
|
188 |
last_visible_line = (INT)text_input -> gx_multi_line_text_view_text_total_rows; |
206 |
|
|
} |
207 |
|
|
|
208 |
|
270 |
shift = (last_visible_line + (INT)old_text_rows - (INT)text_input -> gx_multi_line_text_view_text_total_rows) * line_height + shift; |
209 |
|
270 |
shift += client.gx_rectangle_top; |
210 |
|
|
|
211 |
✓✓ |
270 |
if (shift < dirty_rect.gx_rectangle_bottom) |
212 |
|
|
{ |
213 |
|
147 |
dirty_rect.gx_rectangle_bottom = (GX_VALUE)shift; |
214 |
|
|
} |
215 |
|
|
|
216 |
|
270 |
_gx_system_dirty_partial_add((GX_WIDGET *)text_input, &dirty_rect); |
217 |
|
|
} |
218 |
|
|
} |
219 |
|
|
else |
220 |
|
|
{ |
221 |
|
130 |
_gx_system_dirty_mark((GX_WIDGET *)text_input); |
222 |
|
|
} |
223 |
|
|
} |
224 |
|
|
|
225 |
|
402 |
return GX_SUCCESS; |
226 |
|
|
} |
227 |
|
|
|