Merge branch '2115_input_dialog_buttons'

* 2115_input_dialog_buttons:
  Applied MC indentation policy.
  Ticket #2115: fixed button location in common input dialog.
This commit is contained in:
Andrew Borodin 2010-06-28 16:23:00 +04:00
commit 2e973fbbbd
2 changed files with 465 additions and 429 deletions

View File

@ -3,9 +3,9 @@
2005, 2006, 2007 Free Software Foundation, Inc. 2005, 2006, 2007 Free Software Foundation, Inc.
Authors: 1994, 1995, 1996 Miguel de Icaza Authors: 1994, 1995, 1996 Miguel de Icaza
1994, 1995 Radek Doulik 1994, 1995 Radek Doulik
1995 Jakub Jelinek 1995 Jakub Jelinek
1995 Andrej Borsenkow 1995 Andrej Borsenkow
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -35,26 +35,25 @@
#include "lib/global.h" #include "lib/global.h"
#include "lib/tty/tty.h" #include "lib/tty/tty.h"
#include "lib/tty/key.h" /* tty_getch() */ #include "lib/tty/key.h" /* tty_getch() */
#include "lib/skin.h" /* INPUT_COLOR */ #include "lib/skin.h" /* INPUT_COLOR */
#include "lib/strutil.h" #include "lib/strutil.h"
#include "dialog.h" #include "dialog.h"
#include "widget.h" #include "widget.h"
#include "wtools.h" #include "wtools.h"
#include "background.h" /* parent_call */ #include "background.h" /* parent_call */
Listbox * Listbox *
create_listbox_window_centered (int center_y, int center_x, int lines, int cols, create_listbox_window_centered (int center_y, int center_x, int lines, int cols,
const char *title, const char *help) const char *title, const char *help)
{ {
const int listbox_colors[DLG_COLOR_NUM] = const int listbox_colors[DLG_COLOR_NUM] = {
{ MENU_ENTRY_COLOR,
MENU_ENTRY_COLOR, MENU_SELECTED_COLOR,
MENU_SELECTED_COLOR, MENU_HOT_COLOR,
MENU_HOT_COLOR, MENU_HOTSEL_COLOR,
MENU_HOTSEL_COLOR,
}; };
const int space = 4; const int space = 4;
@ -65,41 +64,44 @@ create_listbox_window_centered (int center_y, int center_x, int lines, int cols,
/* Adjust sizes */ /* Adjust sizes */
lines = min (lines, LINES - 6); lines = min (lines, LINES - 6);
if (title != NULL) { if (title != NULL)
len = str_term_width1 (title) + 4; {
cols = max (cols, len); len = str_term_width1 (title) + 4;
cols = max (cols, len);
} }
cols = min (cols, COLS - 6); cols = min (cols, COLS - 6);
/* adjust position */ /* adjust position */
if ((center_y < 0) || (center_x < 0)) { if ((center_y < 0) || (center_x < 0))
ypos = LINES/2; {
xpos = COLS/2; ypos = LINES / 2;
} else { xpos = COLS / 2;
ypos = center_y; }
xpos = center_x; else
{
ypos = center_y;
xpos = center_x;
} }
ypos -= lines/2; ypos -= lines / 2;
xpos -= cols/2; xpos -= cols / 2;
if (ypos + lines >= LINES) if (ypos + lines >= LINES)
ypos = LINES - lines - space; ypos = LINES - lines - space;
if (ypos < 0) if (ypos < 0)
ypos = 0; ypos = 0;
if (xpos + cols >= COLS) if (xpos + cols >= COLS)
xpos = COLS - cols - space; xpos = COLS - cols - space;
if (xpos < 0) if (xpos < 0)
xpos = 0; xpos = 0;
listbox = g_new (Listbox, 1); listbox = g_new (Listbox, 1);
listbox->dlg = listbox->dlg =
create_dlg (TRUE, ypos, xpos, lines + space, cols + space, create_dlg (TRUE, ypos, xpos, lines + space, cols + space,
listbox_colors, NULL, listbox_colors, NULL, help, title, DLG_REVERSE | DLG_TRYUP);
help, title, DLG_REVERSE | DLG_TRYUP);
listbox->list = listbox_new (2, 2, lines, cols, FALSE, NULL); listbox->list = listbox_new (2, 2, lines, cols, FALSE, NULL);
add_widget (listbox->dlg, listbox->list); add_widget (listbox->dlg, listbox->list);
@ -115,12 +117,12 @@ create_listbox_window (int lines, int cols, const char *title, const char *help)
/* Returns the number of the item selected */ /* Returns the number of the item selected */
int int
run_listbox (Listbox *l) run_listbox (Listbox * l)
{ {
int val = -1; int val = -1;
if (run_dlg (l->dlg) != B_CANCEL) if (run_dlg (l->dlg) != B_CANCEL)
val = l->list->pos; val = l->list->pos;
destroy_dlg (l->dlg); destroy_dlg (l->dlg);
g_free (l); g_free (l);
return val; return val;
@ -128,22 +130,22 @@ run_listbox (Listbox *l)
/* default query callback, used to reposition query */ /* default query callback, used to reposition query */
static cb_ret_t static cb_ret_t
default_query_callback (Dlg_head *h, Widget *sender, default_query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
dlg_msg_t msg, int parm, void *data)
{ {
switch (msg) { switch (msg)
case DLG_RESIZE:
{ {
int xpos = COLS / 2 - h->cols / 2; case DLG_RESIZE:
int ypos = LINES / 3 - (h->lines - 3) / 2; {
int xpos = COLS / 2 - h->cols / 2;
int ypos = LINES / 3 - (h->lines - 3) / 2;
/* set position */ /* set position */
dlg_set_position (h, ypos, xpos, ypos + h->lines, xpos + h->cols); dlg_set_position (h, ypos, xpos, ypos + h->lines, xpos + h->cols);
} }
return MSG_HANDLED; return MSG_HANDLED;
default: default:
return default_dlg_callback (h, sender, msg, parm, data); return default_dlg_callback (h, sender, msg, parm, data);
} }
} }
@ -164,21 +166,22 @@ query_dialog (const char *header, const char *text, int flags, int count, ...)
int result = -1; int result = -1;
int cols, lines; int cols, lines;
char *cur_name; char *cur_name;
const int *query_colors = (flags & D_ERROR) ? const int *query_colors = (flags & D_ERROR) ? alarm_colors : dialog_colors;
alarm_colors : dialog_colors;
if (header == MSG_ERROR) if (header == MSG_ERROR)
header = _("Error"); header = _("Error");
if (count > 0) { if (count > 0)
va_start (ap, count); {
for (i = 0; i < count; i++) { va_start (ap, count);
char *cp = va_arg (ap, char *); for (i = 0; i < count; i++)
win_len += str_term_width1 (cp) + 6; {
if (strchr (cp, '&') != NULL) char *cp = va_arg (ap, char *);
win_len--; win_len += str_term_width1 (cp) + 6;
} if (strchr (cp, '&') != NULL)
va_end (ap); win_len--;
}
va_end (ap);
} }
/* count coordinates */ /* count coordinates */
@ -188,59 +191,62 @@ query_dialog (const char *header, const char *text, int flags, int count, ...)
/* prepare dialog */ /* prepare dialog */
query_dlg = query_dlg =
create_dlg (TRUE, 0, 0, lines, cols, query_colors, default_query_callback, create_dlg (TRUE, 0, 0, lines, cols, query_colors, default_query_callback,
"[QueryBox]", header, DLG_NONE); "[QueryBox]", header, DLG_NONE);
if (count > 0) { if (count > 0)
cols = (cols - win_len - 2) / 2 + 2; {
va_start (ap, count); cols = (cols - win_len - 2) / 2 + 2;
for (i = 0; i < count; i++) { va_start (ap, count);
int xpos; for (i = 0; i < count; i++)
{
int xpos;
cur_name = va_arg (ap, char *); cur_name = va_arg (ap, char *);
xpos = str_term_width1 (cur_name) + 6; xpos = str_term_width1 (cur_name) + 6;
if (strchr (cur_name, '&') != NULL) if (strchr (cur_name, '&') != NULL)
xpos--; xpos--;
button = button = button_new (lines - 3, cols, B_USER + i, NORMAL_BUTTON, cur_name, 0);
button_new (lines - 3, cols, B_USER + i, NORMAL_BUTTON, add_widget (query_dlg, button);
cur_name, 0); cols += xpos;
add_widget (query_dlg, button); if (i == sel_pos)
cols += xpos; defbutton = button;
if (i == sel_pos) }
defbutton = button; va_end (ap);
}
va_end (ap);
add_widget (query_dlg, label_new (2, 3, text)); add_widget (query_dlg, label_new (2, 3, text));
/* do resize before running and selecting any widget */ /* do resize before running and selecting any widget */
default_query_callback (query_dlg, NULL, DLG_RESIZE, 0, NULL); default_query_callback (query_dlg, NULL, DLG_RESIZE, 0, NULL);
if (defbutton) if (defbutton)
dlg_select_widget (defbutton); dlg_select_widget (defbutton);
/* run dialog and make result */ /* run dialog and make result */
switch (run_dlg (query_dlg)) { switch (run_dlg (query_dlg))
case B_CANCEL: {
break; case B_CANCEL:
default: break;
result = query_dlg->ret_value - B_USER; default:
} result = query_dlg->ret_value - B_USER;
}
/* free used memory */ /* free used memory */
destroy_dlg (query_dlg); destroy_dlg (query_dlg);
} else { }
add_widget (query_dlg, label_new (2, 3, text)); else
add_widget (query_dlg, {
button_new (0, 0, 0, HIDDEN_BUTTON, "-", 0)); add_widget (query_dlg, label_new (2, 3, text));
last_query_dlg = query_dlg; add_widget (query_dlg, button_new (0, 0, 0, HIDDEN_BUTTON, "-", 0));
last_query_dlg = query_dlg;
} }
sel_pos = 0; sel_pos = 0;
return result; return result;
} }
void query_set_sel (int new_sel) void
query_set_sel (int new_sel)
{ {
sel_pos = new_sel; sel_pos = new_sel;
} }
@ -316,7 +322,7 @@ bg_message (int dummy, int *flags, char *title, const char *text)
fg_message (*flags, title, text); fg_message (*flags, title, text);
g_free (title); g_free (title);
} }
#endif /* WITH_BACKGROUND */ #endif /* WITH_BACKGROUND */
/* Show message box, background safe */ /* Show message box, background safe */
@ -325,9 +331,10 @@ message (int flags, const char *title, const char *text, ...)
{ {
char *p; char *p;
va_list ap; va_list ap;
union { union
void *p; {
void (*f) (int, int *, char *, const char *); void *p;
void (*f) (int, int *, char *, const char *);
} func; } func;
va_start (ap, text); va_start (ap, text);
@ -335,16 +342,17 @@ message (int flags, const char *title, const char *text, ...)
va_end (ap); va_end (ap);
if (title == MSG_ERROR) if (title == MSG_ERROR)
title = _("Error"); title = _("Error");
#ifdef WITH_BACKGROUND #ifdef WITH_BACKGROUND
if (we_are_background) { if (we_are_background)
func.f = bg_message; {
parent_call (func.p, NULL, 3, sizeof (flags), &flags, func.f = bg_message;
strlen (title), title, strlen (p), p); parent_call (func.p, NULL, 3, sizeof (flags), &flags, strlen (title), title, strlen (p), p);
} else }
#endif /* WITH_BACKGROUND */ else
fg_message (flags, title, p); #endif /* WITH_BACKGROUND */
fg_message (flags, title, p);
g_free (p); g_free (p);
} }
@ -354,7 +362,7 @@ message (int flags, const char *title, const char *text, ...)
int int
quick_dialog_skip (QuickDialog *qd, int nskip) quick_dialog_skip (QuickDialog * qd, int nskip)
{ {
#ifdef ENABLE_NLS #ifdef ENABLE_NLS
#define I18N(x) (x = !qd->i18n && x && *x ? _(x): x) #define I18N(x) (x = !qd->i18n && x && *x ? _(x): x)
@ -367,8 +375,7 @@ quick_dialog_skip (QuickDialog *qd, int nskip)
WRadio *r; WRadio *r;
int return_val; int return_val;
const int input_colors[3] = const int input_colors[3] = {
{
INPUT_COLOR, INPUT_COLOR,
INPUT_UNCHANGED_COLOR, INPUT_UNCHANGED_COLOR,
INPUT_MARK_COLOR INPUT_MARK_COLOR
@ -377,113 +384,120 @@ quick_dialog_skip (QuickDialog *qd, int nskip)
I18N (qd->title); I18N (qd->title);
if ((qd->xpos == -1) || (qd->ypos == -1)) if ((qd->xpos == -1) || (qd->ypos == -1))
dd = create_dlg (TRUE, 0, 0, qd->ylen, qd->xlen, dd = create_dlg (TRUE, 0, 0, qd->ylen, qd->xlen,
dialog_colors, NULL, qd->help, qd->title, dialog_colors, NULL, qd->help, qd->title,
DLG_CENTER | DLG_TRYUP | DLG_REVERSE); DLG_CENTER | DLG_TRYUP | DLG_REVERSE);
else else
dd = create_dlg (TRUE, qd->ypos, qd->xpos, qd->ylen, qd->xlen, dd = create_dlg (TRUE, qd->ypos, qd->xpos, qd->ylen, qd->xlen,
dialog_colors, NULL, qd->help, qd->title, dialog_colors, NULL, qd->help, qd->title, DLG_REVERSE);
DLG_REVERSE);
for (qw = qd->widgets; qw->widget_type != quick_end; qw++) { for (qw = qd->widgets; qw->widget_type != quick_end; qw++)
int xpos; {
int ypos; int xpos;
int ypos;
xpos = (qd->xlen * qw->relative_x) / qw->x_divisions; xpos = (qd->xlen * qw->relative_x) / qw->x_divisions;
ypos = (qd->ylen * qw->relative_y) / qw->y_divisions; ypos = (qd->ylen * qw->relative_y) / qw->y_divisions;
switch (qw->widget_type) { switch (qw->widget_type)
case quick_checkbox: {
qw->widget = (Widget *) check_new (ypos, xpos, *qw->u.checkbox.state, I18N (qw->u.checkbox.text)); case quick_checkbox:
break; qw->widget =
(Widget *) check_new (ypos, xpos, *qw->u.checkbox.state,
case quick_button: I18N (qw->u.checkbox.text));
qw->widget = (Widget *) button_new (ypos, xpos, qw->u.button.action,
(qw->u.button.action == B_ENTER) ? DEFPUSH_BUTTON : NORMAL_BUTTON,
I18N (qw->u.button.text), qw->u.button.callback);
break;
case quick_input:
in = input_new (ypos, xpos, (int *) input_colors,
qw->u.input.len, qw->u.input.text, qw->u.input.histname,
INPUT_COMPLETE_DEFAULT);
in->is_password = (qw->u.input.flags == 1);
if ((qw->u.input.flags & 2) != 0)
in->completion_flags |= INPUT_COMPLETE_CD;
qw->widget = (Widget *) in;
*qw->u.input.result = NULL;
break;
case quick_label:
qw->widget = (Widget *) label_new (ypos, xpos, I18N (qw->u.label.text));
break;
case quick_groupbox:
qw->widget = (Widget *) groupbox_new (ypos, xpos,
qw->u.groupbox.height,
qw->u.groupbox.width,
I18N (qw->u.groupbox.title));
break; break;
case quick_radio: case quick_button:
{ qw->widget = (Widget *) button_new (ypos, xpos, qw->u.button.action,
int i; (qw->u.button.action ==
char **items = NULL; B_ENTER) ? DEFPUSH_BUTTON : NORMAL_BUTTON,
I18N (qw->u.button.text), qw->u.button.callback);
break;
/* create the copy of radio_items to avoid mwmory leak */ case quick_input:
items = g_new0 (char *, qw->u.radio.count + 1); in = input_new (ypos, xpos, (int *) input_colors,
qw->u.input.len, qw->u.input.text, qw->u.input.histname,
INPUT_COMPLETE_DEFAULT);
in->is_password = (qw->u.input.flags == 1);
if ((qw->u.input.flags & 2) != 0)
in->completion_flags |= INPUT_COMPLETE_CD;
qw->widget = (Widget *) in;
*qw->u.input.result = NULL;
break;
if (!qd->i18n) case quick_label:
for (i = 0; i < qw->u.radio.count; i++) qw->widget = (Widget *) label_new (ypos, xpos, I18N (qw->u.label.text));
items[i] = g_strdup (_(qw->u.radio.items[i])); break;
else
for (i = 0; i < qw->u.radio.count; i++)
items[i] = g_strdup (qw->u.radio.items[i]);
r = radio_new (ypos, xpos, qw->u.radio.count, (const char **) items); case quick_groupbox:
r->pos = r->sel = *qw->u.radio.value; qw->widget = (Widget *) groupbox_new (ypos, xpos,
qw->widget = (Widget *) r; qw->u.groupbox.height,
g_strfreev (items); qw->u.groupbox.width,
break; I18N (qw->u.groupbox.title));
} break;
default: case quick_radio:
qw->widget = NULL; {
fprintf (stderr, "QuickWidget: unknown widget type\n"); int i;
break; char **items = NULL;
}
add_widget (dd, qw->widget); /* create the copy of radio_items to avoid mwmory leak */
items = g_new0 (char *, qw->u.radio.count + 1);
if (!qd->i18n)
for (i = 0; i < qw->u.radio.count; i++)
items[i] = g_strdup (_(qw->u.radio.items[i]));
else
for (i = 0; i < qw->u.radio.count; i++)
items[i] = g_strdup (qw->u.radio.items[i]);
r = radio_new (ypos, xpos, qw->u.radio.count, (const char **) items);
r->pos = r->sel = *qw->u.radio.value;
qw->widget = (Widget *) r;
g_strfreev (items);
break;
}
default:
qw->widget = NULL;
fprintf (stderr, "QuickWidget: unknown widget type\n");
break;
}
add_widget (dd, qw->widget);
} }
while (nskip-- != 0) while (nskip-- != 0)
dd->current = dd->current->next; dd->current = dd->current->next;
return_val = run_dlg (dd); return_val = run_dlg (dd);
/* Get the data if we found something interesting */ /* Get the data if we found something interesting */
if (return_val != B_CANCEL) { if (return_val != B_CANCEL)
for (qw = qd->widgets; qw->widget_type != quick_end; qw++) { {
switch (qw->widget_type) { for (qw = qd->widgets; qw->widget_type != quick_end; qw++)
case quick_checkbox: {
*qw->u.checkbox.state = ((WCheck *) qw->widget)->state & C_BOOL; switch (qw->widget_type)
break; {
case quick_checkbox:
*qw->u.checkbox.state = ((WCheck *) qw->widget)->state & C_BOOL;
break;
case quick_input: case quick_input:
if ((qw->u.input.flags & 2) != 0) if ((qw->u.input.flags & 2) != 0)
*qw->u.input.result = tilde_expand (((WInput *) qw->widget)->buffer); *qw->u.input.result = tilde_expand (((WInput *) qw->widget)->buffer);
else else
*qw->u.input.result = g_strdup (((WInput *) qw->widget)->buffer); *qw->u.input.result = g_strdup (((WInput *) qw->widget)->buffer);
break; break;
case quick_radio: case quick_radio:
*qw->u.radio.value = ((WRadio *) qw->widget)->sel; *qw->u.radio.value = ((WRadio *) qw->widget)->sel;
break; break;
default: default:
break; break;
} }
} }
} }
destroy_dlg (dd); destroy_dlg (dd);
@ -493,7 +507,7 @@ quick_dialog_skip (QuickDialog *qd, int nskip)
} }
int int
quick_dialog (QuickDialog *qd) quick_dialog (QuickDialog * qd)
{ {
return quick_dialog_skip (qd, 0); return quick_dialog_skip (qd, 0);
} }
@ -515,76 +529,85 @@ quick_dialog (QuickDialog *qd)
*/ */
static char * static char *
fg_input_dialog_help (const char *header, const char *text, const char *help, fg_input_dialog_help (const char *header, const char *text, const char *help,
const char *history_name, const char *def_text) const char *history_name, const char *def_text)
{ {
char *my_str; char *my_str;
QuickWidget quick_widgets[] = { QuickWidget quick_widgets[] = {
/* 0 */ QUICK_BUTTON (6, 10, 1, 0, N_("&Cancel"), B_CANCEL, NULL), /* 0 */ QUICK_BUTTON (6, 64, 1, 0, N_("&Cancel"), B_CANCEL, NULL),
/* 1 */ QUICK_BUTTON (3, 10, 1, 0, N_("&OK"), B_ENTER, NULL), /* 1 */ QUICK_BUTTON (3, 64, 1, 0, N_("&OK"), B_ENTER, NULL),
/* 2 */ QUICK_INPUT (3, 80, 0, 0, def_text, 58, 0, NULL, &my_str), /* 2 */ QUICK_INPUT (3, 64, 0, 0, def_text, 58, 0, NULL, &my_str),
/* 3 */ QUICK_LABEL (3, 80, 2, 0, ""), /* 3 */ QUICK_LABEL (3, 64, 2, 0, ""),
QUICK_END QUICK_END
}; };
char histname [64] = "inp|"; int b0_len, b1_len, b_len, gap;
char histname[64] = "inp|";
int lines, cols; int lines, cols;
int len; int len;
int i; int i;
char *p_text; char *p_text;
int ret; int ret;
if (history_name != NULL && *history_name != '\0') { /* buttons */
g_strlcpy (histname + 3, history_name, sizeof (histname) - 3); #ifdef ENABLE_NLS
quick_widgets[2].u.input.histname = histname; quick_widgets[0].u.button.text = _(quick_widgets[0].u.button.text);
} quick_widgets[1].u.button.text = _(quick_widgets[1].u.button.text);
#endif /* ENABLE_NLS */
msglen (text, &lines, &cols); b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
len = max (max (str_term_width1 (header), cols) + 4, 64); b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 5; /* default button */
b_len = b0_len + b1_len + 2; /* including gap */
/* input line */
if (history_name != NULL && *history_name != '\0')
{
g_strlcpy (histname + 3, history_name, sizeof (histname) - 3);
quick_widgets[2].u.input.histname = histname;
}
/* The special value of def_text is used to identify password boxes /* The special value of def_text is used to identify password boxes
and hide characters with "*". Don't save passwords in history! */ and hide characters with "*". Don't save passwords in history! */
if (def_text == INPUT_PASSWORD) { if (def_text == INPUT_PASSWORD)
quick_widgets[2].u.input.flags = 1; {
histname[3] = '\0'; quick_widgets[2].u.input.flags = 1;
quick_widgets[2].u.input.text = ""; histname[3] = '\0';
quick_widgets[2].u.input.text = "";
} }
#ifdef ENABLE_NLS /* text */
/*
* An attempt to place buttons symmetrically, based on actual i18n
* length of the string. It looks nicer with i18n (IMO) - alex
*/
quick_widgets[0].u.button.text = _(quick_widgets[0].u.button.text);
quick_widgets[1].u.button.text = _(quick_widgets[1].u.button.text);
quick_widgets[0].relative_x = len / 2 + 4;
quick_widgets[1].relative_x =
len / 2 - (str_term_width1 (quick_widgets[1].u.button.text) + 9);
quick_widgets[0].x_divisions = quick_widgets[1].x_divisions = len;
#endif /* ENABLE_NLS */
p_text = g_strstrip (g_strdup (text)); p_text = g_strstrip (g_strdup (text));
msglen (p_text, &lines, &cols);
quick_widgets[3].u.label.text = p_text; quick_widgets[3].u.label.text = p_text;
/* dialog width */
len = max (max (str_term_width1 (header), cols) + 4, 64);
len = min (max (len, b_len + 6), COLS);
/* button locations */
gap = (len - 8 - b_len) / 3;
quick_widgets[1].relative_x = 3 + gap;
quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + gap + 2;
{ {
QuickDialog Quick_input = QuickDialog Quick_input = {
{ len, lines + 6, -1, -1, header,
len, lines + 6, -1, -1, header, help, quick_widgets, TRUE
help, quick_widgets, TRUE };
};
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++)
quick_widgets[i].x_divisions = Quick_input.xlen; {
quick_widgets[i].y_divisions = Quick_input.ylen; quick_widgets[i].x_divisions = Quick_input.xlen;
} quick_widgets[i].y_divisions = Quick_input.ylen;
}
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
quick_widgets[i].relative_y += 2 + lines; quick_widgets[i].relative_y += 2 + lines;
/* input line length */ /* input line length */
quick_widgets[2].u.input.len = Quick_input.xlen - 6; quick_widgets[2].u.input.len = Quick_input.xlen - 6;
ret = quick_dialog (&Quick_input); ret = quick_dialog (&Quick_input);
} }
g_free (p_text); g_free (p_text);
@ -600,47 +623,48 @@ fg_input_dialog_help (const char *header, const char *text, const char *help,
*/ */
char * char *
input_dialog_help (const char *header, const char *text, const char *help, input_dialog_help (const char *header, const char *text, const char *help,
const char *history_name, const char *def_text) const char *history_name, const char *def_text)
{ {
union { union
void *p; {
char * (*f) (const char *, const char *, const char *, void *p;
const char *, const char *); char *(*f) (const char *, const char *, const char *, const char *, const char *);
} func; } func;
#ifdef WITH_BACKGROUND #ifdef WITH_BACKGROUND
if (we_are_background) if (we_are_background)
{ {
func.f = fg_input_dialog_help; func.f = fg_input_dialog_help;
return parent_call_string (func.p, 5, return parent_call_string (func.p, 5,
strlen (header), header, strlen (text), strlen (header), header, strlen (text),
text, strlen (help), help, text, strlen (help), help,
strlen (history_name), history_name, strlen (history_name), history_name,
strlen (def_text), def_text); strlen (def_text), def_text);
} }
else else
#endif /* WITH_BACKGROUND */ #endif /* WITH_BACKGROUND */
return fg_input_dialog_help (header, text, help, history_name, def_text); return fg_input_dialog_help (header, text, help, history_name, def_text);
} }
/* Show input dialog with default help, background safe */ /* Show input dialog with default help, background safe */
char *input_dialog (const char *header, const char *text, char *
const char *history_name, const char *def_text) input_dialog (const char *header, const char *text, const char *history_name, const char *def_text)
{ {
return input_dialog_help (header, text, "[Input Line Keys]", history_name, def_text); return input_dialog_help (header, text, "[Input Line Keys]", history_name, def_text);
} }
char * char *
input_expand_dialog (const char *header, const char *text, input_expand_dialog (const char *header, const char *text,
const char *history_name, const char *def_text) const char *history_name, const char *def_text)
{ {
char *result; char *result;
char *expanded; char *expanded;
result = input_dialog (header, text, history_name, def_text); result = input_dialog (header, text, history_name, def_text);
if (result) { if (result)
expanded = tilde_expand (result); {
g_free (result); expanded = tilde_expand (result);
return expanded; g_free (result);
return expanded;
} }
return result; return result;
} }
@ -649,7 +673,7 @@ input_expand_dialog (const char *header, const char *text,
/* }}} */ /* }}} */
/* /*
Cause emacs to enter folding mode for this file: Cause emacs to enter folding mode for this file:
Local variables: Local variables:
end: end:
*/ */

View File

@ -10,33 +10,36 @@
#include "dialog.h" #include "dialog.h"
#include "widget.h" #include "widget.h"
typedef struct { typedef struct
{
struct Dlg_head *dlg; struct Dlg_head *dlg;
struct WListbox *list; struct WListbox *list;
} Listbox; } Listbox;
/* Listbox utility functions */ /* Listbox utility functions */
Listbox *create_listbox_window_centered (int center_y, int center_x, int lines, int cols, Listbox *create_listbox_window_centered (int center_y, int center_x, int lines, int cols,
const char *title, const char *help); const char *title, const char *help);
Listbox *create_listbox_window (int lines, int cols, const char *title, const char *help); Listbox *create_listbox_window (int lines, int cols, const char *title, const char *help);
#define LISTBOX_APPEND_TEXT(l,h,t,d) \ #define LISTBOX_APPEND_TEXT(l,h,t,d) \
listbox_add_item (l->list, LISTBOX_APPEND_AT_END, h, t, d) listbox_add_item (l->list, LISTBOX_APPEND_AT_END, h, t, d)
int run_listbox (Listbox *l); int run_listbox (Listbox * l);
/* Quick Widgets */ /* Quick Widgets */
typedef enum { typedef enum
quick_end = 0, {
quick_checkbox = 1, quick_end = 0,
quick_button = 2, quick_checkbox = 1,
quick_input = 3, quick_button = 2,
quick_label = 4, quick_input = 3,
quick_radio = 5, quick_label = 4,
quick_groupbox = 6 quick_radio = 5,
quick_groupbox = 6
} quick_t; } quick_t;
/* The widget is placed on relative_?/divisions_? of the parent widget */ /* The widget is placed on relative_?/divisions_? of the parent widget */
typedef struct { typedef struct
{
quick_t widget_type; quick_t widget_type;
int relative_x; int relative_x;
@ -47,175 +50,184 @@ typedef struct {
Widget *widget; Widget *widget;
/* widget parameters */ /* widget parameters */
union { union
struct { {
const char *text; struct
int *state; /* in/out */ {
} checkbox; const char *text;
int *state; /* in/out */
} checkbox;
struct { struct
const char *text; {
int action; const char *text;
bcback callback; int action;
} button; bcback callback;
} button;
struct { struct
const char *text; {
int len; const char *text;
int flags; /* 1 -- is_password, 2 -- INPUT_COMPLETE_CD */ int len;
const char *histname; int flags; /* 1 -- is_password, 2 -- INPUT_COMPLETE_CD */
char **result; const char *histname;
} input; char **result;
} input;
struct { struct
const char *text; {
} label; const char *text;
} label;
struct { struct
int count; {
const char **items; int count;
int *value; /* in/out */ const char **items;
} radio; int *value; /* in/out */
} radio;
struct { struct
int width; {
int height; int width;
const char *title; int height;
} groupbox; const char *title;
} groupbox;
} u; } u;
} QuickWidget; } QuickWidget;
#define QUICK_CHECKBOX(x, xdiv, y, ydiv, txt, st) \ #define QUICK_CHECKBOX(x, xdiv, y, ydiv, txt, st) \
{ \ { \
.widget_type = quick_checkbox, \ .widget_type = quick_checkbox, \
.relative_x = x, \ .relative_x = x, \
.x_divisions = xdiv, \ .x_divisions = xdiv, \
.relative_y = y, \ .relative_y = y, \
.y_divisions = ydiv, \ .y_divisions = ydiv, \
.widget = NULL, \ .widget = NULL, \
.u = { \ .u = { \
.checkbox = { \ .checkbox = { \
.text = txt, \ .text = txt, \
.state = st \ .state = st \
} \ } \
} \ } \
} }
#define QUICK_BUTTON(x, xdiv, y, ydiv, txt, act, cb) \ #define QUICK_BUTTON(x, xdiv, y, ydiv, txt, act, cb) \
{ \ { \
.widget_type = quick_button, \ .widget_type = quick_button, \
.relative_x = x, \ .relative_x = x, \
.x_divisions = xdiv, \ .x_divisions = xdiv, \
.relative_y = y, \ .relative_y = y, \
.y_divisions = ydiv, \ .y_divisions = ydiv, \
.widget = NULL, \ .widget = NULL, \
.u = { \ .u = { \
.button = { \ .button = { \
.text = txt, \ .text = txt, \
.action = act, \ .action = act, \
.callback = cb \ .callback = cb \
} \ } \
} \ } \
} }
#define QUICK_INPUT(x, xdiv, y, ydiv, txt, len_, flags_, hname, res) \ #define QUICK_INPUT(x, xdiv, y, ydiv, txt, len_, flags_, hname, res) \
{ \ { \
.widget_type = quick_input, \ .widget_type = quick_input, \
.relative_x = x, \ .relative_x = x, \
.x_divisions = xdiv, \ .x_divisions = xdiv, \
.relative_y = y, \ .relative_y = y, \
.y_divisions = ydiv, \ .y_divisions = ydiv, \
.widget = NULL, \ .widget = NULL, \
.u = { \ .u = { \
.input = { \ .input = { \
.text = txt, \ .text = txt, \
.len = len_, \ .len = len_, \
.flags = flags_, \ .flags = flags_, \
.histname = hname, \ .histname = hname, \
.result = res \ .result = res \
} \ } \
} \ } \
} }
#define QUICK_LABEL(x, xdiv, y, ydiv, txt) \ #define QUICK_LABEL(x, xdiv, y, ydiv, txt) \
{ \ { \
.widget_type = quick_label, \ .widget_type = quick_label, \
.relative_x = x, \ .relative_x = x, \
.x_divisions = xdiv, \ .x_divisions = xdiv, \
.relative_y = y, \ .relative_y = y, \
.y_divisions = ydiv, \ .y_divisions = ydiv, \
.widget = NULL, \ .widget = NULL, \
.u = { \ .u = { \
.label = { \ .label = { \
.text = txt \ .text = txt \
} \ } \
} \ } \
} }
#define QUICK_RADIO(x, xdiv, y, ydiv, cnt, items_, val) \ #define QUICK_RADIO(x, xdiv, y, ydiv, cnt, items_, val) \
{ \ { \
.widget_type = quick_radio, \ .widget_type = quick_radio, \
.relative_x = x, \ .relative_x = x, \
.x_divisions = xdiv, \ .x_divisions = xdiv, \
.relative_y = y, \ .relative_y = y, \
.y_divisions = ydiv, \ .y_divisions = ydiv, \
.widget = NULL, \ .widget = NULL, \
.u = { \ .u = { \
.radio = { \ .radio = { \
.count = cnt, \ .count = cnt, \
.items = items_, \ .items = items_, \
.value = val \ .value = val \
} \ } \
} \ } \
} }
#define QUICK_GROUPBOX(x, xdiv, y, ydiv, w, h, t) \ #define QUICK_GROUPBOX(x, xdiv, y, ydiv, w, h, t) \
{ \ { \
.widget_type = quick_groupbox, \ .widget_type = quick_groupbox, \
.relative_x = x, \ .relative_x = x, \
.x_divisions = xdiv, \ .x_divisions = xdiv, \
.relative_y = y, \ .relative_y = y, \
.y_divisions = ydiv, \ .y_divisions = ydiv, \
.widget = NULL, \ .widget = NULL, \
.u = { \ .u = { \
.groupbox = { \ .groupbox = { \
.width = w, \ .width = w, \
.height = h, \ .height = h, \
.title = t \ .title = t \
} \ } \
} \ } \
} }
#define QUICK_END \
{ \ #define QUICK_END \
.widget_type = quick_end, \ { \
.relative_x = 0, \ .widget_type = quick_end, \
.x_divisions = 0, \ .relative_x = 0, \
.relative_y = 0, \ .x_divisions = 0, \
.y_divisions = 0, \ .relative_y = 0, \
.widget = NULL, \ .y_divisions = 0, \
.u = { \ .widget = NULL, \
.input = { \ .u = { \
.text = NULL, \ .input = { \
.len = 0, \ .text = NULL, \
.flags = 0, \ .len = 0, \
.histname = NULL, \ .flags = 0, \
.result = NULL \ .histname = NULL, \
} \ .result = NULL \
} \ } \
} \
} }
typedef struct { typedef struct
int xlen, ylen; {
int xpos, ypos; /* if -1, then center the dialog */ int xlen, ylen;
int xpos, ypos; /* if -1, then center the dialog */
const char *title; const char *title;
const char *help; const char *help;
QuickWidget *widgets; QuickWidget *widgets;
gboolean i18n; /* If true, internationalization has happened */ gboolean i18n; /* If true, internationalization has happened */
} QuickDialog; } QuickDialog;
int quick_dialog (QuickDialog *qd); int quick_dialog (QuickDialog * qd);
int quick_dialog_skip (QuickDialog *qd, int nskip); int quick_dialog_skip (QuickDialog * qd, int nskip);
/* The input dialogs */ /* The input dialogs */
@ -223,18 +235,17 @@ int quick_dialog_skip (QuickDialog *qd, int nskip);
#define INPUT_PASSWORD ((char *) -1) #define INPUT_PASSWORD ((char *) -1)
char *input_dialog (const char *header, const char *text, char *input_dialog (const char *header, const char *text,
const char *history_name, const char *def_text); const char *history_name, const char *def_text);
char *input_dialog_help (const char *header, const char *text, const char *help, char *input_dialog_help (const char *header, const char *text, const char *help,
const char *history_name, const char *def_text); const char *history_name, const char *def_text);
char *input_expand_dialog (const char *header, const char *text, char *input_expand_dialog (const char *header, const char *text,
const char *history_name, const char *def_text); const char *history_name, const char *def_text);
void query_set_sel (int new_sel); void query_set_sel (int new_sel);
/* Create message box but don't dismiss it yet, not background safe */ /* Create message box but don't dismiss it yet, not background safe */
struct Dlg_head *create_message (int flags, const char *title, struct Dlg_head *create_message (int flags, const char *title,
const char *text, ...) const char *text, ...) __attribute__ ((format (__printf__, 3, 4)));
__attribute__ ((format (__printf__, 3, 4)));
/* Show message box, background safe */ /* Show message box, background safe */
void message (int flags, const char *title, const char *text, ...) void message (int flags, const char *title, const char *text, ...)
@ -247,9 +258,10 @@ void message (int flags, const char *title, const char *text, ...)
int query_dialog (const char *header, const char *text, int flags, int count, ...); int query_dialog (const char *header, const char *text, int flags, int count, ...);
/* flags for message() and query_dialog() */ /* flags for message() and query_dialog() */
enum { enum
D_NORMAL = 0, {
D_ERROR = 1 D_NORMAL = 0,
} /* dialog options */; D_ERROR = 1
} /* dialog options */ ;
#endif #endif