mirror of
https://github.com/rkd77/elinks.git
synced 2025-05-18 00:48:57 -04:00
Added format_only parameter for distinguish between formating.
Preparation for using struct terminal in formating functions. By now distinguish between formating widgets and formating widgets with displaying was done with term == NULL and term != NULL. I hope I'am not wrong.
This commit is contained in:
parent
f3a063f1ed
commit
38db20b776
@ -88,7 +88,7 @@ buttons_width(struct widget_data *widget_data, int n,
|
||||
|
||||
while (n--) {
|
||||
int minw = (widget_data++)->widget->info.button.textlen
|
||||
+ BUTTON_HSPACING + BUTTON_LR_LEN;
|
||||
+ BUTTON_HSPACING + BUTTON_LR_LEN;
|
||||
|
||||
maxw += minw;
|
||||
if (minwidth) int_lower_bound(minwidth, minw);
|
||||
@ -100,7 +100,7 @@ buttons_width(struct widget_data *widget_data, int n,
|
||||
void
|
||||
dlg_format_buttons(struct terminal *term,
|
||||
struct widget_data *widget_data, int n,
|
||||
int x, int *y, int w, int *rw, enum format_align align)
|
||||
int x, int *y, int w, int *rw, enum format_align align, int format_only)
|
||||
{
|
||||
int i1 = 0;
|
||||
|
||||
@ -120,7 +120,7 @@ dlg_format_buttons(struct terminal *term,
|
||||
buttons_width(widget_data1, i2 - i1, NULL, &mw);
|
||||
if (rw) int_bounds(rw, mw, w);
|
||||
|
||||
if (term) {
|
||||
if (!format_only) {
|
||||
int i;
|
||||
int p = x + (align == ALIGN_CENTER ? (w - mw) / 2 : 0);
|
||||
|
||||
@ -190,6 +190,7 @@ display_button(struct dialog_data *dlg_data, struct widget_data *widget_data)
|
||||
draw_char(term, x + x1 - !!hk_state, pos->y, data, 0, color);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
len = x1 - !!hk_state;
|
||||
} else
|
||||
|
@ -48,6 +48,6 @@ void add_dlg_button_do(struct dialog *dlg, unsigned char *text, int flags, widge
|
||||
#endif
|
||||
|
||||
extern struct widget_ops button_ops;
|
||||
void dlg_format_buttons(struct terminal *, struct widget_data *, int, int, int *, int, int *, enum format_align);
|
||||
void dlg_format_buttons(struct terminal *, struct widget_data *, int, int, int *, int, int *, enum format_align, int);
|
||||
|
||||
#endif
|
||||
|
@ -39,7 +39,7 @@ void
|
||||
dlg_format_checkbox(struct terminal *term,
|
||||
struct widget_data *widget_data,
|
||||
int x, int *y, int w, int *rw,
|
||||
enum format_align align)
|
||||
enum format_align align, int format_only)
|
||||
{
|
||||
unsigned char *text = widget_data->widget->text;
|
||||
|
||||
@ -52,7 +52,7 @@ dlg_format_checkbox(struct terminal *term,
|
||||
dlg_format_text_do(term, text, x + CHECKBOX_LS, y,
|
||||
w - CHECKBOX_LS, rw,
|
||||
get_bfu_color(term, "dialog.checkbox-label"),
|
||||
align);
|
||||
align, format_only);
|
||||
if (rw) *rw += CHECKBOX_LS;
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ void
|
||||
dlg_format_checkbox(struct terminal *term,
|
||||
struct widget_data *widget_data,
|
||||
int x, int *y, int w, int *rw,
|
||||
enum format_align align);
|
||||
enum format_align align, int format_only);
|
||||
|
||||
#define widget_has_group(widget_data) ((widget_data)->widget->type == WIDGET_CHECKBOX \
|
||||
? (widget_data)->widget->info.checkbox.gid : -1)
|
||||
|
@ -520,7 +520,7 @@ clear_dialog(struct dialog_data *dlg_data, struct widget_data *xxx)
|
||||
|
||||
static void
|
||||
format_widgets(struct terminal *term, struct dialog_data *dlg_data,
|
||||
int x, int *y, int w, int h, int *rw)
|
||||
int x, int *y, int w, int h, int *rw, int format_only)
|
||||
{
|
||||
struct widget_data *wdata = dlg_data->widgets_data;
|
||||
int widgets = dlg_data->number_of_widgets;
|
||||
@ -530,15 +530,18 @@ format_widgets(struct terminal *term, struct dialog_data *dlg_data,
|
||||
switch (wdata->widget->type) {
|
||||
case WIDGET_FIELD_PASS:
|
||||
case WIDGET_FIELD:
|
||||
dlg_format_field(term, wdata, x, y, w, rw, ALIGN_LEFT);
|
||||
dlg_format_field(term, wdata, x, y, w, rw, ALIGN_LEFT,
|
||||
format_only);
|
||||
break;
|
||||
|
||||
case WIDGET_LISTBOX:
|
||||
dlg_format_listbox(term, wdata, x, y, w, h, rw, ALIGN_LEFT);
|
||||
dlg_format_listbox(term, wdata, x, y, w, h, rw,
|
||||
ALIGN_LEFT, format_only);
|
||||
break;
|
||||
|
||||
case WIDGET_TEXT:
|
||||
dlg_format_text(term, wdata, x, y, w, rw, h);
|
||||
dlg_format_text(term, wdata, x, y, w, rw, h,
|
||||
format_only);
|
||||
break;
|
||||
|
||||
case WIDGET_CHECKBOX:
|
||||
@ -556,14 +559,16 @@ format_widgets(struct terminal *term, struct dialog_data *dlg_data,
|
||||
break;
|
||||
}
|
||||
|
||||
dlg_format_group(term, wdata, size, x, y, w, rw);
|
||||
dlg_format_group(term, wdata, size, x, y, w, rw,
|
||||
format_only);
|
||||
wdata += size - 1;
|
||||
|
||||
} else {
|
||||
|
||||
/* No horizontal space between checkboxes belonging to
|
||||
* the same group. */
|
||||
dlg_format_checkbox(term, wdata, x, y, w, rw, ALIGN_LEFT);
|
||||
dlg_format_checkbox(term, wdata, x, y, w, rw,
|
||||
ALIGN_LEFT, format_only);
|
||||
if (widgets > 1
|
||||
&& group == widget_has_group(&wdata[1]))
|
||||
(*y)--;
|
||||
@ -575,7 +580,7 @@ format_widgets(struct terminal *term, struct dialog_data *dlg_data,
|
||||
* of the dialog. */
|
||||
case WIDGET_BUTTON:
|
||||
dlg_format_buttons(term, wdata, widgets,
|
||||
x, y, w, rw, ALIGN_CENTER);
|
||||
x, y, w, rw, ALIGN_CENTER, format_only);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -597,7 +602,7 @@ generic_dialog_layouter(struct dialog_data *dlg_data)
|
||||
int y = dlg_data->dlg->layout.padding_top ? 0 : -1;
|
||||
int x = 0;
|
||||
|
||||
format_widgets(NULL, dlg_data, x, &y, w, height, &rw);
|
||||
format_widgets(term, dlg_data, x, &y, w, height, &rw, 1);
|
||||
|
||||
/* Update the width to respond to the required minimum width */
|
||||
if (dlg_data->dlg->layout.fit_datalen) {
|
||||
@ -612,7 +617,7 @@ generic_dialog_layouter(struct dialog_data *dlg_data)
|
||||
y = dlg_data->box.y + DIALOG_TB + dlg_data->dlg->layout.padding_top;
|
||||
x = dlg_data->box.x + DIALOG_LB;
|
||||
|
||||
format_widgets(term, dlg_data, x, &y, w, height, NULL);
|
||||
format_widgets(term, dlg_data, x, &y, w, height, NULL, 0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
void
|
||||
dlg_format_group(struct terminal *term,
|
||||
struct widget_data *widget_data,
|
||||
int n, int x, int *y, int w, int *rw)
|
||||
int n, int x, int *y, int w, int *rw, int format_only)
|
||||
{
|
||||
int space_between_widgets = 1;
|
||||
int line_width = 0;
|
||||
@ -56,7 +56,7 @@ dlg_format_group(struct terminal *term,
|
||||
|
||||
xpos = x + line_width;
|
||||
|
||||
if (term) {
|
||||
if (!format_only) {
|
||||
if (widget_data->widget->type == WIDGET_CHECKBOX) {
|
||||
/* Draw text at right of checkbox. */
|
||||
if (label_length)
|
||||
@ -72,7 +72,6 @@ dlg_format_group(struct terminal *term,
|
||||
draw_text(term, xpos, *y,
|
||||
text, label_length,
|
||||
0, color);
|
||||
|
||||
set_box(&widget_data->box,
|
||||
xpos + label_padding + label_length, *y,
|
||||
width, 1);
|
||||
@ -97,12 +96,13 @@ group_layouter(struct dialog_data *dlg_data)
|
||||
int y = 0;
|
||||
int n = dlg_data->number_of_widgets - 2;
|
||||
|
||||
dlg_format_group(NULL, dlg_data->widgets_data, n,
|
||||
0, &y, w, &rw);
|
||||
|
||||
dlg_format_group(term, dlg_data->widgets_data, n,
|
||||
0, &y, w, &rw, 1);
|
||||
|
||||
y++;
|
||||
dlg_format_buttons(NULL, dlg_data->widgets_data + n, 2, 0, &y, w,
|
||||
&rw, ALIGN_CENTER);
|
||||
dlg_format_buttons(term, dlg_data->widgets_data + n, 2, 0, &y, w,
|
||||
&rw, ALIGN_CENTER, 1);
|
||||
|
||||
w = rw;
|
||||
|
||||
@ -110,9 +110,9 @@ group_layouter(struct dialog_data *dlg_data)
|
||||
|
||||
y = dlg_data->box.y + DIALOG_TB + 1;
|
||||
dlg_format_group(term, dlg_data->widgets_data, n,
|
||||
dlg_data->box.x + DIALOG_LB, &y, w, NULL);
|
||||
dlg_data->box.x + DIALOG_LB, &y, w, NULL, 0);
|
||||
|
||||
y++;
|
||||
dlg_format_buttons(term, dlg_data->widgets_data + n, 2,
|
||||
dlg_data->box.x + DIALOG_LB, &y, w, &rw, ALIGN_CENTER);
|
||||
dlg_data->box.x + DIALOG_LB, &y, w, &rw, ALIGN_CENTER, 0);
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ struct widget_data;
|
||||
|
||||
void dlg_format_group(struct terminal *term,
|
||||
struct widget_data *widget_data,
|
||||
int n, int x, int *y, int w, int *rw);
|
||||
int n, int x, int *y, int w, int *rw, int format_only);
|
||||
|
||||
void group_layouter(struct dialog_data *);
|
||||
|
||||
|
@ -105,7 +105,7 @@ check_nonempty(struct dialog_data *dlg_data, struct widget_data *widget_data)
|
||||
void
|
||||
dlg_format_field(struct terminal *term,
|
||||
struct widget_data *widget_data,
|
||||
int x, int *y, int w, int *rw, enum format_align align)
|
||||
int x, int *y, int w, int *rw, enum format_align align, int format_only)
|
||||
{
|
||||
static int max_label_width;
|
||||
static int *prev_y; /* Assert the uniqueness of y */ /* TODO: get rid of this !! --Zas */
|
||||
@ -130,9 +130,9 @@ dlg_format_field(struct terminal *term,
|
||||
}
|
||||
|
||||
if (label && *label) {
|
||||
if (term) text_color = get_bfu_color(term, "dialog.text");
|
||||
if (!format_only) text_color = get_bfu_color(term, "dialog.text");
|
||||
|
||||
dlg_format_text_do(term, label, x, y, w, rw, text_color, ALIGN_LEFT);
|
||||
dlg_format_text_do(term, label, x, y, w, rw, text_color, ALIGN_LEFT, format_only);
|
||||
}
|
||||
|
||||
/* XXX: We want the field and label on the same line if the terminal
|
||||
@ -142,7 +142,7 @@ dlg_format_field(struct terminal *term,
|
||||
(*y) -= INPUTFIELD_HEIGHT;
|
||||
dlg_format_text_do(term, INPUTFIELD_FLOAT_SEPARATOR,
|
||||
x + label_width, y, w, rw,
|
||||
text_color, ALIGN_LEFT);
|
||||
text_color, ALIGN_LEFT, format_only);
|
||||
w -= INPUTFIELD_FLOAT_SEPARATOR_LEN + INPUTFIELD_FLOATLABEL_PADDING;
|
||||
x += INPUTFIELD_FLOAT_SEPARATOR_LEN + INPUTFIELD_FLOATLABEL_PADDING;
|
||||
}
|
||||
@ -722,7 +722,7 @@ input_line_layouter(struct dialog_data *dlg_data)
|
||||
- ses->status.show_tabs_bar;
|
||||
|
||||
dlg_format_field(win->term, dlg_data->widgets_data, 0,
|
||||
&y, win->term->width, NULL, ALIGN_LEFT);
|
||||
&y, win->term->width, NULL, ALIGN_LEFT, 0);
|
||||
}
|
||||
|
||||
static widget_handler_status_T
|
||||
|
@ -62,7 +62,7 @@ extern struct widget_ops field_pass_ops;
|
||||
widget_handler_status_T check_number(struct dialog_data *, struct widget_data *);
|
||||
widget_handler_status_T check_nonempty(struct dialog_data *, struct widget_data *);
|
||||
|
||||
void dlg_format_field(struct terminal *, struct widget_data *, int, int *, int, int *, enum format_align);
|
||||
void dlg_format_field(struct terminal *, struct widget_data *, int, int *, int, int *, enum format_align, int format_only);
|
||||
|
||||
void input_field(struct terminal *, struct memory_list *, int, unsigned char *,
|
||||
unsigned char *, unsigned char *, unsigned char *, void *,
|
||||
|
@ -43,7 +43,7 @@ get_listbox_widget_data(struct widget_data *widget_data)
|
||||
void
|
||||
dlg_format_listbox(struct terminal *term, struct widget_data *widget_data,
|
||||
int x, int *y, int w, int max_height, int *rw,
|
||||
enum format_align align)
|
||||
enum format_align align, int format_only)
|
||||
{
|
||||
int min, optimal_h, height;
|
||||
|
||||
|
@ -133,7 +133,7 @@ struct listbox_item {
|
||||
|
||||
extern struct widget_ops listbox_ops;
|
||||
|
||||
void dlg_format_listbox(struct terminal *, struct widget_data *, int, int *, int, int, int *, enum format_align);
|
||||
void dlg_format_listbox(struct terminal *, struct widget_data *, int, int *, int, int, int *, enum format_align, int format_only);
|
||||
|
||||
struct listbox_item *traverse_listbox_items_list(struct listbox_item *, struct listbox_data *, int, int, int (*)(struct listbox_item *, void *, int *), void *);
|
||||
|
||||
|
@ -36,7 +36,7 @@ add_dlg_text(struct dialog *dlg, unsigned char *text,
|
||||
|
||||
/* Returns length of substring (from start of @text) before a split. */
|
||||
static inline int
|
||||
split_line(unsigned char *text, int max_width)
|
||||
split_line(unsigned char *text, int max_width, int *cells)
|
||||
{
|
||||
unsigned char *split = text;
|
||||
|
||||
@ -65,6 +65,7 @@ split_line(unsigned char *text, int max_width)
|
||||
split++;
|
||||
break;
|
||||
}
|
||||
#endif /* CONFIG_UTF_8 */
|
||||
|
||||
/* If no way to do a clean split, just return
|
||||
* requested maximal width. */
|
||||
@ -134,7 +135,8 @@ split_lines(struct widget_data *widget_data, int max_width)
|
||||
void
|
||||
dlg_format_text_do(struct terminal *term, unsigned char *text,
|
||||
int x, int *y, int width, int *real_width,
|
||||
struct color_pair *color, enum format_align align)
|
||||
struct color_pair *color, enum format_align align,
|
||||
int format_only)
|
||||
{
|
||||
int line_width;
|
||||
int firstline = 1;
|
||||
@ -158,7 +160,7 @@ dlg_format_text_do(struct terminal *term, unsigned char *text,
|
||||
}
|
||||
|
||||
if (real_width) int_lower_bound(real_width, line_width);
|
||||
if (!term || !line_width) continue;
|
||||
if (format_only || !line_width) continue;
|
||||
|
||||
/* Calculate the number of chars to indent */
|
||||
if (align == ALIGN_CENTER)
|
||||
@ -176,7 +178,8 @@ dlg_format_text_do(struct terminal *term, unsigned char *text,
|
||||
|
||||
void
|
||||
dlg_format_text(struct terminal *term, struct widget_data *widget_data,
|
||||
int x, int *y, int width, int *real_width, int max_height)
|
||||
int x, int *y, int width, int *real_width, int max_height,
|
||||
int format_only)
|
||||
{
|
||||
unsigned char *text = widget_data->widget->text;
|
||||
unsigned char saved = 0;
|
||||
@ -246,7 +249,7 @@ dlg_format_text(struct terminal *term, struct widget_data *widget_data,
|
||||
dlg_format_text_do(term, text,
|
||||
x, y, width, real_width,
|
||||
get_bfu_color(term, "dialog.text"),
|
||||
widget_data->widget->info.text.align);
|
||||
widget_data->widget->info.text.align, format_only);
|
||||
|
||||
if (widget_data->widget->info.text.is_label) (*y)--;
|
||||
|
||||
@ -333,7 +336,7 @@ format_and_display_text(struct widget_data *widget_data,
|
||||
|
||||
dlg_format_text(term, widget_data,
|
||||
widget_data->box.x, &y, widget_data->box.width, NULL,
|
||||
height);
|
||||
height, 0);
|
||||
|
||||
display_text(dlg_data, widget_data);
|
||||
redraw_from_window(dlg_data->win);
|
||||
|
@ -47,11 +47,11 @@ void add_dlg_text(struct dialog *dlg, unsigned char *text,
|
||||
extern struct widget_ops text_ops;
|
||||
void dlg_format_text_do(struct terminal *term,
|
||||
unsigned char *text, int x, int *y, int w, int *rw,
|
||||
struct color_pair *scolor, enum format_align align);
|
||||
struct color_pair *scolor, enum format_align align, int format_only);
|
||||
|
||||
void
|
||||
dlg_format_text(struct terminal *term, struct widget_data *widget_data,
|
||||
int x, int *y, int dlg_width, int *real_width, int height);
|
||||
int x, int *y, int dlg_width, int *real_width, int height, int format_only);
|
||||
|
||||
#define text_is_scrollable(widget_data) \
|
||||
((widget_data)->widget->info.text.is_scrollable \
|
||||
|
@ -152,8 +152,8 @@ download_dialog_layouter(struct dialog_data *dlg_data)
|
||||
int_lower_bound(&w, DOWN_DLG_MIN);
|
||||
}
|
||||
|
||||
dlg_format_text_do(NULL, url, 0, &y, w, &rw,
|
||||
dialog_text_color, ALIGN_LEFT);
|
||||
dlg_format_text_do(term, url, 0, &y, w, &rw,
|
||||
dialog_text_color, ALIGN_LEFT, 1);
|
||||
|
||||
y++;
|
||||
if (show_meter) y += 2;
|
||||
@ -161,13 +161,13 @@ download_dialog_layouter(struct dialog_data *dlg_data)
|
||||
#if CONFIG_BITTORRENT
|
||||
if (bittorrent) y += 2;
|
||||
#endif
|
||||
dlg_format_text_do(NULL, msg, 0, &y, w, &rw,
|
||||
dialog_text_color, ALIGN_LEFT);
|
||||
dlg_format_text_do(term, msg, 0, &y, w, &rw,
|
||||
dialog_text_color, ALIGN_LEFT, 1);
|
||||
|
||||
y++;
|
||||
dlg_format_buttons(NULL, dlg_data->widgets_data,
|
||||
dlg_format_buttons(term, dlg_data->widgets_data,
|
||||
dlg_data->number_of_widgets, 0, &y, w,
|
||||
&rw, ALIGN_CENTER);
|
||||
&rw, ALIGN_CENTER, 1);
|
||||
|
||||
draw_dialog(dlg_data, w, y);
|
||||
|
||||
@ -186,7 +186,7 @@ download_dialog_layouter(struct dialog_data *dlg_data)
|
||||
y = dlg_data->box.y + DIALOG_TB + 1;
|
||||
x = dlg_data->box.x + DIALOG_LB;
|
||||
dlg_format_text_do(term, url, x, &y, w, NULL,
|
||||
dialog_text_color, ALIGN_LEFT);
|
||||
dialog_text_color, ALIGN_LEFT, 0);
|
||||
|
||||
if (show_meter) {
|
||||
y++;
|
||||
@ -203,12 +203,12 @@ download_dialog_layouter(struct dialog_data *dlg_data)
|
||||
#endif
|
||||
y++;
|
||||
dlg_format_text_do(term, msg, x, &y, w, NULL,
|
||||
dialog_text_color, ALIGN_LEFT);
|
||||
dialog_text_color, ALIGN_LEFT, 0);
|
||||
|
||||
y++;
|
||||
dlg_format_buttons(term, dlg_data->widgets_data,
|
||||
dlg_data->number_of_widgets, x, &y, w,
|
||||
NULL, ALIGN_CENTER);
|
||||
NULL, ALIGN_CENTER, 0);
|
||||
|
||||
mem_free(url);
|
||||
mem_free(msg);
|
||||
|
Loading…
x
Reference in New Issue
Block a user