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
];
120 unsigned short hlead
, hvowel
, htail
;
123 static struct keyboard_parameters kbd_param
[NB_SCREENS
];
124 static bool kbd_loaded
= false;
126 #ifdef KBD_MORSE_INPUT
127 /* FIXME: We should put this to a configuration file. */
128 static const char *morse_alphabets
=
129 "abcdefghijklmnopqrstuvwxyz1234567890,.?-@ ";
130 static const unsigned char morse_codes
[] = {
131 0x05,0x18,0x1a,0x0c,0x02,0x12,0x0e,0x10,0x04,0x17,0x0d,0x14,0x07,
132 0x06,0x0f,0x16,0x1d,0x0a,0x08,0x03,0x09,0x11,0x0b,0x19,0x1b,0x1c,
133 0x2f,0x27,0x23,0x21,0x20,0x30,0x38,0x3c,0x3e,0x3f,
134 0x73,0x55,0x4c,0x61,0x5a,0x80 };
136 static bool morse_mode
= false;
139 /* Loads a custom keyboard into memory
140 call with NULL to reset keyboard */
141 int load_kbd(unsigned char* filename
)
145 unsigned char buf
[4];
147 if (filename
== NULL
)
153 fd
= open_utf8(filename
, O_RDONLY
|O_BINARY
);
157 while (read(fd
, buf
, 1) == 1 && i
< KBD_BUF_SIZE
)
159 /* check how many bytes to read for this character */
160 static const unsigned char sizes
[4] = { 0x80, 0xe0, 0xf0, 0xf5 };
163 for (count
= 0; count
< ARRAYLEN(sizes
); count
++)
165 if (buf
[0] < sizes
[count
])
169 if (count
>= ARRAYLEN(sizes
))
170 continue; /* Invalid size. */
172 if (read(fd
, &buf
[1], count
) != (ssize_t
)count
)
180 utf8decode(buf
, &kbd_param
[l
].kbd_buf
[i
]);
182 if (kbd_param
[0].kbd_buf
[i
] != 0xFEFF &&
183 kbd_param
[0].kbd_buf
[i
] != '\r') /*skip BOM & carriage returns */
193 kbd_param
[l
].nchars
= i
;
198 /* helper function to spell a char if voice UI is enabled */
199 static void kbd_spellchar(unsigned short c
)
201 if (global_settings
.talk_menu
) /* voice UI? */
203 unsigned char tmp
[5];
204 /* store char to pass to talk_spell */
205 unsigned char* utf8
= utf8encode(c
, tmp
);
209 talk_id(VOICE_BLANK
, false);
211 talk_spell(tmp
, false);
216 static void say_edit(void)
218 if(global_settings
.talk_menu
)
219 talk_id(VOICE_EDIT
, false);
223 static void kbd_inschar(unsigned char* text
, int buflen
,
224 int* editpos
, unsigned short ch
)
227 unsigned char tmp
[4];
231 k
= utf8length(text
);
232 utf8
= utf8encode(ch
, tmp
);
233 j
= (long)utf8
- (long)tmp
;
235 if (len
+ j
< buflen
)
237 for (i
= len
+j
; k
>= *editpos
; i
--)
240 if ((text
[i
] & MASK
) != COMP
)
251 static void kbd_delchar(unsigned char* text
, int* editpos
)
258 utf8
= text
+ utf8seek(text
, *editpos
);
265 while ((*utf8
& MASK
) == COMP
);
278 /* Lookup k value based on state of param (pm) */
279 static int get_param_k(const struct keyboard_parameters
*pm
)
281 return (pm
->page
*pm
->lines
+ pm
->y
)*pm
->max_chars
+ pm
->x
;
284 int kbd_input(char* text
, int buflen
)
288 /* This seems to keep the sizes for ARM way down */
289 struct keyboard_parameters
* volatile param
= kbd_param
;
291 struct keyboard_parameters
* const param
= kbd_param
;
293 int l
; /* screen loop variable */
295 int editpos
; /* Edit position on all screens */
296 const int statusbar_size
= 0;
299 bool cur_blink
= true; /* Cursor on/off flag */
300 int ret
= 0; /* assume success */
301 #ifdef KBD_MORSE_INPUT
302 bool morse_reading
= false;
303 unsigned char morse_code
= 0;
307 int oldbars
= viewportmanager_set_statusbar(VP_SB_HIDE_ALL
);
310 struct keyboard_parameters
*pm
= ¶m
[l
];
311 #if LCD_WIDTH >= 160 && LCD_HEIGHT >= 96
312 struct screen
*sc
= &screens
[l
];
314 if (sc
->getwidth() >= 160 && sc
->getheight() >= 96)
317 "ABCDEFG abcdefg !?\" @#$%+'\n"
318 "HIJKLMN hijklmn 789 &_()-`\n"
319 "OPQRSTU opqrstu 456 §|{}/<\n"
320 "VWXYZ., vwxyz.,0123 ~=[]*>\n"
321 "ÀÁÂÃÄÅÆ ÌÍÎÏ ÈÉÊË ¢£¤¥¦§©®\n"
322 "àáâãäåæ ìíîï èéêë «»°ºª¹²³\n"
323 "ÓÒÔÕÖØ ÇÐÞÝß ÙÚÛÜ ¯±×÷¡¿µ·\n"
324 "òóôõöø çðþýÿ ùúûü ¼½¾¬¶¨:;";
326 pm
->DEFAULT_LINES
= 8;
329 #endif /* LCD_WIDTH >= 160 && LCD_HEIGHT >= 96 */
332 "ABCDEFG !?\" @#$%+'\n"
333 "HIJKLMN 789 &_()-`\n"
334 "OPQRSTU 456 §|{}/<\n"
335 "VWXYZ.,0123 ~=[]*>\n"
337 "abcdefg ¢£¤¥¦§©®¬\n"
338 "hijklmn «»°ºª¹²³¶\n"
339 "opqrstu ¯±×÷¡¿µ·¨\n"
342 "ÀÁÂÃÄÅÆ ÌÍÎÏ ÈÉÊË\n"
343 "àáâãäåæ ìíîï èéêë\n"
344 "ÓÒÔÕÖØ ÇÐÞÝß ÙÚÛÜ\n"
347 pm
->DEFAULT_LINES
= 4;
352 #ifdef HAVE_BUTTONBAR
353 struct gui_buttonbar buttonbar
;
354 bool buttonbar_config
= global_settings
.buttonbar
;
356 global_settings
.buttonbar
= true;
357 gui_buttonbar_init(&buttonbar
);
360 gui_buttonbar_set_display(&buttonbar
, &screens
[l
]);
365 struct keyboard_parameters
*pm
= ¶m
[l
];
369 /* Copy default keyboard to buffer */
370 const unsigned char *p
= pm
->default_kbd
;
373 pm
->curfont
= FONT_SYSFIXED
;
376 p
= utf8decode(p
, &pm
->kbd_buf
[i
++]);
382 pm
->curfont
= FONT_UI
;
388 struct keyboard_parameters
*pm
= ¶m
[l
];
389 struct screen
*sc
= &screens
[l
];
392 pm
->font
= font_get(pm
->curfont
);
393 pm
->font_h
= pm
->font
->height
;
395 /* check if FONT_UI fits the screen */
396 if (2*pm
->font_h
+ 3 + statusbar_size
+
397 BUTTONBAR_HEIGHT
> sc
->getheight())
399 pm
->font
= font_get(FONT_SYSFIXED
);
400 pm
->font_h
= pm
->font
->height
;
401 pm
->curfont
= FONT_SYSFIXED
;
404 sc
->setfont(pm
->curfont
);
405 pm
->font_w
= 0; /* reset font width */
406 /* find max width of keyboard glyphs */
407 for (i
= 0; i
< pm
->nchars
; i
++)
409 w
= font_get_width(pm
->font
, pm
->kbd_buf
[i
]);
410 if ( w
> pm
->font_w
)
414 /* Since we're going to be adding spaces, make sure that we check
416 w
= font_get_width( pm
->font
, ' ' );
417 if ( w
> pm
->font_w
)
423 struct keyboard_parameters
*pm
= ¶m
[l
];
424 struct screen
*sc
= &screens
[l
];
427 /* Pad lines with spaces */
428 while (i
< pm
->nchars
)
430 if (pm
->kbd_buf
[i
] == '\n')
432 int k
= sc
->getwidth() / pm
->font_w
433 - i
% ( sc
->getwidth() / pm
->font_w
) - 1;
436 if (k
== sc
->getwidth() / pm
->font_w
- 1)
440 for (j
= i
; j
< pm
->nchars
; j
++)
442 pm
->kbd_buf
[j
] = pm
->kbd_buf
[j
+ 1];
447 if (pm
->nchars
+ k
- 1 >= KBD_BUF_SIZE
)
448 { /* We don't want to overflow the buffer */
449 k
= KBD_BUF_SIZE
- pm
->nchars
;
452 for (j
= pm
->nchars
+ k
- 1; j
> i
+ k
; j
--)
454 pm
->kbd_buf
[j
] = pm
->kbd_buf
[j
-k
];
462 pm
->kbd_buf
[i
++] = ' ';
473 /* Find max width for text string */
477 struct keyboard_parameters
*pm
= ¶m
[l
];
478 struct screen
*sc
= &screens
[l
];
484 int w
= font_get_width(pm
->font
, ch
);
485 utf8
= (unsigned char*)utf8decode(utf8
, &ch
);
491 pm
->max_chars_text
= sc
->getwidth() / text_w
- 2;
493 /* Calculate keyboard grid size */
494 pm
->max_chars
= sc
->getwidth() / pm
->font_w
;
498 pm
->lines
= pm
->DEFAULT_LINES
;
499 pm
->keyboard_margin
= DEFAULT_MARGIN
;
503 pm
->lines
= (sc
->getheight() - BUTTONBAR_HEIGHT
- statusbar_size
)
505 pm
->keyboard_margin
= sc
->getheight() - BUTTONBAR_HEIGHT
-
506 statusbar_size
- (pm
->lines
+1)*pm
->font_h
;
508 if (pm
->keyboard_margin
< 3)
511 pm
->keyboard_margin
+= pm
->font_h
;
514 if (pm
->keyboard_margin
> 6)
515 pm
->keyboard_margin
= 6;
518 pm
->pages
= (pm
->nchars
+ (pm
->lines
*pm
->max_chars
-1))
519 / (pm
->lines
*pm
->max_chars
);
521 if (pm
->pages
== 1 && kbd_loaded
)
522 pm
->lines
= (pm
->nchars
+ pm
->max_chars
- 1) / pm
->max_chars
;
524 pm
->main_y
= pm
->font_h
*pm
->lines
+ pm
->keyboard_margin
+ statusbar_size
;
526 pm
->keyboard_margin
-= pm
->keyboard_margin
/2;
528 #ifdef KBD_MORSE_INPUT
529 pm
->old_main_y
= pm
->main_y
;
531 pm
->main_y
= sc
->getheight() - pm
->font_h
;
535 /* Initial edit position is after last character */
536 editpos
= utf8length(text
);
538 if (global_settings
.talk_menu
) /* voice UI? */
539 talk_spell(text
, true); /* spell initial text */
544 /* These declarations are assigned to the screen on which the key
545 action occurred - pointers save a lot of space over array notation
546 when accessing the same array element countless times */
551 const int button_screen
= 0;
553 struct keyboard_parameters
*pm
;
556 int len_utf8
= utf8length(text
);
559 screens
[l
].clear_display();
561 #ifdef KBD_MORSE_INPUT
566 /* declare scoped pointers inside screen loops - hide the
567 declarations from previous block level */
568 const int w
= 6; /* sysfixed font width */
569 struct keyboard_parameters
*pm
= ¶m
[l
];
570 struct screen
*sc
= &screens
[l
];
573 sc
->setfont(FONT_SYSFIXED
); /* Draw morse code screen with sysfont */
575 pm
->y
= statusbar_size
;
578 /* Draw morse code table with code descriptions. */
579 for (i
= 0; morse_alphabets
[i
] != '\0'; i
++)
584 buf
[0] = morse_alphabets
[i
];
585 sc
->putsxy(pm
->x
, pm
->y
, buf
);
587 for (j
= 0; (morse_codes
[i
] >> j
) > 0x01; j
++) ;
591 for (j
= 0; j
< morse_len
; j
++)
593 if ((morse_codes
[i
] >> (morse_len
-j
-1)) & 0x01)
594 sc
->fillrect(pm
->x
+ j
*4, pm
->y
+ 2, 3, 4);
596 sc
->fillrect(pm
->x
+ j
*4, pm
->y
+ 3, 1, 2);
600 if (pm
->x
>= sc
->getwidth() - w
*6)
603 pm
->y
+= 8; /* sysfixed font height */
609 #endif /* KBD_MORSE_INPUT */
614 struct keyboard_parameters
*pm
= ¶m
[l
];
615 struct screen
*sc
= &screens
[l
];
618 sc
->setfont(pm
->curfont
);
620 k
= pm
->page
*pm
->max_chars
*pm
->lines
;
622 for (i
= j
= 0; j
< pm
->lines
&& k
< pm
->nchars
; k
++)
625 utf8
= utf8encode(pm
->kbd_buf
[k
], outline
);
628 sc
->getstringsize(outline
, &w
, NULL
);
629 sc
->putsxy(i
*pm
->font_w
+ (pm
->font_w
-w
) / 2,
630 j
*pm
->font_h
+ statusbar_size
, outline
);
632 if (++i
>= pm
->max_chars
)
644 struct keyboard_parameters
*pm
= ¶m
[l
];
645 struct screen
*sc
= &screens
[l
];
648 /* Clear text area one pixel above separator line so any overdraw
650 sc
->set_drawmode(DRMODE_SOLID
| DRMODE_INVERSEVID
);
651 sc
->fillrect(0, pm
->main_y
- pm
->keyboard_margin
- 1,
652 sc
->getwidth(), pm
->font_h
+ 4);
653 sc
->set_drawmode(DRMODE_SOLID
);
655 sc
->hline(0, sc
->getwidth() - 1, pm
->main_y
- pm
->keyboard_margin
);
657 /* write out the text */
658 sc
->setfont(pm
->curfont
);
660 pm
->curpos
= MIN(editpos
, pm
->max_chars_text
661 - MIN(len_utf8
- editpos
, 2));
662 pm
->leftpos
= editpos
- pm
->curpos
;
663 utf8
= text
+ utf8seek(text
, pm
->leftpos
);
667 while (*utf8
&& i
< pm
->max_chars_text
)
669 outline
[j
++] = *utf8
++;
671 if ((*utf8
& MASK
) != COMP
)
677 sc
->getstringsize(outline
, &w
, NULL
);
678 sc
->putsxy(i
*text_w
+ (text_w
-w
)/2, pm
->main_y
, outline
);
684 /* Draw nicer bitmap arrow if room, else settle for "<". */
685 if (text_w
>= 6 && pm
->font_h
>= 8)
687 screen_put_iconxy(sc
, (text_w
- 6) / 2,
688 pm
->main_y
+ (pm
->font_h
- 8) / 2 ,
689 Icon_Reverse_Cursor
);
694 sc
->getstringsize("<", &w
, NULL
);
695 sc
->putsxy(text_w
- w
, pm
->main_y
, "<");
699 if (len_utf8
- pm
->leftpos
> pm
->max_chars_text
)
701 /* Draw nicer bitmap arrow if room, else settle for ">". */
702 if (text_w
>= 6 && pm
->font_h
>= 8)
704 screen_put_iconxy(sc
, sc
->getwidth() - text_w
+
706 pm
->main_y
+ (pm
->font_h
- 8) / 2,
711 sc
->putsxy(sc
->getwidth() - text_w
, pm
->main_y
, ">");
716 i
= (pm
->curpos
+ 1) * text_w
;
719 sc
->vline(i
, pm
->main_y
, pm
->main_y
+ pm
->font_h
- 1);
721 if (pm
->hangul
) /* draw underbar */
722 sc
->hline(pm
->curpos
*text_w
, (pm
->curpos
+1)*text_w
,
723 pm
->main_y
+ pm
->font_h
- 1);
726 cur_blink
= !cur_blink
;
728 #ifdef HAVE_BUTTONBAR
729 /* draw the button bar */
730 gui_buttonbar_set(&buttonbar
, "Shift", "OK", "Del");
731 gui_buttonbar_draw(&buttonbar
);
736 struct keyboard_parameters
*pm
= ¶m
[l
];
737 struct screen
*sc
= &screens
[l
];
739 sc
->set_drawmode(DRMODE_COMPLEMENT
);
742 sc
->fillrect(0, pm
->main_y
- pm
->keyboard_margin
+ 2,
743 sc
->getwidth(), pm
->font_h
+ 2);
744 else /* highlight the key that has focus */
746 sc
->fillrect(pm
->font_w
*pm
->x
,
747 statusbar_size
+ pm
->font_h
*pm
->y
,
748 pm
->font_w
, pm
->font_h
);
749 sc
->set_drawmode(DRMODE_SOLID
);
755 button
= get_action(CONTEXT_KEYBOARD
, HZ
/2);
757 button_screen
= (get_action_statuscode(NULL
) & ACTION_REMOTE
) ? 1 : 0;
759 pm
= ¶m
[button_screen
];
760 sc
= &screens
[button_screen
];
762 #if defined KBD_MORSE_INPUT && !defined KBD_MODES
765 /* Remap some buttons for morse mode. */
766 if (button
== ACTION_KBD_LEFT
)
767 button
= ACTION_KBD_CURSOR_LEFT
;
768 if (button
== ACTION_KBD_RIGHT
)
769 button
= ACTION_KBD_CURSOR_RIGHT
;
775 case ACTION_KBD_ABORT
:
777 screens
[l
].setfont(FONT_UI
);
778 ret
= -1; done
= true;
781 case ACTION_KBD_PAGE_FLIP
:
784 #ifdef KBD_MORSE_INPUT
788 if (++pm
->page
>= pm
->pages
)
792 kbd_spellchar(pm
->kbd_buf
[k
]);
796 #ifdef KBD_MORSE_INPUT
797 case ACTION_KBD_MORSE_INPUT
:
798 morse_mode
= !morse_mode
;
802 struct keyboard_parameters
*pm
= ¶m
[l
];
803 struct screen
*sc
= &screens
[l
];
805 pm
->x
= pm
->y
= pm
->page
= 0;
809 pm
->old_main_y
= pm
->main_y
;
810 pm
->main_y
= sc
->getheight() - pm
->font_h
;
814 pm
->main_y
= pm
->old_main_y
;
817 /* FIXME: We should talk something like Morse mode.. */
819 #endif /* KBD_MORSE_INPUT */
821 case ACTION_KBD_RIGHT
:
823 #ifdef KBD_MORSE_INPUT
824 /* allow cursor change in non line edit morse mode */
825 if (pm
->line_edit
|| morse_mode
)
827 /* right doubles as cursor_right in line_edit */
833 if (editpos
< len_utf8
)
835 int c
= utf8seek(text
, ++editpos
);
836 kbd_spellchar(text
[c
]);
838 #if CONFIG_CODEC == SWCODEC
839 else if (global_settings
.talk_menu
)
840 pcmbuf_beep(1000, 150, 1500);
844 #endif /* KBD_MODES */
847 #ifdef KBD_MORSE_INPUT
851 if (++pm
->x
>= pm
->max_chars
)
853 #ifndef KBD_PAGE_FLIP
854 /* no dedicated flip key - flip page on wrap */
855 if (++pm
->page
>= pm
->pages
)
862 kbd_spellchar(pm
->kbd_buf
[k
]);
866 case ACTION_KBD_LEFT
:
868 #ifdef KBD_MORSE_INPUT
869 /* allow cursor change in non line edit morse mode */
870 if (pm
->line_edit
|| morse_mode
)
872 /* left doubles as cursor_left in line_edit */
880 int c
= utf8seek(text
, --editpos
);
881 kbd_spellchar(text
[c
]);
883 #if CONFIG_CODEC == SWCODEC
884 else if (global_settings
.talk_menu
)
885 pcmbuf_beep(1000, 150, 1500);
889 #endif /* KBD_MODES */
892 #ifdef KBD_MORSE_INPUT
898 #ifndef KBD_PAGE_FLIP
899 /* no dedicated flip key - flip page on wrap */
901 pm
->page
= pm
->pages
- 1;
903 pm
->x
= pm
->max_chars
- 1;
907 kbd_spellchar(pm
->kbd_buf
[k
]);
911 case ACTION_KBD_DOWN
:
912 #ifdef KBD_MORSE_INPUT
916 pm
->line_edit
= !pm
->line_edit
;
925 #endif /* KBD_MORSE_INPUT */
931 pm
->line_edit
= false;
935 if (++pm
->y
>= pm
->lines
)
938 pm
->line_edit
= true;
949 int k
= get_param_k(pm
);
950 kbd_spellchar(pm
->kbd_buf
[k
]);
955 #ifdef KBD_MORSE_INPUT
959 pm
->line_edit
= !pm
->line_edit
;
968 #endif /* KBD_MORSE_INPUT */
973 pm
->y
= pm
->lines
- 1;
974 pm
->line_edit
= false;
981 pm
->line_edit
= true;
985 pm
->y
= pm
->lines
- 1;
992 int k
= get_param_k(pm
);
993 kbd_spellchar(pm
->kbd_buf
[k
]);
997 case ACTION_KBD_DONE
:
998 /* accepts what was entered and continues */
1003 #ifdef KBD_MORSE_INPUT
1004 case ACTION_KBD_MORSE_SELECT
:
1005 if (morse_mode
&& morse_reading
)
1008 if ((current_tick
- morse_tick
) > HZ
/5)
1013 #endif /* KBD_MORSE_INPUT */
1015 case ACTION_KBD_SELECT
:
1016 case ACTION_KBD_SELECT_REM
:
1017 #ifdef KBD_MORSE_INPUT
1019 if (morse_mode
&& !pm
->line_edit
)
1024 morse_tick
= current_tick
;
1028 morse_reading
= true;
1033 #endif /* KBD_MORSE_INPUT */
1035 /* inserts the selected char */
1038 { /* select doubles as backspace in line_edit */
1043 else if (pm
->hvowel
)
1049 kbd_delchar(text
, &editpos
);
1054 ch
= hangul_join(pm
->hlead
, pm
->hvowel
, pm
->htail
);
1057 kbd_inschar(text
, buflen
, &editpos
, ch
);
1061 #endif /* KBD_MODES */
1063 /* find input char */
1064 int k
= get_param_k(pm
);
1065 ch
= (k
< pm
->nchars
) ? pm
->kbd_buf
[k
] : ' ';
1067 /* check for hangul input */
1068 if (ch
>= 0x3131 && ch
<= 0x3163)
1074 pm
->hlead
= pm
->hvowel
= pm
->htail
= 0;
1082 else if (!pm
->htail
)
1087 { /* previous hangul complete */
1088 /* check whether tail is actually lead of next char */
1089 tmp
= hangul_join(pm
->htail
, ch
, 0);
1093 tmp
= hangul_join(pm
->hlead
, pm
->hvowel
, 0);
1094 kbd_delchar(text
, &editpos
);
1095 kbd_inschar(text
, buflen
, &editpos
, tmp
);
1096 /* insert dummy char */
1097 kbd_inschar(text
, buflen
, &editpos
, ' ');
1098 pm
->hlead
= pm
->htail
;
1104 pm
->hvowel
= pm
->htail
= 0;
1109 /* combine into hangul */
1110 tmp
= hangul_join(pm
->hlead
, pm
->hvowel
, pm
->htail
);
1114 kbd_delchar(text
, &editpos
);
1119 pm
->hvowel
= pm
->htail
= 0;
1129 kbd_inschar(text
, buflen
, &editpos
, ch
);
1132 if (global_settings
.talk_menu
) /* voice UI? */
1133 talk_spell(text
, false);
1135 /* speak revised text */
1138 #if !defined (KBD_MODES) || defined (KBD_CURSOR_KEYS)
1139 case ACTION_KBD_BACKSPACE
:
1144 else if (pm
->hvowel
)
1150 kbd_delchar(text
, &editpos
);
1155 ch
= hangul_join(pm
->hlead
, pm
->hvowel
, pm
->htail
);
1158 kbd_inschar(text
, buflen
, &editpos
, ch
);
1161 if (global_settings
.talk_menu
) /* voice UI? */
1162 talk_spell(text
, false); /* speak revised text */
1165 case ACTION_KBD_CURSOR_RIGHT
:
1168 if (editpos
< len_utf8
)
1170 int c
= utf8seek(text
, ++editpos
);
1171 kbd_spellchar(text
[c
]);
1173 #if CONFIG_CODEC == SWCODEC
1174 else if (global_settings
.talk_menu
)
1175 pcmbuf_beep(1000, 150, 1500);
1179 case ACTION_KBD_CURSOR_LEFT
:
1184 int c
= utf8seek(text
, --editpos
);
1185 kbd_spellchar(text
[c
]);
1187 #if CONFIG_CODEC == SWCODEC
1188 else if (global_settings
.talk_menu
)
1189 pcmbuf_beep(1000, 150, 1500);
1192 #endif /* !defined (KBD_MODES) || defined (KBD_CURSOR_KEYS) */
1195 #ifdef KBD_MORSE_INPUT
1199 logf("Morse: 0x%02x", morse_code
);
1200 morse_reading
= false;
1202 for (j
= 0; morse_alphabets
[j
] != '\0'; j
++)
1204 if (morse_codes
[j
] == morse_code
)
1208 if (morse_alphabets
[j
] == '\0')
1210 logf("Morse code not found");
1214 /* turn off hangul input */
1216 param
[l
].hangul
= false;
1217 kbd_inschar(text
, buflen
, &editpos
, morse_alphabets
[j
]);
1219 if (global_settings
.talk_menu
) /* voice UI? */
1220 talk_spell(text
, false); /* speak revised text */
1222 #endif /* KBD_MORSE_INPUT */
1226 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
1229 screens
[l
].setfont(FONT_SYSFIXED
);
1235 if (button
!= BUTTON_NONE
)
1241 #ifdef HAVE_BUTTONBAR
1242 global_settings
.buttonbar
= buttonbar_config
;
1246 splash(HZ
/2, ID2P(LANG_CANCEL
));
1249 screens
[l
].setfont(FONT_UI
);
1250 viewportmanager_set_statusbar(oldbars
);
1251 send_event(GUI_EVENT_REFRESH
, NULL
);