GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_single_line_text_input_left_arrow.c Lines: 67 67 100.0 %
Date: 2026-03-06 19:21:09 Branches: 32 32 100.0 %

Line Branch Exec Source
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_left_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 left.                                                         */
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_utility_utf8_string_character_get Parse utf8 string to          */
62
/*                                            multi-byte glyph            */
63
/*    _gx_widget_border_width_get           Get the widget border width   */
64
/*    _gx_widget_client_get                 Get widget client rectangle   */
65
/*    _gx_widget_font_get                   Get font by specified ID      */
66
/*    _gx_system_string_width_get           Get the width of a string     */
67
/*    _gx_system_dirty_mark                 Mark the area of the widget   */
68
/*                                            as dirty                    */
69
/*    _gx_system_dirty_partial_add          Mark the partial area of a    */
70
/*                                            widget as dirty             */
71
/*    _gx_text_input_cursor_dirty_rectangle_get                           */
72
/*                                          Get cursor rectangle          */
73
/*                                                                        */
74
/*  CALLED BY                                                             */
75
/*                                                                        */
76
/*    Application Code                                                    */
77
/*    GUIX Internal Code                                                  */
78
/*                                                                        */
79
/**************************************************************************/
80
581
UINT _gx_single_line_text_input_left_arrow(GX_SINGLE_LINE_TEXT_INPUT *text_input)
81
{
82
581
GX_TEXT_INPUT_CURSOR *cursor_ptr = &text_input -> gx_single_line_text_input_cursor_instance;
83
UINT                  insert_pos;
84
GX_RECTANGLE          client;
85
GX_RECTANGLE          cursor_rect;
86
GX_VALUE              old_cursor_pos;
87
GX_VALUE              cursor_pos;
88
GX_VALUE              width;
89
GX_FONT              *gx_font;
90
581
UINT                  glyph_len = 1;
91
581
UINT                  start_mark = text_input -> gx_single_line_text_input_start_mark;
92
581
UINT                  end_mark = text_input -> gx_single_line_text_input_end_mark;
93
581
GX_BOOL               mark_all = GX_FALSE;
94
GX_STRING             string;
95
96
581
    string.gx_string_ptr = text_input -> gx_single_line_text_input_buffer;
97
581
    string.gx_string_length = text_input -> gx_single_line_text_input_string_size;
98
99
100
    /* Move the cursor to the left by a character width.  */
101
102
    /* Pick up widget border width. */
103
581
    _gx_widget_border_width_get((GX_WIDGET *)text_input, &width);
104
105
    /* Get widget client rectangle. */
106
581
    _gx_widget_client_get((GX_WIDGET *)text_input, width, &client);
107
108
581
    cursor_pos = cursor_ptr -> gx_text_input_cursor_pos.gx_point_x;
109
581
    old_cursor_pos = cursor_pos;
110
111
581
    if (start_mark != end_mark)
112
    {
113
70
        text_input -> gx_single_line_text_input_start_mark = 0;
114
70
        text_input -> gx_single_line_text_input_end_mark = 0;
115
116
70
        if (end_mark < start_mark)
117
        {
118
49
            if (((cursor_pos > client.gx_rectangle_left) &&
119
20
                 (cursor_pos < client.gx_rectangle_right)) ||
120
38
                ((text_input -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK) == GX_STYLE_TEXT_CENTER))
121
            {
122
                /* No need to update cursor position, just need mark
123
                    cursor and highlight area as dirty. */
124
24
                _gx_text_input_cursor_dirty_rectangle_get(cursor_ptr, &cursor_rect);
125
126
24
                _gx_single_line_text_input_text_rectangle_get(text_input, (INT)(start_mark - end_mark), &client);
127
128
                /* Combine cursor rect and highlight area. */
129
24
                _gx_utility_rectangle_combine(&client, &cursor_rect);
130
131
24
                return _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &client);
132
            }
133
        }
134
    }
135
136
557
    insert_pos = text_input -> gx_single_line_text_input_insert_pos;
137
138

557
    if ((insert_pos > 0) || (start_mark > end_mark))
