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