Deleted Added
sdiff udiff text old ( 217309 ) new ( 241818 )
full compact
1/*
2 * $Id: dlg_keys.c,v 1.26 2009/02/22 16:19:51 tom Exp $
3 *
4 * dlg_keys.c -- runtime binding support for dialog
5 *
6 * Copyright 2006-2007,2009 Thomas E. Dickey
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License, version 2.1
10 * as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU

--- 14 unchanged lines hidden (view full) ---

29LIST_BINDINGS {
30 LIST_BINDINGS *link;
31 WINDOW *win; /* window on which widget gets input */
32 const char *name; /* widget name */
33 bool buttons; /* true only for dlg_register_buttons() */
34 DLG_KEYS_BINDING *binding; /* list of bindings */
35};
36
37static LIST_BINDINGS *all_bindings;
38static const DLG_KEYS_BINDING end_keys_binding = END_KEYS_BINDING;
39
40/*
41 * For a given named widget's window, associate a binding table.
42 */
43void
44dlg_register_window(WINDOW *win, const char *name, DLG_KEYS_BINDING * binding)

--- 11 unchanged lines hidden (view full) ---

56 p->win = win;
57 p->name = name;
58 p->binding = binding;
59 if (q != 0)
60 q->link = p;
61 else
62 all_bindings = p;
63 }
64}
65
66/*
67 * Unlike dlg_lookup_key(), this looks for either widget-builtin or rc-file
68 * definitions, depending on whether 'win' is null.
69 */
70static int
71key_is_bound(WINDOW *win, const char *name, int curses_key, int function_key)

--- 112 unchanged lines hidden (view full) ---

184 * curses_key is the value returned by wgetch().
185 * fkey in/out (on input, it is true if curses_key is a function key,
186 * and on output, it is true if the result is a function key).
187 */
188int
189dlg_lookup_key(WINDOW *win, int curses_key, int *fkey)
190{
191 LIST_BINDINGS *p;
192 int n;
193
194 /*
195 * Ignore mouse clicks, since they are already encoded properly.
196 */
197#ifdef KEY_MOUSE
198 if (*fkey != 0 && curses_key == KEY_MOUSE) {
199 ;
200 } else
201#endif
202 /*
203 * Ignore resize events, since they are already encoded properly.
204 */
205#ifdef KEY_RESIZE
206 if (*fkey != 0 && curses_key == KEY_RESIZE) {
207 ;
208 } else
209#endif
210 if (*fkey == 0 || curses_key < KEY_MAX) {
211 for (p = all_bindings; p != 0; p = p->link) {
212 if (p->win == win || p->win == 0) {
213 int function_key = (*fkey != 0);
214 for (n = 0; p->binding[n].is_function_key >= 0; ++n) {
215 if (p->buttons
216 && !function_key
217 && p->binding[n].curses_key == (int) dlg_toupper(curses_key)) {
218 *fkey = 0;
219 return p->binding[n].dialog_key;
220 }
221 if (p->binding[n].curses_key == curses_key
222 && p->binding[n].is_function_key == function_key) {
223 *fkey = p->binding[n].dialog_key;
224 return *fkey;
225 }
226 }
227 }
228 }
229 }
230 return curses_key;
231}

--- 58 unchanged lines hidden (view full) ---

