dialog.h revision 220749
1/*
2 *  $Id: dialog.h,v 1.223 2011/03/02 10:04:09 tom Exp $
3 *
4 *  dialog.h -- common declarations for all dialog modules
5 *
6 *  Copyright 2000-2010,2011	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#undef ERR		/* header conflict with Solaris xpg4 */
48
49#if defined(HAVE_NCURSESW_NCURSES_H)
50#include <ncursesw/ncurses.h>
51#elif defined(HAVE_NCURSES_NCURSES_H)
52#include <ncurses/ncurses.h>
53#elif defined(HAVE_NCURSES_CURSES_H)
54#include <ncurses/curses.h>
55#elif defined(HAVE_NCURSES_H)
56#include <ncurses.h>
57#else
58#include <curses.h>
59#endif
60
61/* most curses.h headers include this, some do not */
62#if defined(HAVE_UNCTRL_H)
63#include <unctrl.h>
64#endif
65
66/* Solaris xpg4 renames these */
67#ifndef KEY_MAX
68#ifdef __KEY_MAX
69#define KEY_MAX __KEY_MAX
70#endif
71#endif
72
73#ifndef KEY_MIN
74#ifdef __KEY_MIN
75#define KEY_MIN __KEY_MIN
76#endif
77#endif
78
79/* possible conflicts with <term.h> which may be included in <curses.h> */
80#ifdef color_names
81#undef color_names
82#endif
83
84#ifdef buttons
85#undef buttons
86#endif
87
88#ifdef ENABLE_NLS
89#include <libintl.h>
90#include <langinfo.h>
91#define _(s) dgettext(PACKAGE, s)
92#else
93#undef _
94#define _(s) s
95#endif
96
97#ifndef GCC_NORETURN
98#define GCC_NORETURN /*nothing*/
99#endif
100
101#ifndef GCC_UNUSED
102#define GCC_UNUSED /*nothing*/
103#endif
104
105#ifndef HAVE_WGET_WCH
106#undef USE_WIDE_CURSES
107#endif
108
109/*
110 * FIXME: a configure check would be useful
111 */
112#ifdef __hpux
113#undef ACS_UARROW
114#undef ACS_DARROW
115#undef ACS_BLOCK
116#endif
117
118/*
119 * Change these if you want
120 */
121#define USE_SHADOW TRUE
122#define USE_COLORS TRUE
123
124#ifdef HAVE_COLOR
125#define SCOLS	(COLS - (dialog_state.use_shadow ? 2 : 0))
126#define SLINES	(LINES - (dialog_state.use_shadow ? 1 : 0))
127#else
128#define SCOLS	COLS
129#define SLINES	LINES
130#endif
131
132#define DLG_EXIT_ESC		255
133#define DLG_EXIT_UNKNOWN	-2	/* never return this (internal use) */
134#define DLG_EXIT_ERROR		-1	/* the shell sees this as 255 */
135#define DLG_EXIT_OK		0
136#define DLG_EXIT_CANCEL		1
137#define DLG_EXIT_HELP		2
138#define DLG_EXIT_EXTRA		3
139#define DLG_EXIT_ITEM_HELP	4	/* actually DLG_EXIT_HELP */
140
141#define DLG_CTRL(n)	((n) & 0x1f)	/* CTRL is preferred, but conflicts */
142
143#define CHR_BACKSPACE	DLG_CTRL('H')
144#define CHR_REPAINT	DLG_CTRL('L')
145#define CHR_KILL	DLG_CTRL('U')
146#define CHR_LITERAL	DLG_CTRL('V')
147#define CHR_DELETE	127
148#define CHR_NEXT	DLG_CTRL('N')
149#define CHR_PREVIOUS	DLG_CTRL('P')
150#define CHR_TRACE	DLG_CTRL('T')
151
152#define ESC		27
153#define TAB		DLG_CTRL('I')
154
155#define MARGIN 1
156#define GUTTER 2
157#define SHADOW_ROWS 1
158#define SHADOW_COLS 2
159#define ARROWS_COL  5
160
161#define MAX_LEN 2048
162#define BUF_SIZE (10L*1024)
163
164#undef  MIN
165#define MIN(x,y) ((x) < (y) ? (x) : (y))
166
167#undef  MAX
168#define MAX(x,y) ((x) > (y) ? (x) : (y))
169
170#define DEFAULT_SEPARATE_STR "\t"
171#define DEFAULT_ASPECT_RATIO 9
172/* how many spaces is a tab long (default)? */
173#define TAB_LEN 8
174#define WTIMEOUT_VAL        10	/* minimum amount of time needed for curses */
175
176#ifndef A_CHARTEXT
177#define A_CHARTEXT 0xff
178#endif
179
180#define CharOf(ch)  ((ch) & 0xff)
181
182#ifndef ACS_ULCORNER
183#define ACS_ULCORNER '+'
184#endif
185#ifndef ACS_LLCORNER
186#define ACS_LLCORNER '+'
187#endif
188#ifndef ACS_URCORNER
189#define ACS_URCORNER '+'
190#endif
191#ifndef ACS_LRCORNER
192#define ACS_LRCORNER '+'
193#endif
194#ifndef ACS_HLINE
195#define ACS_HLINE '-'
196#endif
197#ifndef ACS_VLINE
198#define ACS_VLINE '|'
199#endif
200#ifndef ACS_LTEE
201#define ACS_LTEE '+'
202#endif
203#ifndef ACS_RTEE
204#define ACS_RTEE '+'
205#endif
206#ifndef ACS_UARROW
207#define ACS_UARROW '^'
208#endif
209#ifndef ACS_DARROW
210#define ACS_DARROW 'v'
211#endif
212#ifndef ACS_BLOCK
213#define ACS_BLOCK '#'
214#endif
215
216/* these definitions may work for antique versions of curses */
217#ifndef HAVE_GETBEGYX
218#undef  getbegyx
219#define getbegyx(win,y,x)	(y = (win)?(win)->_begy:ERR, x = (win)?(win)->_begx:ERR)
220#endif
221
222#ifndef HAVE_GETMAXYX
223#undef  getmaxyx
224#define getmaxyx(win,y,x)	(y = (win)?(win)->_maxy:ERR, x = (win)?(win)->_maxx:ERR)
225#endif
226
227#ifndef HAVE_GETPARYX
228#undef  getparyx
229#define getparyx(win,y,x)	(y = (win)?(win)->_pary:ERR, x = (win)?(win)->_parx:ERR)
230#endif
231
232#ifdef __cplusplus
233extern "C" {
234#endif
235
236/* these definitions may be needed for bleeding-edge curses implementations */
237#if !(defined(HAVE_GETBEGX) && defined(HAVE_GETBEGY))
238#undef getbegx
239#undef getbegy
240#define getbegx(win) dlg_getbegx(win)
241#define getbegy(win) dlg_getbegy(win)
242extern int dlg_getbegx(WINDOW * /*win*/);
243extern int dlg_getbegy(WINDOW * /*win*/);
244#endif
245
246#if !(defined(HAVE_GETCURX) && defined(HAVE_GETCURY))
247#undef getcurx
248#undef getcury
249#define getcurx(win) dlg_getcurx(win)
250#define getcury(win) dlg_getcury(win)
251extern int dlg_getcurx(WINDOW * /*win*/);
252extern int dlg_getcury(WINDOW * /*win*/);
253#endif
254
255#if !(defined(HAVE_GETMAXX) && defined(HAVE_GETMAXY))
256#undef getmaxx
257#undef getmaxy
258#define getmaxx(win) dlg_getmaxx(win)
259#define getmaxy(win) dlg_getmaxy(win)
260extern int dlg_getmaxx(WINDOW * /*win*/);
261extern int dlg_getmaxy(WINDOW * /*win*/);
262#endif
263
264#if !(defined(HAVE_GETPARX) && defined(HAVE_GETPARY))
265#undef getparx
266#undef getpary
267#define getparx(win) dlg_getparx(win)
268#define getpary(win) dlg_getpary(win)
269extern int dlg_getparx(WINDOW * /*win*/);
270extern int dlg_getpary(WINDOW * /*win*/);
271#endif
272
273/*
274 * This is a list of "old" names, which should be helpful in updating
275 * applications that use libdialog.  Starting with 2003/11/26, all exported
276 * symbols from libdialog have "dlg_" prefix, or "dialog_" prefix or "_dialog"
277 * suffix (or suffix "_dialog", e.g., init_dialog).
278 */
279#ifdef __DIALOG_OLD_NAMES__
280#define color_table                       dlg_color_table
281#define attr_clear(win,h,w,a)             dlg_attr_clear(win,h,w,a)
282#define auto_size(t,s,h,w,xl,mc)          dlg_auto_size(t,s,h,w,xl,mc)
283#define auto_sizefile(t,f,h,w,xl,mc)      dlg_auto_sizefile(t,f,h,w,xl,mc)
284#define beeping()                         dlg_beeping()
285#define box_x_ordinate(w)                 dlg_box_x_ordinate(w)
286#define box_y_ordinate(h)                 dlg_box_y_ordinate(h)
287#define calc_listh(h,lh,in)               dlg_calc_listh(h,lh,in)
288#define calc_listw(in,items,group)        dlg_calc_listw(in,items,group)
289#define color_setup()                     dlg_color_setup()
290#define create_rc(f)                      dlg_create_rc(f)
291#define ctl_size(h,w)                     dlg_ctl_size(h,w)
292#define del_window(win)                   dlg_del_window(win)
293#define dialog_clear()                    dlg_clear()
294#define draw_bottom_box(win)              dlg_draw_bottom_box(win)
295#define draw_box(win,y,x,h,w,xc,bc)       dlg_draw_box(win,y,x,h,w,xc,bc)
296#define draw_shadow(win,h,w,y,x)          dlg_draw_shadow(win,h,w,y,x)
297#define draw_title(win,t)                 dlg_draw_title(win,t)
298#define exiterr                           dlg_exiterr
299#define killall_bg(n)                     dlg_killall_bg(n)
300#define mouse_bigregion(y,x)              dlg_mouse_bigregion(y,x)
301#define mouse_free_regions()              dlg_mouse_free_regions()
302#define mouse_mkbigregion(y,x,h,w,n,ix,iy,m) dlg_mouse_mkbigregion(y,x,h,w,n,ix,iy,m)
303#define mouse_mkregion(y,x,h,w,n)         dlg_mouse_mkregion(y,x,h,w,n)
304#define mouse_region(y,x)                 dlg_mouse_region(y,x)
305#define mouse_setbase(x,y)                dlg_mouse_setbase(x,y)
306#define mouse_wgetch(w,c)                 dlg_mouse_wgetch(w,c)
307#define new_window(h,w,y,x)               dlg_new_window(h,w,y,x)
308#define parse_rc()                        dlg_parse_rc()
309#define print_autowrap(win,s,h,w)         dlg_print_autowrap(win,s,h,w)
310#define print_size(h,w)                   dlg_print_size(h,w)
311#define put_backtitle()                   dlg_put_backtitle()
312#define strclone(cprompt)                 dlg_strclone(cprompt)
313#define sub_window(win,h,w,y,x)           dlg_sub_window(win,h,w,y,x)
314#define tab_correct_str(s)                dlg_tab_correct_str(s)
315#endif
316
317/*
318 * Attribute names
319 */
320#define DIALOG_ATR(n)                 dlg_color_table[n].atr
321
322#define screen_attr                   DIALOG_ATR(0)
323#define shadow_attr                   DIALOG_ATR(1)
324#define dialog_attr                   DIALOG_ATR(2)
325#define title_attr                    DIALOG_ATR(3)
326#define border_attr                   DIALOG_ATR(4)
327#define button_active_attr            DIALOG_ATR(5)
328#define button_inactive_attr          DIALOG_ATR(6)
329#define button_key_active_attr        DIALOG_ATR(7)
330#define button_key_inactive_attr      DIALOG_ATR(8)
331#define button_label_active_attr      DIALOG_ATR(9)
332#define button_label_inactive_attr    DIALOG_ATR(10)
333#define inputbox_attr                 DIALOG_ATR(11)
334#define inputbox_border_attr          DIALOG_ATR(12)
335#define searchbox_attr                DIALOG_ATR(13)
336#define searchbox_title_attr          DIALOG_ATR(14)
337#define searchbox_border_attr         DIALOG_ATR(15)
338#define position_indicator_attr       DIALOG_ATR(16)
339#define menubox_attr                  DIALOG_ATR(17)
340#define menubox_border_attr           DIALOG_ATR(18)
341#define item_attr                     DIALOG_ATR(19)
342#define item_selected_attr            DIALOG_ATR(20)
343#define tag_attr                      DIALOG_ATR(21)
344#define tag_selected_attr             DIALOG_ATR(22)
345#define tag_key_attr                  DIALOG_ATR(23)
346#define tag_key_selected_attr         DIALOG_ATR(24)
347#define check_attr                    DIALOG_ATR(25)
348#define check_selected_attr           DIALOG_ATR(26)
349#define uarrow_attr                   DIALOG_ATR(27)
350#define darrow_attr                   DIALOG_ATR(28)
351#define itemhelp_attr                 DIALOG_ATR(29)
352#define form_active_text_attr         DIALOG_ATR(30)
353#define form_text_attr                DIALOG_ATR(31)
354#define form_item_readonly_attr       DIALOG_ATR(32)
355#define gauge_attr                    DIALOG_ATR(33)
356
357#define DLGK_max (KEY_MAX + 256)
358
359/*
360 * Callbacks are used to implement the "background" tailbox.
361 */
362struct _dlg_callback;
363
364typedef void (*DIALOG_FREEBACK) (struct _dlg_callback * /* p */);
365
366typedef struct _dlg_callback {
367    struct _dlg_callback *next;
368    FILE *input;
369    WINDOW *win;
370    bool keep_bg;	/* keep in background, on exit */
371    bool bg_task;	/* true if this is background task */
372    bool (*handle_getc)(struct _dlg_callback *p, int ch, int fkey, int *result);
373    bool keep_win;	/* true to not erase window on exit */
374    /* data for dlg_add_callback_ref */
375    struct _dlg_callback **caller;
376    DIALOG_FREEBACK freeback;
377    /* 1.1-20110107 */
378    bool (*handle_input)(struct _dlg_callback *p);
379    bool input_ready;
380} DIALOG_CALLBACK;
381
382typedef 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