2011-10-15 14:56:47 +04:00
|
|
|
/*
|
|
|
|
Widget based utility functions.
|
|
|
|
|
2024-01-01 09:46:17 +03:00
|
|
|
Copyright (C) 1994-2024
|
2014-02-12 10:33:10 +04:00
|
|
|
Free Software Foundation, Inc.
|
2011-10-15 14:56:47 +04:00
|
|
|
|
|
|
|
Authors:
|
|
|
|
Miguel de Icaza, 1994, 1995, 1996
|
|
|
|
Radek Doulik, 1994, 1995
|
|
|
|
Jakub Jelinek, 1995
|
|
|
|
Andrej Borsenkow, 1995
|
2021-10-23 21:10:29 +03:00
|
|
|
Andrew Borodin <aborodin@vmail.ru>, 2009-2022
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
This file is part of the Midnight Commander.
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander 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 3 of the License,
|
|
|
|
or (at your option) any later version.
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander is distributed in the hope that it will be useful,
|
2010-11-12 11:03:57 +03:00
|
|
|
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
|
2011-10-15 14:56:47 +04:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-11-12 11:03:57 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file quick.c
|
|
|
|
* \brief Source: quick dialog engine
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2010-12-01 15:00:35 +03:00
|
|
|
#include <stdio.h> /* fprintf() */
|
2010-11-12 11:03:57 +03:00
|
|
|
|
|
|
|
#include "lib/global.h"
|
2012-09-16 12:54:19 +04:00
|
|
|
#include "lib/strutil.h" /* str_term_width1() */
|
2010-11-12 11:03:57 +03:00
|
|
|
#include "lib/util.h" /* tilde_expand() */
|
|
|
|
#include "lib/widget.h"
|
|
|
|
|
|
|
|
/*** global variables ****************************************************************************/
|
|
|
|
|
|
|
|
/*** file scope macro definitions ****************************************************************/
|
|
|
|
|
2012-09-16 12:54:19 +04:00
|
|
|
#ifdef ENABLE_NLS
|
|
|
|
#define I18N(x) (x = x != NULL && *x != '\0' ? _(x) : x)
|
|
|
|
#else
|
|
|
|
#define I18N(x) (x = x)
|
|
|
|
#endif
|
|
|
|
|
2010-11-12 11:03:57 +03:00
|
|
|
/*** file scope type declarations ****************************************************************/
|
|
|
|
|
2012-09-16 12:54:19 +04:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
Widget *widget;
|
|
|
|
quick_widget_t *quick_widget;
|
|
|
|
} quick_widget_item_t;
|
|
|
|
|
Update template for .c files.
Add section for forward declarations of local functions. This section is
located before file scope variables because functions can be used in
strucutres (see find.c for example):
/*** forward declarations (file scope functions) *************************************************/
/* button callbacks */
static int start_stop (WButton * button, int action);
static int find_do_view_file (WButton * button, int action);
static int find_do_edit_file (WButton * button, int action);
/*** file scope variables ************************************************************************/
static struct
{
...
bcback_fn callback;
} fbuts[] =
{
...
{ B_STOP, NORMAL_BUTTON, N_("S&uspend"), 0, 0, NULL, start_stop },
...
{ B_VIEW, NORMAL_BUTTON, N_("&View - F3"), 0, 0, NULL, find_do_view_file },
{ B_VIEW, NORMAL_BUTTON, N_("&Edit - F4"), 0, 0, NULL, find_do_edit_file }
};
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-02-24 09:27:11 +03:00
|
|
|
/*** forward declarations (file scope functions) *************************************************/
|
|
|
|
|
2010-11-12 11:03:57 +03:00
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
2012-09-16 12:54:19 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2010-11-12 11:03:57 +03:00
|
|
|
/*** file scope functions ************************************************************************/
|
2012-09-16 12:54:19 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static WInput *
|
2024-06-01 21:12:14 +03:00
|
|
|
quick_create_input (int y, int x, const quick_widget_t *qw)
|
2012-09-16 12:54:19 +04:00
|
|
|
{
|
|
|
|
WInput *in;
|
|
|
|
|
2014-03-25 13:37:57 +04:00
|
|
|
in = input_new (y, x, input_colors, 8, qw->u.input.text, qw->u.input.histname,
|
2013-01-25 16:41:41 +04:00
|
|
|
qw->u.input.completion_flags);
|
|
|
|
|
|
|
|
in->is_password = qw->u.input.is_passwd;
|
|
|
|
in->strip_password = qw->u.input.strip_passwd;
|
2012-09-16 12:54:19 +04:00
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
2024-06-01 21:12:14 +03:00
|
|
|
quick_create_labeled_input (GArray *widgets, int *y, int x, quick_widget_t *quick_widget,
|
2012-09-16 12:54:19 +04:00
|
|
|
int *width)
|
|
|
|
{
|
|
|
|
quick_widget_item_t in, label;
|
|
|
|
|
|
|
|
label.quick_widget = g_new0 (quick_widget_t, 1);
|
|
|
|
label.quick_widget->widget_type = quick_label;
|
|
|
|
label.quick_widget->options = quick_widget->options;
|
2016-04-10 12:26:48 +03:00
|
|
|
label.quick_widget->state = quick_widget->state;
|
2012-10-03 13:33:01 +04:00
|
|
|
/* FIXME: this should be turned in depend of label_location */
|
|
|
|
label.quick_widget->pos_flags = quick_widget->pos_flags;
|
2012-09-16 12:54:19 +04:00
|
|
|
|
|
|
|
switch (quick_widget->u.input.label_location)
|
|
|
|
{
|
|
|
|
case input_label_above:
|
|
|
|
label.widget = WIDGET (label_new (*y, x, I18N (quick_widget->u.input.label_text)));
|
2022-05-01 10:43:33 +03:00
|
|
|
*y += label.widget->rect.lines - 1;
|
2012-09-16 12:54:19 +04:00
|
|
|
g_array_append_val (widgets, label);
|
|
|
|
|
|
|
|
in.widget = WIDGET (quick_create_input (++(*y), x, quick_widget));
|
|
|
|
in.quick_widget = quick_widget;
|
|
|
|
g_array_append_val (widgets, in);
|
|
|
|
|
2022-05-01 10:43:33 +03:00
|
|
|
*width = MAX (label.widget->rect.cols, in.widget->rect.cols);
|
2012-09-16 12:54:19 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case input_label_left:
|
|
|
|
label.widget = WIDGET (label_new (*y, x, I18N (quick_widget->u.input.label_text)));
|
|
|
|
g_array_append_val (widgets, label);
|
|
|
|
|
2022-05-01 10:43:33 +03:00
|
|
|
in.widget = WIDGET (quick_create_input (*y, x + label.widget->rect.cols + 1, quick_widget));
|
2012-09-16 12:54:19 +04:00
|
|
|
in.quick_widget = quick_widget;
|
|
|
|
g_array_append_val (widgets, in);
|
|
|
|
|
2022-05-01 10:43:33 +03:00
|
|
|
*width = label.widget->rect.cols + in.widget->rect.cols + 1;
|
2012-09-16 12:54:19 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case input_label_right:
|
|
|
|
in.widget = WIDGET (quick_create_input (*y, x, quick_widget));
|
|
|
|
in.quick_widget = quick_widget;
|
|
|
|
g_array_append_val (widgets, in);
|
|
|
|
|
|
|
|
label.widget =
|
|
|
|
WIDGET (label_new
|
2022-05-01 10:43:33 +03:00
|
|
|
(*y, x + in.widget->rect.cols + 1, I18N (quick_widget->u.input.label_text)));
|
2012-09-16 12:54:19 +04:00
|
|
|
g_array_append_val (widgets, label);
|
|
|
|
|
2022-05-01 10:43:33 +03:00
|
|
|
*width = label.widget->rect.cols + in.widget->rect.cols + 1;
|
2012-09-16 12:54:19 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case input_label_below:
|
|
|
|
in.widget = WIDGET (quick_create_input (*y, x, quick_widget));
|
|
|
|
in.quick_widget = quick_widget;
|
|
|
|
g_array_append_val (widgets, in);
|
|
|
|
|
|
|
|
label.widget = WIDGET (label_new (++(*y), x, I18N (quick_widget->u.input.label_text)));
|
2022-05-01 10:43:33 +03:00
|
|
|
*y += label.widget->rect.lines - 1;
|
2012-09-16 12:54:19 +04:00
|
|
|
g_array_append_val (widgets, label);
|
|
|
|
|
2022-05-01 10:43:33 +03:00
|
|
|
*width = MAX (label.widget->rect.cols, in.widget->rect.cols);
|
2012-09-16 12:54:19 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-11 12:25:07 +04:00
|
|
|
INPUT (in.widget)->label = LABEL (label.widget);
|
2012-09-16 12:54:19 +04:00
|
|
|
/* cross references */
|
|
|
|
label.quick_widget->u.label.input = in.quick_widget;
|
|
|
|
in.quick_widget->u.input.label = label.quick_widget;
|
|
|
|
}
|
2010-11-12 11:03:57 +03:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
2024-06-01 21:12:14 +03:00
|
|
|
quick_dialog_skip (quick_dialog_t *quick_dlg, int nskip)
|
2010-11-12 11:03:57 +03:00
|
|
|
{
|
2012-09-16 12:54:19 +04:00
|
|
|
int len;
|
|
|
|
int blen = 0;
|
|
|
|
int x, y; /* current positions */
|
|
|
|
int y1 = 0; /* bottom of 1st column in case of two columns */
|
|
|
|
int y2 = -1; /* start of two columns */
|
|
|
|
int width1 = 0; /* width of single column */
|
2012-11-20 13:27:10 +04:00
|
|
|
int width2 = 0; /* width of each of two columns */
|
2012-09-16 12:54:19 +04:00
|
|
|
gboolean have_groupbox = FALSE;
|
|
|
|
gboolean two_columns = FALSE;
|
|
|
|
gboolean put_buttons = FALSE;
|
|
|
|
|
|
|
|
/* x position of 1st column is 3 */
|
|
|
|
const int x1 = 3;
|
|
|
|
/* x position of 2nd column is 4 and it will be fixed later, after creation of all widgets */
|
|
|
|
int x2 = 4;
|
|
|
|
|
|
|
|
GArray *widgets;
|
|
|
|
size_t i;
|
|
|
|
quick_widget_t *quick_widget;
|
|
|
|
WGroupbox *g = NULL;
|
2012-09-28 11:18:45 +04:00
|
|
|
WDialog *dd;
|
2015-11-25 19:55:47 +03:00
|
|
|
GList *input_labels = NULL; /* Widgets not directly requested by the user. */
|
2010-11-12 11:03:57 +03:00
|
|
|
int return_val;
|
|
|
|
|
2012-09-16 12:54:19 +04:00
|
|
|
len = str_term_width1 (I18N (quick_dlg->title)) + 6;
|
2022-05-01 10:39:14 +03:00
|
|
|
quick_dlg->rect.cols = MAX (quick_dlg->rect.cols, len);
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2012-09-16 12:54:19 +04:00
|
|
|
y = 1;
|
|
|
|
x = x1;
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2012-09-16 12:54:19 +04:00
|
|
|
/* create widgets */
|
|
|
|
widgets = g_array_sized_new (FALSE, FALSE, sizeof (quick_widget_item_t), 8);
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2012-09-16 12:54:19 +04:00
|
|
|
for (quick_widget = quick_dlg->widgets; quick_widget->widget_type != quick_end; quick_widget++)
|
|
|
|
{
|
|
|
|
quick_widget_item_t item = { NULL, quick_widget };
|
|
|
|
int width = 0;
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2012-09-16 12:54:19 +04:00
|
|
|
switch (quick_widget->widget_type)
|
2010-11-12 11:03:57 +03:00
|
|
|
{
|
|
|
|
case quick_checkbox:
|
2012-09-16 12:54:19 +04:00
|
|
|
item.widget =
|
|
|
|
WIDGET (check_new
|
|
|
|
(++y, x, *quick_widget->u.checkbox.state,
|
|
|
|
I18N (quick_widget->u.checkbox.text)));
|
|
|
|
g_array_append_val (widgets, item);
|
2022-05-01 10:43:33 +03:00
|
|
|
width = item.widget->rect.cols;
|
2012-09-16 12:54:19 +04:00
|
|
|
if (g != NULL)
|
|
|
|
width += 2;
|
|
|
|
if (two_columns)
|
2016-04-07 10:52:04 +03:00
|
|
|
width2 = MAX (width2, width);
|
2012-09-16 12:54:19 +04:00
|
|
|
else
|
2016-04-07 10:52:04 +03:00
|
|
|
width1 = MAX (width1, width);
|
2010-11-12 11:03:57 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_button:
|
2012-09-16 12:54:19 +04:00
|
|
|
/* single button */
|
|
|
|
item.widget = WIDGET (button_new (++y, x, quick_widget->u.button.action,
|
|
|
|
quick_widget->u.button.action == B_ENTER ?
|
|
|
|
DEFPUSH_BUTTON : NORMAL_BUTTON,
|
|
|
|
I18N (quick_widget->u.button.text),
|
|
|
|
quick_widget->u.button.callback));
|
|
|
|
g_array_append_val (widgets, item);
|
2022-05-01 10:43:33 +03:00
|
|
|
width = item.widget->rect.cols;
|
2012-09-16 12:54:19 +04:00
|
|
|
if (g != NULL)
|
|
|
|
width += 2;
|
|
|
|
if (two_columns)
|
2016-04-07 10:52:04 +03:00
|
|
|
width2 = MAX (width2, width);
|
2012-09-16 12:54:19 +04:00
|
|
|
else
|
2016-04-07 10:52:04 +03:00
|
|
|
width1 = MAX (width1, width);
|
2010-11-12 11:03:57 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_input:
|
2012-09-16 12:54:19 +04:00
|
|
|
*quick_widget->u.input.result = NULL;
|
|
|
|
y++;
|
|
|
|
if (quick_widget->u.input.label_location != input_label_none)
|
2015-11-25 19:55:47 +03:00
|
|
|
{
|
2012-09-16 12:54:19 +04:00
|
|
|
quick_create_labeled_input (widgets, &y, x, quick_widget, &width);
|
2015-11-25 19:55:47 +03:00
|
|
|
input_labels = g_list_prepend (input_labels, quick_widget->u.input.label);
|
|
|
|
}
|
2012-09-16 12:54:19 +04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
item.widget = WIDGET (quick_create_input (y, x, quick_widget));
|
|
|
|
g_array_append_val (widgets, item);
|
2022-05-01 10:43:33 +03:00
|
|
|
width = item.widget->rect.cols;
|
2012-09-16 12:54:19 +04:00
|
|
|
}
|
|
|
|
if (g != NULL)
|
|
|
|
width += 2;
|
|
|
|
if (two_columns)
|
2016-04-07 10:52:04 +03:00
|
|
|
width2 = MAX (width2, width);
|
2012-09-16 12:54:19 +04:00
|
|
|
else
|
2016-04-07 10:52:04 +03:00
|
|
|
width1 = MAX (width1, width);
|
2010-11-12 11:03:57 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_label:
|
2012-09-16 12:54:19 +04:00
|
|
|
item.widget = WIDGET (label_new (++y, x, I18N (quick_widget->u.label.text)));
|
|
|
|
g_array_append_val (widgets, item);
|
2022-05-01 10:43:33 +03:00
|
|
|
y += item.widget->rect.lines - 1;
|
|
|
|
width = item.widget->rect.cols;
|
2012-09-16 12:54:19 +04:00
|
|
|
if (g != NULL)
|
|
|
|
width += 2;
|
|
|
|
if (two_columns)
|
2016-04-07 10:52:04 +03:00
|
|
|
width2 = MAX (width2, width);
|
2012-09-16 12:54:19 +04:00
|
|
|
else
|
2016-04-07 10:52:04 +03:00
|
|
|
width1 = MAX (width1, width);
|
2010-11-12 11:03:57 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_radio:
|
|
|
|
{
|
2012-09-16 12:54:19 +04:00
|
|
|
WRadio *r;
|
2010-11-12 11:03:57 +03:00
|
|
|
char **items = NULL;
|
|
|
|
|
|
|
|
/* create the copy of radio_items to avoid mwmory leak */
|
2012-09-16 12:54:19 +04:00
|
|
|
items = g_new (char *, quick_widget->u.radio.count + 1);
|
|
|
|
for (i = 0; i < (size_t) quick_widget->u.radio.count; i++)
|
|
|
|
items[i] = g_strdup (_(quick_widget->u.radio.items[i]));
|
|
|
|
items[i] = NULL;
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2012-09-16 12:54:19 +04:00
|
|
|
r = radio_new (++y, x, quick_widget->u.radio.count, (const char **) items);
|
|
|
|
r->pos = r->sel = *quick_widget->u.radio.value;
|
|
|
|
g_strfreev (items);
|
|
|
|
item.widget = WIDGET (r);
|
|
|
|
g_array_append_val (widgets, item);
|
2022-05-01 10:43:33 +03:00
|
|
|
y += item.widget->rect.lines - 1;
|
|
|
|
width = item.widget->rect.cols;
|
2012-09-16 12:54:19 +04:00
|
|
|
if (g != NULL)
|
|
|
|
width += 2;
|
|
|
|
if (two_columns)
|
2016-04-07 10:52:04 +03:00
|
|
|
width2 = MAX (width2, width);
|
2010-11-12 11:03:57 +03:00
|
|
|
else
|
2016-04-07 10:52:04 +03:00
|
|
|
width1 = MAX (width1, width);
|
2012-09-16 12:54:19 +04:00
|
|
|
}
|
|
|
|
break;
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2012-09-16 12:54:19 +04:00
|
|
|
case quick_start_groupbox:
|
|
|
|
I18N (quick_widget->u.groupbox.title);
|
|
|
|
len = str_term_width1 (quick_widget->u.groupbox.title);
|
|
|
|
g = groupbox_new (++y, x, 1, len + 4, quick_widget->u.groupbox.title);
|
|
|
|
item.widget = WIDGET (g);
|
|
|
|
g_array_append_val (widgets, item);
|
|
|
|
have_groupbox = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_stop_groupbox:
|
|
|
|
if (g != NULL)
|
|
|
|
{
|
|
|
|
Widget *w = WIDGET (g);
|
|
|
|
|
|
|
|
y++;
|
2022-05-01 10:43:33 +03:00
|
|
|
w->rect.lines = y + 1 - w->rect.y;
|
2012-09-16 12:54:19 +04:00
|
|
|
g = NULL;
|
|
|
|
|
|
|
|
g_array_append_val (widgets, item);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_separator:
|
|
|
|
y++;
|
|
|
|
if (quick_widget->u.separator.line)
|
|
|
|
{
|
|
|
|
item.widget = WIDGET (hline_new (y, x, 1));
|
|
|
|
g_array_append_val (widgets, item);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_start_columns:
|
|
|
|
y2 = y;
|
|
|
|
g_array_append_val (widgets, item);
|
|
|
|
two_columns = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_next_column:
|
|
|
|
x = x2;
|
|
|
|
y1 = y;
|
|
|
|
y = y2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_stop_columns:
|
|
|
|
x = x1;
|
2016-04-07 10:52:04 +03:00
|
|
|
y = MAX (y1, y);
|
2012-09-16 12:54:19 +04:00
|
|
|
g_array_append_val (widgets, item);
|
|
|
|
two_columns = FALSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_buttons:
|
|
|
|
/* start put several buttons in bottom line */
|
|
|
|
if (quick_widget->u.separator.space)
|
|
|
|
{
|
|
|
|
y++;
|
|
|
|
|
|
|
|
if (quick_widget->u.separator.line)
|
|
|
|
item.widget = WIDGET (hline_new (y, 1, -1));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_array_append_val (widgets, item);
|
|
|
|
|
|
|
|
/* several buttons in bottom line */
|
|
|
|
y++;
|
|
|
|
quick_widget++;
|
|
|
|
for (; quick_widget->widget_type == quick_button; quick_widget++)
|
|
|
|
{
|
|
|
|
item.widget = WIDGET (button_new (y, x++, quick_widget->u.button.action,
|
|
|
|
quick_widget->u.button.action == B_ENTER ?
|
|
|
|
DEFPUSH_BUTTON : NORMAL_BUTTON,
|
|
|
|
I18N (quick_widget->u.button.text),
|
|
|
|
quick_widget->u.button.callback));
|
|
|
|
item.quick_widget = quick_widget;
|
|
|
|
g_array_append_val (widgets, item);
|
2022-05-01 10:43:33 +03:00
|
|
|
blen += item.widget->rect.cols + 1;
|
2012-09-16 12:54:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* stop dialog build here */
|
|
|
|
blen--;
|
|
|
|
quick_widget->widget_type = quick_end;
|
|
|
|
quick_widget--;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* adjust dialog width */
|
2022-05-01 10:39:14 +03:00
|
|
|
quick_dlg->rect.cols = MAX (quick_dlg->rect.cols, blen + 6);
|
2012-09-16 12:54:19 +04:00
|
|
|
if (have_groupbox)
|
|
|
|
{
|
|
|
|
if (width1 != 0)
|
|
|
|
width1 += 2;
|
|
|
|
if (width2 != 0)
|
|
|
|
width2 += 2;
|
|
|
|
}
|
|
|
|
if (width2 == 0)
|
|
|
|
len = width1 + 6;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
len = width2 * 2 + 7;
|
|
|
|
if (width1 != 0)
|
2016-04-07 10:52:04 +03:00
|
|
|
len = MAX (len, width1 + 6);
|
2012-09-16 12:54:19 +04:00
|
|
|
}
|
|
|
|
|
2022-05-01 10:39:14 +03:00
|
|
|
quick_dlg->rect.cols = MAX (quick_dlg->rect.cols, len);
|
|
|
|
width1 = quick_dlg->rect.cols - 6;
|
|
|
|
width2 = (quick_dlg->rect.cols - 7) / 2;
|
2012-09-16 12:54:19 +04:00
|
|
|
|
2022-05-01 10:39:14 +03:00
|
|
|
if (quick_dlg->rect.x == -1 || quick_dlg->rect.y == -1)
|
|
|
|
dd = dlg_create (TRUE, 0, 0, y + 3, quick_dlg->rect.cols, WPOS_CENTER | WPOS_TRYUP, FALSE,
|
2016-03-06 09:44:16 +03:00
|
|
|
dialog_colors, quick_dlg->callback, quick_dlg->mouse_callback,
|
2016-05-08 21:10:05 +03:00
|
|
|
quick_dlg->help, quick_dlg->title);
|
2012-09-16 12:54:19 +04:00
|
|
|
else
|
2022-05-01 10:39:14 +03:00
|
|
|
dd = dlg_create (TRUE, quick_dlg->rect.y, quick_dlg->rect.x, y + 3, quick_dlg->rect.cols,
|
2016-05-08 21:10:05 +03:00
|
|
|
WPOS_KEEP_DEFAULT, FALSE, dialog_colors, quick_dlg->callback,
|
|
|
|
quick_dlg->mouse_callback, quick_dlg->help, quick_dlg->title);
|
2012-09-16 12:54:19 +04:00
|
|
|
|
|
|
|
/* add widgets into the dialog */
|
|
|
|
x2 = x1 + width2 + 1;
|
|
|
|
g = NULL;
|
|
|
|
two_columns = FALSE;
|
2022-05-01 10:43:33 +03:00
|
|
|
x = (WIDGET (dd)->rect.cols - blen) / 2;
|
2012-09-16 12:54:19 +04:00
|
|
|
|
|
|
|
for (i = 0; i < widgets->len; i++)
|
|
|
|
{
|
|
|
|
quick_widget_item_t *item;
|
|
|
|
int column_width;
|
2022-05-01 10:43:33 +03:00
|
|
|
WRect *r;
|
2012-09-16 12:54:19 +04:00
|
|
|
|
|
|
|
item = &g_array_index (widgets, quick_widget_item_t, i);
|
2022-05-01 10:43:33 +03:00
|
|
|
r = &item->widget->rect;
|
2012-09-16 12:54:19 +04:00
|
|
|
column_width = two_columns ? width2 : width1;
|
|
|
|
|
|
|
|
/* adjust widget width and x position */
|
|
|
|
switch (item->quick_widget->widget_type)
|
|
|
|
{
|
|
|
|
case quick_label:
|
|
|
|
{
|
|
|
|
quick_widget_t *input = item->quick_widget->u.label.input;
|
|
|
|
|
|
|
|
if (input != NULL && input->u.input.label_location == input_label_right)
|
|
|
|
{
|
|
|
|
/* location of this label will be adjusted later */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-12-16 20:52:39 +03:00
|
|
|
MC_FALLTHROUGH;
|
2012-09-16 12:54:19 +04:00
|
|
|
case quick_checkbox:
|
|
|
|
case quick_radio:
|
2022-05-01 10:43:33 +03:00
|
|
|
if (r->x != x1)
|
|
|
|
r->x = x2;
|
2012-09-16 12:54:19 +04:00
|
|
|
if (g != NULL)
|
2022-05-01 10:43:33 +03:00
|
|
|
r->x += 2;
|
2012-09-16 12:54:19 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_button:
|
|
|
|
if (!put_buttons)
|
|
|
|
{
|
2022-05-01 10:43:33 +03:00
|
|
|
if (r->x != x1)
|
|
|
|
r->x = x2;
|
2012-09-16 12:54:19 +04:00
|
|
|
if (g != NULL)
|
2022-05-01 10:43:33 +03:00
|
|
|
r->x += 2;
|
2012-09-16 12:54:19 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-05-01 10:43:33 +03:00
|
|
|
r->x = x;
|
|
|
|
x += r->cols + 1;
|
2012-09-16 12:54:19 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_input:
|
|
|
|
{
|
2012-10-11 12:25:07 +04:00
|
|
|
Widget *label = WIDGET (INPUT (item->widget)->label);
|
2012-09-16 12:54:19 +04:00
|
|
|
int width = column_width;
|
|
|
|
|
|
|
|
if (g != NULL)
|
|
|
|
width -= 4;
|
|
|
|
|
|
|
|
switch (item->quick_widget->u.input.label_location)
|
|
|
|
{
|
|
|
|
case input_label_left:
|
|
|
|
/* label was adjusted before; adjust input line */
|
2022-05-01 10:43:33 +03:00
|
|
|
r->x = label->rect.x + label->rect.cols + 1 - WIDGET (label->owner)->rect.x;
|
|
|
|
r->cols = width - label->rect.cols - 1;
|
2012-09-16 12:54:19 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case input_label_right:
|
2022-05-01 10:43:33 +03:00
|
|
|
if (r->x != x1)
|
|
|
|
r->x = x2;
|
2015-03-17 14:31:52 +03:00
|
|
|
if (g != NULL)
|
2022-05-01 10:43:33 +03:00
|
|
|
r->x += 2;
|
|
|
|
r->cols = width - label->rect.cols - 1;
|
|
|
|
label->rect.x = r->x + r->cols + 1;
|
2012-09-16 12:54:19 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-05-01 10:43:33 +03:00
|
|
|
if (r->x != x1)
|
|
|
|
r->x = x2;
|
2012-09-16 12:54:19 +04:00
|
|
|
if (g != NULL)
|
2022-05-01 10:43:33 +03:00
|
|
|
r->x += 2;
|
|
|
|
r->cols = width;
|
2012-09-16 12:54:19 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-05-01 10:43:33 +03:00
|
|
|
/* forced update internal variables of input line */
|
|
|
|
r->lines = 1;
|
|
|
|
widget_set_size_rect (item->widget, r);
|
2012-09-16 12:54:19 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_start_groupbox:
|
2012-10-11 12:25:07 +04:00
|
|
|
g = GROUPBOX (item->widget);
|
2022-05-01 10:43:33 +03:00
|
|
|
if (r->x != x1)
|
|
|
|
r->x = x2;
|
|
|
|
r->cols = column_width;
|
2012-09-16 12:54:19 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_stop_groupbox:
|
|
|
|
g = NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_separator:
|
|
|
|
if (item->widget != NULL)
|
|
|
|
{
|
|
|
|
if (g != NULL)
|
|
|
|
{
|
|
|
|
Widget *wg = WIDGET (g);
|
|
|
|
|
2012-10-11 12:25:07 +04:00
|
|
|
HLINE (item->widget)->auto_adjust_cols = FALSE;
|
2022-05-01 10:43:33 +03:00
|
|
|
r->x = wg->rect.x + 1 - WIDGET (wg->owner)->rect.x;
|
|
|
|
r->cols = wg->rect.cols;
|
2012-09-16 12:54:19 +04:00
|
|
|
}
|
|
|
|
else if (two_columns)
|
|
|
|
{
|
2012-10-11 12:25:07 +04:00
|
|
|
HLINE (item->widget)->auto_adjust_cols = FALSE;
|
2022-05-01 10:43:33 +03:00
|
|
|
if (r->x != x1)
|
|
|
|
r->x = x2;
|
|
|
|
r->x--;
|
|
|
|
r->cols = column_width + 2;
|
2012-09-16 12:54:19 +04:00
|
|
|
}
|
|
|
|
else
|
2012-10-11 12:25:07 +04:00
|
|
|
HLINE (item->widget)->auto_adjust_cols = TRUE;
|
2010-11-12 11:03:57 +03:00
|
|
|
}
|
2012-09-16 12:54:19 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_start_columns:
|
|
|
|
two_columns = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_stop_columns:
|
|
|
|
two_columns = FALSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_buttons:
|
|
|
|
/* several buttons in bottom line */
|
|
|
|
put_buttons = TRUE;
|
|
|
|
break;
|
2010-11-12 11:03:57 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-09-16 12:54:19 +04:00
|
|
|
if (item->widget != NULL)
|
2010-11-12 11:03:57 +03:00
|
|
|
{
|
2012-09-16 12:54:19 +04:00
|
|
|
unsigned long id;
|
|
|
|
|
|
|
|
/* add widget into dialog */
|
|
|
|
item->widget->options |= item->quick_widget->options; /* FIXME: cannot reset flags, setup only */
|
2016-04-10 12:26:48 +03:00
|
|
|
item->widget->state |= item->quick_widget->state; /* FIXME: cannot reset flags, setup only */
|
2016-09-28 11:01:30 +03:00
|
|
|
id = group_add_widget_autopos (GROUP (dd), item->widget, item->quick_widget->pos_flags,
|
|
|
|
NULL);
|
2012-09-16 12:54:19 +04:00
|
|
|
if (item->quick_widget->id != NULL)
|
|
|
|
*item->quick_widget->id = id;
|
2010-11-12 11:03:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-16 11:01:30 +03:00
|
|
|
/* skip frame widget */
|
2016-10-16 19:45:50 +03:00
|
|
|
if (dd->bg != NULL)
|
2016-10-16 11:01:30 +03:00
|
|
|
nskip++;
|
|
|
|
|
2010-11-12 11:03:57 +03:00
|
|
|
while (nskip-- != 0)
|
2016-09-27 16:16:38 +03:00
|
|
|
group_set_current_widget_next (GROUP (dd));
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2013-06-24 11:40:53 +04:00
|
|
|
return_val = dlg_run (dd);
|
2010-11-12 11:03:57 +03:00
|
|
|
|
|
|
|
/* Get the data if we found something interesting */
|
|
|
|
if (return_val != B_CANCEL)
|
2012-09-16 12:54:19 +04:00
|
|
|
for (i = 0; i < widgets->len; i++)
|
2010-11-12 11:03:57 +03:00
|
|
|
{
|
2012-09-16 12:54:19 +04:00
|
|
|
quick_widget_item_t *item;
|
|
|
|
|
|
|
|
item = &g_array_index (widgets, quick_widget_item_t, i);
|
|
|
|
|
|
|
|
switch (item->quick_widget->widget_type)
|
2010-11-12 11:03:57 +03:00
|
|
|
{
|
|
|
|
case quick_checkbox:
|
2016-11-25 09:32:04 +03:00
|
|
|
*item->quick_widget->u.checkbox.state = CHECK (item->widget)->state;
|
2010-11-12 11:03:57 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_input:
|
2017-10-28 19:18:23 +03:00
|
|
|
if ((item->quick_widget->u.input.completion_flags & INPUT_COMPLETE_CD) != 0)
|
2012-09-16 12:54:19 +04:00
|
|
|
*item->quick_widget->u.input.result =
|
2022-08-04 09:44:55 +03:00
|
|
|
tilde_expand (input_get_ctext (INPUT (item->widget)));
|
2010-11-12 11:03:57 +03:00
|
|
|
else
|
2021-10-23 21:10:29 +03:00
|
|
|
*item->quick_widget->u.input.result = input_get_text (INPUT (item->widget));
|
2010-11-12 11:03:57 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case quick_radio:
|
2012-10-11 12:25:07 +04:00
|
|
|
*item->quick_widget->u.radio.value = RADIO (item->widget)->sel;
|
2010-11-12 11:03:57 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-31 19:32:29 +03:00
|
|
|
widget_destroy (WIDGET (dd));
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2015-11-25 19:55:47 +03:00
|
|
|
g_list_free_full (input_labels, g_free); /* destroy input labels created before */
|
2012-09-16 12:54:19 +04:00
|
|
|
g_array_free (widgets, TRUE);
|
|
|
|
|
2010-11-12 11:03:57 +03:00
|
|
|
return return_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|