xref: /freebsd/contrib/dialog/dlg_keys.h (revision 884a2a699669ec61e2366e3e358342dbc94be24a)
1 /*
2  *  $Id: dlg_keys.h,v 1.24 2010/01/19 00:57:36 tom Exp $
3  *
4  * dlg_keys.h -- runtime binding support for dialog
5  *
6  * Copyright 2005-2007,2010 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
15  *  Lesser General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Lesser General Public
18  *  License along with this program; if not, write to
19  *	Free Software Foundation, Inc.
20  *	51 Franklin St., Fifth Floor
21  *	Boston, MA 02110, USA.
22  */
23 
24 #ifndef DLG_KEYS_H_included
25 #define DLG_KEYS_H_included 1
26 
27 #include <dialog.h>
28 
29 #ifdef USE_WIDE_CURSES
30 #include <wctype.h>
31 #define dlg_toupper(ch) towupper((wint_t)ch)
32 #define dlg_isupper(ch) iswupper((wint_t)ch)
33 #else
34 #define dlg_toupper(ch) toupper(ch)
35 #define dlg_isupper(ch) (isalpha(ch) && isupper(ch))
36 #endif
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 typedef struct {
43     int is_function_key;
44     int	curses_key;
45     int dialog_key;
46 } DLG_KEYS_BINDING;
47 
48 #define DLG_KEYS_DATA(dialog, curses)  { curses >= KEY_MIN, curses, dialog }
49 
50 #define END_KEYS_BINDING { -1, 0, 0 }
51 
52 /*
53  * Define dialog's internal function-keys past the range used by curses.
54  */
55 typedef enum {
56     DLGK_MIN = KEY_MAX + 1,
57     /* predefined buttons */
58     DLGK_OK,
59     DLGK_CANCEL,
60     DLGK_EXTRA,
61     DLGK_HELP,
62     DLGK_ESC,
63     /* moving from screen to screen (pages) */
64     DLGK_PAGE_FIRST,
65     DLGK_PAGE_LAST,
66     DLGK_PAGE_NEXT,
67     DLGK_PAGE_PREV,
68     /* moving within a list */
69     DLGK_ITEM_FIRST,
70     DLGK_ITEM_LAST,
71     DLGK_ITEM_NEXT,
72     DLGK_ITEM_PREV,
73     /* moving from field to field (or buttons) */
74     DLGK_FIELD_FIRST,
75     DLGK_FIELD_LAST,
76     DLGK_FIELD_NEXT,
77     DLGK_FIELD_PREV,
78     /* moving within a grid */
79     DLGK_GRID_UP,
80     DLGK_GRID_DOWN,
81     DLGK_GRID_LEFT,
82     DLGK_GRID_RIGHT,
83     /* delete */
84     DLGK_DELETE_LEFT,
85     DLGK_DELETE_RIGHT,
86     DLGK_DELETE_ALL,
87     /* special */
88     DLGK_ENTER,
89     DLGK_BEGIN,
90     DLGK_FINAL,
91     DLGK_SELECT,
92     DLGK_TRACE
93 } DLG_KEYS_ENUM;
94 
95 #define is_DLGK_MOUSE(code)	((code) >= M_EVENT)
96 #define DLGK_MOUSE(code)	((code) + M_EVENT)
97 
98 #define ENTERKEY_BINDINGS \
99 	DLG_KEYS_DATA( DLGK_ENTER,	   '\n' ), \
100 	DLG_KEYS_DATA( DLGK_ENTER,	   '\r' ), \
101 	DLG_KEYS_DATA( DLGK_ENTER,	   KEY_ENTER )
102 
103 /* ^U == 21 */
104 #define INPUTSTR_BINDINGS \
105 	DLG_KEYS_DATA( DLGK_BEGIN,	   KEY_HOME ), \
106 	DLG_KEYS_DATA( DLGK_DELETE_ALL,    CHR_KILL ), \
107 	DLG_KEYS_DATA( DLGK_DELETE_LEFT,   CHR_BACKSPACE ), \
108 	DLG_KEYS_DATA( DLGK_DELETE_LEFT,   KEY_BACKSPACE ), \
109 	DLG_KEYS_DATA( DLGK_DELETE_RIGHT,  CHR_DELETE ), \
110 	DLG_KEYS_DATA( DLGK_DELETE_RIGHT,  KEY_DC ), \
111 	DLG_KEYS_DATA( DLGK_FINAL,	   KEY_END ), \
112 	DLG_KEYS_DATA( DLGK_GRID_LEFT,	   KEY_LEFT ), \
113 	DLG_KEYS_DATA( DLGK_GRID_RIGHT,	   KEY_RIGHT )
114 
115 #define SCROLLKEY_BINDINGS \
116 	DLG_KEYS_DATA( DLGK_GRID_DOWN,	'J' ), \
117 	DLG_KEYS_DATA( DLGK_GRID_DOWN,	'j' ), \
118 	DLG_KEYS_DATA( DLGK_GRID_DOWN,	KEY_DOWN ), \
119 	DLG_KEYS_DATA( DLGK_GRID_UP,	'K' ), \
120 	DLG_KEYS_DATA( DLGK_GRID_UP,	'k' ), \
121 	DLG_KEYS_DATA( DLGK_GRID_UP,	KEY_UP ), \
122 	DLG_KEYS_DATA( DLGK_PAGE_FIRST,	'g' ), \
123 	DLG_KEYS_DATA( DLGK_PAGE_FIRST,	KEY_HOME ), \
124 	DLG_KEYS_DATA( DLGK_PAGE_LAST,	'G' ), \
125 	DLG_KEYS_DATA( DLGK_PAGE_LAST,	KEY_END ), \
126 	DLG_KEYS_DATA( DLGK_PAGE_NEXT,	'F' ), \
127 	DLG_KEYS_DATA( DLGK_PAGE_NEXT,	'f' ), \
128 	DLG_KEYS_DATA( DLGK_PAGE_NEXT,	KEY_NPAGE ), \
129 	DLG_KEYS_DATA( DLGK_PAGE_PREV,	'B' ), \
130 	DLG_KEYS_DATA( DLGK_PAGE_PREV,	'b' ), \
131 	DLG_KEYS_DATA( DLGK_PAGE_PREV,	KEY_PPAGE )
132 
133 extern int dlg_lookup_key(WINDOW * /*win*/, int /*curses_key*/, int * /*dialog_key*/);
134 extern int dlg_result_key(int /*dialog_key*/, int /*fkey*/, int * /*resultp*/);
135 extern void dlg_register_buttons(WINDOW * /*win*/, const char * /*name*/, const char ** /*buttons*/);
136 extern void dlg_register_window(WINDOW * /*win*/, const char * /*name*/, DLG_KEYS_BINDING * /*binding*/);
137 extern void dlg_unregister_window(WINDOW * /*win*/);
138 
139 #ifdef HAVE_RC_FILE
140 extern int dlg_parse_bindkey(char * /*params*/);
141 extern void dlg_dump_keys(FILE * /*fp*/);
142 #endif
143 
144 #ifdef __cplusplus
145 }
146 #endif
147 
148 #endif /* DLG_KEYS_H_included */
149