1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Björn Stenberg
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
29 #include "statusbar.h"
32 #include "rbunicode.h"
36 #define KBD_BUF_SIZE 64
37 #define KEYBOARD_PAGES 3
39 static unsigned short *kbd_setupkeys(int page
, int* len
)
41 static unsigned short kbdline
[KBD_BUF_SIZE
];
42 const unsigned char *p
;
47 case 0: /* Capitals */
48 p
= "ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅ"
49 "ÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝ";
53 p
= "abcdefghijklmnopqrstuvwxyzßàáâãä"
54 "åçèéêëìíîïñòóôõöøùúûüýÿ";
58 p
= " !\"#$%&'()*+,-./0123456789:;<=>?@[]_{}~";
63 p
= utf8decode(p
, &kbdline
[i
++]);
70 /* Delimiters for highlighting the character selected for insertion */
71 #define KEYBOARD_INSERT_LEFT 0xe110
72 #define KEYBOARD_INSERT_RIGHT 0xe10f
74 #define KEYBOARD_CURSOR 0x7f
75 #define KEYBOARD_ARROW 0xe10c
77 /* helper function to spell a char if voice UI is enabled */
78 static void kbd_spellchar(unsigned short c
)
80 if (global_settings
.talk_menu
) /* voice UI? */
83 /* store char to pass to talk_spell */
84 unsigned char* utf8
= utf8encode(c
, tmp
);
88 talk_id(VOICE_BLANK
, false);
90 talk_spell(tmp
, false);
94 static void say_edit(void)
96 if (global_settings
.talk_menu
)
97 talk_id(VOICE_EDIT
, false);
100 int kbd_input(char* text
, int buflen
)
104 bool line_edit
= false;
108 int len
, len_utf8
, i
, j
;
109 int editpos
, curpos
, leftpos
;
110 unsigned short *line
= kbd_setupkeys(page
, &linelen
);
111 unsigned char temptext
[36];
114 int button
, lastbutton
= 0;
116 editpos
= utf8length(text
);
118 if (global_settings
.talk_menu
) /* voice UI? */
119 talk_spell(text
, true); /* spell initial text */
124 len_utf8
= utf8length(text
);
131 lcd_putc(0, 1, KEYBOARD_ARROW
);
135 lcd_putc(0, 0, KEYBOARD_ARROW
);
139 lcd_putc(1, 0, KEYBOARD_INSERT_LEFT
);
140 lcd_putc(2, 0, line
[x
]);
141 lcd_putc(3, 0, KEYBOARD_INSERT_RIGHT
);
142 for (i
= 1; i
< 8; i
++)
144 lcd_putc(i
+ 3, 0, line
[(x
+i
)%linelen
]);
147 /* write out the text */
148 curpos
= MIN(MIN(editpos
, 10 - MIN(len_utf8
- editpos
, 3)), 9);
149 leftpos
= editpos
- curpos
;
151 utf8
= text
+ utf8seek(text
, leftpos
);
158 utf8
= text
+ utf8seek(text
, leftpos
+1);
160 while (*utf8
&& i
< 10) {
161 temptext
[j
++] = *utf8
++;
162 if ((*utf8
& MASK
) != COMP
)
168 if (len_utf8
- leftpos
> 10) {
169 utf8
= temptext
+ utf8seek(temptext
, 9);
175 lcd_puts(1, 1, temptext
);
176 lcd_put_cursor(curpos
+ 1, 1, KEYBOARD_CURSOR
);
178 gui_syncstatusbar_draw(&statusbars
, true);
181 /* The default action is to redraw */
184 button
= button_get_w_tmo(HZ
/2);
187 case BUTTON_STOP
: /* abort */
191 case BUTTON_MENU
: /* page flip */
192 if (++page
== KEYBOARD_PAGES
)
194 line
= kbd_setupkeys(page
, &linelen
);
197 kbd_spellchar(line
[x
]);
200 case BUTTON_ON
: /* toggle mode */
201 line_edit
= !line_edit
;
205 kbd_spellchar(line
[x
]);
209 case BUTTON_RIGHT
| BUTTON_REPEAT
:
212 if (editpos
< len_utf8
)
215 int c
= utf8seek(text
, editpos
);
216 kbd_spellchar(text
[c
]);
223 kbd_spellchar(line
[x
]);
228 case BUTTON_LEFT
| BUTTON_REPEAT
:
234 int c
= utf8seek(text
, editpos
);
235 kbd_spellchar(text
[c
]);
242 kbd_spellchar(line
[x
]);
246 case BUTTON_PLAY
| BUTTON_REPEAT
:
247 /* accepts what was entered and continues */
251 case BUTTON_PLAY
| BUTTON_REL
:
252 if (lastbutton
!= BUTTON_PLAY
)
254 if (line_edit
) /* backspace in line_edit */
258 utf8
= text
+ utf8seek(text
, editpos
);
263 } while ((*utf8
& MASK
) == COMP
);
272 else /* inserts the selected char */
274 utf8
= utf8encode(line
[x
], temptext
);
276 j
= strlen(temptext
);
277 if (len
+ j
< buflen
)
280 for (i
= len
+j
; k
>= editpos
; i
--) {
282 if ((text
[i
] & MASK
) != COMP
)
286 text
[i
--] = temptext
[j
];
290 if (global_settings
.talk_menu
) /* voice UI? */
291 talk_spell(text
, false); /* speak revised text */
295 gui_syncstatusbar_draw(&statusbars
, false);
300 default_event_handler(button
);
303 if (button
!= BUTTON_NONE
)