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