139
    {
140
531
        if (end_mark >= start_mark)
141
        {
142
            /* Calculate new cursor position. */
143
506
            if (end_mark != start_mark)
144
            {
145
21
                glyph_len = end_mark - start_mark;
146
            }
147
#ifdef GX_UTF8_SUPPORT
148
            else
149
            {
150
                /* Get the glyph length of the cursor left character. */
151
485
                _gx_utility_utf8_string_backward_character_length_get(&string, (INT)(insert_pos - 1), &glyph_len);
152
            }
153
#endif
154
            /* Reset the value of cursor positin. */
155
506
            text_input -> gx_single_line_text_input_insert_pos -= glyph_len;
156
157
            /* Pick up text font. */
158
506
            _gx_widget_font_get((GX_WIDGET *)text_input, text_input -> gx_prompt_font_id, &gx_font);
159
160
            /* Get text length before current cursor position to new cursor position. */
161
506
            string.gx_string_ptr += (insert_pos - glyph_len);
162
506
            string.gx_string_length = glyph_len;
163
506
            _gx_system_string_width_get_ext(gx_font, &string, &width);
164
165
506
            cursor_pos = (GX_VALUE)(cursor_ptr -> gx_text_input_cursor_pos.gx_point_x - width);
166
        }
167
168
531
        switch (text_input -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK)
169
        {
170
129
        case GX_STYLE_TEXT_CENTER:
171
129
            if (start_mark == end_mark)
172
            {
173
                /* Mark old cursor area dirty. */
174
122
                _gx_text_input_cursor_dirty_rectangle_get(cursor_ptr, &client);
175
122
                _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &client);
176
            }
177
178
129
            cursor_ptr -> gx_text_input_cursor_pos.gx_point_x = cursor_pos;
179
180
            /* Mark new cursor area dirty. */
181
129
            _gx_text_input_cursor_dirty_rectangle_get(cursor_ptr, &client);
182
129
            _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &client);
183
129
            break;
184
185
402
        case GX_STYLE_TEXT_RIGHT:
186
        case GX_STYLE_TEXT_LEFT:
187
        default:
188
402
            if (cursor_pos < client.gx_rectangle_left + 1)
189
            {
190
                /* Update text input x offset. */
191
57
                text_input -> gx_single_line_text_input_xoffset = (GX_VALUE)(text_input -> gx_single_line_text_input_xoffset -
192
57
                                                                             client.gx_rectangle_left - 1 + cursor_pos);
193
57
                cursor_ptr -> gx_text_input_cursor_pos.gx_point_x = (GX_VALUE)(client.gx_rectangle_left + 1);
194
195
57
                mark_all = GX_TRUE;
196
            }
197
345
            else if (cursor_pos > client.gx_rectangle_right - 1)
198
            {
199
                /* Cursor position is out of client rectangle, update x offset. */
200
8
                text_input -> gx_single_line_text_input_xoffset = (GX_VALUE)(text_input -> gx_single_line_text_input_xoffset +
201
8
                                                                             cursor_pos - client.gx_rectangle_right + 1);
202
8
                cursor_ptr -> gx_text_input_cursor_pos.gx_point_x = (GX_VALUE)(client.gx_rectangle_right - 1);
203
204
                /* Should mark all widget as dirty.  */
205
8
                mark_all = GX_TRUE;
206
            }
207
            else
208
            {
209
337
                if (start_mark == end_mark)
210
                {
211
                    /* Mark old cursor area dirty. */
212
333
                    _gx_text_input_cursor_dirty_rectangle_get(cursor_ptr, &client);
213
333
                    _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &client);
214
                }
215
337
                cursor_ptr -> gx_text_input_cursor_pos.gx_point_x = cursor_pos;
216
217
                /* Mark new cursor area dirty. */
218
337
                _gx_text_input_cursor_dirty_rectangle_get(cursor_ptr, &client);
219
337
                _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &client);
220
            }
221
402
            break;
222
        }
223
224

531
        if ((!mark_all) && (start_mark != end_mark))
225
        {
226
            /* Mark highlight area as dirty. */
227
11
            client.gx_rectangle_left = cursor_pos;
228
11
            client.gx_rectangle_right = (GX_VALUE)(old_cursor_pos - 1);
229
        }
230
231
531
        _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &client);
232
    }
233
234
557
    return GX_SUCCESS;
235
}
236