1 /* 2 * $Id: dlg_keys.h,v 1.42 2022/04/14 23:14:33 tom Exp $ 3 * 4 * dlg_keys.h -- runtime binding support for dialog 5 * 6 * Copyright 2005-2020,2022 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 /* *INDENT-OFF* */ 27 28 #include <dialog.h> 29 30 #ifdef USE_WIDE_CURSES 31 #include <wctype.h> 32 #define dlg_toupper(ch) towupper((wint_t)ch) 33 #define dlg_isupper(ch) iswupper((wint_t)ch) 34 #else 35 #define dlg_toupper(ch) (((ch) > 0 && (ch) <= 255) ? toupper(ch) : (ch)) 36 #define dlg_isupper(ch) (isalpha(ch) && isupper(ch)) 37 #endif 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 typedef struct { 44 int is_function_key; 45 int curses_key; 46 int dialog_key; 47 } DLG_KEYS_BINDING; 48 49 #define DLG_KEYS_DATA(dialog, curses) { (curses) >= KEY_MIN, curses, dialog } 50 51 #define END_KEYS_BINDING { -1, 0, 0 } 52 53 /* 54 * Define dialog's internal function-keys past the range used by curses. 55 */ 56 typedef enum { 57 DLGK_MIN = KEY_MAX + 1, 58 /* predefined buttons */ 59 DLGK_OK, 60 DLGK_CANCEL, 61 DLGK_EXTRA, 62 DLGK_HELP, 63 DLGK_ESC, 64 /* moving from screen to screen (pages) */ 65 DLGK_PAGE_FIRST, 66 DLGK_PAGE_LAST, 67 DLGK_PAGE_NEXT, 68 DLGK_PAGE_PREV, 69 /* moving within a list */ 70 DLGK_ITEM_FIRST, 71 DLGK_ITEM_LAST, 72 DLGK_ITEM_NEXT, 73 DLGK_ITEM_PREV, 74 /* moving from field to field (or buttons) */ 75 DLGK_FIELD_FIRST, 76 DLGK_FIELD_LAST, 77 DLGK_FIELD_NEXT, 78 DLGK_FIELD_PREV, 79 /* moving from form-field to form-field (or buttons) */ 80 DLGK_FORM_FIRST, 81 DLGK_FORM_LAST, 82 DLGK_FORM_NEXT, 83 DLGK_FORM_PREV, 84 /* moving within a grid */ 85 DLGK_GRID_UP, 86 DLGK_GRID_DOWN, 87 DLGK_GRID_LEFT, 88 DLGK_GRID_RIGHT, 89 /* delete */ 90 DLGK_DELETE_LEFT, 91 DLGK_DELETE_RIGHT, 92 DLGK_DELETE_ALL, 93 /* special */ 94 DLGK_ENTER, 95 DLGK_BEGIN, 96 DLGK_FINAL, 97 DLGK_SELECT, 98 DLGK_HELPFILE, 99 DLGK_TRACE, 100 DLGK_TOGGLE, 101 DLGK_LEAVE 102 } DLG_KEYS_ENUM; 103 104 #define is_DLGK_MOUSE(code) ((code) >= M_EVENT) 105 #define DLGK_MOUSE(code) ((code) + M_EVENT) 106 107 #define DLG_CTRL(n) ((n) & 0x1f) /* CTRL is preferred, but conflicts */ 108 109 #define CHR_LEAVE DLG_CTRL('D') 110 #define CHR_HELP DLG_CTRL('E') 111 #define CHR_BACKSPACE DLG_CTRL('H') 112 #define CHR_REPAINT DLG_CTRL('L') 113 #define CHR_NEXT DLG_CTRL('N') 114 #define CHR_PREVIOUS DLG_CTRL('P') 115 #define CHR_KILL DLG_CTRL('U') 116 #define CHR_TRACE DLG_CTRL('T') 117 #define CHR_LITERAL DLG_CTRL('V') 118 #define CHR_SPACE ' ' 119 #define CHR_DELETE 127 120 121 #define ESC DLG_CTRL('[') 122 #define TAB DLG_CTRL('I') 123 124 #define HELPKEY_BINDINGS \ 125 DLG_KEYS_DATA( DLGK_HELPFILE, CHR_HELP ), \ 126 DLG_KEYS_DATA( DLGK_HELPFILE, KEY_F(1) ), \ 127 DLG_KEYS_DATA( DLGK_HELPFILE, KEY_HELP ) 128 129 #define ENTERKEY_BINDINGS \ 130 DLG_KEYS_DATA( DLGK_ENTER, '\n' ), \ 131 DLG_KEYS_DATA( DLGK_ENTER, '\r' ), \ 132 DLG_KEYS_DATA( DLGK_ENTER, KEY_ENTER ), \ 133 DLG_KEYS_DATA( DLGK_LEAVE, CHR_LEAVE ) 134 135 /* ^U == 21 */ 136 #define INPUTSTR_BINDINGS \ 137 DLG_KEYS_DATA( DLGK_BEGIN, KEY_HOME ), \ 138 DLG_KEYS_DATA( DLGK_DELETE_ALL, CHR_KILL ), \ 139 DLG_KEYS_DATA( DLGK_DELETE_LEFT, CHR_BACKSPACE ), \ 140 DLG_KEYS_DATA( DLGK_DELETE_LEFT, KEY_BACKSPACE ), \ 141 DLG_KEYS_DATA( DLGK_DELETE_RIGHT, CHR_DELETE ), \ 142 DLG_KEYS_DATA( DLGK_DELETE_RIGHT, KEY_DC ), \ 143 DLG_KEYS_DATA( DLGK_FINAL, KEY_END ), \ 144 DLG_KEYS_DATA( DLGK_GRID_LEFT, KEY_LEFT ), \ 145 DLG_KEYS_DATA( DLGK_GRID_RIGHT, KEY_RIGHT ) 146 147 #define SCROLL_FKEY_BINDINGS \ 148 DLG_KEYS_DATA( DLGK_GRID_DOWN, KEY_DOWN ), \ 149 DLG_KEYS_DATA( DLGK_GRID_UP, KEY_UP ), \ 150 DLG_KEYS_DATA( DLGK_PAGE_FIRST, KEY_HOME ), \ 151 DLG_KEYS_DATA( DLGK_PAGE_LAST, KEY_END ), \ 152 DLG_KEYS_DATA( DLGK_PAGE_NEXT, KEY_NPAGE ), \ 153 DLG_KEYS_DATA( DLGK_PAGE_PREV, KEY_PPAGE ) 154 155 #define SCROLLKEY_BINDINGS \ 156 SCROLL_FKEY_BINDINGS, \ 157 DLG_KEYS_DATA( DLGK_GRID_DOWN, 'J' ), \ 158 DLG_KEYS_DATA( DLGK_GRID_DOWN, 'j' ), \ 159 DLG_KEYS_DATA( DLGK_GRID_UP, 'K' ), \ 160 DLG_KEYS_DATA( DLGK_GRID_UP, 'k' ), \ 161 DLG_KEYS_DATA( DLGK_PAGE_FIRST, 'g' ), \ 162 DLG_KEYS_DATA( DLGK_PAGE_LAST, 'G' ), \ 163 DLG_KEYS_DATA( DLGK_PAGE_NEXT, 'F' ), \ 164 DLG_KEYS_DATA( DLGK_PAGE_NEXT, 'f' ), \ 165 DLG_KEYS_DATA( DLGK_PAGE_PREV, 'B' ), \ 166 DLG_KEYS_DATA( DLGK_PAGE_PREV, 'b' ) 167 168 #define TRAVERSE_BINDINGS \ 169 DLG_KEYS_DATA( DLGK_ENTER, CHR_SPACE ), \ 170 DLG_KEYS_DATA( DLGK_FIELD_NEXT, KEY_DOWN ), \ 171 DLG_KEYS_DATA( DLGK_FIELD_NEXT, KEY_RIGHT ), \ 172 DLG_KEYS_DATA( DLGK_FIELD_NEXT, TAB ), \ 173 DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_UP ), \ 174 DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_BTAB ), \ 175 DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_LEFT ) 176 177 #define TOGGLEKEY_BINDINGS \ 178 DLG_KEYS_DATA( DLGK_TOGGLE, CHR_SPACE ) 179 180 extern int dlg_button_key(int /*exit_code*/, int * /*button*/, int * /*dialog_key*/, int * /*fkey*/); 181 extern int dlg_lookup_key(WINDOW * /*win*/, int /*curses_key*/, int * /*dialog_key*/); 182 extern int dlg_ok_button_key(int /*exit_code*/, int * /*button*/, int * /*dialog_key*/, int * /*fkey*/); 183 extern int dlg_result_key(int /*dialog_key*/, int /*fkey*/, int * /*resultp*/); 184 extern void dlg_register_buttons(WINDOW * /*win*/, const char * /*name*/, const char ** /*buttons*/); 185 extern void dlg_register_window(WINDOW * /*win*/, const char * /*name*/, DLG_KEYS_BINDING * /*binding*/); 186 extern void dlg_unregister_window(WINDOW * /*win*/); 187 188 #ifdef HAVE_RC_FILE 189 extern int dlg_parse_bindkey(char * /*params*/); 190 extern void dlg_dump_keys(FILE * /*fp*/); 191 extern void dlg_dump_window_keys(FILE * /*fp*/, WINDOW * /*win*/); 192 #endif 193 194 #ifdef __cplusplus 195 } 196 #endif 197 /* *INDENT-ON* */ 198 199 #endif /* DLG_KEYS_H_included */ 200