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_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 |
|
|
/**************************************************************************/ |
82 |
|
12077 |
VOID _gx_single_line_text_input_keydown_process(GX_SINGLE_LINE_TEXT_INPUT *text_input, GX_EVENT *event_ptr) |
83 |
|
|
{ |
84 |
|
12077 |
GX_WIDGET *widget = (GX_WIDGET *)text_input; |
85 |
|
|
USHORT key_value; |
86 |
|
|
GX_UBYTE utf8_str[10]; |
87 |
|
|
UINT utf8_size; |
88 |
|
|
|
89 |
|
|
/* Process relative to the value of key. */ |
90 |
✓✓✓✓ ✓✓✓✓ ✓ |
12077 |
switch (event_ptr -> gx_event_payload.gx_event_ushortdata[0]) |
91 |
|
|
{ |
92 |
|
667 |
case GX_KEY_HOME: |
93 |
|
667 |
_gx_single_line_text_input_home(text_input); |
94 |
|
667 |
break; |
95 |
|
|
|
96 |
|
660 |
case GX_KEY_END: |
97 |
|
660 |
_gx_single_line_text_input_end(text_input); |
98 |
|
660 |
break; |
99 |
|
|
|
100 |
|
548 |
case GX_KEY_BACKSPACE: |
101 |
|
548 |
_gx_single_line_text_input_backspace(text_input); |
102 |
|
548 |
break; |
103 |
|
|
|
104 |
|
559 |
case GX_KEY_DELETE: |
105 |
|
559 |
_gx_single_line_text_input_character_delete(text_input); |
106 |
|
559 |
break; |
107 |
|
|
|
108 |
|
556 |
case GX_KEY_LEFT_ARROW: |
109 |
|
556 |
_gx_single_line_text_input_left_arrow(text_input); |
110 |
|
556 |
break; |
111 |
|
|
|
112 |
|
6404 |
case GX_KEY_RIGHT_ARROW: |
113 |
|
6404 |
_gx_single_line_text_input_right_arrow(text_input); |
114 |
|
6404 |
break; |
115 |
|
|
|
116 |
|
501 |
case GX_KEY_SELECT: |
117 |
✓✓ |
501 |
if (text_input -> gx_single_line_text_input_was_modified) |
118 |
|
|
{ |
119 |
|
497 |
_gx_widget_event_generate(widget, GX_EVENT_TEXT_EDITED, 0); |
120 |
|
497 |
text_input -> gx_single_line_text_input_was_modified = GX_FALSE; |
121 |
|
|
} |
122 |
|
501 |
break; |
123 |
|
516 |
case GX_KEY_SPACE: |
124 |
|
516 |
utf8_str[0] = ' '; |
125 |
|
516 |
utf8_size = 1; |
126 |
|
516 |
_gx_single_line_text_input_character_insert(text_input, utf8_str, utf8_size); |
127 |
|
516 |
break; |
128 |
|
|
|
129 |
|
1666 |
default: |
130 |
|
1666 |
key_value = event_ptr -> gx_event_payload.gx_event_ushortdata[0]; |
131 |
|
|
|
132 |
✓✓✓✓
|
1666 |
if ((key_value <= 0x1f) || |
133 |
✓✓ |
408 |
((key_value >= 0x1b01) && key_value <= 0x1b14)) |
134 |
|
|
{ |
135 |
|
293 |
_gx_widget_event_process((GX_WIDGET *)text_input, event_ptr); |
136 |
|
293 |
return; |
137 |
|
|
} |
138 |
|
|
|
139 |
|
|
/* If the key value is displayable, insert the value to the text input. */ |
140 |
✓✓ |
1373 |
if (key_value <= 0x7e) |
141 |
|
|
{ |
142 |
|
1255 |
utf8_str[0] = (GX_UBYTE)key_value; |
143 |
|
1255 |
utf8_size = 1; |
144 |
|
1255 |
_gx_single_line_text_input_character_insert(text_input, utf8_str, utf8_size); |
145 |
|
|
} |
146 |
|
|
#ifdef GX_UTF8_SUPPORT |
147 |
|
|
else |
148 |
|
|
{ |
149 |
|
118 |
_gx_utility_unicode_to_utf8(key_value, utf8_str, &utf8_size); |
150 |
|
|
|
151 |
|
|
/* Insert a utf8 string to input buffer. */ |
152 |
|
118 |
_gx_single_line_text_input_character_insert(text_input, utf8_str, utf8_size); |
153 |
|
|
} |
154 |
|
|
#endif |
155 |
|
1373 |
break; |
156 |
|
|
} |
157 |
|
|
} |
158 |
|
|
|