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 sc
->setfont(pm
->curfont
);
412 /* find max width of keyboard glyphs.
413 * since we're going to be adding spaces,
414 * max width is at least their width */
415 pm
->font_w
= font_get_width(pm
->font
, ' ');
416 for (i
= 0; i
< pm
->nchars
; i
++)
418 if (pm
->kbd_buf
[i
] != '\n')
420 w
= font_get_width(pm
->font
, pm
->kbd_buf
[i
]);
429 struct keyboard_parameters
*pm
= ¶m
[l
];
430 struct screen
*sc
= &screens
[l
];
433 pm
->max_chars
= sc
->getwidth() / pm
->font_w
;
435 /* Pad lines with spaces */
436 while (i
< pm
->nchars
)
438 if (pm
->kbd_buf
[i
] == '\n')
440 int k
= pm
->max_chars
- i
% ( pm
->max_chars
) - 1;
443 if (k
== pm
->max_chars
- 1)
447 for (j
= i
; j
< pm
->nchars
; j
++)
449 pm
->kbd_buf
[j
] = pm
->kbd_buf
[j
+ 1];
454 if (pm
->nchars
+ k
- 1 >= KBD_BUF_SIZE
)
455 { /* We don't want to overflow the buffer */
456 k
= KBD_BUF_SIZE
- pm
->nchars
;
459 for (j
= pm
->nchars
+ k
- 1; j
> i
+ k
; j
--)
461 pm
->kbd_buf
[j
] = pm
->kbd_buf
[j
-k
];
469 pm
->kbd_buf
[i
++] = ' ';
480 /* Find max width for text string */
483 struct keyboard_parameters
*pm
= ¶m
[l
];
484 struct screen
*sc
= &screens
[l
];
487 pm
->text_w
= pm
->font_w
;
493 utf8
= (unsigned char*)utf8decode(utf8
, &ch
);
494 w
= font_get_width(pm
->font
, ch
);
499 icon_w
= get_icon_width(l
);
500 pm
->max_chars_text
= (sc
->getwidth() - icon_w
* 2)
502 if(pm
->max_chars_text
< 3 && icon_w
> pm
->text_w
)
503 pm
->max_chars_text
= sc
->getwidth() / pm
->text_w
- 2;
507 pm
->lines
= pm
->DEFAULT_LINES
;
508 pm
->keyboard_margin
= DEFAULT_MARGIN
;
512 pm
->lines
= (sc
->getheight() - BUTTONBAR_HEIGHT
- statusbar_size
)
514 pm
->keyboard_margin
= sc
->getheight() - BUTTONBAR_HEIGHT
-
515 statusbar_size
- (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
->getheight() - 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(pm
->curpos
*text_w
, (pm
->curpos
+1)*text_w
,
733 pm
->main_y
+ pm
->font_h
- 1);
736 cur_blink
= !cur_blink
;
738 #ifdef HAVE_BUTTONBAR
739 /* draw the button bar */
740 gui_buttonbar_set(&buttonbar
, "Shift", "OK", "Del");
741 gui_buttonbar_draw(&buttonbar
);
746 struct keyboard_parameters
*pm
= ¶m
[l
];
747 struct screen
*sc
= &screens
[l
];
749 sc
->set_drawmode(DRMODE_COMPLEMENT
);
752 sc
->fillrect(0, pm
->main_y
- pm
->keyboard_margin
+ 2,
753 sc
->getwidth(), pm
->font_h
+ 2);
754 else /* highlight the key that has focus */
756 #ifdef KBD_MORSE_INPUT
759 sc
->fillrect(pm
->font_w
*pm
->x
,
760 statusbar_size
+ pm
->font_h
*pm
->y
,
761 pm
->font_w
, pm
->font_h
);
762 sc
->set_drawmode(DRMODE_SOLID
);
768 button
= get_action(CONTEXT_KEYBOARD
, HZ
/2);
770 button_screen
= (get_action_statuscode(NULL
) & ACTION_REMOTE
) ? 1 : 0;
772 pm
= ¶m
[button_screen
];
773 sc
= &screens
[button_screen
];
775 #if defined KBD_MORSE_INPUT && !defined KBD_MODES
778 /* Remap some buttons for morse mode. */
779 if (button
== ACTION_KBD_LEFT
)
780 button
= ACTION_KBD_CURSOR_LEFT
;
781 if (button
== ACTION_KBD_RIGHT
)
782 button
= ACTION_KBD_CURSOR_RIGHT
;
788 case ACTION_KBD_ABORT
:
793 case ACTION_KBD_PAGE_FLIP
:
795 #ifdef KBD_MORSE_INPUT
799 if (++pm
->page
>= pm
->pages
)
807 #ifdef KBD_MORSE_INPUT
808 case ACTION_KBD_MORSE_INPUT
:
809 morse_mode
= !morse_mode
;
813 struct keyboard_parameters
*pm
= ¶m
[l
];
814 struct screen
*sc
= &screens
[l
];
818 pm
->old_main_y
= pm
->main_y
;
819 pm
->main_y
= sc
->getheight() - pm
->font_h
;
823 pm
->main_y
= pm
->old_main_y
;
826 /* FIXME: We should talk something like Morse mode.. */
828 #endif /* KBD_MORSE_INPUT */
830 case ACTION_KBD_RIGHT
:
832 #ifdef KBD_MORSE_INPUT
833 /* allow cursor change in non line edit morse mode */
834 if (pm
->line_edit
|| morse_mode
)
836 /* right doubles as cursor_right in line_edit */
842 if (editpos
< len_utf8
)
844 int c
= utf8seek(text
, ++editpos
);
845 kbd_spellchar(text
[c
]);
847 #if CONFIG_CODEC == SWCODEC
848 else if (global_settings
.talk_menu
)
849 pcmbuf_beep(1000, 150, 1500);
853 #endif /* KBD_MODES */
855 #ifdef KBD_MORSE_INPUT
859 if (++pm
->x
>= pm
->max_chars
)
861 #ifndef KBD_PAGE_FLIP
862 /* no dedicated flip key - flip page on wrap */
863 if (++pm
->page
>= pm
->pages
)
874 case ACTION_KBD_LEFT
:
876 #ifdef KBD_MORSE_INPUT
877 /* allow cursor change in non line edit morse mode */
878 if (pm
->line_edit
|| morse_mode
)
880 /* left doubles as cursor_left in line_edit */
888 int c
= utf8seek(text
, --editpos
);
889 kbd_spellchar(text
[c
]);
891 #if CONFIG_CODEC == SWCODEC
892 else if (global_settings
.talk_menu
)
893 pcmbuf_beep(1000, 150, 1500);
897 #endif /* KBD_MODES */
899 #ifdef KBD_MORSE_INPUT
905 #ifndef KBD_PAGE_FLIP
906 /* no dedicated flip key - flip page on wrap */
908 pm
->page
= pm
->pages
- 1;
910 pm
->x
= pm
->max_chars
- 1;
918 case ACTION_KBD_DOWN
:
919 #ifdef KBD_MORSE_INPUT
923 pm
->line_edit
= !pm
->line_edit
;
932 #endif /* KBD_MORSE_INPUT */
938 pm
->line_edit
= false;
942 if (++pm
->y
>= pm
->lines
)
945 pm
->line_edit
= true;
962 #ifdef KBD_MORSE_INPUT
966 pm
->line_edit
= !pm
->line_edit
;
975 #endif /* KBD_MORSE_INPUT */
980 pm
->y
= pm
->lines
- 1;
981 pm
->line_edit
= false;
988 pm
->line_edit
= true;
992 pm
->y
= pm
->lines
- 1;
1004 case ACTION_KBD_DONE
:
1005 /* accepts what was entered and continues */
1010 #ifdef KBD_MORSE_INPUT
1011 case ACTION_KBD_MORSE_SELECT
:
1012 if (morse_mode
&& morse_reading
)
1015 if ((current_tick
- morse_tick
) > HZ
/5)
1020 #endif /* KBD_MORSE_INPUT */
1022 case ACTION_KBD_SELECT
:
1023 case ACTION_KBD_SELECT_REM
:
1024 #ifdef KBD_MORSE_INPUT
1026 if (morse_mode
&& !pm
->line_edit
)
1031 morse_tick
= current_tick
;
1035 morse_reading
= true;
1040 #endif /* KBD_MORSE_INPUT */
1042 /* inserts the selected char */
1045 { /* select doubles as backspace in line_edit */
1050 else if (pm
->hvowel
)
1056 kbd_delchar(text
, &editpos
);
1061 ch
= hangul_join(pm
->hlead
, pm
->hvowel
, pm
->htail
);
1064 kbd_inschar(text
, buflen
, &editpos
, ch
);
1068 #endif /* KBD_MODES */
1070 /* find input char */
1071 ch
= get_kbd_ch(pm
);
1073 /* check for hangul input */
1074 if (ch
>= 0x3131 && ch
<= 0x3163)
1080 pm
->hlead
= pm
->hvowel
= pm
->htail
= 0;
1088 else if (!pm
->htail
)
1093 { /* previous hangul complete */
1094 /* check whether tail is actually lead of next char */
1095 tmp
= hangul_join(pm
->htail
, ch
, 0);
1099 tmp
= hangul_join(pm
->hlead
, pm
->hvowel
, 0);
1100 kbd_delchar(text
, &editpos
);
1101 kbd_inschar(text
, buflen
, &editpos
, tmp
);
1102 /* insert dummy char */
1103 kbd_inschar(text
, buflen
, &editpos
, ' ');
1104 pm
->hlead
= pm
->htail
;
1110 pm
->hvowel
= pm
->htail
= 0;
1115 /* combine into hangul */
1116 tmp
= hangul_join(pm
->hlead
, pm
->hvowel
, pm
->htail
);
1120 kbd_delchar(text
, &editpos
);
1125 pm
->hvowel
= pm
->htail
= 0;
1135 kbd_inschar(text
, buflen
, &editpos
, ch
);
1138 if (global_settings
.talk_menu
) /* voice UI? */
1139 talk_spell(text
, false);
1141 /* speak revised text */
1144 #if !defined (KBD_MODES) || defined (KBD_CURSOR_KEYS)
1145 case ACTION_KBD_BACKSPACE
:
1150 else if (pm
->hvowel
)
1156 kbd_delchar(text
, &editpos
);
1161 ch
= hangul_join(pm
->hlead
, pm
->hvowel
, pm
->htail
);
1164 kbd_inschar(text
, buflen
, &editpos
, ch
);
1167 if (global_settings
.talk_menu
) /* voice UI? */
1168 talk_spell(text
, false); /* speak revised text */
1171 case ACTION_KBD_CURSOR_RIGHT
:
1174 if (editpos
< len_utf8
)
1176 int c
= utf8seek(text
, ++editpos
);
1177 kbd_spellchar(text
[c
]);
1179 #if CONFIG_CODEC == SWCODEC
1180 else if (global_settings
.talk_menu
)
1181 pcmbuf_beep(1000, 150, 1500);
1185 case ACTION_KBD_CURSOR_LEFT
:
1190 int c
= utf8seek(text
, --editpos
);
1191 kbd_spellchar(text
[c
]);
1193 #if CONFIG_CODEC == SWCODEC
1194 else if (global_settings
.talk_menu
)
1195 pcmbuf_beep(1000, 150, 1500);
1198 #endif /* !defined (KBD_MODES) || defined (KBD_CURSOR_KEYS) */
1201 #ifdef KBD_MORSE_INPUT
1205 logf("Morse: 0x%02x", morse_code
);
1206 morse_reading
= false;
1208 for (j
= 0; morse_alphabets
[j
] != '\0'; j
++)
1210 if (morse_codes
[j
] == morse_code
)
1214 if (morse_alphabets
[j
] == '\0')
1216 logf("Morse code not found");
1220 /* turn off hangul input */
1222 param
[l
].hangul
= false;
1223 kbd_inschar(text
, buflen
, &editpos
, morse_alphabets
[j
]);
1225 if (global_settings
.talk_menu
) /* voice UI? */
1226 talk_spell(text
, false); /* speak revised text */
1228 #endif /* KBD_MORSE_INPUT */
1232 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
1235 screens
[l
].setfont(FONT_SYSFIXED
);
1241 if (button
!= BUTTON_NONE
)
1247 #ifdef HAVE_BUTTONBAR
1248 global_settings
.buttonbar
= buttonbar_config
;
1252 splash(HZ
/2, ID2P(LANG_CANCEL
));
1255 screens
[l
].setfont(FONT_UI
);
1256 viewportmanager_set_statusbar(oldbars
);
1257 send_event(GUI_EVENT_REFRESH
, NULL
);