/* * Match a given character against the beginning of the string, ignoring case * of the given character. The matching string must begin with an uppercase * character. */ int dlg_match_char(int ch, const char *string) { if (string != 0) { int cmp2 = string_to_char(&string); #ifdef USE_WIDE_CURSES wint_t cmp1 = dlg_toupper(ch); if (cmp2 != 0 && (wchar_t) cmp1 == (wchar_t) dlg_toupper(cmp2)) { return TRUE; } #else if (ch > 0 && ch < 256) { if (dlg_toupper(ch) == dlg_toupper(cmp2)) return TRUE; } #endif } return FALSE; }
/* * Call this after wgetch(), using the same window pointer and passing * the curses-key. * * If there is no binding associated with the widget, it simply returns * the given curses-key. * * Parameters: * win is the window on which the wgetch() was done. * curses_key is the value returned by wgetch(). * fkey in/out (on input, it is true if curses_key is a function key, * and on output, it is true if the result is a function key). */ int dlg_lookup_key(WINDOW *win, int curses_key, int *fkey) { LIST_BINDINGS *p; DLG_KEYS_BINDING *q; /* * Ignore mouse clicks, since they are already encoded properly. */ #ifdef KEY_MOUSE if (*fkey != 0 && curses_key == KEY_MOUSE) { ; } else #endif /* * Ignore resize events, since they are already encoded properly. */ #ifdef KEY_RESIZE if (*fkey != 0 && curses_key == KEY_RESIZE) { ; } else #endif if (*fkey == 0 || curses_key < KEY_MAX) { const char *name = WILDNAME; if (win != 0) { for (p = all_bindings; p != 0; p = p->link) { if (p->win == win) { name = p->name; break; } } } for (p = all_bindings; p != 0; p = p->link) { if (p->win == win || (p->win == 0 && (!strcmp(p->name, name) || !strcmp(p->name, WILDNAME)))) { int function_key = (*fkey != 0); for (q = p->binding; q->is_function_key >= 0; ++q) { if (p->buttons && !function_key && q->curses_key == (int) dlg_toupper(curses_key)) { *fkey = 0; return q->dialog_key; } if (q->curses_key == curses_key && q->is_function_key == function_key) { *fkey = q->dialog_key; return *fkey; } } } } } return curses_key; }
/* * Given a list of button labels, and a character which may be the abbreviation * for one, find it, if it exists. An abbreviation will be the first character * which happens to be capitalized in the label. */ int dlg_char_to_button(int ch, const char **labels) { if (labels != 0) { int j; ch = (int) dlg_toupper(dlg_last_getc()); for (j = 0; labels[j] != 0; ++j) { int cmp = dlg_button_to_char(labels[j]); if (ch == cmp) { dlg_flush_getc(); return j; } } } return DLG_EXIT_UNKNOWN; }
/* * Call this after wgetch(), using the same window pointer and passing * the curses-key. * * If there is no binding associated with the widget, it simply returns * the given curses-key. * * Parameters: * win is the window on which the wgetch() was done. * curses_key is the value returned by wgetch(). * fkey in/out (on input, it is true if curses_key is a function key, * and on output, it is true if the result is a function key). */ int dlg_lookup_key(WINDOW *win, int curses_key, int *fkey) { LIST_BINDINGS *p; int n; /* * Ignore mouse clicks, since they are already encoded properly. */ #ifdef KEY_MOUSE if (*fkey != 0 && curses_key == KEY_MOUSE) { ; } else #endif /* * Ignore resize events, since they are already encoded properly. */ #ifdef KEY_RESIZE if (*fkey != 0 && curses_key == KEY_RESIZE) { ; } else #endif if (*fkey == 0 || curses_key < KEY_MAX) { for (p = all_bindings; p != 0; p = p->link) { if (p->win == win || p->win == 0) { int function_key = (*fkey != 0); for (n = 0; p->binding[n].is_function_key >= 0; ++n) { if (p->buttons && !function_key && p->binding[n].curses_key == (int) dlg_toupper(curses_key)) { *fkey = 0; return p->binding[n].dialog_key; } if (p->binding[n].curses_key == curses_key && p->binding[n].is_function_key == function_key) { *fkey = p->binding[n].dialog_key; return *fkey; } } } } } return curses_key; }