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"
33 #define KBD_BUF_SIZE 64
34 #define KEYBOARD_PAGES 3
36 static unsigned short *kbd_setupkeys(int page
, int* len
)
38 static unsigned short kbdline
[KBD_BUF_SIZE
];
39 const unsigned char *p
;
44 case 0: /* Capitals */
45 p
= "ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅ"
46 "ÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝ";
50 p
= "abcdefghijklmnopqrstuvwxyzßàáâãä"
51 "åçèéêëìíîïñòóôõöøùúûüýÿ";
55 p
= " !\"#$%&'()*+,-./0123456789:;<=>?@[]_{}~";
60 p
= utf8decode(p
, &kbdline
[i
++]);
67 /* Delimiters for highlighting the character selected for insertion */
68 #define KEYBOARD_INSERT_LEFT 0xe110
69 #define KEYBOARD_INSERT_RIGHT 0xe10f
71 #define KEYBOARD_CURSOR 0x7f
72 #define KEYBOARD_ARROW 0xe10c
74 /* helper function to spell a char if voice UI is enabled */
75 static void kbd_spellchar(char c
)
77 if (talk_menus_enabled()) /* voice UI? */
80 /* store char to pass to talk_spell */
81 unsigned char* utf8
= utf8encode(c
, tmp
);
85 talk_id(VOICE_BLANK
, false);
87 talk_spell(tmp
, false);
91 static void say_edit(void)
93 if (talk_menus_enabled())
94 talk_id(VOICE_EDIT
, false);
97 int kbd_input(char* text
, int buflen
)
101 bool line_edit
= false;
105 int len
, len_utf8
, i
, j
;
106 int editpos
, curpos
, leftpos
;
107 unsigned short *line
= kbd_setupkeys(page
, &linelen
);
108 unsigned char temptext
[36];
111 int button
, lastbutton
= 0;
113 editpos
= utf8length(text
);
115 if (talk_menus_enabled()) /* voice UI? */
116 talk_spell(text
, true); /* spell initial text */
121 len_utf8
= utf8length(text
);
128 lcd_putc(0, 1, KEYBOARD_ARROW
);
132 lcd_putc(0, 0, KEYBOARD_ARROW
);
136 lcd_putc(1, 0, KEYBOARD_INSERT_LEFT
);
137 lcd_putc(2, 0, line
[x
]);
138 lcd_putc(3, 0, KEYBOARD_INSERT_RIGHT
);
139 for (i
= 1; i
< 8; i
++)
141 lcd_putc(i
+ 3, 0, line
[(x
+i
)%linelen
]);
144 /* write out the text */
145 curpos
= MIN(MIN(editpos
, 10 - MIN(len_utf8
- editpos
, 3)), 9);
146 leftpos
= editpos
- curpos
;
148 utf8
= text
+ utf8seek(text
, leftpos
);
155 utf8
= text
+ utf8seek(text
, leftpos
+1);
157 while (*utf8
&& i
< 10) {
158 temptext
[j
++] = *utf8
++;
159 if ((*utf8
& MASK
) != COMP
)
165 if (len_utf8
- leftpos
> 10) {
166 utf8
= temptext
+ utf8seek(temptext
, 9);
172 lcd_puts(1, 1, temptext
);
173 lcd_put_cursor(curpos
+ 1, 1, KEYBOARD_CURSOR
);
175 gui_syncstatusbar_draw(&statusbars
, true);
178 /* The default action is to redraw */
181 button
= button_get_w_tmo(HZ
/2);
184 case BUTTON_STOP
: /* abort */
188 case BUTTON_MENU
: /* page flip */
189 if (++page
== KEYBOARD_PAGES
)
191 line
= kbd_setupkeys(page
, &linelen
);
194 kbd_spellchar(line
[x
]);
197 case BUTTON_ON
: /* toggle mode */
198 line_edit
= !line_edit
;
202 kbd_spellchar(line
[x
]);
206 case BUTTON_RIGHT
| BUTTON_REPEAT
:
209 if (editpos
< len_utf8
)
212 int c
= utf8seek(text
, editpos
);
213 kbd_spellchar(text
[c
]);
220 kbd_spellchar(line
[x
]);
225 case BUTTON_LEFT
| BUTTON_REPEAT
:
231 int c
= utf8seek(text
, editpos
);
232 kbd_spellchar(text
[c
]);
239 kbd_spellchar(line
[x
]);
243 case BUTTON_PLAY
| BUTTON_REPEAT
:
244 /* accepts what was entered and continues */
248 case BUTTON_PLAY
| BUTTON_REL
:
249 if (lastbutton
!= BUTTON_PLAY
)
251 if (line_edit
) /* backspace in line_edit */
255 utf8
= text
+ utf8seek(text
, editpos
);
260 } while ((*utf8
& MASK
) == COMP
);
269 else /* inserts the selected char */
271 utf8
= utf8encode(line
[x
], temptext
);
273 j
= strlen(temptext
);
274 if (len
+ j
< buflen
)
277 for (i
= len
+j
; k
>= editpos
; i
--) {
279 if ((text
[i
] & MASK
) != COMP
)
283 text
[i
--] = temptext
[j
];
287 if (talk_menus_enabled()) /* voice UI? */
288 talk_spell(text
, false); /* speak revised text */
292 gui_syncstatusbar_draw(&statusbars
, false);
297 default_event_handler(button
);
300 if (button
!= BUTTON_NONE
)