1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Björn Stenberg
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
30 #include "rbunicode.h"
31 #include "buttonbar.h"
42 #include "appevents.h"
49 #define DEFAULT_MARGIN 6
50 #define KBD_BUF_SIZE 500
52 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
53 (CONFIG_KEYPAD == IRIVER_H300_PAD)
54 #define KBD_CURSOR_KEYS /* certain key combos move the cursor even if not
56 #define KBD_MODES /* I-Rivers can use picker, line edit and cursor keys */
57 #define KBD_MORSE_INPUT /* I-Rivers have a Morse input mode */
59 #elif CONFIG_KEYPAD == ONDIO_PAD /* restricted Ondio keypad */
60 #define KBD_MODES /* Ondio uses 2 modes, picker and line edit */
62 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) \
63 || (CONFIG_KEYPAD == IPOD_4G_PAD)
64 #define KBD_MODES /* iPod uses 2 modes, picker and line edit */
65 #define KBD_MORSE_INPUT
67 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
68 #define KBD_MODES /* iFP7xx uses 2 modes, picker and line edit */
70 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD) || (CONFIG_KEYPAD == IAUDIO_M3_PAD)
71 #define KBD_MODES /* iAudios use 2 modes, picker and line edit */
73 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
74 #define KBD_MODES /* iriver H10 uses 2 modes, picker and line edit */
75 #define KBD_MORSE_INPUT
77 #elif CONFIG_KEYPAD == GIGABEAT_PAD
78 #define KBD_CURSOR_KEYS
80 #define KBD_MORSE_INPUT
82 #elif CONFIG_KEYPAD == SANSA_E200_PAD \
83 || CONFIG_KEYPAD == SANSA_FUZE_PAD \
84 || CONFIG_KEYPAD == SANSA_C200_PAD \
85 || CONFIG_KEYPAD == SAMSUNG_YH_PAD
86 #define KBD_CURSOR_KEYS
89 #elif CONFIG_KEYPAD == MROBE100_PAD
90 #define KBD_MORSE_INPUT
93 struct keyboard_parameters
95 const unsigned char* default_kbd
;
97 unsigned short kbd_buf
[KBD_BUF_SIZE
];
121 unsigned short hlead
, hvowel
, htail
;
124 static struct keyboard_parameters kbd_param
[NB_SCREENS
];
125 static bool kbd_loaded
= false;
127 #ifdef KBD_MORSE_INPUT
128 /* FIXME: We should put this to a configuration file. */
129 static const char *morse_alphabets
=
130 "abcdefghijklmnopqrstuvwxyz1234567890,.?-@ ";
131 static const unsigned char morse_codes
[] = {
132 0x05,0x18,0x1a,0x0c,0x02,0x12,0x0e,0x10,0x04,0x17,0x0d,0x14,0x07,
133 0x06,0x0f,0x16,0x1d,0x0a,0x08,0x03,0x09,0x11,0x0b,0x19,0x1b,0x1c,
134 0x2f,0x27,0x23,0x21,0x20,0x30,0x38,0x3c,0x3e,0x3f,
135 0x73,0x55,0x4c,0x61,0x5a,0x80 };
137 static bool morse_mode
= false;
140 /* Loads a custom keyboard into memory
141 call with NULL to reset keyboard */
142 int load_kbd(unsigned char* filename
)
146 unsigned char buf
[4];
150 struct keyboard_parameters
*pm
= &kbd_param
[l
];
151 pm
->x
= pm
->y
= pm
->page
= 0;
154 if (filename
== NULL
)
160 fd
= open_utf8(filename
, O_RDONLY
|O_BINARY
);
164 while (read(fd
, buf
, 1) == 1 && i
< KBD_BUF_SIZE
)
166 /* check how many bytes to read for this character */
167 static const unsigned char sizes
[4] = { 0x80, 0xe0, 0xf0, 0xf5 };
171 for (count
= 0; count
< ARRAYLEN(sizes
); count
++)
173 if (buf
[0] < sizes
[count
])
177 if (count
>= ARRAYLEN(sizes
))
178 continue; /* Invalid size. */
180 if (read(fd
, &buf
[1], count
) != (ssize_t
)count
)
187 utf8decode(buf
, &ch
);
189 kbd_param
[l
].kbd_buf
[i
] = ch
;
191 if (ch
!= 0xFEFF && ch
!= '\r') /*skip BOM & carriage returns */
201 kbd_param
[l
].nchars
= i
;
206 /* helper function to spell a char if voice UI is enabled */
207 static void kbd_spellchar(unsigned short c
)
209 if (global_settings
.talk_menu
) /* voice UI? */
211 unsigned char tmp
[5];
212 /* store char to pass to talk_spell */
213 unsigned char* utf8
= utf8encode(c
, tmp
);
217 talk_id(VOICE_BLANK
, false);
219 talk_spell(tmp
, false);
224 static void say_edit(void)
226 if(global_settings
.talk_menu
)
227 talk_id(VOICE_EDIT
, false);
231 static void kbd_inschar(unsigned char* text
, int buflen
,
232 int* editpos
, unsigned short ch
)
235 unsigned char tmp
[4];
239 k
= utf8length(text
);
240 utf8
= utf8encode(ch
, tmp
);
241 j
= (long)utf8
- (long)tmp
;
243 if (len
+ j
< buflen
)
245 for (i
= len
+j
; k
>= *editpos
; i
--)
248 if ((text
[i
] & MASK
) != COMP
)
259 static void kbd_delchar(unsigned char* text
, int* editpos
)
266 utf8
= text
+ utf8seek(text
, *editpos
);
273 while ((*utf8
& MASK
) == COMP
);
286 /* Lookup k value based on state of param (pm) */
287 static unsigned short get_kbd_ch(const struct keyboard_parameters
*pm
)
289 int k
= (pm
->page
*pm
->lines
+ pm
->y
)*pm
->max_chars
+ pm
->x
;
290 return (k
< pm
->nchars
)? pm
->kbd_buf
[k
]: ' ';
293 int kbd_input(char* text
, int buflen
)
297 /* This seems to keep the sizes for ARM way down */
298 struct keyboard_parameters
* volatile param
= kbd_param
;
300 struct keyboard_parameters
* const param
= kbd_param
;
302 int l
; /* screen loop variable */
303 int editpos
; /* Edit position on all screens */
304 const int statusbar_size
= 0;
307 bool cur_blink
= true; /* Cursor on/off flag */
308 int ret
= 0; /* assume success */
309 #ifdef KBD_MORSE_INPUT
310 bool morse_reading
= false;
311 unsigned char morse_code
= 0;
314 int oldbars
= viewportmanager_set_statusbar(VP_SB_HIDE_ALL
);
317 struct keyboard_parameters
*pm
= ¶m
[l
];
318 #if LCD_WIDTH >= 160 && LCD_HEIGHT >= 96
319 struct screen
*sc
= &screens
[l
];
321 if (sc
->getwidth() >= 160 && sc
->getheight() >= 96)
324 "ABCDEFG abcdefg !?\" @#$%+'\n"
325 "HIJKLMN hijklmn 789 &_()-`\n"
326 "OPQRSTU opqrstu 456 §|{}/<\n"
327 "VWXYZ., vwxyz.,0123 ~=[]*>\n"
328 "ÀÁÂÃÄÅÆ ÌÍÎÏ ÈÉÊË ¢£¤¥¦§©®\n"
329 "àáâãäåæ ìíîï èéêë «»°ºª¹²³\n"
330 "ÓÒÔÕÖØ ÇÐÞÝß ÙÚÛÜ ¯±×÷¡¿µ·\n"
331 "òóôõöø çðþýÿ ùúûü ¼½¾¬¶¨:;";
333 pm
->DEFAULT_LINES
= 8;
336 #endif /* LCD_WIDTH >= 160 && LCD_HEIGHT >= 96 */
339 "ABCDEFG !?\" @#$%+'\n"
340 "HIJKLMN 789 &_()-`\n"
341 "OPQRSTU 456 §|{}/<\n"
342 "VWXYZ.,0123 ~=[]*>\n"
344 "abcdefg ¢£¤¥¦§©®¬\n"
345 "hijklmn «»°ºª¹²³¶\n"
346 "opqrstu ¯±×÷¡¿µ·¨\n"
349 "ÀÁÂÃÄÅÆ ÌÍÎÏ ÈÉÊË\n"
350 "àáâãäåæ ìíîï èéêë\n"
351 "ÓÒÔÕÖØ ÇÐÞÝß ÙÚÛÜ\n"
354 pm
->DEFAULT_LINES
= 4;
359 #ifdef HAVE_BUTTONBAR
360 struct gui_buttonbar buttonbar
;
361 bool buttonbar_config
= global_settings
.buttonbar
;
363 global_settings
.buttonbar
= true;
364 gui_buttonbar_init(&buttonbar
);
367 gui_buttonbar_set_display(&buttonbar
, &screens
[l
]);
372 struct keyboard_parameters
*pm
= ¶m
[l
];
376 /* Copy default keyboard to buffer */
377 const unsigned char *p
= pm
->default_kbd
;
380 pm
->curfont
= FONT_SYSFIXED
;
383 p
= utf8decode(p
, &pm
->kbd_buf
[i
++]);
389 pm
->curfont
= FONT_UI
;
395 struct keyboard_parameters
*pm
= ¶m
[l
];
396 struct screen
*sc
= &screens
[l
];
399 pm
->font
= font_get(pm
->curfont
);
400 pm
->font_h
= pm
->font
->height
;
402 /* check if FONT_UI fits the screen */
403 if (2*pm
->font_h
+ 3 + statusbar_size
+
404 BUTTONBAR_HEIGHT
> sc
->getheight())
406 pm
->font
= font_get(FONT_SYSFIXED
);
407 pm
->font_h
= pm
->font
->height
;
408 pm
->curfont
= FONT_SYSFIXED
;
411 /* find max width of keyboard glyphs.
412 * since we're going to be adding spaces,
413 * max width is at least their width */
414 pm
->font_w
= font_get_width(pm
->font
, ' ');
415 for (i
= 0; i
< pm
->nchars
; i
++)
417 if (pm
->kbd_buf
[i
] != '\n')
419 w
= font_get_width(pm
->font
, pm
->kbd_buf
[i
]);
428 struct keyboard_parameters
*pm
= ¶m
[l
];
429 struct screen
*sc
= &screens
[l
];
432 pm
->max_chars
= sc
->getwidth() / pm
->font_w
;
434 /* Pad lines with spaces */
435 while (i
< pm
->nchars
)
437 if (pm
->kbd_buf
[i
] == '\n')
439 int k
= pm
->max_chars
- i
% ( pm
->max_chars
) - 1;
442 if (k
== pm
->max_chars
- 1)
446 for (j
= i
; j
< pm
->nchars
; j
++)
448 pm
->kbd_buf
[j
] = pm
->kbd_buf
[j
+ 1];
453 if (pm
->nchars
+ k
- 1 >= KBD_BUF_SIZE
)
454 { /* We don't want to overflow the buffer */
455 k
= KBD_BUF_SIZE
- pm
->nchars
;
458 for (j
= pm
->nchars
+ k
- 1; j
> i
+ k
; j
--)
460 pm
->kbd_buf
[j
] = pm
->kbd_buf
[j
-k
];
468 pm
->kbd_buf
[i
++] = ' ';
479 /* Find max width for text string */
482 struct keyboard_parameters
*pm
= ¶m
[l
];
483 struct screen
*sc
= &screens
[l
];
484 int icon_w
, sc_w
, sc_h
;
486 pm
->text_w
= pm
->font_w
;
492 utf8
= (unsigned char*)utf8decode(utf8
, &ch
);
493 w
= font_get_width(pm
->font
, ch
);
498 icon_w
= get_icon_width(l
);
499 sc_w
= sc
->getwidth();
500 sc_h
= sc
->getheight();
501 pm
->max_chars_text
= (sc_w
- icon_w
* 2 - 2) / pm
->text_w
;
502 if(pm
->max_chars_text
< 3 && icon_w
> pm
->text_w
)
503 pm
->max_chars_text
= sc_w
/ pm
->text_w
- 2;
507 pm
->lines
= pm
->DEFAULT_LINES
;
508 pm
->keyboard_margin
= DEFAULT_MARGIN
;
512 pm
->lines
= (sc_h
- BUTTONBAR_HEIGHT
- statusbar_size
)
514 pm
->keyboard_margin
= sc_h
- BUTTONBAR_HEIGHT
- statusbar_size
515 - (pm
->lines
+1)*pm
->font_h
;
517 if (pm
->keyboard_margin
< 3)
520 pm
->keyboard_margin
+= pm
->font_h
;
523 if (pm
->keyboard_margin
> 6)
524 pm
->keyboard_margin
= 6;
527 pm
->pages
= (pm
->nchars
+ (pm
->lines
*pm
->max_chars
-1))
528 / (pm
->lines
*pm
->max_chars
);
530 if (pm
->pages
== 1 && kbd_loaded
)
531 pm
->lines
= (pm
->nchars
+ pm
->max_chars
- 1) / pm
->max_chars
;
533 pm
->main_y
= pm
->font_h
*pm
->lines
+ pm
->keyboard_margin
+ statusbar_size
;
535 pm
->keyboard_margin
-= pm
->keyboard_margin
/2;
537 #ifdef KBD_MORSE_INPUT
538 pm
->old_main_y
= pm
->main_y
;
540 pm
->main_y
= sc_h
- pm
->font_h
;
544 /* Initial edit position is after last character */
545 editpos
= utf8length(text
);
547 if (global_settings
.talk_menu
) /* voice UI? */
548 talk_spell(text
, true); /* spell initial text */
553 /* These declarations are assigned to the screen on which the key
554 action occurred - pointers save a lot of space over array notation
555 when accessing the same array element countless times */
560 const int button_screen
= 0;
562 struct keyboard_parameters
*pm
;
565 int len_utf8
= utf8length(text
);
568 screens
[l
].clear_display();
570 #ifdef KBD_MORSE_INPUT
575 /* declare scoped pointers inside screen loops - hide the
576 declarations from previous block level */
577 const int w
= 6; /* sysfixed font width */
578 struct screen
*sc
= &screens
[l
];
581 /* Draw morse code screen with sysfont */
582 sc
->setfont(FONT_SYSFIXED
);
587 /* Draw morse code table with code descriptions. */
588 for (i
= 0; morse_alphabets
[i
] != '\0'; i
++)
593 outline
[0] = morse_alphabets
[i
];
594 sc
->putsxy(x
, y
, outline
);
596 for (j
= 0; (morse_codes
[i
] >> j
) > 0x01; j
++) ;
600 for (j
= 0; j
< morse_len
; j
++)
602 if ((morse_codes
[i
] >> (morse_len
-j
-1)) & 0x01)
603 sc
->fillrect(x
+ j
*4, y
+ 2, 3, 4);
605 sc
->fillrect(x
+ j
*4, y
+ 3, 1, 2);
609 if (x
+ w
*6 >= sc
->getwidth())
612 y
+= 8; /* sysfixed font height */
618 #endif /* KBD_MORSE_INPUT */
623 struct keyboard_parameters
*pm
= ¶m
[l
];
624 struct screen
*sc
= &screens
[l
];
627 sc
->setfont(pm
->curfont
);
629 k
= pm
->page
*pm
->max_chars
*pm
->lines
;
631 for (i
= j
= 0; j
< pm
->lines
&& k
< pm
->nchars
; k
++)
634 utf8
= utf8encode(pm
->kbd_buf
[k
], outline
);
637 sc
->getstringsize(outline
, &w
, NULL
);
638 sc
->putsxy(i
*pm
->font_w
+ (pm
->font_w
-w
) / 2,
639 j
*pm
->font_h
+ statusbar_size
, outline
);
641 if (++i
>= pm
->max_chars
)
652 struct keyboard_parameters
*pm
= ¶m
[l
];
653 struct screen
*sc
= &screens
[l
];
654 int i
= 0, j
= 0, icon_w
;
655 int text_w
= pm
->text_w
;
656 int sc_w
= sc
->getwidth();
657 int text_margin
= (sc_w
- text_w
* pm
->max_chars_text
) / 2;
659 /* Clear text area one pixel above separator line so any overdraw
661 sc
->set_drawmode(DRMODE_SOLID
| DRMODE_INVERSEVID
);
662 sc
->fillrect(0, pm
->main_y
- pm
->keyboard_margin
- 1,
663 sc_w
, pm
->font_h
+ 4);
664 sc
->set_drawmode(DRMODE_SOLID
);
666 sc
->hline(0, sc_w
- 1, pm
->main_y
- pm
->keyboard_margin
);
668 /* write out the text */
669 sc
->setfont(pm
->curfont
);
671 pm
->curpos
= MIN(editpos
, pm
->max_chars_text
672 - MIN(len_utf8
- editpos
, 2));
673 pm
->leftpos
= editpos
- pm
->curpos
;
674 utf8
= text
+ utf8seek(text
, pm
->leftpos
);
676 while (*utf8
&& i
< pm
->max_chars_text
)
678 outline
[j
++] = *utf8
++;
680 if ((*utf8
& MASK
) != COMP
)
685 sc
->getstringsize(outline
, &w
, NULL
);
686 sc
->putsxy(text_margin
+ i
*text_w
+ (text_w
-w
)/2,
687 pm
->main_y
, outline
);
692 icon_w
= get_icon_width(l
);
695 /* Draw nicer bitmap arrow if room, else settle for "<". */
696 if (text_margin
>= icon_w
)
698 screen_put_icon_with_offset(sc
, 0, 0,
699 (text_margin
- icon_w
) / 2,
700 pm
->main_y
, Icon_Reverse_Cursor
);
705 sc
->getstringsize("<", &w
, NULL
);
706 sc
->putsxy(text_margin
- w
, pm
->main_y
, "<");
710 if (len_utf8
- pm
->leftpos
> pm
->max_chars_text
)
712 /* Draw nicer bitmap arrow if room, else settle for ">". */
713 if (text_margin
>= icon_w
)
715 screen_put_icon_with_offset(sc
, 0, 0,
716 sc_w
- (text_margin
+ icon_w
) / 2,
717 pm
->main_y
, Icon_Cursor
);
721 sc
->putsxy(sc_w
- text_margin
, pm
->main_y
, ">");
726 i
= text_margin
+ pm
->curpos
* text_w
;
729 sc
->vline(i
, pm
->main_y
, pm
->main_y
+ pm
->font_h
- 1);
731 if (pm
->hangul
) /* draw underbar */
732 sc
->hline(i
- text_w
, i
, pm
->main_y
+ pm
->font_h
- 1);
735 cur_blink
= !cur_blink
;
737 #ifdef HAVE_BUTTONBAR
738 /* draw the button bar */
739 gui_buttonbar_set(&buttonbar
, "Shift", "OK", "Del");
740 gui_buttonbar_draw(&buttonbar
);
745 struct keyboard_parameters
*pm
= ¶m
[l
];
746 struct screen
*sc
= &screens
[l
];
748 sc
->set_drawmode(DRMODE_COMPLEMENT
);
751 sc
->fillrect(0, pm
->main_y
- pm
->keyboard_margin
+ 2,
752 sc
->getwidth(), pm
->font_h
+ 2);
753 else /* highlight the key that has focus */
755 #ifdef KBD_MORSE_INPUT
758 sc
->fillrect(pm
->font_w
*pm
->x
,
759 statusbar_size
+ pm
->font_h
*pm
->y
,
760 pm
->font_w
, pm
->font_h
);
761 sc
->set_drawmode(DRMODE_SOLID
);
767 button
= get_action(CONTEXT_KEYBOARD
, HZ
/2);
769 button_screen
= (get_action_statuscode(NULL
) & ACTION_REMOTE
) ? 1 : 0;
771 pm
= ¶m
[button_screen
];
772 sc
= &screens
[button_screen
];
774 #if defined(KBD_MODES) || defined(KBD_MORSE_INPUT)
775 /* Remap some buttons to allow to move
776 * cursor in line edit mode and morse mode. */
777 #if defined(KBD_MODES) && defined(KBD_MORSE_INPUT)
778 if (pm
->line_edit
|| morse_mode
)
779 #elif defined(KBD_MODES)
781 #else /* defined(KBD_MORSE_INPUT) */
785 if (button
== ACTION_KBD_LEFT
)
786 button
= ACTION_KBD_CURSOR_LEFT
;
787 if (button
== ACTION_KBD_RIGHT
)
788 button
= ACTION_KBD_CURSOR_RIGHT
;
790 #endif /* defined(KBD_MODES) || defined(KBD_MORSE_INPUT) */
794 case ACTION_KBD_ABORT
:
799 case ACTION_KBD_PAGE_FLIP
:
801 #ifdef KBD_MORSE_INPUT
805 if (++pm
->page
>= pm
->pages
)
813 #ifdef KBD_MORSE_INPUT
814 case ACTION_KBD_MORSE_INPUT
:
815 morse_mode
= !morse_mode
;
819 struct keyboard_parameters
*pm
= ¶m
[l
];
820 struct screen
*sc
= &screens
[l
];
824 pm
->old_main_y
= pm
->main_y
;
825 pm
->main_y
= sc
->getheight() - pm
->font_h
;
829 pm
->main_y
= pm
->old_main_y
;
832 /* FIXME: We should talk something like Morse mode.. */
834 #endif /* KBD_MORSE_INPUT */
836 case ACTION_KBD_RIGHT
:
837 if (++pm
->x
>= pm
->max_chars
)
839 #ifndef KBD_PAGE_FLIP
840 /* no dedicated flip key - flip page on wrap */
841 if (++pm
->page
>= pm
->pages
)
851 case ACTION_KBD_LEFT
:
854 #ifndef KBD_PAGE_FLIP
855 /* no dedicated flip key - flip page on wrap */
857 pm
->page
= pm
->pages
- 1;
859 pm
->x
= pm
->max_chars
- 1;
866 case ACTION_KBD_DOWN
:
867 #ifdef KBD_MORSE_INPUT
871 pm
->line_edit
= !pm
->line_edit
;
880 #endif /* KBD_MORSE_INPUT */
886 pm
->line_edit
= false;
890 if (++pm
->y
>= pm
->lines
)
893 pm
->line_edit
= true;
910 #ifdef KBD_MORSE_INPUT
914 pm
->line_edit
= !pm
->line_edit
;
923 #endif /* KBD_MORSE_INPUT */
928 pm
->y
= pm
->lines
- 1;
929 pm
->line_edit
= false;
936 pm
->line_edit
= true;
940 pm
->y
= pm
->lines
- 1;
952 case ACTION_KBD_DONE
:
953 /* accepts what was entered and continues */
958 #ifdef KBD_MORSE_INPUT
959 case ACTION_KBD_MORSE_SELECT
:
960 if (morse_mode
&& morse_reading
)
963 if ((current_tick
- morse_tick
) > HZ
/5)
968 #endif /* KBD_MORSE_INPUT */
970 case ACTION_KBD_SELECT
:
971 #ifdef KBD_MORSE_INPUT
973 if (morse_mode
&& !pm
->line_edit
)
978 morse_tick
= current_tick
;
982 morse_reading
= true;
987 #endif /* KBD_MORSE_INPUT */
989 /* inserts the selected char */
992 { /* select doubles as backspace in line_edit */
1003 kbd_delchar(text
, &editpos
);
1008 ch
= hangul_join(pm
->hlead
, pm
->hvowel
, pm
->htail
);
1011 kbd_inschar(text
, buflen
, &editpos
, ch
);
1015 #endif /* KBD_MODES */
1017 /* find input char */
1018 ch
= get_kbd_ch(pm
);
1020 /* check for hangul input */
1021 if (ch
>= 0x3131 && ch
<= 0x3163)
1027 pm
->hlead
= pm
->hvowel
= pm
->htail
= 0;
1035 else if (!pm
->htail
)
1040 { /* previous hangul complete */
1041 /* check whether tail is actually lead of next char */
1042 tmp
= hangul_join(pm
->htail
, ch
, 0);
1046 tmp
= hangul_join(pm
->hlead
, pm
->hvowel
, 0);
1047 kbd_delchar(text
, &editpos
);
1048 kbd_inschar(text
, buflen
, &editpos
, tmp
);
1049 /* insert dummy char */
1050 kbd_inschar(text
, buflen
, &editpos
, ' ');
1051 pm
->hlead
= pm
->htail
;
1057 pm
->hvowel
= pm
->htail
= 0;
1062 /* combine into hangul */
1063 tmp
= hangul_join(pm
->hlead
, pm
->hvowel
, pm
->htail
);
1067 kbd_delchar(text
, &editpos
);
1072 pm
->hvowel
= pm
->htail
= 0;
1082 kbd_inschar(text
, buflen
, &editpos
, ch
);
1085 if (global_settings
.talk_menu
) /* voice UI? */
1086 talk_spell(text
, false);
1088 /* speak revised text */
1091 #if !defined (KBD_MODES) || defined (KBD_CURSOR_KEYS)
1092 case ACTION_KBD_BACKSPACE
:
1097 else if (pm
->hvowel
)
1103 kbd_delchar(text
, &editpos
);
1108 ch
= hangul_join(pm
->hlead
, pm
->hvowel
, pm
->htail
);
1111 kbd_inschar(text
, buflen
, &editpos
, ch
);
1114 if (global_settings
.talk_menu
) /* voice UI? */
1115 talk_spell(text
, false); /* speak revised text */
1117 #endif /* !defined (KBD_MODES) || defined (KBD_CURSOR_KEYS) */
1119 case ACTION_KBD_CURSOR_RIGHT
:
1122 if (editpos
< len_utf8
)
1124 int c
= utf8seek(text
, ++editpos
);
1125 kbd_spellchar(text
[c
]);
1127 #if CONFIG_CODEC == SWCODEC
1128 else if (global_settings
.talk_menu
)
1129 pcmbuf_beep(1000, 150, 1500);
1133 case ACTION_KBD_CURSOR_LEFT
:
1138 int c
= utf8seek(text
, --editpos
);
1139 kbd_spellchar(text
[c
]);
1141 #if CONFIG_CODEC == SWCODEC
1142 else if (global_settings
.talk_menu
)
1143 pcmbuf_beep(1000, 150, 1500);
1148 #ifdef KBD_MORSE_INPUT
1152 logf("Morse: 0x%02x", morse_code
);
1153 morse_reading
= false;
1155 for (j
= 0; morse_alphabets
[j
] != '\0'; j
++)
1157 if (morse_codes
[j
] == morse_code
)
1161 if (morse_alphabets
[j
] == '\0')
1163 logf("Morse code not found");
1167 /* turn off hangul input */
1169 param
[l
].hangul
= false;
1170 kbd_inschar(text
, buflen
, &editpos
, morse_alphabets
[j
]);
1172 if (global_settings
.talk_menu
) /* voice UI? */
1173 talk_spell(text
, false); /* speak revised text */
1175 #endif /* KBD_MORSE_INPUT */
1179 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
1182 screens
[l
].setfont(FONT_SYSFIXED
);
1188 if (button
!= BUTTON_NONE
)
1194 #ifdef HAVE_BUTTONBAR
1195 global_settings
.buttonbar
= buttonbar_config
;
1199 splash(HZ
/2, ID2P(LANG_CANCEL
));
1202 screens
[l
].setfont(FONT_UI
);
1203 viewportmanager_set_statusbar(oldbars
);
1204 send_event(GUI_EVENT_REFRESH
, NULL
);