GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_multi_line_text_input_keydown_process.c Lines: 53 53 100.0 %
Date: 2024-12-05 08:52:37 Branches: 19 19 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_multi_line_text_input.h"
28
#include "gx_utility.h"
29
#include "gx_window.h"
30
#include "gx_system.h"
31
#include "gx_multi_line_text_view.h"
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _gx_multi_line_text_input_keydown_process           PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Kenneth Maxwell, Microsoft Corporation                              */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function processes events for the specified text input widget. */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    input                                 Multi line text input         */
50
/*                                            control block               */
51
/*    event_ptr                             Incoming event to process     */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    None                                                                */
56
/*                                                                        */
57
/*  CALLS                                                                 */
58
/*                                                                        */
59
/*    _gx_multi_line_text_input_backspace   Process the backspace key     */
60
/*    _gx_multi_line_text_input_delete      Process the delete key        */
61
/*    _gx_multi_line_text_input_left_arrow  Process the left arrow key    */
62
/*    _gx_multi_line_text_input_right_arrow Process the right arrow key   */
63
/*    _gx_multi_line_text_input_up_arrow    Process the up arrow key      */
64
/*    _gx_multi_line_text_input_down_arrow  Process the down arrow key    */
65
/*    _gx_multi_line_text_input_char_insert                               */
66
/*                                          Insert a character            */
67
/*    _gx_multi_line_text_input_home        Process the HOME key          */
68
/*    _gx_multi_line_text_input_end         Process the END key           */
69
/*    _gx_utility_unicode_to_utf8           Parse a unicode to utf8 string*/
70
/*    _gx_window_event_process              Default window event process  */
71
/*                                                                        */
72
/*  CALLED BY                                                             */
73
/*                                                                        */
74
/*    _gx_multi_line_text_input_event_process                             */
75
/*                                                                        */
76
/*  RELEASE HISTORY                                                       */
77
/*                                                                        */
78
/*    DATE              NAME                      DESCRIPTION             */
79
/*                                                                        */
80
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
81
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
82
/*                                            resulting in version 6.1    */
83
/*                                                                        */
84
/**************************************************************************/
85
4152
UINT  _gx_multi_line_text_input_keydown_process(GX_MULTI_LINE_TEXT_INPUT *input, GX_EVENT *event_ptr)
86
{
87
UINT      status;
88
USHORT    key_value;
89
GX_UBYTE  utf8_str[10];
90
GX_STRING string;
91
92


4152
    switch (event_ptr -> gx_event_payload.gx_event_ushortdata[0])
93
    {
94
310
    case GX_KEY_BACKSPACE:
95
310
        status = _gx_multi_line_text_input_backspace(input);
96
310
        break;
97
98
303
    case GX_KEY_DELETE:
99
303
        status = _gx_multi_line_text_input_delete(input);
100
303
        break;
101
102
523
    case GX_KEY_LEFT_ARROW:
103
523
        status = _gx_multi_line_text_input_left_arrow(input);
104
523
        break;
105
106
385
    case GX_KEY_RIGHT_ARROW:
107
385
        status = _gx_multi_line_text_input_right_arrow(input);
108
385
        break;
109
110
208
    case GX_KEY_UP_ARROW:
111
208
        status = _gx_multi_line_text_input_up_arrow(input);
112
208
        break;
113
114
222
    case GX_KEY_DOWN_ARROW:
115
222
        status = _gx_multi_line_text_input_down_arrow(input);
116
222
        break;
117
118
521
    case GX_KEY_CARRIAGE_RETURN:
119
    case GX_KEY_LINE_FEED:
120
521
        utf8_str[0] = (GX_UBYTE)event_ptr -> gx_event_payload.gx_event_ushortdata[0];
121
521
        string.gx_string_ptr = (GX_CHAR *)utf8_str;
122
521
        string.gx_string_length = 1;
123
521
        status = _gx_multi_line_text_input_char_insert_ext(input, &string);
124
521
        break;
125
126
83
    case GX_KEY_SPACE:
127
83
        utf8_str[0] = ' ';
128
83
        string.gx_string_ptr = (GX_CHAR *)utf8_str;
129
83
        string.gx_string_length = 1;
130
83
        status = _gx_multi_line_text_input_char_insert_ext(input, &string);
131
83
        break;
132
133
268
    case GX_KEY_HOME:
134
268
        status = _gx_multi_line_text_input_home(input);
135
268
        break;
136
137
268
    case GX_KEY_END:
138
268
        status = _gx_multi_line_text_input_end(input);
139
268
        break;
140
141
1061
    default:
142
1061
        key_value = event_ptr -> gx_event_payload.gx_event_ushortdata[0];
143
144

1061
        if ((key_value <= 0x1f) ||
145
3
            ((key_value >= 0x1b01) && key_value <= 0x1b14))
146
        {
147
9
            return _gx_window_event_process((GX_WINDOW *)input, event_ptr);
148
        }
149
150
1052
        if (key_value <= 0x7e)
151
        {
152
1051
            utf8_str[0] = (GX_UBYTE)key_value;
153
1051
            string.gx_string_ptr = (GX_CHAR *)utf8_str;
154
1051
            string.gx_string_length = 1;
155
1051
            status = _gx_multi_line_text_input_char_insert_ext(input, &string);
156
        }
157
#ifdef GX_UTF8_SUPPORT
158
        else
159
        {
160
161
1
            _gx_utility_unicode_to_utf8(key_value, utf8_str, &string.gx_string_length);
162
163
1
            string.gx_string_ptr = (GX_CHAR *)utf8_str;
164
165
            /* Insert a utf8 string to input buffer. */
166
1
            status = _gx_multi_line_text_input_char_insert_ext(input, &string);
167
        }
168
#endif
169
1052
        break;
170
    }
171
172
4143
    return status;
173
}
174