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-07 00:56:26 +00:00
|
|
|
|
#include "system.h"
|
2002-12-04 15:04:43 +00:00
|
|
|
|
#include "version.h"
|
|
|
|
|
#include "debug_menu.h"
|
|
|
|
|
#include "sprintf.h"
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include "font.h"
|
2003-03-10 15:09:27 +00:00
|
|
|
|
#include "screens.h"
|
2005-11-20 01:02:14 +00:00
|
|
|
|
#include "statusbar.h"
|
2004-05-21 06:29:55 +00:00
|
|
|
|
#include "talk.h"
|
|
|
|
|
#include "settings.h"
|
2004-07-26 16:06:59 +00:00
|
|
|
|
#include "misc.h"
|
2005-12-06 13:27:15 +00:00
|
|
|
|
#include "rbunicode.h"
|
2005-11-20 01:02:14 +00:00
|
|
|
|
#include "buttonbar.h"
|
2005-12-02 19:41:09 +00:00
|
|
|
|
#include "logf.h"
|
2006-03-29 16:21:42 +00:00
|
|
|
|
#include "icons.h"
|
|
|
|
|
#include "file.h"
|
|
|
|
|
#include "hangul.h"
|
2002-12-04 15:04:43 +00:00
|
|
|
|
|
2006-03-29 16:21:42 +00:00
|
|
|
|
#ifndef O_BINARY
|
|
|
|
|
#define O_BINARY 0
|
|
|
|
|
#endif
|
2005-10-08 07:12:28 +00:00
|
|
|
|
|
2006-03-29 16:21:42 +00:00
|
|
|
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
|
|
|
|
#define BUTTONBAR_HEIGHT 8
|
2005-10-08 07:12:28 +00:00
|
|
|
|
#else
|
2006-03-29 16:21:42 +00:00
|
|
|
|
#define BUTTONBAR_HEIGHT 0
|
|
|
|
|
#endif
|
2005-10-08 07:12:28 +00:00
|
|
|
|
|
2006-03-29 16:21:42 +00:00
|
|
|
|
#if (LCD_WIDTH >= 160) && (LCD_HEIGHT >= 96)
|
|
|
|
|
#define DEFAULT_LINES 8
|
|
|
|
|
#else
|
|
|
|
|
#define DEFAULT_LINES 4
|
2005-10-08 07:12:28 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2006-03-29 16:21:42 +00:00
|
|
|
|
#define DEFAULT_MARGIN 6
|
|
|
|
|
#define KBD_BUF_SIZE 500
|
2004-10-22 17:00:30 +00:00
|
|
|
|
|
2005-06-29 12:47:24 +00:00
|
|
|
|
#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
|
|
|
|
|
(CONFIG_KEYPAD == IRIVER_H300_PAD)
|
2004-11-19 10:54:59 +00:00
|
|
|
|
#define KBD_CURSOR_RIGHT (BUTTON_ON | BUTTON_RIGHT)
|
|
|
|
|
#define KBD_CURSOR_LEFT (BUTTON_ON | BUTTON_LEFT)
|
|
|
|
|
#define KBD_SELECT BUTTON_SELECT
|
2005-10-08 07:12:28 +00:00
|
|
|
|
#define KBD_PAGE_FLIP BUTTON_MODE /* unused */
|
2005-07-22 12:42:50 +00:00
|
|
|
|
#define KBD_DONE_PRE BUTTON_ON
|
|
|
|
|
#define KBD_DONE (BUTTON_ON | BUTTON_REL)
|
2004-11-19 10:54:59 +00:00
|
|
|
|
#define KBD_ABORT BUTTON_OFF
|
|
|
|
|
#define KBD_BACKSPACE BUTTON_REC
|
2005-11-19 03:19:12 +00:00
|
|
|
|
#define KBD_LEFT BUTTON_LEFT
|
|
|
|
|
#define KBD_RIGHT BUTTON_RIGHT
|
|
|
|
|
#define KBD_UP BUTTON_UP
|
|
|
|
|
#define KBD_DOWN BUTTON_DOWN
|
2006-03-29 16:21:42 +00:00
|
|
|
|
#define KBD_MORSE_INPUT (BUTTON_ON | BUTTON_MODE)
|
2005-01-23 01:01:14 +00:00
|
|
|
|
|
2004-11-19 10:54:59 +00:00
|
|
|
|
#elif CONFIG_KEYPAD == RECORDER_PAD
|
2004-10-22 17:00:30 +00:00
|
|
|
|
#define KBD_CURSOR_RIGHT (BUTTON_ON | BUTTON_RIGHT)
|
|
|
|
|
#define KBD_CURSOR_LEFT (BUTTON_ON | BUTTON_LEFT)
|
|
|
|
|
#define KBD_SELECT BUTTON_PLAY
|
|
|
|
|
#define KBD_PAGE_FLIP BUTTON_F1
|
|
|
|
|
#define KBD_DONE BUTTON_F2
|
|
|
|
|
#define KBD_ABORT BUTTON_OFF
|
|
|
|
|
#define KBD_BACKSPACE BUTTON_F3
|
2005-11-19 03:19:12 +00:00
|
|
|
|
#define KBD_LEFT BUTTON_LEFT
|
|
|
|
|
#define KBD_RIGHT BUTTON_RIGHT
|
|
|
|
|
#define KBD_UP BUTTON_UP
|
|
|
|
|
#define KBD_DOWN BUTTON_DOWN
|
2005-01-23 01:01:14 +00:00
|
|
|
|
|
2004-10-22 17:00:30 +00:00
|
|
|
|
#elif CONFIG_KEYPAD == ONDIO_PAD /* restricted Ondio keypad */
|
2004-11-14 23:08:08 +00:00
|
|
|
|
#define KBD_MODES /* Ondio uses 2 modes, picker and line edit */
|
|
|
|
|
#define KBD_SELECT (BUTTON_MENU | BUTTON_REL) /* backspace in line edit */
|
2004-10-22 17:00:30 +00:00
|
|
|
|
#define KBD_SELECT_PRE BUTTON_MENU
|
2004-11-14 23:08:08 +00:00
|
|
|
|
#define KBD_DONE (BUTTON_MENU | BUTTON_REPEAT)
|
|
|
|
|
#define KBD_ABORT BUTTON_OFF
|
2005-11-19 03:19:12 +00:00
|
|
|
|
#define KBD_LEFT BUTTON_LEFT
|
|
|
|
|
#define KBD_RIGHT BUTTON_RIGHT
|
|
|
|
|
#define KBD_UP BUTTON_UP
|
|
|
|
|
#define KBD_DOWN BUTTON_DOWN
|
2005-01-23 01:01:14 +00:00
|
|
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == GMINI100_PAD
|
|
|
|
|
#define KBD_CURSOR_RIGHT (BUTTON_MENU | BUTTON_RIGHT)
|
|
|
|
|
#define KBD_CURSOR_LEFT (BUTTON_MENU | BUTTON_LEFT)
|
|
|
|
|
#define KBD_SELECT (BUTTON_PLAY | BUTTON_REL)
|
|
|
|
|
#define KBD_SELECT_PRE BUTTON_PLAY
|
|
|
|
|
#define KBD_PAGE_FLIP BUTTON_ON
|
|
|
|
|
#define KBD_DONE (BUTTON_PLAY | BUTTON_REPEAT)
|
|
|
|
|
#define KBD_ABORT BUTTON_OFF
|
|
|
|
|
#define KBD_BACKSPACE (BUTTON_MENU | BUTTON_PLAY)
|
2005-11-19 03:19:12 +00:00
|
|
|
|
#define KBD_LEFT BUTTON_LEFT
|
|
|
|
|
#define KBD_RIGHT BUTTON_RIGHT
|
|
|
|
|
#define KBD_UP BUTTON_UP
|
|
|
|
|
#define KBD_DOWN BUTTON_DOWN
|
2005-01-23 01:01:14 +00:00
|
|
|
|
|
2006-02-05 21:18:19 +00:00
|
|
|
|
#elif (CONFIG_KEYPAD == IPOD_3G_PAD) || (CONFIG_KEYPAD == IPOD_4G_PAD)
|
2005-11-12 16:07:17 +00:00
|
|
|
|
|
2005-11-19 03:19:12 +00:00
|
|
|
|
#define KBD_MODES /* iPod uses 2 modes, picker and line edit */
|
|
|
|
|
#define KBD_SELECT (BUTTON_SELECT | BUTTON_REL) /* backspace in line edit */
|
|
|
|
|
#define KBD_SELECT_PRE BUTTON_SELECT
|
|
|
|
|
#define KBD_DONE (BUTTON_SELECT | BUTTON_REPEAT)
|
|
|
|
|
#define KBD_ABORT BUTTON_MENU
|
2005-11-12 16:07:17 +00:00
|
|
|
|
|
2005-11-22 01:15:31 +00:00
|
|
|
|
#define KBD_LEFT BUTTON_LEFT
|
|
|
|
|
#define KBD_RIGHT BUTTON_RIGHT
|
2005-11-19 03:19:12 +00:00
|
|
|
|
#define KBD_UP BUTTON_SCROLL_BACK
|
|
|
|
|
#define KBD_DOWN BUTTON_SCROLL_FWD
|
2005-11-12 16:07:17 +00:00
|
|
|
|
|
2006-01-12 00:35:50 +00:00
|
|
|
|
#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
|
|
|
|
|
|
|
|
|
|
/* TODO: Check keyboard mappings */
|
|
|
|
|
|
|
|
|
|
#define KBD_MODES /* iFP7xx uses 2 modes, picker and line edit */
|
|
|
|
|
#define KBD_SELECT (BUTTON_SELECT | BUTTON_REL) /* backspace in line edit */
|
|
|
|
|
#define KBD_SELECT_PRE BUTTON_SELECT
|
|
|
|
|
#define KBD_DONE BUTTON_MODE
|
|
|
|
|
#define KBD_ABORT BUTTON_PLAY
|
|
|
|
|
#define KBD_LEFT BUTTON_LEFT
|
|
|
|
|
#define KBD_RIGHT BUTTON_RIGHT
|
|
|
|
|
#define KBD_UP BUTTON_UP
|
|
|
|
|
#define KBD_DOWN BUTTON_DOWN
|
|
|
|
|
|
2006-01-18 11:09:06 +00:00
|
|
|
|
#elif CONFIG_KEYPAD == IAUDIO_X5_PAD
|
|
|
|
|
|
|
|
|
|
/* TODO: Check keyboard mappings */
|
|
|
|
|
|
|
|
|
|
#define KBD_MODES /* iAudio X5 uses 2 modes, picker and line edit */
|
2006-02-24 15:06:25 +00:00
|
|
|
|
#define KBD_SELECT (BUTTON_SELECT | BUTTON_REL) /* backspace in line edit */
|
|
|
|
|
#define KBD_SELECT_PRE BUTTON_SELECT
|
2006-01-19 12:44:46 +00:00
|
|
|
|
#define KBD_DONE BUTTON_PLAY
|
|
|
|
|
#define KBD_ABORT BUTTON_REC
|
|
|
|
|
#define KBD_LEFT BUTTON_LEFT
|
|
|
|
|
#define KBD_RIGHT BUTTON_RIGHT
|
|
|
|
|
#define KBD_UP BUTTON_UP
|
|
|
|
|
#define KBD_DOWN BUTTON_DOWN
|
|
|
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == IAUDIO_X5_PAD
|
|
|
|
|
|
|
|
|
|
/* TODO: Check keyboard mappings */
|
|
|
|
|
|
|
|
|
|
#define KBD_MODES /* iAudio X5 uses 2 modes, picker and line edit */
|
|
|
|
|
#define KBD_SELECT (BUTTON_MENU | BUTTON_REL) /* backspace in line edit */
|
|
|
|
|
#define KBD_SELECT_PRE BUTTON_MENU
|
2006-01-18 11:09:06 +00:00
|
|
|
|
#define KBD_DONE BUTTON_PLAY
|
|
|
|
|
#define KBD_ABORT BUTTON_REC
|
|
|
|
|
#define KBD_LEFT BUTTON_LEFT
|
|
|
|
|
#define KBD_RIGHT BUTTON_RIGHT
|
|
|
|
|
#define KBD_UP BUTTON_UP
|
|
|
|
|
#define KBD_DOWN BUTTON_DOWN
|
|
|
|
|
|
2006-02-24 15:42:52 +00:00
|
|
|
|
#elif CONFIG_KEYPAD == GIGABEAT_PAD
|
|
|
|
|
|
|
|
|
|
/* TODO: Check keyboard mappings */
|
|
|
|
|
|
|
|
|
|
#define KBD_MODES /* Gigabeat uses 2 modes, picker and line edit */
|
|
|
|
|
#define KBD_SELECT (BUTTON_MENU | BUTTON_REL) /* backspace in line edit */
|
|
|
|
|
#define KBD_SELECT_PRE BUTTON_MENU
|
|
|
|
|
#define KBD_DONE BUTTON_POWER
|
|
|
|
|
#define KBD_ABORT BUTTON_A
|
|
|
|
|
#define KBD_LEFT BUTTON_LEFT
|
|
|
|
|
#define KBD_RIGHT BUTTON_RIGHT
|
|
|
|
|
#define KBD_UP BUTTON_UP
|
|
|
|
|
#define KBD_DOWN BUTTON_DOWN
|
|
|
|
|
|
2004-10-22 17:00:30 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2006-03-29 16:21:42 +00:00
|
|
|
|
#if (LCD_WIDTH >= 160) && (LCD_HEIGHT >= 96)
|
|
|
|
|
static const unsigned char * default_kbd =
|
|
|
|
|
"ABCDEFG abcdefg !?\" @#$%+'\n"
|
|
|
|
|
"HIJKLMN hijklmn 789 &_()-`\n"
|
|
|
|
|
"OPQRSTU opqrstu 456 §|{}/<\n"
|
|
|
|
|
"VWXYZ., vwxyz.,0123 ~=[]*>\n"
|
|
|
|
|
"ÀÁÂÃÄÅÆ ÌÍÎÏ ÈÉÊË ¢£¤¥¦§©®\n"
|
|
|
|
|
"àáâãäåæ ìíîï èéêë «»°ºª¹²³\n"
|
|
|
|
|
"ÓÒÔÕÖØ ÇÐÞÝß ÙÚÛÜ ¯±×÷¡¿µ·\n"
|
|
|
|
|
"òóôõöø çðþýÿ ùúûü ¼½¾¬¶¨";
|
2005-10-08 07:12:28 +00:00
|
|
|
|
#else
|
2006-03-29 16:21:42 +00:00
|
|
|
|
static const unsigned char * default_kbd =
|
|
|
|
|
"ABCDEFG !?\" @#$%+'\n"
|
|
|
|
|
"HIJKLMN 789 &_()-`\n"
|
|
|
|
|
"OPQRSTU 456 §|{}/<\n"
|
|
|
|
|
"VWXYZ.,0123 ~=[]*>\n"
|
2004-10-22 17:00:30 +00:00
|
|
|
|
|
2006-03-29 16:21:42 +00:00
|
|
|
|
"abcdefg ¢£¤¥¦§©®¬\n"
|
|
|
|
|
"hijklmn «»°ºª¹²³¶\n"
|
|
|
|
|
"opqrstu ¯±×÷¡¿µ·¨\n"
|
|
|
|
|
"vwxyz., ¼½¾ \n"
|
2003-11-17 02:10:09 +00:00
|
|
|
|
|
2006-03-29 16:21:42 +00:00
|
|
|
|
"ÀÁÂÃÄÅÆ ÌÍÎÏ ÈÉÊË\n"
|
|
|
|
|
"àáâãäåæ ìíîï èéêë\n"
|
|
|
|
|
"ÓÒÔÕÖØ ÇÐÞÝß ÙÚÛÜ\n"
|
|
|
|
|
"òóôõöø çðþýÿ ùúûü";
|
2005-10-08 07:12:28 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2006-03-29 16:21:42 +00:00
|
|
|
|
static unsigned short kbd_buf[KBD_BUF_SIZE];
|
|
|
|
|
static bool kbd_loaded = false;
|
|
|
|
|
static int nchars = 0;
|
|
|
|
|
|
|
|
|
|
#ifdef KBD_MORSE_INPUT
|
2005-12-02 19:41:09 +00:00
|
|
|
|
/* FIXME: We should put this to a configuration file. */
|
|
|
|
|
static const char *morse_alphabets =
|
2005-12-21 12:46:50 +00:00
|
|
|
|
"abcdefghijklmnopqrstuvwxyz1234567890,.?-@ ";
|
2005-12-02 19:41:09 +00:00
|
|
|
|
static const unsigned char morse_codes[] = {
|
|
|
|
|
0x05,0x18,0x1a,0x0c,0x02,0x12,0x0e,0x10,0x04,0x17,0x0d,0x14,0x07,
|
|
|
|
|
0x06,0x0f,0x16,0x1d,0x0a,0x08,0x03,0x09,0x11,0x0b,0x19,0x1b,0x1c,
|
2005-12-21 12:46:50 +00:00
|
|
|
|
0x2f,0x27,0x23,0x21,0x20,0x30,0x38,0x3c,0x3e,0x3f,
|
2005-12-04 08:45:24 +00:00
|
|
|
|
0x73,0x55,0x4c,0x61,0x5a,0x80 };
|
2005-12-02 19:41:09 +00:00
|
|
|
|
|
|
|
|
|
static bool morse_mode = false;
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-03-29 16:21:42 +00:00
|
|
|
|
/* Loads a custom keyboard into memory
|
|
|
|
|
call with NULL to reset keyboard */
|
|
|
|
|
int load_kbd(unsigned char* filename)
|
|
|
|
|
{
|
|
|
|
|
int fd, count;
|
|
|
|
|
int i = 0;
|
|
|
|
|
unsigned char buf[4];
|
|
|
|
|
|
|
|
|
|
if (filename == NULL) {
|
|
|
|
|
kbd_loaded = false;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fd = open(filename, O_RDONLY|O_BINARY);
|
|
|
|
|
if (fd < 0)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
while (read(fd, buf, 1) == 1 && i < KBD_BUF_SIZE) {
|
|
|
|
|
/* check how many bytes to read */
|
|
|
|
|
if (buf[0] < 0x80) {
|
|
|
|
|
count = 0;
|
|
|
|
|
} else if (buf[0] < 0xe0) {
|
|
|
|
|
count = 1;
|
|
|
|
|
} else if (buf[0] < 0xf0) {
|
|
|
|
|
count = 2;
|
|
|
|
|
} else if (buf[0] < 0xf5) {
|
|
|
|
|
count = 3;
|
|
|
|
|
} else {
|
|
|
|
|
/* Invalid size. */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (read(fd, &buf[1], count) != count) {
|
|
|
|
|
close(fd);
|
|
|
|
|
kbd_loaded = false;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
utf8decode(buf, &kbd_buf[i]);
|
|
|
|
|
if (kbd_buf[i] != 0xFEFF && kbd_buf[i] != '\n' &&
|
|
|
|
|
kbd_buf[i] != '\r') /*skip BOM & newlines */
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
kbd_loaded = true;
|
|
|
|
|
nchars = i;
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-21 06:29:55 +00:00
|
|
|
|
/* helper function to spell a char if voice UI is enabled */
|
2006-03-29 16:21:42 +00:00
|
|
|
|
static void kbd_spellchar(unsigned short c)
|
2004-05-21 06:29:55 +00:00
|
|
|
|
{
|
2005-02-07 00:56:26 +00:00
|
|
|
|
static char spell_char[2] = "\0\0"; /* store char to pass to talk_spell */
|
2004-05-21 06:29:55 +00:00
|
|
|
|
|
2006-03-29 16:21:42 +00:00
|
|
|
|
if (global_settings.talk_menu && c < 128) /* voice UI? */
|
2004-05-21 06:29:55 +00:00
|
|
|
|
{
|
2006-03-29 16:21:42 +00:00
|
|
|
|
spell_char[0] = (char)c;
|
2005-02-07 00:56:26 +00:00
|
|
|
|
talk_spell(spell_char, false);
|
2004-05-21 06:29:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-29 16:21:42 +00:00
|
|
|
|
void kbd_inschar(unsigned char* text, int buflen, int* editpos, unsigned short ch)
|
|
|
|
|
{
|
|
|
|
|
int i, j, k, len;
|
|
|
|
|
unsigned char tmp[4];
|
|
|
|
|
unsigned char* utf8;
|
|
|
|
|
|
|
|
|
|
len = strlen(text);
|
|
|
|
|
k = utf8length(text);
|
|
|
|
|
utf8 = utf8encode(ch, tmp);
|
|
|
|
|
j = (long)utf8 - (long)tmp;
|
|
|
|
|
|
|
|
|
|
if (len + j < buflen)
|
|
|
|
|
{
|
|
|
|
|
for (i = len+j; k >= *editpos; i--) {
|
|
|
|
|
text[i] = text[i-j];
|
|
|
|
|
if ((text[i] & MASK) != COMP)
|
|
|
|
|
k--;
|
|
|
|
|
}
|
|
|
|
|
while (j--)
|
|
|
|
|
text[i--] = tmp[j];
|
|
|
|
|
(*editpos)++;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void kbd_delchar(unsigned char* text, int* editpos)
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
unsigned char* utf8;
|
|
|
|
|
|
|
|
|
|
if (*editpos > 0)
|
|
|
|
|
{
|
|
|
|
|
utf8 = text + utf8seek(text, *editpos);
|
|
|
|
|
do {
|
|
|
|
|
i++;
|
|
|
|
|
utf8--;
|
|
|
|
|
} while ((*utf8 & MASK) == COMP);
|
|
|
|
|
while (utf8[i]) {
|
|
|
|
|
*utf8 = utf8[i];
|
|
|
|
|
utf8++;
|
|
|
|
|
}
|
|
|
|
|
*utf8 = 0;
|
|
|
|
|
(*editpos)--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-04 15:04:43 +00:00
|
|
|
|
int kbd_input(char* text, int buflen)
|
|
|
|
|
{
|
2005-12-04 07:37:24 +00:00
|
|
|
|
bool done = false;
|
2002-12-04 15:04:43 +00:00
|
|
|
|
int page = 0;
|
2006-03-29 16:21:42 +00:00
|
|
|
|
int font_w = 0, font_h = 0, text_w = 0;
|
|
|
|
|
int i = 0, j, k, w;
|
2002-12-04 15:04:43 +00:00
|
|
|
|
int x = 0, y = 0;
|
2006-03-29 16:21:42 +00:00
|
|
|
|
int main_x, main_y, max_chars, max_chars_text;
|
|
|
|
|
int len_utf8, c = 0;
|
2005-02-07 00:56:26 +00:00
|
|
|
|
int editpos, curpos, leftpos;
|
2006-03-29 16:21:42 +00:00
|
|
|
|
int lines, pages, keyboard_margin;
|
|
|
|
|
int curfont;
|
|
|
|
|
int statusbar_size = global_settings.statusbar ? STATUSBAR_HEIGHT : 0;
|
|
|
|
|
unsigned short ch, tmp, hlead = 0, hvowel = 0, htail = 0;
|
|
|
|
|
bool hangul = false;
|
2003-11-17 02:10:09 +00:00
|
|
|
|
bool redraw = true;
|
2005-12-06 13:27:15 +00:00
|
|
|
|
unsigned char *utf8;
|
2006-03-29 16:21:42 +00:00
|
|
|
|
const unsigned char *p;
|
|
|
|
|
#ifdef KBD_MORSE_INPUT
|
2005-12-02 19:41:09 +00:00
|
|
|
|
bool morse_reading = false;
|
|
|
|
|
unsigned char morse_code = 0;
|
2006-03-29 16:21:42 +00:00
|
|
|
|
int morse_tick = 0, morse_len, old_main_y;
|
2005-12-02 19:41:09 +00:00
|
|
|
|
char buf[2];
|
|
|
|
|
#endif
|
2004-11-14 23:08:08 +00:00
|
|
|
|
#ifdef KBD_MODES
|
|
|
|
|
bool line_edit = false;
|
|
|
|
|
#endif
|
2002-12-04 15:04:43 +00:00
|
|
|
|
|
2003-03-10 15:09:27 +00:00
|
|
|
|
char outline[256];
|
2006-03-29 16:21:42 +00:00
|
|
|
|
struct font* font;
|
2004-10-22 17:00:30 +00:00
|
|
|
|
int button, lastbutton = 0;
|
2005-11-20 01:02:14 +00:00
|
|
|
|
#ifdef HAS_BUTTONBAR
|
|
|
|
|
struct gui_buttonbar buttonbar;
|
2006-03-11 22:31:53 +00:00
|
|
|
|
bool buttonbar_config = global_settings.buttonbar;
|
|
|
|
|
global_settings.buttonbar = true;
|
2005-11-20 01:02:14 +00:00
|
|
|
|
gui_buttonbar_init(&buttonbar);
|
|
|
|
|
gui_buttonbar_set_display(&buttonbar, &(screens[SCREEN_MAIN]) );
|
|
|
|
|
#endif
|
2006-03-29 16:21:42 +00:00
|
|
|
|
|
|
|
|
|
if (!kbd_loaded) {
|
|
|
|
|
curfont = FONT_SYSFIXED;
|
|
|
|
|
p = default_kbd;
|
|
|
|
|
while (*p != 0) {
|
|
|
|
|
p = utf8decode(p, &kbd_buf[i]);
|
|
|
|
|
if (kbd_buf[i] == '\n')
|
|
|
|
|
while (i % (LCD_WIDTH/6))
|
|
|
|
|
kbd_buf[i++] = ' ';
|
|
|
|
|
else
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
nchars = i;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
curfont = FONT_UI;
|
|
|
|
|
|
|
|
|
|
font = font_get(curfont);
|
2002-12-04 15:04:43 +00:00
|
|
|
|
font_h = font->height;
|
|
|
|
|
|
2006-03-29 16:21:42 +00:00
|
|
|
|
/* check if FONT_UI fits the screen */
|
|
|
|
|
if (2*font_h+3+statusbar_size + BUTTONBAR_HEIGHT > LCD_HEIGHT) {
|
|
|
|
|
font = font_get(FONT_SYSFIXED);
|
|
|
|
|
font_h = font->height;
|
|
|
|
|
curfont = FONT_SYSFIXED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lcd_setfont(curfont);
|
|
|
|
|
|
|
|
|
|
/* find max width of keyboard glyphs */
|
|
|
|
|
for (i=0; i<nchars; i++) {
|
|
|
|
|
w = font_get_width(font, kbd_buf[i]);
|
|
|
|
|
if (w > font_w)
|
|
|
|
|
font_w = w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* find max width for text string */
|
|
|
|
|
utf8 = text;
|
|
|
|
|
text_w = font_w;
|
|
|
|
|
while (*utf8) {
|
|
|
|
|
utf8 = (unsigned char*)utf8decode(utf8, &ch);
|
|
|
|
|
w = font_get_width(font, ch);
|
|
|
|
|
if (w > text_w)
|
|
|
|
|
text_w = w;
|
|
|
|
|
}
|
|
|
|
|
max_chars_text = LCD_WIDTH / text_w - 2;
|
|
|
|
|
|
|
|
|
|
/* calculate keyboard grid size */
|
|
|
|
|
max_chars = LCD_WIDTH / font_w;
|
|
|
|
|
if (!kbd_loaded) {
|
|
|
|
|
lines = DEFAULT_LINES;
|
|
|
|
|
keyboard_margin = DEFAULT_MARGIN;
|
|
|
|
|
} else {
|
|
|
|
|
lines = (LCD_HEIGHT - BUTTONBAR_HEIGHT - statusbar_size) / font_h - 1;
|
|
|
|
|
keyboard_margin = LCD_HEIGHT - BUTTONBAR_HEIGHT - statusbar_size - (lines+1)*font_h;
|
|
|
|
|
if (keyboard_margin < 3) {
|
|
|
|
|
lines--;
|
|
|
|
|
keyboard_margin += font_h;
|
|
|
|
|
}
|
|
|
|
|
if (keyboard_margin > 6)
|
|
|
|
|
keyboard_margin = 6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pages = (nchars + (lines*max_chars-1))/(lines*max_chars);
|
|
|
|
|
if (pages == 1 && kbd_loaded)
|
|
|
|
|
lines = (nchars + max_chars - 1) / max_chars;
|
|
|
|
|
|
|
|
|
|
main_y = font_h*lines + keyboard_margin + statusbar_size;
|
|
|
|
|
main_x = 0;
|
|
|
|
|
keyboard_margin -= keyboard_margin/2;
|
|
|
|
|
|
|
|
|
|
#ifdef KBD_MORSE_INPUT
|
|
|
|
|
old_main_y = main_y;
|
2005-12-04 08:45:24 +00:00
|
|
|
|
if (morse_mode)
|
|
|
|
|
main_y = LCD_HEIGHT - font_h;
|
|
|
|
|
#endif
|
2002-12-04 15:04:43 +00:00
|
|
|
|
|
2005-12-06 13:27:15 +00:00
|
|
|
|
editpos = utf8length(text);
|
2002-12-04 15:04:43 +00:00
|
|
|
|
|
2004-05-21 06:29:55 +00:00
|
|
|
|
if (global_settings.talk_menu) /* voice UI? */
|
2005-12-02 19:41:09 +00:00
|
|
|
|
talk_spell(text, true); /* spell initial text */
|
2004-05-21 06:29:55 +00:00
|
|
|
|
|
2002-12-04 15:04:43 +00:00
|
|
|
|
while(!done)
|
|
|
|
|
{
|
2005-12-06 13:27:15 +00:00
|
|
|
|
len_utf8 = utf8length(text);
|
2005-12-02 19:41:09 +00:00
|
|
|
|
|
2005-12-06 13:27:15 +00:00
|
|
|
|
if(redraw)
|
2003-03-10 15:09:27 +00:00
|
|
|
|
{
|
2003-11-17 02:10:09 +00:00
|
|
|
|
lcd_clear_display();
|
2005-12-06 13:27:15 +00:00
|
|
|
|
|
2006-03-29 16:21:42 +00:00
|
|
|
|
#ifdef KBD_MORSE_INPUT
|
2005-12-02 19:41:09 +00:00
|
|
|
|
if (morse_mode)
|
|
|
|
|
{
|
2006-03-29 16:21:42 +00:00
|
|
|
|
lcd_setfont(FONT_SYSFIXED); /* Draw morse code screen with sysfont */
|
|
|
|
|
w = 6; /* sysfixed font width */
|
2005-12-02 19:41:09 +00:00
|
|
|
|
x = 0;
|
2006-03-29 16:21:42 +00:00
|
|
|
|
y = statusbar_size;
|
2005-12-02 19:41:09 +00:00
|
|
|
|
buf[1] = '\0';
|
|
|
|
|
/* Draw morse code table with code descriptions. */
|
|
|
|
|
for (i = 0; morse_alphabets[i] != '\0'; i++)
|
|
|
|
|
{
|
|
|
|
|
buf[0] = morse_alphabets[i];
|
|
|
|
|
lcd_putsxy(x, y, buf);
|
|
|
|
|
|
|
|
|
|
for (j = 0; (morse_codes[i] >> j) > 0x01; j++) ;
|
|
|
|
|
morse_len = j;
|
|
|
|
|
|
2006-03-29 16:21:42 +00:00
|
|
|
|
x += w + 3;
|
2005-12-02 19:41:09 +00:00
|
|
|
|
for (j = 0; j < morse_len; j++)
|
|
|
|
|
{
|
|
|
|
|
if ((morse_codes[i] >> (morse_len-j-1)) & 0x01)
|
|
|
|
|
lcd_fillrect(x + j*4, y + 2, 3, 4);
|
|
|
|
|
else
|
|
|
|
|
lcd_fillrect(x + j*4, y + 3, 1, 2);
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-29 16:21:42 +00:00
|
|
|
|
x += w * 5 - 3;
|
|
|
|
|
if (x >= LCD_WIDTH - (w*6))
|
2005-12-02 19:41:09 +00:00
|
|
|
|
{
|
|
|
|
|
x = 0;
|
2006-03-29 16:21:42 +00:00
|
|
|
|
y += 8; /* sysfixed font height */
|
2005-12-02 19:41:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
/* draw page */
|
2006-03-29 16:21:42 +00:00
|
|
|
|
lcd_setfont(curfont);
|
|
|
|
|
k = page*max_chars*lines;
|
|
|
|
|
for (i=j=0; j < lines && k < nchars; k++) {
|
|
|
|
|
utf8 = utf8encode(kbd_buf[k], outline);
|
|
|
|
|
*utf8 = 0;
|
|
|
|
|
lcd_getstringsize(outline, &w, NULL);
|
|
|
|
|
lcd_putsxy(i*font_w + (font_w-w)/2, j*font_h + statusbar_size, outline);
|
|
|
|
|
if (++i == max_chars) {
|
|
|
|
|
i = 0;
|
|
|
|
|
j++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-12-02 19:41:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-11-17 02:10:09 +00:00
|
|
|
|
/* separator */
|
2006-03-29 16:21:42 +00:00
|
|
|
|
lcd_hline(0, LCD_WIDTH - 1, main_y - keyboard_margin);
|
2005-12-06 13:27:15 +00:00
|
|
|
|
|
2003-11-17 02:10:09 +00:00
|
|
|
|
/* write out the text */
|
2006-03-29 16:21:42 +00:00
|
|
|
|
lcd_setfont(curfont);
|
|
|
|
|
i=j=0;
|
|
|
|
|
curpos = MIN(editpos, max_chars_text - MIN(len_utf8 - editpos, 2));
|
2005-02-07 00:56:26 +00:00
|
|
|
|
leftpos = editpos - curpos;
|
2005-12-06 13:27:15 +00:00
|
|
|
|
utf8 = text + utf8seek(text, leftpos);
|
2006-03-29 16:21:42 +00:00
|
|
|
|
|
|
|
|
|
while (*utf8 && i < max_chars_text) {
|
2005-12-06 13:27:15 +00:00
|
|
|
|
outline[j++] = *utf8++;
|
2006-03-29 16:21:42 +00:00
|
|
|
|
if ((*utf8 & MASK) != COMP) {
|
|
|
|
|
outline[j] = 0;
|
|
|
|
|
j=0;
|
2005-12-06 13:27:15 +00:00
|
|
|
|
i++;
|
2006-03-29 16:21:42 +00:00
|
|
|
|
lcd_getstringsize(outline, &w, NULL);
|
|
|
|
|
lcd_putsxy(i*text_w + (text_w-w)/2, main_y, outline);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (leftpos) {
|
|
|
|
|
lcd_getstringsize("<", &w, NULL);
|
|
|
|
|
lcd_putsxy(text_w - w, main_y, "<");
|
2005-12-06 13:27:15 +00:00
|
|
|
|
}
|
2006-03-29 16:21:42 +00:00
|
|
|
|
if (len_utf8 - leftpos > max_chars_text)
|
|
|
|
|
lcd_putsxy(LCD_WIDTH - text_w, main_y, ">");
|
|
|
|
|
|
2003-11-17 02:10:09 +00:00
|
|
|
|
/* cursor */
|
2006-03-29 16:21:42 +00:00
|
|
|
|
i = (curpos + 1) * text_w;
|
2005-06-25 00:28:09 +00:00
|
|
|
|
lcd_vline(i, main_y, main_y + font_h);
|
2006-03-29 16:21:42 +00:00
|
|
|
|
if (hangul) /* draw underbar */
|
|
|
|
|
lcd_hline(curpos*text_w, (curpos+1)*text_w, main_y+font_h-1);
|
|
|
|
|
|
2005-11-20 01:02:14 +00:00
|
|
|
|
#ifdef HAS_BUTTONBAR
|
2003-11-17 02:10:09 +00:00
|
|
|
|
/* draw the status bar */
|
2005-11-20 01:02:14 +00:00
|
|
|
|
gui_buttonbar_set(&buttonbar, "Shift", "OK", "Del");
|
|
|
|
|
gui_buttonbar_draw(&buttonbar);
|
2005-02-07 00:56:26 +00:00
|
|
|
|
#endif
|
2006-03-29 16:21:42 +00:00
|
|
|
|
|
2004-11-14 23:08:08 +00:00
|
|
|
|
#ifdef KBD_MODES
|
|
|
|
|
if (!line_edit)
|
|
|
|
|
#endif
|
2005-06-24 22:33:21 +00:00
|
|
|
|
{
|
2004-11-14 23:08:08 +00:00
|
|
|
|
/* highlight the key that has focus */
|
2005-06-24 22:33:21 +00:00
|
|
|
|
lcd_set_drawmode(DRMODE_COMPLEMENT);
|
2006-03-29 16:21:42 +00:00
|
|
|
|
lcd_fillrect(font_w * x, statusbar_size + font_h * y, font_w, font_h);
|
2005-06-24 22:33:21 +00:00
|
|
|
|
lcd_set_drawmode(DRMODE_SOLID);
|
|
|
|
|
}
|
2004-11-14 23:08:08 +00:00
|
|
|
|
|
2005-11-20 01:02:14 +00:00
|
|
|
|
gui_syncstatusbar_draw(&statusbars, true);
|
2003-11-17 02:10:09 +00:00
|
|
|
|
lcd_update();
|
|
|
|
|
}
|
2002-12-04 15:04:43 +00:00
|
|
|
|
|
2003-11-17 02:10:09 +00:00
|
|
|
|
/* The default action is to redraw */
|
|
|
|
|
redraw = true;
|
2004-07-26 16:06:59 +00:00
|
|
|
|
|
|
|
|
|
button = button_get_w_tmo(HZ/2);
|
2006-03-29 16:21:42 +00:00
|
|
|
|
#ifdef KBD_MORSE_INPUT
|
2005-12-04 08:45:24 +00:00
|
|
|
|
if (morse_mode)
|
|
|
|
|
{
|
|
|
|
|
/* Remap some buttons for morse mode. */
|
|
|
|
|
if (button == KBD_LEFT || button == (KBD_LEFT | BUTTON_REPEAT))
|
|
|
|
|
button = KBD_CURSOR_LEFT;
|
|
|
|
|
if (button == KBD_RIGHT || button == (KBD_RIGHT | BUTTON_REPEAT))
|
|
|
|
|
button = KBD_CURSOR_RIGHT;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2005-12-02 19:41:09 +00:00
|
|
|
|
|
2004-07-26 16:06:59 +00:00
|
|
|
|
switch ( button ) {
|
2002-12-04 15:04:43 +00:00
|
|
|
|
|
2004-10-22 17:00:30 +00:00
|
|
|
|
case KBD_ABORT:
|
2003-01-15 13:48:54 +00:00
|
|
|
|
lcd_setfont(FONT_UI);
|
2006-03-11 22:31:53 +00:00
|
|
|
|
#ifdef HAS_BUTTONBAR
|
|
|
|
|
global_settings.buttonbar=buttonbar_config;
|
|
|
|
|
#endif
|
2003-01-15 13:48:54 +00:00
|
|
|
|
return -1;
|
|
|
|
|
break;
|
|
|
|
|
|
2005-12-02 19:41:09 +00:00
|
|
|
|
#if defined(KBD_PAGE_FLIP)
|
|
|
|
|
case KBD_PAGE_FLIP:
|
2006-03-29 16:21:42 +00:00
|
|
|
|
#ifdef KBD_MORSE_INPUT
|
2005-12-02 19:41:09 +00:00
|
|
|
|
if (morse_mode)
|
2006-03-29 16:21:42 +00:00
|
|
|
|
break;
|
2005-12-02 19:41:09 +00:00
|
|
|
|
#endif
|
2006-03-29 16:21:42 +00:00
|
|
|
|
if (++page == pages)
|
2003-01-15 13:48:54 +00:00
|
|
|
|
page = 0;
|
2006-03-29 16:21:42 +00:00
|
|
|
|
k = (page*lines + y)*max_chars + x;
|
|
|
|
|
kbd_spellchar(kbd_buf[k]);
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
2004-11-14 23:08:08 +00:00
|
|
|
|
#endif
|
2003-01-15 13:48:54 +00:00
|
|
|
|
|
2006-03-29 16:21:42 +00:00
|
|
|
|
#ifdef KBD_MORSE_INPUT
|
|
|
|
|
case KBD_MORSE_INPUT:
|
|
|
|
|
morse_mode = !morse_mode;
|
|
|
|
|
x = y = page = 0;
|
|
|
|
|
if (morse_mode) {
|
|
|
|
|
old_main_y = main_y;
|
|
|
|
|
main_y = LCD_HEIGHT - font_h;
|
|
|
|
|
} else
|
|
|
|
|
main_y = old_main_y;
|
|
|
|
|
/* FIXME: We should talk something like Morse mode.. */
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
2005-11-19 03:19:12 +00:00
|
|
|
|
case KBD_RIGHT:
|
|
|
|
|
case KBD_RIGHT | BUTTON_REPEAT:
|
2006-03-29 16:21:42 +00:00
|
|
|
|
#ifdef KBD_MORSE_INPUT
|
2005-12-02 19:41:09 +00:00
|
|
|
|
if (morse_mode)
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
2004-11-14 23:08:08 +00:00
|
|
|
|
#ifdef KBD_MODES
|
|
|
|
|
if (line_edit) /* right doubles as cursor_right in line_edit */
|
|
|
|
|
{
|
2006-03-31 13:59:04 +00:00
|
|
|
|
if (hangul)
|
2006-03-29 16:21:42 +00:00
|
|
|
|
hangul = false;
|
2005-12-06 13:27:15 +00:00
|
|
|
|
if (editpos < len_utf8)
|
2005-02-07 00:56:26 +00:00
|
|
|
|
{
|
|
|
|
|
editpos++;
|
2005-12-06 13:27:15 +00:00
|
|
|
|
c = utf8seek(text, editpos);
|
|
|
|
|
kbd_spellchar(text[c]);
|
2005-02-07 00:56:26 +00:00
|
|
|
|
}
|
2004-11-14 23:08:08 +00:00
|
|
|
|
}
|
2003-03-10 15:09:27 +00:00
|
|
|
|
else
|
2004-11-14 23:08:08 +00:00
|
|
|
|
#endif
|
2005-08-24 06:48:39 +00:00
|
|
|
|
{
|
2006-03-29 16:21:42 +00:00
|
|
|
|
if (++x == max_chars) {
|
2004-11-14 23:08:08 +00:00
|
|
|
|
x = 0;
|
2006-03-29 16:21:42 +00:00
|
|
|
|
#if !defined(KBD_PAGE_FLIP)
|
2005-10-08 07:12:28 +00:00
|
|
|
|
/* no dedicated flip key - flip page on wrap */
|
2006-03-29 16:21:42 +00:00
|
|
|
|
if (++page == pages)
|
2004-11-14 23:08:08 +00:00
|
|
|
|
page = 0;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2006-03-29 16:21:42 +00:00
|
|
|
|
k = (page*lines + y)*max_chars + x;
|
|
|
|
|
kbd_spellchar(kbd_buf[k]);
|
2004-11-14 23:08:08 +00:00
|
|
|
|
}
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2005-11-19 03:19:12 +00:00
|
|
|
|
case KBD_LEFT:
|
|
|
|
|
case KBD_LEFT | BUTTON_REPEAT:
|
2006-03-29 16:21:42 +00:00
|
|
|
|
#ifdef KBD_MORSE_INPUT
|
2005-12-02 19:41:09 +00:00
|
|
|
|
if (morse_mode)
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
2004-11-14 23:08:08 +00:00
|
|
|
|
#ifdef KBD_MODES
|
|
|
|
|
if (line_edit) /* left doubles as cursor_left in line_edit */
|
|
|
|
|
{
|
2006-03-31 13:59:04 +00:00
|
|
|
|
if (hangul)
|
2006-03-29 16:21:42 +00:00
|
|
|
|
hangul = false;
|
2005-02-07 00:56:26 +00:00
|
|
|
|
if (editpos)
|
|
|
|
|
{
|
|
|
|
|
editpos--;
|
2005-12-06 13:27:15 +00:00
|
|
|
|
c = utf8seek(text, editpos);
|
|
|
|
|
kbd_spellchar(text[c]);
|
2005-02-07 00:56:26 +00:00
|
|
|
|
}
|
2004-11-14 23:08:08 +00:00
|
|
|
|
}
|
2003-01-15 13:48:54 +00:00
|
|
|
|
else
|
2004-11-14 23:08:08 +00:00
|
|
|
|
#endif
|
2006-03-29 16:21:42 +00:00
|
|
|
|
{
|
2004-11-14 23:08:08 +00:00
|
|
|
|
if (x)
|
|
|
|
|
x--;
|
|
|
|
|
else
|
|
|
|
|
{
|
2006-03-29 16:21:42 +00:00
|
|
|
|
#if !defined(KBD_PAGE_FLIP)
|
2005-10-08 07:12:28 +00:00
|
|
|
|
/* no dedicated flip key - flip page on wrap */
|
2004-11-14 23:08:08 +00:00
|
|
|
|
if (--page < 0)
|
2006-03-29 16:21:42 +00:00
|
|
|
|
page = (pages-1);
|
2004-11-14 23:08:08 +00:00
|
|
|
|
#endif
|
2006-03-29 16:21:42 +00:00
|
|
|
|
x = max_chars - 1;
|
2004-11-14 23:08:08 +00:00
|
|
|
|
}
|
2006-03-29 16:21:42 +00:00
|
|
|
|
k = (page*lines + y)*max_chars + x;
|
|
|
|
|
kbd_spellchar(kbd_buf[k]);
|
2004-11-14 23:08:08 +00:00
|
|
|
|
}
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2005-11-19 03:19:12 +00:00
|
|
|
|
case KBD_DOWN:
|
|
|
|
|
case KBD_DOWN | BUTTON_REPEAT:
|
2006-03-29 16:21:42 +00:00
|
|
|
|
#ifdef KBD_MORSE_INPUT
|
2005-12-02 19:41:09 +00:00
|
|
|
|
if (morse_mode)
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
2004-11-14 23:08:08 +00:00
|
|
|
|
#ifdef KBD_MODES
|
|
|
|
|
if (line_edit)
|
|
|
|
|
{
|
|
|
|
|
y = 0;
|
|
|
|
|
line_edit = false;
|
|
|
|
|
}
|
2003-01-15 13:48:54 +00:00
|
|
|
|
else
|
2004-11-14 23:08:08 +00:00
|
|
|
|
{
|
|
|
|
|
#endif
|
2006-03-29 16:21:42 +00:00
|
|
|
|
if (y < lines - 1)
|
2004-11-14 23:08:08 +00:00
|
|
|
|
y++;
|
|
|
|
|
else
|
|
|
|
|
#ifndef KBD_MODES
|
|
|
|
|
y=0;
|
|
|
|
|
#else
|
|
|
|
|
line_edit = true;
|
|
|
|
|
}
|
|
|
|
|
if (!line_edit)
|
|
|
|
|
#endif
|
2006-03-29 16:21:42 +00:00
|
|
|
|
{
|
|
|
|
|
k = (page*lines + y)*max_chars + x;
|
|
|
|
|
kbd_spellchar(kbd_buf[k]);
|
|
|
|
|
}
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2005-11-19 03:19:12 +00:00
|
|
|
|
case KBD_UP:
|
|
|
|
|
case KBD_UP | BUTTON_REPEAT:
|
2006-03-29 16:21:42 +00:00
|
|
|
|
#ifdef KBD_MORSE_INPUT
|
2005-12-02 19:41:09 +00:00
|
|
|
|
if (morse_mode)
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
2004-11-14 23:08:08 +00:00
|
|
|
|
#ifdef KBD_MODES
|
|
|
|
|
if (line_edit)
|
|
|
|
|
{
|
2006-03-29 16:21:42 +00:00
|
|
|
|
y = lines - 1;
|
2004-11-14 23:08:08 +00:00
|
|
|
|
line_edit = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
2003-03-10 15:09:27 +00:00
|
|
|
|
{
|
2004-11-14 23:08:08 +00:00
|
|
|
|
#endif
|
|
|
|
|
if (y)
|
|
|
|
|
y--;
|
|
|
|
|
else
|
|
|
|
|
#ifndef KBD_MODES
|
2006-03-29 16:21:42 +00:00
|
|
|
|
y = lines - 1;
|
2004-11-14 23:08:08 +00:00
|
|
|
|
#else
|
|
|
|
|
line_edit = true;
|
2003-03-10 15:09:27 +00:00
|
|
|
|
}
|
2004-11-14 23:08:08 +00:00
|
|
|
|
if (!line_edit)
|
|
|
|
|
#endif
|
2006-03-29 16:21:42 +00:00
|
|
|
|
{
|
|
|
|
|
k = (page*lines + y)*max_chars + x;
|
|
|
|
|
kbd_spellchar(kbd_buf[k]);
|
|
|
|
|
}
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2004-10-22 17:00:30 +00:00
|
|
|
|
case KBD_DONE:
|
|
|
|
|
/* accepts what was entered and continues */
|
2005-07-22 12:42:50 +00:00
|
|
|
|
#ifdef KBD_DONE_PRE
|
|
|
|
|
if (lastbutton != KBD_DONE_PRE)
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
2003-01-15 13:48:54 +00:00
|
|
|
|
done = true;
|
|
|
|
|
break;
|
|
|
|
|
|
2006-03-29 16:21:42 +00:00
|
|
|
|
#ifdef KBD_MORSE_INPUT
|
2005-12-02 19:41:09 +00:00
|
|
|
|
case KBD_SELECT | BUTTON_REL:
|
|
|
|
|
if (morse_mode && morse_reading)
|
|
|
|
|
{
|
|
|
|
|
morse_code <<= 1;
|
|
|
|
|
if ((current_tick - morse_tick) > HZ/5)
|
|
|
|
|
morse_code |= 0x01;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-10-22 17:00:30 +00:00
|
|
|
|
case KBD_SELECT:
|
2006-03-29 16:21:42 +00:00
|
|
|
|
#ifdef KBD_MORSE_INPUT
|
2005-12-02 19:41:09 +00:00
|
|
|
|
if (morse_mode)
|
|
|
|
|
{
|
|
|
|
|
morse_tick = current_tick;
|
|
|
|
|
if (!morse_reading)
|
|
|
|
|
{
|
|
|
|
|
morse_reading = true;
|
|
|
|
|
morse_code = 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-10-22 17:00:30 +00:00
|
|
|
|
/* inserts the selected char */
|
|
|
|
|
#ifdef KBD_SELECT_PRE
|
|
|
|
|
if (lastbutton != KBD_SELECT_PRE)
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
2004-11-14 23:08:08 +00:00
|
|
|
|
#ifdef KBD_MODES
|
2006-03-29 16:21:42 +00:00
|
|
|
|
if (line_edit) { /* select doubles as backspace in line_edit */
|
|
|
|
|
if (hangul) {
|
2006-03-31 13:59:04 +00:00
|
|
|
|
if (htail)
|
2006-03-29 16:21:42 +00:00
|
|
|
|
htail = 0;
|
2006-03-31 13:59:04 +00:00
|
|
|
|
else if (hvowel)
|
2006-03-29 16:21:42 +00:00
|
|
|
|
hvowel = 0;
|
2006-03-31 13:59:04 +00:00
|
|
|
|
else
|
2006-03-29 16:21:42 +00:00
|
|
|
|
hangul = false;
|
|
|
|
|
}
|
|
|
|
|
kbd_delchar(text, &editpos);
|
|
|
|
|
if (hangul) {
|
2006-03-31 13:59:04 +00:00
|
|
|
|
if (hvowel)
|
2006-03-29 16:21:42 +00:00
|
|
|
|
ch = hangul_join(hlead, hvowel, htail);
|
|
|
|
|
else
|
|
|
|
|
ch = hlead;
|
|
|
|
|
kbd_inschar(text, buflen, &editpos, ch);
|
2003-03-10 15:09:27 +00:00
|
|
|
|
}
|
2004-11-14 23:08:08 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
{
|
2006-03-29 16:21:42 +00:00
|
|
|
|
/* find input char */
|
|
|
|
|
k = (page*lines + y)*max_chars + x;
|
|
|
|
|
if (k < nchars)
|
|
|
|
|
ch = kbd_buf[k];
|
|
|
|
|
else
|
|
|
|
|
ch = ' ';
|
|
|
|
|
|
|
|
|
|
/* check for hangul input */
|
|
|
|
|
if (ch >= 0x3131 && ch <= 0x3163) {
|
2006-03-31 13:59:04 +00:00
|
|
|
|
if (!hangul) {
|
|
|
|
|
hlead=hvowel=htail=0;
|
|
|
|
|
hangul = true;
|
|
|
|
|
}
|
|
|
|
|
if (!hvowel)
|
|
|
|
|
hvowel = ch;
|
|
|
|
|
else if (!htail)
|
|
|
|
|
htail = ch;
|
|
|
|
|
else { /* previous hangul complete */
|
|
|
|
|
/* check whether tail is actually lead of next char */
|
|
|
|
|
if ((tmp = hangul_join(htail, ch, 0)) != 0xfffd) {
|
|
|
|
|
tmp = hangul_join(hlead, hvowel, 0);
|
2006-03-29 16:21:42 +00:00
|
|
|
|
kbd_delchar(text, &editpos);
|
2006-03-31 13:59:04 +00:00
|
|
|
|
kbd_inschar(text, buflen, &editpos, tmp);
|
|
|
|
|
/* insert dummy char */
|
|
|
|
|
kbd_inschar(text, buflen, &editpos, ' ');
|
|
|
|
|
hlead = htail;
|
|
|
|
|
hvowel = ch;
|
|
|
|
|
htail = 0;
|
|
|
|
|
} else {
|
|
|
|
|
hvowel=htail=0;
|
|
|
|
|
hlead = ch;
|
2006-03-29 16:21:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2006-03-31 13:59:04 +00:00
|
|
|
|
/* combine into hangul */
|
|
|
|
|
if ((tmp = hangul_join(hlead, hvowel, htail)) != 0xfffd) {
|
2006-03-29 16:21:42 +00:00
|
|
|
|
kbd_delchar(text, &editpos);
|
2006-03-31 13:59:04 +00:00
|
|
|
|
ch = tmp;
|
|
|
|
|
} else {
|
|
|
|
|
hvowel=htail=0;
|
|
|
|
|
hlead = ch;
|
2006-03-29 16:21:42 +00:00
|
|
|
|
}
|
2006-03-31 13:59:04 +00:00
|
|
|
|
} else {
|
2006-03-29 16:21:42 +00:00
|
|
|
|
hangul = false;
|
2003-03-10 15:09:27 +00:00
|
|
|
|
}
|
2006-03-29 16:21:42 +00:00
|
|
|
|
/* insert char */
|
|
|
|
|
kbd_inschar(text, buflen, &editpos, ch);
|
2004-11-14 23:08:08 +00:00
|
|
|
|
}
|
2005-02-07 00:56:26 +00:00
|
|
|
|
if (global_settings.talk_menu) /* voice UI? */
|
|
|
|
|
talk_spell(text, false); /* speak revised text */
|
2004-11-14 23:08:08 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
#ifndef KBD_MODES
|
|
|
|
|
case KBD_BACKSPACE:
|
|
|
|
|
case KBD_BACKSPACE | BUTTON_REPEAT:
|
2006-03-29 16:21:42 +00:00
|
|
|
|
if (hangul) {
|
2006-03-31 13:59:04 +00:00
|
|
|
|
if (htail)
|
2006-03-29 16:21:42 +00:00
|
|
|
|
htail = 0;
|
2006-03-31 13:59:04 +00:00
|
|
|
|
else if (hvowel)
|
2006-03-29 16:21:42 +00:00
|
|
|
|
hvowel = 0;
|
2006-03-31 13:59:04 +00:00
|
|
|
|
else
|
2006-03-29 16:21:42 +00:00
|
|
|
|
hangul = false;
|
|
|
|
|
}
|
|
|
|
|
kbd_delchar(text, &editpos);
|
|
|
|
|
if (hangul) {
|
2006-03-31 13:59:04 +00:00
|
|
|
|
if (hvowel)
|
2006-03-29 16:21:42 +00:00
|
|
|
|
ch = hangul_join(hlead, hvowel, htail);
|
|
|
|
|
else
|
|
|
|
|
ch = hlead;
|
|
|
|
|
kbd_inschar(text, buflen, &editpos, ch);
|
2003-01-15 13:48:54 +00:00
|
|
|
|
}
|
2005-02-07 00:56:26 +00:00
|
|
|
|
if (global_settings.talk_menu) /* voice UI? */
|
|
|
|
|
talk_spell(text, false); /* speak revised text */
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
2003-03-10 15:09:27 +00:00
|
|
|
|
|
2004-10-22 17:00:30 +00:00
|
|
|
|
case KBD_CURSOR_RIGHT:
|
|
|
|
|
case KBD_CURSOR_RIGHT | BUTTON_REPEAT:
|
2006-03-31 13:59:04 +00:00
|
|
|
|
if (hangul)
|
2006-03-29 16:21:42 +00:00
|
|
|
|
hangul = false;
|
2005-12-06 13:27:15 +00:00
|
|
|
|
if (editpos < len_utf8)
|
2005-02-07 00:56:26 +00:00
|
|
|
|
{
|
|
|
|
|
editpos++;
|
2005-12-06 13:27:15 +00:00
|
|
|
|
c = utf8seek(text, editpos);
|
|
|
|
|
kbd_spellchar(text[c]);
|
2005-02-07 00:56:26 +00:00
|
|
|
|
}
|
2003-03-10 15:09:27 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2004-10-22 17:00:30 +00:00
|
|
|
|
case KBD_CURSOR_LEFT:
|
|
|
|
|
case KBD_CURSOR_LEFT | BUTTON_REPEAT:
|
2006-03-31 13:59:04 +00:00
|
|
|
|
if (hangul)
|
2006-03-29 16:21:42 +00:00
|
|
|
|
hangul = false;
|
2005-02-07 00:56:26 +00:00
|
|
|
|
if (editpos)
|
|
|
|
|
{
|
|
|
|
|
editpos--;
|
2005-12-06 13:27:15 +00:00
|
|
|
|
c = utf8seek(text, editpos);
|
|
|
|
|
kbd_spellchar(text[c]);
|
2005-02-07 00:56:26 +00:00
|
|
|
|
}
|
2003-03-10 15:09:27 +00:00
|
|
|
|
break;
|
2004-11-14 23:08:08 +00:00
|
|
|
|
#endif /* !KBD_MODES */
|
2003-03-10 15:09:27 +00:00
|
|
|
|
|
2003-11-04 12:36:55 +00:00
|
|
|
|
case BUTTON_NONE:
|
2005-11-20 01:02:14 +00:00
|
|
|
|
gui_syncstatusbar_draw(&statusbars, false);
|
2003-11-17 02:10:09 +00:00
|
|
|
|
redraw = false;
|
2006-03-29 16:21:42 +00:00
|
|
|
|
#ifdef KBD_MORSE_INPUT
|
2005-12-02 19:41:09 +00:00
|
|
|
|
if (morse_reading)
|
|
|
|
|
{
|
|
|
|
|
logf("Morse: 0x%02x", morse_code);
|
|
|
|
|
morse_reading = false;
|
|
|
|
|
|
|
|
|
|
for (j = 0; morse_alphabets[j] != '\0'; j++)
|
|
|
|
|
{
|
|
|
|
|
if (morse_codes[j] == morse_code)
|
|
|
|
|
break ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (morse_alphabets[j] == '\0')
|
|
|
|
|
{
|
|
|
|
|
logf("Morse code not found");
|
|
|
|
|
break ;
|
|
|
|
|
}
|
2006-03-29 16:21:42 +00:00
|
|
|
|
|
2006-03-31 13:59:04 +00:00
|
|
|
|
/* turn off hangul input */
|
|
|
|
|
if (hangul)
|
2006-03-29 16:21:42 +00:00
|
|
|
|
hangul = false;
|
|
|
|
|
|
|
|
|
|
kbd_inschar(text, buflen, &editpos, morse_alphabets[j]);
|
|
|
|
|
|
2005-12-02 19:41:09 +00:00
|
|
|
|
if (global_settings.talk_menu) /* voice UI? */
|
|
|
|
|
talk_spell(text, false); /* speak revised text */
|
|
|
|
|
redraw = true;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-11-04 12:36:55 +00:00
|
|
|
|
break;
|
2004-07-26 16:06:59 +00:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
if(default_event_handler(button) == SYS_USB_CONNECTED)
|
|
|
|
|
lcd_setfont(FONT_SYSFIXED);
|
|
|
|
|
break;
|
|
|
|
|
|
2002-12-04 15:04:43 +00:00
|
|
|
|
}
|
2004-10-22 17:00:30 +00:00
|
|
|
|
if (button != BUTTON_NONE)
|
|
|
|
|
lastbutton = button;
|
2002-12-04 15:04:43 +00:00
|
|
|
|
}
|
2006-03-11 22:31:53 +00:00
|
|
|
|
#ifdef HAS_BUTTONBAR
|
|
|
|
|
global_settings.buttonbar=buttonbar_config;
|
|
|
|
|
#endif
|
2003-01-15 13:48:54 +00:00
|
|
|
|
lcd_setfont(FONT_UI);
|
2004-09-19 21:58:37 +00:00
|
|
|
|
|
2002-12-04 15:04:43 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|