2002-12-04 15:04:43 +00:00
|
|
|
|
/***************************************************************************
|
|
|
|
|
* __________ __ ___.
|
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2002 by Bj<EFBFBD>rn Stenberg
|
|
|
|
|
*
|
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
|
*
|
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
|
* KIND, either express or implied.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
#include "lcd.h"
|
|
|
|
|
#include "button.h"
|
|
|
|
|
#include "kernel.h"
|
2005-02-06 23:23:49 +00:00
|
|
|
|
#include "system.h"
|
2002-12-04 15:04:43 +00:00
|
|
|
|
#include "version.h"
|
|
|
|
|
#include "sprintf.h"
|
|
|
|
|
#include <string.h>
|
2005-02-06 23:23:49 +00:00
|
|
|
|
#include "settings.h"
|
2005-11-20 01:02:14 +00:00
|
|
|
|
#include "statusbar.h"
|
2005-02-06 23:23:49 +00:00
|
|
|
|
#include "talk.h"
|
|
|
|
|
#include "misc.h"
|
2005-12-06 13:27:15 +00:00
|
|
|
|
#include "rbunicode.h"
|
2002-12-04 15:04:43 +00:00
|
|
|
|
|
2007-03-26 07:52:13 +00:00
|
|
|
|
#define KBD_BUF_SIZE 64
|
2003-01-20 12:25:28 +00:00
|
|
|
|
#define KEYBOARD_PAGES 3
|
|
|
|
|
|
2007-03-26 07:52:13 +00:00
|
|
|
|
static unsigned short *kbd_setupkeys(int page, int* len)
|
2002-12-04 15:04:43 +00:00
|
|
|
|
{
|
2007-03-26 07:52:13 +00:00
|
|
|
|
static unsigned short kbdline[KBD_BUF_SIZE];
|
|
|
|
|
const unsigned char *p;
|
2003-01-20 12:25:28 +00:00
|
|
|
|
int i = 0;
|
|
|
|
|
|
2007-03-26 07:52:13 +00:00
|
|
|
|
switch (page)
|
2005-02-06 23:23:49 +00:00
|
|
|
|
{
|
|
|
|
|
case 0: /* Capitals */
|
2007-03-26 07:52:13 +00:00
|
|
|
|
p = "ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅ"
|
2007-03-27 18:32:58 +00:00
|
|
|
|
"ÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝ";
|
2005-02-06 23:23:49 +00:00
|
|
|
|
break;
|
2003-01-20 12:25:28 +00:00
|
|
|
|
|
2005-02-06 23:23:49 +00:00
|
|
|
|
case 1: /* Small */
|
2007-03-26 07:52:13 +00:00
|
|
|
|
p = "abcdefghijklmnopqrstuvwxyzßàáâãä"
|
2007-03-27 18:32:58 +00:00
|
|
|
|
"åçèéêëìíîïñòóôõöøùúûüýÿ";
|
2005-02-06 23:23:49 +00:00
|
|
|
|
break;
|
2003-01-20 12:25:28 +00:00
|
|
|
|
|
2007-03-26 07:52:13 +00:00
|
|
|
|
default: /* Others */
|
|
|
|
|
p = " !\"#$%&'()*+,-./0123456789:;<=>?@[]_{}~";
|
2005-02-06 23:23:49 +00:00
|
|
|
|
break;
|
2003-01-20 12:25:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-03-26 07:52:13 +00:00
|
|
|
|
while (*p)
|
|
|
|
|
p = utf8decode(p, &kbdline[i++]);
|
|
|
|
|
|
2003-01-20 12:25:28 +00:00
|
|
|
|
*len = i;
|
|
|
|
|
|
2007-03-26 07:52:13 +00:00
|
|
|
|
return kbdline;
|
2002-12-04 15:04:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-24 14:51:22 +00:00
|
|
|
|
/* Delimiters for highlighting the character selected for insertion */
|
2007-03-26 07:52:13 +00:00
|
|
|
|
#define KEYBOARD_INSERT_LEFT 0xe110
|
|
|
|
|
#define KEYBOARD_INSERT_RIGHT 0xe10f
|
2003-01-24 14:51:22 +00:00
|
|
|
|
|
|
|
|
|
#define KEYBOARD_CURSOR 0x7f
|
2007-03-26 07:52:13 +00:00
|
|
|
|
#define KEYBOARD_ARROW 0xe10c
|
2003-01-24 14:51:22 +00:00
|
|
|
|
|
2005-02-06 23:23:49 +00:00
|
|
|
|
/* helper function to spell a char if voice UI is enabled */
|
|
|
|
|
static void kbd_spellchar(char c)
|
|
|
|
|
{
|
|
|
|
|
static char spell_char[2] = "\0\0"; /* store char to pass to talk_spell */
|
|
|
|
|
|
2007-06-11 08:30:13 +00:00
|
|
|
|
if (talk_menus_enabled()) /* voice UI? */
|
2005-02-06 23:23:49 +00:00
|
|
|
|
{
|
|
|
|
|
spell_char[0] = c;
|
|
|
|
|
talk_spell(spell_char, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-01-24 14:51:22 +00:00
|
|
|
|
|
2002-12-04 15:04:43 +00:00
|
|
|
|
int kbd_input(char* text, int buflen)
|
|
|
|
|
{
|
|
|
|
|
bool done = false;
|
2005-02-06 23:23:49 +00:00
|
|
|
|
bool redraw = true;
|
|
|
|
|
bool line_edit = false;
|
|
|
|
|
int page = 0, x = 0;
|
2003-01-20 12:25:28 +00:00
|
|
|
|
int linelen;
|
2005-02-06 23:23:49 +00:00
|
|
|
|
|
2005-12-06 13:27:15 +00:00
|
|
|
|
int len, len_utf8, i, j;
|
2005-02-06 23:23:49 +00:00
|
|
|
|
int editpos, curpos, leftpos;
|
2007-03-26 07:52:13 +00:00
|
|
|
|
unsigned short *line = kbd_setupkeys(page, &linelen);
|
2005-12-06 13:27:15 +00:00
|
|
|
|
unsigned char temptext[36];
|
|
|
|
|
unsigned char *utf8;
|
2002-12-04 15:04:43 +00:00
|
|
|
|
|
2005-02-06 23:23:49 +00:00
|
|
|
|
int button, lastbutton = 0;
|
|
|
|
|
|
2005-12-06 13:27:15 +00:00
|
|
|
|
editpos = utf8length(text);
|
2005-02-06 23:23:49 +00:00
|
|
|
|
|
2007-06-11 08:30:13 +00:00
|
|
|
|
if (talk_menus_enabled()) /* voice UI? */
|
2005-02-06 23:23:49 +00:00
|
|
|
|
talk_spell(text, true); /* spell initial text */
|
|
|
|
|
|
|
|
|
|
while (!done)
|
|
|
|
|
{
|
|
|
|
|
len = strlen(text);
|
2005-12-06 13:27:15 +00:00
|
|
|
|
len_utf8 = utf8length(text);
|
|
|
|
|
|
2005-02-06 23:23:49 +00:00
|
|
|
|
if (redraw)
|
|
|
|
|
{
|
|
|
|
|
if (line_edit)
|
|
|
|
|
{
|
|
|
|
|
lcd_putc(0, 0, ' ');
|
|
|
|
|
lcd_putc(0, 1, KEYBOARD_ARROW);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
lcd_putc(0, 0, KEYBOARD_ARROW);
|
|
|
|
|
lcd_putc(0, 1, ' ');
|
|
|
|
|
}
|
2007-03-26 07:52:13 +00:00
|
|
|
|
|
|
|
|
|
lcd_putc(1, 0, KEYBOARD_INSERT_LEFT);
|
|
|
|
|
lcd_putc(2, 0, line[x]);
|
|
|
|
|
lcd_putc(3, 0, KEYBOARD_INSERT_RIGHT);
|
2005-02-06 23:23:49 +00:00
|
|
|
|
for (i = 1; i < 8; i++)
|
|
|
|
|
{
|
2007-03-26 07:52:13 +00:00
|
|
|
|
lcd_putc(i + 3, 0, line[(x+i)%linelen]);
|
2005-02-06 23:23:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* write out the text */
|
2005-12-06 13:27:15 +00:00
|
|
|
|
curpos = MIN(MIN(editpos, 10 - MIN(len_utf8 - editpos, 3)), 9);
|
2005-02-06 23:23:49 +00:00
|
|
|
|
leftpos = editpos - curpos;
|
2005-12-06 13:27:15 +00:00
|
|
|
|
if (!leftpos) {
|
|
|
|
|
utf8 = text + utf8seek(text, leftpos);
|
|
|
|
|
i = 0;
|
|
|
|
|
j = 0;
|
|
|
|
|
} else {
|
2005-02-06 23:23:49 +00:00
|
|
|
|
temptext[0] = '<';
|
2005-12-06 13:27:15 +00:00
|
|
|
|
i = 1;
|
|
|
|
|
j = 1;
|
|
|
|
|
utf8 = text + utf8seek(text, leftpos+1);
|
|
|
|
|
}
|
|
|
|
|
while (*utf8 && i < 10) {
|
|
|
|
|
temptext[j++] = *utf8++;
|
|
|
|
|
if ((*utf8 & MASK) != COMP)
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
temptext[j] = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (len_utf8 - leftpos > 10) {
|
|
|
|
|
utf8 = temptext + utf8seek(temptext, 9);
|
|
|
|
|
*utf8++ = '>';
|
|
|
|
|
*utf8 = 0;
|
|
|
|
|
}
|
2005-02-06 23:23:49 +00:00
|
|
|
|
|
|
|
|
|
lcd_remove_cursor();
|
|
|
|
|
lcd_puts(1, 1, temptext);
|
|
|
|
|
lcd_put_cursor(curpos + 1, 1, KEYBOARD_CURSOR);
|
2007-03-26 07:52:13 +00:00
|
|
|
|
|
2005-11-20 01:02:14 +00:00
|
|
|
|
gui_syncstatusbar_draw(&statusbars, true);
|
2003-01-21 14:26:56 +00:00
|
|
|
|
}
|
2005-02-06 23:23:49 +00:00
|
|
|
|
|
|
|
|
|
/* The default action is to redraw */
|
|
|
|
|
redraw = true;
|
|
|
|
|
|
|
|
|
|
button = button_get_w_tmo(HZ/2);
|
|
|
|
|
switch (button)
|
|
|
|
|
{
|
|
|
|
|
case BUTTON_STOP: /* abort */
|
|
|
|
|
return -1;
|
2003-01-24 14:51:22 +00:00
|
|
|
|
break;
|
2005-02-06 23:23:49 +00:00
|
|
|
|
|
|
|
|
|
case BUTTON_MENU: /* page flip */
|
|
|
|
|
if (++page == KEYBOARD_PAGES)
|
|
|
|
|
page = 0;
|
|
|
|
|
line = kbd_setupkeys(page, &linelen);
|
|
|
|
|
if (x > linelen - 1)
|
|
|
|
|
x = linelen - 1;
|
|
|
|
|
kbd_spellchar(line[x]);
|
2003-01-24 14:51:22 +00:00
|
|
|
|
break;
|
2005-02-06 23:23:49 +00:00
|
|
|
|
|
|
|
|
|
case BUTTON_ON: /* toggle mode */
|
|
|
|
|
line_edit = !line_edit;
|
|
|
|
|
if (!line_edit)
|
|
|
|
|
kbd_spellchar(line[x]);
|
2003-01-24 14:51:22 +00:00
|
|
|
|
break;
|
2002-12-04 15:04:43 +00:00
|
|
|
|
|
2005-02-06 23:23:49 +00:00
|
|
|
|
case BUTTON_RIGHT:
|
|
|
|
|
case BUTTON_RIGHT | BUTTON_REPEAT:
|
|
|
|
|
if (line_edit)
|
2003-01-24 14:51:22 +00:00
|
|
|
|
{
|
2005-12-06 13:27:15 +00:00
|
|
|
|
if (editpos < len_utf8)
|
2005-02-06 23:23:49 +00:00
|
|
|
|
{
|
|
|
|
|
editpos++;
|
2005-12-06 13:27:15 +00:00
|
|
|
|
int c = utf8seek(text, editpos);
|
|
|
|
|
kbd_spellchar(text[c]);
|
2005-02-06 23:23:49 +00:00
|
|
|
|
}
|
2003-01-24 14:51:22 +00:00
|
|
|
|
}
|
2005-02-06 23:23:49 +00:00
|
|
|
|
else
|
2003-01-24 14:51:22 +00:00
|
|
|
|
{
|
2005-08-24 06:48:39 +00:00
|
|
|
|
if (++x >= linelen)
|
2005-02-06 23:23:49 +00:00
|
|
|
|
x = 0;
|
|
|
|
|
kbd_spellchar(line[x]);
|
2003-01-21 14:26:56 +00:00
|
|
|
|
}
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
2003-01-24 14:51:22 +00:00
|
|
|
|
|
2005-02-06 23:23:49 +00:00
|
|
|
|
case BUTTON_LEFT:
|
|
|
|
|
case BUTTON_LEFT | BUTTON_REPEAT:
|
|
|
|
|
if (line_edit)
|
|
|
|
|
{
|
|
|
|
|
if (editpos)
|
|
|
|
|
{
|
|
|
|
|
editpos--;
|
2005-12-06 13:27:15 +00:00
|
|
|
|
int c = utf8seek(text, editpos);
|
|
|
|
|
kbd_spellchar(text[c]);
|
2005-02-06 23:23:49 +00:00
|
|
|
|
}
|
2003-01-27 14:37:03 +00:00
|
|
|
|
}
|
2005-02-06 23:23:49 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2005-08-24 06:48:39 +00:00
|
|
|
|
if (--x < 0)
|
2005-02-06 23:23:49 +00:00
|
|
|
|
x = linelen - 1;
|
|
|
|
|
kbd_spellchar(line[x]);
|
2003-01-21 14:26:56 +00:00
|
|
|
|
}
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
2003-01-24 14:51:22 +00:00
|
|
|
|
|
2005-02-06 23:23:49 +00:00
|
|
|
|
case BUTTON_PLAY | BUTTON_REPEAT:
|
|
|
|
|
/* accepts what was entered and continues */
|
|
|
|
|
done = true;
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
2003-01-24 14:51:22 +00:00
|
|
|
|
|
2005-02-06 23:23:49 +00:00
|
|
|
|
case BUTTON_PLAY | BUTTON_REL:
|
|
|
|
|
if (lastbutton != BUTTON_PLAY)
|
|
|
|
|
break;
|
|
|
|
|
if (line_edit) /* backspace in line_edit */
|
|
|
|
|
{
|
|
|
|
|
if (editpos > 0)
|
|
|
|
|
{
|
2005-12-06 13:27:15 +00:00
|
|
|
|
utf8 = text + utf8seek(text, editpos);
|
|
|
|
|
i = 0;
|
|
|
|
|
do {
|
|
|
|
|
i++;
|
|
|
|
|
utf8--;
|
|
|
|
|
} while ((*utf8 & MASK) == COMP);
|
|
|
|
|
while (utf8[i]) {
|
|
|
|
|
*utf8 = utf8[i];
|
|
|
|
|
utf8++;
|
|
|
|
|
}
|
|
|
|
|
*utf8 = 0;
|
2005-02-06 23:23:49 +00:00
|
|
|
|
editpos--;
|
|
|
|
|
}
|
2003-01-24 14:51:22 +00:00
|
|
|
|
}
|
2005-02-06 23:23:49 +00:00
|
|
|
|
else /* inserts the selected char */
|
|
|
|
|
{
|
2007-03-26 07:52:13 +00:00
|
|
|
|
utf8 = utf8encode(line[x], temptext);
|
2005-12-06 13:27:15 +00:00
|
|
|
|
*utf8 = 0;
|
|
|
|
|
j = strlen(temptext);
|
|
|
|
|
if (len + j < buflen)
|
2005-02-06 23:23:49 +00:00
|
|
|
|
{
|
2005-12-06 13:27:15 +00:00
|
|
|
|
int k = len_utf8;
|
|
|
|
|
for (i = len+j; k >= editpos; i--) {
|
|
|
|
|
text[i] = text[i-j];
|
|
|
|
|
if ((text[i] & MASK) != COMP)
|
|
|
|
|
k--;
|
|
|
|
|
}
|
|
|
|
|
while (j--)
|
|
|
|
|
text[i--] = temptext[j];
|
2005-02-06 23:23:49 +00:00
|
|
|
|
editpos++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-06-11 08:30:13 +00:00
|
|
|
|
if (talk_menus_enabled()) /* voice UI? */
|
2005-02-06 23:23:49 +00:00
|
|
|
|
talk_spell(text, false); /* speak revised text */
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
2003-01-21 14:26:56 +00:00
|
|
|
|
|
2003-01-24 14:51:22 +00:00
|
|
|
|
case BUTTON_NONE:
|
2005-11-20 01:02:14 +00:00
|
|
|
|
gui_syncstatusbar_draw(&statusbars, false);
|
2005-02-06 23:23:49 +00:00
|
|
|
|
redraw = false;
|
2003-01-24 14:51:22 +00:00
|
|
|
|
break;
|
2003-01-21 14:26:56 +00:00
|
|
|
|
|
2005-02-06 23:23:49 +00:00
|
|
|
|
default:
|
|
|
|
|
default_event_handler(button);
|
2003-01-24 14:51:22 +00:00
|
|
|
|
break;
|
2002-12-04 15:04:43 +00:00
|
|
|
|
}
|
2005-02-06 23:23:49 +00:00
|
|
|
|
if (button != BUTTON_NONE)
|
|
|
|
|
lastbutton = button;
|
2002-12-04 15:04:43 +00:00
|
|
|
|
}
|
2005-02-06 23:23:49 +00:00
|
|
|
|
|
2002-12-04 15:04:43 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2005-02-06 23:23:49 +00:00
|
|
|
|
|