grafthistory: support curl
[elinks/elinks-j605.git] / src / bfu / group.c
blob28eb20c83972c8ca3741cc8695a15e44bcc78e7f
1 /* Widget group implementation. */
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif
7 #include <string.h>
9 #include "elinks.h"
11 #include "bfu/dialog.h"
12 #include "bfu/button.h"
13 #include "bfu/group.h"
14 #include "intl/gettext/libintl.h"
15 #include "terminal/draw.h"
16 #include "terminal/terminal.h"
17 #include "util/color.h"
19 void
20 dlg_format_group(struct terminal *term,
21 struct widget_data *widget_data,
22 int n, int x, int *y, int w, int *rw)
24 int space_between_widgets = 1;
25 int line_width = 0;
26 int xpos;
27 struct color_pair *color = get_bfu_color(term, "dialog.text");
29 assert(n > 0);
30 if_assert_failed return;
32 while (n--) {
33 int widget_width;
34 int width;
35 unsigned char *text = widget_data->widget->text;
36 int label_length = (text && *text) ? strlen(text) : 0;
37 int label_padding = (label_length > 0);
39 if (widget_data->widget->type == WIDGET_CHECKBOX) {
40 width = 3;
41 } else if (widget_is_textfield(widget_data)) {
42 width = widget_data->widget->datalen;
43 } else {
44 /* TODO: handle all widget types. */
45 widget_data++;
46 continue;
49 int_bounds(&label_length, 0, w - width - label_padding);
51 widget_width = width + label_padding + label_length;
52 if (line_width + widget_width > w) {
53 line_width = 0;
54 (*y) += 2; /* Next line */
57 xpos = x + line_width;
59 if (term) {
60 if (widget_data->widget->type == WIDGET_CHECKBOX) {
61 /* Draw text at right of checkbox. */
62 if (label_length)
63 draw_text(term, xpos + width + label_padding, *y,
64 text, label_length,
65 0, color);
67 set_box(&widget_data->box, xpos, *y, width, 1);
69 } else if (widget_is_textfield(widget_data)) {
70 /* Draw label at left of widget. */
71 if (label_length)
72 draw_text(term, xpos, *y,
73 text, label_length,
74 0, color);
76 set_box(&widget_data->box,
77 xpos + label_padding + label_length, *y,
78 width, 1);
82 line_width += widget_width;
83 if (rw) int_bounds(rw, line_width, w);
84 line_width += space_between_widgets;
86 widget_data++;
88 (*y)++;
91 void
92 group_layouter(struct dialog_data *dlg_data)
94 struct terminal *term = dlg_data->win->term;
95 int w = dialog_max_width(term);
96 int rw = int_min(w, strlen(dlg_data->dlg->title));
97 int y = 0;
98 int n = dlg_data->number_of_widgets - 2;
100 dlg_format_group(NULL, dlg_data->widgets_data, n,
101 0, &y, w, &rw);
103 y++;
104 dlg_format_buttons(NULL, dlg_data->widgets_data + n, 2, 0, &y, w,
105 &rw, ALIGN_CENTER);
107 w = rw;
109 draw_dialog(dlg_data, w, y);
111 y = dlg_data->box.y + DIALOG_TB + 1;
112 dlg_format_group(term, dlg_data->widgets_data, n,
113 dlg_data->box.x + DIALOG_LB, &y, w, NULL);
115 y++;
116 dlg_format_buttons(term, dlg_data->widgets_data + n, 2,
117 dlg_data->box.x + DIALOG_LB, &y, w, &rw, ALIGN_CENTER);