diff options
author | Teruaki Kawashima <teru@rockbox.org> | 2009-11-09 14:26:20 +0000 |
---|---|---|
committer | Teruaki Kawashima <teru@rockbox.org> | 2009-11-09 14:26:20 +0000 |
commit | 7243fdcee3ce88970bfcd2cce7a7c2e0b8e72cbb (patch) | |
tree | a81ff284b91bbe2e79fb102f78af87ffd93b8249 /apps | |
parent | ad72fce1a507eada75e84694bbfb1c1dd3591198 (diff) | |
download | rockbox-7243fdcee3ce88970bfcd2cce7a7c2e0b8e72cbb.tar.gz rockbox-7243fdcee3ce88970bfcd2cce7a7c2e0b8e72cbb.zip |
keyboard: some random cleanup.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23586 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/recorder/keyboard.c | 197 |
1 files changed, 71 insertions, 126 deletions
diff --git a/apps/recorder/keyboard.c b/apps/recorder/keyboard.c index 2c40ae7ede..e6d31cb450 100644 --- a/apps/recorder/keyboard.c +++ b/apps/recorder/keyboard.c | |||
@@ -103,14 +103,13 @@ struct keyboard_parameters | |||
103 | int text_w; | 103 | int text_w; |
104 | struct font* font; | 104 | struct font* font; |
105 | int curfont; | 105 | int curfont; |
106 | int main_x; | ||
107 | int main_y; | 106 | int main_y; |
107 | int old_main_y; | ||
108 | int max_chars; | 108 | int max_chars; |
109 | int max_chars_text; | 109 | int max_chars_text; |
110 | int lines; | 110 | int lines; |
111 | int pages; | 111 | int pages; |
112 | int keyboard_margin; | 112 | int keyboard_margin; |
113 | int old_main_y; | ||
114 | int curpos; | 113 | int curpos; |
115 | int leftpos; | 114 | int leftpos; |
116 | int page; | 115 | int page; |
@@ -190,9 +189,7 @@ int load_kbd(unsigned char* filename) | |||
190 | kbd_param[l].kbd_buf[i] = ch; | 189 | kbd_param[l].kbd_buf[i] = ch; |
191 | 190 | ||
192 | if (ch != 0xFEFF && ch != '\r') /*skip BOM & carriage returns */ | 191 | if (ch != 0xFEFF && ch != '\r') /*skip BOM & carriage returns */ |
193 | { | ||
194 | i++; | 192 | i++; |
195 | } | ||
196 | } | 193 | } |
197 | 194 | ||
198 | close(fd); | 195 | close(fd); |
@@ -232,55 +229,37 @@ static void say_edit(void) | |||
232 | static void kbd_inschar(unsigned char* text, int buflen, | 229 | static void kbd_inschar(unsigned char* text, int buflen, |
233 | int* editpos, unsigned short ch) | 230 | int* editpos, unsigned short ch) |
234 | { | 231 | { |
235 | int i, j, k, len; | 232 | int i, j, len; |
236 | unsigned char tmp[4]; | 233 | unsigned char tmp[4]; |
237 | unsigned char* utf8; | 234 | unsigned char* utf8; |
238 | 235 | ||
239 | len = strlen(text); | 236 | len = strlen(text); |
240 | k = utf8length(text); | ||
241 | utf8 = utf8encode(ch, tmp); | 237 | utf8 = utf8encode(ch, tmp); |
242 | j = (long)utf8 - (long)tmp; | 238 | j = (long)utf8 - (long)tmp; |
243 | 239 | ||
244 | if (len + j < buflen) | 240 | if (len + j < buflen) |
245 | { | 241 | { |
246 | for (i = len+j; k >= *editpos; i--) | 242 | i = utf8seek(text, *editpos); |
247 | { | 243 | utf8 = text + i; |
248 | text[i] = text[i-j]; | 244 | memmove(utf8 + j, utf8, len - i + 1); |
249 | if ((text[i] & MASK) != COMP) | 245 | memcpy(utf8, tmp, j); |
250 | k--; | ||
251 | } | ||
252 | |||
253 | while (j--) | ||
254 | text[i--] = tmp[j]; | ||
255 | |||
256 | (*editpos)++; | 246 | (*editpos)++; |
257 | } | 247 | } |
258 | } | 248 | } |
259 | 249 | ||
260 | static void kbd_delchar(unsigned char* text, int* editpos) | 250 | static void kbd_delchar(unsigned char* text, int* editpos) |
261 | { | 251 | { |
262 | int i = 0; | 252 | int i, j, len; |
263 | unsigned char* utf8; | 253 | unsigned char* utf8; |
264 | 254 | ||
265 | if (*editpos > 0) | 255 | if (*editpos > 0) |
266 | { | 256 | { |
267 | utf8 = text + utf8seek(text, *editpos); | ||
268 | |||
269 | do | ||
270 | { | ||
271 | i++; | ||
272 | utf8--; | ||
273 | } | ||
274 | while ((*utf8 & MASK) == COMP); | ||
275 | |||
276 | while (utf8[i]) | ||
277 | { | ||
278 | *utf8 = utf8[i]; | ||
279 | utf8++; | ||
280 | } | ||
281 | |||
282 | *utf8 = 0; | ||
283 | (*editpos)--; | 257 | (*editpos)--; |
258 | len = strlen(text); | ||
259 | i = utf8seek(text, *editpos); | ||
260 | utf8 = text + i; | ||
261 | j = utf8seek(utf8, 1); | ||
262 | memmove(utf8, utf8 + j, len - i - j + 1); | ||
284 | } | 263 | } |
285 | } | 264 | } |
286 | 265 | ||
@@ -302,7 +281,6 @@ int kbd_input(char* text, int buflen) | |||
302 | #endif | 281 | #endif |
303 | int l; /* screen loop variable */ | 282 | int l; /* screen loop variable */ |
304 | int editpos; /* Edit position on all screens */ | 283 | int editpos; /* Edit position on all screens */ |
305 | const int statusbar_size = 0; | ||
306 | unsigned short ch; | 284 | unsigned short ch; |
307 | unsigned char *utf8; | 285 | unsigned char *utf8; |
308 | bool cur_blink = true; /* Cursor on/off flag */ | 286 | bool cur_blink = true; /* Cursor on/off flag */ |
@@ -402,8 +380,7 @@ int kbd_input(char* text, int buflen) | |||
402 | pm->font_h = pm->font->height; | 380 | pm->font_h = pm->font->height; |
403 | 381 | ||
404 | /* check if FONT_UI fits the screen */ | 382 | /* check if FONT_UI fits the screen */ |
405 | if (2*pm->font_h + 3 + statusbar_size + | 383 | if (2*pm->font_h + 3 + BUTTONBAR_HEIGHT > sc->getheight()) |
406 | BUTTONBAR_HEIGHT > sc->getheight()) | ||
407 | { | 384 | { |
408 | pm->font = font_get(FONT_SYSFIXED); | 385 | pm->font = font_get(FONT_SYSFIXED); |
409 | pm->font_h = pm->font->height; | 386 | pm->font_h = pm->font->height; |
@@ -504,36 +481,30 @@ int kbd_input(char* text, int buflen) | |||
504 | if(pm->max_chars_text < 3 && icon_w > pm->text_w) | 481 | if(pm->max_chars_text < 3 && icon_w > pm->text_w) |
505 | pm->max_chars_text = sc_w / pm->text_w - 2; | 482 | pm->max_chars_text = sc_w / pm->text_w - 2; |
506 | 483 | ||
507 | if (!kbd_loaded) | 484 | pm->lines = (sc_h - BUTTONBAR_HEIGHT) / pm->font_h - 1; |
508 | { | 485 | |
486 | if (!kbd_loaded && pm->lines > pm->DEFAULT_LINES) | ||
509 | pm->lines = pm->DEFAULT_LINES; | 487 | pm->lines = pm->DEFAULT_LINES; |
510 | pm->keyboard_margin = DEFAULT_MARGIN; | ||
511 | } | ||
512 | else | ||
513 | { | ||
514 | pm->lines = (sc_h - BUTTONBAR_HEIGHT - statusbar_size) | ||
515 | / pm->font_h - 1; | ||
516 | pm->keyboard_margin = sc_h - BUTTONBAR_HEIGHT - statusbar_size | ||
517 | - (pm->lines+1)*pm->font_h; | ||
518 | 488 | ||
519 | if (pm->keyboard_margin < 3) | 489 | pm->keyboard_margin = sc_h - BUTTONBAR_HEIGHT |
520 | { | 490 | - (pm->lines+1)*pm->font_h; |
521 | pm->lines--; | ||
522 | pm->keyboard_margin += pm->font_h; | ||
523 | } | ||
524 | 491 | ||
525 | if (pm->keyboard_margin > 6) | 492 | if (pm->keyboard_margin < 3 && pm->lines > 1) |
526 | pm->keyboard_margin = 6; | 493 | { |
494 | pm->lines--; | ||
495 | pm->keyboard_margin += pm->font_h; | ||
527 | } | 496 | } |
528 | 497 | ||
498 | if (pm->keyboard_margin > DEFAULT_MARGIN) | ||
499 | pm->keyboard_margin = DEFAULT_MARGIN; | ||
500 | |||
529 | pm->pages = (pm->nchars + (pm->lines*pm->max_chars-1)) | 501 | pm->pages = (pm->nchars + (pm->lines*pm->max_chars-1)) |
530 | / (pm->lines*pm->max_chars); | 502 | / (pm->lines*pm->max_chars); |
531 | 503 | ||
532 | if (pm->pages == 1 && kbd_loaded) | 504 | if (pm->pages == 1) |
533 | pm->lines = (pm->nchars + pm->max_chars - 1) / pm->max_chars; | 505 | pm->lines = (pm->nchars + pm->max_chars - 1) / pm->max_chars; |
534 | 506 | ||
535 | pm->main_y = pm->font_h*pm->lines + pm->keyboard_margin + statusbar_size; | 507 | pm->main_y = pm->font_h*pm->lines + pm->keyboard_margin; |
536 | pm->main_x = 0; | ||
537 | pm->keyboard_margin -= pm->keyboard_margin/2; | 508 | pm->keyboard_margin -= pm->keyboard_margin/2; |
538 | 509 | ||
539 | #ifdef HAVE_MORSE_INPUT | 510 | #ifdef HAVE_MORSE_INPUT |
@@ -549,7 +520,6 @@ int kbd_input(char* text, int buflen) | |||
549 | if (global_settings.talk_menu) /* voice UI? */ | 520 | if (global_settings.talk_menu) /* voice UI? */ |
550 | talk_spell(text, true); /* spell initial text */ | 521 | talk_spell(text, true); /* spell initial text */ |
551 | 522 | ||
552 | |||
553 | while (!done) | 523 | while (!done) |
554 | { | 524 | { |
555 | /* These declarations are assigned to the screen on which the key | 525 | /* These declarations are assigned to the screen on which the key |
@@ -583,7 +553,7 @@ int kbd_input(char* text, int buflen) | |||
583 | /* Draw morse code screen with sysfont */ | 553 | /* Draw morse code screen with sysfont */ |
584 | sc->setfont(FONT_SYSFIXED); | 554 | sc->setfont(FONT_SYSFIXED); |
585 | x = 0; | 555 | x = 0; |
586 | y = statusbar_size; | 556 | y = 0; |
587 | outline[1] = '\0'; | 557 | outline[1] = '\0'; |
588 | 558 | ||
589 | /* Draw morse code table with code descriptions. */ | 559 | /* Draw morse code table with code descriptions. */ |
@@ -638,7 +608,7 @@ int kbd_input(char* text, int buflen) | |||
638 | 608 | ||
639 | sc->getstringsize(outline, &w, NULL); | 609 | sc->getstringsize(outline, &w, NULL); |
640 | sc->putsxy(i*pm->font_w + (pm->font_w-w) / 2, | 610 | sc->putsxy(i*pm->font_w + (pm->font_w-w) / 2, |
641 | j*pm->font_h + statusbar_size, outline); | 611 | j*pm->font_h, outline); |
642 | 612 | ||
643 | if (++i >= pm->max_chars) | 613 | if (++i >= pm->max_chars) |
644 | { | 614 | { |
@@ -683,7 +653,7 @@ int kbd_input(char* text, int buflen) | |||
683 | { | 653 | { |
684 | int w; | 654 | int w; |
685 | outline[j] = 0; | 655 | outline[j] = 0; |
686 | j=0; | 656 | j = 0; |
687 | sc->getstringsize(outline, &w, NULL); | 657 | sc->getstringsize(outline, &w, NULL); |
688 | sc->putsxy(text_margin + i*text_w + (text_w-w)/2, | 658 | sc->putsxy(text_margin + i*text_w + (text_w-w)/2, |
689 | pm->main_y, outline); | 659 | pm->main_y, outline); |
@@ -757,8 +727,7 @@ int kbd_input(char* text, int buflen) | |||
757 | #ifdef HAVE_MORSE_INPUT | 727 | #ifdef HAVE_MORSE_INPUT |
758 | if(!morse_mode) | 728 | if(!morse_mode) |
759 | #endif | 729 | #endif |
760 | sc->fillrect(pm->font_w*pm->x, | 730 | sc->fillrect(pm->font_w*pm->x, pm->font_h*pm->y, |
761 | statusbar_size + pm->font_h*pm->y, | ||
762 | pm->font_w, pm->font_h); | 731 | pm->font_w, pm->font_h); |
763 | sc->set_drawmode(DRMODE_SOLID); | 732 | sc->set_drawmode(DRMODE_SOLID); |
764 | } | 733 | } |
@@ -798,13 +767,18 @@ int kbd_input(char* text, int buflen) | |||
798 | 767 | ||
799 | switch ( button ) | 768 | switch ( button ) |
800 | { | 769 | { |
770 | case ACTION_KBD_DONE: | ||
771 | /* accepts what was entered and continues */ | ||
772 | ret = 0; | ||
773 | done = true; | ||
774 | break; | ||
775 | |||
801 | case ACTION_KBD_ABORT: | 776 | case ACTION_KBD_ABORT: |
802 | ret = -1; | 777 | ret = -1; |
803 | done = true; | 778 | done = true; |
804 | break; | 779 | break; |
805 | 780 | ||
806 | case ACTION_KBD_PAGE_FLIP: | 781 | case ACTION_KBD_PAGE_FLIP: |
807 | { | ||
808 | #ifdef HAVE_MORSE_INPUT | 782 | #ifdef HAVE_MORSE_INPUT |
809 | if (morse_mode) | 783 | if (morse_mode) |
810 | break; | 784 | break; |
@@ -815,7 +789,6 @@ int kbd_input(char* text, int buflen) | |||
815 | ch = get_kbd_ch(pm); | 789 | ch = get_kbd_ch(pm); |
816 | kbd_spellchar(ch); | 790 | kbd_spellchar(ch); |
817 | break; | 791 | break; |
818 | } | ||
819 | 792 | ||
820 | #if defined(HAVE_MORSE_INPUT) && defined(KBD_TOGGLE_INPUT) | 793 | #if defined(HAVE_MORSE_INPUT) && defined(KBD_TOGGLE_INPUT) |
821 | case ACTION_KBD_MORSE_INPUT: | 794 | case ACTION_KBD_MORSE_INPUT: |
@@ -827,18 +800,13 @@ int kbd_input(char* text, int buflen) | |||
827 | struct screen *sc = &screens[l]; | 800 | struct screen *sc = &screens[l]; |
828 | 801 | ||
829 | if (morse_mode) | 802 | if (morse_mode) |
830 | { | ||
831 | pm->old_main_y = pm->main_y; | ||
832 | pm->main_y = sc->getheight() - pm->font_h - BUTTONBAR_HEIGHT; | 803 | pm->main_y = sc->getheight() - pm->font_h - BUTTONBAR_HEIGHT; |
833 | } | ||
834 | else | 804 | else |
835 | { | ||
836 | pm->main_y = pm->old_main_y; | 805 | pm->main_y = pm->old_main_y; |
837 | } | ||
838 | } | 806 | } |
839 | /* FIXME: We should talk something like Morse mode.. */ | 807 | /* FIXME: We should talk something like Morse mode.. */ |
840 | break; | 808 | break; |
841 | #endif /* KBD_TOGGLE_INPUT */ | 809 | #endif /* HAVE_MORSE_INPUT && KBD_TOGGLE_INPUT */ |
842 | 810 | ||
843 | case ACTION_KBD_RIGHT: | 811 | case ACTION_KBD_RIGHT: |
844 | if (++pm->x >= pm->max_chars) | 812 | if (++pm->x >= pm->max_chars) |
@@ -872,38 +840,31 @@ int kbd_input(char* text, int buflen) | |||
872 | 840 | ||
873 | case ACTION_KBD_DOWN: | 841 | case ACTION_KBD_DOWN: |
874 | #ifdef HAVE_MORSE_INPUT | 842 | #ifdef HAVE_MORSE_INPUT |
875 | #ifdef KBD_MODES | ||
876 | if (morse_mode) | 843 | if (morse_mode) |
877 | { | 844 | { |
845 | #ifdef KBD_MODES | ||
878 | pm->line_edit = !pm->line_edit; | 846 | pm->line_edit = !pm->line_edit; |
879 | if(pm->line_edit) | 847 | if(pm->line_edit) |
880 | say_edit(); | 848 | say_edit(); |
881 | } | ||
882 | else | ||
883 | #else | ||
884 | if (morse_mode) | ||
885 | break; | ||
886 | #endif | 849 | #endif |
850 | break; | ||
851 | } | ||
887 | #endif /* HAVE_MORSE_INPUT */ | 852 | #endif /* HAVE_MORSE_INPUT */ |
888 | { | ||
889 | #ifdef KBD_MODES | ||
890 | if (pm->line_edit) | ||
891 | { | ||
892 | pm->y = 0; | ||
893 | pm->line_edit = false; | ||
894 | } | ||
895 | else | ||
896 | #endif | ||
897 | if (++pm->y >= pm->lines) | ||
898 | #ifdef KBD_MODES | 853 | #ifdef KBD_MODES |
899 | { | 854 | if (pm->line_edit) |
900 | pm->line_edit = true; | 855 | { |
901 | say_edit(); | 856 | pm->y = 0; |
902 | } | 857 | pm->line_edit = false; |
858 | } | ||
859 | else if (++pm->y >= pm->lines) | ||
860 | { | ||
861 | pm->line_edit = true; | ||
862 | say_edit(); | ||
863 | } | ||
903 | #else | 864 | #else |
904 | pm->y = 0; | 865 | if (++pm->y >= pm->lines) |
866 | pm->y = 0; | ||
905 | #endif | 867 | #endif |
906 | } | ||
907 | #ifdef KBD_MODES | 868 | #ifdef KBD_MODES |
908 | if (!pm->line_edit) | 869 | if (!pm->line_edit) |
909 | #endif | 870 | #endif |
@@ -915,38 +876,31 @@ int kbd_input(char* text, int buflen) | |||
915 | 876 | ||
916 | case ACTION_KBD_UP: | 877 | case ACTION_KBD_UP: |
917 | #ifdef HAVE_MORSE_INPUT | 878 | #ifdef HAVE_MORSE_INPUT |
918 | #ifdef KBD_MODES | ||
919 | if (morse_mode) | 879 | if (morse_mode) |
920 | { | 880 | { |
881 | #ifdef KBD_MODES | ||
921 | pm->line_edit = !pm->line_edit; | 882 | pm->line_edit = !pm->line_edit; |
922 | if(pm->line_edit) | 883 | if(pm->line_edit) |
923 | say_edit(); | 884 | say_edit(); |
924 | } | ||
925 | else | ||
926 | #else | ||
927 | if (morse_mode) | ||
928 | break; | ||
929 | #endif | 885 | #endif |
886 | break; | ||
887 | } | ||
930 | #endif /* HAVE_MORSE_INPUT */ | 888 | #endif /* HAVE_MORSE_INPUT */ |
931 | { | ||
932 | #ifdef KBD_MODES | 889 | #ifdef KBD_MODES |
933 | if (pm->line_edit) | 890 | if (pm->line_edit) |
934 | { | 891 | { |
935 | pm->y = pm->lines - 1; | 892 | pm->y = pm->lines - 1; |
936 | pm->line_edit = false; | 893 | pm->line_edit = false; |
937 | } | 894 | } |
938 | else | 895 | else if (--pm->y < 0) |
939 | #endif | 896 | { |
940 | if (--pm->y < 0) | 897 | pm->line_edit = true; |
941 | #ifdef KBD_MODES | 898 | say_edit(); |
942 | { | 899 | } |
943 | pm->line_edit = true; | ||
944 | say_edit(); | ||
945 | } | ||
946 | #else | 900 | #else |
947 | pm->y = pm->lines - 1; | 901 | if (--pm->y < 0) |
902 | pm->y = pm->lines - 1; | ||
948 | #endif | 903 | #endif |
949 | } | ||
950 | #ifdef KBD_MODES | 904 | #ifdef KBD_MODES |
951 | if (!pm->line_edit) | 905 | if (!pm->line_edit) |
952 | #endif | 906 | #endif |
@@ -956,12 +910,6 @@ int kbd_input(char* text, int buflen) | |||
956 | } | 910 | } |
957 | break; | 911 | break; |
958 | 912 | ||
959 | case ACTION_KBD_DONE: | ||
960 | /* accepts what was entered and continues */ | ||
961 | ret = 0; | ||
962 | done = true; | ||
963 | break; | ||
964 | |||
965 | #ifdef HAVE_MORSE_INPUT | 913 | #ifdef HAVE_MORSE_INPUT |
966 | case ACTION_KBD_MORSE_SELECT: | 914 | case ACTION_KBD_MORSE_SELECT: |
967 | if (morse_mode && morse_reading) | 915 | if (morse_mode && morse_reading) |
@@ -970,7 +918,6 @@ int kbd_input(char* text, int buflen) | |||
970 | if ((current_tick - morse_tick) > HZ/5) | 918 | if ((current_tick - morse_tick) > HZ/5) |
971 | morse_code |= 0x01; | 919 | morse_code |= 0x01; |
972 | } | 920 | } |
973 | |||
974 | break; | 921 | break; |
975 | #endif /* HAVE_MORSE_INPUT */ | 922 | #endif /* HAVE_MORSE_INPUT */ |
976 | 923 | ||
@@ -1058,9 +1005,7 @@ int kbd_input(char* text, int buflen) | |||
1058 | kbd_inschar(text, buflen, &editpos, ch); | 1005 | kbd_inschar(text, buflen, &editpos, ch); |
1059 | 1006 | ||
1060 | if (global_settings.talk_menu) /* voice UI? */ | 1007 | if (global_settings.talk_menu) /* voice UI? */ |
1061 | talk_spell(text, false); | 1008 | talk_spell(text, false); /* speak revised text */ |
1062 | |||
1063 | /* speak revised text */ | ||
1064 | } | 1009 | } |
1065 | break; | 1010 | break; |
1066 | 1011 | ||
@@ -1172,13 +1117,13 @@ int kbd_input(char* text, int buflen) | |||
1172 | if (ret < 0) | 1117 | if (ret < 0) |
1173 | splash(HZ/2, ID2P(LANG_CANCEL)); | 1118 | splash(HZ/2, ID2P(LANG_CANCEL)); |
1174 | 1119 | ||
1175 | #ifdef HAVE_MORSE_INPUT | 1120 | #if defined(HAVE_MORSE_INPUT) && defined(KBD_TOGGLE_INPUT) |
1176 | if(global_settings.morse_input != morse_mode) | 1121 | if(global_settings.morse_input != morse_mode) |
1177 | { | 1122 | { |
1178 | global_settings.morse_input = morse_mode; | 1123 | global_settings.morse_input = morse_mode; |
1179 | settings_save(); | 1124 | settings_save(); |
1180 | } | 1125 | } |
1181 | #endif /* HAVE_MORSE_INPUT */ | 1126 | #endif /* HAVE_MORSE_INPUT && KBD_TOGGLE_INPUT */ |
1182 | 1127 | ||
1183 | FOR_NB_SCREENS(l) | 1128 | FOR_NB_SCREENS(l) |
1184 | screens[l].setfont(FONT_UI); | 1129 | screens[l].setfont(FONT_UI); |