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 ****************************************************************************/
29 #include "rbunicode.h"
30 #include "buttonbar.h"
47 #define DEFAULT_MARGIN 6
48 #define KBD_BUF_SIZE 500
50 #if (CONFIG_KEYPAD == ONDIO_PAD) \
51 || (CONFIG_KEYPAD == IPOD_1G2G_PAD) \
52 || (CONFIG_KEYPAD == IPOD_3G_PAD) \
53 || (CONFIG_KEYPAD == IPOD_4G_PAD) \
54 || (CONFIG_KEYPAD == IRIVER_IFP7XX_PAD) \
55 || (CONFIG_KEYPAD == IAUDIO_X5M5_PAD) \
56 || (CONFIG_KEYPAD == IAUDIO_M3_PAD) \
57 || (CONFIG_KEYPAD == IRIVER_H10_PAD) \
58 || (CONFIG_KEYPAD == PBELL_VIBE500_PAD) \
59 /* no key combos to move the cursor if not in line edit mode */
60 #define KBD_MODES /* uses 2 modes, picker and line edit */
62 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) \
63 || (CONFIG_KEYPAD == IRIVER_H300_PAD) \
64 || (CONFIG_KEYPAD == GIGABEAT_PAD) \
65 || (CONFIG_KEYPAD == GIGABEAT_S_PAD) \
66 || (CONFIG_KEYPAD == SANSA_E200_PAD) \
67 || (CONFIG_KEYPAD == SANSA_FUZE_PAD) \
68 || (CONFIG_KEYPAD == SANSA_C200_PAD) \
69 || (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
70 /* certain key combos move the cursor even if not in line edit mode */
71 #define KBD_CURSOR_KEYS
72 #define KBD_MODES /* uses 2 modes, picker and line edit */
75 #define KBD_CURSOR_KEYS /* certain keys move the cursor, no line edit mode */
78 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) \
79 || (CONFIG_KEYPAD == IRIVER_H300_PAD) \
80 || (CONFIG_KEYPAD == IPOD_1G2G_PAD) \
81 || (CONFIG_KEYPAD == IPOD_3G_PAD) \
82 || (CONFIG_KEYPAD == IPOD_4G_PAD) \
83 || (CONFIG_KEYPAD == IRIVER_H10_PAD) \
84 || (CONFIG_KEYPAD == GIGABEAT_PAD) \
85 || (CONFIG_KEYPAD == GIGABEAT_S_PAD) \
86 || (CONFIG_KEYPAD == MROBE100_PAD) \
87 || (CONFIG_KEYPAD == SANSA_E200_PAD) \
88 || (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD) \
89 || (CONFIG_KEYPAD == PHILIPS_SA9200_PAD) \
90 || (CONFIG_KEYPAD == PBELL_VIBE500_PAD)
91 /* certain key combos toggle input mode between keyboard input and Morse input */
92 #define KBD_TOGGLE_INPUT
95 struct keyboard_parameters
97 unsigned short kbd_buf
[KBD_BUF_SIZE
];
105 #ifdef HAVE_MORSE_INPUT
128 int editpos
; /* Edit position on all screens */
129 bool cur_blink
; /* Cursor on/off flag */
131 unsigned short hlead
, hvowel
, htail
;
132 #ifdef HAVE_MORSE_INPUT
135 unsigned char morse_code
;
140 static struct keyboard_parameters kbd_param
[NB_SCREENS
];
141 static bool kbd_loaded
= false;
143 #ifdef HAVE_MORSE_INPUT
144 /* FIXME: We should put this to a configuration file. */
145 static const char *morse_alphabets
=
146 "abcdefghijklmnopqrstuvwxyz1234567890,.?-@ ";
147 static const unsigned char morse_codes
[] = {
148 0x05,0x18,0x1a,0x0c,0x02,0x12,0x0e,0x10,0x04,0x17,0x0d,0x14,0x07,
149 0x06,0x0f,0x16,0x1d,0x0a,0x08,0x03,0x09,0x11,0x0b,0x19,0x1b,0x1c,
150 0x2f,0x27,0x23,0x21,0x20,0x30,0x38,0x3c,0x3e,0x3f,
151 0x73,0x55,0x4c,0x61,0x5a,0x80 };
154 /* Loads a custom keyboard into memory
155 call with NULL to reset keyboard */
156 int load_kbd(unsigned char* filename
)
160 unsigned char buf
[4];
162 if (filename
== NULL
)
168 fd
= open_utf8(filename
, O_RDONLY
|O_BINARY
);
172 while (read(fd
, buf
, 1) == 1 && i
< KBD_BUF_SIZE
)
174 /* check how many bytes to read for this character */
175 static const unsigned char sizes
[4] = { 0x80, 0xe0, 0xf0, 0xf5 };
179 for (count
= 0; count
< ARRAYLEN(sizes
); count
++)
181 if (buf
[0] < sizes
[count
])
185 if (count
>= ARRAYLEN(sizes
))
186 continue; /* Invalid size. */
188 if (read(fd
, &buf
[1], count
) != (ssize_t
)count
)
195 utf8decode(buf
, &ch
);
196 if (ch
!= 0xFEFF && ch
!= '\r') /* skip BOM & carriage returns */
199 kbd_param
[l
].kbd_buf
[i
] = ch
;
209 struct keyboard_parameters
*pm
= &kbd_param
[l
];
211 /* initialize parameters */
212 pm
->x
= pm
->y
= pm
->page
= 0;
213 pm
->default_lines
= 0;
219 /* helper function to spell a char if voice UI is enabled */
220 static void kbd_spellchar(unsigned short c
)
222 if (global_settings
.talk_menu
) /* voice UI? */
224 unsigned char tmp
[5];
225 /* store char to pass to talk_spell */
226 unsigned char* utf8
= utf8encode(c
, tmp
);
230 talk_id(VOICE_BLANK
, false);
232 talk_spell(tmp
, false);
237 static void say_edit(void)
239 if (global_settings
.talk_menu
)
240 talk_id(VOICE_EDIT
, false);
244 static void kbd_inschar(struct edit_state
*state
, unsigned short ch
)
247 unsigned char tmp
[4];
250 len
= strlen(state
->text
);
251 utf8
= utf8encode(ch
, tmp
);
252 j
= (long)utf8
- (long)tmp
;
254 if (len
+ j
< state
->buflen
)
256 i
= utf8seek(state
->text
, state
->editpos
);
257 utf8
= state
->text
+ i
;
258 memmove(utf8
+ j
, utf8
, len
- i
+ 1);
259 memcpy(utf8
, tmp
, j
);
264 static void kbd_delchar(struct edit_state
*state
)
269 if (state
->editpos
> 0)
272 len
= strlen(state
->text
);
273 i
= utf8seek(state
->text
, state
->editpos
);
274 utf8
= state
->text
+ i
;
275 j
= utf8seek(utf8
, 1);
276 memmove(utf8
, utf8
+ j
, len
- i
- j
+ 1);
280 /* Lookup k value based on state of param (pm) */
281 static unsigned short get_kbd_ch(const struct keyboard_parameters
*pm
)
283 int k
= (pm
->page
*pm
->lines
+ pm
->y
)*pm
->max_chars
+ pm
->x
;
284 return (k
< pm
->nchars
)? pm
->kbd_buf
[k
]: ' ';
287 static void kbd_calc_params(struct keyboard_parameters
*pm
,
288 struct screen
*sc
, struct edit_state
*state
);
289 static void kbd_draw_picker(struct keyboard_parameters
*pm
,
290 struct screen
*sc
, struct edit_state
*state
);
291 static void kbd_draw_edit_line(struct keyboard_parameters
*pm
,
292 struct screen
*sc
, struct edit_state
*state
);
294 int kbd_input(char* text
, int buflen
)
298 /* This seems to keep the sizes for ARM way down */
299 struct keyboard_parameters
* volatile param
= kbd_param
;
301 struct keyboard_parameters
* const param
= kbd_param
;
303 struct edit_state state
;
304 int l
; /* screen loop variable */
306 int ret
= 0; /* assume success */
309 viewportmanager_theme_enable(l
, false, NULL
);
312 #ifdef HAVE_BUTTONBAR
313 struct gui_buttonbar buttonbar
;
314 bool buttonbar_config
= global_settings
.buttonbar
;
316 global_settings
.buttonbar
= true;
317 gui_buttonbar_init(&buttonbar
);
318 gui_buttonbar_set_display(&buttonbar
, &screens
[SCREEN_MAIN
]);
321 /* initialize state */
323 state
.buflen
= buflen
;
324 /* Initial edit position is after last character */
325 state
.editpos
= utf8length(state
.text
);
326 state
.cur_blink
= true;
327 #ifdef HAVE_MORSE_INPUT
328 state
.morse_mode
= global_settings
.morse_input
;
329 state
.morse_reading
= false;
331 state
.hangul
= false;
335 /* Copy default keyboard to buffer */
338 struct keyboard_parameters
*pm
= ¶m
[l
];
339 const unsigned char *p
;
342 #if LCD_WIDTH >= 160 && LCD_HEIGHT >= 96
343 struct screen
*sc
= &screens
[l
];
345 if (sc
->getwidth() >= 160 && sc
->getheight() >= 96)
347 p
= "ABCDEFG abcdefg !?\" @#$%+'\n"
348 "HIJKLMN hijklmn 789 &_()-`\n"
349 "OPQRSTU opqrstu 456 §|{}/<\n"
350 "VWXYZ., vwxyz.,0123 ~=[]*>\n"
351 "ÀÁÂÃÄÅÆ ÌÍÎÏ ÈÉÊË ¢£¤¥¦§©®\n"
352 "àáâãäåæ ìíîï èéêë «»°ºª¹²³\n"
353 "ÓÒÔÕÖØ ÇÐÞÝß ÙÚÛÜ ¯±×÷¡¿µ·\n"
354 "òóôõöø çðþýÿ ùúûü ¼½¾¬¶¨:;";
356 pm
->default_lines
= 8;
359 #endif /* LCD_WIDTH >= 160 && LCD_HEIGHT >= 96 */
361 p
= "ABCDEFG !?\" @#$%+'\n"
362 "HIJKLMN 789 &_()-`\n"
363 "OPQRSTU 456 §|{}/<\n"
364 "VWXYZ.,0123 ~=[]*>\n"
366 "abcdefg ¢£¤¥¦§©®¬\n"
367 "hijklmn «»°ºª¹²³¶\n"
368 "opqrstu ¯±×÷¡¿µ·¨\n"
371 "ÀÁÂÃÄÅÆ ÌÍÎÏ ÈÉÊË\n"
372 "àáâãäåæ ìíîï èéêë\n"
373 "ÓÒÔÕÖØ ÇÐÞÝß ÙÚÛÜ\n"
376 pm
->default_lines
= 4;
380 p
= utf8decode(p
, &pm
->kbd_buf
[i
++]);
383 /* initialize parameters */
384 pm
->x
= pm
->y
= pm
->page
= 0;
391 struct keyboard_parameters
*pm
= ¶m
[l
];
392 struct screen
*sc
= &screens
[l
];
393 kbd_calc_params(pm
, sc
, &state
);
396 if (global_settings
.talk_menu
) /* voice UI? */
397 talk_spell(state
.text
, true); /* spell initial text */
401 /* These declarations are assigned to the screen on which the key
402 action occurred - pointers save a lot of space over array notation
403 when accessing the same array element countless times */
408 const int button_screen
= 0;
410 struct keyboard_parameters
*pm
;
413 state
.len_utf8
= utf8length(state
.text
);
417 /* declare scoped pointers inside screen loops - hide the
418 declarations from previous block level */
419 struct keyboard_parameters
*pm
= ¶m
[l
];
420 struct screen
*sc
= &screens
[l
];
422 kbd_draw_picker(pm
, sc
, &state
);
423 kbd_draw_edit_line(pm
, sc
, &state
);
426 state
.cur_blink
= !state
.cur_blink
;
428 #ifdef HAVE_BUTTONBAR
429 /* draw the button bar */
430 gui_buttonbar_set(&buttonbar
, "Shift", "OK", "Del");
431 gui_buttonbar_draw(&buttonbar
);
438 #ifdef HAVE_MORSE_INPUT
439 state
.morse_mode
? CONTEXT_MORSE_INPUT
:
441 CONTEXT_KEYBOARD
, HZ
/2);
443 button_screen
= (get_action_statuscode(NULL
) & ACTION_REMOTE
) ? 1 : 0;
445 pm
= ¶m
[button_screen
];
446 sc
= &screens
[button_screen
];
448 #if defined(KBD_MODES) || defined(HAVE_MORSE_INPUT)
449 /* Remap some buttons to allow to move
450 * cursor in line edit mode and morse mode. */
451 #if defined(KBD_MODES) && defined(HAVE_MORSE_INPUT)
452 if (pm
->line_edit
|| state
.morse_mode
)
453 #elif defined(KBD_MODES)
455 #else /* defined(HAVE_MORSE_INPUT) */
456 if (state
.morse_mode
)
459 if (button
== ACTION_KBD_LEFT
)
460 button
= ACTION_KBD_CURSOR_LEFT
;
461 if (button
== ACTION_KBD_RIGHT
)
462 button
= ACTION_KBD_CURSOR_RIGHT
;
464 /* select doubles as backspace in line_edit */
465 if (pm
->line_edit
&& button
== ACTION_KBD_SELECT
)
466 button
= ACTION_KBD_BACKSPACE
;
469 #endif /* defined(KBD_MODES) || defined(HAVE_MORSE_INPUT) */
473 case ACTION_KBD_DONE
:
474 /* accepts what was entered and continues */
479 case ACTION_KBD_ABORT
:
484 case ACTION_KBD_PAGE_FLIP
:
485 #ifdef HAVE_MORSE_INPUT
486 if (state
.morse_mode
)
489 if (++pm
->page
>= pm
->pages
)
496 #if defined(HAVE_MORSE_INPUT) && defined(KBD_TOGGLE_INPUT)
497 case ACTION_KBD_MORSE_INPUT
:
498 state
.morse_mode
= !state
.morse_mode
;
502 struct keyboard_parameters
*pm
= ¶m
[l
];
504 pm
->main_y
= pm
->old_main_y
;
507 /* FIXME: We should talk something like Morse mode.. */
509 #endif /* HAVE_MORSE_INPUT && KBD_TOGGLE_INPUT */
511 case ACTION_KBD_RIGHT
:
512 if (++pm
->x
>= pm
->max_chars
)
514 #ifndef KBD_PAGE_FLIP
515 /* no dedicated flip key - flip page on wrap */
516 if (++pm
->page
>= pm
->pages
)
526 case ACTION_KBD_LEFT
:
529 #ifndef KBD_PAGE_FLIP
530 /* no dedicated flip key - flip page on wrap */
532 pm
->page
= pm
->pages
- 1;
534 pm
->x
= pm
->max_chars
- 1;
541 case ACTION_KBD_DOWN
:
542 #ifdef HAVE_MORSE_INPUT
543 if (state
.morse_mode
)
546 pm
->line_edit
= !pm
->line_edit
;
552 #endif /* HAVE_MORSE_INPUT */
557 pm
->line_edit
= false;
559 else if (++pm
->y
>= pm
->lines
)
561 pm
->line_edit
= true;
565 if (++pm
->y
>= pm
->lines
)
578 #ifdef HAVE_MORSE_INPUT
579 if (state
.morse_mode
)
582 pm
->line_edit
= !pm
->line_edit
;
588 #endif /* HAVE_MORSE_INPUT */
592 pm
->y
= pm
->lines
- 1;
593 pm
->line_edit
= false;
595 else if (--pm
->y
< 0)
597 pm
->line_edit
= true;
602 pm
->y
= pm
->lines
- 1;
613 #ifdef HAVE_MORSE_INPUT
614 case ACTION_KBD_MORSE_SELECT
:
615 if (state
.morse_mode
&& state
.morse_reading
)
617 state
.morse_code
<<= 1;
618 if ((current_tick
- state
.morse_tick
) > HZ
/5)
619 state
.morse_code
|= 0x01;
622 #endif /* HAVE_MORSE_INPUT */
624 case ACTION_KBD_SELECT
:
625 #ifdef HAVE_MORSE_INPUT
626 if (state
.morse_mode
)
628 state
.morse_tick
= current_tick
;
630 if (!state
.morse_reading
)
632 state
.morse_reading
= true;
633 state
.morse_code
= 1;
637 #endif /* HAVE_MORSE_INPUT */
639 /* inserts the selected char */
640 /* find input char */
643 /* check for hangul input */
644 if (ch
>= 0x3131 && ch
<= 0x3163)
650 state
.hlead
= state
.hvowel
= state
.htail
= 0;
658 else if (!state
.htail
)
664 /* previous hangul complete */
665 /* check whether tail is actually lead of next char */
666 tmp
= hangul_join(state
.htail
, ch
, 0);
670 tmp
= hangul_join(state
.hlead
, state
.hvowel
, 0);
672 kbd_inschar(&state
, tmp
);
673 /* insert dummy char */
674 kbd_inschar(&state
, ' ');
675 state
.hlead
= state
.htail
;
681 state
.hvowel
= state
.htail
= 0;
686 /* combine into hangul */
687 tmp
= hangul_join(state
.hlead
, state
.hvowel
, state
.htail
);
696 state
.hvowel
= state
.htail
= 0;
702 state
.hangul
= false;
706 kbd_inschar(&state
, ch
);
708 if (global_settings
.talk_menu
) /* voice UI? */
709 talk_spell(state
.text
, false); /* speak revised text */
713 case ACTION_KBD_BACKSPACE
:
718 else if (state
.hvowel
)
721 state
.hangul
= false;
729 ch
= hangul_join(state
.hlead
, state
.hvowel
, state
.htail
);
732 kbd_inschar(&state
, ch
);
735 if (global_settings
.talk_menu
) /* voice UI? */
736 talk_spell(state
.text
, false); /* speak revised text */
739 case ACTION_KBD_CURSOR_RIGHT
:
740 state
.hangul
= false;
742 if (state
.editpos
< state
.len_utf8
)
744 int c
= utf8seek(state
.text
, ++state
.editpos
);
745 kbd_spellchar(state
.text
[c
]);
747 #if CONFIG_CODEC == SWCODEC
748 else if (global_settings
.talk_menu
)
749 pcmbuf_beep(1000, 150, 1500);
753 case ACTION_KBD_CURSOR_LEFT
:
754 state
.hangul
= false;
756 if (state
.editpos
> 0)
758 int c
= utf8seek(state
.text
, --state
.editpos
);
759 kbd_spellchar(state
.text
[c
]);
761 #if CONFIG_CODEC == SWCODEC
762 else if (global_settings
.talk_menu
)
763 pcmbuf_beep(1000, 150, 1500);
768 #ifdef HAVE_MORSE_INPUT
769 if (state
.morse_reading
)
772 logf("Morse: 0x%02x", state
.morse_code
);
773 state
.morse_reading
= false;
775 for (j
= 0; morse_alphabets
[j
] != '\0'; j
++)
777 if (morse_codes
[j
] == state
.morse_code
)
781 if (morse_alphabets
[j
] == '\0')
783 logf("Morse code not found");
787 /* turn off hangul input */
788 state
.hangul
= false;
789 kbd_inschar(&state
, morse_alphabets
[j
]);
791 if (global_settings
.talk_menu
) /* voice UI? */
792 talk_spell(state
.text
, false); /* speak revised text */
794 #endif /* HAVE_MORSE_INPUT */
798 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
801 screens
[l
].setfont(FONT_SYSFIXED
);
807 if (button
!= ACTION_NONE
)
809 state
.cur_blink
= true;
813 #ifdef HAVE_BUTTONBAR
814 global_settings
.buttonbar
= buttonbar_config
;
818 splash(HZ
/2, ID2P(LANG_CANCEL
));
820 #if defined(HAVE_MORSE_INPUT) && defined(KBD_TOGGLE_INPUT)
821 if (global_settings
.morse_input
!= state
.morse_mode
)
823 global_settings
.morse_input
= state
.morse_mode
;
826 #endif /* HAVE_MORSE_INPUT && KBD_TOGGLE_INPUT */
830 screens
[l
].setfont(FONT_UI
);
831 viewportmanager_theme_undo(l
, false);
836 static void kbd_calc_params(struct keyboard_parameters
*pm
,
837 struct screen
*sc
, struct edit_state
*state
)
840 const unsigned char *p
;
842 int icon_w
, sc_w
, sc_h
, w
;
845 pm
->curfont
= pm
->default_lines
? FONT_SYSFIXED
: FONT_UI
;
846 font
= font_get(pm
->curfont
);
847 pm
->font_h
= font
->height
;
849 /* check if FONT_UI fits the screen */
850 if (2*pm
->font_h
+ 3 + BUTTONBAR_HEIGHT
> sc
->getheight())
852 pm
->curfont
= FONT_SYSFIXED
;
853 font
= font_get(FONT_SYSFIXED
);
854 pm
->font_h
= font
->height
;
857 /* find max width of keyboard glyphs.
858 * since we're going to be adding spaces,
859 * max width is at least their width */
860 pm
->font_w
= font_get_width(font
, ' ');
861 for (i
= 0; i
< pm
->nchars
; i
++)
863 if (pm
->kbd_buf
[i
] != '\n')
865 w
= font_get_width(font
, pm
->kbd_buf
[i
]);
871 /* Find max width for text string */
872 pm
->text_w
= pm
->font_w
;
876 p
= utf8decode(p
, &ch
);
877 w
= font_get_width(font
, ch
);
882 /* calculate how many characters to put in a row. */
883 icon_w
= get_icon_width(sc
->screen_type
);
884 sc_w
= sc
->getwidth();
885 pm
->max_chars
= sc_w
/ pm
->font_w
;
886 pm
->max_chars_text
= (sc_w
- icon_w
* 2 - 2) / pm
->text_w
;
887 if (pm
->max_chars_text
< 3 && icon_w
> pm
->text_w
)
888 pm
->max_chars_text
= sc_w
/ pm
->text_w
- 2;
892 /* Pad lines with spaces */
893 while (i
< pm
->nchars
)
895 if (pm
->kbd_buf
[i
] == '\n')
897 int k
= pm
->max_chars
- i
% ( pm
->max_chars
) - 1;
900 if (k
== pm
->max_chars
- 1)
904 for (j
= i
; j
< pm
->nchars
; j
++)
906 pm
->kbd_buf
[j
] = pm
->kbd_buf
[j
+ 1];
911 if (pm
->nchars
+ k
- 1 >= KBD_BUF_SIZE
)
912 { /* We don't want to overflow the buffer */
913 k
= KBD_BUF_SIZE
- pm
->nchars
;
916 for (j
= pm
->nchars
+ k
- 1; j
> i
+ k
; j
--)
918 pm
->kbd_buf
[j
] = pm
->kbd_buf
[j
-k
];
926 pm
->kbd_buf
[i
++] = ' ';
936 /* calculate pm->pages and pm->lines */
937 sc_h
= sc
->getheight();
938 pm
->lines
= (sc_h
- BUTTONBAR_HEIGHT
) / pm
->font_h
- 1;
940 if (pm
->default_lines
&& pm
->lines
> pm
->default_lines
)
941 pm
->lines
= pm
->default_lines
;
943 pm
->keyboard_margin
= sc_h
- BUTTONBAR_HEIGHT
944 - (pm
->lines
+1)*pm
->font_h
;
946 if (pm
->keyboard_margin
< 3 && pm
->lines
> 1)
949 pm
->keyboard_margin
+= pm
->font_h
;
952 if (pm
->keyboard_margin
> DEFAULT_MARGIN
)
953 pm
->keyboard_margin
= DEFAULT_MARGIN
;
955 total_lines
= (pm
->nchars
+ pm
->max_chars
- 1) / pm
->max_chars
;
956 pm
->pages
= (total_lines
+ pm
->lines
- 1) / pm
->lines
;
957 pm
->lines
= (total_lines
+ pm
->pages
- 1) / pm
->pages
;
959 pm
->main_y
= pm
->font_h
*pm
->lines
+ pm
->keyboard_margin
;
960 pm
->keyboard_margin
-= pm
->keyboard_margin
/2;
962 #ifdef HAVE_MORSE_INPUT
963 pm
->old_main_y
= sc_h
- pm
->font_h
- BUTTONBAR_HEIGHT
;
964 if (state
->morse_mode
)
967 pm
->main_y
= pm
->old_main_y
;
973 static void kbd_draw_picker(struct keyboard_parameters
*pm
,
974 struct screen
*sc
, struct edit_state
*state
)
977 #ifdef HAVE_MORSE_INPUT
978 if (state
->morse_mode
)
980 const int w
= 6, h
= 8; /* sysfixed font width, height */
982 int sc_w
= sc
->getwidth(), sc_h
= pm
->main_y
- pm
->keyboard_margin
- 1;
984 /* Draw morse code screen with sysfont */
985 sc
->setfont(FONT_SYSFIXED
);
990 /* Draw morse code table with code descriptions. */
991 for (i
= 0; morse_alphabets
[i
] != '\0'; i
++)
995 outline
[0] = morse_alphabets
[i
];
996 sc
->putsxy(x
, y
, outline
);
998 morse_code
= morse_codes
[i
];
999 for (j
= 0; morse_code
> 0x01; morse_code
>>= 1)
1003 morse_code
= morse_codes
[i
];
1004 for (; morse_code
> 0x01; morse_code
>>= 1)
1007 if (morse_code
& 0x01)
1008 sc
->fillrect(x
, y
+ 2, 3, 4);
1010 sc
->fillrect(x
, y
+ 3, 1, 2);
1014 if (x
+ w
*6 >= sc_w
)
1026 #endif /* HAVE_MORSE_INPUT */
1031 sc
->setfont(pm
->curfont
);
1033 k
= pm
->page
*pm
->max_chars
*pm
->lines
;
1035 for (i
= j
= 0; k
< pm
->nchars
; k
++)
1038 unsigned char *utf8
;
1039 utf8
= utf8encode(pm
->kbd_buf
[k
], outline
);
1042 sc
->getstringsize(outline
, &w
, NULL
);
1043 sc
->putsxy(i
*pm
->font_w
+ (pm
->font_w
-w
) / 2,
1044 j
*pm
->font_h
, outline
);
1046 if (++i
>= pm
->max_chars
)
1049 if (++j
>= pm
->lines
)
1058 /* highlight the key that has focus */
1059 sc
->set_drawmode(DRMODE_COMPLEMENT
);
1060 sc
->fillrect(pm
->font_w
*pm
->x
, pm
->font_h
*pm
->y
,
1061 pm
->font_w
, pm
->font_h
);
1062 sc
->set_drawmode(DRMODE_SOLID
);
1067 static void kbd_draw_edit_line(struct keyboard_parameters
*pm
,
1068 struct screen
*sc
, struct edit_state
*state
)
1071 unsigned char *utf8
;
1072 int i
= 0, j
= 0, icon_w
, w
;
1073 int sc_w
= sc
->getwidth();
1074 int y
= pm
->main_y
- pm
->keyboard_margin
;
1075 int text_margin
= (sc_w
- pm
->text_w
* pm
->max_chars_text
) / 2;
1077 /* Clear text area one pixel above separator line so any overdraw
1079 screen_clear_area(sc
, 0, y
- 1, sc_w
, pm
->font_h
+ 6);
1081 sc
->hline(0, sc_w
- 1, y
);
1083 /* write out the text */
1084 sc
->setfont(pm
->curfont
);
1086 pm
->leftpos
= MAX(0, MIN(state
->len_utf8
, state
->editpos
+ 2)
1087 - pm
->max_chars_text
);
1088 pm
->curpos
= state
->editpos
- pm
->leftpos
;
1089 utf8
= state
->text
+ utf8seek(state
->text
, pm
->leftpos
);
1091 while (*utf8
&& i
< pm
->max_chars_text
)
1093 j
= utf8seek(utf8
, 1);
1094 strlcpy(outline
, utf8
, j
+1);
1095 sc
->getstringsize(outline
, &w
, NULL
);
1096 sc
->putsxy(text_margin
+ i
*pm
->text_w
+ (pm
->text_w
-w
)/2,
1097 pm
->main_y
, outline
);
1102 icon_w
= get_icon_width(sc
->screen_type
);
1103 if (pm
->leftpos
> 0)
1105 /* Draw nicer bitmap arrow if room, else settle for "<". */
1106 if (text_margin
>= icon_w
)
1108 screen_put_icon_with_offset(sc
, 0, 0,
1109 (text_margin
- icon_w
) / 2,
1110 pm
->main_y
, Icon_Reverse_Cursor
);
1114 sc
->getstringsize("<", &w
, NULL
);
1115 sc
->putsxy(text_margin
- w
, pm
->main_y
, "<");
1119 if (state
->len_utf8
- pm
->leftpos
> pm
->max_chars_text
)
1121 /* Draw nicer bitmap arrow if room, else settle for ">". */
1122 if (text_margin
>= icon_w
)
1124 screen_put_icon_with_offset(sc
, 0, 0,
1125 sc_w
- (text_margin
+ icon_w
) / 2,
1126 pm
->main_y
, Icon_Cursor
);
1130 sc
->putsxy(sc_w
- text_margin
, pm
->main_y
, ">");
1135 i
= text_margin
+ pm
->curpos
* pm
->text_w
;
1137 if (state
->cur_blink
)
1138 sc
->vline(i
, pm
->main_y
, pm
->main_y
+ pm
->font_h
- 1);
1140 if (state
->hangul
) /* draw underbar */
1141 sc
->hline(i
- pm
->text_w
, i
, pm
->main_y
+ pm
->font_h
- 1);
1146 sc
->set_drawmode(DRMODE_COMPLEMENT
);
1147 sc
->fillrect(0, y
+ 2, sc_w
, pm
->font_h
+ 2);
1148 sc
->set_drawmode(DRMODE_SOLID
);