1
0
Fork 0
forked from len0rd/rockbox

Optimize keyboard code a bit

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9391 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Frank Dischner 2006-03-31 13:59:04 +00:00
parent dcee4d5459
commit 367b8ecd02

View file

@ -630,11 +630,8 @@ int kbd_input(char* text, int buflen)
#ifdef KBD_MODES #ifdef KBD_MODES
if (line_edit) /* right doubles as cursor_right in line_edit */ if (line_edit) /* right doubles as cursor_right in line_edit */
{ {
if (hangul) { if (hangul)
hangul = false; hangul = false;
hlead=hvowel=htail=0;
break;
}
if (editpos < len_utf8) if (editpos < len_utf8)
{ {
editpos++; editpos++;
@ -667,11 +664,8 @@ int kbd_input(char* text, int buflen)
#ifdef KBD_MODES #ifdef KBD_MODES
if (line_edit) /* left doubles as cursor_left in line_edit */ if (line_edit) /* left doubles as cursor_left in line_edit */
{ {
if (hangul) { if (hangul)
hangul = false; hangul = false;
hlead=hvowel=htail=0;
break;
}
if (editpos) if (editpos)
{ {
editpos--; editpos--;
@ -803,18 +797,16 @@ int kbd_input(char* text, int buflen)
#ifdef KBD_MODES #ifdef KBD_MODES
if (line_edit) { /* select doubles as backspace in line_edit */ if (line_edit) { /* select doubles as backspace in line_edit */
if (hangul) { if (hangul) {
if (htail != 0) if (htail)
htail = 0; htail = 0;
else if (hvowel != 0) else if (hvowel)
hvowel = 0; hvowel = 0;
else { else
hlead = 0;
hangul = false; hangul = false;
}
} }
kbd_delchar(text, &editpos); kbd_delchar(text, &editpos);
if (hangul) { if (hangul) {
if (hvowel != 0) if (hvowel)
ch = hangul_join(hlead, hvowel, htail); ch = hangul_join(hlead, hvowel, htail);
else else
ch = hlead; ch = hlead;
@ -833,59 +825,40 @@ int kbd_input(char* text, int buflen)
/* check for hangul input */ /* check for hangul input */
if (ch >= 0x3131 && ch <= 0x3163) { if (ch >= 0x3131 && ch <= 0x3163) {
if (hangul) { if (!hangul) {
if ((hvowel == 0) && (jamo_table[ch-0x3131][1] != 0)) { hlead=hvowel=htail=0;
hvowel = ch;
ch = hangul_join(hlead, hvowel, htail);
kbd_delchar(text, &editpos);
}
else if ((htail == 0) && (hvowel != 0) && (jamo_table[ch-0x3131][2] != 0)) {
htail = ch;
/* combine into hangul */
ch = hangul_join(hlead, hvowel, htail);
kbd_delchar(text, &editpos);
}
else { /* invalid following char or hangul complete */
/* check whether tail is actually lead of next char */
if (htail != 0 && (jamo_table[htail-0x3131][0] != 0)
&& (jamo_table[ch-0x3131][1] != 0)) {
tmp = hangul_join(hlead, hvowel, 0);
kbd_delchar(text, &editpos);
kbd_inschar(text, buflen, &editpos, tmp);
hlead = htail;
hvowel = ch;
htail = 0;
ch = hangul_join(hlead, hvowel, htail);
}
else if (hlead != 0 && hvowel != 0) {
/* finish previous hangul */
tmp = hangul_join(hlead, hvowel, htail);
kbd_delchar(text, &editpos);
kbd_inschar(text, buflen, &editpos, tmp);
hlead=hvowel=htail=0;
/* start of new hangul? */
if (jamo_table[ch-0x3131][0] != 0) {
hlead = ch;
}
else
hangul = false;
}
}
}
else if (jamo_table[ch-0x3131][0] != 0) {
hlead = ch;
hangul = true; hangul = true;
} }
} if (!hvowel)
else if (hangul) { hvowel = ch;
/* finish previous hangul */ else if (!htail)
if (hlead != 0 && hvowel != 0) { htail = ch;
tmp = hangul_join(hlead, hvowel, htail); else { /* previous hangul complete */
kbd_delchar(text, &editpos); /* check whether tail is actually lead of next char */
kbd_inschar(text, buflen, &editpos, tmp); if ((tmp = hangul_join(htail, ch, 0)) != 0xfffd) {
tmp = hangul_join(hlead, hvowel, 0);
kbd_delchar(text, &editpos);
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;
}
} }
/* combine into hangul */
if ((tmp = hangul_join(hlead, hvowel, htail)) != 0xfffd) {
kbd_delchar(text, &editpos);
ch = tmp;
} else {
hvowel=htail=0;
hlead = ch;
}
} else {
hangul = false; hangul = false;
hlead=hvowel=htail=0;
} }
/* insert char */ /* insert char */
kbd_inschar(text, buflen, &editpos, ch); kbd_inschar(text, buflen, &editpos, ch);
@ -898,18 +871,16 @@ int kbd_input(char* text, int buflen)
case KBD_BACKSPACE: case KBD_BACKSPACE:
case KBD_BACKSPACE | BUTTON_REPEAT: case KBD_BACKSPACE | BUTTON_REPEAT:
if (hangul) { if (hangul) {
if (htail != 0) if (htail)
htail = 0; htail = 0;
else if (hvowel != 0) else if (hvowel)
hvowel = 0; hvowel = 0;
else { else
hlead = 0;
hangul = false; hangul = false;
}
} }
kbd_delchar(text, &editpos); kbd_delchar(text, &editpos);
if (hangul) { if (hangul) {
if (hvowel != 0) if (hvowel)
ch = hangul_join(hlead, hvowel, htail); ch = hangul_join(hlead, hvowel, htail);
else else
ch = hlead; ch = hlead;
@ -921,11 +892,8 @@ int kbd_input(char* text, int buflen)
case KBD_CURSOR_RIGHT: case KBD_CURSOR_RIGHT:
case KBD_CURSOR_RIGHT | BUTTON_REPEAT: case KBD_CURSOR_RIGHT | BUTTON_REPEAT:
if (hangul) { if (hangul)
hangul = false; hangul = false;
hlead=hvowel=htail=0;
break;
}
if (editpos < len_utf8) if (editpos < len_utf8)
{ {
editpos++; editpos++;
@ -936,11 +904,8 @@ int kbd_input(char* text, int buflen)
case KBD_CURSOR_LEFT: case KBD_CURSOR_LEFT:
case KBD_CURSOR_LEFT | BUTTON_REPEAT: case KBD_CURSOR_LEFT | BUTTON_REPEAT:
if (hangul) { if (hangul)
hangul = false; hangul = false;
hlead=hvowel=htail=0;
break;
}
if (editpos) if (editpos)
{ {
editpos--; editpos--;
@ -971,11 +936,9 @@ int kbd_input(char* text, int buflen)
break ; break ;
} }
/* finish hangul char if necessary */ /* turn off hangul input */
if (hangul) { if (hangul)
hangul = false; hangul = false;
hlead=hvowel=htail=0;
}
kbd_inschar(text, buflen, &editpos, morse_alphabets[j]); kbd_inschar(text, buflen, &editpos, morse_alphabets[j]);