GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_multi_line_text_input_create.c Lines: 45 45 100.0 %
Date: 2024-12-05 08:52:37 Branches: 14 14 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 *
4
 * This program and the accompanying materials are made available under the
5
 * terms of the MIT License which is available at
6
 * https://opensource.org/licenses/MIT.
7
 *
8
 * SPDX-License-Identifier: MIT
9
 **************************************************************************/
10
11
12
/**************************************************************************/
13
/**************************************************************************/
14
/**                                                                       */
15
/** GUIX Component                                                        */
16
/**                                                                       */
17
/**   Multi Line Text Input Management (Multi Line Text Input)            */
18
/**                                                                       */
19
/**************************************************************************/
20
21
#define GX_SOURCE_CODE
22
23
24
/* Include necessary system files.  */
25
26
#include "gx_api.h"
27
#include "gx_widget.h"
28
#include "gx_multi_line_text_input.h"
29
#include "gx_multi_line_text_view.h"
30
#include "gx_utility.h"
31
#include "gx_system.h"
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _gx_multi_line_text_input_create                    PORTABLE C      */
38
/*                                                           6.1.3        */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Kenneth Maxwell, Microsoft Corporation                              */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function creates a multi-line text input widget.               */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    text_input                          Multi-line input widget control */
50
/*                                          block                         */
51
/*    name                                Name of text input widget       */
52
/*    parent                              Pointer to parent widget        */
53
/*    input_buffer                        Pointer to text input buffer    */
54
/*    buffer_size                         Size of text input buffer in    */
55
/*                                          bytes                         */
56
/*    style                               Style of text input widget      */
57
/*    text_input_id                       Application-defined ID of the   */
58
/*                                          text input widget             */
59
/*    Size                                Dimensions of text input widget */
60
/*                                                                        */
61
/*  OUTPUT                                                                */
62
/*                                                                        */
63
/*    status                                Completion status             */
64
/*                                                                        */
65
/*  CALLS                                                                 */
66
/*                                                                        */
67
/*    _gx_multi_line_text_view_create     Create the multi line text view */
68
/*                                          widget                        */
69
/*    _gx_multi_line_text_view_text_set   Set the multi line text view    */
70
/*                                          text                          */
71
/*    _gx_widget_link                     Link the widget to its parent   */
72
/*                                                                        */
73
/*  CALLED BY                                                             */
74
/*                                                                        */
75
/*    Application Code                                                    */
76
/*                                                                        */
77
/*  RELEASE HISTORY                                                       */
78
/*                                                                        */
79
/*    DATE              NAME                      DESCRIPTION             */
80
/*                                                                        */
81
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
82
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
83
/*                                            resulting in version 6.1    */
84
/*  12-31-2020     Kenneth Maxwell          Modified comment(s),          */
85
/*                                            supported dynamic buffer,   */
86
/*                                            resulting in version 6.1.3  */
87
/*                                                                        */
88
/**************************************************************************/
89
573
UINT  _gx_multi_line_text_input_create(GX_MULTI_LINE_TEXT_INPUT *text_input,
90
                                       GX_CONST GX_CHAR *name,
91
                                       GX_WIDGET *parent,
92
                                       GX_CHAR *input_buffer,
93
                                       UINT buffer_size,
94
                                       ULONG style,
95
                                       USHORT text_input_id,
96
                                       GX_CONST GX_RECTANGLE *size)
97
{
98
573
GX_MULTI_LINE_TEXT_VIEW *view = (GX_MULTI_LINE_TEXT_VIEW *)text_input;
99
573
GX_TEXT_INPUT_CURSOR    *cursor_ptr = &text_input -> gx_multi_line_text_input_cursor_instance;
100
GX_STRING                string;
101
102
    /* Don't allow the GX_STYLE_TEXT_COPY style, the text input always uses a dynamic buffer */
103
573
    style &= (ULONG) ~GX_STYLE_TEXT_COPY;
104
105
    /* Call the multi-line text view create function. */
106
573
    _gx_multi_line_text_view_create(view, name, GX_NULL, 0, style, text_input_id, size);
107
108

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