2005-09-15 09:58:31 -04:00
|
|
|
/* Widget group implementation. */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "elinks.h"
|
|
|
|
|
|
|
|
#include "bfu/dialog.h"
|
|
|
|
#include "bfu/button.h"
|
|
|
|
#include "bfu/group.h"
|
2021-08-08 15:25:08 -04:00
|
|
|
#include "intl/libintl.h"
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "terminal/draw.h"
|
|
|
|
#include "terminal/terminal.h"
|
|
|
|
#include "util/color.h"
|
|
|
|
|
2006-03-06 09:15:30 -05:00
|
|
|
/* Same as in src/bfu/checkbox.c */
|
|
|
|
#define CHECKBOX_LEN 3 /* "[X]" or "(X)" */
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
void
|
2008-09-07 12:27:06 -04:00
|
|
|
dlg_format_group(struct dialog_data *dlg_data,
|
2005-09-15 09:58:31 -04:00
|
|
|
struct widget_data *widget_data,
|
2006-03-06 00:01:12 -05:00
|
|
|
int n, int x, int *y, int w, int *rw, int format_only)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
2008-09-07 12:27:06 -04:00
|
|
|
struct terminal *term = dlg_data->win->term;
|
2005-09-15 09:58:31 -04:00
|
|
|
int space_between_widgets = 1;
|
|
|
|
int line_width = 0;
|
|
|
|
int xpos;
|
2022-10-16 09:18:34 -04:00
|
|
|
struct color_pair *color = get_bfu_color(term, "dialog.text");
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
assert(n > 0);
|
|
|
|
if_assert_failed return;
|
|
|
|
|
|
|
|
while (n--) {
|
|
|
|
int widget_width;
|
|
|
|
int width;
|
2021-01-02 10:20:27 -05:00
|
|
|
char *text = widget_data->widget->text;
|
2006-03-06 09:15:30 -05:00
|
|
|
int label_length;
|
|
|
|
int label_padding;
|
|
|
|
|
2006-09-17 09:12:47 -04:00
|
|
|
#ifdef CONFIG_UTF8
|
2007-05-20 08:31:02 -04:00
|
|
|
if (term->utf8_cp) {
|
2006-03-06 09:15:30 -05:00
|
|
|
if (text && *text)
|
|
|
|
label_length = utf8_ptr2cells(text, NULL);
|
|
|
|
else
|
|
|
|
label_length = 0;
|
|
|
|
} else
|
2006-09-17 09:12:47 -04:00
|
|
|
#endif /* CONFIG_UTF8 */
|
2006-03-06 09:15:30 -05:00
|
|
|
label_length = (text && *text) ? strlen(text) : 0;
|
|
|
|
|
|
|
|
label_padding = (label_length > 0);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
if (widget_data->widget->type == WIDGET_CHECKBOX) {
|
2006-03-06 09:15:30 -05:00
|
|
|
width = CHECKBOX_LEN;
|
2005-09-15 09:58:31 -04:00
|
|
|
} else if (widget_is_textfield(widget_data)) {
|
2006-09-17 09:12:47 -04:00
|
|
|
#ifdef CONFIG_UTF8
|
2007-05-20 08:31:02 -04:00
|
|
|
if (term->utf8_cp) {
|
2022-01-24 15:53:18 -05:00
|
|
|
width = utf8_ptr2cells((char *)widget_data->widget->data,
|
2006-03-06 09:15:30 -05:00
|
|
|
NULL);
|
|
|
|
} else
|
2006-09-17 09:12:47 -04:00
|
|
|
#endif /* CONFIG_UTF8 */
|
2006-03-06 09:15:30 -05:00
|
|
|
width = widget_data->widget->datalen;
|
2005-09-15 09:58:31 -04:00
|
|
|
} else {
|
|
|
|
/* TODO: handle all widget types. */
|
|
|
|
widget_data++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int_bounds(&label_length, 0, w - width - label_padding);
|
|
|
|
|
|
|
|
widget_width = width + label_padding + label_length;
|
|
|
|
if (line_width + widget_width > w) {
|
|
|
|
line_width = 0;
|
|
|
|
(*y) += 2; /* Next line */
|
|
|
|
}
|
|
|
|
|
|
|
|
xpos = x + line_width;
|
|
|
|
|
2006-03-06 00:01:12 -05:00
|
|
|
if (!format_only) {
|
2005-09-15 09:58:31 -04:00
|
|
|
if (widget_data->widget->type == WIDGET_CHECKBOX) {
|
|
|
|
/* Draw text at right of checkbox. */
|
2006-03-06 09:15:30 -05:00
|
|
|
if (label_length) {
|
2006-09-17 09:12:47 -04:00
|
|
|
#ifdef CONFIG_UTF8
|
2007-05-20 08:31:02 -04:00
|
|
|
if (term->utf8_cp) {
|
2006-03-06 09:15:30 -05:00
|
|
|
int lb = utf8_cells2bytes(
|
|
|
|
text,
|
|
|
|
label_length,
|
|
|
|
NULL);
|
2022-10-16 09:18:34 -04:00
|
|
|
draw_dlg_text(dlg_data, xpos + width
|
2006-03-06 09:15:30 -05:00
|
|
|
+ label_padding,
|
|
|
|
*y, text, lb, 0,
|
2022-10-16 09:18:34 -04:00
|
|
|
color);
|
2006-03-06 09:15:30 -05:00
|
|
|
} else
|
2006-09-17 09:12:47 -04:00
|
|
|
#endif /* CONFIG_UTF8 */
|
2006-03-06 09:15:30 -05:00
|
|
|
{
|
2022-10-16 09:18:34 -04:00
|
|
|
draw_dlg_text(dlg_data, xpos + width
|
2006-03-06 09:15:30 -05:00
|
|
|
+ label_padding,
|
|
|
|
*y, text,
|
|
|
|
label_length, 0,
|
2022-10-16 09:18:34 -04:00
|
|
|
color);
|
2006-03-06 09:15:30 -05:00
|
|
|
}
|
|
|
|
}
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
set_box(&widget_data->box, xpos, *y, width, 1);
|
|
|
|
|
|
|
|
} else if (widget_is_textfield(widget_data)) {
|
|
|
|
/* Draw label at left of widget. */
|
2006-03-06 09:15:30 -05:00
|
|
|
if (label_length) {
|
2006-09-17 09:12:47 -04:00
|
|
|
#ifdef CONFIG_UTF8
|
2007-05-20 08:31:02 -04:00
|
|
|
if (term->utf8_cp) {
|
2006-03-06 09:15:30 -05:00
|
|
|
int lb = utf8_cells2bytes(
|
|
|
|
text,
|
|
|
|
label_length,
|
|
|
|
NULL);
|
2022-10-16 09:18:34 -04:00
|
|
|
draw_dlg_text(dlg_data, xpos, *y,
|
|
|
|
text, lb, 0, color);
|
2006-03-06 09:15:30 -05:00
|
|
|
} else
|
2006-09-17 09:12:47 -04:00
|
|
|
#endif /* CONFIG_UTF8 */
|
2006-03-06 09:15:30 -05:00
|
|
|
{
|
2022-10-16 09:18:34 -04:00
|
|
|
draw_dlg_text(dlg_data, xpos, *y,
|
2006-07-27 03:51:10 -04:00
|
|
|
text, label_length,
|
2022-10-16 09:18:34 -04:00
|
|
|
0, color);
|
2006-03-06 09:15:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
set_box(&widget_data->box,
|
|
|
|
xpos + label_padding + label_length, *y,
|
|
|
|
width, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
line_width += widget_width;
|
|
|
|
if (rw) int_bounds(rw, line_width, w);
|
|
|
|
line_width += space_between_widgets;
|
|
|
|
|
|
|
|
widget_data++;
|
|
|
|
}
|
|
|
|
(*y)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
group_layouter(struct dialog_data *dlg_data)
|
|
|
|
{
|
|
|
|
struct terminal *term = dlg_data->win->term;
|
|
|
|
int w = dialog_max_width(term);
|
2006-03-06 09:15:30 -05:00
|
|
|
int rw;
|
2005-09-15 09:58:31 -04:00
|
|
|
int y = 0;
|
|
|
|
int n = dlg_data->number_of_widgets - 2;
|
|
|
|
|
2006-09-17 09:12:47 -04:00
|
|
|
#ifdef CONFIG_UTF8
|
2007-05-20 08:31:02 -04:00
|
|
|
if (term->utf8_cp)
|
2006-03-06 09:15:30 -05:00
|
|
|
rw = int_min(w, utf8_ptr2cells(dlg_data->dlg->title, NULL));
|
|
|
|
else
|
2006-09-17 09:12:47 -04:00
|
|
|
#endif /* CONFIG_UTF8 */
|
2006-03-06 09:15:30 -05:00
|
|
|
rw = int_min(w, strlen(dlg_data->dlg->title));
|
2006-03-06 00:01:12 -05:00
|
|
|
|
2008-09-07 12:27:06 -04:00
|
|
|
dlg_format_group(dlg_data, dlg_data->widgets_data, n,
|
2006-03-06 00:01:12 -05:00
|
|
|
0, &y, w, &rw, 1);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
y++;
|
2008-09-07 12:27:06 -04:00
|
|
|
dlg_format_buttons(dlg_data, dlg_data->widgets_data + n, 2, 0, &y, w,
|
2006-03-06 00:01:12 -05:00
|
|
|
&rw, ALIGN_CENTER, 1);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
w = rw;
|
|
|
|
|
|
|
|
draw_dialog(dlg_data, w, y);
|
|
|
|
|
|
|
|
y = dlg_data->box.y + DIALOG_TB + 1;
|
2008-09-07 12:27:06 -04:00
|
|
|
dlg_format_group(dlg_data, dlg_data->widgets_data, n,
|
2006-03-06 00:01:12 -05:00
|
|
|
dlg_data->box.x + DIALOG_LB, &y, w, NULL, 0);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
y++;
|
2008-09-07 12:27:06 -04:00
|
|
|
dlg_format_buttons(dlg_data, dlg_data->widgets_data + n, 2,
|
2006-03-06 00:01:12 -05:00
|
|
|
dlg_data->box.x + DIALOG_LB, &y, w, &rw, ALIGN_CENTER, 0);
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|