10f66f451Sopenharmony_ci/*
20f66f451Sopenharmony_ci *  dialog.h -- common declarations for all dialog modules
30f66f451Sopenharmony_ci *
40f66f451Sopenharmony_ci *  AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
50f66f451Sopenharmony_ci *
60f66f451Sopenharmony_ci *  This program is free software; you can redistribute it and/or
70f66f451Sopenharmony_ci *  modify it under the terms of the GNU General Public License
80f66f451Sopenharmony_ci *  as published by the Free Software Foundation; either version 2
90f66f451Sopenharmony_ci *  of the License, or (at your option) any later version.
100f66f451Sopenharmony_ci *
110f66f451Sopenharmony_ci *  This program is distributed in the hope that it will be useful,
120f66f451Sopenharmony_ci *  but WITHOUT ANY WARRANTY; without even the implied warranty of
130f66f451Sopenharmony_ci *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
140f66f451Sopenharmony_ci *  GNU General Public License for more details.
150f66f451Sopenharmony_ci *
160f66f451Sopenharmony_ci *  You should have received a copy of the GNU General Public License
170f66f451Sopenharmony_ci *  along with this program; if not, write to the Free Software
180f66f451Sopenharmony_ci *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
190f66f451Sopenharmony_ci */
200f66f451Sopenharmony_ci
210f66f451Sopenharmony_ci#include <sys/types.h>
220f66f451Sopenharmony_ci#include <fcntl.h>
230f66f451Sopenharmony_ci#include <unistd.h>
240f66f451Sopenharmony_ci#include <ctype.h>
250f66f451Sopenharmony_ci#include <stdlib.h>
260f66f451Sopenharmony_ci#include <string.h>
270f66f451Sopenharmony_ci#include <stdbool.h>
280f66f451Sopenharmony_ci
290f66f451Sopenharmony_ci#ifdef __sun__
300f66f451Sopenharmony_ci#define CURS_MACROS
310f66f451Sopenharmony_ci#endif
320f66f451Sopenharmony_ci#include CURSES_LOC
330f66f451Sopenharmony_ci
340f66f451Sopenharmony_ci/*
350f66f451Sopenharmony_ci * Colors in ncurses 1.9.9e do not work properly since foreground and
360f66f451Sopenharmony_ci * background colors are OR'd rather than separately masked.  This version
370f66f451Sopenharmony_ci * of dialog was hacked to work with ncurses 1.9.9e, making it incompatible
380f66f451Sopenharmony_ci * with standard curses.  The simplest fix (to make this work with standard
390f66f451Sopenharmony_ci * curses) uses the wbkgdset() function, not used in the original hack.
400f66f451Sopenharmony_ci * Turn it off if we're building with 1.9.9e, since it just confuses things.
410f66f451Sopenharmony_ci */
420f66f451Sopenharmony_ci#if defined(NCURSES_VERSION) && defined(_NEED_WRAP) && !defined(GCC_PRINTFLIKE)
430f66f451Sopenharmony_ci#define OLD_NCURSES 1
440f66f451Sopenharmony_ci#undef  wbkgdset
450f66f451Sopenharmony_ci#define wbkgdset(w,p)		/*nothing */
460f66f451Sopenharmony_ci#else
470f66f451Sopenharmony_ci#define OLD_NCURSES 0
480f66f451Sopenharmony_ci#endif
490f66f451Sopenharmony_ci
500f66f451Sopenharmony_ci#define TR(params) _tracef params
510f66f451Sopenharmony_ci
520f66f451Sopenharmony_ci#define KEY_ESC 27
530f66f451Sopenharmony_ci#define TAB 9
540f66f451Sopenharmony_ci#define MAX_LEN 2048
550f66f451Sopenharmony_ci#define BUF_SIZE (10*1024)
560f66f451Sopenharmony_ci#define MIN(x,y) (x < y ? x : y)
570f66f451Sopenharmony_ci#define MAX(x,y) (x > y ? x : y)
580f66f451Sopenharmony_ci
590f66f451Sopenharmony_ci#ifndef ACS_ULCORNER
600f66f451Sopenharmony_ci#define ACS_ULCORNER '+'
610f66f451Sopenharmony_ci#endif
620f66f451Sopenharmony_ci#ifndef ACS_LLCORNER
630f66f451Sopenharmony_ci#define ACS_LLCORNER '+'
640f66f451Sopenharmony_ci#endif
650f66f451Sopenharmony_ci#ifndef ACS_URCORNER
660f66f451Sopenharmony_ci#define ACS_URCORNER '+'
670f66f451Sopenharmony_ci#endif
680f66f451Sopenharmony_ci#ifndef ACS_LRCORNER
690f66f451Sopenharmony_ci#define ACS_LRCORNER '+'
700f66f451Sopenharmony_ci#endif
710f66f451Sopenharmony_ci#ifndef ACS_HLINE
720f66f451Sopenharmony_ci#define ACS_HLINE '-'
730f66f451Sopenharmony_ci#endif
740f66f451Sopenharmony_ci#ifndef ACS_VLINE
750f66f451Sopenharmony_ci#define ACS_VLINE '|'
760f66f451Sopenharmony_ci#endif
770f66f451Sopenharmony_ci#ifndef ACS_LTEE
780f66f451Sopenharmony_ci#define ACS_LTEE '+'
790f66f451Sopenharmony_ci#endif
800f66f451Sopenharmony_ci#ifndef ACS_RTEE
810f66f451Sopenharmony_ci#define ACS_RTEE '+'
820f66f451Sopenharmony_ci#endif
830f66f451Sopenharmony_ci#ifndef ACS_UARROW
840f66f451Sopenharmony_ci#define ACS_UARROW '^'
850f66f451Sopenharmony_ci#endif
860f66f451Sopenharmony_ci#ifndef ACS_DARROW
870f66f451Sopenharmony_ci#define ACS_DARROW 'v'
880f66f451Sopenharmony_ci#endif
890f66f451Sopenharmony_ci
900f66f451Sopenharmony_ci/* error return codes */
910f66f451Sopenharmony_ci#define ERRDISPLAYTOOSMALL (KEY_MAX + 1)
920f66f451Sopenharmony_ci
930f66f451Sopenharmony_ci/*
940f66f451Sopenharmony_ci *   Color definitions
950f66f451Sopenharmony_ci */
960f66f451Sopenharmony_cistruct dialog_color {
970f66f451Sopenharmony_ci	chtype atr;	/* Color attribute */
980f66f451Sopenharmony_ci	int fg;		/* foreground */
990f66f451Sopenharmony_ci	int bg;		/* background */
1000f66f451Sopenharmony_ci	int hl;		/* highlight this item */
1010f66f451Sopenharmony_ci};
1020f66f451Sopenharmony_ci
1030f66f451Sopenharmony_cistruct dialog_info {
1040f66f451Sopenharmony_ci	const char *backtitle;
1050f66f451Sopenharmony_ci	struct dialog_color screen;
1060f66f451Sopenharmony_ci	struct dialog_color shadow;
1070f66f451Sopenharmony_ci	struct dialog_color dialog;
1080f66f451Sopenharmony_ci	struct dialog_color title;
1090f66f451Sopenharmony_ci	struct dialog_color border;
1100f66f451Sopenharmony_ci	struct dialog_color button_active;
1110f66f451Sopenharmony_ci	struct dialog_color button_inactive;
1120f66f451Sopenharmony_ci	struct dialog_color button_key_active;
1130f66f451Sopenharmony_ci	struct dialog_color button_key_inactive;
1140f66f451Sopenharmony_ci	struct dialog_color button_label_active;
1150f66f451Sopenharmony_ci	struct dialog_color button_label_inactive;
1160f66f451Sopenharmony_ci	struct dialog_color inputbox;
1170f66f451Sopenharmony_ci	struct dialog_color inputbox_border;
1180f66f451Sopenharmony_ci	struct dialog_color searchbox;
1190f66f451Sopenharmony_ci	struct dialog_color searchbox_title;
1200f66f451Sopenharmony_ci	struct dialog_color searchbox_border;
1210f66f451Sopenharmony_ci	struct dialog_color position_indicator;
1220f66f451Sopenharmony_ci	struct dialog_color menubox;
1230f66f451Sopenharmony_ci	struct dialog_color menubox_border;
1240f66f451Sopenharmony_ci	struct dialog_color item;
1250f66f451Sopenharmony_ci	struct dialog_color item_selected;
1260f66f451Sopenharmony_ci	struct dialog_color tag;
1270f66f451Sopenharmony_ci	struct dialog_color tag_selected;
1280f66f451Sopenharmony_ci	struct dialog_color tag_key;
1290f66f451Sopenharmony_ci	struct dialog_color tag_key_selected;
1300f66f451Sopenharmony_ci	struct dialog_color check;
1310f66f451Sopenharmony_ci	struct dialog_color check_selected;
1320f66f451Sopenharmony_ci	struct dialog_color uarrow;
1330f66f451Sopenharmony_ci	struct dialog_color darrow;
1340f66f451Sopenharmony_ci};
1350f66f451Sopenharmony_ci
1360f66f451Sopenharmony_ci/*
1370f66f451Sopenharmony_ci * Global variables
1380f66f451Sopenharmony_ci */
1390f66f451Sopenharmony_ciextern struct dialog_info dlg;
1400f66f451Sopenharmony_ciextern char dialog_input_result[];
1410f66f451Sopenharmony_ci
1420f66f451Sopenharmony_ci/*
1430f66f451Sopenharmony_ci * Function prototypes
1440f66f451Sopenharmony_ci */
1450f66f451Sopenharmony_ci
1460f66f451Sopenharmony_ci/* item list as used by checklist and menubox */
1470f66f451Sopenharmony_civoid item_reset(void);
1480f66f451Sopenharmony_civoid item_make(const char *fmt, ...);
1490f66f451Sopenharmony_civoid item_add_str(const char *fmt, ...);
1500f66f451Sopenharmony_civoid item_set_tag(char tag);
1510f66f451Sopenharmony_civoid item_set_data(void *p);
1520f66f451Sopenharmony_civoid item_set_selected(int val);
1530f66f451Sopenharmony_ciint item_activate_selected(void);
1540f66f451Sopenharmony_civoid *item_data(void);
1550f66f451Sopenharmony_cichar item_tag(void);
1560f66f451Sopenharmony_ci
1570f66f451Sopenharmony_ci/* item list manipulation for lxdialog use */
1580f66f451Sopenharmony_ci#define MAXITEMSTR 200
1590f66f451Sopenharmony_cistruct dialog_item {
1600f66f451Sopenharmony_ci	char str[MAXITEMSTR];	/* promtp displayed */
1610f66f451Sopenharmony_ci	char tag;
1620f66f451Sopenharmony_ci	void *data;	/* pointer to menu item - used by menubox+checklist */
1630f66f451Sopenharmony_ci	int selected;	/* Set to 1 by dialog_*() function if selected. */
1640f66f451Sopenharmony_ci};
1650f66f451Sopenharmony_ci
1660f66f451Sopenharmony_ci/* list of lialog_items */
1670f66f451Sopenharmony_cistruct dialog_list {
1680f66f451Sopenharmony_ci	struct dialog_item node;
1690f66f451Sopenharmony_ci	struct dialog_list *next;
1700f66f451Sopenharmony_ci};
1710f66f451Sopenharmony_ci
1720f66f451Sopenharmony_ciextern struct dialog_list *item_cur;
1730f66f451Sopenharmony_ciextern struct dialog_list item_nil;
1740f66f451Sopenharmony_ciextern struct dialog_list *item_head;
1750f66f451Sopenharmony_ci
1760f66f451Sopenharmony_ciint item_count(void);
1770f66f451Sopenharmony_civoid item_set(int n);
1780f66f451Sopenharmony_ciint item_n(void);
1790f66f451Sopenharmony_ciconst char *item_str(void);
1800f66f451Sopenharmony_ciint item_is_selected(void);
1810f66f451Sopenharmony_ciint item_is_tag(char tag);
1820f66f451Sopenharmony_ci#define item_foreach() \
1830f66f451Sopenharmony_ci	for (item_cur = item_head ? item_head: item_cur; \
1840f66f451Sopenharmony_ci	     item_cur && (item_cur != &item_nil); item_cur = item_cur->next)
1850f66f451Sopenharmony_ci
1860f66f451Sopenharmony_ci/* generic key handlers */
1870f66f451Sopenharmony_ciint on_key_esc(WINDOW *win);
1880f66f451Sopenharmony_ciint on_key_resize(void);
1890f66f451Sopenharmony_ci
1900f66f451Sopenharmony_civoid init_dialog(const char *backtitle);
1910f66f451Sopenharmony_civoid reset_dialog(void);
1920f66f451Sopenharmony_civoid end_dialog(void);
1930f66f451Sopenharmony_civoid attr_clear(WINDOW * win, int height, int width, chtype attr);
1940f66f451Sopenharmony_civoid dialog_clear(void);
1950f66f451Sopenharmony_civoid print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x);
1960f66f451Sopenharmony_civoid print_button(WINDOW * win, const char *label, int y, int x, int selected);
1970f66f451Sopenharmony_civoid print_title(WINDOW *dialog, const char *title, int width);
1980f66f451Sopenharmony_civoid draw_box(WINDOW * win, int y, int x, int height, int width, chtype box,
1990f66f451Sopenharmony_ci	      chtype border);
2000f66f451Sopenharmony_civoid draw_shadow(WINDOW * win, int y, int x, int height, int width);
2010f66f451Sopenharmony_ci
2020f66f451Sopenharmony_ciint first_alpha(const char *string, const char *exempt);
2030f66f451Sopenharmony_ciint dialog_yesno(const char *title, const char *prompt, int height, int width);
2040f66f451Sopenharmony_ciint dialog_msgbox(const char *title, const char *prompt, int height,
2050f66f451Sopenharmony_ci		  int width, int pause);
2060f66f451Sopenharmony_ciint dialog_textbox(const char *title, const char *file, int height, int width);
2070f66f451Sopenharmony_ciint dialog_menu(const char *title, const char *prompt,
2080f66f451Sopenharmony_ci		const void *selected, int *s_scroll);
2090f66f451Sopenharmony_ciint dialog_checklist(const char *title, const char *prompt, int height,
2100f66f451Sopenharmony_ci		     int width, int list_height);
2110f66f451Sopenharmony_ciextern char dialog_input_result[];
2120f66f451Sopenharmony_ciint dialog_inputbox(const char *title, const char *prompt, int height,
2130f66f451Sopenharmony_ci		    int width, const char *init);
2140f66f451Sopenharmony_ci
2150f66f451Sopenharmony_ci/*
2160f66f451Sopenharmony_ci * This is the base for fictitious keys, which activate
2170f66f451Sopenharmony_ci * the buttons.
2180f66f451Sopenharmony_ci *
2190f66f451Sopenharmony_ci * Mouse-generated keys are the following:
2200f66f451Sopenharmony_ci *   -- the first 32 are used as numbers, in addition to '0'-'9'
2210f66f451Sopenharmony_ci *   -- the lowercase are used to signal mouse-enter events (M_EVENT + 'o')
2220f66f451Sopenharmony_ci *   -- uppercase chars are used to invoke the button (M_EVENT + 'O')
2230f66f451Sopenharmony_ci */
2240f66f451Sopenharmony_ci#define M_EVENT (KEY_MAX+1)
225