From 4d80fe645327c071f53ea2b4f4c4ccfd389cdf73 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sun, 13 Aug 2006 20:30:19 +0300 Subject: [PATCH] BFU UTF-8: select_button_by_key() folds the case of Unicode characters. This causes the documented-slow cp2u() to be called in a loop, which fortunately doesn't have very many iterations. If this is too slow, then cp2u() can be rewritten, or the hotkeys can be cached in struct widget or struct widget_data. Note that check_kbd_label_key() does not yet allow non-ASCII characters when CONFIG_UTF_8 is defined. Before they are allowed, menu.c should also be updated. --- src/bfu/dialog.c | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/src/bfu/dialog.c b/src/bfu/dialog.c index 289f4b66b..eab5e81c1 100644 --- a/src/bfu/dialog.c +++ b/src/bfu/dialog.c @@ -285,16 +285,33 @@ select_button_by_flag(struct dialog_data *dlg_data, int flag) static void select_button_by_key(struct dialog_data *dlg_data) { +#ifdef CONFIG_UTF_8 + unicode_val_T key; + int codepage; +#else unsigned char key; +#endif + struct widget_data *widget_data; struct term_event *ev = dlg_data->term_event; if (!check_kbd_label_key(ev)) return; +#ifdef CONFIG_UTF_8 + key = unicode_fold_label_case(get_kbd_key(ev)); + codepage = get_opt_codepage_tree(dlg_data->win->term->spec, "charset"); +#else key = toupper(get_kbd_key(ev)); +#endif foreach_widget(dlg_data, widget_data) { int hk_pos; + unsigned char *hk_ptr; +#ifdef CONFIG_UTF_8 + unicode_val_T hk_char; +#else + unsigned char hk_char; +#endif if (widget_data->widget->type != WIDGET_BUTTON) continue; @@ -303,16 +320,26 @@ select_button_by_key(struct dialog_data *dlg_data) * one else we fallback to first character in button * name. */ hk_pos = widget_data->widget->info.button.hotkey_pos; - if (hk_pos >= 0) { - if (toupper(widget_data->widget->text[hk_pos + 1]) != key) - continue; - } else { - if (toupper(widget_data->widget->text[0]) != key) - continue; - } + if (hk_pos >= 0) + hk_ptr = &widget_data->widget->text[hk_pos + 1]; + else + hk_ptr = widget_data->widget->text; - select_dlg_item(dlg_data, widget_data); - break; +#ifdef CONFIG_UTF_8 + if (is_cp_utf8(codepage)) + hk_char = utf_8_to_unicode(&hk_ptr, + strchr(hk_ptr, '\0')); + else + hk_char = cp2u(codepage, *hk_ptr); + hk_char = unicode_fold_label_case(hk_char); +#else + hk_char = toupper(*hk_ptr); +#endif + + if (hk_char == key) { + select_dlg_item(dlg_data, widget_data); + break; + } } }