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 /** Multi Line Text Input Management (Multi 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_window.h"
29 #include "gx_scrollbar.h"
30 #include "gx_multi_line_text_input.h"
31 #include "gx_multi_line_text_view.h"
32 #include "gx_text_input_cursor.h"
33 #include "gx_utility.h"
34
35 /**************************************************************************/
36 /* */
37 /* FUNCTION RELEASE */
38 /* */
39 /* _gx_multi_line_text_input_right_arrow PORTABLE C */
40 /* 6.1 */
41 /* AUTHOR */
42 /* */
43 /* Kenneth Maxwell, Microsoft Corporation */
44 /* */
45 /* DESCRIPTION */
46 /* */
47 /* This function move the cursor to right by one pixel. */
48 /* */
49 /* INPUT */
50 /* */
51 /* text_input Multi line text input */
52 /* control block */
53 /* */
54 /* OUTPUT */
55 /* */
56 /* None */
57 /* */
58 /* CALLS */
59 /* */
60 /* _gx_text_input_cursor_dirty_rectangle_get */
61 /* Get cursor rectangle */
62 /* _gx_multi_line_text_input_cursor_pos_update */
63 /* Calculate cursor position */
64 /* according to insert index */
65 /* _gx_system_dirty_partial_add Add one dirty area to */
66 /* dirty list */
67 /* _gx_system_dirty_mark Mark widget area dirty */
68 /* _gx_utility_utf8_string_character_get Parses utf8 string to */
69 /* multi-byte glyph */
70 /* _gx_utility_string_length_check Test string length */
71 /* */
72 /* CALLED BY */
73 /* */
74 /* _gx_multi_line_text_input_keydown_process */
75 /* */
76 /* RELEASE HISTORY */
77 /* */
78 /* DATE NAME DESCRIPTION */
79 /* */
80 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
81 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */
82 /* resulting in version 6.1 */
83 /* */
84 /**************************************************************************/
_gx_multi_line_text_input_right_arrow(GX_MULTI_LINE_TEXT_INPUT * text_input)85 UINT _gx_multi_line_text_input_right_arrow(GX_MULTI_LINE_TEXT_INPUT *text_input)
86 {
87 GX_TEXT_INPUT_CURSOR *cursor_ptr = &text_input -> gx_multi_line_text_input_cursor_instance;
88 UINT index;
89 GX_RECTANGLE cur_rect;
90 INT shift;
91 UINT glyph_len = 1;
92 GX_STRING *view_text;
93 UINT start_mark = text_input -> gx_multi_line_text_input_start_mark;
94 UINT end_mark = text_input -> gx_multi_line_text_input_end_mark;
95 GX_POINT end_pos;
96 #ifdef GX_UTF8_SUPPORT
97 GX_STRING string;
98 #endif
99
100 if (start_mark != end_mark)
101 {
102 end_pos = cursor_ptr -> gx_text_input_cursor_pos;
103
104 if (start_mark < end_mark)
105 {
106 _gx_multi_line_text_input_cursor_visible(text_input);
107
108 /* Get highlight area. */
109 _gx_multi_line_text_input_highlight_rectangle_get(text_input, &cur_rect);
110 }
111 else
112 {
113 text_input -> gx_multi_line_text_input_text_insert_position = start_mark;
114
115 shift = text_input -> gx_multi_line_text_view_text_scroll_shift;
116
117 /* Recalculate cursor position according to cursor insert position. */
118 _gx_multi_line_text_input_cursor_pos_update(text_input, GX_TRUE);
119
120 /* Dirty mark. */
121 if (shift == text_input -> gx_multi_line_text_view_text_scroll_shift)
122 {
123 _gx_multi_line_text_input_text_rectangle_get(text_input, cursor_ptr -> gx_text_input_cursor_pos, end_pos, &cur_rect);
124 }
125 else
126 {
127 cur_rect = text_input -> gx_widget_size;
128 }
129 }
130
131 text_input -> gx_multi_line_text_input_start_mark = 0;
132 text_input -> gx_multi_line_text_input_end_mark = 0;
133
134 _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &cur_rect);
135
136 /* Mark cursor area as dirty. */
137 _gx_text_input_cursor_dirty_rectangle_get(&text_input -> gx_multi_line_text_input_cursor_instance, &cur_rect);
138 _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &cur_rect);
139 }
140 else
141 {
142 view_text = &text_input -> gx_multi_line_text_view_text;
143 index = text_input -> gx_multi_line_text_input_text_insert_position;
144 if (index < view_text -> gx_string_length)
145 {
146 if ((view_text -> gx_string_ptr[index] == GX_KEY_CARRIAGE_RETURN) ||
147 (view_text -> gx_string_ptr[index] == GX_KEY_LINE_FEED))
148 {
149 glyph_len = text_input -> gx_multi_line_text_input_new_line_character_size;
150 }
151 #ifdef GX_UTF8_SUPPORT
152 else
153 {
154 /* Calculate glygh length. */
155 string.gx_string_ptr = view_text -> gx_string_ptr + index;
156 string.gx_string_length = view_text -> gx_string_length - index;
157 _gx_utility_utf8_string_character_get(&string, GX_NULL, &glyph_len);
158 }
159 #endif
160
161 /* Move the cursor position in the input buffer forward by one character. */
162 text_input -> gx_multi_line_text_input_text_insert_position += glyph_len;
163
164 /* Record scroll shift before recalculate cursor position. */
165 _gx_text_input_cursor_dirty_rectangle_get(&text_input -> gx_multi_line_text_input_cursor_instance, &cur_rect);
166 shift = text_input -> gx_multi_line_text_view_text_scroll_shift;
167
168 /* Recalculate cursor position according to cursor insert position. */
169 _gx_multi_line_text_input_cursor_pos_update(text_input, GX_TRUE);
170
171 /* Dirty mark. */
172 if (shift == text_input -> gx_multi_line_text_view_text_scroll_shift)
173 {
174 _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &cur_rect);
175 _gx_text_input_cursor_dirty_rectangle_get(&text_input -> gx_multi_line_text_input_cursor_instance, &cur_rect);
176 _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &cur_rect);
177 }
178 else
179 {
180 _gx_system_dirty_mark((GX_WIDGET *)text_input);
181 }
182 }
183 }
184 return GX_SUCCESS;
185 }
186
187