1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

BFU UTF-8: check_hotkeys_common() compares hotkeys as Unicode.

This commit is contained in:
Kalle Olavi Niemitalo 2006-08-13 23:45:41 +03:00 committed by Kalle Olavi Niemitalo
parent 85d4c5679c
commit 6773c8505d
2 changed files with 28 additions and 8 deletions

View File

@ -122,10 +122,15 @@ refresh_hotkeys(struct terminal *term, struct menu *menu)
} }
static int static int
check_hotkeys_common(struct menu *menu, unsigned char hotkey, struct terminal *term, check_hotkeys_common(struct menu *menu, term_event_char_T hotkey, struct terminal *term,
int check_mode) int check_mode)
{ {
#ifdef CONFIG_UTF_8
unicode_val_T key = unicode_fold_label_case(hotkey);
int codepage = get_opt_codepage_tree(term->spec, "charset");
#else
unsigned char key = toupper(hotkey); unsigned char key = toupper(hotkey);
#endif
int i = menu->selected; int i = menu->selected;
int start; int start;
@ -138,6 +143,9 @@ check_hotkeys_common(struct menu *menu, unsigned char hotkey, struct terminal *t
do { do {
struct menu_item *item; struct menu_item *item;
unsigned char *text; unsigned char *text;
#ifdef CONFIG_UTF_8
unicode_val_T items_hotkey;
#endif
int found; int found;
if (++i == menu->size) i = 0; if (++i == menu->size) i = 0;
@ -150,6 +158,8 @@ check_hotkeys_common(struct menu *menu, unsigned char hotkey, struct terminal *t
if (mi_text_translate(item)) text = _(text, term); if (mi_text_translate(item)) text = _(text, term);
if (!text || !*text) continue; if (!text || !*text) continue;
/* Change @text to point to the character that should
* be compared to @key. */
if (check_mode == 0) { if (check_mode == 0) {
/* Does the key (upcased) matches one of the /* Does the key (upcased) matches one of the
* hotkeys in menu ? */ * hotkeys in menu ? */
@ -158,14 +168,22 @@ check_hotkeys_common(struct menu *menu, unsigned char hotkey, struct terminal *t
#ifdef CONFIG_DEBUG #ifdef CONFIG_DEBUG
if (key_pos < 0) key_pos = -key_pos; if (key_pos < 0) key_pos = -key_pos;
#endif #endif
found = (key_pos && (toupper(text[key_pos]) == key)); if (!key_pos) continue;
text += key_pos;
} else { } else {
/* Does the key (upcased) matches first letter /* Does the key (upcased) matches first letter
* of menu item left text ? */ * of menu item left text ? */
found = (toupper(*text) == key);
} }
/* Compare @key to the character to which @text points. */
#ifdef CONFIG_UTF_8
items_hotkey = cp_to_unicode(codepage, &text,
strchr(text, '\0'));
found = (unicode_fold_label_case(items_hotkey) == key);
#else
found = (toupper(*text) == key);
#endif
if (found) { if (found) {
menu->selected = i; menu->selected = i;
return 1; return 1;
@ -178,7 +196,7 @@ check_hotkeys_common(struct menu *menu, unsigned char hotkey, struct terminal *t
/* Returns true if a hotkey was found in the menu, and set menu->selected. */ /* Returns true if a hotkey was found in the menu, and set menu->selected. */
int int
check_hotkeys(struct menu *menu, unsigned char key, struct terminal *term) check_hotkeys(struct menu *menu, term_event_char_T key, struct terminal *term)
{ {
return check_hotkeys_common(menu, key, term, 0); return check_hotkeys_common(menu, key, term, 0);
} }
@ -188,7 +206,7 @@ check_hotkeys(struct menu *menu, unsigned char key, struct terminal *term)
* to selected entry. * to selected entry.
* It returns 1 if found and set menu->selected. */ * It returns 1 if found and set menu->selected. */
int int
check_not_so_hot_keys(struct menu *menu, unsigned char key, struct terminal *term) check_not_so_hot_keys(struct menu *menu, term_event_char_T key, struct terminal *term)
{ {
return check_hotkeys_common(menu, key, term, 1); return check_hotkeys_common(menu, key, term, 1);
} }

View File

@ -3,6 +3,8 @@
#ifndef EL__BFU_HOTKEY_H #ifndef EL__BFU_HOTKEY_H
#define EL__BFU_HOTKEY_H #define EL__BFU_HOTKEY_H
#include "terminal/kbd.h"
struct menu; struct menu;
struct terminal; struct terminal;
@ -13,7 +15,7 @@ void clear_hotkeys_cache(struct menu *menu);
#endif #endif
void refresh_hotkeys(struct terminal *term, struct menu *menu); void refresh_hotkeys(struct terminal *term, struct menu *menu);
/* int is_hotkey(struct menu_item *item, unsigned char key, struct terminal *term); */ /* int is_hotkey(struct menu_item *item, unsigned char key, struct terminal *term); */
int check_hotkeys(struct menu *menu, unsigned char hotkey, struct terminal *term); int check_hotkeys(struct menu *menu, term_event_char_T hotkey, struct terminal *term);
int check_not_so_hot_keys(struct menu *menu, unsigned char key, struct terminal *term); int check_not_so_hot_keys(struct menu *menu, term_event_char_T key, struct terminal *term);
#endif #endif