183cbb37nwhitehorn/*
2f8604a5bapt *  $Id: dlg_keys.h,v 1.36 2016/08/28 21:23:17 tom Exp $
383cbb37nwhitehorn *
494f19e0nwhitehorn *  dlg_keys.h -- runtime binding support for dialog
583cbb37nwhitehorn *
6f8604a5bapt *  Copyright 2005-2012,2016 Thomas E.  Dickey
783cbb37nwhitehorn *
883cbb37nwhitehorn *  This program is free software; you can redistribute it and/or modify
983cbb37nwhitehorn *  it under the terms of the GNU Lesser General Public License, version 2.1
1083cbb37nwhitehorn *  as published by the Free Software Foundation.
1183cbb37nwhitehorn *
1283cbb37nwhitehorn *  This program is distributed in the hope that it will be useful, but
1383cbb37nwhitehorn *  WITHOUT ANY WARRANTY; without even the implied warranty of
1483cbb37nwhitehorn *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1583cbb37nwhitehorn *  Lesser General Public License for more details.
1683cbb37nwhitehorn *
1783cbb37nwhitehorn *  You should have received a copy of the GNU Lesser General Public
1883cbb37nwhitehorn *  License along with this program; if not, write to
1983cbb37nwhitehorn *	Free Software Foundation, Inc.
2083cbb37nwhitehorn *	51 Franklin St., Fifth Floor
2183cbb37nwhitehorn *	Boston, MA 02110, USA.
2283cbb37nwhitehorn */
2383cbb37nwhitehorn
2483cbb37nwhitehorn#ifndef DLG_KEYS_H_included
2583cbb37nwhitehorn#define DLG_KEYS_H_included 1
26a94245bnwhitehorn/* *INDENT-OFF* */
2783cbb37nwhitehorn
2883cbb37nwhitehorn#include <dialog.h>
2983cbb37nwhitehorn
3083cbb37nwhitehorn#ifdef USE_WIDE_CURSES
3183cbb37nwhitehorn#include <wctype.h>
3283cbb37nwhitehorn#define dlg_toupper(ch) towupper((wint_t)ch)
3383cbb37nwhitehorn#define dlg_isupper(ch) iswupper((wint_t)ch)
3483cbb37nwhitehorn#else
35a94245bnwhitehorn#define dlg_toupper(ch) (((ch) > 0 && (ch) <= 255) ? toupper(ch) : (ch))
3683cbb37nwhitehorn#define dlg_isupper(ch) (isalpha(ch) && isupper(ch))
3783cbb37nwhitehorn#endif
3883cbb37nwhitehorn
3983cbb37nwhitehorn#ifdef __cplusplus
4083cbb37nwhitehornextern "C" {
4183cbb37nwhitehorn#endif
4283cbb37nwhitehorn
4383cbb37nwhitehorntypedef struct {
4483cbb37nwhitehorn    int is_function_key;
4583cbb37nwhitehorn    int	curses_key;
4683cbb37nwhitehorn    int dialog_key;
4783cbb37nwhitehorn} DLG_KEYS_BINDING;
4883cbb37nwhitehorn
49a94245bnwhitehorn#define DLG_KEYS_DATA(dialog, curses)  { (curses) >= KEY_MIN, curses, dialog }
5083cbb37nwhitehorn
5183cbb37nwhitehorn#define END_KEYS_BINDING { -1, 0, 0 }
5283cbb37nwhitehorn
5383cbb37nwhitehorn/*
5483cbb37nwhitehorn * Define dialog's internal function-keys past the range used by curses.
5583cbb37nwhitehorn */
5683cbb37nwhitehorntypedef enum {
5783cbb37nwhitehorn    DLGK_MIN = KEY_MAX + 1,
5883cbb37nwhitehorn    /* predefined buttons */
5983cbb37nwhitehorn    DLGK_OK,
6083cbb37nwhitehorn    DLGK_CANCEL,
6183cbb37nwhitehorn    DLGK_EXTRA,
6283cbb37nwhitehorn    DLGK_HELP,
6383cbb37nwhitehorn    DLGK_ESC,
6483cbb37nwhitehorn    /* moving from screen to screen (pages) */
6583cbb37nwhitehorn    DLGK_PAGE_FIRST,
6683cbb37nwhitehorn    DLGK_PAGE_LAST,
6783cbb37nwhitehorn    DLGK_PAGE_NEXT,
6883cbb37nwhitehorn    DLGK_PAGE_PREV,
6983cbb37nwhitehorn    /* moving within a list */
7083cbb37nwhitehorn    DLGK_ITEM_FIRST,
7183cbb37nwhitehorn    DLGK_ITEM_LAST,
7283cbb37nwhitehorn    DLGK_ITEM_NEXT,
7383cbb37nwhitehorn    DLGK_ITEM_PREV,
7483cbb37nwhitehorn    /* moving from field to field (or buttons) */
7583cbb37nwhitehorn    DLGK_FIELD_FIRST,
7683cbb37nwhitehorn    DLGK_FIELD_LAST,
7783cbb37nwhitehorn    DLGK_FIELD_NEXT,
7883cbb37nwhitehorn    DLGK_FIELD_PREV,
79a94245bnwhitehorn    /* moving from form-field to form-field (or buttons) */
80a94245bnwhitehorn    DLGK_FORM_FIRST,
81a94245bnwhitehorn    DLGK_FORM_LAST,
82a94245bnwhitehorn    DLGK_FORM_NEXT,
83a94245bnwhitehorn    DLGK_FORM_PREV,
8483cbb37nwhitehorn    /* moving within a grid */
8583cbb37nwhitehorn    DLGK_GRID_UP,
8683cbb37nwhitehorn    DLGK_GRID_DOWN,
8783cbb37nwhitehorn    DLGK_GRID_LEFT,
8883cbb37nwhitehorn    DLGK_GRID_RIGHT,
8983cbb37nwhitehorn    /* delete */
9083cbb37nwhitehorn    DLGK_DELETE_LEFT,
9183cbb37nwhitehorn    DLGK_DELETE_RIGHT,
9283cbb37nwhitehorn    DLGK_DELETE_ALL,
9383cbb37nwhitehorn    /* special */
9483cbb37nwhitehorn    DLGK_ENTER,
9583cbb37nwhitehorn    DLGK_BEGIN,
9683cbb37nwhitehorn    DLGK_FINAL,
9783cbb37nwhitehorn    DLGK_SELECT,
9894f19e0nwhitehorn    DLGK_HELPFILE,
99f8604a5bapt    DLGK_TRACE,
100f8604a5bapt    DLGK_TOGGLE
10183cbb37nwhitehorn} DLG_KEYS_ENUM;
10283cbb37nwhitehorn
10383cbb37nwhitehorn#define is_DLGK_MOUSE(code)	((code) >= M_EVENT)
10483cbb37nwhitehorn#define DLGK_MOUSE(code)	((code) + M_EVENT)
10583cbb37nwhitehorn
10694f19e0nwhitehorn#define HELPKEY_BINDINGS \
10794f19e0nwhitehorn	DLG_KEYS_DATA( DLGK_HELPFILE,	   CHR_HELP ), \
10894f19e0nwhitehorn	DLG_KEYS_DATA( DLGK_HELPFILE,	   KEY_F(1) ), \
10994f19e0nwhitehorn	DLG_KEYS_DATA( DLGK_HELPFILE,	   KEY_HELP )
11094f19e0nwhitehorn
11183cbb37nwhitehorn#define ENTERKEY_BINDINGS \
11283cbb37nwhitehorn	DLG_KEYS_DATA( DLGK_ENTER,	   '\n' ), \
11383cbb37nwhitehorn	DLG_KEYS_DATA( DLGK_ENTER,	   '\r' ), \
11483cbb37nwhitehorn	DLG_KEYS_DATA( DLGK_ENTER,	   KEY_ENTER )
11583cbb37nwhitehorn
11683cbb37nwhitehorn/* ^U == 21 */
11783cbb37nwhitehorn#define INPUTSTR_BINDINGS \
11883cbb37nwhitehorn	DLG_KEYS_DATA( DLGK_BEGIN,	   KEY_HOME ), \
11983cbb37nwhitehorn	DLG_KEYS_DATA( DLGK_DELETE_ALL,    CHR_KILL ), \
12083cbb37nwhitehorn	DLG_KEYS_DATA( DLGK_DELETE_LEFT,   CHR_BACKSPACE ), \
12183cbb37nwhitehorn	DLG_KEYS_DATA( DLGK_DELETE_LEFT,   KEY_BACKSPACE ), \
12283cbb37nwhitehorn	DLG_KEYS_DATA( DLGK_DELETE_RIGHT,  CHR_DELETE ), \
12383cbb37nwhitehorn	DLG_KEYS_DATA( DLGK_DELETE_RIGHT,  KEY_DC ), \
12483cbb37nwhitehorn	DLG_KEYS_DATA( DLGK_FINAL,	   KEY_END ), \
12583cbb37nwhitehorn	DLG_KEYS_DATA( DLGK_GRID_LEFT,	   KEY_LEFT ), \
12683cbb37nwhitehorn	DLG_KEYS_DATA( DLGK_GRID_RIGHT,	   KEY_RIGHT )
12783cbb37nwhitehorn
1282b5579cbapt#define SCROLL_FKEY_BINDINGS \
1292b5579cbapt	DLG_KEYS_DATA( DLGK_GRID_DOWN,	KEY_DOWN ), \
1302b5579cbapt	DLG_KEYS_DATA( DLGK_GRID_UP,	KEY_UP ), \
1312b5579cbapt	DLG_KEYS_DATA( DLGK_PAGE_FIRST,	KEY_HOME ), \
1322b5579cbapt	DLG_KEYS_DATA( DLGK_PAGE_LAST,	KEY_END ), \
1332b5579cbapt	DLG_KEYS_DATA( DLGK_PAGE_NEXT,	KEY_NPAGE ), \
1342b5579cbapt	DLG_KEYS_DATA( DLGK_PAGE_PREV,	KEY_PPAGE )
1352b5579cbapt
13683cbb37nwhitehorn#define SCROLLKEY_BINDINGS \
1372b5579cbapt	SCROLL_FKEY_BINDINGS, \
13883cbb37nwhitehorn	DLG_KEYS_DATA( DLGK_GRID_DOWN,	'J' ), \
13983cbb37nwhitehorn	DLG_KEYS_DATA( DLGK_GRID_DOWN,	'j' ), \
14083cbb37nwhitehorn	DLG_KEYS_DATA( DLGK_GRID_UP,	'K' ), \
14183cbb37nwhitehorn	DLG_KEYS_DATA( DLGK_GRID_UP,	'k' ), \
14283cbb37nwhitehorn	DLG_KEYS_DATA( DLGK_PAGE_FIRST,	'g' ), \
14383cbb37nwhitehorn	DLG_KEYS_DATA( DLGK_PAGE_LAST,	'G' ), \
14483cbb37nwhitehorn	DLG_KEYS_DATA( DLGK_PAGE_NEXT,	'F' ), \
14583cbb37nwhitehorn	DLG_KEYS_DATA( DLGK_PAGE_NEXT,	'f' ), \
14683cbb37nwhitehorn	DLG_KEYS_DATA( DLGK_PAGE_PREV,	'B' ), \
1472b5579cbapt	DLG_KEYS_DATA( DLGK_PAGE_PREV,	'b' )
14883cbb37nwhitehorn
149a94245bnwhitehorn#define TRAVERSE_BINDINGS \
150f8604a5bapt	DLG_KEYS_DATA( DLGK_ENTER,	CHR_SPACE ), \
151a94245bnwhitehorn	DLG_KEYS_DATA( DLGK_FIELD_NEXT,	KEY_DOWN ), \
152a94245bnwhitehorn	DLG_KEYS_DATA( DLGK_FIELD_NEXT, KEY_RIGHT ), \
153a94245bnwhitehorn	DLG_KEYS_DATA( DLGK_FIELD_NEXT, TAB ), \
154a94245bnwhitehorn	DLG_KEYS_DATA( DLGK_FIELD_PREV,	KEY_UP ), \
155a94245bnwhitehorn	DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_BTAB ), \
156a94245bnwhitehorn	DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_LEFT )
157a94245bnwhitehorn
158f8604a5bapt#define TOGGLEKEY_BINDINGS \
159f8604a5bapt	DLG_KEYS_DATA( DLGK_TOGGLE,	CHR_SPACE )
160f8604a5bapt
16183cbb37nwhitehornextern int dlg_lookup_key(WINDOW * /*win*/, int /*curses_key*/, int * /*dialog_key*/);
16283cbb37nwhitehornextern int dlg_result_key(int /*dialog_key*/, int /*fkey*/, int * /*resultp*/);
16383cbb37nwhitehornextern void dlg_register_buttons(WINDOW * /*win*/, const char * /*name*/, const char ** /*buttons*/);
16483cbb37nwhitehornextern void dlg_register_window(WINDOW * /*win*/, const char * /*name*/, DLG_KEYS_BINDING * /*binding*/);
16583cbb37nwhitehornextern void dlg_unregister_window(WINDOW * /*win*/);
16683cbb37nwhitehorn
16783cbb37nwhitehorn#ifdef HAVE_RC_FILE
16883cbb37nwhitehornextern int dlg_parse_bindkey(char * /*params*/);
16983cbb37nwhitehornextern void dlg_dump_keys(FILE * /*fp*/);
170a94245bnwhitehornextern void dlg_dump_window_keys(FILE * /*fp*/, WINDOW * /*win*/);
17183cbb37nwhitehorn#endif
17283cbb37nwhitehorn
17383cbb37nwhitehorn#ifdef __cplusplus
17483cbb37nwhitehorn}
17583cbb37nwhitehorn#endif
176a94245bnwhitehorn/* *INDENT-ON* */
17783cbb37nwhitehorn
17883cbb37nwhitehorn#endif /* DLG_KEYS_H_included */
179