1998-02-27 07:54:42 +03:00
|
|
|
/* Widget based utility functions.
|
|
|
|
Copyright (C) 1994, 1995 the Free Software Foundation
|
|
|
|
|
|
|
|
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
|
2000-08-23 02:50:00 +04:00
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
2001-09-03 09:07:40 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "global.h"
|
2001-09-03 09:07:40 +04:00
|
|
|
#include "tty.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "win.h"
|
|
|
|
#include "color.h"
|
|
|
|
#include "mouse.h"
|
2003-10-25 03:20:30 +04:00
|
|
|
#include "dialog.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "widget.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "wtools.h"
|
|
|
|
#include "key.h" /* For mi_getch() */
|
|
|
|
#include "complete.h" /* INPUT_COMPLETE_CD */
|
2003-10-26 01:54:55 +04:00
|
|
|
#include "background.h" /* parent_call */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
2003-09-03 09:19:08 +04:00
|
|
|
Listbox *
|
|
|
|
create_listbox_window (int cols, int lines, char *title, 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);
|
|
|
|
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
|
|
|
|
2003-09-03 09:19:08 +04:00
|
|
|
if (title && (cols < (len = strlen (title) + 2)))
|
|
|
|
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 */
|
|
|
|
if (cols < (len = strlen (cancel_string) + 3))
|
|
|
|
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;
|
|
|
|
xpos = (COLS - cols) / 2;
|
|
|
|
ypos = (LINES - lines) / 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,
|
2003-09-13 01:22:01 +04:00
|
|
|
help, title, DLG_CENTER | DLG_REVERSE);
|
2003-09-03 09:19:08 +04:00
|
|
|
|
2003-09-01 11:31:56 +04:00
|
|
|
listbox->list = listbox_new (2, 2, cols, lines, 0);
|
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,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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);
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +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 *);
|
|
|
|
win_len += strlen (cp) + 6;
|
|
|
|
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 */
|
1998-04-16 00:09:13 +04:00
|
|
|
cols = 6 + max (win_len, max (strlen (header), msglen (text, &lines)));
|
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 *);
|
2003-09-01 06:07:02 +04:00
|
|
|
xpos = strlen (cur_name) + 6;
|
|
|
|
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)
|
|
|
|
dlg_select_widget (query_dlg, defbutton);
|
|
|
|
|
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 */
|
|
|
|
p = g_strdup_printf ("\n%s\n", text);
|
|
|
|
query_dialog (title, p, flags, 0);
|
|
|
|
d = last_query_dlg;
|
|
|
|
init_dlg (d);
|
|
|
|
g_free (p);
|
|
|
|
|
|
|
|
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);
|
|
|
|
g_free (p);
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
message (int flags, const char *title, const char *text, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
Dlg_head *d;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
va_start (args, text);
|
|
|
|
p = g_strdup_vprintf (text, args);
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
d = do_create_message (flags, title, p);
|
|
|
|
g_free (p);
|
|
|
|
|
|
|
|
mi_getch ();
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
title = g_strdup_printf ("%s %s", _("Background process:"), title);
|
|
|
|
message (*flags, title, "%s", text);
|
|
|
|
g_free (title);
|
|
|
|
}
|
|
|
|
#endif /* WITH_BACKGROUND */
|
|
|
|
|
|
|
|
|
|
|
|
/* Show message box, background safe */
|
|
|
|
void
|
|
|
|
mc_message (int flags, char *title, const char *text, ...)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start (ap, text);
|
|
|
|
p = g_strdup_vprintf (text, ap);
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
#ifdef WITH_BACKGROUND
|
|
|
|
if (we_are_background) {
|
|
|
|
if (title == MSG_ERROR)
|
|
|
|
title = _("Error");
|
|
|
|
parent_call ((void *) bg_message, 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 02:13:01 +04:00
|
|
|
message (flags, title, "%s", p);
|
2003-10-26 01:54:55 +04:00
|
|
|
|
|
|
|
g_free (p);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2002-11-13 03:20:15 +03:00
|
|
|
void *widget;
|
|
|
|
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;
|
|
|
|
int count = 0; /* number of quick widgets */
|
|
|
|
int curr_widget; /* number of the current quick widget */
|
|
|
|
Widget **widgets; /* table of corresponding widgets */
|
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-09-13 01:22:01 +04: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
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* We pass this to the callback */
|
2002-11-13 03:20:15 +03:00
|
|
|
dd->cols = qd->xlen;
|
1998-02-27 07:54:42 +03:00
|
|
|
dd->lines = qd->ylen;
|
|
|
|
|
2002-11-13 03:20:15 +03:00
|
|
|
/* Count widgets */
|
|
|
|
for (qw = qd->widgets; qw->widget_type; qw++) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
widgets = (Widget **) g_new (Widget *, count);
|
|
|
|
|
|
|
|
for (curr_widget = 0, 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:
|
2003-09-10 03:12:06 +04:00
|
|
|
widget = check_new (ypos, xpos, *qw->result, I18N (qw->text));
|
1998-02-27 07:54:42 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_radio:
|
2003-09-01 04:18:37 +04:00
|
|
|
r = radio_new (ypos, xpos, qw->hotkey_pos, qw->str_result, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
r->pos = r->sel = qw->value;
|
|
|
|
widget = r;
|
|
|
|
break;
|
2002-11-13 03:20:15 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
case quick_button:
|
2002-11-13 03:20:15 +03:00
|
|
|
widget =
|
|
|
|
button_new (ypos, xpos, qw->value,
|
|
|
|
(qw->value ==
|
|
|
|
B_ENTER) ? DEFPUSH_BUTTON : NORMAL_BUTTON,
|
2003-09-01 06:07:02 +04:00
|
|
|
I18N (qw->text), 0);
|
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,
|
|
|
|
qw->text, qw->histname);
|
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;
|
1998-02-27 07:54:42 +03:00
|
|
|
widget = input;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_label:
|
2003-09-01 04:18:37 +04:00
|
|
|
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:
|
|
|
|
widget = 0;
|
|
|
|
fprintf (stderr, "QuickWidget: unknown widget type\n");
|
|
|
|
break;
|
|
|
|
}
|
2002-11-13 03:20:15 +03:00
|
|
|
widgets[curr_widget++] = widget;
|
2001-04-07 01:48:11 +04:00
|
|
|
add_widget (dd, 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) {
|
|
|
|
for (curr_widget = 0, qw = qd->widgets; qw->widget_type; qw++) {
|
|
|
|
Widget *w = widgets[curr_widget++];
|
|
|
|
|
|
|
|
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:
|
2002-11-13 03:20:15 +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
|
|
|
g_free (widgets);
|
|
|
|
|
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
|
|
|
|
|
|
|
/* Show dialog, not background safe */
|
|
|
|
static char *
|
|
|
|
fg_input_dialog_help (char *header, char *text, char *help,
|
2002-09-17 03:28:09 +04:00
|
|
|
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,
|
2003-09-01 05:34:17 +04:00
|
|
|
NULL},
|
|
|
|
{quick_button, 3, 10, 1, 0, N_("&OK"), 0, B_ENTER, 0, 0, NULL},
|
|
|
|
{quick_input, 4, 80, 0, 0, "", 58, 0, 0, 0, NULL},
|
|
|
|
{quick_label, 4, 80, 2, 0, "", 0, 0, 0, 0, NULL},
|
2002-09-17 03:28:09 +04:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
int len;
|
|
|
|
int i;
|
|
|
|
int lines;
|
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|";
|
2002-09-17 03:28:09 +04:00
|
|
|
|
2003-09-01 05:34:17 +04:00
|
|
|
/* we need a unique name for histname because widget.c:history_tool()
|
|
|
|
needs a unique name for each dialog - using the header is ideal */
|
|
|
|
strncpy (histname + 3, header, 60);
|
|
|
|
histname[63] = '\0';
|
|
|
|
quick_widgets[2].histname = histname;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
len = max (strlen (header), msglen (text, &lines)) + 4;
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
quick_widgets[0].relative_x = len / 2 + 4;
|
|
|
|
quick_widgets[1].relative_x =
|
|
|
|
len / 2 - (strlen (_(quick_widgets[1].text)) + 9);
|
|
|
|
quick_widgets[0].x_divisions = quick_widgets[1].x_divisions = len;
|
|
|
|
#endif /* ENABLE_NLS */
|
|
|
|
|
|
|
|
Quick_input.xlen = len;
|
|
|
|
Quick_input.xpos = -1;
|
1998-02-27 07:54:42 +03:00
|
|
|
Quick_input.title = header;
|
2002-09-17 03:28:09 +04:00
|
|
|
Quick_input.help = help;
|
|
|
|
Quick_input.i18n = 0;
|
|
|
|
quick_widgets[INPUT_INDEX + 1].text = g_strstrip (g_strdup (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);
|
|
|
|
g_free (quick_widgets[INPUT_INDEX + 1].text);
|
|
|
|
|
|
|
|
if (ret != B_CANCEL) {
|
|
|
|
return *(quick_widgets[INPUT_INDEX].str_result);
|
1998-02-27 07:54:42 +03:00
|
|
|
} else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-10-26 01:54:55 +04:00
|
|
|
/* Show input dialog, background safe */
|
|
|
|
char *
|
|
|
|
input_dialog_help (char *header, char *text, char *help, char *def_text)
|
|
|
|
{
|
|
|
|
#ifdef WITH_BACKGROUND
|
|
|
|
if (we_are_background)
|
|
|
|
return parent_call_string ((void *) fg_input_dialog_help, 4,
|
|
|
|
strlen (header), header, strlen (text),
|
|
|
|
text, strlen (help), help,
|
|
|
|
strlen (def_text), def_text);
|
|
|
|
else
|
|
|
|
#endif /* WITH_BACKGROUND */
|
|
|
|
return fg_input_dialog_help (header, text, help, def_text);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Show input dialog with default help, background safe */
|
1998-02-27 07:54:42 +03:00
|
|
|
char *input_dialog (char *header, char *text, char *def_text)
|
|
|
|
{
|
|
|
|
return input_dialog_help (header, text, "[Input Line Keys]", def_text);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *input_expand_dialog (char *header, char *text, char *def_text)
|
|
|
|
{
|
|
|
|
char *result;
|
|
|
|
char *expanded;
|
|
|
|
|
|
|
|
result = input_dialog (header, text, def_text);
|
|
|
|
if (result){
|
|
|
|
expanded = tilde_expand (result);
|
|
|
|
if (expanded){
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (result);
|
1998-02-27 07:54:42 +03:00
|
|
|
return expanded;
|
2001-06-16 10:17:28 +04:00
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
/*
|
|
|
|
Cause emacs to enter folding mode for this file:
|
|
|
|
Local variables:
|
|
|
|
end:
|
|
|
|
*/
|