1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Björn Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
27 #include "statusbar.h"
30 #include "rbunicode.h"
32 #define KBD_BUF_SIZE 64
33 #define KEYBOARD_PAGES 3
35 static unsigned short *kbd_setupkeys(int page
, int* len
)
37 static unsigned short kbdline
[KBD_BUF_SIZE
];
38 const unsigned char *p
;
43 case 0: /* Capitals */
44 p
= "ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅ"
45 "ÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝ";
49 p
= "abcdefghijklmnopqrstuvwxyzßàáâãä"
50 "åçèéêëìíîïñòóôõöøùúûüýÿ";
54 p
= " !\"#$%&'()*+,-./0123456789:;<=>?@[]_{}~";
59 p
= utf8decode(p
, &kbdline
[i
++]);
66 /* Delimiters for highlighting the character selected for insertion */
67 #define KEYBOARD_INSERT_LEFT 0xe110
68 #define KEYBOARD_INSERT_RIGHT 0xe10f
70 #define KEYBOARD_CURSOR 0x7f
71 #define KEYBOARD_ARROW 0xe10c
73 /* helper function to spell a char if voice UI is enabled */
74 static void kbd_spellchar(char c
)
76 static char spell_char
[2] = "\0\0"; /* store char to pass to talk_spell */
78 if (talk_menus_enabled()) /* voice UI? */
81 talk_spell(spell_char
, false);
85 int kbd_input(char* text
, int buflen
)
89 bool line_edit
= false;
93 int len
, len_utf8
, i
, j
;
94 int editpos
, curpos
, leftpos
;
95 unsigned short *line
= kbd_setupkeys(page
, &linelen
);
96 unsigned char temptext
[36];
99 int button
, lastbutton
= 0;
101 editpos
= utf8length(text
);
103 if (talk_menus_enabled()) /* voice UI? */
104 talk_spell(text
, true); /* spell initial text */
109 len_utf8
= utf8length(text
);
116 lcd_putc(0, 1, KEYBOARD_ARROW
);
120 lcd_putc(0, 0, KEYBOARD_ARROW
);
124 lcd_putc(1, 0, KEYBOARD_INSERT_LEFT
);
125 lcd_putc(2, 0, line
[x
]);
126 lcd_putc(3, 0, KEYBOARD_INSERT_RIGHT
);
127 for (i
= 1; i
< 8; i
++)
129 lcd_putc(i
+ 3, 0, line
[(x
+i
)%linelen
]);
132 /* write out the text */
133 curpos
= MIN(MIN(editpos
, 10 - MIN(len_utf8
- editpos
, 3)), 9);
134 leftpos
= editpos
- curpos
;
136 utf8
= text
+ utf8seek(text
, leftpos
);
143 utf8
= text
+ utf8seek(text
, leftpos
+1);
145 while (*utf8
&& i
< 10) {
146 temptext
[j
++] = *utf8
++;
147 if ((*utf8
& MASK
) != COMP
)
153 if (len_utf8
- leftpos
> 10) {
154 utf8
= temptext
+ utf8seek(temptext
, 9);
160 lcd_puts(1, 1, temptext
);
161 lcd_put_cursor(curpos
+ 1, 1, KEYBOARD_CURSOR
);
163 gui_syncstatusbar_draw(&statusbars
, true);
166 /* The default action is to redraw */
169 button
= button_get_w_tmo(HZ
/2);
172 case BUTTON_STOP
: /* abort */
176 case BUTTON_MENU
: /* page flip */
177 if (++page
== KEYBOARD_PAGES
)
179 line
= kbd_setupkeys(page
, &linelen
);
182 kbd_spellchar(line
[x
]);
185 case BUTTON_ON
: /* toggle mode */
186 line_edit
= !line_edit
;
188 kbd_spellchar(line
[x
]);
192 case BUTTON_RIGHT
| BUTTON_REPEAT
:
195 if (editpos
< len_utf8
)
198 int c
= utf8seek(text
, editpos
);
199 kbd_spellchar(text
[c
]);
206 kbd_spellchar(line
[x
]);
211 case BUTTON_LEFT
| BUTTON_REPEAT
:
217 int c
= utf8seek(text
, editpos
);
218 kbd_spellchar(text
[c
]);
225 kbd_spellchar(line
[x
]);
229 case BUTTON_PLAY
| BUTTON_REPEAT
:
230 /* accepts what was entered and continues */
234 case BUTTON_PLAY
| BUTTON_REL
:
235 if (lastbutton
!= BUTTON_PLAY
)
237 if (line_edit
) /* backspace in line_edit */
241 utf8
= text
+ utf8seek(text
, editpos
);
246 } while ((*utf8
& MASK
) == COMP
);
255 else /* inserts the selected char */
257 utf8
= utf8encode(line
[x
], temptext
);
259 j
= strlen(temptext
);
260 if (len
+ j
< buflen
)
263 for (i
= len
+j
; k
>= editpos
; i
--) {
265 if ((text
[i
] & MASK
) != COMP
)
269 text
[i
--] = temptext
[j
];
273 if (talk_menus_enabled()) /* voice UI? */
274 talk_spell(text
, false); /* speak revised text */
278 gui_syncstatusbar_draw(&statusbars
, false);
283 default_event_handler(button
);
286 if (button
!= BUTTON_NONE
)