2002-12-04 15:04:43 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2009-03-23 17:08:46 +00:00
|
|
|
* Copyright (C) 2002 by Björn Stenberg
|
2002-12-04 15:04:43 +00:00
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-12-04 15:04:43 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "kernel.h"
|
2005-02-07 00:56:26 +00:00
|
|
|
#include "system.h"
|
2010-05-06 21:04:40 +00:00
|
|
|
#include "string-extra.h"
|
2002-12-04 15:04:43 +00:00
|
|
|
#include "font.h"
|
2003-03-10 15:09:27 +00:00
|
|
|
#include "screens.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 "hangul.h"
|
2006-08-22 13:21:13 +00:00
|
|
|
#include "action.h"
|
2007-04-16 09:14:36 +00:00
|
|
|
#include "icon.h"
|
2007-10-10 02:28:58 +00:00
|
|
|
#include "pcmbuf.h"
|
|
|
|
#include "lang.h"
|
2008-05-03 08:35:14 +00:00
|
|
|
#include "keyboard.h"
|
2009-01-05 10:25:41 +00:00
|
|
|
#include "viewport.h"
|
2009-03-08 20:57:37 +00:00
|
|
|
#include "file.h"
|
2009-08-12 14:51:16 +00:00
|
|
|
#include "splash.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
|
|
|
#define DEFAULT_MARGIN 6
|
|
|
|
#define KBD_BUF_SIZE 500
|
2004-10-22 17:00:30 +00:00
|
|
|
|
2009-11-08 13:14:50 +00:00
|
|
|
#if (CONFIG_KEYPAD == IRIVER_H100_PAD) \
|
|
|
|
|| (CONFIG_KEYPAD == IRIVER_H300_PAD) \
|
|
|
|
|| (CONFIG_KEYPAD == IPOD_1G2G_PAD) \
|
|
|
|
|| (CONFIG_KEYPAD == IPOD_3G_PAD) \
|
|
|
|
|| (CONFIG_KEYPAD == IPOD_4G_PAD) \
|
|
|
|
|| (CONFIG_KEYPAD == IRIVER_H10_PAD) \
|
|
|
|
|| (CONFIG_KEYPAD == GIGABEAT_PAD) \
|
|
|
|
|| (CONFIG_KEYPAD == GIGABEAT_S_PAD) \
|
|
|
|
|| (CONFIG_KEYPAD == MROBE100_PAD) \
|
|
|
|
|| (CONFIG_KEYPAD == SANSA_E200_PAD) \
|
|
|
|
|| (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD) \
|
2010-02-11 20:04:09 +00:00
|
|
|
|| (CONFIG_KEYPAD == PHILIPS_SA9200_PAD) \
|
|
|
|
|| (CONFIG_KEYPAD == PBELL_VIBE500_PAD)
|
2009-11-08 13:14:50 +00:00
|
|
|
/* certain key combos toggle input mode between keyboard input and Morse input */
|
|
|
|
#define KBD_TOGGLE_INPUT
|
2004-10-22 17:00:30 +00:00
|
|
|
#endif
|
|
|
|
|
2010-02-25 06:40:36 +00:00
|
|
|
#define CHANGED_PICKER 1
|
|
|
|
#define CHANGED_CURSOR 2
|
|
|
|
#define CHANGED_TEXT 3
|
|
|
|
|
2007-03-06 07:59:25 +00:00
|
|
|
struct keyboard_parameters
|
|
|
|
{
|
2006-07-19 12:07:51 +00:00
|
|
|
unsigned short kbd_buf[KBD_BUF_SIZE];
|
2010-02-13 13:10:32 +00:00
|
|
|
unsigned short max_line_len;
|
2010-01-31 13:38:47 +00:00
|
|
|
int default_lines;
|
2006-07-19 12:07:51 +00:00
|
|
|
int nchars;
|
|
|
|
int font_w;
|
|
|
|
int font_h;
|
2009-10-03 13:53:49 +00:00
|
|
|
int text_w;
|
2006-07-19 12:07:51 +00:00
|
|
|
int curfont;
|
|
|
|
int main_y;
|
2010-01-31 13:38:47 +00:00
|
|
|
#ifdef HAVE_MORSE_INPUT
|
2009-11-09 14:26:20 +00:00
|
|
|
int old_main_y;
|
2010-01-31 13:38:47 +00:00
|
|
|
#endif
|
2006-07-19 12:07:51 +00:00
|
|
|
int max_chars;
|
|
|
|
int max_chars_text;
|
|
|
|
int lines;
|
|
|
|
int pages;
|
|
|
|
int keyboard_margin;
|
|
|
|
int curpos;
|
|
|
|
int leftpos;
|
|
|
|
int page;
|
|
|
|
int x;
|
|
|
|
int y;
|
2007-03-06 05:43:04 +00:00
|
|
|
bool line_edit;
|
2010-01-31 13:38:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct edit_state
|
|
|
|
{
|
|
|
|
char* text;
|
|
|
|
int buflen;
|
|
|
|
int len_utf8;
|
|
|
|
int editpos; /* Edit position on all screens */
|
|
|
|
bool cur_blink; /* Cursor on/off flag */
|
2007-03-06 05:43:04 +00:00
|
|
|
bool hangul;
|
|
|
|
unsigned short hlead, hvowel, htail;
|
2010-01-31 13:38:47 +00:00
|
|
|
#ifdef HAVE_MORSE_INPUT
|
|
|
|
bool morse_mode;
|
|
|
|
bool morse_reading;
|
|
|
|
unsigned char morse_code;
|
|
|
|
int morse_tick;
|
|
|
|
#endif
|
2010-02-25 06:40:36 +00:00
|
|
|
int changed;
|
2006-07-19 12:07:51 +00:00
|
|
|
};
|
|
|
|
|
2007-03-06 07:59:25 +00:00
|
|
|
static struct keyboard_parameters kbd_param[NB_SCREENS];
|
2006-03-29 16:21:42 +00:00
|
|
|
static bool kbd_loaded = false;
|
|
|
|
|
2009-11-08 13:14:50 +00:00
|
|
|
#ifdef HAVE_MORSE_INPUT
|
2005-12-02 19:41:09 +00:00
|
|
|
/* FIXME: We should put this to a configuration file. */
|
2006-04-22 09:43:43 +00:00
|
|
|
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
|
|
|
#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)
|
|
|
|
{
|
2007-03-06 05:43:04 +00:00
|
|
|
int fd, l;
|
2010-02-14 05:00:41 +00:00
|
|
|
int i, line_len, max_line_len;
|
2006-07-23 18:54:00 +00:00
|
|
|
unsigned char buf[4];
|
2006-03-29 16:21:42 +00:00
|
|
|
|
2007-03-06 05:43:04 +00:00
|
|
|
if (filename == NULL)
|
|
|
|
{
|
2006-03-29 16:21:42 +00:00
|
|
|
kbd_loaded = false;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-02 20:39:03 +00:00
|
|
|
fd = open_utf8(filename, O_RDONLY|O_BINARY);
|
2006-03-29 16:21:42 +00:00
|
|
|
if (fd < 0)
|
|
|
|
return 1;
|
|
|
|
|
2010-02-13 13:10:32 +00:00
|
|
|
line_len = 0;
|
2010-02-14 05:00:41 +00:00
|
|
|
max_line_len = 1;
|
|
|
|
i = 0;
|
2007-03-06 05:43:04 +00:00
|
|
|
while (read(fd, buf, 1) == 1 && i < KBD_BUF_SIZE)
|
|
|
|
{
|
|
|
|
/* check how many bytes to read for this character */
|
|
|
|
static const unsigned char sizes[4] = { 0x80, 0xe0, 0xf0, 0xf5 };
|
|
|
|
size_t count;
|
2009-10-03 13:53:49 +00:00
|
|
|
unsigned short ch;
|
2007-03-06 05:43:04 +00:00
|
|
|
|
|
|
|
for (count = 0; count < ARRAYLEN(sizes); count++)
|
|
|
|
{
|
|
|
|
if (buf[0] < sizes[count])
|
|
|
|
break;
|
2006-07-23 18:33:43 +00:00
|
|
|
}
|
|
|
|
|
2007-03-06 05:43:04 +00:00
|
|
|
if (count >= ARRAYLEN(sizes))
|
|
|
|
continue; /* Invalid size. */
|
|
|
|
|
|
|
|
if (read(fd, &buf[1], count) != (ssize_t)count)
|
|
|
|
{
|
2006-07-23 18:33:43 +00:00
|
|
|
close(fd);
|
|
|
|
kbd_loaded = false;
|
|
|
|
return 1;
|
2006-07-19 12:07:51 +00:00
|
|
|
}
|
2006-07-23 18:54:00 +00:00
|
|
|
|
2009-10-03 13:53:49 +00:00
|
|
|
utf8decode(buf, &ch);
|
2010-01-31 13:38:47 +00:00
|
|
|
if (ch != 0xFEFF && ch != '\r') /* skip BOM & carriage returns */
|
|
|
|
{
|
|
|
|
FOR_NB_SCREENS(l)
|
|
|
|
kbd_param[l].kbd_buf[i] = ch;
|
2006-07-23 18:33:43 +00:00
|
|
|
i++;
|
2010-02-13 13:10:32 +00:00
|
|
|
if (ch == '\n')
|
|
|
|
{
|
|
|
|
if (max_line_len < line_len)
|
|
|
|
max_line_len = line_len;
|
|
|
|
line_len = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
line_len++;
|
2010-01-31 13:38:47 +00:00
|
|
|
}
|
2006-03-29 16:21:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
kbd_loaded = true;
|
2007-03-06 05:43:04 +00:00
|
|
|
|
2010-02-14 05:00:41 +00:00
|
|
|
if (max_line_len < line_len)
|
|
|
|
max_line_len = line_len;
|
|
|
|
|
2006-07-19 12:07:51 +00:00
|
|
|
FOR_NB_SCREENS(l)
|
2010-02-04 14:53:45 +00:00
|
|
|
{
|
|
|
|
struct keyboard_parameters *pm = &kbd_param[l];
|
|
|
|
pm->nchars = i;
|
|
|
|
/* initialize parameters */
|
|
|
|
pm->x = pm->y = pm->page = 0;
|
|
|
|
pm->default_lines = 0;
|
2010-02-13 13:10:32 +00:00
|
|
|
pm->max_line_len = max_line_len;
|
2010-02-04 14:53:45 +00:00
|
|
|
}
|
2006-03-29 16:21:42 +00:00
|
|
|
|
2007-03-06 05:43:04 +00:00
|
|
|
return 0;
|
2006-03-29 16:21:42 +00:00
|
|
|
}
|
|
|
|
|
2010-02-25 06:40:36 +00:00
|
|
|
/* helper function to spell a char */
|
2006-03-29 16:21:42 +00:00
|
|
|
static void kbd_spellchar(unsigned short c)
|
2004-05-21 06:29:55 +00:00
|
|
|
{
|
2010-02-25 06:40:36 +00:00
|
|
|
unsigned char tmp[5];
|
|
|
|
/* store char to pass to talk_spell */
|
|
|
|
unsigned char* utf8 = utf8encode(c, tmp);
|
|
|
|
*utf8 = 0;
|
2007-10-10 06:02:08 +00:00
|
|
|
|
2010-02-25 06:40:36 +00:00
|
|
|
if (c == ' ')
|
|
|
|
talk_id(VOICE_BLANK, false);
|
|
|
|
else
|
|
|
|
talk_spell(tmp, false);
|
2007-10-10 02:28:58 +00:00
|
|
|
}
|
|
|
|
|
2010-01-31 13:38:47 +00:00
|
|
|
static void kbd_inschar(struct edit_state *state, unsigned short ch)
|
2006-03-29 16:21:42 +00:00
|
|
|
{
|
2009-11-09 14:26:20 +00:00
|
|
|
int i, j, len;
|
2006-03-29 16:21:42 +00:00
|
|
|
unsigned char tmp[4];
|
|
|
|
unsigned char* utf8;
|
|
|
|
|
2010-01-31 13:38:47 +00:00
|
|
|
len = strlen(state->text);
|
2006-03-29 16:21:42 +00:00
|
|
|
utf8 = utf8encode(ch, tmp);
|
|
|
|
j = (long)utf8 - (long)tmp;
|
|
|
|
|
2010-01-31 13:38:47 +00:00
|
|
|
if (len + j < state->buflen)
|
2007-03-06 05:43:04 +00:00
|
|
|
{
|
2010-01-31 13:38:47 +00:00
|
|
|
i = utf8seek(state->text, state->editpos);
|
|
|
|
utf8 = state->text + i;
|
2009-11-09 14:26:20 +00:00
|
|
|
memmove(utf8 + j, utf8, len - i + 1);
|
|
|
|
memcpy(utf8, tmp, j);
|
2010-01-31 13:38:47 +00:00
|
|
|
state->editpos++;
|
2010-02-25 06:40:36 +00:00
|
|
|
state->changed = CHANGED_TEXT;
|
2006-03-29 16:21:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-31 13:38:47 +00:00
|
|
|
static void kbd_delchar(struct edit_state *state)
|
2006-03-29 16:21:42 +00:00
|
|
|
{
|
2009-11-09 14:26:20 +00:00
|
|
|
int i, j, len;
|
2006-03-29 16:21:42 +00:00
|
|
|
unsigned char* utf8;
|
|
|
|
|
2010-01-31 13:38:47 +00:00
|
|
|
if (state->editpos > 0)
|
2006-03-29 16:21:42 +00:00
|
|
|
{
|
2010-01-31 13:38:47 +00:00
|
|
|
state->editpos--;
|
|
|
|
len = strlen(state->text);
|
|
|
|
i = utf8seek(state->text, state->editpos);
|
|
|
|
utf8 = state->text + i;
|
2009-11-09 14:26:20 +00:00
|
|
|
j = utf8seek(utf8, 1);
|
|
|
|
memmove(utf8, utf8 + j, len - i - j + 1);
|
2010-02-25 06:40:36 +00:00
|
|
|
state->changed = CHANGED_TEXT;
|
2006-03-29 16:21:42 +00:00
|
|
|
}
|
2007-03-06 05:43:04 +00:00
|
|
|
}
|
2006-03-29 16:21:42 +00:00
|
|
|
|
2007-03-06 05:43:04 +00:00
|
|
|
/* Lookup k value based on state of param (pm) */
|
2009-10-03 13:53:49 +00:00
|
|
|
static unsigned short get_kbd_ch(const struct keyboard_parameters *pm)
|
2007-03-06 05:43:04 +00:00
|
|
|
{
|
2009-10-03 13:53:49 +00:00
|
|
|
int k = (pm->page*pm->lines + pm->y)*pm->max_chars + pm->x;
|
|
|
|
return (k < pm->nchars)? pm->kbd_buf[k]: ' ';
|
2006-03-29 16:21:42 +00:00
|
|
|
}
|
|
|
|
|
2010-02-04 14:53:45 +00:00
|
|
|
static void kbd_calc_params(struct keyboard_parameters *pm,
|
|
|
|
struct screen *sc, struct edit_state *state);
|
|
|
|
static void kbd_draw_picker(struct keyboard_parameters *pm,
|
|
|
|
struct screen *sc, struct edit_state *state);
|
|
|
|
static void kbd_draw_edit_line(struct keyboard_parameters *pm,
|
|
|
|
struct screen *sc, struct edit_state *state);
|
2010-02-25 06:40:36 +00:00
|
|
|
static void kbd_insert_selected(struct keyboard_parameters *pm,
|
|
|
|
struct edit_state *state);
|
|
|
|
static void kbd_backspace(struct edit_state *state);
|
|
|
|
static void kbd_move_cursor(struct edit_state *state, int dir);
|
2010-06-09 12:08:25 +00:00
|
|
|
static void kbd_move_picker_horizontal(struct keyboard_parameters *pm,
|
|
|
|
struct edit_state *state, int dir);
|
2010-02-25 06:40:36 +00:00
|
|
|
static void kbd_move_picker_vertical(struct keyboard_parameters *pm,
|
|
|
|
struct edit_state *state, int dir);
|
2010-02-04 14:53:45 +00:00
|
|
|
|
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;
|
2007-03-06 08:19:00 +00:00
|
|
|
#ifdef CPU_ARM
|
|
|
|
/* This seems to keep the sizes for ARM way down */
|
2007-03-06 07:59:25 +00:00
|
|
|
struct keyboard_parameters * volatile param = kbd_param;
|
2007-03-06 08:19:00 +00:00
|
|
|
#else
|
|
|
|
struct keyboard_parameters * const param = kbd_param;
|
|
|
|
#endif
|
2010-01-31 13:38:47 +00:00
|
|
|
struct edit_state state;
|
2007-03-06 05:43:04 +00:00
|
|
|
int l; /* screen loop variable */
|
|
|
|
unsigned short ch;
|
2009-08-12 14:51:16 +00:00
|
|
|
int ret = 0; /* assume success */
|
2006-07-19 12:07:51 +00:00
|
|
|
FOR_NB_SCREENS(l)
|
|
|
|
{
|
2009-12-09 07:25:46 +00:00
|
|
|
viewportmanager_theme_enable(l, false, NULL);
|
2006-07-19 12:07:51 +00:00
|
|
|
}
|
2002-12-04 15:04:43 +00:00
|
|
|
|
2008-05-29 20:32:39 +00:00
|
|
|
#ifdef HAVE_BUTTONBAR
|
2005-11-20 01:02:14 +00:00
|
|
|
struct gui_buttonbar buttonbar;
|
2006-03-11 22:31:53 +00:00
|
|
|
bool buttonbar_config = global_settings.buttonbar;
|
2007-03-06 05:43:04 +00:00
|
|
|
|
2006-03-11 22:31:53 +00:00
|
|
|
global_settings.buttonbar = true;
|
2005-11-20 01:02:14 +00:00
|
|
|
gui_buttonbar_init(&buttonbar);
|
2010-01-31 13:38:47 +00:00
|
|
|
gui_buttonbar_set_display(&buttonbar, &screens[SCREEN_MAIN]);
|
|
|
|
#endif
|
2007-03-06 05:43:04 +00:00
|
|
|
|
2010-01-31 13:38:47 +00:00
|
|
|
/* initialize state */
|
|
|
|
state.text = text;
|
|
|
|
state.buflen = buflen;
|
2010-02-04 14:53:45 +00:00
|
|
|
/* Initial edit position is after last character */
|
|
|
|
state.editpos = utf8length(state.text);
|
2010-01-31 13:38:47 +00:00
|
|
|
state.cur_blink = true;
|
|
|
|
#ifdef HAVE_MORSE_INPUT
|
|
|
|
state.morse_mode = global_settings.morse_input;
|
|
|
|
state.morse_reading = false;
|
2006-07-19 12:07:51 +00:00
|
|
|
#endif
|
2010-01-31 13:38:47 +00:00
|
|
|
state.hangul = false;
|
2010-02-25 06:40:36 +00:00
|
|
|
state.changed = 0;
|
2007-03-06 05:43:04 +00:00
|
|
|
|
2010-01-31 13:38:47 +00:00
|
|
|
if (!kbd_loaded)
|
2006-07-19 12:07:51 +00:00
|
|
|
{
|
2010-01-31 13:38:47 +00:00
|
|
|
/* Copy default keyboard to buffer */
|
|
|
|
FOR_NB_SCREENS(l)
|
2006-07-23 17:16:38 +00:00
|
|
|
{
|
2010-01-31 13:38:47 +00:00
|
|
|
struct keyboard_parameters *pm = ¶m[l];
|
|
|
|
const unsigned char *p;
|
2007-03-06 05:43:04 +00:00
|
|
|
int i = 0;
|
|
|
|
|
2010-01-31 13:38:47 +00:00
|
|
|
#if LCD_WIDTH >= 160 && LCD_HEIGHT >= 96
|
|
|
|
struct screen *sc = &screens[l];
|
2007-03-06 05:43:04 +00:00
|
|
|
|
2010-01-31 13:38:47 +00:00
|
|
|
if (sc->getwidth() >= 160 && sc->getheight() >= 96)
|
|
|
|
{
|
|
|
|
p = "ABCDEFG abcdefg !?\" @#$%+'\n"
|
|
|
|
"HIJKLMN hijklmn 789 &_()-`\n"
|
|
|
|
"OPQRSTU opqrstu 456 §|{}/<\n"
|
|
|
|
"VWXYZ., vwxyz.,0123 ~=[]*>\n"
|
|
|
|
"ÀÁÂÃÄÅÆ ÌÍÎÏ ÈÉÊË ¢£¤¥¦§©®\n"
|
|
|
|
"àáâãäåæ ìíîï èéêë «»°ºª¹²³\n"
|
|
|
|
"ÓÒÔÕÖØ ÇÐÞÝß ÙÚÛÜ ¯±×÷¡¿µ·\n"
|
|
|
|
"òóôõöø çðþýÿ ùúûü ¼½¾¬¶¨:;";
|
|
|
|
|
|
|
|
pm->default_lines = 8;
|
2010-02-13 13:10:32 +00:00
|
|
|
pm->max_line_len = 26;
|
2010-01-31 13:38:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif /* LCD_WIDTH >= 160 && LCD_HEIGHT >= 96 */
|
|
|
|
{
|
|
|
|
p = "ABCDEFG !?\" @#$%+'\n"
|
|
|
|
"HIJKLMN 789 &_()-`\n"
|
|
|
|
"OPQRSTU 456 §|{}/<\n"
|
|
|
|
"VWXYZ.,0123 ~=[]*>\n"
|
|
|
|
|
|
|
|
"abcdefg ¢£¤¥¦§©®¬\n"
|
|
|
|
"hijklmn «»°ºª¹²³¶\n"
|
|
|
|
"opqrstu ¯±×÷¡¿µ·¨\n"
|
|
|
|
"vwxyz., :;¼½¾ \n"
|
|
|
|
|
|
|
|
"ÀÁÂÃÄÅÆ ÌÍÎÏ ÈÉÊË\n"
|
|
|
|
"àáâãäåæ ìíîï èéêë\n"
|
|
|
|
"ÓÒÔÕÖØ ÇÐÞÝß ÙÚÛÜ\n"
|
|
|
|
"òóôõöø çðþýÿ ùúûü";
|
|
|
|
|
|
|
|
pm->default_lines = 4;
|
2010-02-13 13:10:32 +00:00
|
|
|
pm->max_line_len = 18;
|
2010-01-31 13:38:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (*p)
|
2007-03-06 05:43:04 +00:00
|
|
|
p = utf8decode(p, &pm->kbd_buf[i++]);
|
|
|
|
|
|
|
|
pm->nchars = i;
|
2010-02-04 14:53:45 +00:00
|
|
|
/* initialize parameters */
|
|
|
|
pm->x = pm->y = pm->page = 0;
|
2006-03-29 16:21:42 +00:00
|
|
|
}
|
2010-01-31 13:38:47 +00:00
|
|
|
kbd_loaded = true;
|
2006-03-29 16:21:42 +00:00
|
|
|
}
|
2007-03-06 05:43:04 +00:00
|
|
|
|
2006-07-19 12:07:51 +00:00
|
|
|
FOR_NB_SCREENS(l)
|
|
|
|
{
|
2007-03-06 05:43:04 +00:00
|
|
|
struct keyboard_parameters *pm = ¶m[l];
|
|
|
|
struct screen *sc = &screens[l];
|
2010-02-04 14:53:45 +00:00
|
|
|
kbd_calc_params(pm, sc, &state);
|
2006-07-23 17:16:38 +00:00
|
|
|
}
|
2007-03-06 05:43:04 +00:00
|
|
|
|
2010-01-31 13:38:47 +00:00
|
|
|
if (global_settings.talk_menu) /* voice UI? */
|
|
|
|
talk_spell(state.text, true); /* spell initial text */
|
2004-05-21 06:29:55 +00:00
|
|
|
|
2007-03-06 05:43:04 +00:00
|
|
|
while (!done)
|
2002-12-04 15:04:43 +00:00
|
|
|
{
|
2007-03-06 05:43:04 +00:00
|
|
|
/* These declarations are assigned to the screen on which the key
|
|
|
|
action occurred - pointers save a lot of space over array notation
|
|
|
|
when accessing the same array element countless times */
|
|
|
|
int button;
|
|
|
|
#if NB_SCREENS > 1
|
|
|
|
int button_screen;
|
|
|
|
#else
|
|
|
|
const int button_screen = 0;
|
|
|
|
#endif
|
|
|
|
struct keyboard_parameters *pm;
|
|
|
|
struct screen *sc;
|
|
|
|
|
2010-01-31 13:38:47 +00:00
|
|
|
state.len_utf8 = utf8length(state.text);
|
2007-03-06 05:43:04 +00:00
|
|
|
|
2006-07-19 12:07:51 +00:00
|
|
|
FOR_NB_SCREENS(l)
|
|
|
|
{
|
2010-02-04 14:53:45 +00:00
|
|
|
/* declare scoped pointers inside screen loops - hide the
|
|
|
|
declarations from previous block level */
|
2007-03-06 05:43:04 +00:00
|
|
|
struct keyboard_parameters *pm = ¶m[l];
|
|
|
|
struct screen *sc = &screens[l];
|
2010-02-04 14:53:45 +00:00
|
|
|
sc->clear_display();
|
|
|
|
kbd_draw_picker(pm, sc, &state);
|
|
|
|
kbd_draw_edit_line(pm, sc, &state);
|
2006-07-19 12:07:51 +00:00
|
|
|
}
|
2007-03-06 05:43:04 +00:00
|
|
|
|
2008-05-29 20:32:39 +00:00
|
|
|
#ifdef HAVE_BUTTONBAR
|
2006-04-22 13:06:57 +00:00
|
|
|
/* draw the button bar */
|
|
|
|
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
|
|
|
|
2006-07-19 12:07:51 +00:00
|
|
|
FOR_NB_SCREENS(l)
|
2007-03-06 05:43:04 +00:00
|
|
|
screens[l].update();
|
|
|
|
|
2010-02-25 06:40:36 +00:00
|
|
|
state.cur_blink = !state.cur_blink;
|
|
|
|
|
2010-01-16 13:54:10 +00:00
|
|
|
button = get_action(
|
|
|
|
#ifdef HAVE_MORSE_INPUT
|
2010-01-31 13:38:47 +00:00
|
|
|
state.morse_mode? CONTEXT_MORSE_INPUT:
|
2010-01-16 13:54:10 +00:00
|
|
|
#endif
|
|
|
|
CONTEXT_KEYBOARD, HZ/2);
|
2007-03-06 05:55:23 +00:00
|
|
|
#if NB_SCREENS > 1
|
2007-03-06 05:43:04 +00:00
|
|
|
button_screen = (get_action_statuscode(NULL) & ACTION_REMOTE) ? 1 : 0;
|
|
|
|
#endif
|
|
|
|
pm = ¶m[button_screen];
|
|
|
|
sc = &screens[button_screen];
|
2004-07-26 16:06:59 +00:00
|
|
|
|
2009-11-06 12:53:02 +00:00
|
|
|
/* Remap some buttons to allow to move
|
|
|
|
* cursor in line edit mode and morse mode. */
|
2010-06-09 12:08:25 +00:00
|
|
|
if (pm->line_edit
|
|
|
|
#ifdef HAVE_MORSE_INPUT
|
|
|
|
|| state.morse_mode
|
|
|
|
#endif /* HAVE_MORSE_INPUT */
|
|
|
|
)
|
2005-12-04 08:45:24 +00:00
|
|
|
{
|
2006-08-22 13:21:13 +00:00
|
|
|
if (button == ACTION_KBD_LEFT)
|
|
|
|
button = ACTION_KBD_CURSOR_LEFT;
|
|
|
|
if (button == ACTION_KBD_RIGHT)
|
|
|
|
button = ACTION_KBD_CURSOR_RIGHT;
|
2005-12-04 08:45:24 +00:00
|
|
|
}
|
2006-04-22 09:43:43 +00:00
|
|
|
|
2007-03-06 05:43:04 +00:00
|
|
|
switch ( button )
|
|
|
|
{
|
2009-11-09 14:26:20 +00:00
|
|
|
case ACTION_KBD_DONE:
|
|
|
|
/* accepts what was entered and continues */
|
|
|
|
ret = 0;
|
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
|
2006-08-22 13:21:13 +00:00
|
|
|
case ACTION_KBD_ABORT:
|
2009-10-04 14:45:29 +00:00
|
|
|
ret = -1;
|
|
|
|
done = true;
|
2003-01-15 13:48:54 +00:00
|
|
|
break;
|
|
|
|
|
2006-08-22 13:21:13 +00:00
|
|
|
case ACTION_KBD_PAGE_FLIP:
|
2009-11-08 13:14:50 +00:00
|
|
|
#ifdef HAVE_MORSE_INPUT
|
2010-01-31 13:38:47 +00:00
|
|
|
if (state.morse_mode)
|
2006-03-29 16:21:42 +00:00
|
|
|
break;
|
2005-12-02 19:41:09 +00:00
|
|
|
#endif
|
2007-03-06 05:43:04 +00:00
|
|
|
if (++pm->page >= pm->pages)
|
2009-10-04 14:45:29 +00:00
|
|
|
pm->page = 0;
|
2007-03-06 05:43:04 +00:00
|
|
|
|
2010-02-25 06:40:36 +00:00
|
|
|
state.changed = CHANGED_PICKER;
|
2003-01-15 13:48:54 +00:00
|
|
|
break;
|
|
|
|
|
2006-08-22 13:21:13 +00:00
|
|
|
case ACTION_KBD_RIGHT:
|
2010-06-09 12:08:25 +00:00
|
|
|
kbd_move_picker_horizontal(pm, &state, 1);
|
2003-01-15 13:48:54 +00:00
|
|
|
break;
|
2006-08-22 13:21:13 +00:00
|
|
|
|
|
|
|
case ACTION_KBD_LEFT:
|
2010-06-09 12:08:25 +00:00
|
|
|
kbd_move_picker_horizontal(pm, &state, -1);
|
2003-01-15 13:48:54 +00:00
|
|
|
break;
|
|
|
|
|
2006-08-22 13:21:13 +00:00
|
|
|
case ACTION_KBD_DOWN:
|
2010-02-25 06:40:36 +00:00
|
|
|
kbd_move_picker_vertical(pm, &state, 1);
|
2003-01-15 13:48:54 +00:00
|
|
|
break;
|
|
|
|
|
2006-08-22 13:21:13 +00:00
|
|
|
case ACTION_KBD_UP:
|
2010-02-25 06:40:36 +00:00
|
|
|
kbd_move_picker_vertical(pm, &state, -1);
|
|
|
|
break;
|
|
|
|
|
2009-11-08 13:14:50 +00:00
|
|
|
#ifdef HAVE_MORSE_INPUT
|
2010-02-25 06:40:36 +00:00
|
|
|
#ifdef KBD_TOGGLE_INPUT
|
|
|
|
case ACTION_KBD_MORSE_INPUT:
|
|
|
|
state.morse_mode = !state.morse_mode;
|
2010-06-09 12:08:25 +00:00
|
|
|
state.changed = CHANGED_PICKER;
|
2010-02-25 06:40:36 +00:00
|
|
|
|
|
|
|
FOR_NB_SCREENS(l)
|
2006-03-29 16:21:42 +00:00
|
|
|
{
|
2010-02-25 06:40:36 +00:00
|
|
|
struct keyboard_parameters *pm = ¶m[l];
|
|
|
|
int y = pm->main_y;
|
|
|
|
pm->main_y = pm->old_main_y;
|
|
|
|
pm->old_main_y = y;
|
2006-03-29 16:21:42 +00:00
|
|
|
}
|
2003-01-15 13:48:54 +00:00
|
|
|
break;
|
2010-02-25 06:40:36 +00:00
|
|
|
#endif /* KBD_TOGGLE_INPUT */
|
2003-01-15 13:48:54 +00:00
|
|
|
|
2006-08-22 13:21:13 +00:00
|
|
|
case ACTION_KBD_MORSE_SELECT:
|
2010-01-31 13:38:47 +00:00
|
|
|
if (state.morse_mode && state.morse_reading)
|
2005-12-02 19:41:09 +00:00
|
|
|
{
|
2010-01-31 13:38:47 +00:00
|
|
|
state.morse_code <<= 1;
|
|
|
|
if ((current_tick - state.morse_tick) > HZ/5)
|
|
|
|
state.morse_code |= 0x01;
|
2005-12-02 19:41:09 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-11-08 13:14:50 +00:00
|
|
|
#endif /* HAVE_MORSE_INPUT */
|
2006-04-22 09:43:43 +00:00
|
|
|
|
2006-08-22 13:21:13 +00:00
|
|
|
case ACTION_KBD_SELECT:
|
2010-06-09 12:08:25 +00:00
|
|
|
/* select doubles as backspace in line_edit */
|
|
|
|
if (pm->line_edit)
|
|
|
|
kbd_backspace(&state);
|
|
|
|
else
|
2009-11-08 13:14:50 +00:00
|
|
|
#ifdef HAVE_MORSE_INPUT
|
2010-01-31 13:38:47 +00:00
|
|
|
if (state.morse_mode)
|
2005-12-02 19:41:09 +00:00
|
|
|
{
|
2010-01-31 13:38:47 +00:00
|
|
|
state.morse_tick = current_tick;
|
2007-03-06 05:43:04 +00:00
|
|
|
|
2010-01-31 13:38:47 +00:00
|
|
|
if (!state.morse_reading)
|
2005-12-02 19:41:09 +00:00
|
|
|
{
|
2010-01-31 13:38:47 +00:00
|
|
|
state.morse_reading = true;
|
|
|
|
state.morse_code = 1;
|
2005-12-02 19:41:09 +00:00
|
|
|
}
|
2004-11-14 23:08:08 +00:00
|
|
|
}
|
|
|
|
else
|
2009-11-08 14:24:47 +00:00
|
|
|
#endif /* HAVE_MORSE_INPUT */
|
2010-02-25 06:40:36 +00:00
|
|
|
kbd_insert_selected(pm, &state);
|
2004-11-14 23:08:08 +00:00
|
|
|
break;
|
|
|
|
|
2006-08-22 13:21:13 +00:00
|
|
|
case ACTION_KBD_BACKSPACE:
|
2010-02-25 06:40:36 +00:00
|
|
|
kbd_backspace(&state);
|
2003-01-15 13:48:54 +00:00
|
|
|
break;
|
2003-03-10 15:09:27 +00:00
|
|
|
|
2006-08-22 13:21:13 +00:00
|
|
|
case ACTION_KBD_CURSOR_RIGHT:
|
2010-02-25 06:40:36 +00:00
|
|
|
kbd_move_cursor(&state, 1);
|
2003-03-10 15:09:27 +00:00
|
|
|
break;
|
|
|
|
|
2006-08-22 13:21:13 +00:00
|
|
|
case ACTION_KBD_CURSOR_LEFT:
|
2010-02-25 06:40:36 +00:00
|
|
|
kbd_move_cursor(&state, -1);
|
2003-03-10 15:09:27 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-31 13:38:47 +00:00
|
|
|
case ACTION_NONE:
|
2009-11-08 13:14:50 +00:00
|
|
|
#ifdef HAVE_MORSE_INPUT
|
2010-01-31 13:38:47 +00:00
|
|
|
if (state.morse_reading)
|
2005-12-02 19:41:09 +00:00
|
|
|
{
|
2007-03-06 05:43:04 +00:00
|
|
|
int j;
|
2010-01-31 13:38:47 +00:00
|
|
|
logf("Morse: 0x%02x", state.morse_code);
|
|
|
|
state.morse_reading = false;
|
2005-12-02 19:41:09 +00:00
|
|
|
|
|
|
|
for (j = 0; morse_alphabets[j] != '\0'; j++)
|
|
|
|
{
|
2010-01-31 13:38:47 +00:00
|
|
|
if (morse_codes[j] == state.morse_code)
|
2005-12-02 19:41:09 +00:00
|
|
|
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 */
|
2010-01-31 13:38:47 +00:00
|
|
|
state.hangul = false;
|
|
|
|
kbd_inschar(&state, morse_alphabets[j]);
|
2005-12-02 19:41:09 +00:00
|
|
|
}
|
2009-11-08 13:14:50 +00:00
|
|
|
#endif /* HAVE_MORSE_INPUT */
|
2003-11-04 12:36:55 +00:00
|
|
|
break;
|
2004-07-26 16:06:59 +00:00
|
|
|
|
|
|
|
default:
|
2007-03-06 05:43:04 +00:00
|
|
|
if (default_event_handler(button) == SYS_USB_CONNECTED)
|
|
|
|
{
|
2006-07-19 12:07:51 +00:00
|
|
|
FOR_NB_SCREENS(l)
|
|
|
|
screens[l].setfont(FONT_SYSFIXED);
|
2007-03-06 05:43:04 +00:00
|
|
|
}
|
2004-07-26 16:06:59 +00:00
|
|
|
break;
|
|
|
|
|
2007-03-06 05:43:04 +00:00
|
|
|
} /* end switch */
|
|
|
|
|
2010-01-31 13:38:47 +00:00
|
|
|
if (button != ACTION_NONE)
|
2006-04-22 13:06:57 +00:00
|
|
|
{
|
2010-01-31 13:38:47 +00:00
|
|
|
state.cur_blink = true;
|
2006-04-22 13:06:57 +00:00
|
|
|
}
|
2010-02-25 06:40:36 +00:00
|
|
|
if (global_settings.talk_menu) /* voice UI? */
|
|
|
|
{
|
|
|
|
if (state.changed == CHANGED_PICKER)
|
|
|
|
{
|
|
|
|
if (pm->line_edit)
|
|
|
|
{
|
|
|
|
talk_id(VOICE_EDIT, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#ifdef HAVE_MORSE_INPUT
|
2010-06-09 12:08:25 +00:00
|
|
|
/* FIXME: We should talk something like Morse mode.. */
|
2010-02-25 06:40:36 +00:00
|
|
|
if (!state.morse_mode)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
ch = get_kbd_ch(pm);
|
|
|
|
kbd_spellchar(ch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (state.changed == CHANGED_CURSOR)
|
|
|
|
{
|
|
|
|
int c = utf8seek(state.text, state.editpos);
|
|
|
|
kbd_spellchar(state.text[c]);
|
|
|
|
}
|
|
|
|
else if (state.changed == CHANGED_TEXT)
|
|
|
|
talk_spell(state.text, false); /* speak revised text */
|
|
|
|
}
|
|
|
|
state.changed = 0;
|
2002-12-04 15:04:43 +00:00
|
|
|
}
|
2007-03-06 05:43:04 +00:00
|
|
|
|
2008-05-29 20:32:39 +00:00
|
|
|
#ifdef HAVE_BUTTONBAR
|
2007-03-06 05:43:04 +00:00
|
|
|
global_settings.buttonbar = buttonbar_config;
|
2006-03-11 22:31:53 +00:00
|
|
|
#endif
|
2007-03-06 05:43:04 +00:00
|
|
|
|
2009-08-16 22:20:11 +00:00
|
|
|
if (ret < 0)
|
|
|
|
splash(HZ/2, ID2P(LANG_CANCEL));
|
|
|
|
|
2009-11-09 14:26:20 +00:00
|
|
|
#if defined(HAVE_MORSE_INPUT) && defined(KBD_TOGGLE_INPUT)
|
2010-01-31 13:38:47 +00:00
|
|
|
if (global_settings.morse_input != state.morse_mode)
|
2009-11-08 13:14:50 +00:00
|
|
|
{
|
2010-01-31 13:38:47 +00:00
|
|
|
global_settings.morse_input = state.morse_mode;
|
2009-11-08 13:14:50 +00:00
|
|
|
settings_save();
|
|
|
|
}
|
2009-11-09 14:26:20 +00:00
|
|
|
#endif /* HAVE_MORSE_INPUT && KBD_TOGGLE_INPUT */
|
2009-11-08 13:14:50 +00:00
|
|
|
|
2006-07-19 12:07:51 +00:00
|
|
|
FOR_NB_SCREENS(l)
|
2009-12-09 07:25:46 +00:00
|
|
|
{
|
2006-07-19 12:07:51 +00:00
|
|
|
screens[l].setfont(FONT_UI);
|
2009-12-21 05:19:12 +00:00
|
|
|
viewportmanager_theme_undo(l, false);
|
2010-01-31 13:38:47 +00:00
|
|
|
}
|
2009-08-12 14:38:25 +00:00
|
|
|
return ret;
|
2002-12-04 15:04:43 +00:00
|
|
|
}
|
2010-02-04 14:53:45 +00:00
|
|
|
|
|
|
|
static void kbd_calc_params(struct keyboard_parameters *pm,
|
|
|
|
struct screen *sc, struct edit_state *state)
|
|
|
|
{
|
|
|
|
struct font* font;
|
|
|
|
const unsigned char *p;
|
|
|
|
unsigned short ch;
|
|
|
|
int icon_w, sc_w, sc_h, w;
|
|
|
|
int i, total_lines;
|
|
|
|
|
|
|
|
pm->curfont = pm->default_lines ? FONT_SYSFIXED : FONT_UI;
|
|
|
|
font = font_get(pm->curfont);
|
|
|
|
pm->font_h = font->height;
|
|
|
|
|
|
|
|
/* check if FONT_UI fits the screen */
|
|
|
|
if (2*pm->font_h + 3 + BUTTONBAR_HEIGHT > sc->getheight())
|
|
|
|
{
|
|
|
|
pm->curfont = FONT_SYSFIXED;
|
|
|
|
font = font_get(FONT_SYSFIXED);
|
|
|
|
pm->font_h = font->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find max width of keyboard glyphs.
|
|
|
|
* since we're going to be adding spaces,
|
|
|
|
* max width is at least their width */
|
|
|
|
pm->font_w = font_get_width(font, ' ');
|
|
|
|
for (i = 0; i < pm->nchars; i++)
|
|
|
|
{
|
|
|
|
if (pm->kbd_buf[i] != '\n')
|
|
|
|
{
|
|
|
|
w = font_get_width(font, pm->kbd_buf[i]);
|
|
|
|
if (pm->font_w < w)
|
|
|
|
pm->font_w = w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find max width for text string */
|
|
|
|
pm->text_w = pm->font_w;
|
|
|
|
p = state->text;
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
p = utf8decode(p, &ch);
|
|
|
|
w = font_get_width(font, ch);
|
|
|
|
if (pm->text_w < w)
|
|
|
|
pm->text_w = w;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate how many characters to put in a row. */
|
|
|
|
icon_w = get_icon_width(sc->screen_type);
|
|
|
|
sc_w = sc->getwidth();
|
2010-02-13 13:10:32 +00:00
|
|
|
if (pm->font_w < sc_w / pm->max_line_len)
|
|
|
|
pm->font_w = sc_w / pm->max_line_len;
|
2010-02-04 14:53:45 +00:00
|
|
|
pm->max_chars = sc_w / pm->font_w;
|
|
|
|
pm->max_chars_text = (sc_w - icon_w * 2 - 2) / pm->text_w;
|
|
|
|
if (pm->max_chars_text < 3 && icon_w > pm->text_w)
|
|
|
|
pm->max_chars_text = sc_w / pm->text_w - 2;
|
|
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
/* Pad lines with spaces */
|
|
|
|
while (i < pm->nchars)
|
|
|
|
{
|
|
|
|
if (pm->kbd_buf[i] == '\n')
|
|
|
|
{
|
|
|
|
int k = pm->max_chars - i % ( pm->max_chars ) - 1;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
if (k == pm->max_chars - 1)
|
|
|
|
{
|
|
|
|
pm->nchars--;
|
|
|
|
|
|
|
|
for (j = i; j < pm->nchars; j++)
|
|
|
|
{
|
|
|
|
pm->kbd_buf[j] = pm->kbd_buf[j + 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pm->nchars + k - 1 >= KBD_BUF_SIZE)
|
|
|
|
{ /* We don't want to overflow the buffer */
|
|
|
|
k = KBD_BUF_SIZE - pm->nchars;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = pm->nchars + k - 1; j > i + k; j--)
|
|
|
|
{
|
|
|
|
pm->kbd_buf[j] = pm->kbd_buf[j-k];
|
|
|
|
}
|
|
|
|
|
|
|
|
pm->nchars += k;
|
|
|
|
k++;
|
|
|
|
|
|
|
|
while (k--)
|
|
|
|
{
|
|
|
|
pm->kbd_buf[i++] = ' ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2010-02-14 05:00:41 +00:00
|
|
|
if (pm->nchars == 0)
|
|
|
|
pm->kbd_buf[pm->nchars++] = ' ';
|
2010-02-04 14:53:45 +00:00
|
|
|
|
|
|
|
/* calculate pm->pages and pm->lines */
|
|
|
|
sc_h = sc->getheight();
|
|
|
|
pm->lines = (sc_h - BUTTONBAR_HEIGHT) / pm->font_h - 1;
|
|
|
|
|
|
|
|
if (pm->default_lines && pm->lines > pm->default_lines)
|
|
|
|
pm->lines = pm->default_lines;
|
|
|
|
|
|
|
|
pm->keyboard_margin = sc_h - BUTTONBAR_HEIGHT
|
|
|
|
- (pm->lines+1)*pm->font_h;
|
|
|
|
|
|
|
|
if (pm->keyboard_margin < 3 && pm->lines > 1)
|
|
|
|
{
|
|
|
|
pm->lines--;
|
|
|
|
pm->keyboard_margin += pm->font_h;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pm->keyboard_margin > DEFAULT_MARGIN)
|
|
|
|
pm->keyboard_margin = DEFAULT_MARGIN;
|
|
|
|
|
|
|
|
total_lines = (pm->nchars + pm->max_chars - 1) / pm->max_chars;
|
|
|
|
pm->pages = (total_lines + pm->lines - 1) / pm->lines;
|
|
|
|
pm->lines = (total_lines + pm->pages - 1) / pm->pages;
|
|
|
|
|
|
|
|
pm->main_y = pm->font_h*pm->lines + pm->keyboard_margin;
|
|
|
|
pm->keyboard_margin -= pm->keyboard_margin/2;
|
|
|
|
|
|
|
|
#ifdef HAVE_MORSE_INPUT
|
|
|
|
pm->old_main_y = sc_h - pm->font_h - BUTTONBAR_HEIGHT;
|
|
|
|
if (state->morse_mode)
|
|
|
|
{
|
|
|
|
int y = pm->main_y;
|
|
|
|
pm->main_y = pm->old_main_y;
|
|
|
|
pm->old_main_y = y;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void kbd_draw_picker(struct keyboard_parameters *pm,
|
|
|
|
struct screen *sc, struct edit_state *state)
|
|
|
|
{
|
|
|
|
char outline[8];
|
|
|
|
#ifdef HAVE_MORSE_INPUT
|
|
|
|
if (state->morse_mode)
|
|
|
|
{
|
|
|
|
const int w = 6, h = 8; /* sysfixed font width, height */
|
|
|
|
int i, j, x, y;
|
|
|
|
int sc_w = sc->getwidth(), sc_h = pm->main_y - pm->keyboard_margin - 1;
|
|
|
|
|
|
|
|
/* Draw morse code screen with sysfont */
|
|
|
|
sc->setfont(FONT_SYSFIXED);
|
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
outline[1] = '\0';
|
|
|
|
|
|
|
|
/* Draw morse code table with code descriptions. */
|
|
|
|
for (i = 0; morse_alphabets[i] != '\0'; i++)
|
|
|
|
{
|
|
|
|
int morse_code;
|
|
|
|
|
|
|
|
outline[0] = morse_alphabets[i];
|
|
|
|
sc->putsxy(x, y, outline);
|
|
|
|
|
|
|
|
morse_code = morse_codes[i];
|
|
|
|
for (j = 0; morse_code > 0x01; morse_code >>= 1)
|
|
|
|
j++;
|
|
|
|
|
|
|
|
x += w + 3 + j*4;
|
|
|
|
morse_code = morse_codes[i];
|
|
|
|
for (; morse_code > 0x01; morse_code >>= 1)
|
|
|
|
{
|
|
|
|
x -= 4;
|
|
|
|
if (morse_code & 0x01)
|
|
|
|
sc->fillrect(x, y + 2, 3, 4);
|
|
|
|
else
|
|
|
|
sc->fillrect(x, y + 3, 1, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
x += w*5 - 3;
|
|
|
|
if (x + w*6 >= sc_w)
|
|
|
|
{
|
|
|
|
x = 0;
|
|
|
|
y += h;
|
|
|
|
if (y + h >= sc_h)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#else
|
|
|
|
(void) state;
|
|
|
|
#endif /* HAVE_MORSE_INPUT */
|
|
|
|
{
|
|
|
|
/* draw page */
|
|
|
|
int i, j, k;
|
|
|
|
|
|
|
|
sc->setfont(pm->curfont);
|
|
|
|
|
|
|
|
k = pm->page*pm->max_chars*pm->lines;
|
|
|
|
|
|
|
|
for (i = j = 0; k < pm->nchars; k++)
|
|
|
|
{
|
|
|
|
int w;
|
|
|
|
unsigned char *utf8;
|
|
|
|
utf8 = utf8encode(pm->kbd_buf[k], outline);
|
|
|
|
*utf8 = 0;
|
|
|
|
|
|
|
|
sc->getstringsize(outline, &w, NULL);
|
|
|
|
sc->putsxy(i*pm->font_w + (pm->font_w-w) / 2,
|
|
|
|
j*pm->font_h, outline);
|
|
|
|
|
|
|
|
if (++i >= pm->max_chars)
|
|
|
|
{
|
|
|
|
i = 0;
|
|
|
|
if (++j >= pm->lines)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pm->line_edit)
|
|
|
|
{
|
|
|
|
/* highlight the key that has focus */
|
|
|
|
sc->set_drawmode(DRMODE_COMPLEMENT);
|
|
|
|
sc->fillrect(pm->font_w*pm->x, pm->font_h*pm->y,
|
|
|
|
pm->font_w, pm->font_h);
|
|
|
|
sc->set_drawmode(DRMODE_SOLID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void kbd_draw_edit_line(struct keyboard_parameters *pm,
|
|
|
|
struct screen *sc, struct edit_state *state)
|
|
|
|
{
|
|
|
|
char outline[8];
|
|
|
|
unsigned char *utf8;
|
|
|
|
int i = 0, j = 0, icon_w, w;
|
|
|
|
int sc_w = sc->getwidth();
|
|
|
|
int y = pm->main_y - pm->keyboard_margin;
|
|
|
|
int text_margin = (sc_w - pm->text_w * pm->max_chars_text) / 2;
|
|
|
|
|
|
|
|
/* Clear text area one pixel above separator line so any overdraw
|
|
|
|
doesn't collide */
|
|
|
|
screen_clear_area(sc, 0, y - 1, sc_w, pm->font_h + 6);
|
|
|
|
|
|
|
|
sc->hline(0, sc_w - 1, y);
|
|
|
|
|
|
|
|
/* write out the text */
|
|
|
|
sc->setfont(pm->curfont);
|
|
|
|
|
|
|
|
pm->leftpos = MAX(0, MIN(state->len_utf8, state->editpos + 2)
|
|
|
|
- pm->max_chars_text);
|
|
|
|
pm->curpos = state->editpos - pm->leftpos;
|
|
|
|
utf8 = state->text + utf8seek(state->text, pm->leftpos);
|
|
|
|
|
|
|
|
while (*utf8 && i < pm->max_chars_text)
|
|
|
|
{
|
|
|
|
j = utf8seek(utf8, 1);
|
|
|
|
strlcpy(outline, utf8, j+1);
|
|
|
|
sc->getstringsize(outline, &w, NULL);
|
|
|
|
sc->putsxy(text_margin + i*pm->text_w + (pm->text_w-w)/2,
|
|
|
|
pm->main_y, outline);
|
|
|
|
utf8 += j;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
icon_w = get_icon_width(sc->screen_type);
|
|
|
|
if (pm->leftpos > 0)
|
|
|
|
{
|
|
|
|
/* Draw nicer bitmap arrow if room, else settle for "<". */
|
|
|
|
if (text_margin >= icon_w)
|
|
|
|
{
|
|
|
|
screen_put_icon_with_offset(sc, 0, 0,
|
|
|
|
(text_margin - icon_w) / 2,
|
|
|
|
pm->main_y, Icon_Reverse_Cursor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sc->getstringsize("<", &w, NULL);
|
|
|
|
sc->putsxy(text_margin - w, pm->main_y, "<");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state->len_utf8 - pm->leftpos > pm->max_chars_text)
|
|
|
|
{
|
|
|
|
/* Draw nicer bitmap arrow if room, else settle for ">". */
|
|
|
|
if (text_margin >= icon_w)
|
|
|
|
{
|
|
|
|
screen_put_icon_with_offset(sc, 0, 0,
|
|
|
|
sc_w - (text_margin + icon_w) / 2,
|
|
|
|
pm->main_y, Icon_Cursor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sc->putsxy(sc_w - text_margin, pm->main_y, ">");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cursor */
|
|
|
|
i = text_margin + pm->curpos * pm->text_w;
|
|
|
|
|
|
|
|
if (state->cur_blink)
|
|
|
|
sc->vline(i, pm->main_y, pm->main_y + pm->font_h - 1);
|
|
|
|
|
|
|
|
if (state->hangul) /* draw underbar */
|
|
|
|
sc->hline(i - pm->text_w, i, pm->main_y + pm->font_h - 1);
|
|
|
|
|
|
|
|
if (pm->line_edit)
|
|
|
|
{
|
|
|
|
sc->set_drawmode(DRMODE_COMPLEMENT);
|
|
|
|
sc->fillrect(0, y + 2, sc_w, pm->font_h + 2);
|
|
|
|
sc->set_drawmode(DRMODE_SOLID);
|
|
|
|
}
|
|
|
|
}
|
2010-02-25 06:40:36 +00:00
|
|
|
|
|
|
|
/* inserts the selected char */
|
|
|
|
static void kbd_insert_selected(struct keyboard_parameters *pm,
|
|
|
|
struct edit_state *state)
|
|
|
|
{
|
|
|
|
/* find input char */
|
|
|
|
unsigned short ch = get_kbd_ch(pm);
|
|
|
|
|
|
|
|
/* check for hangul input */
|
|
|
|
if (ch >= 0x3131 && ch <= 0x3163)
|
|
|
|
{
|
|
|
|
unsigned short tmp;
|
|
|
|
|
|
|
|
if (!state->hangul)
|
|
|
|
{
|
|
|
|
state->hlead = state->hvowel = state->htail = 0;
|
|
|
|
state->hangul = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!state->hvowel)
|
|
|
|
{
|
|
|
|
state->hvowel = ch;
|
|
|
|
}
|
|
|
|
else if (!state->htail)
|
|
|
|
{
|
|
|
|
state->htail = ch;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* previous hangul complete */
|
|
|
|
/* check whether tail is actually lead of next char */
|
|
|
|
tmp = hangul_join(state->htail, ch, 0);
|
|
|
|
|
|
|
|
if (tmp != 0xfffd)
|
|
|
|
{
|
|
|
|
tmp = hangul_join(state->hlead, state->hvowel, 0);
|
|
|
|
kbd_delchar(state);
|
|
|
|
kbd_inschar(state, tmp);
|
|
|
|
/* insert dummy char */
|
|
|
|
kbd_inschar(state, ' ');
|
|
|
|
state->hlead = state->htail;
|
|
|
|
state->hvowel = ch;
|
|
|
|
state->htail = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
state->hvowel = state->htail = 0;
|
|
|
|
state->hlead = ch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* combine into hangul */
|
|
|
|
tmp = hangul_join(state->hlead, state->hvowel, state->htail);
|
|
|
|
|
|
|
|
if (tmp != 0xfffd)
|
|
|
|
{
|
|
|
|
kbd_delchar(state);
|
|
|
|
ch = tmp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
state->hvowel = state->htail = 0;
|
|
|
|
state->hlead = ch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
state->hangul = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* insert char */
|
|
|
|
kbd_inschar(state, ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void kbd_backspace(struct edit_state *state)
|
|
|
|
{
|
|
|
|
unsigned short ch;
|
|
|
|
if (state->hangul)
|
|
|
|
{
|
|
|
|
if (state->htail)
|
|
|
|
state->htail = 0;
|
|
|
|
else if (state->hvowel)
|
|
|
|
state->hvowel = 0;
|
|
|
|
else
|
|
|
|
state->hangul = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
kbd_delchar(state);
|
|
|
|
|
|
|
|
if (state->hangul)
|
|
|
|
{
|
|
|
|
if (state->hvowel)
|
|
|
|
ch = hangul_join(state->hlead, state->hvowel, state->htail);
|
|
|
|
else
|
|
|
|
ch = state->hlead;
|
|
|
|
kbd_inschar(state, ch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void kbd_move_cursor(struct edit_state *state, int dir)
|
|
|
|
{
|
|
|
|
state->hangul = false;
|
|
|
|
state->editpos += dir;
|
|
|
|
|
|
|
|
if (state->editpos >= 0 && state->editpos <= state->len_utf8)
|
|
|
|
{
|
|
|
|
state->changed = CHANGED_CURSOR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
state->editpos -= dir;
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
if (global_settings.talk_menu)
|
|
|
|
pcmbuf_beep(1000, 150, 1500);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-09 12:08:25 +00:00
|
|
|
static void kbd_move_picker_horizontal(struct keyboard_parameters *pm,
|
|
|
|
struct edit_state *state, int dir)
|
|
|
|
{
|
|
|
|
state->changed = CHANGED_PICKER;
|
|
|
|
|
|
|
|
pm->x += dir;
|
|
|
|
if (pm->x < 0)
|
|
|
|
{
|
|
|
|
if (--pm->page < 0)
|
|
|
|
pm->page = pm->pages - 1;
|
|
|
|
pm->x = pm->max_chars - 1;
|
|
|
|
}
|
|
|
|
else if (pm->x >= pm->max_chars)
|
|
|
|
{
|
|
|
|
if (++pm->page >= pm->pages)
|
|
|
|
pm->page = 0;
|
|
|
|
pm->x = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-25 06:40:36 +00:00
|
|
|
static void kbd_move_picker_vertical(struct keyboard_parameters *pm,
|
|
|
|
struct edit_state *state, int dir)
|
|
|
|
{
|
|
|
|
state->changed = CHANGED_PICKER;
|
2010-06-09 12:08:25 +00:00
|
|
|
|
2010-02-25 06:40:36 +00:00
|
|
|
#ifdef HAVE_MORSE_INPUT
|
|
|
|
if (state->morse_mode)
|
|
|
|
{
|
|
|
|
pm->line_edit = !pm->line_edit;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_MORSE_INPUT */
|
2010-06-09 12:08:25 +00:00
|
|
|
|
2010-02-25 06:40:36 +00:00
|
|
|
pm->y += dir;
|
|
|
|
if (pm->line_edit)
|
|
|
|
{
|
|
|
|
pm->y = (dir > 0 ? 0 : pm->lines - 1);
|
|
|
|
pm->line_edit = false;
|
|
|
|
}
|
|
|
|
else if (pm->y < 0 || pm->y >= pm->lines)
|
|
|
|
{
|
|
|
|
pm->line_edit = true;
|
|
|
|
}
|
|
|
|
}
|