dialog.h revision 251843
1/*
2 *  $Id: dialog.h,v 1.260 2013/03/17 15:03:41 tom Exp $
3 *
4 *  dialog.h -- common declarations for all dialog modules
5 *
6 *  Copyright 2000-2012,2013	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 *  An earlier version of this program lists as authors
24 *	Savio Lam (lam836@cs.cuhk.hk)
25 */
26
27#ifndef DIALOG_H_included
28#define DIALOG_H_included 1
29/* *INDENT-OFF* */
30
31#include <dlg_config.h>
32
33#ifdef __hpux
34#define __HP_CURSES_COMPAT	/* workaround for getattrs, etc. */
35#endif
36
37#include <sys/types.h>
38#include <fcntl.h>
39#include <unistd.h>
40#include <ctype.h>
41#include <stdlib.h>
42#include <stdarg.h>
43#include <string.h>
44#include <signal.h>	/* fork() etc. */
45#include <math.h>	/* sqrt() */
46
47/* header conflict with Solaris xpg4 versus <sys/regset.h> */
48#if defined(ERR) && (ERR == 13)
49#undef ERR
50#endif
51
52#if defined(HAVE_NCURSESW_NCURSES_H)
53#include <ncursesw/ncurses.h>
54#elif defined(HAVE_NCURSES_NCURSES_H)
55#include <ncurses/ncurses.h>
56#elif defined(HAVE_NCURSES_CURSES_H)
57#include <ncurses/curses.h>
58#elif defined(HAVE_NCURSES_H)
59#include <ncurses.h>
60#else
61#include <curses.h>
62#if defined(HAVE_UNCTRL_H)
63#include <unctrl.h> /* most curses.h headers include this, some do not */
64#endif
65#endif
66
67/* Solaris xpg4 renames these */
68#ifndef KEY_MAX
69#ifdef __KEY_MAX
70#define KEY_MAX __KEY_MAX
71#endif
72#endif
73
74#ifndef KEY_MIN
75#ifdef __KEY_MIN
76#define KEY_MIN __KEY_MIN
77#endif
78#endif
79
80/* possible conflicts with <term.h> which may be included in <curses.h> */
81#ifdef color_names
82#undef color_names
83#endif
84
85#ifdef buttons
86#undef buttons
87#endif
88
89#ifdef ENABLE_NLS
90#include <libintl.h>
91#include <langinfo.h>
92#define _(s) dgettext(PACKAGE, s)
93#else
94#undef _
95#define _(s) s
96#endif
97
98#ifndef GCC_PRINTFLIKE
99#define GCC_PRINTFLIKE(fmt,var) /*nothing*/
100#endif
101
102#ifndef GCC_NORETURN
103#define GCC_NORETURN /*nothing*/
104#endif
105
106#ifndef GCC_UNUSED
107#define GCC_UNUSED /*nothing*/
108#endif
109
110#ifndef HAVE_WGET_WCH
111#undef USE_WIDE_CURSES
112#endif
113
114/*
115 * FIXME: a configure check would be useful
116 */
117#ifdef __hpux
118#undef ACS_UARROW
119#undef ACS_DARROW
120#undef ACS_BLOCK
121#endif
122
123/*
124 * Change these if you want
125 */
126#define USE_SHADOW TRUE
127#define USE_COLORS TRUE
128
129#ifdef HAVE_COLOR
130#define SCOLS	(COLS - (dialog_state.use_shadow ? 2 : 0))
131#define SLINES	(LINES - (dialog_state.use_shadow ? 1 : 0))
132#else
133#define SCOLS	COLS
134#define SLINES	LINES
135#endif
136
137#define DLG_EXIT_ESC		255
138#define DLG_EXIT_UNKNOWN	-2	/* never return this (internal use) */
139#define DLG_EXIT_ERROR		-1	/* the shell sees this as 255 */
140#define DLG_EXIT_OK		0
141#define DLG_EXIT_CANCEL		1
142#define DLG_EXIT_HELP		2
143#define DLG_EXIT_EXTRA		3
144#define DLG_EXIT_ITEM_HELP	4	/* actually DLG_EXIT_HELP */
145
146#define DLG_CTRL(n)	((n) & 0x1f)	/* CTRL is preferred, but conflicts */
147
148#define CHR_HELP	DLG_CTRL('E')
149#define CHR_BACKSPACE	DLG_CTRL('H')
150#define CHR_REPAINT	DLG_CTRL('L')
151#define CHR_KILL	DLG_CTRL('U')
152#define CHR_LITERAL	DLG_CTRL('V')
153#define CHR_DELETE	127
154#define CHR_NEXT	DLG_CTRL('N')
155#define CHR_PREVIOUS	DLG_CTRL('P')
156#define CHR_TRACE	DLG_CTRL('T')
157
158#define ESC		27
159#define TAB		DLG_CTRL('I')
160
161#define MARGIN 1
162#define GUTTER 2
163#define SHADOW_ROWS 1
164#define SHADOW_COLS 2
165#define ARROWS_COL  5
166
167#define MAX_LEN 2048
168#define BUF_SIZE (10L*1024)
169
170#undef  MIN
171#define MIN(x,y) ((x) < (y) ? (x) : (y))
172
173#undef  MAX
174#define MAX(x,y) ((x) > (y) ? (x) : (y))
175
176#define DEFAULT_SEPARATE_STR "\t"
177#define DEFAULT_ASPECT_RATIO 9
178/* how many spaces is a tab long (default)? */
179#define TAB_LEN 8
180#define WTIMEOUT_VAL        10	/* minimum amount of time needed for curses */
181
182#ifndef A_CHARTEXT
183#define A_CHARTEXT 0xff
184#endif
185
186#define CharOf(ch)  ((ch) & 0xff)
187
188#ifndef ACS_ULCORNER
189#define ACS_ULCORNER '+'
190#endif
191#ifndef ACS_LLCORNER
192#define ACS_LLCORNER '+'
193#endif
194#ifndef ACS_URCORNER
195#define ACS_URCORNER '+'
196#endif
197#ifndef ACS_LRCORNER
198#define ACS_LRCORNER '+'
199#endif
200#ifndef ACS_HLINE
201#define ACS_HLINE '-'
202#endif
203#ifndef ACS_VLINE
204#define ACS_VLINE '|'
205#endif
206#ifndef ACS_LTEE
207#define ACS_LTEE '+'
208#endif
209#ifndef ACS_RTEE
210#define ACS_RTEE '+'
211#endif
212#ifndef ACS_UARROW
213#define ACS_UARROW '^'
214#endif
215#ifndef ACS_DARROW
216#define ACS_DARROW 'v'
217#endif
218#ifndef ACS_BLOCK
219#define ACS_BLOCK '#'
220#endif
221
222/* these definitions may work for antique versions of curses */
223#ifndef HAVE_GETBEGYX
224#undef  getbegyx
225#define getbegyx(win,y,x)	(y = (win)?(win)->_begy:ERR, x = (win)?(win)->_begx:ERR)
226#endif
227
228#ifndef HAVE_GETMAXYX
229#undef  getmaxyx
230#define getmaxyx(win,y,x)	(y = (win)?(win)->_maxy:ERR, x = (win)?(win)->_maxx:ERR)
231#endif
232
233#ifndef HAVE_GETPARYX
234#undef  getparyx
235#define getparyx(win,y,x)	(y = (win)?(win)->_pary:ERR, x = (win)?(win)->_parx:ERR)
236#endif
237
238#if !defined(HAVE_WGETPARENT) && defined(HAVE_WINDOW__PARENT)
239#undef  wgetparent
240#define wgetparent(win)		((win) ? (win)->_parent : 0)
241#endif
242
243#if !defined(HAVE_WSYNCUP)
244#undef wsyncup
245#define wsyncup(win) /* nothing */
246#endif
247
248#if !defined(HAVE_WCURSYNCUP)
249#undef wcursyncup
250#define wcursyncup(win) /* nothing */
251#endif
252
253#ifdef __cplusplus
254extern "C" {
255#endif
256
257/* these definitions may be needed for bleeding-edge curses implementations */
258#if !(defined(HAVE_GETBEGX) && defined(HAVE_GETBEGY))
259#undef getbegx
260#undef getbegy
261#define getbegx(win) dlg_getbegx(win)
262#define getbegy(win) dlg_getbegy(win)
263extern int dlg_getbegx(WINDOW * /*win*/);
264extern int dlg_getbegy(WINDOW * /*win*/);
265#endif
266
267#if !(defined(HAVE_GETCURX) && defined(HAVE_GETCURY))
268#undef getcurx
269#undef getcury
270#define getcurx(win) dlg_getcurx(win)
271#define getcury(win) dlg_getcury(win)
272extern int dlg_getcurx(WINDOW * /*win*/);
273extern int dlg_getcury(WINDOW * /*win*/);
274#endif
275
276#if !(defined(HAVE_GETMAXX) && defined(HAVE_GETMAXY))
277#undef getmaxx
278#undef getmaxy
279#define getmaxx(win) dlg_getmaxx(win)
280#define getmaxy(win) dlg_getmaxy(win)
281extern int dlg_getmaxx(WINDOW * /*win*/);
282extern int dlg_getmaxy(WINDOW * /*win*/);
283#endif
284
285#if !(defined(HAVE_GETPARX) && defined(HAVE_GETPARY))
286#undef getparx
287#undef getpary
288#define getparx(win) dlg_getparx(win)
289#define getpary(win) dlg_getpary(win)
290extern int dlg_getparx(WINDOW * /*win*/);
291extern int dlg_getpary(WINDOW * /*win*/);
292#endif
293
294#if !(defined(HAVE_WGETPARENT) && defined(HAVE_WINDOW__PARENT))
295#undef wgetparent
296#define wgetparent(win) dlg_wgetparent(win)
297extern WINDOW * dlg_wgetparent(WINDOW * /*win*/);
298#endif
299
300/*
301 * This is a list of "old" names, which should be helpful in updating
302 * applications that use libdialog.  Starting with 2003/11/26, all exported
303 * symbols from libdialog have "dlg_" prefix, or "dialog_" prefix or "_dialog"
304 * suffix (or suffix "_dialog", e.g., init_dialog).
305 */
306#ifdef __DIALOG_OLD_NAMES__
307#define color_table                       dlg_color_table
308#define attr_clear(win,h,w,a)             dlg_attr_clear(win,h,w,a)
309#define auto_size(t,s,h,w,xl,mc)          dlg_auto_size(t,s,h,w,xl,mc)
310#define auto_sizefile(t,f,h,w,xl,mc)      dlg_auto_sizefile(t,f,h,w,xl,mc)
311#define beeping()                         dlg_beeping()
312#define box_x_ordinate(w)                 dlg_box_x_ordinate(w)
313#define box_y_ordinate(h)                 dlg_box_y_ordinate(h)
314#define calc_listh(h,lh,in)               dlg_calc_listh(h,lh,in)
315#define calc_listw(in,items,group)        dlg_calc_listw(in,items,group)
316#define color_setup()                     dlg_color_setup()
317#define create_rc(f)                      dlg_create_rc(f)
318#define ctl_size(h,w)                     dlg_ctl_size(h,w)
319#define del_window(win)                   dlg_del_window(win)
320#define dialog_clear()                    dlg_clear()
321#define draw_bottom_box(win)              dlg_draw_bottom_box(win)
322#define draw_box(win,y,x,h,w,xc,bc)       dlg_draw_box(win,y,x,h,w,xc,bc)
323#define draw_shadow(win,h,w,y,x)          dlg_draw_shadow(win,h,w,y,x)
324#define draw_title(win,t)                 dlg_draw_title(win,t)
325#define exiterr                           dlg_exiterr
326#define killall_bg(n)                     dlg_killall_bg(n)
327#define mouse_bigregion(y,x)              dlg_mouse_bigregion(y,x)
328#define mouse_free_regions()              dlg_mouse_free_regions()
329#define mouse_mkbigregion(y,x,h,w,n,ix,iy,m) dlg_mouse_mkbigregion(y,x,h,w,n,ix,iy,m)
330#define mouse_mkregion(y,x,h,w,n)         dlg_mouse_mkregion(y,x,h,w,n)
331#define mouse_region(y,x)                 dlg_mouse_region(y,x)
332#define mouse_setbase(x,y)                dlg_mouse_setbase(x,y)
333#define mouse_setcode(c)                  dlg_mouse_setcode(c)
334#define mouse_wgetch(w,c)                 dlg_mouse_wgetch(w,c)
335#define new_window(h,w,y,x)               dlg_new_window(h,w,y,x)
336#define parse_rc()                        dlg_parse_rc()
337#define print_autowrap(win,s,h,w)         dlg_print_autowrap(win,s,h,w)
338#define print_size(h,w)                   dlg_print_size(h,w)
339#define put_backtitle()                   dlg_put_backtitle()
340#define strclone(cprompt)                 dlg_strclone(cprompt)
341#define sub_window(win,h,w,y,x)           dlg_sub_window(win,h,w,y,x)
342#define tab_correct_str(s)                dlg_tab_correct_str(s)
343#endif
344
345/*
346 * Attribute names
347 */
348#define DIALOG_ATR(n)                 dlg_color_table[n].atr
349
350#define screen_attr                   DIALOG_ATR(0)
351#define shadow_attr                   DIALOG_ATR(1)
352#define dialog_attr                   DIALOG_ATR(2)
353#define title_attr                    DIALOG_ATR(3)
354#define border_attr                   DIALOG_ATR(4)
355#define button_active_attr            DIALOG_ATR(5)
356#define button_inactive_attr          DIALOG_ATR(6)
357#define button_key_active_attr        DIALOG_ATR(7)
358#define button_key_inactive_attr      DIALOG_ATR(8)
359#define button_label_active_attr      DIALOG_ATR(9)
360#define button_label_inactive_attr    DIALOG_ATR(10)
361#define inputbox_attr                 DIALOG_ATR(11)
362#define inputbox_border_attr          DIALOG_ATR(12)
363#define searchbox_attr                DIALOG_ATR(13)
364#define searchbox_title_attr          DIALOG_ATR(14)
365#define searchbox_border_attr         DIALOG_ATR(15)
366#define position_indicator_attr       DIALOG_ATR(16)
367#define menubox_attr                  DIALOG_ATR(17)
368#define menubox_border_attr           DIALOG_ATR(18)
369#define item_attr                     DIALOG_ATR(19)
370#define item_selected_attr            DIALOG_ATR(20)
371#define tag_attr                      DIALOG_ATR(21)
372#define tag_selected_attr             DIALOG_ATR(22)
373#define tag_key_attr                  DIALOG_ATR(23)
374#define tag_key_selected_attr         DIALOG_ATR(24)
375#define check_attr                    DIALOG_ATR(25)
376#define check_selected_attr           DIALOG_ATR(26)
377#define uarrow_attr                   DIALOG_ATR(27)
378#define darrow_attr                   DIALOG_ATR(28)
379#define itemhelp_attr                 DIALOG_ATR(29)
380#define form_active_text_attr         DIALOG_ATR(30)
381#define form_text_attr                DIALOG_ATR(31)
382#define form_item_readonly_attr       DIALOG_ATR(32)
383#define gauge_attr                    DIALOG_ATR(33)
384#define border2_attr                  DIALOG_ATR(34)
385#define inputbox_border2_attr         DIALOG_ATR(35)
386#define searchbox_border2_attr        DIALOG_ATR(36)
387#define menubox_border2_attr          DIALOG_ATR(37)
388
389#define DLGK_max (KEY_MAX + 256)
390
391/*
392 * Callbacks are used to implement the "background" tailbox.
393 */
394struct _dlg_callback;
395
396typedef void (*DIALOG_FREEBACK) (struct _dlg_callback * /* p */);
397
398typedef struct _dlg_callback {
399    struct _dlg_callback *next;
400    FILE *input;
401    WINDOW *win;
402    bool keep_bg;	/* keep in background, on exit */
403    bool bg_task;	/* true if this is background task */
404    bool (*handle_getc)(struct _dlg_callback *p, int ch, int fkey, int *result);
405    bool keep_win;	/* true to not erase window on exit */
406    /* data for dlg_add_callback_ref */
407    struct _dlg_callback **caller;
408    DIALOG_FREEBACK freeback;
409    /* 1.1-20110107 */
410    bool (*handle_input)(struct _dlg_callback *p);
411    bool input_ready;
412} DIALOG_CALLBACK;
413
414typedef struct _dlg_windows {
415    struct _dlg_windows *next;
416    WINDOW *normal;
417    WINDOW *shadow;
418} DIALOG_WINDOWS;
419
420/*
421 * Global variables, which are initialized as needed
422 */
423typedef struct {
424    DIALOG_CALLBACK *getc_callbacks;
425    DIALOG_CALLBACK *getc_redirect;
426    DIALOG_WINDOWS *all_windows;
427    DIALOG_WINDOWS *all_subwindows;
428    FILE *output;		/* option "--output-fd fd" */
429    FILE *pipe_input;		/* used for gauge widget */
430    FILE *screen_output;	/* newterm(), etc. */
431    bool screen_initialized;
432    bool use_colors;		/* use colors by default? */
433    bool use_scrollbar;		/* option "--scrollbar" */
434    bool use_shadow;		/* shadow dialog boxes by default? */
435    bool visit_items;		/* option "--visit-items" */
436    char *separate_str;		/* option "--separate-widget string" */
437    int aspect_ratio;		/* option "--aspect ratio" */
438    int output_count;		/* # of widgets that may have done output */
439    int tab_len;		/* option "--tab-len n" */
440    /* 1.0-20070227 */
441    FILE *input;		/* option "--input-fd fd" */
442#ifdef HAVE_DLG_TRACE
443    FILE *trace_output;		/* option "--trace file" */
444#endif
445    /* 1.1-20110106 */
446    bool no_mouse;		/* option "--no-mouse" */
447    int visit_cols;		/* option "--visit-items" */
448} DIALOG_STATE;
449
450extern DIALOG_STATE dialog_state;
451
452/*
453 * Global variables, which dialog resets before each widget
454 */
455typedef struct {
456    bool beep_after_signal;	/* option "--beep-after" */
457    bool beep_signal;		/* option "--beep" */
458    bool begin_set;		/* option "--begin y x" was used */
459    bool cant_kill;		/* option "--no-kill" */
460    bool colors;		/* option "--colors" */
461    bool cr_wrap;		/* option "--cr-wrap" */
462    bool defaultno;		/* option "--defaultno" */
463    bool dlg_clear_screen;	/* option "--clear" */
464    bool extra_button;		/* option "--extra-button" */
465    bool help_button;		/* option "--help-button" */
466    bool help_status;		/* option "--help-status" */
467    bool input_menu;		/* menu vs inputmenu widget */
468    bool insecure;		/* option "--insecure" */
469    bool item_help;		/* option "--item-help" */
470    bool keep_window;		/* option "--keep-window" */
471    bool nocancel;		/* option "--no-cancel" */
472    bool nocollapse;		/* option "--no-collapse" */
473    bool print_siz;		/* option "--print-size" */
474    bool separate_output;	/* option "--separate-output" */
475    bool single_quoted;		/* option "--single-quoted" */
476    bool size_err;		/* option "--size-err" */
477    bool tab_correct;		/* option "--tab-correct" */
478    bool trim_whitespace;	/* option "--trim" */
479    char *backtitle;		/* option "--backtitle backtitle" */
480    char *cancel_label;		/* option "--cancel-label string" */
481    char *default_item;		/* option "--default-item string" */
482    char *exit_label;		/* option "--exit-label string" */
483    char *extra_label;		/* option "--extra-label string" */
484    char *help_label;		/* option "--help-label string" */
485    char *input_result;
486    char *no_label;		/* option "--no-label string" */
487    char *ok_label;		/* option "--ok-label string" */
488    char *title;		/* option "--title title" */
489    char *yes_label;		/* option "--yes-label string" */
490    int begin_x;		/* option "--begin y x" (second value) */
491    int begin_y;		/* option "--begin y x" (first value) */
492    int max_input;		/* option "--max-input size" */
493    int scale_factor;		/* RESERVED */
494    int sleep_secs;		/* option "--sleep secs" */
495    int timeout_secs;		/* option "--timeout secs" */
496    unsigned input_length;	/* nonzero if input_result is allocated */
497    /* 1.0-20051207 */
498    unsigned formitem_type;	/* DIALOG_FORMITEM.type in dialog_form() */
499    /* 1.1-20070227 */
500    bool keep_tite;		/* option "--keep-tite" */
501    bool ascii_lines;		/* option "--ascii-lines" */
502    bool no_lines;		/* option "--no-lines" */
503    /* 1.1-20070930 */
504    bool nook;			/* option "--no-ok" */
505    /* 1.1-20080727 */
506    bool quoted;		/* option "--quoted" */
507    char *column_header;	/* RESERVED "--column-header" */
508    char *column_separator;	/* option "--column-separator" */
509    char *output_separator;	/* option "--output-separator" */
510    /* 1.1-20100118 */
511    char *date_format;		/* option "--date-format" */
512    char *time_format;		/* option "--time-format" */
513    /* 1.1-20110629 */
514    char *help_line;		/* option "--hline" */
515    char *help_file;		/* option "--hfile" */
516    bool in_helpfile;		/* flag to prevent recursion in --hfile */
517    bool no_nl_expand;		/* option "--no-nl-expand" */
518    /* 1.1-20120701 */
519    int default_button;		/* option "--default-button" (exit code) */
520    /* 1.1-20121218 */
521    bool no_tags;		/* option "--no-tags" */
522    bool no_items;		/* option "--no-items" */
523    /* 1.2-20130315 */
524    bool last_key;		/* option "--last-key" */
525} DIALOG_VARS;
526
527#define USE_ITEM_HELP(s)        (dialog_vars.item_help && (s) != 0)
528
529/*
530 * Some settings change the number of data items per row which dialog reads
531 * from a script.
532 */
533#define DLG__NO_ITEMS		(dialog_vars.no_items ? 0 : 1)
534#define DLG__ITEM_HELP          (dialog_vars.item_help ? 1 : 0)
535
536/*
537 * These are the total number of data items per row used for each widget type.
538 */
539#define CHECKBOX_TAGS           (2 + DLG__ITEM_HELP + DLG__NO_ITEMS)
540#define MENUBOX_TAGS            (1 + DLG__ITEM_HELP + DLG__NO_ITEMS)
541#define FORMBOX_TAGS            (8 + DLG__ITEM_HELP)
542#define MIXEDFORM_TAGS          (1 + FORMBOX_TAGS)
543#define MIXEDGAUGE_TAGS         2
544#define TREEVIEW_TAGS           (3 + DLG__ITEM_HELP + DLG__NO_ITEMS)
545
546extern DIALOG_VARS dialog_vars;
547
548#ifndef HAVE_TYPE_CHTYPE
549#define chtype long
550#endif
551
552#define UCH(ch)			((unsigned char)(ch))
553
554#define assert_ptr(ptr,msg) if ((ptr) == 0) dlg_exiterr("cannot allocate memory in " msg)
555
556#define dlg_malloc(t,n)    (t *) malloc((size_t)(n) * sizeof(t))
557#define dlg_calloc(t,n)    (t *) calloc((size_t)(n), sizeof(t))
558#define dlg_realloc(t,n,p) (t *) realloc((p), (n) * sizeof(t))
559
560/*
561 * Table for attribute- and color-values.
562 */
563typedef struct {
564    chtype atr;
565#ifdef HAVE_COLOR
566    int fg;
567    int bg;
568    int hilite;
569#endif
570#ifdef HAVE_RC_FILE
571    const char *name;
572    const char *comment;
573#endif
574} DIALOG_COLORS;
575
576extern DIALOG_COLORS dlg_color_table[];
577
578/*
579 * Function prototypes
580 */
581extern const char *dialog_version(void);
582
583/* widgets, each in separate files */
584extern int dialog_buildlist(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*list_height*/, int /*item_no*/, char ** /*items*/, int /*order_mode*/);
585extern int dialog_calendar(const char * /*title*/, const char * /*subtitle*/, int /*height*/, int /*width*/, int /*day*/, int /*month*/, int /*year*/);
586extern int dialog_checklist(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*list_height*/, int /*item_no*/, char ** /*items*/, int /*flag*/);
587extern int dialog_dselect(const char * /*title*/, const char * /*path*/, int /*height*/, int /*width*/);
588extern int dialog_editbox(const char * /*title*/, const char * /*file*/, int /*height*/, int /*width*/);
589extern int dialog_form(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*form_height*/, int /*item_no*/, char ** /*items*/);
590extern int dialog_fselect(const char * /*title*/, const char * /*path*/, int /*height*/, int /*width*/);
591extern int dialog_gauge(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*percent*/);
592extern int dialog_helpfile(const char * /*title*/, const char * /*file*/, int /*height*/, int /*width*/);
593extern int dialog_inputbox(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, const char * /*init*/, const int /*password*/);
594extern int dialog_menu(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*menu_height*/, int /*item_no*/, char ** /*items*/);
595extern int dialog_mixedform(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*form_height*/, int /*item_no*/, char ** /*items*/);
596extern int dialog_mixedgauge(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*percent*/, int /*item_no*/, char ** /*items*/);
597extern int dialog_msgbox(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*pauseopt*/);
598extern int dialog_pause(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*seconds*/);
599extern int dialog_prgbox(const char * /*title*/, const char * /*cprompt*/, const char * /*command*/, int /*height*/, int /*width*/, int /*pauseopt*/);
600extern int dialog_progressbox(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/);
601extern int dialog_rangebox(const char * /*title*/, const char * /*file*/, int /*height*/, int /*width*/, int /*min_value*/, int /*max_value*/, int /*default_value*/);
602extern int dialog_tailbox(const char * /*title*/, const char * /*file*/, int /*height*/, int /*width*/, int /*bg_task*/);
603extern int dialog_textbox(const char * /*title*/, const char * /*file*/, int /*height*/, int /*width*/);
604extern int dialog_timebox(const char * /*title*/, const char * /*subtitle*/, int /*height*/, int /*width*/, int /*hour*/, int /*minute*/, int /*second*/);
605extern int dialog_treeview(const char * /*title*/, const char * /*subtitle*/, int /*height*/, int /*width*/, int /*list_height*/, int /*item_no*/, char ** /*items*/, int /*flag*/);
606extern int dialog_yesno(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/);
607
608/* some widgets have alternate entrypoints, to allow list manipulation */
609typedef struct {
610    char *name;
611    char *text;
612    char *help;
613    int state;
614} DIALOG_LISTITEM;
615
616typedef struct {
617    unsigned type;		/* the field type (0=input, 1=password) */
618    char *name;			/* the field label */
619    int name_len;		/* ...its length */
620    int name_y;			/* ...its y-ordinate */
621    int name_x;			/* ...its x-ordinate */
622    bool name_free;		/* ...true if .name can be freed */
623    char *text;			/* the field contents */
624    int text_len;		/* ...its length on the screen */
625    int text_y;			/* ...its y-ordinate */
626    int text_x;			/* ...its x-ordinate */
627    int text_flen;		/* ...its length on screen, or 0 if no input allowed */
628    int text_ilen;		/* ...its limit on amount to be entered */
629    bool text_free;		/* ...true if .text can be freed */
630    char *help;			/* help-message, if any */
631    bool help_free;		/* ...true if .help can be freed */
632} DIALOG_FORMITEM;
633
634typedef	int (DIALOG_INPUTMENU) (DIALOG_LISTITEM * /*items*/, int /*current*/, char * /*newtext*/);
635
636extern 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*/);
637extern 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*/);
638extern 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*/);
639extern int dlg_progressbox(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*pauseopt*/, FILE * /* fp */);
640
641/* argv.c */
642extern char ** dlg_string_to_argv(char * /* blob */);
643extern int dlg_count_argv(char ** /* argv */);
644extern int dlg_eat_argv(int * /* argcp */, char *** /* argvp */, int /* start */, int /* count */);
645
646/* arrows.c */
647extern void dlg_draw_arrows(WINDOW * /*dialog*/, int /*top_arrow*/, int /*bottom_arrow*/, int /*x*/, int /*top*/, int /*bottom*/);
648extern void dlg_draw_arrows2(WINDOW * /*dialog*/, int /*top_arrow*/, int /*bottom_arrow*/, int /*x*/, int /*top*/, int /*bottom*/, chtype /*attr*/, chtype /*borderattr*/);
649extern void dlg_draw_helpline(WINDOW * /*dialog*/, bool /*decorations*/);
650extern 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*/);
651
652/* buildlist.c */
653extern int dlg_buildlist(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*list_height*/, int /*item_no*/, DIALOG_LISTITEM * /*items*/, const char * /*states*/, int /*order_mode*/, int * /*current_item*/);
654
655/* buttons.c */
656extern const char ** dlg_exit_label(void);
657extern const char ** dlg_ok_label(void);
658extern const char ** dlg_ok_labels(void);
659extern const char ** dlg_yes_labels(void);
660extern int dlg_button_count(const char ** /*labels*/);
661extern int dlg_button_to_char(const char * /*label*/);
662extern int dlg_button_x_step(const char ** /*labels*/, int /*limit*/, int * /*gap*/, int * /*margin*/, int * /*step*/);
663extern int dlg_char_to_button(int /*ch*/, const char ** /*labels*/);
664extern int dlg_exit_buttoncode(int /*button*/);
665extern int dlg_match_char(int /*ch*/, const char * /*string*/);
666extern int dlg_next_button(const char ** /*labels*/, int /*button*/);
667extern int dlg_next_ok_buttonindex(int /*current*/, int /*extra*/);
668extern int dlg_ok_buttoncode(int /*button*/);
669extern int dlg_prev_button(const char ** /*labels*/, int /*button*/);
670extern int dlg_prev_ok_buttonindex(int /*current*/, int /*extra*/);
671extern int dlg_yes_buttoncode(int /*button*/);
672extern void dlg_button_layout(const char ** /*labels*/, int * /*limit*/);
673extern void dlg_button_sizes(const char ** /*labels*/, int /*vertical*/, int * /*longest*/, int * /*length*/);
674extern void dlg_draw_buttons(WINDOW * /*win*/, int /*y*/, int /*x*/, const char ** /*labels*/, int /*selected*/, int /*vertical*/, int /*limit*/);
675
676/* columns.c */
677extern void dlg_align_columns(char ** /* target */, int  /* per_row */, int /* num_rows */);
678extern void dlg_free_columns(char ** /* target */, int  /* per_row */, int /* num_rows */);
679
680/* editbox.c */
681extern int dlg_editbox(const char * /*title*/, char *** /*list*/, int * /*rows*/, int /*height*/, int /*width*/);
682
683/* formbox.c */
684extern int dlg_default_formitem(DIALOG_FORMITEM * /*items*/);
685extern int dlg_ordinate(const char * /*s*/);
686extern void dlg_free_formitems(DIALOG_FORMITEM * /*items*/);
687
688/* guage.c */
689extern void * dlg_allocate_gauge(const char * /* title */, const char * /* cprompt */, int /* height */, int /* width */, int /* percent */);
690extern void dlg_free_gauge(void * /* objptr */);
691extern void dlg_update_gauge(void * /* objptr */, int /* percent */);
692
693/* inputstr.c */
694extern bool dlg_edit_string(char * /*string*/, int * /*offset*/, int /*key*/, int /*fkey*/, bool /*force*/);
695extern const int * dlg_index_columns(const char * /*string*/);
696extern const int * dlg_index_wchars(const char * /*string*/);
697extern int dlg_count_columns(const char * /*string*/);
698extern int dlg_count_wchars(const char * /*string*/);
699extern int dlg_edit_offset(char * /*string*/, int /*offset*/, int /*x_last*/);
700extern int dlg_find_index(const int * /*list*/, int  /*limit*/, int /*to_find*/);
701extern int dlg_limit_columns(const char * /*string*/, int /*limit*/, int /*offset*/);
702extern 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*/);
703
704/* menubox.c */
705extern int dlg_dummy_menutext(DIALOG_LISTITEM * /*items*/, int /*current*/, char * /*newtext*/);
706extern int dlg_renamed_menutext(DIALOG_LISTITEM * /*items*/, int /*current*/, char * /*newtext*/);
707
708/* rc.c */
709#ifdef HAVE_RC_FILE
710extern int dlg_parse_rc(void);
711extern void dlg_create_rc(const char * /*filename*/);
712#endif
713
714/* treeview.c */
715extern int dlg_treeview(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*list_height*/, int /*item_no*/, DIALOG_LISTITEM * /*items*/, const char * /*states*/, int * /*depths*/, int /*flag*/, int * /*current_item*/);
716
717/* ui_getc.c */
718extern int dlg_getc(WINDOW * /*win*/, int * /*fkey*/);
719extern int dlg_getc_callbacks(int /*ch*/, int /*fkey*/, int * /*result*/);
720extern int dlg_last_getc(void);
721extern void dlg_add_last_key(int /*mode*/);
722extern void dlg_add_callback(DIALOG_CALLBACK * /*p*/);
723extern void dlg_add_callback_ref(DIALOG_CALLBACK ** /*p*/, DIALOG_FREEBACK /* cleanup */);
724extern void dlg_flush_getc(void);
725extern void dlg_remove_callback(DIALOG_CALLBACK * /*p*/);
726extern void dlg_killall_bg(int *retval);
727
728/* util.c */
729extern WINDOW * dlg_new_modal_window(WINDOW * /*parent*/, int /*height*/, int /*width*/, int /*y*/, int /*x*/);
730extern WINDOW * dlg_new_window(int /*height*/, int /*width*/, int /*y*/, int /*x*/);
731extern WINDOW * dlg_sub_window(WINDOW * /*win*/, int /*height*/, int /*width*/, int /*y*/, int /*x*/);
732extern bool dlg_need_separator(void);
733extern char * dlg_set_result(const char * /*string*/);
734extern char * dlg_strclone(const char * /*cprompt*/);
735extern char * dlg_strempty(void);
736extern chtype dlg_asciibox(chtype /*ch*/);
737extern chtype dlg_boxchar(chtype /*ch*/);
738extern chtype dlg_get_attrs(WINDOW * /*win*/);
739extern const char * dlg_print_line(WINDOW * /*win*/, chtype * /*attr*/, const char * /*prompt*/, int /*lm*/, int /*rm*/, int * /*x*/);
740extern int dlg_box_x_ordinate(int /*width*/);
741extern int dlg_box_y_ordinate(int /*height*/);
742extern int dlg_calc_list_width(int /*item_no*/, DIALOG_LISTITEM * /*items*/);
743extern int dlg_calc_listw(int /*item_no*/, char ** /*items*/, int /*group*/);
744extern int dlg_check_scrolled(int /* key */, int /* last */, int /* page */, bool * /* show */, int * /* offset */);
745extern int dlg_count_real_columns(const char * /*text*/);
746extern int dlg_default_item(char ** /*items*/, int /*llen*/);
747extern int dlg_default_listitem(DIALOG_LISTITEM * /*items*/);
748extern int dlg_defaultno_button(void);
749extern int dlg_default_button(void);
750extern int dlg_max_input(int /*max_len*/);
751extern int dlg_print_scrolled(WINDOW * /* win */, const char * /* prompt */, int /* offset */, int /* height */, int /* width */, int /* pauseopt */);
752extern void dlg_add_quoted(char * /*string*/);
753extern void dlg_add_result(const char * /*string*/);
754extern void dlg_add_separator(void);
755extern void dlg_add_string(char * /*string*/);
756extern void dlg_attr_clear(WINDOW * /*win*/, int /*height*/, int /*width*/, chtype /*attr*/);
757extern void dlg_auto_size(const char * /*title*/, const char * /*prompt*/, int * /*height*/, int * /*width*/, int /*boxlines*/, int /*mincols*/);
758extern void dlg_auto_sizefile(const char * /*title*/, const char * /*file*/, int * /*height*/, int * /*width*/, int /*boxlines*/, int /*mincols*/);
759extern void dlg_beeping(void);
760extern void dlg_calc_listh(int * /*height*/, int * /*list_height*/, int /*item_no*/);
761extern void dlg_clear(void);
762extern void dlg_clr_result(void);
763extern void dlg_ctl_size(int /*height*/, int /*width*/);
764extern void dlg_del_window(WINDOW * /*win*/);
765extern void dlg_does_output(void);
766extern void dlg_draw_bottom_box(WINDOW * /*win*/);
767extern void dlg_draw_bottom_box2(WINDOW * /*win*/, chtype /*on_left*/, chtype /*on_right*/, chtype /*on_inside*/);
768extern void dlg_draw_box(WINDOW * /*win*/, int /*y*/, int /*x*/, int /*height*/, int /*width*/, chtype /*boxchar*/, chtype /*borderchar*/);
769extern void dlg_draw_box2(WINDOW * /*win*/, int /*y*/, int /*x*/, int /*height*/, int /*width*/, chtype /*boxchar*/, chtype /*borderchar*/, chtype /*borderchar2*/);
770extern void dlg_draw_title(WINDOW *win, const char *title);
771extern void dlg_exit(int /*code*/) GCC_NORETURN;
772extern void dlg_item_help(const char * /*txt*/);
773extern void dlg_print_autowrap(WINDOW * /*win*/, const char * /*prompt*/, int /*height*/, int /*width*/);
774extern void dlg_print_listitem(WINDOW * /*win*/, const char * /*text*/, int /*climit*/, bool /*first*/, int /*selected*/);
775extern void dlg_print_size(int /*height*/, int /*width*/);
776extern void dlg_print_text(WINDOW * /*win*/, const char * /*txt*/, int /*len*/, chtype * /*attr*/);
777extern void dlg_put_backtitle(void);
778extern void dlg_restore_vars(DIALOG_VARS * /* save */);
779extern void dlg_save_vars(DIALOG_VARS * /* save */);
780extern void dlg_set_focus(WINDOW * /*parent*/, WINDOW * /*win*/);
781extern void dlg_tab_correct_str(char * /*prompt*/);
782extern void dlg_trim_string(char * /*src*/);
783extern void end_dialog(void);
784extern void init_dialog(FILE * /*input*/, FILE * /*output*/);
785
786extern void dlg_exiterr(const char *, ...) GCC_NORETURN GCC_PRINTFLIKE(1,2);
787
788#ifdef HAVE_COLOR
789extern chtype dlg_color_pair(int /*foreground*/, int /*background*/);
790extern int dlg_color_count(void);
791extern void dlg_color_setup(void);
792extern void dlg_draw_shadow(WINDOW * /*win*/, int /*height*/, int /*width*/, int /*y*/, int /*x*/);
793#endif
794
795#ifdef HAVE_STRCASECMP
796#define dlg_strcmp(a,b) strcasecmp(a,b)
797#else
798extern int dlg_strcmp(const char * /*a*/, const char * /*b*/);
799#endif
800
801#ifdef HAVE_DLG_TRACE
802#define DLG_TRACE(params) dlg_trace_msg params
803extern void dlg_trace_msg(const char *fmt, ...) GCC_PRINTFLIKE(1,2);
804extern void dlg_trace_win(WINDOW * /*win*/);
805extern void dlg_trace_chr(int /*ch*/, int /*fkey*/);
806extern void dlg_trace(const char * /*fname*/);
807#else
808#define DLG_TRACE(params) /* nothing */
809#define dlg_trace_win(win) /* nothing */
810#define dlg_trace_chr(ch,fkey) /* nothing */
811#define dlg_trace(fname) /* nothing */
812#endif
813
814#ifdef KEY_RESIZE
815extern void dlg_move_window(WINDOW * /*win*/, int /*height*/, int /*width*/, int /*y*/, int /*x*/);
816#endif
817
818/*
819 * Normally "enter" means "ok".  Use this macro to handle the explicit
820 * check for DLGK_ENTER:
821 */
822#define dlg_enter_buttoncode(code) (dialog_vars.nook ? DLG_EXIT_OK : dlg_ok_buttoncode(code))
823
824/*
825 * The following stuff is needed for mouse support
826 */
827typedef struct mseRegion {
828    int x, y, X, Y, code;
829    int mode, step_x, step_y;
830    struct mseRegion *next;
831} mseRegion;
832
833#if defined(NCURSES_MOUSE_VERSION)
834
835#define	mouse_open() mousemask(BUTTON1_CLICKED, (mmask_t *) 0)
836#define	mouse_close() mousemask(0, (mmask_t *) 0)
837
838extern mseRegion * dlg_mouse_mkregion (int /*y*/, int /*x*/, int /*height*/, int /*width*/, int /*code*/);
839extern void dlg_mouse_free_regions (void);
840extern void dlg_mouse_mkbigregion (int /*y*/, int /*x*/, int /*height*/, int /*width*/, int /*code*/, int /*step_x*/, int /*step_y*/, int /*mode*/);
841extern void dlg_mouse_setbase (int /*x*/, int /*y*/);
842extern void dlg_mouse_setcode (int /*code*/);
843
844#define USE_MOUSE 1
845
846#else
847
848#define	mouse_open() /*nothing*/
849#define	mouse_close() /*nothing*/
850#define dlg_mouse_free_regions() /* nothing */
851#define	dlg_mouse_mkregion(y, x, height, width, code) /*nothing*/
852#define	dlg_mouse_mkbigregion(y, x, height, width, code, step_x, step_y, mode) /*nothing*/
853#define	dlg_mouse_setbase(x, y) /*nothing*/
854#define	dlg_mouse_setcode(c) /*nothing*/
855
856#define USE_MOUSE 0
857
858#endif
859
860extern mseRegion *dlg_mouse_region (int /*y*/, int /*x*/);
861extern mseRegion *dlg_mouse_bigregion (int /*y*/, int /*x*/);
862extern int dlg_mouse_wgetch (WINDOW * /*win*/, int * /*fkey*/);
863extern int dlg_mouse_wgetch_nowait (WINDOW * /*win*/, int * /*fkey*/);
864
865#define mouse_mkbutton(y,x,len,code) dlg_mouse_mkregion(y,x,1,len,code);
866
867/*
868 * This is the base for fictitious keys, which activate
869 * the buttons.
870 *
871 * Mouse-generated keys are the following:
872 *   -- the first 32 are used as numbers, in addition to '0'-'9'
873 *   -- uppercase chars are used to invoke the button (M_EVENT + 'O')
874 */
875#define M_EVENT (DLGK_max + 1)
876
877/*
878 * The `flag' parameter in checklist is used to select between
879 * radiolist and checklist
880 */
881#define FLAG_CHECK 1
882#define FLAG_RADIO 0
883
884/*
885 * This is used only for debugging (FIXME: should have a separate header).
886 */
887#ifdef NO_LEAKS
888extern void _dlg_inputstr_leaks(void);
889#if defined(NCURSES_VERSION) && defined(HAVE__NC_FREE_AND_EXIT)
890extern void _nc_free_and_exit(int);	/* nc_alloc.h normally not installed */
891#endif
892#endif
893
894#ifdef __cplusplus
895}
896#endif
897/* *INDENT-ON* */
898
899#endif /* DIALOG_H_included */
900