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