1998-02-27 07:54:42 +03:00
|
|
|
/* Widget based utility functions.
|
2007-09-25 19:33:35 +04:00
|
|
|
Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
|
|
|
2005, 2006, 2007 Free Software Foundation, Inc.
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
Authors: 1994, 1995, 1996 Miguel de Icaza
|
|
|
|
1994, 1995 Radek Doulik
|
|
|
|
1995 Jakub Jelinek
|
|
|
|
1995 Andrej Borsenkow
|
|
|
|
|
|
|
|
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
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2005-05-27 07:35:10 +04:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2009-02-05 21:28:18 +03:00
|
|
|
/** \file wtools.c
|
|
|
|
* \brief Source: widget based utility functions
|
|
|
|
*/
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <config.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <stdarg.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2001-09-03 09:07:40 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "global.h"
|
2009-05-30 21:39:02 +04:00
|
|
|
|
2009-05-08 14:01:05 +04:00
|
|
|
#include "../src/tty/tty.h"
|
2009-05-30 21:39:02 +04:00
|
|
|
#include "../src/tty/color.h" /* INPUT_COLOR */
|
2009-06-19 21:33:41 +04:00
|
|
|
#include "../src/tty/key.h" /* tty_getch() */
|
2009-05-30 21:39:02 +04:00
|
|
|
|
2003-10-25 03:20:30 +04:00
|
|
|
#include "dialog.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "widget.h"
|
|
|
|
#include "wtools.h"
|
2003-10-26 07:03:07 +03:00
|
|
|
#include "background.h" /* parent_call */
|
2008-12-29 01:59:38 +03:00
|
|
|
#include "strutil.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
2003-09-03 09:19:08 +04:00
|
|
|
Listbox *
|
2009-04-21 12:48:13 +04:00
|
|
|
create_listbox_window_delta (int delta_x, int delta_y, int cols, int lines, const char *title, const char *help)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int xpos, ypos, len;
|
2003-09-03 09:19:08 +04:00
|
|
|
Listbox *listbox = g_new (Listbox, 1);
|
2004-08-16 19:45:05 +04:00
|
|
|
const char *cancel_string = _("&Cancel");
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* Adjust sizes */
|
2003-09-03 09:19:08 +04:00
|
|
|
lines = (lines > LINES - 6) ? LINES - 6 : lines;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2008-12-29 01:59:38 +03:00
|
|
|
if (title && (cols < (len = str_term_width1 (title) + 2)))
|
2003-09-03 09:19:08 +04:00
|
|
|
cols = len;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2003-09-03 09:19:08 +04:00
|
|
|
/* no &, but 4 spaces around button for brackets and such */
|
2008-12-29 01:59:38 +03:00
|
|
|
if (cols < (len = str_term_width1 (cancel_string) + 3))
|
2003-09-03 09:19:08 +04:00
|
|
|
cols = len;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2003-09-03 09:19:08 +04:00
|
|
|
cols = cols > COLS - 6 ? COLS - 6 : cols;
|
2009-04-21 12:48:13 +04:00
|
|
|
xpos = (COLS - cols + delta_x) / 2;
|
|
|
|
ypos = (LINES - lines + delta_y) / 2 - 2;
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Create components */
|
2003-09-03 09:19:08 +04:00
|
|
|
listbox->dlg =
|
|
|
|
create_dlg (ypos, xpos, lines + 6, cols + 4, dialog_colors, NULL,
|
2009-04-21 12:48:13 +04:00
|
|
|
help, title, DLG_REVERSE);
|
2003-09-03 09:19:08 +04:00
|
|
|
|
2009-04-15 20:22:26 +04:00
|
|
|
listbox->list = listbox_new (2, 2, lines, cols, NULL);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
add_widget (listbox->dlg,
|
2003-09-03 09:19:08 +04:00
|
|
|
button_new (lines + 3, (cols / 2 + 2) - len / 2, B_CANCEL,
|
2005-09-05 07:20:53 +04:00
|
|
|
NORMAL_BUTTON, cancel_string, 0));
|
1998-02-27 07:54:42 +03:00
|
|
|
add_widget (listbox->dlg, listbox->list);
|
2003-09-03 09:19:08 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return listbox;
|
|
|
|
}
|
|
|
|
|
2009-04-21 12:48:13 +04:00
|
|
|
Listbox *
|
|
|
|
create_listbox_window (int cols, int lines, const char *title, const char *help)
|
|
|
|
{
|
|
|
|
return create_listbox_window_delta (0, 0, cols, lines, title, help);
|
|
|
|
}
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Returns the number of the item selected */
|
|
|
|
int run_listbox (Listbox *l)
|
|
|
|
{
|
|
|
|
int val;
|
|
|
|
|
|
|
|
run_dlg (l->dlg);
|
|
|
|
if (l->dlg->ret_value == B_CANCEL)
|
|
|
|
val = -1;
|
|
|
|
else
|
|
|
|
val = l->list->pos;
|
|
|
|
destroy_dlg (l->dlg);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (l);
|
1998-02-27 07:54:42 +03:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-15 01:58:56 +04:00
|
|
|
static Dlg_head *last_query_dlg;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
static int sel_pos = 0;
|
|
|
|
|
|
|
|
/* Used to ask questions to the user */
|
2003-09-01 06:07:02 +04:00
|
|
|
int
|
2003-10-26 01:12:05 +04:00
|
|
|
query_dialog (const char *header, const char *text, int flags, int count, ...)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
Dlg_head *query_dlg;
|
2003-09-12 12:28:21 +04:00
|
|
|
WButton *button;
|
|
|
|
WButton *defbutton = NULL;
|
1998-02-27 07:54:42 +03:00
|
|
|
int win_len = 0;
|
|
|
|
int i;
|
|
|
|
int result = -1;
|
|
|
|
int xpos, ypos;
|
|
|
|
int cols, lines;
|
|
|
|
char *cur_name;
|
2002-08-31 04:31:14 +04:00
|
|
|
static const int *query_colors;
|
2002-08-31 04:29:48 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* set dialog colors */
|
2002-08-31 04:29:48 +04:00
|
|
|
if (flags & D_ERROR)
|
|
|
|
query_colors = alarm_colors;
|
|
|
|
else
|
|
|
|
query_colors = dialog_colors;
|
2003-09-01 06:07:02 +04:00
|
|
|
|
1998-03-30 01:07:37 +04:00
|
|
|
if (header == MSG_ERROR)
|
2002-10-21 08:13:49 +04:00
|
|
|
header = _("Error");
|
2003-09-01 06:07:02 +04:00
|
|
|
|
|
|
|
if (count > 0) {
|
1998-02-27 07:54:42 +03:00
|
|
|
va_start (ap, count);
|
2003-09-01 06:07:02 +04:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
char *cp = va_arg (ap, char *);
|
2008-12-29 01:59:38 +03:00
|
|
|
win_len += str_term_width1 (cp) + 6;
|
2003-09-01 06:07:02 +04:00
|
|
|
if (strchr (cp, '&') != NULL)
|
|
|
|
win_len--;
|
1998-04-16 00:09:13 +04:00
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
va_end (ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* count coordinates */
|
2008-12-29 01:59:38 +03:00
|
|
|
str_msg_term_size (text, &lines, &cols);
|
|
|
|
cols = 6 + max (win_len, max (str_term_width1 (header), cols));
|
1998-02-27 07:54:42 +03:00
|
|
|
lines += 4 + (count > 0 ? 2 : 0);
|
2003-09-01 06:07:02 +04:00
|
|
|
xpos = COLS / 2 - cols / 2;
|
|
|
|
ypos = LINES / 3 - (lines - 3) / 2;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* prepare dialog */
|
2003-09-01 06:07:02 +04:00
|
|
|
query_dlg =
|
|
|
|
create_dlg (ypos, xpos, lines, cols, query_colors, NULL,
|
2003-09-13 01:22:01 +04:00
|
|
|
"[QueryBox]", header, DLG_NONE);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2003-09-01 06:07:02 +04:00
|
|
|
if (count > 0) {
|
|
|
|
cols = (cols - win_len - 2) / 2 + 2;
|
1998-02-27 07:54:42 +03:00
|
|
|
va_start (ap, count);
|
2003-09-01 06:07:02 +04:00
|
|
|
for (i = 0; i < count; i++) {
|
1998-02-27 07:54:42 +03:00
|
|
|
cur_name = va_arg (ap, char *);
|
2008-12-29 01:59:38 +03:00
|
|
|
xpos = str_term_width1 (cur_name) + 6;
|
2003-09-01 06:07:02 +04:00
|
|
|
if (strchr (cur_name, '&') != NULL)
|
|
|
|
xpos--;
|
2003-09-12 12:28:21 +04:00
|
|
|
|
|
|
|
button =
|
|
|
|
button_new (lines - 3, cols, B_USER + i, NORMAL_BUTTON,
|
|
|
|
cur_name, 0);
|
|
|
|
add_widget (query_dlg, button);
|
1998-02-27 07:54:42 +03:00
|
|
|
cols += xpos;
|
|
|
|
if (i == sel_pos)
|
2003-09-12 12:28:21 +04:00
|
|
|
defbutton = button;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
va_end (ap);
|
|
|
|
|
2003-09-01 04:18:37 +04:00
|
|
|
add_widget (query_dlg, label_new (2, 3, text));
|
2003-09-01 06:07:02 +04:00
|
|
|
|
2003-09-12 12:28:21 +04:00
|
|
|
if (defbutton)
|
2005-05-21 00:22:06 +04:00
|
|
|
dlg_select_widget (defbutton);
|
2003-09-12 12:28:21 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* run dialog and make result */
|
|
|
|
run_dlg (query_dlg);
|
2003-09-01 06:07:02 +04:00
|
|
|
switch (query_dlg->ret_value) {
|
1998-02-27 07:54:42 +03:00
|
|
|
case B_CANCEL:
|
|
|
|
break;
|
|
|
|
default:
|
2003-09-01 06:07:02 +04:00
|
|
|
result = query_dlg->ret_value - B_USER;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* free used memory */
|
|
|
|
destroy_dlg (query_dlg);
|
|
|
|
} else {
|
2003-09-01 04:18:37 +04:00
|
|
|
add_widget (query_dlg, label_new (2, 3, text));
|
2003-09-01 06:07:02 +04:00
|
|
|
add_widget (query_dlg,
|
|
|
|
button_new (0, 0, 0, HIDDEN_BUTTON, "-", 0));
|
1998-02-27 07:54:42 +03:00
|
|
|
last_query_dlg = query_dlg;
|
|
|
|
}
|
|
|
|
sel_pos = 0;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void query_set_sel (int new_sel)
|
|
|
|
{
|
|
|
|
sel_pos = new_sel;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-26 01:12:05 +04:00
|
|
|
/* Create message dialog */
|
|
|
|
static struct Dlg_head *
|
|
|
|
do_create_message (int flags, const char *title, const char *text)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
Dlg_head *d;
|
|
|
|
|
|
|
|
/* Add empty lines before and after the message */
|
2004-09-24 19:05:28 +04:00
|
|
|
p = g_strconcat ("\n", text, "\n", (char *) NULL);
|
2003-10-26 01:12:05 +04:00
|
|
|
query_dialog (title, p, flags, 0);
|
|
|
|
d = last_query_dlg;
|
|
|
|
init_dlg (d);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (p);
|
2003-10-26 01:12:05 +04:00
|
|
|
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2003-10-26 01:12:05 +04:00
|
|
|
/*
|
|
|
|
* Create message dialog. The caller must call dlg_run_done() and
|
|
|
|
* destroy_dlg() to dismiss it. Not safe to call from background.
|
|
|
|
*/
|
2002-11-14 10:25:18 +03:00
|
|
|
struct Dlg_head *
|
2003-10-26 01:12:05 +04:00
|
|
|
create_message (int flags, const char *title, const char *text, ...)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2003-10-26 01:12:05 +04:00
|
|
|
va_list args;
|
1998-02-27 07:54:42 +03:00
|
|
|
Dlg_head *d;
|
2003-10-26 01:12:05 +04:00
|
|
|
char *p;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
va_start (args, text);
|
2003-10-26 01:12:05 +04:00
|
|
|
p = g_strdup_vprintf (text, args);
|
1998-02-27 07:54:42 +03:00
|
|
|
va_end (args);
|
1998-12-03 02:44:06 +03:00
|
|
|
|
2003-10-26 01:12:05 +04:00
|
|
|
d = do_create_message (flags, title, p);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (p);
|
2003-10-26 01:12:05 +04:00
|
|
|
|
|
|
|
return d;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2003-10-26 01:12:05 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Show message dialog. Dismiss it when any key is pressed.
|
|
|
|
* Not safe to call from background.
|
|
|
|
*/
|
2003-10-26 07:47:20 +03:00
|
|
|
static void
|
|
|
|
fg_message (int flags, const char *title, const char *text)
|
2003-10-26 01:12:05 +04:00
|
|
|
{
|
|
|
|
Dlg_head *d;
|
|
|
|
|
2003-10-26 07:47:20 +03:00
|
|
|
d = do_create_message (flags, title, text);
|
2009-06-19 21:33:41 +04:00
|
|
|
tty_getch ();
|
2003-10-26 01:12:05 +04:00
|
|
|
dlg_run_done (d);
|
|
|
|
destroy_dlg (d);
|
|
|
|
}
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2003-10-26 01:54:55 +04:00
|
|
|
/* Show message box from background */
|
|
|
|
#ifdef WITH_BACKGROUND
|
|
|
|
static void
|
|
|
|
bg_message (int dummy, int *flags, char *title, const char *text)
|
|
|
|
{
|
2005-02-09 01:33:52 +03:00
|
|
|
(void) dummy;
|
2004-09-24 19:05:28 +04:00
|
|
|
title = g_strconcat (_("Background process:"), " ", title, (char *) NULL);
|
2003-10-26 07:47:20 +03:00
|
|
|
fg_message (*flags, title, text);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (title);
|
2003-10-26 01:54:55 +04:00
|
|
|
}
|
|
|
|
#endif /* WITH_BACKGROUND */
|
|
|
|
|
|
|
|
|
|
|
|
/* Show message box, background safe */
|
|
|
|
void
|
2003-10-26 07:47:20 +03:00
|
|
|
message (int flags, const char *title, const char *text, ...)
|
2003-10-26 01:54:55 +04:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
va_list ap;
|
2009-04-24 02:47:22 +04:00
|
|
|
union {
|
|
|
|
void *p;
|
|
|
|
void (*f) (int, int *, char *, const char *);
|
|
|
|
} func;
|
2003-10-26 01:54:55 +04:00
|
|
|
|
|
|
|
va_start (ap, text);
|
|
|
|
p = g_strdup_vprintf (text, ap);
|
|
|
|
va_end (ap);
|
|
|
|
|
2003-10-26 07:47:20 +03:00
|
|
|
if (title == MSG_ERROR)
|
|
|
|
title = _("Error");
|
|
|
|
|
2003-10-26 01:54:55 +04:00
|
|
|
#ifdef WITH_BACKGROUND
|
|
|
|
if (we_are_background) {
|
2009-04-24 02:47:22 +04:00
|
|
|
func.f = bg_message;
|
|
|
|
parent_call (func.p, NULL, 3, sizeof (flags), &flags,
|
2003-10-26 02:13:01 +04:00
|
|
|
strlen (title), title, strlen (p), p);
|
2003-10-26 01:54:55 +04:00
|
|
|
} else
|
|
|
|
#endif /* WITH_BACKGROUND */
|
2003-10-26 07:47:20 +03:00
|
|
|
fg_message (flags, title, p);
|
2003-10-26 01:54:55 +04:00
|
|
|
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (p);
|
2003-10-26 01:54:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* {{{ Quick dialog routines */
|
|
|
|
|
1998-03-30 23:14:22 +04:00
|
|
|
#define I18N(x) (do_int && *x ? (x = _(x)): x)
|
|
|
|
|
2002-11-13 03:20:15 +03:00
|
|
|
int
|
|
|
|
quick_dialog_skip (QuickDialog *qd, int nskip)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
Dlg_head *dd;
|
2009-04-29 14:43:18 +04:00
|
|
|
|
2002-11-13 03:20:15 +03:00
|
|
|
WRadio *r;
|
|
|
|
int xpos;
|
|
|
|
int ypos;
|
|
|
|
int return_val;
|
|
|
|
WInput *input;
|
1998-02-27 07:54:42 +03:00
|
|
|
QuickWidget *qw;
|
2002-11-13 03:20:15 +03:00
|
|
|
int do_int;
|
1998-03-25 08:16:00 +03:00
|
|
|
|
2002-11-13 03:20:15 +03:00
|
|
|
if (!qd->i18n) {
|
1998-03-25 08:16:00 +03:00
|
|
|
qd->i18n = 1;
|
|
|
|
do_int = 1;
|
1998-03-30 23:14:22 +04:00
|
|
|
if (*qd->title)
|
|
|
|
qd->title = _(qd->title);
|
1998-03-25 08:16:00 +03:00
|
|
|
} else
|
|
|
|
do_int = 0;
|
2002-11-13 03:20:15 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (qd->xpos == -1)
|
2003-09-10 03:12:06 +04:00
|
|
|
dd = create_dlg (0, 0, qd->ylen, qd->xlen, dialog_colors, NULL,
|
2003-11-27 12:55:15 +03:00
|
|
|
qd->help, qd->title,
|
|
|
|
DLG_CENTER | DLG_TRYUP | DLG_REVERSE);
|
1998-02-27 07:54:42 +03:00
|
|
|
else
|
2002-11-13 03:20:15 +03:00
|
|
|
dd = create_dlg (qd->ypos, qd->xpos, qd->ylen, qd->xlen,
|
2003-09-10 03:12:06 +04:00
|
|
|
dialog_colors, NULL, qd->help, qd->title,
|
2003-09-13 01:22:01 +04:00
|
|
|
DLG_REVERSE);
|
2002-11-13 03:20:15 +03:00
|
|
|
|
|
|
|
for (qw = qd->widgets; qw->widget_type; qw++) {
|
|
|
|
xpos = (qd->xlen * qw->relative_x) / qw->x_divisions;
|
|
|
|
ypos = (qd->ylen * qw->relative_y) / qw->y_divisions;
|
|
|
|
|
|
|
|
switch (qw->widget_type) {
|
1998-02-27 07:54:42 +03:00
|
|
|
case quick_checkbox:
|
2009-05-09 10:48:07 +04:00
|
|
|
qw->widget = (Widget *)check_new (ypos, xpos, *qw->result, I18N (qw->text));
|
1998-02-27 07:54:42 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_radio:
|
2006-02-28 19:15:21 +03:00
|
|
|
r = radio_new (ypos, xpos, qw->hotkey_pos, const_cast(const char **, qw->str_result));
|
1998-02-27 07:54:42 +03:00
|
|
|
r->pos = r->sel = qw->value;
|
2009-05-09 10:48:07 +04:00
|
|
|
qw->widget = (Widget *)r;
|
1998-02-27 07:54:42 +03:00
|
|
|
break;
|
2002-11-13 03:20:15 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
case quick_button:
|
2009-05-09 10:48:07 +04:00
|
|
|
qw->widget = (Widget *)
|
2002-11-13 03:20:15 +03:00
|
|
|
button_new (ypos, xpos, qw->value,
|
|
|
|
(qw->value ==
|
|
|
|
B_ENTER) ? DEFPUSH_BUTTON : NORMAL_BUTTON,
|
2009-04-29 15:07:09 +04:00
|
|
|
I18N (qw->text), (bcback) qw->cb);
|
1998-02-27 07:54:42 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* We use the hotkey pos as the field length */
|
|
|
|
case quick_input:
|
2003-09-10 03:12:06 +04:00
|
|
|
input =
|
|
|
|
input_new (ypos, xpos, INPUT_COLOR, qw->hotkey_pos,
|
2009-01-29 21:17:43 +03:00
|
|
|
qw->text, qw->histname, INPUT_COMPLETE_DEFAULT);
|
1998-02-27 07:54:42 +03:00
|
|
|
input->is_password = qw->value == 1;
|
|
|
|
input->point = 0;
|
|
|
|
if (qw->value & 2)
|
2002-11-13 03:20:15 +03:00
|
|
|
input->completion_flags |= INPUT_COMPLETE_CD;
|
2009-05-09 10:48:07 +04:00
|
|
|
qw->widget = (Widget *)input;
|
1998-02-27 07:54:42 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_label:
|
2009-05-09 10:48:07 +04:00
|
|
|
qw->widget = (Widget *)label_new (ypos, xpos, I18N (qw->text));
|
1998-02-27 07:54:42 +03:00
|
|
|
break;
|
2002-11-13 03:20:15 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
default:
|
2009-04-29 14:43:18 +04:00
|
|
|
qw->widget = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
fprintf (stderr, "QuickWidget: unknown widget type\n");
|
|
|
|
break;
|
|
|
|
}
|
2009-04-29 14:43:18 +04:00
|
|
|
add_widget (dd, qw->widget);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
while (nskip--)
|
|
|
|
dd->current = dd->current->next;
|
|
|
|
|
|
|
|
run_dlg (dd);
|
|
|
|
|
|
|
|
/* Get the data if we found something interesting */
|
2002-11-13 03:20:15 +03:00
|
|
|
if (dd->ret_value != B_CANCEL) {
|
2009-04-29 14:43:18 +04:00
|
|
|
for (qw = qd->widgets; qw->widget_type; qw++) {
|
|
|
|
Widget *w = qw->widget;
|
2002-11-13 03:20:15 +03:00
|
|
|
|
|
|
|
switch (qw->widget_type) {
|
1998-02-27 07:54:42 +03:00
|
|
|
case quick_checkbox:
|
2002-11-13 03:20:15 +03:00
|
|
|
*qw->result = ((WCheck *) w)->state & C_BOOL;
|
1998-02-27 07:54:42 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_radio:
|
2002-11-13 03:20:15 +03:00
|
|
|
*qw->result = ((WRadio *) w)->sel;
|
1998-02-27 07:54:42 +03:00
|
|
|
break;
|
2002-11-13 03:20:15 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
case quick_input:
|
2003-11-27 12:55:15 +03:00
|
|
|
if (qw->value & 2)
|
|
|
|
*qw->str_result =
|
|
|
|
tilde_expand (((WInput *) w)->buffer);
|
|
|
|
else
|
2009-02-06 01:40:32 +03:00
|
|
|
*qw->str_result = g_strdup (((WInput *) w)->buffer);
|
1998-02-27 07:54:42 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return_val = dd->ret_value;
|
|
|
|
destroy_dlg (dd);
|
2002-11-13 03:20:15 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return return_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
int quick_dialog (QuickDialog *qd)
|
|
|
|
{
|
|
|
|
return quick_dialog_skip (qd, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ Input routines */
|
1999-03-16 03:11:32 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#define INPUT_INDEX 2
|
2003-10-26 01:54:55 +04:00
|
|
|
|
2006-09-14 13:12:49 +04:00
|
|
|
/*
|
|
|
|
* Show dialog, not background safe.
|
|
|
|
*
|
|
|
|
* If the arguments "header" and "text" should be translated,
|
|
|
|
* that MUST be done by the caller of fg_input_dialog_help().
|
2009-01-14 03:01:18 +03:00
|
|
|
*
|
|
|
|
* The argument "history_name" holds the name of a section
|
|
|
|
* in the history file. Data entered in the input field of
|
|
|
|
* the dialog box will be stored there.
|
2006-09-14 13:12:49 +04:00
|
|
|
*
|
|
|
|
*/
|
2003-10-26 01:54:55 +04:00
|
|
|
static char *
|
2004-08-16 19:45:05 +04:00
|
|
|
fg_input_dialog_help (const char *header, const char *text, const char *help,
|
2009-01-14 03:01:18 +03:00
|
|
|
const char *history_name, const char *def_text)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
QuickDialog Quick_input;
|
2002-09-17 03:28:09 +04:00
|
|
|
QuickWidget quick_widgets[] = {
|
|
|
|
{quick_button, 6, 10, 1, 0, N_("&Cancel"), 0, B_CANCEL, 0, 0,
|
2009-04-29 15:07:09 +04:00
|
|
|
NULL, NULL, NULL},
|
|
|
|
{quick_button, 3, 10, 1, 0, N_("&OK"), 0, B_ENTER, 0, 0, NULL, NULL, NULL},
|
|
|
|
{quick_input, 4, 80, 0, 0, "", 58, 0, 0, 0, NULL, NULL, NULL},
|
|
|
|
{quick_label, 4, 80, 2, 0, "", 0, 0, 0, 0, NULL, NULL, NULL},
|
2004-08-15 22:24:06 +04:00
|
|
|
NULL_QuickWidget
|
2002-09-17 03:28:09 +04:00
|
|
|
};
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
int len;
|
|
|
|
int i;
|
2005-02-05 16:03:11 +03:00
|
|
|
int lines, cols;
|
2002-09-17 03:28:09 +04:00
|
|
|
int ret;
|
1998-02-27 07:54:42 +03:00
|
|
|
char *my_str;
|
2003-09-01 05:34:17 +04:00
|
|
|
char histname[64] = "inp|";
|
2004-09-17 07:19:21 +04:00
|
|
|
char *p_text;
|
2002-09-17 03:28:09 +04:00
|
|
|
|
2009-01-14 03:01:18 +03:00
|
|
|
if (history_name != NULL && *history_name != '\0') {
|
|
|
|
g_strlcpy (histname + 3, history_name, 61);
|
|
|
|
quick_widgets[2].histname = histname;
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2005-02-05 16:03:11 +03:00
|
|
|
msglen (text, &lines, &cols);
|
2008-12-29 01:59:38 +03:00
|
|
|
len = max (str_term_width1 (header), cols) + 4;
|
1998-02-27 07:54:42 +03:00
|
|
|
len = max (len, 64);
|
2002-09-17 03:28:09 +04:00
|
|
|
|
2002-09-03 21:36:27 +04:00
|
|
|
/* The special value of def_text is used to identify password boxes
|
|
|
|
and hide characters with "*". Don't save passwords in history! */
|
|
|
|
if (def_text == INPUT_PASSWORD) {
|
2002-09-17 03:28:09 +04:00
|
|
|
quick_widgets[INPUT_INDEX].value = 1;
|
2003-09-01 05:34:17 +04:00
|
|
|
histname[3] = 0;
|
2002-09-03 21:36:27 +04:00
|
|
|
def_text = "";
|
1998-02-27 07:54:42 +03:00
|
|
|
} else {
|
2002-09-17 03:28:09 +04:00
|
|
|
quick_widgets[INPUT_INDEX].value = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
1998-04-07 23:08:31 +04:00
|
|
|
|
|
|
|
#ifdef ENABLE_NLS
|
2002-09-17 03:28:09 +04:00
|
|
|
/*
|
|
|
|
* An attempt to place buttons symmetrically, based on actual i18n
|
|
|
|
* length of the string. It looks nicer with i18n (IMO) - alex
|
|
|
|
*/
|
2006-09-14 13:12:49 +04:00
|
|
|
quick_widgets[0].text = _(quick_widgets[0].text);
|
|
|
|
quick_widgets[1].text = _(quick_widgets[1].text);
|
2002-09-17 03:28:09 +04:00
|
|
|
quick_widgets[0].relative_x = len / 2 + 4;
|
|
|
|
quick_widgets[1].relative_x =
|
2008-12-29 01:59:38 +03:00
|
|
|
len / 2 - (str_term_width1 (quick_widgets[1].text) + 9);
|
2002-09-17 03:28:09 +04:00
|
|
|
quick_widgets[0].x_divisions = quick_widgets[1].x_divisions = len;
|
|
|
|
#endif /* ENABLE_NLS */
|
|
|
|
|
|
|
|
Quick_input.xlen = len;
|
|
|
|
Quick_input.xpos = -1;
|
2004-09-17 07:19:21 +04:00
|
|
|
Quick_input.title = header;
|
|
|
|
Quick_input.help = help;
|
2006-09-14 13:12:49 +04:00
|
|
|
Quick_input.i18n = 1; /* The dialog is already translated. */
|
2009-02-06 01:40:32 +03:00
|
|
|
p_text = g_strstrip (g_strdup (text));
|
2004-09-17 07:19:21 +04:00
|
|
|
quick_widgets[INPUT_INDEX + 1].text = p_text;
|
|
|
|
quick_widgets[INPUT_INDEX].text = def_text;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
2002-09-17 03:28:09 +04:00
|
|
|
quick_widgets[i].y_divisions = lines + 6;
|
|
|
|
Quick_input.ylen = lines + 6;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
2002-09-17 03:28:09 +04:00
|
|
|
quick_widgets[i].relative_y += 2 + lines;
|
|
|
|
|
|
|
|
quick_widgets[INPUT_INDEX].str_result = &my_str;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
Quick_input.widgets = quick_widgets;
|
2002-09-17 03:28:09 +04:00
|
|
|
ret = quick_dialog (&Quick_input);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (p_text);
|
2002-09-17 03:28:09 +04:00
|
|
|
|
|
|
|
if (ret != B_CANCEL) {
|
2004-09-17 07:19:21 +04:00
|
|
|
return my_str;
|
1998-02-27 07:54:42 +03:00
|
|
|
} else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-14 13:12:49 +04:00
|
|
|
/*
|
|
|
|
* Show input dialog, background safe.
|
|
|
|
*
|
|
|
|
* If the arguments "header" and "text" should be translated,
|
|
|
|
* that MUST be done by the caller of these wrappers.
|
|
|
|
*/
|
2003-10-26 01:54:55 +04:00
|
|
|
char *
|
2009-01-14 03:01:18 +03:00
|
|
|
input_dialog_help (const char *header, const char *text, const char *help,
|
|
|
|
const char *history_name, const char *def_text)
|
2003-10-26 01:54:55 +04:00
|
|
|
{
|
2009-04-24 02:47:22 +04:00
|
|
|
union {
|
|
|
|
void *p;
|
|
|
|
char * (*f) (const char *, const char *, const char *,
|
|
|
|
const char *, const char *);
|
|
|
|
} func;
|
2003-10-26 01:54:55 +04:00
|
|
|
#ifdef WITH_BACKGROUND
|
|
|
|
if (we_are_background)
|
2009-04-24 02:47:22 +04:00
|
|
|
{
|
|
|
|
func.f = fg_input_dialog_help;
|
|
|
|
return parent_call_string (func.p, 5,
|
2003-10-26 01:54:55 +04:00
|
|
|
strlen (header), header, strlen (text),
|
|
|
|
text, strlen (help), help,
|
2009-01-14 03:01:18 +03:00
|
|
|
strlen (history_name), history_name,
|
2003-10-26 01:54:55 +04:00
|
|
|
strlen (def_text), def_text);
|
2009-04-24 02:47:22 +04:00
|
|
|
}
|
2003-10-26 01:54:55 +04:00
|
|
|
else
|
|
|
|
#endif /* WITH_BACKGROUND */
|
2009-01-14 03:01:18 +03:00
|
|
|
return fg_input_dialog_help (header, text, help, history_name, def_text);
|
2003-10-26 01:54:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Show input dialog with default help, background safe */
|
2009-01-14 03:01:18 +03:00
|
|
|
char *input_dialog (const char *header, const char *text,
|
|
|
|
const char *history_name, const char *def_text)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-01-14 03:01:18 +03:00
|
|
|
return input_dialog_help (header, text, "[Input Line Keys]", history_name, def_text);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2003-11-27 12:45:22 +03:00
|
|
|
char *
|
2009-01-14 03:01:18 +03:00
|
|
|
input_expand_dialog (const char *header, const char *text,
|
|
|
|
const char *history_name, const char *def_text)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
char *result;
|
|
|
|
char *expanded;
|
|
|
|
|
2009-01-14 03:01:18 +03:00
|
|
|
result = input_dialog (header, text, history_name, def_text);
|
2003-11-27 12:45:22 +03:00
|
|
|
if (result) {
|
1998-02-27 07:54:42 +03:00
|
|
|
expanded = tilde_expand (result);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (result);
|
2003-11-27 12:45:22 +03:00
|
|
|
return expanded;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
/*
|
|
|
|
Cause emacs to enter folding mode for this file:
|
|
|
|
Local variables:
|
|
|
|
end:
|
|
|
|
*/
|