GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_single_line_text_input_mark_home.c Lines: 46 46 100.0 %
Date: 2026-03-06 19:21:09 Branches: 13 13 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_mark_home                PORTABLE C      */
40
/*                                                           6.1          */
41
/*  AUTHOR                                                                */
42
/*                                                                        */
43
/*    Kenneth Maxwell, Microsoft Corporation                              */
44
/*                                                                        */
45
/*  DESCRIPTION                                                           */
46
/*                                                                        */
47
/*    This service moves the end mark position to the start of the input  */
48
/*    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
/*    _gx_single_line_text_input_text_rectangle_get                       */
71
/*                                          Retrieve text rectangle       */
72
/*                                                                        */
73
/*  CALLED BY                                                             */
74
/*                                                                        */
75
/*    GUIX Internal Code                                                  */
76
/*                                                                        */
77
/**************************************************************************/
78
41
UINT _gx_single_line_text_input_mark_home(GX_SINGLE_LINE_TEXT_INPUT *text_input)
79
{
80
GX_TEXT_INPUT_CURSOR *cursor_ptr;
81
GX_VALUE              border_width;
82
GX_VALUE              text_width;
83
GX_RECTANGLE          client;
84
GX_FONT              *gx_font;
85
GX_VALUE              new_xoffset;
86
GX_VALUE              new_cursor_pos;
87
41
UINT                  start_mark = text_input -> gx_single_line_text_input_start_mark;
88
41
UINT                  end_mark = text_input -> gx_single_line_text_input_end_mark;
89
GX_STRING             string;
90
91
41
    cursor_ptr = &text_input -> gx_single_line_text_input_cursor_instance;
92
93
    /* Check if cursor already in the home position. */
94
41
    if (text_input -> gx_single_line_text_input_insert_pos == 0)
95
    {
96
2
        return GX_SUCCESS;
97
    }
98
99
39
    if (start_mark == end_mark)
100
    {
101
        /* Set start mark and end mark to current cursor position. */
102
3
        start_mark = text_input -> gx_single_line_text_input_insert_pos;
103
3
        end_mark = text_input -> gx_single_line_text_input_insert_pos;
104
105
3
        text_input -> gx_single_line_text_input_start_mark = start_mark;
106
3
        text_input -> gx_single_line_text_input_end_mark = end_mark;
107
    }
108
109
39
    _gx_widget_border_width_get((GX_WIDGET *)text_input, &border_width);
110
39
    _gx_widget_client_get((GX_WIDGET *)text_input, border_width, &client);
111
112
39
    switch (text_input -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK)
113
    {
114
13
    case GX_STYLE_TEXT_RIGHT:
115
        /* Calculate new x offset.  */
116
13
        _gx_widget_font_get((GX_WIDGET *)text_input, text_input -> gx_prompt_font_id, &gx_font);
117
13
        string.gx_string_ptr = text_input -> gx_single_line_text_input_buffer;
118
13
        string.gx_string_length = text_input -> gx_single_line_text_input_string_size;
119
13
        _gx_system_string_width_get_ext(gx_font, &string, &text_width);
120
13
        new_xoffset = (GX_VALUE)(client.gx_rectangle_right - client.gx_rectangle_left + 1);
121
122
13
        new_xoffset = (GX_VALUE)(new_xoffset - 3);
123
124
13
        if (text_width < new_xoffset)
125
        {
126
1
            new_xoffset = text_width;
127
        }
128
129
        /* Calculate new cursor position.  */
130
13
        new_cursor_pos = (GX_VALUE)(client.gx_rectangle_right - 1 - new_xoffset);
131
13
        break;
132
133
12
    case GX_STYLE_TEXT_CENTER:
134
        /* Calculate new cursor position.  */
135
12
        new_xoffset = 0;
136
12
        new_cursor_pos = (GX_VALUE)(client.gx_rectangle_left + 1 + ((client.gx_rectangle_right - client.gx_rectangle_left + 1) >> 1));
137
12
        new_cursor_pos = (GX_VALUE)(new_cursor_pos - text_input -> gx_single_line_text_input_xoffset);
138
12
        break;
139
140
141
14
    case GX_STYLE_TEXT_LEFT:
142
    default:
143
14
        new_xoffset = 0;
144
14
        new_cursor_pos = (GX_VALUE)(client.gx_rectangle_left + 1);
145
14
        break;
146
    }
147
148
39
    if (text_input -> gx_single_line_text_input_xoffset != new_xoffset)
149
    {
150
        /* We need to update x offset, mark whole text input area dirty.  */
151
28
        _gx_system_dirty_mark((GX_WIDGET *)text_input);
152
    }
153
    else
154
    {
155
11
        if (start_mark == end_mark)
156
        {
157
            /* Mark old curosr rectangle as dirty. */
158
3
            _gx_text_input_cursor_dirty_rectangle_get(cursor_ptr, &client);
159
3
            _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &client);
160
        }
161
162
        /* Get bounding rectangle of highlight text. */
163
11
        _gx_single_line_text_input_text_rectangle_get(text_input, (INT)(0 - end_mark), &client);
164
165
        /* Mark highlight area as dirty. */
166
11
        _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &client);
167
    }
168
169
39
    text_input -> gx_single_line_text_input_end_mark = 0;
170
171
    /* Update cursor position. */
172
39
    cursor_ptr -> gx_text_input_cursor_pos.gx_point_x = new_cursor_pos;
173
174
    /* Update character insert position.  */
175
39
    text_input -> gx_single_line_text_input_insert_pos = 0;
176
177
    /* Update text input x offset.  */
178
39
    text_input -> gx_single_line_text_input_xoffset = new_xoffset;
179
180
39
    return GX_SUCCESS;
181
}
182