aboutsummaryrefslogtreecommitdiff
path: root/dialog.c
diff options
context:
space:
mode:
Diffstat (limited to 'dialog.c')
-rw-r--r--dialog.c200
1 files changed, 169 insertions, 31 deletions
diff --git a/dialog.c b/dialog.c
index 249eaaca918a..ff803f94fea2 100644
--- a/dialog.c
+++ b/dialog.c
@@ -1,9 +1,9 @@
/*
- * $Id: dialog.c,v 1.202 2012/07/01 20:20:39 tom Exp $
+ * $Id: dialog.c,v 1.230 2013/03/15 09:07:30 tom Exp $
*
* cdialog - Display simple dialog boxes from shell scripts
*
- * Copyright 2000-2011,2012 Thomas E. Dickey
+ * Copyright 2000-2012,2013 Thomas E. Dickey
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License, version 2.1
@@ -48,7 +48,6 @@ typedef enum {
,o_beep
,o_beep_after
,o_begin
- ,o_calendar
,o_cancel_label
,o_checklist
,o_clear
@@ -60,15 +59,11 @@ typedef enum {
,o_default_button
,o_default_item
,o_defaultno
- ,o_dselect
- ,o_editbox
,o_exit_label
,o_extra_button
,o_extra_label
,o_fixed_font
,o_form
- ,o_fselect
- ,o_fullbutton
,o_gauge
,o_help
,o_help_button
@@ -87,6 +82,7 @@ typedef enum {
,o_keep_colors
,o_keep_tite
,o_keep_window
+ ,o_last_key
,o_max_input
,o_menu
,o_mixedform
@@ -102,7 +98,6 @@ typedef enum {
,o_no_nl_expand
,o_no_shadow
,o_nocancel
- ,o_noitem
,o_nook
,o_ok_label
,o_output_fd
@@ -136,7 +131,6 @@ typedef enum {
,o_tailboxbg
,o_textbox
,o_time_format
- ,o_timebox
,o_timeout
,o_title
,o_trim
@@ -146,6 +140,26 @@ typedef enum {
,o_wmclass
,o_yes_label
,o_yesno
+#ifdef HAVE_WHIPTAIL
+ ,o_fullbutton
+ ,o_topleft
+#endif
+#ifdef HAVE_XDIALOG
+ ,o_calendar
+ ,o_dselect
+ ,o_editbox
+ ,o_fselect
+ ,o_timebox
+#endif
+#ifdef HAVE_XDIALOG2
+ ,o_buildlist
+ ,o_rangebox
+ ,o_treeview
+#endif
+#if defined(HAVE_XDIALOG2) || defined(HAVE_WHIPTAIL)
+ ,o_no_items
+ ,o_no_tags
+#endif
#ifdef HAVE_DLG_TRACE
,o_trace
#endif
@@ -190,10 +204,9 @@ static const Options options[] = {
{ "aspect", o_aspect, 1, "<ratio>" },
{ "auto-placement", o_auto_placement, 1, NULL },
{ "backtitle", o_backtitle, 1, "<backtitle>" },
- { "beep", o_beep, 1, NULL },
- { "beep-after", o_beep_after, 1, NULL },
+ { "beep", o_beep, 1, "" },
+ { "beep-after", o_beep_after, 1, "" },
{ "begin", o_begin, 1, "<y> <x>" },
- { "calendar", o_calendar, 2, "<text> <height> <width> <day> <month> <year>" },
{ "cancel-label", o_cancel_label, 1, "<str>" },
{ "checklist", o_checklist, 2, "<text> <height> <width> <list height> <tag1> <item1> <status1>..." },
{ "clear", o_clear, 1, "" },
@@ -205,16 +218,11 @@ static const Options options[] = {
{ "default-button", o_default_button, 1, "<str>" },
{ "default-item", o_default_item, 1, "<str>" },
{ "defaultno", o_defaultno, 1, "" },
- { "dselect", o_dselect, 2, "<directory> <height> <width>" },
- { "editbox", o_editbox, 2, "<file> <height> <width>" },
{ "exit-label", o_exit_label, 1, "<str>" },
{ "extra-button", o_extra_button, 1, "" },
{ "extra-label", o_extra_label, 1, "<str>" },
- { "fb", o_fullbutton, 1, NULL },
{ "fixed-font", o_fixed_font, 1, NULL },
{ "form", o_form, 2, "<text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1>..." },
- { "fselect", o_fselect, 2, "<filepath> <height> <width>" },
- { "fullbutton", o_fullbutton, 1, NULL },
{ "gauge", o_gauge, 2, "<text> <height> <width> [<percent>]" },
{ "guage", o_gauge, 2, NULL },
{ "help", o_help, 4, "" },
@@ -234,6 +242,7 @@ static const Options options[] = {
{ "keep-colors", o_keep_colors, 1, NULL },
{ "keep-tite", o_keep_tite, 1, "" },
{ "keep-window", o_keep_window, 1, "" },
+ { "last-key", o_last_key, 1, "" },
{ "max-input", o_max_input, 1, "<n>" },
{ "menu", o_menu, 2, "<text> <height> <width> <menu height> <tag1> <item1>..." },
{ "mixedform", o_mixedform, 2, "<text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1> <itype>..." },
@@ -242,7 +251,7 @@ static const Options options[] = {
{ "no-cancel", o_nocancel, 1, "" },
{ "no-close", o_no_close, 1, NULL },
{ "no-collapse", o_no_collapse, 1, "" },
- { "no-cr-wrap", o_no_cr_wrap, 1, NULL },
+ { "no-cr-wrap", o_no_cr_wrap, 1, "" },
{ "no-kill", o_no_kill, 1, "" },
{ "no-label", o_no_label, 1, "<str>" },
{ "no-lines", o_no_lines, 1, "" },
@@ -251,7 +260,6 @@ static const Options options[] = {
{ "no-ok", o_nook, 1, "" },
{ "no-shadow", o_no_shadow, 1, "" },
{ "nocancel", o_nocancel, 1, NULL }, /* see --no-cancel */
- { "noitem", o_noitem, 1, NULL },
{ "nook", o_nook, 1, "" }, /* See no-ok */
{ "ok-label", o_ok_label, 1, "<str>" },
{ "output-fd", o_output_fd, 1, "<fd>" },
@@ -285,7 +293,6 @@ static const Options options[] = {
{ "tailboxbg", o_tailboxbg, 2, "<file> <height> <width>" },
{ "textbox", o_textbox, 2, "<file> <height> <width>" },
{ "time-format", o_time_format, 1, "<str>" },
- { "timebox", o_timebox, 2, "<text> <height> <width> <hour> <minute> <second>" },
{ "timeout", o_timeout, 1, "<secs>" },
{ "title", o_title, 1, "<title>" },
{ "trim", o_trim, 1, "" },
@@ -295,6 +302,34 @@ static const Options options[] = {
{ "wmclass", o_wmclass, 1, NULL },
{ "yes-label", o_yes_label, 1, "<str>" },
{ "yesno", o_yesno, 2, "<text> <height> <width>" },
+#ifdef HAVE_WHIPTAIL
+ { "cancel-button", o_cancel_label, 1, NULL },
+ { "fb", o_fullbutton, 1, NULL },
+ { "fullbutton", o_fullbutton, 1, NULL },
+ { "no-button", o_no_label, 1, NULL },
+ { "ok-button", o_ok_label, 1, NULL },
+ { "scrolltext", o_scrollbar, 1, NULL },
+ { "topleft", o_topleft, 1, NULL },
+ { "yes-button", o_yes_label, 1, NULL },
+#endif
+#ifdef HAVE_XDIALOG
+ { "calendar", o_calendar, 2, "<text> <height> <width> <day> <month> <year>" },
+ { "dselect", o_dselect, 2, "<directory> <height> <width>" },
+ { "editbox", o_editbox, 2, "<file> <height> <width>" },
+ { "fselect", o_fselect, 2, "<filepath> <height> <width>" },
+ { "timebox", o_timebox, 2, "<text> <height> <width> <hour> <minute> <second>" },
+#endif
+#ifdef HAVE_XDIALOG2
+ { "buildlist", o_buildlist, 2, "<text> <height> <width> <tag1> <item1> <status1>..." },
+ { "no-items", o_no_items, 1, "" },
+ { "no-tags", o_no_tags, 1, "" },
+ { "rangebox", o_rangebox, 2, "<text> <height> <width> <min-value> <max-value> <default-value>" },
+ { "treeview", o_treeview, 2, "<text> <height> <width> <list-height> <tag1> <item1> <status1> <depth1>..." },
+#endif
+#if defined(HAVE_XDIALOG2) || defined(HAVE_WHIPTAIL)
+ { "noitem", o_no_items, 1, NULL },
+ { "notags", o_no_tags, 1, NULL },
+#endif
#ifdef HAVE_DLG_TRACE
{ "trace", o_trace, 1, "<file>" },
#endif
@@ -537,13 +572,17 @@ howmany_tags(char *argv[], int group)
static int
numeric_arg(char **av, int n)
{
- char *last = 0;
- int result = (int) strtol(av[n], &last, 10);
- char msg[80];
+ int result = 0;
- if (last == 0 || *last != 0) {
- sprintf(msg, "Expected a number for token %d of %.20s", n, av[0]);
- Usage(msg);
+ if (n < dlg_count_argv(av)) {
+ char msg[80];
+ char *last = 0;
+ result = (int) strtol(av[n], &last, 10);
+
+ if (last == 0 || *last != 0) {
+ sprintf(msg, "Expected a number for token %d of %.20s", n, av[0]);
+ Usage(msg);
+ }
}
return result;
}
@@ -803,6 +842,75 @@ call_timebox(CALLARGS)
}
#endif /* HAVE_XDIALOG */
+/* dialog 1.2 widgets */
+#ifdef HAVE_XDIALOG2
+
+#define DisableNoTags() \
+ bool save_no_tags = dialog_vars.no_tags; \
+ bool save_no_items = dialog_vars.no_items; \
+ dialog_vars.no_tags = TRUE; \
+ dialog_vars.no_items = FALSE
+
+#define RestoreNoTags() \
+ dialog_vars.no_tags = save_no_tags; \
+ dialog_vars.no_items = save_no_items
+
+static int
+call_buildlist(CALLARGS)
+{
+ int tags = howmany_tags(av + 5, CHECKBOX_TAGS);
+ int result;
+
+ DisableNoTags();
+
+ *offset_add = 5 + tags * CHECKBOX_TAGS;
+ result = dialog_buildlist(t,
+ av[1],
+ numeric_arg(av, 2),
+ numeric_arg(av, 3),
+ numeric_arg(av, 4),
+ tags, av + 5,
+ TRUE);
+ RestoreNoTags();
+ return result;
+}
+
+static int
+call_rangebox(CALLARGS)
+{
+ int min_value;
+
+ *offset_add = arg_rest(av);
+ min_value = numeric_arg(av, 4);
+ return dialog_rangebox(t,
+ av[1],
+ numeric_arg(av, 2),
+ numeric_arg(av, 3),
+ min_value,
+ numeric_arg(av, 5),
+ (*offset_add > 6) ? numeric_arg(av, 6) : min_value);
+}
+
+static int
+call_treeview(CALLARGS)
+{
+ int tags = howmany_tags(av + 5, TREEVIEW_TAGS);
+ int result;
+
+ DisableNoTags();
+
+ *offset_add = arg_rest(av);
+ result = dialog_treeview(t,
+ av[1],
+ numeric_arg(av, 2),
+ numeric_arg(av, 3),
+ numeric_arg(av, 4),
+ tags, av + 5, FLAG_RADIO);
+ RestoreNoTags();
+ return result;
+}
+#endif /* HAVE_XDIALOG */
+
#ifdef HAVE_DLG_FORMBOX
static int
call_form(CALLARGS)
@@ -1017,11 +1125,14 @@ static const Mode modes[] =
{o_tailboxbg, 4, 4, call_tailboxbg},
#endif
#ifdef HAVE_XDIALOG
+ {o_buildlist, 4, 0, call_buildlist},
{o_calendar, 4, 7, call_calendar},
{o_dselect, 4, 5, call_dselect},
{o_editbox, 4, 4, call_editbox},
{o_fselect, 4, 5, call_fselect},
+ {o_rangebox, 5, 7, call_rangebox},
{o_timebox, 4, 7, call_timebox},
+ {o_treeview, 4, 0, call_treeview},
#endif
};
/* *INDENT-ON* */
@@ -1163,7 +1274,7 @@ Help(void)
static const char *const tbl_1[] =
{
"cdialog (ComeOn Dialog!) version %s",
- "Copyright 2000-2011,2012 Thomas E. Dickey",
+ "Copyright 2000-2012,2013 Thomas E. Dickey",
"This is free software; see the source for copying conditions. There is NO",
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.",
"",
@@ -1239,14 +1350,17 @@ process_trace_option(char **argv, int *offset)
{
int j;
- if (dialog_state.trace_output == 0)
+ if (dialog_state.trace_output == 0) {
dlg_trace(optionString(argv, offset));
+ } else {
+ dlg_trace_msg("# ignore extra --trace option\n");
+ *offset += 1;
+ }
dlg_trace_msg("# Parameters:\n");
for (j = 0; argv[j] != 0; ++j) {
dlg_trace_msg("# argv[%d] = %s\n", j, argv[j]);
}
- *offset += 1;
}
#endif
@@ -1357,6 +1471,9 @@ process_common_options(int argc, char **argv, int offset, bool output)
case o_keep_window:
dialog_vars.keep_window = TRUE;
break;
+ case o_last_key:
+ dialog_vars.last_key = TRUE;
+ break;
case o_no_shadow:
dialog_state.use_shadow = FALSE;
break;
@@ -1410,6 +1527,7 @@ process_common_options(int argc, char **argv, int offset, bool output)
break;
case o_visit_items:
dialog_state.visit_items = TRUE;
+ dialog_state.visit_cols = 1;
break;
case o_aspect:
dialog_state.aspect_ratio = optionValue(argv, &offset);
@@ -1464,10 +1582,16 @@ process_common_options(int argc, char **argv, int offset, bool output)
dialog_state.no_mouse = TRUE;
mouse_close();
break;
- case o_noitem:
+#ifdef HAVE_WHIPTAIL
+ case o_topleft:
+ dialog_vars.begin_set = TRUE;
+ dialog_vars.begin_y = 0;
+ dialog_vars.begin_x = 0;
+ break;
case o_fullbutton:
/* ignore */
break;
+#endif
/* options of Xdialog which we ignore */
case o_icon:
case o_wmclass:
@@ -1495,6 +1619,14 @@ process_common_options(int argc, char **argv, int offset, bool output)
process_trace_option(argv, &offset);
break;
#endif
+#if defined(HAVE_XDIALOG2) || defined(HAVE_WHIPTAIL)
+ case o_no_items:
+ dialog_vars.no_items = TRUE;
+ break;
+ case o_no_tags:
+ dialog_vars.no_tags = TRUE;
+ break;
+#endif
}
if (!done)
offset++;
@@ -1773,7 +1905,13 @@ main(int argc, char *argv[])
break;
default:
if (argv[j] != 0) {
- dlg_trim_string(argv[j]);
+ char *argv_j = strdup(argv[j]);
+ if (argv_j != 0) {
+ dlg_trim_string(argv_j);
+ argv[j] = argv_j;
+ } else {
+ argv[j] = strdup("?");
+ }
}
break;
}