GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_multi_line_text_input_create.c Lines: 45 45 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_widget.h"
29
#include "gx_multi_line_text_input.h"
30
#include "gx_multi_line_text_view.h"
31
#include "gx_utility.h"
32
#include "gx_system.h"
33
34
/**************************************************************************/
35
/*                                                                        */
36
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _gx_multi_line_text_input_create                    PORTABLE C      */
39
/*                                                           6.1.3        */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Kenneth Maxwell, Microsoft Corporation                              */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This function creates a multi-line text input widget.               */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    text_input                          Multi-line input widget control */
51
/*                                          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 in    */
56
/*                                          bytes                         */
57
/*    style                               Style of text input widget      */
58
/*    text_input_id                       Application-defined ID of the   */
59
/*                                          text input widget             */
60
/*    Size                                Dimensions of text input widget */
61
/*                                                                        */
62
/*  OUTPUT                                                                */
63
/*                                                                        */
64
/*    status                                Completion status             */
65
/*                                                                        */
66
/*  CALLS                                                                 */
67
/*                                                                        */
68
/*    _gx_multi_line_text_view_create     Create the multi line text view */
69
/*                                          widget                        */
70
/*    _gx_multi_line_text_view_text_set   Set the multi line text view    */
71
/*                                          text                          */
72
/*    _gx_widget_link                     Link the widget to its parent   */
73
/*                                                                        */
74
/*  CALLED BY                                                             */
75
/*                                                                        */
76
/*    Application Code                                                    */
77
/*                                                                        */
78
/**************************************************************************/
79
573
UINT  _gx_multi_line_text_input_create(GX_MULTI_LINE_TEXT_INPUT *text_input,
80
                                       GX_CONST GX_CHAR *name,
81
                                       GX_WIDGET *parent,
82
                                       GX_CHAR *input_buffer,
83
                                       UINT buffer_size,
84
                                       ULONG style,
85
                                       USHORT text_input_id,
86
                                       GX_CONST GX_RECTANGLE *size)
87
{
88
573
GX_MULTI_LINE_TEXT_VIEW *view = (GX_MULTI_LINE_TEXT_VIEW *)text_input;
89
573
GX_TEXT_INPUT_CURSOR    *cursor_ptr = &text_input -> gx_multi_line_text_input_cursor_instance;
90
GX_STRING                string;
91
92
    /* Don't allow the GX_STYLE_TEXT_COPY style, the text input always uses a dynamic buffer */
93
573
    style &= (ULONG) ~GX_STYLE_TEXT_COPY;
94
95
    /* Call the multi-line text view create function. */
96
573
    _gx_multi_line_text_view_create(view, name, GX_NULL, 0, style, text_input_id, size);
97
98

573
    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
571
    if (_gx_utility_string_length_check(input_buffer, &string.gx_string_length, buffer_size - 1) == GX_SUCCESS)
116
    {
117
569
        string.gx_string_ptr = input_buffer;
118
569
        _gx_multi_line_text_view_text_set_ext(view, &string);
119
    }
120
    else
121
    {
122
2
        text_input -> gx_multi_line_text_view_text.gx_string_ptr = input_buffer;
123
2
        text_input -> gx_multi_line_text_view_text.gx_string_length = 0;
124
    }
125
126
571
    text_input -> gx_widget_type = GX_TYPE_MULTI_LINE_TEXT_INPUT;
127
571
    text_input -> gx_widget_event_process_function = (UINT (*)(GX_WIDGET *, GX_EVENT *))_gx_multi_line_text_input_event_process;
128
571
    text_input -> gx_widget_draw_function = (VOID (*)(GX_WIDGET *))_gx_multi_line_text_input_draw;
129
571
    text_input -> gx_multi_line_text_input_text_was_modified = GX_FALSE;
130
571
    text_input -> gx_multi_line_text_input_buffer_size = buffer_size;
131
571
    text_input -> gx_widget_style |= GX_STYLE_CURSOR_BLINK;
132
571
    text_input -> gx_multi_line_text_input_text_cursor_line = 1;
133
571
    text_input -> gx_multi_line_text_input_text_insert_position = 0;
134
571
    text_input -> gx_multi_line_text_input_new_line_character[0] = GX_KEY_CARRIAGE_RETURN;
135
571
    text_input -> gx_multi_line_text_input_new_line_character[1] = '\0';
136
571
    text_input -> gx_multi_line_text_input_new_line_character_size = 1;
137
571
    text_input -> gx_multi_line_text_input_readonly_text_color = GX_COLOR_ID_READONLY_TEXT;
138
571
    text_input -> gx_multi_line_text_input_readonly_fill_color = GX_COLOR_ID_READONLY_FILL;
139
571
    text_input -> gx_widget_selected_fill_color = GX_COLOR_ID_SELECTED_FILL;
140
571
    text_input -> gx_multi_line_text_view_selected_text_color = GX_COLOR_ID_SELECTED_TEXT;
141
571
    text_input -> gx_multi_line_text_input_start_mark = 0;
142
571
    text_input -> gx_multi_line_text_input_end_mark = 0;
143
144
571
    cursor_ptr -> gx_text_input_cursor_height = 0;
145
571
    cursor_ptr -> gx_text_input_cursor_width = 1;
146
571
    cursor_ptr -> gx_text_input_cursor_flags = 0;
147
571
    cursor_ptr -> gx_text_input_cursor_blink_interval = GX_CURSOR_BLINK_INTERVAL;
148
571
    cursor_ptr -> gx_text_input_cursor_pos.gx_point_y = 0;
149
571
    cursor_ptr -> gx_text_input_cursor_pos.gx_point_x = (GX_VALUE)(text_input -> gx_window_client.gx_rectangle_left + 1);
150
151
    /* Determine if a parent widget was provided.  */
152
571
    if (parent)
153
    {
154
568
        _gx_widget_link((GX_WIDGET *)parent, (GX_WIDGET *)text_input);
155
    }
156
157
571
    if (text_input -> gx_widget_style & GX_STYLE_CURSOR_ALWAYS)
158
    {
159
1
        text_input -> gx_widget_status |= (GX_STATUS_CURSOR_SHOW | GX_STATUS_CURSOR_DRAW);
160
    }
161
162
571
    return(GX_SUCCESS);
163
}
164