dialog.h revision 220749
180708Sjake/*
280708Sjake *  $Id: dialog.h,v 1.223 2011/03/02 10:04:09 tom Exp $
3223126Smarius *
480708Sjake *  dialog.h -- common declarations for all dialog modules
580708Sjake *
680708Sjake *  Copyright 2000-2010,2011	Thomas E. Dickey
780708Sjake *
880708Sjake *  This program is free software; you can redistribute it and/or modify
980708Sjake *  it under the terms of the GNU Lesser General Public License, version 2.1
1080708Sjake *  as published by the Free Software Foundation.
1180708Sjake *
1280708Sjake *  This program is distributed in the hope that it will be useful, but
1380708Sjake *  WITHOUT ANY WARRANTY; without even the implied warranty of
1480708Sjake *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1581334Sobrien *  Lesser General Public License for more details.
1680708Sjake *
1780708Sjake *  You should have received a copy of the GNU Lesser General Public
1881334Sobrien *  License along with this program; if not, write to
1980708Sjake *	Free Software Foundation, Inc.
2080708Sjake *	51 Franklin St., Fifth Floor
2180708Sjake *	Boston, MA 02110, USA.
2280708Sjake *
2380708Sjake *  An earlier version of this program lists as authors
2480708Sjake *	Savio Lam (lam836@cs.cuhk.hk)
2580708Sjake */
2680708Sjake
2780708Sjake#ifndef DIALOG_H_included
2880708Sjake#define DIALOG_H_included 1
2980708Sjake/* *INDENT-OFF* */
3080708Sjake
3180708Sjake#include <dlg_config.h>
3280708Sjake
33183142Smarius#ifdef __hpux
34183142Smarius#define __HP_CURSES_COMPAT	/* workaround for getattrs, etc. */
35182730Smarius#endif
36182730Smarius
37182730Smarius#include <sys/types.h>
38182730Smarius#include <fcntl.h>
3989051Sjake#include <unistd.h>
4089051Sjake#include <ctype.h>
4189051Sjake#include <stdlib.h>
42222813Sattilio#include <stdarg.h>
43209695Smarius#include <string.h>
44209695Smarius#include <signal.h>	/* fork() etc. */
45245850Smarius#include <math.h>	/* sqrt() */
46209695Smarius
4791157Sjake#undef ERR		/* header conflict with Solaris xpg4 */
48169730Skan
4991617Sjake#if defined(HAVE_NCURSESW_NCURSES_H)
5091157Sjake#include <ncursesw/ncurses.h>
51170846Smarius#elif defined(HAVE_NCURSES_NCURSES_H)
52170846Smarius#include <ncurses/ncurses.h>
53170846Smarius#elif defined(HAVE_NCURSES_CURSES_H)
54170846Smarius#include <ncurses/curses.h>
55170846Smarius#elif defined(HAVE_NCURSES_H)
56170846Smarius#include <ncurses.h>
5789051Sjake#else
58169796Smarius#include <curses.h>
59170846Smarius#endif
60169796Smarius
6189051Sjake/* most curses.h headers include this, some do not */
6289051Sjake#if defined(HAVE_UNCTRL_H)
63178048Smarius#include <unctrl.h>
64210601Smav#endif
6589051Sjake
66196196Sattilio/* Solaris xpg4 renames these */
6789051Sjake#ifndef KEY_MAX
68135943Skensmith#ifdef __KEY_MAX
6989051Sjake#define KEY_MAX __KEY_MAX
7089051Sjake#endif
7191783Sjake#endif
7289051Sjake
7389051Sjake#ifndef KEY_MIN
7491783Sjake#ifdef __KEY_MIN
7591617Sjake#define KEY_MIN __KEY_MIN
76182730Smarius#endif
7791617Sjake#endif
7891617Sjake
7989051Sjake/* possible conflicts with <term.h> which may be included in <curses.h> */
8089051Sjake#ifdef color_names
8197001Sjake#undef color_names
82222813Sattilio#endif
83113238Sjake
8497001Sjake#ifdef buttons
8597001Sjake#undef buttons
86211071Smarius#endif
87222813Sattilio
88211071Smarius#ifdef ENABLE_NLS
89211071Smarius#include <libintl.h>
90211071Smarius#include <langinfo.h>
9189051Sjake#define _(s) dgettext(PACKAGE, s)
92222813Sattilio#else
9391783Sjake#undef _
9489051Sjake#define _(s) s
9589051Sjake#endif
9689051Sjake
9789051Sjake#ifndef GCC_NORETURN
9889051Sjake#define GCC_NORETURN /*nothing*/
9989051Sjake#endif
10089051Sjake
101152022Sjhb#ifndef GCC_UNUSED
102152022Sjhb#define GCC_UNUSED /*nothing*/
10389051Sjake#endif
10492199Sjake
10589051Sjake#ifndef HAVE_WGET_WCH
106222813Sattilio#undef USE_WIDE_CURSES
107170846Smarius#endif
108211050Smarius
109211050Smarius/*
11089051Sjake * FIXME: a configure check would be useful
111204152Smarius */
11291617Sjake#ifdef __hpux
113108187Sjake#undef ACS_UARROW
114211071Smarius#undef ACS_DARROW
115108187Sjake#undef ACS_BLOCK
11689051Sjake#endif
11791617Sjake
11891617Sjake/*
11991617Sjake * Change these if you want
12091617Sjake */
12191617Sjake#define USE_SHADOW TRUE
12291617Sjake#define USE_COLORS TRUE
12391617Sjake
124112399Sjake#ifdef HAVE_COLOR
125112399Sjake#define SCOLS	(COLS - (dialog_state.use_shadow ? 2 : 0))
126112399Sjake#define SLINES	(LINES - (dialog_state.use_shadow ? 1 : 0))
127112399Sjake#else
12889051Sjake#define SCOLS	COLS
129211071Smarius#define SLINES	LINES
130211071Smarius#endif
131211071Smarius
132211071Smarius#define DLG_EXIT_ESC		255
13389051Sjake#define DLG_EXIT_UNKNOWN	-2	/* never return this (internal use) */
13489051Sjake#define DLG_EXIT_ERROR		-1	/* the shell sees this as 255 */
13589051Sjake#define DLG_EXIT_OK		0
13689051Sjake#define DLG_EXIT_CANCEL		1
137183142Smarius#define DLG_EXIT_HELP		2
138183142Smarius#define DLG_EXIT_EXTRA		3
139183142Smarius#define DLG_EXIT_ITEM_HELP	4	/* actually DLG_EXIT_HELP */
140223126Smarius
14189051Sjake#define DLG_CTRL(n)	((n) & 0x1f)	/* CTRL is preferred, but conflicts */
142223126Smarius
143223126Smarius#define CHR_BACKSPACE	DLG_CTRL('H')
144223126Smarius#define CHR_REPAINT	DLG_CTRL('L')
145183142Smarius#define CHR_KILL	DLG_CTRL('U')
146183142Smarius#define CHR_LITERAL	DLG_CTRL('V')
147183142Smarius#define CHR_DELETE	127
148222813Sattilio#define CHR_NEXT	DLG_CTRL('N')
149183142Smarius#define CHR_PREVIOUS	DLG_CTRL('P')
150183142Smarius#define CHR_TRACE	DLG_CTRL('T')
151183142Smarius
152183142Smarius#define ESC		27
153183142Smarius#define TAB		DLG_CTRL('I')
154210939Sjhb
155210939Sjhb#define MARGIN 1
156210939Sjhb#define GUTTER 2
157210939Sjhb#define SHADOW_ROWS 1
158211050Smarius#define SHADOW_COLS 2
159210939Sjhb#define ARROWS_COL  5
160210939Sjhb
161108187Sjake#define MAX_LEN 2048
162108187Sjake#define BUF_SIZE (10L*1024)
16397001Sjake
164113238Sjake#undef  MIN
16597001Sjake#define MIN(x,y) ((x) < (y) ? (x) : (y))
16697001Sjake
16797001Sjake#undef  MAX
16897001Sjake#define MAX(x,y) ((x) > (y) ? (x) : (y))
16997001Sjake
170209695Smarius#define DEFAULT_SEPARATE_STR "\t"
17197001Sjake#define DEFAULT_ASPECT_RATIO 9
172239864Smarius/* how many spaces is a tab long (default)? */
17397001Sjake#define TAB_LEN 8
174223126Smarius#define WTIMEOUT_VAL        10	/* minimum amount of time needed for curses */
17597001Sjake
176223126Smarius#ifndef A_CHARTEXT
17797001Sjake#define A_CHARTEXT 0xff
17897001Sjake#endif
17997001Sjake
18097001Sjake#define CharOf(ch)  ((ch) & 0xff)
181113238Sjake
18297001Sjake#ifndef ACS_ULCORNER
18397001Sjake#define ACS_ULCORNER '+'
18497001Sjake#endif
18597001Sjake#ifndef ACS_LLCORNER
18697001Sjake#define ACS_LLCORNER '+'
187209695Smarius#endif
18897001Sjake#ifndef ACS_URCORNER
189239864Smarius#define ACS_URCORNER '+'
19097001Sjake#endif
191223126Smarius#ifndef ACS_LRCORNER
19297001Sjake#define ACS_LRCORNER '+'
193223126Smarius#endif
19497001Sjake#ifndef ACS_HLINE
19597001Sjake#define ACS_HLINE '-'
19697001Sjake#endif
19789051Sjake#ifndef ACS_VLINE
198211071Smarius#define ACS_VLINE '|'
199211071Smarius#endif
200211071Smarius#ifndef ACS_LTEE
201211071Smarius#define ACS_LTEE '+'
202211071Smarius#endif
203211071Smarius#ifndef ACS_RTEE
204211071Smarius#define ACS_RTEE '+'
205211071Smarius#endif
206245850Smarius#ifndef ACS_UARROW
207223126Smarius#define ACS_UARROW '^'
208211071Smarius#endif
209211071Smarius#ifndef ACS_DARROW
210211071Smarius#define ACS_DARROW 'v'
211211071Smarius#endif
212211071Smarius#ifndef ACS_BLOCK
213211071Smarius#define ACS_BLOCK '#'
21491783Sjake#endif
21589051Sjake
21689051Sjake/* these definitions may work for antique versions of curses */
217222813Sattilio#ifndef HAVE_GETBEGYX
21889051Sjake#undef  getbegyx
21991783Sjake#define getbegyx(win,y,x)	(y = (win)?(win)->_begy:ERR, x = (win)?(win)->_begx:ERR)
22089051Sjake#endif
221209695Smarius
222222813Sattilio#ifndef HAVE_GETMAXYX
223223126Smarius#undef  getmaxyx
224223126Smarius#define getmaxyx(win,y,x)	(y = (win)?(win)->_maxy:ERR, x = (win)?(win)->_maxx:ERR)
225222813Sattilio#endif
226209695Smarius
22791783Sjake#ifndef HAVE_GETPARYX
228209695Smarius#undef  getparyx
22989051Sjake#define getparyx(win,y,x)	(y = (win)?(win)->_pary:ERR, x = (win)?(win)->_parx:ERR)
230239864Smarius#endif
231222813Sattilio
23291783Sjake#ifdef __cplusplus
23391783Sjakeextern "C" {
23491783Sjake#endif
23592199Sjake
23689051Sjake/* these definitions may be needed for bleeding-edge curses implementations */
23789051Sjake#if !(defined(HAVE_GETBEGX) && defined(HAVE_GETBEGY))
23889051Sjake#undef getbegx
239100718Sjake#undef getbegy
24089051Sjake#define getbegx(win) dlg_getbegx(win)
24189051Sjake#define getbegy(win) dlg_getbegy(win)
242222813Sattilioextern int dlg_getbegx(WINDOW * /*win*/);
24389051Sjakeextern int dlg_getbegy(WINDOW * /*win*/);
24491783Sjake#endif
24589051Sjake
246209695Smarius#if !(defined(HAVE_GETCURX) && defined(HAVE_GETCURY))
247222813Sattilio#undef getcurx
248223126Smarius#undef getcury
249223126Smarius#define getcurx(win) dlg_getcurx(win)
250222813Sattilio#define getcury(win) dlg_getcury(win)
251209695Smariusextern int dlg_getcurx(WINDOW * /*win*/);
25291783Sjakeextern int dlg_getcury(WINDOW * /*win*/);
253209695Smarius#endif
25489051Sjake
255239864Smarius#if !(defined(HAVE_GETMAXX) && defined(HAVE_GETMAXY))
256222813Sattilio#undef getmaxx
25791783Sjake#undef getmaxy
25889051Sjake#define getmaxx(win) dlg_getmaxx(win)
25991783Sjake#define getmaxy(win) dlg_getmaxy(win)
26092199Sjakeextern int dlg_getmaxx(WINDOW * /*win*/);
26189051Sjakeextern int dlg_getmaxy(WINDOW * /*win*/);
26289051Sjake#endif
26389051Sjake
26491783Sjake#if !(defined(HAVE_GETPARX) && defined(HAVE_GETPARY))
26589051Sjake#undef getparx
26689051Sjake#undef getpary
267222813Sattilio#define getparx(win) dlg_getparx(win)
26889051Sjake#define getpary(win) dlg_getpary(win)
26991783Sjakeextern int dlg_getparx(WINDOW * /*win*/);
27089051Sjakeextern int dlg_getpary(WINDOW * /*win*/);
271209695Smarius#endif
272222813Sattilio
273223126Smarius/*
274223126Smarius * This is a list of "old" names, which should be helpful in updating
275222813Sattilio * applications that use libdialog.  Starting with 2003/11/26, all exported
276209695Smarius * symbols from libdialog have "dlg_" prefix, or "dialog_" prefix or "_dialog"
27791783Sjake * suffix (or suffix "_dialog", e.g., init_dialog).
278209695Smarius */
27989051Sjake#ifdef __DIALOG_OLD_NAMES__
280239864Smarius#define color_table                       dlg_color_table
281222813Sattilio#define attr_clear(win,h,w,a)             dlg_attr_clear(win,h,w,a)
28291783Sjake#define auto_size(t,s,h,w,xl,mc)          dlg_auto_size(t,s,h,w,xl,mc)
28389051Sjake#define auto_sizefile(t,f,h,w,xl,mc)      dlg_auto_sizefile(t,f,h,w,xl,mc)
28489051Sjake#define beeping()                         dlg_beeping()
285211050Smarius#define box_x_ordinate(w)                 dlg_box_x_ordinate(w)
286211050Smarius#define box_y_ordinate(h)                 dlg_box_y_ordinate(h)
28792199Sjake#define calc_listh(h,lh,in)               dlg_calc_listh(h,lh,in)
28889051Sjake#define calc_listw(in,items,group)        dlg_calc_listw(in,items,group)
28989051Sjake#define color_setup()                     dlg_color_setup()
29089051Sjake#define create_rc(f)                      dlg_create_rc(f)
29189051Sjake#define ctl_size(h,w)                     dlg_ctl_size(h,w)
29289051Sjake#define del_window(win)                   dlg_del_window(win)
293222813Sattilio#define dialog_clear()                    dlg_clear()
29489051Sjake#define draw_bottom_box(win)              dlg_draw_bottom_box(win)
29592199Sjake#define draw_box(win,y,x,h,w,xc,bc)       dlg_draw_box(win,y,x,h,w,xc,bc)
296222813Sattilio#define draw_shadow(win,h,w,y,x)          dlg_draw_shadow(win,h,w,y,x)
29791617Sjake#define draw_title(win,t)                 dlg_draw_title(win,t)
298239864Smarius#define exiterr                           dlg_exiterr
299209695Smarius#define killall_bg(n)                     dlg_killall_bg(n)
30089051Sjake#define mouse_bigregion(y,x)              dlg_mouse_bigregion(y,x)
30189051Sjake#define mouse_free_regions()              dlg_mouse_free_regions()
30289051Sjake#define mouse_mkbigregion(y,x,h,w,n,ix,iy,m) dlg_mouse_mkbigregion(y,x,h,w,n,ix,iy,m)
303108187Sjake#define mouse_mkregion(y,x,h,w,n)         dlg_mouse_mkregion(y,x,h,w,n)
30491783Sjake#define mouse_region(y,x)                 dlg_mouse_region(y,x)
305183142Smarius#define mouse_setbase(x,y)                dlg_mouse_setbase(x,y)
306183142Smarius#define mouse_wgetch(w,c)                 dlg_mouse_wgetch(w,c)
30789051Sjake#define new_window(h,w,y,x)               dlg_new_window(h,w,y,x)
30889051Sjake#define parse_rc()                        dlg_parse_rc()
309183142Smarius#define print_autowrap(win,s,h,w)         dlg_print_autowrap(win,s,h,w)
310183142Smarius#define print_size(h,w)                   dlg_print_size(h,w)
31189051Sjake#define put_backtitle()                   dlg_put_backtitle()
312209695Smarius#define strclone(cprompt)                 dlg_strclone(cprompt)
31397001Sjake#define sub_window(win,h,w,y,x)           dlg_sub_window(win,h,w,y,x)
314169796Smarius#define tab_correct_str(s)                dlg_tab_correct_str(s)
31597001Sjake#endif
31697001Sjake
31797001Sjake/*
31897001Sjake * Attribute names
319209695Smarius */
32097001Sjake#define DIALOG_ATR(n)                 dlg_color_table[n].atr
321169796Smarius
32297001Sjake#define screen_attr                   DIALOG_ATR(0)
32397001Sjake#define shadow_attr                   DIALOG_ATR(1)
32497001Sjake#define dialog_attr                   DIALOG_ATR(2)
32597001Sjake#define title_attr                    DIALOG_ATR(3)
326211071Smarius#define border_attr                   DIALOG_ATR(4)
327211071Smarius#define button_active_attr            DIALOG_ATR(5)
328211071Smarius#define button_inactive_attr          DIALOG_ATR(6)
329211071Smarius#define button_key_active_attr        DIALOG_ATR(7)
330211071Smarius#define button_key_inactive_attr      DIALOG_ATR(8)
331211071Smarius#define button_label_active_attr      DIALOG_ATR(9)
332211071Smarius#define button_label_inactive_attr    DIALOG_ATR(10)
333209695Smarius#define inputbox_attr                 DIALOG_ATR(11)
33489051Sjake#define inputbox_border_attr          DIALOG_ATR(12)
335169796Smarius#define searchbox_attr                DIALOG_ATR(13)
33689051Sjake#define searchbox_title_attr          DIALOG_ATR(14)
33789051Sjake#define searchbox_border_attr         DIALOG_ATR(15)
33889051Sjake#define position_indicator_attr       DIALOG_ATR(16)
33989051Sjake#define menubox_attr                  DIALOG_ATR(17)
340209695Smarius#define menubox_border_attr           DIALOG_ATR(18)
34189051Sjake#define item_attr                     DIALOG_ATR(19)
342169796Smarius#define item_selected_attr            DIALOG_ATR(20)
34389051Sjake#define tag_attr                      DIALOG_ATR(21)
34489051Sjake#define tag_selected_attr             DIALOG_ATR(22)
34589051Sjake#define tag_key_attr                  DIALOG_ATR(23)
34689051Sjake#define tag_key_selected_attr         DIALOG_ATR(24)
347209695Smarius#define check_attr                    DIALOG_ATR(25)
348209695Smarius#define check_selected_attr           DIALOG_ATR(26)
34989051Sjake#define uarrow_attr                   DIALOG_ATR(27)
350169796Smarius#define darrow_attr                   DIALOG_ATR(28)
35189051Sjake#define itemhelp_attr                 DIALOG_ATR(29)
35289051Sjake#define form_active_text_attr         DIALOG_ATR(30)
35389051Sjake#define form_text_attr                DIALOG_ATR(31)
35489051Sjake#define form_item_readonly_attr       DIALOG_ATR(32)
355239864Smarius#define gauge_attr                    DIALOG_ATR(33)
35689051Sjake
357169796Smarius#define DLGK_max (KEY_MAX + 256)
35889051Sjake
35989051Sjake/*
360183142Smarius * Callbacks are used to implement the "background" tailbox.
361183142Smarius */
362183142Smariusstruct _dlg_callback;
36389051Sjake
364183142Smariustypedef void (*DIALOG_FREEBACK) (struct _dlg_callback * /* p */);
365183142Smarius
366183142Smariustypedef struct _dlg_callback {
367183142Smarius    struct _dlg_callback *next;
368183142Smarius    FILE *input;
369183142Smarius    WINDOW *win;
370183142Smarius    bool keep_bg;	/* keep in background, on exit */
371183142Smarius    bool bg_task;	/* true if this is background task */
372183142Smarius    bool (*handle_getc)(struct _dlg_callback *p, int ch, int fkey, int *result);
373183142Smarius    bool keep_win;	/* true to not erase window on exit */
374183142Smarius    /* data for dlg_add_callback_ref */
375183142Smarius    struct _dlg_callback **caller;
376183142Smarius    DIALOG_FREEBACK freeback;
377183142Smarius    /* 1.1-20110107 */
37889051Sjake    bool (*handle_input)(struct _dlg_callback *p);
37989051Sjake    bool input_ready;
380183142Smarius} DIALOG_CALLBACK;
381183142Smarius
38280708Sjaketypedef struct _dlg_windows {
383    struct _dlg_windows *next;
384    WINDOW *normal;
385    WINDOW *shadow;
386} DIALOG_WINDOWS;
387
388/*
389 * Global variables, which are initialized as needed
390 */
391typedef struct {
392    DIALOG_CALLBACK *getc_callbacks;
393    DIALOG_CALLBACK *getc_redirect;
394    DIALOG_WINDOWS *all_windows;
395    FILE *output;		/* option "--output-fd fd" */
396    FILE *pipe_input;		/* used for gauge widget */
397    FILE *screen_output;	/* newterm(), etc. */
398    bool screen_initialized;
399    bool use_colors;		/* use colors by default? */
400    bool use_scrollbar;		/* option "--scrollbar" */
401    bool use_shadow;		/* shadow dialog boxes by default? */
402    bool visit_items;		/* option "--visit-items" */
403    char *separate_str;		/* option "--separate-widget string" */
404    int aspect_ratio;		/* option "--aspect ratio" */
405    int output_count;		/* # of widgets that may have done output */
406    int tab_len;		/* option "--tab-len n" */
407    /* 1.0-20070227 */
408    FILE *input;		/* option "--input-fd fd" */
409#ifdef HAVE_DLG_TRACE
410    FILE *trace_output;		/* option "--trace file" */
411#endif
412    /* 1.1-20110106 */
413    bool no_mouse;		/* option "--no-mouse" */
414} DIALOG_STATE;
415
416extern DIALOG_STATE dialog_state;
417
418/*
419 * Global variables, which dialog resets before each widget
420 */
421typedef struct {
422    bool beep_after_signal;	/* option "--beep-after" */
423    bool beep_signal;		/* option "--beep" */
424    bool begin_set;		/* option "--begin y x" was used */
425    bool cant_kill;		/* option "--no-kill" */
426    bool colors;		/* option "--colors" */
427    bool cr_wrap;		/* option "--cr-wrap" */
428    bool defaultno;		/* option "--defaultno" */
429    bool dlg_clear_screen;	/* option "--clear" */
430    bool extra_button;		/* option "--extra-button" */
431    bool help_button;		/* option "--help-button" */
432    bool help_status;		/* option "--help-status" */
433    bool input_menu;		/* menu vs inputmenu widget */
434    bool insecure;		/* option "--insecure" */
435    bool item_help;		/* option "--item-help" */
436    bool keep_window;		/* option "--keep-window" */
437    bool nocancel;		/* option "--no-cancel" */
438    bool nocollapse;		/* option "--no-collapse" */
439    bool print_siz;		/* option "--print-size" */
440    bool separate_output;	/* option "--separate-output" */
441    bool single_quoted;		/* option "--single-quoted" */
442    bool size_err;		/* option "--size-err" */
443    bool tab_correct;		/* option "--tab-correct" */
444    bool trim_whitespace;	/* option "--trim" */
445    char *backtitle;		/* option "--backtitle backtitle" */
446    char *cancel_label;		/* option "--cancel-label string" */
447    char *default_item;		/* option "--default-item string" */
448    char *exit_label;		/* option "--exit-label string" */
449    char *extra_label;		/* option "--extra-label string" */
450    char *help_label;		/* option "--help-label string" */
451    char *input_result;
452    char *no_label;		/* option "--no-label string" */
453    char *ok_label;		/* option "--ok-label string" */
454    char *title;		/* option "--title title" */
455    char *yes_label;		/* option "--yes-label string" */
456    int begin_x;		/* option "--begin y x" (second value) */
457    int begin_y;		/* option "--begin y x" (first value) */
458    int max_input;		/* option "--max-input size" */
459    int scale_factor;		/* RESERVED */
460    int sleep_secs;		/* option "--sleep secs" */
461    int timeout_secs;		/* option "--timeout secs" */
462    unsigned input_length;	/* nonzero if input_result is allocated */
463    /* 1.0-20051207 */
464    unsigned formitem_type;	/* DIALOG_FORMITEM.type in dialog_form() */
465    /* 1.1-20070227 */
466    bool keep_tite;		/* option "--keep-tite" */
467    bool ascii_lines;		/* option "--ascii-lines" */
468    bool no_lines;		/* option "--no-lines" */
469    /* 1.1-20070930 */
470    bool nook;			/* option "--no-ok" */
471    /* 1.1-20080727 */
472    bool quoted;		/* option "--quoted" */
473    char *column_header;	/* RESERVED "--column-header" */
474    char *column_separator;	/* option "--column-separator" */
475    char *output_separator;	/* option "--output-separator" */
476    /* 1.1-20100118 */
477    char *date_format;		/* option "--date-format" */
478    char *time_format;		/* option "--time-format" */
479} DIALOG_VARS;
480
481#define USE_ITEM_HELP(s)        (dialog_vars.item_help && (s) != 0)
482#define CHECKBOX_TAGS           (dialog_vars.item_help ? 4 : 3)
483#define MENUBOX_TAGS            (dialog_vars.item_help ? 3 : 2)
484#define FORMBOX_TAGS            (dialog_vars.item_help ? 9 : 8)
485#define MIXEDFORM_TAGS          (FORMBOX_TAGS + 1)
486#define MIXEDGAUGE_TAGS         2
487
488extern DIALOG_VARS dialog_vars;
489
490#ifndef HAVE_TYPE_CHTYPE
491#define chtype long
492#endif
493
494#define UCH(ch)			((unsigned char)(ch))
495
496#define assert_ptr(ptr,msg) if ((ptr) == 0) dlg_exiterr("cannot allocate memory in " msg)
497
498#define dlg_malloc(t,n)    (t *) malloc((size_t)(n) * sizeof(t))
499#define dlg_calloc(t,n)    (t *) calloc((size_t)(n), sizeof(t))
500#define dlg_realloc(t,n,p) (t *) realloc((p), (n) * sizeof(t))
501
502/*
503 * Table for attribute- and color-values.
504 */
505typedef struct {
506    chtype atr;
507#ifdef HAVE_COLOR
508    int fg;
509    int bg;
510    int hilite;
511#endif
512#ifdef HAVE_RC_FILE
513    const char *name;
514    const char *comment;
515#endif
516} DIALOG_COLORS;
517
518extern DIALOG_COLORS dlg_color_table[];
519
520/*
521 * Function prototypes
522 */
523extern const char *dialog_version(void);
524
525/* widgets, each in separate files */
526extern int dialog_calendar(const char * /*title*/, const char * /*subtitle*/, int /*height*/, int /*width*/, int /*day*/, int /*month*/, int /*year*/);
527extern int dialog_checklist(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*list_height*/, int /*item_no*/, char ** /*items*/, int /*flag*/);
528extern int dialog_dselect(const char * /*title*/, const char * /*path*/, int /*height*/, int /*width*/);
529extern int dialog_editbox(const char * /*title*/, const char * /*file*/, int /*height*/, int /*width*/);
530extern int dialog_form(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*form_height*/, int /*item_no*/, char ** /*items*/);
531extern int dialog_fselect(const char * /*title*/, const char * /*path*/, int /*height*/, int /*width*/);
532extern int dialog_gauge(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*percent*/);
533extern int dialog_inputbox(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, const char * /*init*/, const int /*password*/);
534extern int dialog_menu(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*menu_height*/, int /*item_no*/, char ** /*items*/);
535extern int dialog_mixedform(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*form_height*/, int /*item_no*/, char ** /*items*/);
536extern int dialog_mixedgauge(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*percent*/, int /*item_no*/, char ** /*items*/);
537extern int dialog_msgbox(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*pauseopt*/);
538extern int dialog_pause(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*seconds*/);
539extern int dialog_prgbox(const char * /*title*/, const char * /*cprompt*/, const char * /*command*/, int /*height*/, int /*width*/, int /*pauseopt*/);
540extern int dialog_progressbox(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/);
541extern int dialog_tailbox(const char * /*title*/, const char * /*file*/, int /*height*/, int /*width*/, int /*bg_task*/);
542extern int dialog_textbox(const char * /*title*/, const char * /*file*/, int /*height*/, int /*width*/);
543extern int dialog_timebox(const char * /*title*/, const char * /*subtitle*/, int /*height*/, int /*width*/, int /*hour*/, int /*minute*/, int /*second*/);
544extern int dialog_yesno(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/);
545
546/* some widgets have alternate entrypoints, to allow list manipulation */
547typedef struct {
548    char *name;
549    char *text;
550    char *help;
551    int state;
552} DIALOG_LISTITEM;
553
554typedef struct {
555    unsigned type;		/* the field type (0=input, 1=password) */
556    char *name;			/* the field label */
557    int name_len;		/* ...its length */
558    int name_y;			/* ...its y-ordinate */
559    int name_x;			/* ...its x-ordinate */
560    bool name_free;		/* ...true if .name can be freed */
561    char *text;			/* the field contents */
562    int text_len;		/* ...its length on the screen */
563    int text_y;			/* ...its y-ordinate */
564    int text_x;			/* ...its x-ordinate */
565    int text_flen;		/* ...its length on screen, or 0 if no input allowed */
566    int text_ilen;		/* ...its limit on amount to be entered */
567    bool text_free;		/* ...true if .text can be freed */
568    char *help;			/* help-message, if any */
569    bool help_free;		/* ...true if .help can be freed */
570} DIALOG_FORMITEM;
571
572typedef	int (DIALOG_INPUTMENU) (DIALOG_LISTITEM * /*items*/, int /*current*/, char * /*newtext*/);
573
574extern int dlg_checklist(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*list_height*/, int /*item_no*/, DIALOG_LISTITEM * /*items*/, const char * /*states*/, int /*flag*/, int * /*current_item*/);
575extern int dlg_form(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*form_height*/, int /*item_no*/, DIALOG_FORMITEM * /*items*/, int * /*current_item*/);
576extern int dlg_menu(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*menu_height*/, int /*item_no*/, DIALOG_LISTITEM * /*items*/, int * /*current_item*/, DIALOG_INPUTMENU /*rename_menu*/);
577extern int dlg_progressbox(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*pauseopt*/, FILE * /* fp */);
578
579/* argv.c */
580extern char ** dlg_string_to_argv(char * /* blob */);
581extern int dlg_count_argv(char ** /* argv */);
582extern int dlg_eat_argv(int * /* argcp */, char *** /* argvp */, int /* start */, int /* count */);
583
584/* arrows.c */
585extern void dlg_draw_arrows(WINDOW * /*dialog*/, int /*top_arrow*/, int /*bottom_arrow*/, int /*x*/, int /*top*/, int /*bottom*/);
586extern void dlg_draw_arrows2(WINDOW * /*dialog*/, int /*top_arrow*/, int /*bottom_arrow*/, int /*x*/, int /*top*/, int /*bottom*/, chtype /*attr*/, chtype /*borderattr*/);
587extern void dlg_draw_scrollbar(WINDOW * /*dialog*/, long /* first_data */, long /* this_data */, long /* next_data */, long /* total_data */, int /* left */, int /* right */, int /*top*/, int /*bottom*/, chtype /*attr*/, chtype /*borderattr*/);
588
589/* buttons.c */
590extern const char ** dlg_exit_label(void);
591extern const char ** dlg_ok_label(void);
592extern const char ** dlg_ok_labels(void);
593extern const char ** dlg_yes_labels(void);
594extern int dlg_button_count(const char ** /*labels*/);
595extern int dlg_button_to_char(const char * /*label*/);
596extern int dlg_button_x_step(const char ** /*labels*/, int /*limit*/, int * /*gap*/, int * /*margin*/, int * /*step*/);
597extern int dlg_char_to_button(int /*ch*/, const char ** /*labels*/);
598extern int dlg_exit_buttoncode(int /*button*/);
599extern int dlg_match_char(int /*ch*/, const char * /*string*/);
600extern int dlg_next_button(const char ** /*labels*/, int /*button*/);
601extern int dlg_next_ok_buttonindex(int /*current*/, int /*extra*/);
602extern int dlg_ok_buttoncode(int /*button*/);
603extern int dlg_prev_button(const char ** /*labels*/, int /*button*/);
604extern int dlg_prev_ok_buttonindex(int /*current*/, int /*extra*/);
605extern int dlg_yes_buttoncode(int /*button*/);
606extern void dlg_button_layout(const char ** /*labels*/, int * /*limit*/);
607extern void dlg_button_sizes(const char ** /*labels*/, int /*vertical*/, int * /*longest*/, int * /*length*/);
608extern void dlg_draw_buttons(WINDOW * /*win*/, int /*y*/, int /*x*/, const char ** /*labels*/, int /*selected*/, int /*vertical*/, int /*limit*/);
609
610/* columns.c */
611extern void dlg_align_columns(char ** /* target */, int  /* per_row */, int /* num_rows */);
612extern void dlg_free_columns(char ** /* target */, int  /* per_row */, int /* num_rows */);
613
614/* editbox.c */
615extern int dlg_editbox(const char */*title*/, char ***/*list*/, int */*rows*/, int /*height*/, int /*width*/);
616
617/* formbox.c */
618extern int dlg_default_formitem(DIALOG_FORMITEM * /*items*/);
619extern int dlg_ordinate(const char * /*s*/);
620extern void dlg_free_formitems(DIALOG_FORMITEM * /*items*/);
621
622/* inputstr.c */
623extern bool dlg_edit_string(char * /*string*/, int * /*offset*/, int /*key*/, int /*fkey*/, bool /*force*/);
624extern const int * dlg_index_columns(const char * /*string*/);
625extern const int * dlg_index_wchars(const char * /*string*/);
626extern int dlg_count_columns(const char * /*string*/);
627extern int dlg_count_wchars(const char * /*string*/);
628extern int dlg_edit_offset(char * /*string*/, int /*offset*/, int /*x_last*/);
629extern int dlg_find_index(const int * /*list*/, int  /*limit*/, int /*to_find*/);
630extern int dlg_limit_columns(const char * /*string*/, int /*limit*/, int /*offset*/);
631extern void dlg_show_string(WINDOW * /*win*/, const char * /*string*/, int /*offset*/, chtype /*attr*/, int /*y_base*/, int /*x_base*/, int /*x_last*/, bool /*hidden*/, bool /*force*/);
632
633/* rc.c */
634#ifdef HAVE_RC_FILE
635extern int dlg_parse_rc(void);
636extern void dlg_create_rc(const char * /*filename*/);
637#endif
638
639/* ui_getc.c */
640extern int dlg_getc(WINDOW * /*win*/, int * /*fkey*/);
641extern int dlg_getc_callbacks(int /*ch*/, int /*fkey*/, int * /*result*/);
642extern int dlg_last_getc(void);
643extern void dlg_add_callback(DIALOG_CALLBACK * /*p*/);
644extern void dlg_add_callback_ref(DIALOG_CALLBACK ** /*p*/, DIALOG_FREEBACK /* cleanup */);
645extern void dlg_flush_getc(void);
646extern void dlg_remove_callback(DIALOG_CALLBACK * /*p*/);
647extern void dlg_killall_bg(int *retval);
648
649/* util.c */
650extern WINDOW * dlg_new_modal_window(WINDOW * /*parent*/, int /*height*/, int /*width*/, int /*y*/, int /*x*/);
651extern WINDOW * dlg_new_window(int /*height*/, int /*width*/, int /*y*/, int /*x*/);
652extern WINDOW * dlg_sub_window(WINDOW * /*win*/, int /*height*/, int /*width*/, int /*y*/, int /*x*/);
653extern bool dlg_need_separator(void);
654extern char * dlg_set_result(const char * /*string*/);
655extern char * dlg_strclone(const char * /*cprompt*/);
656extern char * dlg_strempty(void);
657extern chtype dlg_asciibox(chtype /*ch*/);
658extern chtype dlg_boxchar(chtype /*ch*/);
659extern chtype dlg_get_attrs(WINDOW * /*win*/);
660extern const char * dlg_print_line(WINDOW */*win*/, chtype */*attr*/, const char */*prompt*/, int /*lm*/, int /*rm*/, int */*x*/);
661extern int dlg_box_x_ordinate(int /*width*/);
662extern int dlg_box_y_ordinate(int /*height*/);
663extern int dlg_calc_list_width(int /*item_no*/, DIALOG_LISTITEM * /*items*/);
664extern int dlg_calc_listw(int /*item_no*/, char ** /*items*/, int /*group*/);
665extern int dlg_check_scrolled(int /* key */, int /* last */, int /* page */, bool */* show */, int */* offset */);
666extern int dlg_default_item(char ** /*items*/, int /*llen*/);
667extern int dlg_default_listitem(DIALOG_LISTITEM * /*items*/);
668extern int dlg_defaultno_button(void);
669extern int dlg_max_input(int /*max_len*/);
670extern int dlg_print_scrolled(WINDOW * /* win */, const char * /* prompt */, int /* offset */, int /* height */, int /* width */, int /* pauseopt */);
671extern void dlg_add_quoted(char * /*string*/);
672extern void dlg_add_result(const char * /*string*/);
673extern void dlg_add_separator(void);
674extern void dlg_add_string(char * /*string*/);
675extern void dlg_attr_clear(WINDOW * /*win*/, int /*height*/, int /*width*/, chtype /*attr*/);
676extern void dlg_auto_size(const char * /*title*/, const char * /*prompt*/, int * /*height*/, int * /*width*/, int /*boxlines*/, int /*mincols*/);
677extern void dlg_auto_sizefile(const char * /*title*/, const char * /*file*/, int * /*height*/, int * /*width*/, int /*boxlines*/, int /*mincols*/);
678extern void dlg_beeping(void);
679extern void dlg_calc_listh(int * /*height*/, int * /*list_height*/, int /*item_no*/);
680extern void dlg_clear(void);
681extern void dlg_clr_result(void);
682extern void dlg_ctl_size(int /*height*/, int /*width*/);
683extern void dlg_del_window(WINDOW * /*win*/);
684extern void dlg_does_output(void);
685extern void dlg_draw_bottom_box(WINDOW * /*win*/);
686extern void dlg_draw_box(WINDOW * /*win*/, int /*y*/, int /*x*/, int /*height*/, int /*width*/, chtype /*boxchar*/, chtype /*borderchar*/);
687extern void dlg_draw_title(WINDOW *win, const char *title);
688extern void dlg_exit(int /*code*/) GCC_NORETURN;
689extern void dlg_item_help(const char * /*txt*/);
690extern void dlg_print_autowrap(WINDOW * /*win*/, const char * /*prompt*/, int /*height*/, int /*width*/);
691extern void dlg_print_size(int /*height*/, int /*width*/);
692extern void dlg_print_text(WINDOW * /*win*/, const char * /*txt*/, int /*len*/, chtype * /*attr*/);
693extern void dlg_put_backtitle(void);
694extern void dlg_restore_vars(DIALOG_VARS * /* save */);
695extern void dlg_save_vars(DIALOG_VARS * /* save */);
696extern void dlg_set_focus(WINDOW * /*parent*/, WINDOW * /*win*/);
697extern void dlg_tab_correct_str(char * /*prompt*/);
698extern void dlg_trim_string(char * /*src*/);
699extern void end_dialog(void);
700extern void init_dialog(FILE * /*input*/, FILE * /*output*/);
701
702extern void dlg_exiterr(const char *, ...) GCC_NORETURN
703#if defined(__GNUC__) && !defined(printf)
704__attribute__((format(printf,1,2)))
705#endif
706;
707
708#ifdef HAVE_COLOR
709extern chtype dlg_color_pair(int /*foreground*/, int /*background*/);
710extern int dlg_color_count(void);
711extern void dlg_color_setup(void);
712extern void dlg_draw_shadow(WINDOW * /*win*/, int /*height*/, int /*width*/, int /*y*/, int /*x*/);
713#endif
714
715#ifdef HAVE_STRCASECMP
716#define dlg_strcmp(a,b) strcasecmp(a,b)
717#else
718extern int dlg_strcmp(const char * /*a*/, const char * /*b*/);
719#endif
720
721#ifdef HAVE_DLG_TRACE
722#define DLG_TRACE(params) dlg_trace_msg params
723extern void dlg_trace_msg(const char *fmt, ...)
724#ifdef GCC_PRINTF
725    __attribute__((format(printf,1,2)))
726#endif
727;
728extern void dlg_trace_win(WINDOW * /*win*/);
729extern void dlg_trace_chr(int /*ch*/, int /*fkey*/);
730extern void dlg_trace(const char * /*fname*/);
731#else
732#define DLG_TRACE(params) /* nothing */
733#define dlg_trace_win(win) /* nothing */
734#define dlg_trace_chr(ch,fkey) /* nothing */
735#define dlg_trace(fname) /* nothing */
736#endif
737
738#ifdef KEY_RESIZE
739extern void dlg_move_window(WINDOW * /*win*/, int /*height*/, int /*width*/, int /*y*/, int /*x*/);
740#endif
741
742/*
743 * The following stuff is needed for mouse support
744 */
745typedef struct mseRegion {
746    int x, y, X, Y, code;
747    int mode, step_x, step_y;
748    struct mseRegion *next;
749} mseRegion;
750
751#if defined(NCURSES_MOUSE_VERSION)
752
753#define	mouse_open() mousemask(BUTTON1_CLICKED, (mmask_t *) 0)
754#define	mouse_close() mousemask(0, (mmask_t *) 0)
755
756extern mseRegion * dlg_mouse_mkregion (int /*y*/, int /*x*/, int /*height*/, int /*width*/, int /*code*/);
757extern void dlg_mouse_free_regions (void);
758extern void dlg_mouse_mkbigregion (int /*y*/, int /*x*/, int /*height*/, int /*width*/, int /*code*/, int /*step_x*/, int /*step_y*/, int /*mode*/);
759extern void dlg_mouse_setbase (int /*x*/, int /*y*/);
760
761#define USE_MOUSE 1
762
763#else
764
765#define	mouse_open() /*nothing*/
766#define	mouse_close() /*nothing*/
767#define dlg_mouse_free_regions() /* nothing */
768#define	dlg_mouse_mkregion(y, x, height, width, code) /*nothing*/
769#define	dlg_mouse_mkbigregion(y, x, height, width, code, step_x, step_y, mode) /*nothing*/
770#define	dlg_mouse_setbase(x, y) /*nothing*/
771
772#define USE_MOUSE 0
773
774#endif
775
776extern mseRegion *dlg_mouse_region (int /*y*/, int /*x*/);
777extern mseRegion *dlg_mouse_bigregion (int /*y*/, int /*x*/);
778extern int dlg_mouse_wgetch (WINDOW * /*win*/, int * /*fkey*/);
779extern int dlg_mouse_wgetch_nowait (WINDOW * /*win*/, int * /*fkey*/);
780
781#define mouse_mkbutton(y,x,len,code) dlg_mouse_mkregion(y,x,1,len,code);
782
783/*
784 * This is the base for fictitious keys, which activate
785 * the buttons.
786 *
787 * Mouse-generated keys are the following:
788 *   -- the first 32 are used as numbers, in addition to '0'-'9'
789 *   -- uppercase chars are used to invoke the button (M_EVENT + 'O')
790 */
791#define M_EVENT (DLGK_max + 1)
792
793/*
794 * The `flag' parameter in checklist is used to select between
795 * radiolist and checklist
796 */
797#define FLAG_CHECK 1
798#define FLAG_RADIO 0
799
800/*
801 * This is used only for debugging (FIXME: should have a separate header).
802 */
803#ifdef NO_LEAKS
804extern void _dlg_inputstr_leaks(void);
805#if defined(NCURSES_VERSION) && defined(HAVE__NC_FREE_AND_EXIT)
806extern void _nc_free_and_exit(int);	/* nc_alloc.h normally not installed */
807#endif
808#endif
809
810#ifdef __cplusplus
811}
812#endif
813/* *INDENT-ON* */
814
815#endif /* DIALOG_H_included */
816