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"
37 #define KBD_BUF_SIZE 64
38 #define KEYBOARD_PAGES 3
40 static unsigned short *kbd_setupkeys(int page
, int* len
)
42 static unsigned short kbdline
[KBD_BUF_SIZE
];
43 const unsigned char *p
;
48 case 0: /* Capitals */
49 p
= "ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅ"
50 "ÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝ";
54 p
= "abcdefghijklmnopqrstuvwxyzßàáâãä"
55 "åçèéêëìíîïñòóôõöøùúûüýÿ";
59 p
= " !\"#$%&'()*+,-./0123456789:;<=>?@[]_{}~";
64 p
= utf8decode(p
, &kbdline
[i
++]);
71 /* Delimiters for highlighting the character selected for insertion */
72 #define KEYBOARD_INSERT_LEFT 0xe110
73 #define KEYBOARD_INSERT_RIGHT 0xe10f
75 #define KEYBOARD_CURSOR 0x7f
76 #define KEYBOARD_ARROW 0xe10c
78 /* helper function to spell a char if voice UI is enabled */
79 static void kbd_spellchar(unsigned short c
)
81 if (global_settings
.talk_menu
) /* voice UI? */
84 /* store char to pass to talk_spell */
85 unsigned char* utf8
= utf8encode(c
, tmp
);
89 talk_id(VOICE_BLANK
, false);
91 talk_spell(tmp
, false);
95 static void say_edit(void)
97 if (global_settings
.talk_menu
)
98 talk_id(VOICE_EDIT
, false);
101 int kbd_input(char* text
, int buflen
)
105 bool line_edit
= false;
109 int len
, len_utf8
, i
, j
;
110 int editpos
, curpos
, leftpos
;
111 unsigned short *line
= kbd_setupkeys(page
, &linelen
);
112 unsigned char temptext
[36];
115 int button
, lastbutton
= 0;
116 int ret
= 0; /* assume success */
118 editpos
= utf8length(text
);
120 if (global_settings
.talk_menu
) /* voice UI? */
121 talk_spell(text
, true); /* spell initial text */
126 len_utf8
= utf8length(text
);
133 lcd_putc(0, 1, KEYBOARD_ARROW
);
137 lcd_putc(0, 0, KEYBOARD_ARROW
);
141 lcd_putc(1, 0, KEYBOARD_INSERT_LEFT
);
142 lcd_putc(2, 0, line
[x
]);
143 lcd_putc(3, 0, KEYBOARD_INSERT_RIGHT
);
144 for (i
= 1; i
< 8; i
++)
146 lcd_putc(i
+ 3, 0, line
[(x
+i
)%linelen
]);
149 /* write out the text */
150 curpos
= MIN(MIN(editpos
, 10 - MIN(len_utf8
- editpos
, 3)), 9);
151 leftpos
= editpos
- curpos
;
153 utf8
= text
+ utf8seek(text
, leftpos
);
160 utf8
= text
+ utf8seek(text
, leftpos
+1);
162 while (*utf8
&& i
< 10) {
163 temptext
[j
++] = *utf8
++;
164 if ((*utf8
& MASK
) != COMP
)
170 if (len_utf8
- leftpos
> 10) {
171 utf8
= temptext
+ utf8seek(temptext
, 9);
177 lcd_puts(1, 1, temptext
);
178 lcd_put_cursor(curpos
+ 1, 1, KEYBOARD_CURSOR
);
180 gui_syncstatusbar_draw(&statusbars
, true);
183 /* The default action is to redraw */
186 button
= button_get_w_tmo(HZ
/2);
189 case BUTTON_STOP
: /* abort */
190 ret
= -1; done
= true;
193 case BUTTON_MENU
: /* page flip */
194 if (++page
== KEYBOARD_PAGES
)
196 line
= kbd_setupkeys(page
, &linelen
);
199 kbd_spellchar(line
[x
]);
202 case BUTTON_ON
: /* toggle mode */
203 line_edit
= !line_edit
;
207 kbd_spellchar(line
[x
]);
211 case BUTTON_RIGHT
| BUTTON_REPEAT
:
214 if (editpos
< len_utf8
)
217 int c
= utf8seek(text
, editpos
);
218 kbd_spellchar(text
[c
]);
225 kbd_spellchar(line
[x
]);
230 case BUTTON_LEFT
| BUTTON_REPEAT
:
236 int c
= utf8seek(text
, editpos
);
237 kbd_spellchar(text
[c
]);
244 kbd_spellchar(line
[x
]);
248 case BUTTON_PLAY
| BUTTON_REPEAT
:
249 /* accepts what was entered and continues */
250 ret
= 0; done
= true;
253 case BUTTON_PLAY
| BUTTON_REL
:
254 if (lastbutton
!= BUTTON_PLAY
)
256 if (line_edit
) /* backspace in line_edit */
260 utf8
= text
+ utf8seek(text
, editpos
);
265 } while ((*utf8
& MASK
) == COMP
);
274 else /* inserts the selected char */
276 utf8
= utf8encode(line
[x
], temptext
);
278 j
= strlen(temptext
);
279 if (len
+ j
< buflen
)
282 for (i
= len
+j
; k
>= editpos
; i
--) {
284 if ((text
[i
] & MASK
) != COMP
)
288 text
[i
--] = temptext
[j
];
292 if (global_settings
.talk_menu
) /* voice UI? */
293 talk_spell(text
, false); /* speak revised text */
297 gui_syncstatusbar_draw(&statusbars
, false);
302 default_event_handler(button
);
305 if (button
!= BUTTON_NONE
)
310 splash(HZ
/2, ID2P(LANG_CANCEL
));