1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-30 01:55:30 +00:00

Added support for double-width UTF-8 checkboxes and listbox in dialogs.

This commit is contained in:
Pavol Babincak 2006-03-06 15:15:30 +01:00 committed by Pavol Babincak
parent 10303bb94a
commit 509fe2cf0d
2 changed files with 79 additions and 14 deletions

View File

@ -16,6 +16,9 @@
#include "terminal/terminal.h"
#include "util/color.h"
/* Same as in src/bfu/checkbox.c */
#define CHECKBOX_LEN 3 /* "[X]" or "(X)" */
void
dlg_format_group(struct terminal *term,
struct widget_data *widget_data,
@ -33,13 +36,31 @@ dlg_format_group(struct terminal *term,
int widget_width;
int width;
unsigned char *text = widget_data->widget->text;
int label_length = (text && *text) ? strlen(text) : 0;
int label_padding = (label_length > 0);
int label_length;
int label_padding;
#ifdef CONFIG_UTF_8
if (term->utf8) {
if (text && *text)
label_length = utf8_ptr2cells(text, NULL);
else
label_length = 0;
} else
#endif /* CONFIG_UTF_8 */
label_length = (text && *text) ? strlen(text) : 0;
label_padding = (label_length > 0);
if (widget_data->widget->type == WIDGET_CHECKBOX) {
width = 3;
width = CHECKBOX_LEN;
} else if (widget_is_textfield(widget_data)) {
width = widget_data->widget->datalen;
#ifdef CONFIG_UTF_8
if (term->utf8) {
width = utf8_ptr2cells(widget_data->widget->data,
NULL);
} else
#endif /* CONFIG_UTF_8 */
width = widget_data->widget->datalen;
} else {
/* TODO: handle all widget types. */
widget_data++;
@ -59,19 +80,50 @@ dlg_format_group(struct terminal *term,
if (!format_only) {
if (widget_data->widget->type == WIDGET_CHECKBOX) {
/* Draw text at right of checkbox. */
if (label_length)
draw_text(term, xpos + width + label_padding, *y,
text, label_length,
0, color);
if (label_length) {
#ifdef CONFIG_UTF_8
if (term->utf8) {
int lb = utf8_cells2bytes(
text,
label_length,
NULL);
draw_text(term, xpos + width
+ label_padding,
*y, text, lb, 0,
color);
} else
#endif /* CONFIG_UTF_8 */
{
draw_text(term, xpos + width
+ label_padding,
*y, text,
label_length, 0,
color);
}
}
set_box(&widget_data->box, xpos, *y, width, 1);
} else if (widget_is_textfield(widget_data)) {
/* Draw label at left of widget. */
if (label_length)
draw_text(term, xpos, *y,
text, label_length,
0, color);
if (label_length) {
#ifdef CONFIG_UTF_8
if (term->utf8) {
int lb = utf8_cells2bytes(
text,
label_length,
NULL);
draw_text(term, xpos, *y,
text, lb, 0, color);
} else
#endif /* CONFIG_UTF_8 */
{
draw_text(term, xpos, *y,
text, label_length,
0, color);
}
}
set_box(&widget_data->box,
xpos + label_padding + label_length, *y,
width, 1);
@ -92,10 +144,16 @@ group_layouter(struct dialog_data *dlg_data)
{
struct terminal *term = dlg_data->win->term;
int w = dialog_max_width(term);
int rw = int_min(w, strlen(dlg_data->dlg->title));
int rw;
int y = 0;
int n = dlg_data->number_of_widgets - 2;
#ifdef CONFIG_UTF_8
if (term->utf8)
rw = int_min(w, utf8_ptr2cells(dlg_data->dlg->title, NULL));
else
#endif /* CONFIG_UTF_8 */
rw = int_min(w, strlen(dlg_data->dlg->title));
dlg_format_group(term, dlg_data->widgets_data, n,
0, &y, w, &rw, 1);

View File

@ -453,6 +453,7 @@ display_listbox_item(struct listbox_item *item, void *data_, int *offset)
} else {
unsigned char *text;
struct listbox_ops *ops = data->box->ops;
int len_bytes;
assert(ops && ops->get_info);
@ -461,8 +462,14 @@ display_listbox_item(struct listbox_item *item, void *data_, int *offset)
len = strlen(text);
int_upper_bound(&len, int_max(0, data->widget_data->box.width - depth * 5));
#ifdef CONFIG_UTF_8
if (data->term->utf8)
len_bytes = utf8_cells2bytes(text, len, NULL);
else
#endif /* CONFIG_UTF_8 */
len_bytes = len;
draw_text(data->term, x, y, text, len, 0, text_color);
draw_text(data->term, x, y, text, len_bytes, 0, text_color);
mem_free(text);
}