1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
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_single_line_text_input.h"
31 #include "gx_utility.h"
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _gx_single_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 key-down events for the single line text */
46 /* input widget. */
47 /* */
48 /* INPUT */
49 /* */
50 /* text_input Single-line text input widget */
51 /* control block */
52 /* event_ptr Pointer to GX_EVENT structure */
53 /* */
54 /* OUTPUT */
55 /* */
56 /* None */
57 /* */
58 /* CALLS */
59 /* */
60 /* _gx_widget_event_process Default widget event process */
61 /* _gx_widget_event_generate Create a event and send it to */
62 /* parent */
63 /* _gx_single_line_text_input_home Process the home key */
64 /* _gx_single_line_text_input_end Process the end key */
65 /* _gx_single_line_text_input_backspace Process the backspace key */
66 /* _gx_single_line_text_input_character_delete */
67 /* Delete a character */
68 /* _gx_single_line_text_input_left_arrow */
69 /* Process the left arrow key */
70 /* _gx_single_line_text_input_right_arrow */
71 /* Process the right arrow key */
72 /* _gx_single_line_text_input_character_insert */
73 /* Insert a charcter */
74 /* */
75 /* CALLED BY */
76 /* */
77 /* _gx_single_line_text_input_event_process */
78 /* Single line text input widget */
79 /* event process routine */
80 /* */
81 /* RELEASE HISTORY */
82 /* */
83 /* DATE NAME DESCRIPTION */
84 /* */
85 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
86 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */
87 /* resulting in version 6.1 */
88 /* */
89 /**************************************************************************/
_gx_single_line_text_input_keydown_process(GX_SINGLE_LINE_TEXT_INPUT * text_input,GX_EVENT * event_ptr)90 VOID _gx_single_line_text_input_keydown_process(GX_SINGLE_LINE_TEXT_INPUT *text_input, GX_EVENT *event_ptr)
91 {
92 GX_WIDGET *widget = (GX_WIDGET *)text_input;
93 USHORT key_value;
94 GX_UBYTE utf8_str[10];
95 UINT utf8_size;
96
97 /* Process relative to the value of key. */
98 switch (event_ptr -> gx_event_payload.gx_event_ushortdata[0])
99 {
100 case GX_KEY_HOME:
101 _gx_single_line_text_input_home(text_input);
102 break;
103
104 case GX_KEY_END:
105 _gx_single_line_text_input_end(text_input);
106 break;
107
108 case GX_KEY_BACKSPACE:
109 _gx_single_line_text_input_backspace(text_input);
110 break;
111
112 case GX_KEY_DELETE:
113 _gx_single_line_text_input_character_delete(text_input);
114 break;
115
116 case GX_KEY_LEFT_ARROW:
117 _gx_single_line_text_input_left_arrow(text_input);
118 break;
119
120 case GX_KEY_RIGHT_ARROW:
121 _gx_single_line_text_input_right_arrow(text_input);
122 break;
123
124 case GX_KEY_SELECT:
125 if (text_input -> gx_single_line_text_input_was_modified)
126 {
127 _gx_widget_event_generate(widget, GX_EVENT_TEXT_EDITED, 0);
128 text_input -> gx_single_line_text_input_was_modified = GX_FALSE;
129 }
130 break;
131 case GX_KEY_SPACE:
132 utf8_str[0] = ' ';
133 utf8_size = 1;
134 _gx_single_line_text_input_character_insert(text_input, utf8_str, utf8_size);
135 break;
136
137 default:
138 key_value = event_ptr -> gx_event_payload.gx_event_ushortdata[0];
139
140 if ((key_value <= 0x1f) ||
141 ((key_value >= 0x1b01) && key_value <= 0x1b14))
142 {
143 _gx_widget_event_process((GX_WIDGET *)text_input, event_ptr);
144 return;
145 }
146
147 /* If the key value is displayable, insert the value to the text input. */
148 if (key_value <= 0x7e)
149 {
150 utf8_str[0] = (GX_UBYTE)key_value;
151 utf8_size = 1;
152 _gx_single_line_text_input_character_insert(text_input, utf8_str, utf8_size);
153 }
154 #ifdef GX_UTF8_SUPPORT
155 else
156 {
157 _gx_utility_unicode_to_utf8(key_value, utf8_str, &utf8_size);
158
159 /* Insert a utf8 string to input buffer. */
160 _gx_single_line_text_input_character_insert(text_input, utf8_str, utf8_size);
161 }
162 #endif
163 break;
164 }
165 }
166
167