GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_single_line_text_input_create.c Lines: 58 58 100.0 %
Date: 2026-03-06 19:21:09 Branches: 19 19 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_widget.h"
30
#include "gx_prompt.h"
31
#include "gx_single_line_text_input.h"
32
#include "gx_utility.h"
33
34
/**************************************************************************/
35
/*                                                                        */
36
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _gx_single_line_text_input_create                   PORTABLE C      */
39
/*                                                           6.1.3        */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Kenneth Maxwell, Microsoft Corporation                              */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This service creates a single-line text input widget.               */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    text_input                        Single-line text input widget     */
51
/*                                        control block                   */
52
/*    name                              Name of text input widget         */
53
/*    parent                            Pointer to parent widget          */
54
/*    input_buffer                      Pointer to text input buffer      */
55
/*    buffer_size                       Size of text input buffer         */
56
/*    style                             Style of text input widget.       */
57
/*    text_input_id                     Application-defined ID for text   */
58
/*                                        input                           */
59
/*    size                              Dimensions of text input widget   */
60
/*                                                                        */
61
/*  OUTPUT                                                                */
62
/*                                                                        */
63
/*    status                            Completion status                 */
64
/*                                                                        */
65
/*  CALLS                                                                 */
66
/*                                                                        */
67
/*    _gx_prompt_create                 Create a prompt                   */
68
/*    _gx_widget_border_width_get       Get widget border width           */
69
/*    _gx_widget_client_get             Get widget client rectangle       */
70
/*    _gx_widget_link                   Link the widget to its parent     */
71
/*    _gx_utility_string_length_check   Test string length                */
72
/*                                                                        */
73
/*  CALLED BY                                                             */
74
/*                                                                        */
75
/*    Application Code                                                    */
76
/*                                                                        */
77
/**************************************************************************/
78
876
UINT  _gx_single_line_text_input_create(GX_SINGLE_LINE_TEXT_INPUT *text_input,
79
                                        GX_CONST GX_CHAR *name,
80
                                        GX_WIDGET *parent,
81
                                        GX_CHAR *input_buffer,
82
                                        UINT buffer_size,
83
                                        UINT style,
84
                                        USHORT text_input_id,
85
                                        GX_CONST GX_RECTANGLE *size)
