GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_single_line_text_input_home.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_system.h"
29
#include "gx_display.h"
30
#include "gx_context.h"
31
#include "gx_widget.h"
32
#include "gx_single_line_text_input.h"
33
#include "gx_text_input_cursor.h"
34
35
/**************************************************************************/
36
/*                                                                        */
37
/*  FUNCTION                                               RELEASE        */
38
/*                                                                        */
39
/*    _gx_single_line_text_input_home                     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 position to the start of   */
48
/*    the input string.                                                   */
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_widget_font_get                   Get font by specified ID      */
62
/*    _gx_widget_border_width_get           Get the widget border width   */
63
/*    _gx_widget_client_get                 Retrieves client area of the  */
64
/*                                            widget                      */
65
/*    _gx_system_string_width_get           Get the width of a string     */
66
/*    _gx_system_dirty_mark                 Mart the area of the widget   */
67
/*                                            dirty                       */
68
/*    _gx_system_dirty_partial_add          Mark the partial area of a    */
69
/*                                            widget as dirty             */
70
/*                                                                        */
71
/*  CALLED BY                                                             */
72
/*                                                                        */
73
/*    Application Code                                                    */
74
/*    GUIX Internal Code                                                  */
75
/*                                                                        */
76
/**************************************************************************/
77
668
UINT _gx_single_line_text_input_home(GX_SINGLE_LINE_TEXT_INPUT *text_input)
78
{
79
GX_TEXT_INPUT_CURSOR *cursor_ptr;
80
GX_VALUE              border_width;
81
GX_VALUE              text_width;
82
GX_RECTANGLE          client;
83
GX_FONT              *gx_font;
84
GX_VALUE              new_xoffset;
85
GX_VALUE              new_cursor_pos;
86
668
UINT                  start_mark = text_input -> gx_single_line_text_input_start_mark;
87
668
UINT                  end_mark = text_input -> gx_single_line_text_input_end_mark;
88
668
GX_BOOL               mark_new_cursor_dirty = GX_FALSE;
89
GX_STRING             string;
90
91
668
    if (start_mark != end_mark)
92
    {
93
78
        text_input -> gx_single_line_text_input_start_mark = 0;
94
78
        text_input -> gx_single_line_text_input_end_mark = 0;
95
    }
96
97
668
    cursor_ptr = &text_input -> gx_single_line_text_input_cursor_instance;
98
99
    /* Check if cursor already in the home position. */
100
668
    if (text_input -> gx_single_line_text_input_insert_pos == 0)
101
    {
102
30
        return GX_SUCCESS;
103
    }
104
105
638
    _gx_widget_border_width_get((GX_WIDGET *)text_input, &border_width);
106
638
    _gx_widget_client_get((GX_WIDGET *)text_input, border_width, &client);
107
108
638
    switch (text_input -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK)
109
    {
110
172
    case GX_STYLE_TEXT_RIGHT:
111
        /* Calculate new x offset.  */
112
172
        _gx_widget_font_get((GX_WIDGET *)text_input, text_input -> gx_prompt_font_id, &gx_font);
113
114
172
        string.gx_string_ptr = text_input -> gx_single_line_text_input_buffer;
115
172
        string.gx_string_length = text_input -> gx_single_line_text_input_string_size;
116
172
        _gx_system_string_width_get_ext(gx_font, &string, &text_width);
117
172
        new_xoffset = (GX_VALUE)(client.gx_rectangle_right - client.gx_rectangle_left + 1);
118
119
172
        new_xoffset = (GX_VALUE)(new_xoffset - 3);
120
121
172
        if (text_width < new_xoffset)
122
        {
123
28
            new_xoffset = text_width;
124
        }
125
126
        /* Calculate new cursor position.  */
127
172
        new_cursor_pos = (GX_VALUE)(client.gx_rectangle_right - 1 - new_xoffset);
128
172
        break;
129
130
173
    case GX_STYLE_TEXT_CENTER:
131
        /* Calculate new cursor position.  */
132
173
        new_xoffset = 0;
133
173
        new_cursor_pos = (GX_VALUE)(client.gx_rectangle_left + 1 + ((client.gx_rectangle_right - client.gx_rectangle_left + 1) >> 1));
134
173
        new_cursor_pos = (GX_VALUE)(new_cursor_pos - text_input -> gx_single_line_text_input_xoffset);
135
173
        break;
136
137
138
293
    case GX_STYLE_TEXT_LEFT:
139
    default:
140
293
        new_xoffset = 0;
141
293
        new_cursor_pos = (GX_VALUE)(client.gx_rectangle_left + 1);
142
293
        break;
143
    }
144
145
638
    if (text_input -> gx_single_line_text_input_xoffset != new_xoffset)
146
    {
147
        /* We need to update x offset, mark whole text input area dirty.  */
148
522
        _gx_system_dirty_mark((GX_WIDGET *)text_input);
149
    }
150
    else
151
    {
152
116
        if (start_mark != end_mark)
153
        {
154
            /* Get bounding rectangle of highlight text. */
155
16
            _gx_single_line_text_input_text_rectangle_get(text_input, (INT)(start_mark - end_mark), &client);
156
157
            /* Mark highlight area as dirty. */
158
16
            _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &client);
159
160
16
            mark_new_cursor_dirty = GX_TRUE;
161
        }
162
        else
163
        {
164
            /* No need to update x offset, mark old and new cursor position area dirty.  */
165
166
            /* Mark old curosr rectangle as dirty. */
167
100
            _gx_text_input_cursor_dirty_rectangle_get(cursor_ptr, &client);
168
100
            _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &client);
169
170
100
            mark_new_cursor_dirty = GX_TRUE;
171
        }
172
    }
173
174
    /* Update cursor position. */
175
638
    cursor_ptr -> gx_text_input_cursor_pos.gx_point_x = new_cursor_pos;
176
177
    /* Update character insert position.  */
178
638
    text_input -> gx_single_line_text_input_insert_pos = 0;
179
180
    /* Update text input x offset.  */
181
638
    text_input -> gx_single_line_text_input_xoffset = new_xoffset;
182
183
638
    if (mark_new_cursor_dirty)
184
    {
185
        /* Mark new cursor rectangle as dirty. */
186
116
        _gx_text_input_cursor_dirty_rectangle_get(cursor_ptr, &client);
187
116
        _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &client);
188
    }
189
190
638
    return GX_SUCCESS;
191
}
192