290}
291
292#ifdef HAVE_RC_FILE
293typedef struct {
294 const char *name;
295 int code;
296} CODENAME;
297
298#define CURSES_NAME(upper) { #upper, KEY_ ## upper }
299#define COUNT_CURSES sizeof(curses_names)/sizeof(curses_names[0])
300static const CODENAME curses_names[] =
301{
302 CURSES_NAME(DOWN),
303 CURSES_NAME(UP),
304 CURSES_NAME(LEFT),
305 CURSES_NAME(RIGHT),
306 CURSES_NAME(HOME),
307 CURSES_NAME(BACKSPACE),
308 CURSES_NAME(F0),
309 CURSES_NAME(DL),

--- 93 unchanged lines hidden (view full) ---

403 DIALOG_NAME(ITEM_FIRST),
404 DIALOG_NAME(ITEM_LAST),
405 DIALOG_NAME(ITEM_NEXT),
406 DIALOG_NAME(ITEM_PREV),
407 DIALOG_NAME(FIELD_FIRST),
408 DIALOG_NAME(FIELD_LAST),
409 DIALOG_NAME(FIELD_NEXT),
410 DIALOG_NAME(FIELD_PREV),
411 DIALOG_NAME(GRID_UP),
412 DIALOG_NAME(GRID_DOWN),
413 DIALOG_NAME(GRID_LEFT),
414 DIALOG_NAME(GRID_RIGHT),
415 DIALOG_NAME(DELETE_LEFT),
416 DIALOG_NAME(DELETE_RIGHT),
417 DIALOG_NAME(DELETE_ALL),
418 DIALOG_NAME(ENTER),
419 DIALOG_NAME(BEGIN),
420 DIALOG_NAME(FINAL),
421 DIALOG_NAME(SELECT)
422};
423
424static char *
425skip_white(char *s)
426{
427 while (*s != '\0' && isspace(UCH(*s)))
428 ++s;
429 return s;

--- 37 unchanged lines hidden (view full) ---

467 */
468static int
469compare_bindings(LIST_BINDINGS * a, LIST_BINDINGS * b)
470{
471 int result = 0;
472 if (a->win == b->win) {
473 if (!strcmp(a->name, b->name)) {
474 result = a->binding[0].curses_key - b->binding[0].curses_key;
475 } else if (!strcmp(b->name, "*")) {
476 result = -1;
477 } else if (!strcmp(a->name, "*")) {
478 result = 1;
479 } else {
480 result = dlg_strcmp(a->name, b->name);
481 }
482 } else if (b->win) {
483 result = -1;
484 } else {
485 result = 1;

--- 81 unchanged lines hidden (view full) ---

567
568 curses_key = -1;
569 dialog_key = -1;
570 widget = p;
571
572 p = skip_black(p);
573 if (p != widget && *p != '\0') {
574 *p++ = '\0';
575 q = p;
576 while (*p != '\0' && curses_key < 0) {
577 if (escaped) {
578 escaped = FALSE;
579 curses_key = *p;
580 } else if (*p == '\\') {
581 escaped = TRUE;
582 } else if (modified) {

--- 25 unchanged lines hidden (view full) ---

608 int keynumber;
609 if (sscanf(q, "%[Ff]%d%c", fprefix, &keynumber, check) == 2) {
610 curses_key = KEY_F(keynumber);
611 is_function = TRUE;
612 } else {
613 for (xx = 0; xx < COUNT_CURSES; ++xx) {
614 if (!dlg_strcmp(curses_names[xx].name, q)) {
615 curses_key = curses_names[xx].code;
616 is_function = TRUE;
617 break;
618 }
619 }
620 }
621 }
622 }
623 q = skip_white(p);
624 p = skip_black(q);

--- 70 unchanged lines hidden (view full) ---

695{
696 fprintf(fp, "bindkey %s ", widget);
697 dump_curses_key(fp, binding->curses_key);
698 fputc(' ', fp);
699 dump_dialog_key(fp, binding->dialog_key);
700 fputc('\n', fp);
701}
702
703void
704dlg_dump_keys(FILE *fp)
705{
706 LIST_BINDINGS *p;
707 const char *last = "";
708 unsigned n;
709 unsigned count = 0;
710
711 for (p = all_bindings; p != 0; p = p->link) {
712 if (p->win == 0) {
713 ++count;
714 }
715 }
716 if (count != 0) {
717 for (p = all_bindings, n = 0; p != 0; p = p->link) {
718 if (p->win == 0) {
719 if (dlg_strcmp(last, p->name)) {
720 fprintf(fp, "\n# key bindings for %s widgets\n",
721 !strcmp(p->name, "*") ? "all" : p->name);
722 last = p->name;
723 }
724 dump_one_binding(fp, p->name, p->binding);
725 }
726 }
727 }
728}
729#endif /* HAVE_RC_FILE */