86
{
87
GX_TEXT_INPUT_CURSOR *cursor_ptr;
88
GX_VALUE              width;
89
GX_RECTANGLE          client;
90
91
    /* Don't allow TEXT_COPY style, the text input widget always uses a dynamic buffer */
92
876
    style &= (ULONG) ~GX_STYLE_TEXT_COPY;
93
94
    /* Call the prompt widget create function.  */
95
876
    _gx_prompt_create((GX_PROMPT *)text_input, name, GX_NULL, 0, style, text_input_id, size);
96
97
98

876
    if ((!input_buffer) && buffer_size)
99
    {
100
278
        if (!_gx_system_memory_allocator)
101
        {
102
1
            return GX_SYSTEM_MEMORY_ERROR;
103
        }
104
105
277
        input_buffer = _gx_system_memory_allocator(buffer_size);
106
107
277
        if (!input_buffer)
108
        {
109
1
            return GX_SYSTEM_MEMORY_ERROR;
110
        }
111
112
276
        text_input -> gx_widget_status |= GX_STATUS_DYNAMIC_BUFFER;
113
    }
114
115
874
    cursor_ptr = &text_input -> gx_single_line_text_input_cursor_instance;
116
117
    /* Finish the rest of the single line text input widget creation process. */
118
874
    text_input -> gx_widget_type = GX_TYPE_SINGLE_LINE_TEXT_INPUT;
119
874
    text_input -> gx_prompt_font_id = GX_FONT_ID_TEXT_INPUT;
120
874
    text_input -> gx_prompt_normal_text_color = GX_COLOR_ID_TEXT_INPUT_TEXT;
121
874
    text_input -> gx_widget_normal_fill_color = GX_COLOR_ID_TEXT_INPUT_FILL;
122
874
    text_input -> gx_single_line_text_input_readonly_text_color = GX_COLOR_ID_READONLY_TEXT;
123
874
    text_input -> gx_single_line_text_input_readonly_fill_color = GX_COLOR_ID_READONLY_FILL;
124
874
    text_input -> gx_widget_draw_function = (VOID (*)(GX_WIDGET *))_gx_single_line_text_input_draw;
125
874
    text_input -> gx_widget_event_process_function = (UINT (*)(GX_WIDGET *, GX_EVENT *))_gx_single_line_text_input_event_process;
126
874
    text_input -> gx_single_line_text_input_buffer = input_buffer;
127
874
    text_input -> gx_single_line_text_input_buffer_size = buffer_size;
128
874
    text_input -> gx_widget_style |= GX_STYLE_CURSOR_BLINK;
129
874
    text_input -> gx_single_line_text_input_was_modified = GX_FALSE;
130
874
    text_input -> gx_single_line_text_input_yoffset = 0;
131
874
    text_input -> gx_widget_selected_fill_color = GX_COLOR_ID_SELECTED_FILL;
132
874
    text_input -> gx_prompt_selected_text_color = GX_COLOR_ID_SELECTED_TEXT;
133
874
    text_input -> gx_single_line_text_input_start_mark = 0;
134
874
    text_input -> gx_single_line_text_input_end_mark = 0;
135
136
874
    cursor_ptr -> gx_text_input_cursor_blink_interval = GX_CURSOR_BLINK_INTERVAL;
137
874
    cursor_ptr -> gx_text_input_cursor_height = 0;
138
874
    cursor_ptr -> gx_text_input_cursor_width = 1;
139
874
    cursor_ptr -> gx_text_input_cursor_pos.gx_point_x = 0;
140
874
    cursor_ptr -> gx_text_input_cursor_pos.gx_point_y = 0;
141
874
    cursor_ptr -> gx_text_input_cursor_flags = 0;
142
143
    /* Pickup widget width. */
144
874
    _gx_widget_border_width_get((GX_WIDGET *)text_input, &width);
145
146
    /* Pickup client rectangle. */
147
874
    _gx_widget_client_get((GX_WIDGET *)text_input, width, &client);
148
149
    /* Calculate client width.  */
150
874
    width = (GX_VALUE)(client.gx_rectangle_right - client.gx_rectangle_left + 1);
151
152
874
    switch (text_input -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK)
153
    {
154
94
    case GX_STYLE_TEXT_RIGHT:
155
        /* Right aliagnment. */
156
94
        text_input -> gx_single_line_text_input_xoffset = (GX_VALUE)(3 - width);
157
94
        break;
158
159
1
    case GX_STYLE_TEXT_CENTER:
160
        /* Center aligned. */
161
1
        text_input -> gx_single_line_text_input_xoffset = (GX_VALUE)(width >> 1);
162
1
        break;
163
164
779
    case GX_STYLE_TEXT_LEFT:
165
    default:
166
        /* Default: Left aliagnment. */
167
779
        text_input -> gx_single_line_text_input_xoffset = 0;
168
779
        break;
169
    }
170
171
874
    if (buffer_size)
172
    {
173
872
        if (_gx_utility_string_length_check(input_buffer, &text_input -> gx_single_line_text_input_string_size, buffer_size - 1) != GX_SUCCESS)
174
        {
175
1
            text_input -> gx_single_line_text_input_string_size = 0;
176
        }
177
    }
178
    else
179
    {
180
2
        text_input -> gx_single_line_text_input_string_size = 0;
181
    }
182
183
874
    text_input -> gx_single_line_text_input_insert_pos = text_input -> gx_single_line_text_input_string_size;
184
185
874
    if (text_input -> gx_widget_style & GX_STYLE_CURSOR_ALWAYS)
186
    {
187
3
        text_input -> gx_widget_status |= (GX_STATUS_CURSOR_SHOW | GX_STATUS_CURSOR_DRAW);
188
189
        /* this widget wants to be notified if it is moved or re-sized */
190
3
        text_input -> gx_widget_status |= GX_STATUS_RESIZE_NOTIFY;
191
    }
192
193
    /* Determine if a parent widget was provided.  */
194
874
    if (parent)
195
    {
196
870
        _gx_widget_link(parent, (GX_WIDGET *)text_input);
197
    }
198
199
    /* Return the complete status */
200
874
    return(GX_SUCCESS);
201
}
202