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